[Code formatting: Change indentation style to space](https://github.com/clicon/clixon/issues/379)

* Applies to all c/h/y/l/sh files and .editorconfig
This commit is contained in:
Olof hagsand 2022-10-27 14:21:17 +02:00
parent a9d1ab006c
commit d84c529ff1
376 changed files with 38147 additions and 38133 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -92,12 +92,12 @@ confirmed_commit_init(clicon_handle h)
struct confirmed_commit *cc = NULL;
if ((cc = calloc(1, sizeof(*cc))) == NULL){
clicon_err(OE_UNIX, errno, "calloc");
goto done;
clicon_err(OE_UNIX, errno, "calloc");
goto done;
}
cc->cc_state = INACTIVE;
if (clicon_ptr_set(h, "confirmed-commit-struct", cc) < 0)
goto done;
goto done;
retval = 0;
done:
return retval;
@ -114,9 +114,9 @@ confirmed_commit_free(clicon_handle h)
clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc);
if (cc != NULL){
if (cc->cc_persist_id != NULL)
free (cc->cc_persist_id);
free(cc);
if (cc->cc_persist_id != NULL)
free (cc->cc_persist_id);
free(cc);
}
clicon_ptr_del(h, "confirmed-commit-struct");
return 0;
@ -136,7 +136,7 @@ confirmed_commit_state_get(clicon_handle h)
static int
confirmed_commit_state_set(clicon_handle h,
enum confirmed_commit_state state)
enum confirmed_commit_state state)
{
struct confirmed_commit *cc = NULL;
@ -156,21 +156,21 @@ confirmed_commit_persist_id_get(clicon_handle h)
static int
confirmed_commit_persist_id_set(clicon_handle h,
char *persist_id)
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);
free(cc->cc_persist_id);
if (persist_id){
if ((cc->cc_persist_id = strdup4(persist_id)) == NULL){
clicon_err(OE_UNIX, errno, "strdup4");
return -1;
}
if ((cc->cc_persist_id = strdup4(persist_id)) == NULL){
clicon_err(OE_UNIX, errno, "strdup4");
return -1;
}
}
else
cc->cc_persist_id = NULL;
cc->cc_persist_id = NULL;
return 0;
}
@ -185,7 +185,7 @@ confirmed_commit_session_id_get(clicon_handle h)
static int
confirmed_commit_session_id_set(clicon_handle h,
uint32_t session_id)
uint32_t session_id)
{
struct confirmed_commit *cc = NULL;
@ -196,8 +196,8 @@ confirmed_commit_session_id_set(clicon_handle h,
static int
confirmed_commit_fn_arg_get(clicon_handle h,
int (**fn)(int, void*),
void **arg)
int (**fn)(int, void*),
void **arg)
{
struct confirmed_commit *cc = NULL;
@ -209,8 +209,8 @@ confirmed_commit_fn_arg_get(clicon_handle h,
static int
confirmed_commit_fn_arg_set(clicon_handle h,
int (*fn)(int, void*),
void *arg)
int (*fn)(int, void*),
void *arg)
{
struct confirmed_commit *cc = NULL;
@ -239,13 +239,13 @@ xe_confirmed(cxobj *xe)
*/
static int
xe_persist(cxobj *xe,
char **str)
char **str)
{
cxobj *xml;
if ((xml = xml_find_type(xe, NULL, "persist", CX_ELMNT)) != NULL){
*str = xml_body(xml);
return 1;
*str = xml_body(xml);
return 1;
}
*str = NULL;
return 0;
@ -260,13 +260,13 @@ xe_persist(cxobj *xe,
*/
static int
xe_persist_id(cxobj *xe,
char **str)
char **str)
{
cxobj *xml;
if ((xml = xml_find_type(xe, NULL, "persist-id", CX_ELMNT)) != NULL){
*str = xml_body(xml);
return 1;
*str = xml_body(xml);
return 1;
}
*str = NULL;
return 0;
@ -283,8 +283,8 @@ xe_timeout(cxobj *xe)
char *str;
if ((xml = xml_find_type(xe, NULL, "confirm-timeout", CX_ELMNT)) != NULL &&
(str = xml_body(xml)) != NULL)
return strtoul(str, NULL, 10);
(str = xml_body(xml)) != NULL)
return strtoul(str, NULL, 10);
return 0;
}
@ -382,14 +382,14 @@ cancel_confirmed_commit(clicon_handle h)
cancel_rollback_event(h);
if (confirmed_commit_state_get(h) == PERSISTENT &&
confirmed_commit_persist_id_get(h) != NULL) {
confirmed_commit_persist_id_set(h, NULL);
confirmed_commit_persist_id_get(h) != NULL) {
confirmed_commit_persist_id_set(h, NULL);
}
confirmed_commit_state_set(h, INACTIVE);
if (xmldb_delete(h, "rollback") < 0)
clicon_err(OE_DB, 0, "Error deleting the rollback configuration");
clicon_err(OE_DB, 0, "Error deleting the rollback configuration");
return 0;
}
@ -409,34 +409,34 @@ cancel_confirmed_commit(clicon_handle h)
*/
static int
check_valid_confirming_commit(clicon_handle h,
cxobj *xe,
cxobj *xe,
uint32_t myid)
{
int retval = -1;
char *persist_id = NULL;
if (xe == NULL){
clicon_err(OE_CFG, EINVAL, "xe is NULL");
goto done;
clicon_err(OE_CFG, EINVAL, "xe is NULL");
goto done;
}
switch (confirmed_commit_state_get(h)) {
case PERSISTENT:
if (xe_persist_id(xe, &persist_id)) {
if (clicon_strcmp(persist_id, confirmed_commit_persist_id_get(h)) == 0) {
if (clicon_strcmp(persist_id, confirmed_commit_persist_id_get(h)) == 0) {
/* the RPC included a <persist-id> matching the prior confirming-commit's <persist> */
break; // valid
}
else {
else {
clicon_log(LOG_INFO,
"a persistent confirmed-commit is in progress but the client issued a "
"confirming-commit with an incorrect persist-id");
goto invalid;
goto invalid;
}
} else {
clicon_log(LOG_INFO,
"a persistent confirmed-commit is in progress but the client issued a confirming-commit"
"without a persist-id");
goto invalid;
goto invalid;
}
case EPHEMERAL:
if (myid == confirmed_commit_session_id_get(h)) {
@ -447,10 +447,10 @@ check_valid_confirming_commit(clicon_handle h,
}
clicon_log(LOG_DEBUG, "an ephemeral confirmed-commit is in progress, but there confirming-commit was"
"not issued on the same session as the confirmed-commit");
goto invalid;
goto invalid;
default:
clicon_debug(1, "commit-confirmed state !? %d", confirmed_commit_state_get(h));
goto invalid;
goto invalid;
}
retval = 1; // valid
done:
@ -475,7 +475,7 @@ check_valid_confirming_commit(clicon_handle h,
*/
int
handle_confirmed_commit(clicon_handle h,
cxobj *xe)
cxobj *xe)
{
int retval = -1;
uint32_t session_id;
@ -485,13 +485,13 @@ handle_confirmed_commit(clicon_handle h,
int db_exists;
if (xe == NULL){
clicon_err(OE_CFG, EINVAL, "xe is NULL");
clicon_err(OE_CFG, EINVAL, "xe is NULL");
goto done;
}
if (clicon_session_id_get(h, &session_id) < 0) {
clicon_err(OE_DAEMON, 0,
"an ephemeral confirmed-commit was issued, but the session-id could not be determined");
goto done;
clicon_err(OE_DAEMON, 0,
"an ephemeral confirmed-commit was issued, but the session-id could not be determined");
goto done;
};
/* The case of a valid confirming-commit is also handled in the first phase, but only if there is no subsequent
* confirmed-commit. It is tested again here as the case of a valid confirming-commit *with* a subsequent
@ -505,45 +505,45 @@ handle_confirmed_commit(clicon_handle h,
}
if (confirmed_commit_state_get(h) == PERSISTENT &&
confirmed_commit_persist_id_get(h) != NULL) {
confirmed_commit_persist_id_set(h, NULL);
confirmed_commit_persist_id_get(h) != NULL) {
confirmed_commit_persist_id_set(h, NULL);
}
confirmed_commit_state_set(h, INACTIVE);
confirmed_commit_state_set(h, INACTIVE);
}
/* Now, determine if there is a subsequent confirmed-commit */
if (xe_confirmed(xe)){
/* There is, get it's confirm-timeout value, which will default per the yang schema if not client-specified */
/* Clixon also pre-validates input according to the schema, so bounds checking here is redundant */
confirm_timeout = xe_timeout(xe);
if (xe_persist(xe, &persist)){
confirm_timeout = xe_timeout(xe);
if (xe_persist(xe, &persist)){
if (persist == NULL) {
confirmed_commit_persist_id_set(h, NULL);
confirmed_commit_persist_id_set(h, NULL);
}
else if (confirmed_commit_persist_id_set(h, persist) < 0){
else if (confirmed_commit_persist_id_set(h, persist) < 0){
goto done;
}
/* The client has passed <persist>; the confirming-commit MUST now be accompanied by a matching
* <persist-id>
*/
confirmed_commit_state_set(h, PERSISTENT);
confirmed_commit_state_set(h, PERSISTENT);
clicon_log(LOG_INFO,
"a persistent confirmed-commit has been requested with persist id of '%s' and a timeout of %lu seconds",
confirmed_commit_persist_id_get(h), confirm_timeout);
}
else {
else {
/* The client did not pass a value for <persist> and therefore any subsequent confirming-commit must be
* issued within the same session.
*/
confirmed_commit_session_id_set(h, session_id);
confirmed_commit_state_set(h, EPHEMERAL);
confirmed_commit_session_id_set(h, session_id);
confirmed_commit_state_set(h, EPHEMERAL);
clicon_log(LOG_INFO,
"an ephemeral confirmed-commit has been requested by session-id %u and a timeout of %lu seconds",
confirmed_commit_session_id_get(h),
confirmed_commit_session_id_get(h),
confirm_timeout);
}
@ -627,7 +627,7 @@ handle_confirmed_commit(clicon_handle h,
*/
int
do_rollback(clicon_handle h,
uint8_t *errs)
uint8_t *errs)
{
int retval = -1;
uint8_t errstate = 0;
@ -646,8 +646,8 @@ do_rollback(clicon_handle h,
}
if (confirmed_commit_state_get(h) == PERSISTENT &&
confirmed_commit_persist_id_get(h) != NULL) {
confirmed_commit_persist_id_set(h, NULL);
confirmed_commit_persist_id_get(h) != NULL) {
confirmed_commit_persist_id_set(h, NULL);
}
confirmed_commit_state_set(h, ROLLBACK);
if (candidate_commit(h, NULL, "rollback", cbret) < 0) { /* Assume validation fail, nofatal */
@ -708,10 +708,10 @@ do_rollback(clicon_handle h,
*/
int
from_client_cancel_commit(clicon_handle h,
cxobj *xe,
cbuf *cbret,
void *arg,
void *regarg)
cxobj *xe,
cbuf *cbret,
void *arg,
void *regarg)
{
cxobj *persist_id_xml;
char *persist_id = NULL;
@ -737,37 +737,37 @@ from_client_cancel_commit(clicon_handle h,
if (netconf_invalid_value(cbret, "protocol", "confirming-commit must be given within session that gave the confirmed-commit") < 0)
goto done;
}
else
rollback++;
break;
else
rollback++;
break;
case PERSISTENT:
if (persist_id_xml == NULL) {
if (netconf_invalid_value(cbret, "protocol", "persist-id is required") < 0)
goto done;
}
else if (clicon_strcmp(persist_id, confirmed_commit_persist_id_get(h)) != 0){
if (netconf_invalid_value(cbret, "application", "a confirmed-commit with the given persist-id was not found") < 0)
goto done;
}
else
rollback++;
break;
else if (clicon_strcmp(persist_id, confirmed_commit_persist_id_get(h)) != 0){
if (netconf_invalid_value(cbret, "application", "a confirmed-commit with the given persist-id was not found") < 0)
goto done;
}
else
rollback++;
break;
case INACTIVE:
if (netconf_invalid_value(cbret, "application", "no confirmed-commit is in progress") < 0)
goto done;
break;
break;
default:
if (netconf_invalid_value(cbret, "application", "server error") < 0)
goto done;
break;
break;
}
/* all invalid conditions jump to done: and valid code paths jump to or fall through to here. */
if (rollback){
cancel_rollback_event(h);
if (do_rollback(h, NULL) < 0)
goto done;
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE);
clicon_log(LOG_INFO, "a confirmed-commit has been cancelled by client request");
goto done;
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE);
clicon_log(LOG_INFO, "a confirmed-commit has been cancelled by client request");
}
retval = 0;
done:
@ -785,20 +785,20 @@ from_client_cancel_commit(clicon_handle h,
*/
int
from_client_confirmed_commit(clicon_handle h,
cxobj *xe,
uint32_t myid,
cbuf *cbret)
cxobj *xe,
uint32_t myid,
cbuf *cbret)
{
int retval = -1;
int cc_valid;
if ((cc_valid = check_valid_confirming_commit(h, xe, myid)) < 0)
goto done;
goto done;
/* If <confirmed/> is *not* present, this will conclude the confirmed-commit, so cancel the rollback. */
if (!xe_confirmed(xe) && cc_valid) {
cancel_confirmed_commit(h);
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE);
goto dontcommit;
cancel_confirmed_commit(h);
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE);
goto dontcommit;
}
retval = 1;
done:

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -74,27 +74,27 @@
*/
int
clixon_plugin_reset_one(clixon_plugin_t *cp,
clicon_handle h,
char *db)
clicon_handle h,
char *db)
{
int retval = -1;
plgreset_t *fn; /* callback */
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_reset) != NULL){
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h, db) < 0) {
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
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;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h, db) < 0) {
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
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;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
retval = 0;
done:
@ -110,7 +110,7 @@ clixon_plugin_reset_one(clixon_plugin_t *cp,
*/
int
clixon_plugin_reset_all(clicon_handle h,
char *db)
char *db)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
@ -118,8 +118,8 @@ clixon_plugin_reset_all(clicon_handle h,
clicon_debug(1, "%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)
goto done;
if (clixon_plugin_reset_one(cp, h, db) < 0)
goto done;
}
retval = 0;
done:
@ -141,20 +141,20 @@ clixon_plugin_pre_daemon_one(clixon_plugin_t *cp,
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_pre_daemon) != NULL){
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h) < 0) {
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: Pre-daemon callback in plugin:\
%s returned -1 but did not make a clicon_err call",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
retval = 0;
done:
@ -195,26 +195,26 @@ clixon_plugin_pre_daemon_all(clicon_handle h)
*/
static int
clixon_plugin_daemon_one(clixon_plugin_t *cp,
clicon_handle h)
clicon_handle h)
{
int retval = -1;
plgdaemon_t *fn; /* Daemonize plugin callback function */
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_daemon) != NULL){
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h) < 0) {
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
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;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h) < 0) {
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
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;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
retval = 0;
done:
@ -241,8 +241,8 @@ clixon_plugin_daemon_all(clicon_handle h)
clicon_debug(1, "%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)
goto done;
if (clixon_plugin_daemon_one(cp, h) < 0)
goto done;
}
retval = 0;
done:
@ -276,10 +276,10 @@ clixon_plugin_daemon_all(clicon_handle h)
*/
static int
clixon_plugin_statedata_one(clixon_plugin_t *cp,
clicon_handle h,
cvec *nsc,
char *xpath,
cxobj **xp)
clicon_handle h,
cvec *nsc,
char *xpath,
cxobj **xp)
{
int retval = -1;
plgstatedata_t *fn; /* Plugin statedata fn */
@ -287,24 +287,24 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
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;
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
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)
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 */
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if ((x = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
goto done;
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
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)
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 */
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
if (xp && x)
*xp = x;
*xp = x;
retval = 1;
done:
return retval;
@ -332,10 +332,10 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
*/
int
clixon_plugin_statedata_all(clicon_handle h,
yang_stmt *yspec,
cvec *nsc,
char *xpath,
cxobj **xret)
yang_stmt *yspec,
cvec *nsc,
char *xpath,
cxobj **xret)
{
int retval = -1;
int ret;
@ -346,69 +346,69 @@ clixon_plugin_statedata_all(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if ((ret = clixon_plugin_statedata_one(cp, h, nsc, xpath, &x)) < 0)
goto done;
if (ret == 0){
if ((cberr = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
/* error reason should be in clicon_err_reason */
cprintf(cberr, "Internal error, state callback in plugin %s returned invalid XML: %s",
clixon_plugin_name_get(cp), clicon_err_reason);
if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0)
goto done;
xml_free(*xret);
*xret = xerr;
xerr = NULL;
goto fail;
}
if (x == NULL)
continue;
if (xml_child_nr(x) == 0){
xml_free(x);
x = NULL;
continue;
}
if (clicon_debug_get())
clicon_log_xml(LOG_DEBUG, 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(x, YB_MODULE, yspec, &xerr)) < 0)
goto done;
if (ret == 0){
if (clixon_netconf_internal_error(xerr,
". Internal error, state callback returned invalid XML from plugin: ",
clixon_plugin_name_get(cp)) < 0)
goto done;
xml_free(*xret);
*xret = xerr;
xerr = NULL;
goto fail;
}
if (xml_sort_recurse(x) < 0)
goto done;
/* Remove global defaults and empty non-presence containers */
if (xml_defaults_nopresence(x, 2) < 0)
goto done;
if (xml_default_recurse(x, 1) < 0)
goto done;
if ((ret = netconf_trymerge(x, yspec, xret)) < 0)
goto done;
if (ret == 0)
goto fail;
if (x){
xml_free(x);
x = NULL;
}
if ((ret = clixon_plugin_statedata_one(cp, h, nsc, xpath, &x)) < 0)
goto done;
if (ret == 0){
if ((cberr = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
/* error reason should be in clicon_err_reason */
cprintf(cberr, "Internal error, state callback in plugin %s returned invalid XML: %s",
clixon_plugin_name_get(cp), clicon_err_reason);
if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0)
goto done;
xml_free(*xret);
*xret = xerr;
xerr = NULL;
goto fail;
}
if (x == NULL)
continue;
if (xml_child_nr(x) == 0){
xml_free(x);
x = NULL;
continue;
}
if (clicon_debug_get())
clicon_log_xml(LOG_DEBUG, 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(x, YB_MODULE, yspec, &xerr)) < 0)
goto done;
if (ret == 0){
if (clixon_netconf_internal_error(xerr,
". Internal error, state callback returned invalid XML from plugin: ",
clixon_plugin_name_get(cp)) < 0)
goto done;
xml_free(*xret);
*xret = xerr;
xerr = NULL;
goto fail;
}
if (xml_sort_recurse(x) < 0)
goto done;
/* Remove global defaults and empty non-presence containers */
if (xml_defaults_nopresence(x, 2) < 0)
goto done;
if (xml_default_recurse(x, 1) < 0)
goto done;
if ((ret = netconf_trymerge(x, yspec, xret)) < 0)
goto done;
if (ret == 0)
goto fail;
if (x){
xml_free(x);
x = NULL;
}
} /* while plugin */
retval = 1;
done:
if (xerr)
xml_free(xerr);
xml_free(xerr);
if (cberr)
cbuf_free(cberr);
cbuf_free(cberr);
if (x)
xml_free(x);
xml_free(x);
return retval;
fail:
retval = 0;
@ -426,23 +426,23 @@ clixon_plugin_statedata_all(clicon_handle h,
*/
static int
clixon_plugin_lockdb_one(clixon_plugin_t *cp,
clicon_handle h,
char *db,
int lock,
int id)
clicon_handle h,
char *db,
int lock,
int id)
{
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;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
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;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
retval = 0;
done:
@ -459,10 +459,10 @@ clixon_plugin_lockdb_one(clixon_plugin_t *cp,
*/
int
clixon_plugin_lockdb_all(clicon_handle h,
char *db,
int lock,
int id
)
char *db,
int lock,
int id
)
{
int retval = -1;
@ -470,8 +470,8 @@ clixon_plugin_lockdb_all(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (clixon_plugin_lockdb_one(cp, h, db, lock, id) < 0)
goto done;
if (clixon_plugin_lockdb_one(cp, h, db, lock, id) < 0)
goto done;
}
retval = 0;
done:
@ -485,11 +485,11 @@ clixon_plugin_lockdb_all(clicon_handle h,
*/
int
clixon_pagination_cb_call(clicon_handle h,
char *xpath,
int locked,
uint32_t offset,
uint32_t limit,
cxobj *xstate)
char *xpath,
int locked,
uint32_t offset,
uint32_t limit,
cxobj *xstate)
{
int retval = -1;
pagination_data_t pd;
@ -501,7 +501,7 @@ clixon_pagination_cb_call(clicon_handle h,
pd.pd_xstate = xstate;
clicon_ptr_get(h, "pagination-entries", (void**)&htable);
if (htable && dispatcher_call_handlers(htable, h, xpath, &pd) < 0)
goto done;
goto done;
retval = 1;
done:
return retval;
@ -516,9 +516,9 @@ clixon_pagination_cb_call(clicon_handle h,
*/
int
clixon_pagination_cb_register(clicon_handle h,
handler_function fn,
char *xpath,
void *arg)
handler_function fn,
char *xpath,
void *arg)
{
int retval = -1;
dispatcher_definition x = {xpath, fn, arg};
@ -526,11 +526,11 @@ clixon_pagination_cb_register(clicon_handle h,
clicon_ptr_get(h, "pagination-entries", (void**)&htable);
if (dispatcher_register_handler(&htable, &x) < 0){
clicon_err(OE_PLUGIN, errno, "dispatcher");
goto done;
clicon_err(OE_PLUGIN, errno, "dispatcher");
goto done;
}
if (clicon_ptr_set(h, "pagination-entries", htable) < 0)
goto done;
goto done;
retval = 0;
done:
return retval;
@ -547,7 +547,7 @@ clixon_pagination_free(clicon_handle h)
clicon_ptr_get(h, "pagination-entries", (void**)&htable);
if (htable)
dispatcher_free(htable);
dispatcher_free(htable);
return 0;
}
@ -563,8 +563,8 @@ transaction_new(void)
static uint64_t id = 0; /* Global transaction id */
if ((td = malloc(sizeof(*td))) == NULL){
clicon_err(OE_CFG, errno, "malloc");
return NULL;
clicon_err(OE_CFG, errno, "malloc");
return NULL;
}
memset(td, 0, sizeof(*td));
td->td_id = id++;
@ -579,17 +579,17 @@ int
transaction_free(transaction_data_t *td)
{
if (td->td_src)
xml_free(td->td_src);
xml_free(td->td_src);
if (td->td_target)
xml_free(td->td_target);
xml_free(td->td_target);
if (td->td_dvec)
free(td->td_dvec);
free(td->td_dvec);
if (td->td_avec)
free(td->td_avec);
free(td->td_avec);
if (td->td_scvec)
free(td->td_scvec);
free(td->td_scvec);
if (td->td_tcvec)
free(td->td_tcvec);
free(td->td_tcvec);
free(td);
return 0;
}
@ -603,27 +603,27 @@ transaction_free(transaction_data_t *td)
*/
int
plugin_transaction_begin_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
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)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
retval = 0;
done:
@ -640,15 +640,15 @@ plugin_transaction_begin_one(clixon_plugin_t *cp,
*/
int
plugin_transaction_begin_all(clicon_handle h,
transaction_data_t *td)
transaction_data_t *td)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(1, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_begin_one(cp, h, td) < 0)
goto done;
if (plugin_transaction_begin_one(cp, h, td) < 0)
goto done;
}
retval = 0;
done:
@ -664,28 +664,28 @@ plugin_transaction_begin_all(clicon_handle h,
*/
int
plugin_transaction_validate_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
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_validate) != NULL){
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
retval = 0;
done:
@ -699,15 +699,15 @@ plugin_transaction_validate_one(clixon_plugin_t *cp,
* @retval -1 Error: one of the plugin callbacks returned validation fail
*/
int
plugin_transaction_validate_all(clicon_handle h,
transaction_data_t *td)
plugin_transaction_validate_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_validate_one(cp, h, td) < 0)
goto done;
if (plugin_transaction_validate_one(cp, h, td) < 0)
goto done;
}
retval = 0;
done:
@ -724,27 +724,27 @@ plugin_transaction_validate_all(clicon_handle h,
*/
int
plugin_transaction_complete_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
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)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
retval = 0;
done:
@ -761,14 +761,14 @@ plugin_transaction_complete_one(clixon_plugin_t *cp,
*/
int
plugin_transaction_complete_all(clicon_handle h,
transaction_data_t *td)
transaction_data_t *td)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_complete_one(cp, h, td) < 0)
goto done;
if (plugin_transaction_complete_one(cp, h, td) < 0)
goto done;
}
retval = 0;
done:
@ -786,21 +786,21 @@ plugin_transaction_complete_all(clicon_handle h,
*/
static int
plugin_transaction_revert_all(clicon_handle h,
transaction_data_t *td,
int nr)
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",
__FUNCTION__, clixon_plugin_name_get(cp));
break;
}
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",
__FUNCTION__, clixon_plugin_name_get(cp));
break;
}
}
return retval; /* ignore errors */
}
@ -815,27 +815,27 @@ plugin_transaction_revert_all(clicon_handle h,
*/
int
plugin_transaction_commit_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
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)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
retval = 0;
done:
@ -853,19 +853,19 @@ plugin_transaction_commit_one(clixon_plugin_t *cp,
*/
int
plugin_transaction_commit_all(clicon_handle h,
transaction_data_t *td)
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);
goto done;
}
i++;
if (plugin_transaction_commit_one(cp, h, td) < 0){
/* Make an effort to revert transaction */
plugin_transaction_revert_all(h, td, i-1);
goto done;
}
}
retval = 0;
done:
@ -881,27 +881,27 @@ plugin_transaction_commit_all(clicon_handle h,
*/
int
plugin_transaction_commit_done_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
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)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
retval = 0;
done:
@ -917,14 +917,14 @@ plugin_transaction_commit_done_one(clixon_plugin_t *cp,
*/
int
plugin_transaction_commit_done_all(clicon_handle h,
transaction_data_t *td)
transaction_data_t *td)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_commit_done_one(cp, h, td) < 0)
goto done;
if (plugin_transaction_commit_done_one(cp, h, td) < 0)
goto done;
}
retval = 0;
done:
@ -940,27 +940,27 @@ plugin_transaction_commit_done_all(clicon_handle h,
*/
int
plugin_transaction_end_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
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)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
retval = 0;
done:
@ -975,15 +975,15 @@ plugin_transaction_end_one(clixon_plugin_t *cp,
*/
int
plugin_transaction_end_all(clicon_handle h,
transaction_data_t *td)
transaction_data_t *td)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(1, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_end_one(cp, h, td) < 0)
goto done;
if (plugin_transaction_end_one(cp, h, td) < 0)
goto done;
}
retval = 0;
done:
@ -992,27 +992,27 @@ plugin_transaction_end_all(clicon_handle h,
int
plugin_transaction_abort_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
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)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h, (transaction_data)td) < 0){
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",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
retval = 0;
done:
@ -1027,15 +1027,15 @@ plugin_transaction_abort_one(clixon_plugin_t *cp,
*/
int
plugin_transaction_abort_all(clicon_handle h,
transaction_data_t *td)
transaction_data_t *td)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(1, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_abort_one(cp, h, td) < 0)
; /* dont abort on error */
if (plugin_transaction_abort_one(cp, h, td) < 0)
; /* dont abort on error */
}
retval = 0;
return retval;

View file

@ -73,7 +73,7 @@
*/
static int
restconf_pseudo_set_log(clicon_handle h,
cxobj *xt)
cxobj *xt)
{
int retval = -1;
char **argv;
@ -84,47 +84,47 @@ restconf_pseudo_set_log(clicon_handle h,
cxobj *xb;
if ((xb = xpath_first(xt, NULL, "/restconf/log-destination")) != NULL)
log = xml_body(xb);
log = xml_body(xb);
if ((xb = xpath_first(xt, NULL, "/restconf/debug")) != NULL)
dbg = xml_body(xb);
dbg = xml_body(xb);
if (dbg == NULL && log == NULL)
goto ok;
goto ok;
if (clixon_process_argv_get(h, RESTCONF_PROCESS, &argv, &argc) < 0)
goto done;
goto done;
for (i=0; i<argc; i++){
if (argv[i] == NULL)
break;
if (strcmp(argv[i], "-l") == 0 && argc > i+1 && argv[i+1]){
if (log){
if (strcmp(log, "syslog") == 0){
if (argv[i+1])
free(argv[i+1]);
if ((argv[i+1] = strdup("s")) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
}
else if (strcmp(log, "file") == 0){
if (argv[i+1])
free(argv[i+1]);
if ((argv[i+1] = strdup("f/var/log/clixon_restconf.log")) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
}
}
i++;
}
if (strcmp(argv[i], "-D") == 0 && argc > i+1 && argv[i+1]){
if (dbg){
free(argv[i+1]);
if ((argv[i+1] = strdup(dbg)) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
}
i++;
}
if (argv[i] == NULL)
break;
if (strcmp(argv[i], "-l") == 0 && argc > i+1 && argv[i+1]){
if (log){
if (strcmp(log, "syslog") == 0){
if (argv[i+1])
free(argv[i+1]);
if ((argv[i+1] = strdup("s")) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
}
else if (strcmp(log, "file") == 0){
if (argv[i+1])
free(argv[i+1]);
if ((argv[i+1] = strdup("f/var/log/clixon_restconf.log")) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
}
}
i++;
}
if (strcmp(argv[i], "-D") == 0 && argc > i+1 && argv[i+1]){
if (dbg){
free(argv[i+1]);
if ((argv[i+1] = strdup(dbg)) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
}
i++;
}
}
ok:
retval = 0;
@ -141,7 +141,7 @@ restconf_pseudo_set_log(clicon_handle h,
*/
static int
restconf_pseudo_set_inline(clicon_handle h,
cxobj *xt)
cxobj *xt)
{
int retval = -1;
char **argv;
@ -153,33 +153,33 @@ restconf_pseudo_set_inline(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_process_argv_get(h, RESTCONF_PROCESS, &argv, &argc) < 0)
goto done;
goto done;
if ((xrestconf = xpath_first(xt, NULL, "restconf")) != NULL)
for (i=0; i<argc; i++){
if (argv[i] == NULL)
break;
if (strcmp(argv[i], "-R") == 0 && argc > i+1 && argv[i+1]){
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (clixon_xml2cbuf(cb, xrestconf, 0, 0, -1, 0) < 0)
goto done;
if ((str = strdup(cbuf_get(cb))) == NULL){
clicon_err(OE_XML, errno, "stdup");
goto done;
}
clicon_debug(1, "%s str:%s", __FUNCTION__, str);
if (argv[i+1])
free(argv[i+1]);
argv[i+1] = str;
break;
}
}
for (i=0; i<argc; i++){
if (argv[i] == NULL)
break;
if (strcmp(argv[i], "-R") == 0 && argc > i+1 && argv[i+1]){
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (clixon_xml2cbuf(cb, xrestconf, 0, 0, -1, 0) < 0)
goto done;
if ((str = strdup(cbuf_get(cb))) == NULL){
clicon_err(OE_XML, errno, "stdup");
goto done;
}
clicon_debug(1, "%s str:%s", __FUNCTION__, str);
if (argv[i+1])
free(argv[i+1]);
argv[i+1] = str;
break;
}
}
retval = 0;
done:
if (cb)
cbuf_free(cb);
cbuf_free(cb);
return retval;
}
@ -190,8 +190,8 @@ restconf_pseudo_set_inline(clicon_handle h,
*/
int
restconf_rpc_wrapper(clicon_handle h,
process_entry_t *pe,
proc_operation *operation)
process_entry_t *pe,
proc_operation *operation)
{
int retval = -1;
cxobj *xt = NULL;
@ -199,36 +199,36 @@ restconf_rpc_wrapper(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
switch (*operation){
case PROC_OP_STOP:
/* if RPC op is stop, stop the service */
break;
/* 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;
if (xt != NULL &&
xpath_first(xt, NULL, "/restconf[enable='false']") != NULL) {
*operation = PROC_OP_NONE;
}
else{
/* Get debug flag of restconf config, set the restconf start -D daemon flag according
* to it. The restconf daemon cannoit read its debug flag from config initially,
* but in this way it is set directly in its input args.
* Its a trick.
*/
if (restconf_pseudo_set_log(h, xt) < 0)
goto done;
if (restconf_pseudo_set_inline(h, xt) < 0)
goto done;
}
break;
if (xmldb_get(h, "running", NULL, "/restconf", &xt) < 0)
goto done;
if (xt != NULL &&
xpath_first(xt, NULL, "/restconf[enable='false']") != NULL) {
*operation = PROC_OP_NONE;
}
else{
/* Get debug flag of restconf config, set the restconf start -D daemon flag according
* to it. The restconf daemon cannoit read its debug flag from config initially,
* but in this way it is set directly in its input args.
* Its a trick.
*/
if (restconf_pseudo_set_log(h, xt) < 0)
goto done;
if (restconf_pseudo_set_inline(h, xt) < 0)
goto done;
}
break;
default:
break;
break;
}
retval = 0;
done:
if (xt)
xml_free(xt);
xml_free(xt);
return retval;
}
@ -255,13 +255,13 @@ restconf_pseudo_process_control(clicon_handle h)
nr = 10;
if ((argv = calloc(nr, sizeof(char *))) == NULL){
clicon_err(OE_UNIX, errno, "calloc");
goto done;
clicon_err(OE_UNIX, errno, "calloc");
goto done;
}
i = 0;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
/* Try to figure out where clixon_restconf is installed
* If config option CLICON_RESTCONF_INSTALLDIR is installed, use that.
@ -269,32 +269,32 @@ restconf_pseudo_process_control(clicon_handle h)
* Use PATH?
*/
if ((dir0 = clicon_option_str(h, "CLICON_RESTCONF_INSTALLDIR")) != NULL){
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);
found++;
}
else
clicon_debug(1, "Not found: %s", pgm);
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);
found++;
}
else
clicon_debug(1, "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);
if (stat(pgm, &fstat) == 0){ /* Sanity check: program exists */
clicon_debug(1, "Found %s", pgm);
found++;
}
else
clicon_debug(1, "Not found: %s", pgm);
(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);
if (stat(pgm, &fstat) == 0){ /* Sanity check: program exists */
clicon_debug(1, "Found %s", pgm);
found++;
}
else
clicon_debug(1, "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",
dir0, dir1);
goto done;
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",
dir0, dir1);
goto done;
}
argv[i++] = pgm;
argv[i++] = "-f";
@ -312,17 +312,17 @@ restconf_pseudo_process_control(clicon_handle h)
argv[i++] = NULL;
assert(i==nr);
if (clixon_process_register(h, RESTCONF_PROCESS,
"Clixon RESTCONF process",
NULL /* XXX network namespace */,
restconf_rpc_wrapper,
argv, nr) < 0)
goto done;
"Clixon RESTCONF process",
NULL /* XXX network namespace */,
restconf_rpc_wrapper,
argv, nr) < 0)
goto done;
if (argv != NULL)
free(argv);
free(argv);
retval = 0;
done:
if (cb)
cbuf_free(cb);
cbuf_free(cb);
return retval;
}
@ -330,7 +330,7 @@ restconf_pseudo_process_control(clicon_handle h)
*/
static int
restconf_pseudo_process_validate(clicon_handle h,
transaction_data td)
transaction_data td)
{
int retval = -1;
cxobj *xtarget;
@ -340,16 +340,16 @@ restconf_pseudo_process_validate(clicon_handle h,
/* If ssl-enable is true and (at least a) socket has ssl,
* then server-cert-path and server-key-path must exist */
if (xpath_first(xtarget, NULL, "restconf/enable[.='true']") &&
xpath_first(xtarget, NULL, "restconf/socket[ssl='true']")){
/* Should filepath be checked? One could claim this is a runtime system,... */
if (xpath_first(xtarget, 0, "restconf/server-cert-path") == NULL){
clicon_err(OE_CFG, 0, "SSL enabled but server-cert-path not set");
return -1; /* induce fail */
}
if (xpath_first(xtarget, 0, "restconf/server-key-path") == NULL){
clicon_err(OE_CFG, 0, "SSL enabled but server-key-path not set");
return -1; /* induce fail */
}
xpath_first(xtarget, NULL, "restconf/socket[ssl='true']")){
/* Should filepath be checked? One could claim this is a runtime system,... */
if (xpath_first(xtarget, 0, "restconf/server-cert-path") == NULL){
clicon_err(OE_CFG, 0, "SSL enabled but server-cert-path not set");
return -1; /* induce fail */
}
if (xpath_first(xtarget, 0, "restconf/server-key-path") == NULL){
clicon_err(OE_CFG, 0, "SSL enabled but server-key-path not set");
return -1; /* induce fail */
}
}
retval = 0;
return retval;
@ -359,7 +359,7 @@ restconf_pseudo_process_validate(clicon_handle h,
*/
static int
restconf_pseudo_process_commit(clicon_handle h,
transaction_data td)
transaction_data td)
{
int retval = -1;
cxobj *xtarget;
@ -371,45 +371,45 @@ restconf_pseudo_process_commit(clicon_handle h,
xtarget = transaction_target(td);
xsource = transaction_src(td);
if (xpath_first(xtarget, NULL, "/restconf[enable='true']") != NULL)
enabled++;
enabled++;
/* Get debug flag of restconf config, set the restconf start -D daemon flag according
* to it. The restconf daemon cannoit read its debug flag from config initially,
* but in this way it is set directly in its input args.
* Its a trick.
*/
if (restconf_pseudo_set_log(h, xtarget) < 0)
goto done;
goto done;
if (restconf_pseudo_set_inline(h, xtarget) < 0)
goto done;
goto done;
/* Toggle start/stop if enable flag changed */
if ((cx = xpath_first(xtarget, NULL, "/restconf/enable")) != NULL &&
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_ADD)){
if (clixon_process_operation(h, RESTCONF_PROCESS,
enabled?PROC_OP_START:PROC_OP_STOP, 0) < 0)
goto done;
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_ADD)){
if (clixon_process_operation(h, RESTCONF_PROCESS,
enabled?PROC_OP_START:PROC_OP_STOP, 0) < 0)
goto done;
}
else if (enabled){ /* If something changed and running, restart process */
if (transaction_dlen(td) != 0 ||
transaction_alen(td) != 0 ||
transaction_clen(td) != 0){
if ((cx = xpath_first(xtarget, NULL, "/restconf")) != NULL &&
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_ADD)){
/* A restart can terminate a restconf connection (cut the tree limb you are sitting on)
* Specifically, the socket is terminated where the reply is sent, which will
* cause the curl to fail.
* Note that it should really be a START if the process is stopped, but the
* commit code need not know any of that
*/
if (clixon_process_operation(h, RESTCONF_PROCESS, PROC_OP_RESTART, 0) < 0)
goto done;
}
else if ((cx = xpath_first(xsource, NULL, "/restconf")) != NULL &&
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_DEL)){
/* Or something deleted */
if (clixon_process_operation(h, RESTCONF_PROCESS, PROC_OP_RESTART, 0) < 0)
goto done;
}
}
if (transaction_dlen(td) != 0 ||
transaction_alen(td) != 0 ||
transaction_clen(td) != 0){
if ((cx = xpath_first(xtarget, NULL, "/restconf")) != NULL &&
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_ADD)){
/* A restart can terminate a restconf connection (cut the tree limb you are sitting on)
* Specifically, the socket is terminated where the reply is sent, which will
* cause the curl to fail.
* Note that it should really be a START if the process is stopped, but the
* commit code need not know any of that
*/
if (clixon_process_operation(h, RESTCONF_PROCESS, PROC_OP_RESTART, 0) < 0)
goto done;
}
else if ((cx = xpath_first(xsource, NULL, "/restconf")) != NULL &&
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_DEL)){
/* Or something deleted */
if (clixon_process_operation(h, RESTCONF_PROCESS, PROC_OP_RESTART, 0) < 0)
goto done;
}
}
}
retval = 0;
done:
@ -421,20 +421,20 @@ restconf_pseudo_process_commit(clicon_handle h,
*/
int
backend_plugin_restconf_register(clicon_handle h,
yang_stmt *yspec)
yang_stmt *yspec)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
if (clixon_pseudo_plugin(h, "restconf pseudo plugin", &cp) < 0)
goto done;
goto done;
clixon_plugin_api_get(cp)->ca_trans_validate = restconf_pseudo_process_validate;
clixon_plugin_api_get(cp)->ca_trans_commit = restconf_pseudo_process_commit;
/* Register generic process-control of restconf daemon, ie start/stop restconf */
if (restconf_pseudo_process_control(h) < 0)
goto done;
goto done;
retval = 0;
done:
return retval;

View file

@ -84,7 +84,7 @@
*/
static int
config_socket_init_ipv4(clicon_handle h,
char *dst)
char *dst)
{
int s;
struct sockaddr_in addr;
@ -95,25 +95,25 @@ config_socket_init_ipv4(clicon_handle h,
/* create inet socket */
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
clicon_err(OE_UNIX, errno, "socket");
return -1;
clicon_err(OE_UNIX, errno, "socket");
return -1;
}
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&one, sizeof(one));
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
if (inet_pton(addr.sin_family, dst, &addr.sin_addr) != 1){
clicon_err(OE_UNIX, errno, "inet_pton: %s (Expected IPv4 address. Check settings of CLICON_SOCK_FAMILY and CLICON_SOCK)", dst);
goto err; /* Could check getaddrinfo */
clicon_err(OE_UNIX, errno, "inet_pton: %s (Expected IPv4 address. Check settings of CLICON_SOCK_FAMILY and CLICON_SOCK)", dst);
goto err; /* Could check getaddrinfo */
}
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0){
clicon_err(OE_UNIX, errno, "bind");
goto err;
clicon_err(OE_UNIX, errno, "bind");
goto err;
}
clicon_debug(1, "Listen on server socket at %s:%hu", dst, port);
if (listen(s, 5) < 0){
clicon_err(OE_UNIX, errno, "listen");
goto err;
clicon_err(OE_UNIX, errno, "listen");
goto err;
}
return s;
err:
@ -132,7 +132,7 @@ config_socket_init_ipv4(clicon_handle h,
*/
static int
config_socket_init_unix(clicon_handle h,
char *sock)
char *sock)
{
int s;
struct sockaddr_un addr;
@ -142,24 +142,24 @@ config_socket_init_unix(clicon_handle h,
struct stat st;
if (lstat(sock, &st) == 0 && unlink(sock) < 0){
clicon_err(OE_UNIX, errno, "unlink(%s)", sock);
return -1;
clicon_err(OE_UNIX, errno, "unlink(%s)", sock);
return -1;
}
/* then find configuration group (for clients) and find its groupid */
if ((config_group = clicon_sock_group(h)) == NULL){
clicon_err(OE_FATAL, 0, "clicon_sock_group option not set");
return -1;
clicon_err(OE_FATAL, 0, "clicon_sock_group option not set");
return -1;
}
if (group_name2gid(config_group, &gid) < 0)
return -1;
return -1;
#if 0
if (gid == 0)
clicon_log(LOG_WARNING, "%s: No such group: %s", __FUNCTION__, config_group);
clicon_log(LOG_WARNING, "%s: No such group: %s", __FUNCTION__, config_group);
#endif
/* create unix socket */
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
clicon_err(OE_UNIX, errno, "socket");
return -1;
clicon_err(OE_UNIX, errno, "socket");
return -1;
}
// setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&one, sizeof(one));
memset(&addr, 0, sizeof(addr));
@ -167,20 +167,20 @@ config_socket_init_unix(clicon_handle h,
strncpy(addr.sun_path, sock, sizeof(addr.sun_path)-1);
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);
goto err;
clicon_err(OE_UNIX, errno, "bind");
umask(old_mask);
goto err;
}
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_err(OE_UNIX, errno, "lchown(%s, %s)", sock, config_group);
goto err;
}
clicon_debug(1, "Listen on server socket at %s", addr.sun_path);
if (listen(s, 5) < 0){
clicon_err(OE_UNIX, errno, "listen");
goto err;
clicon_err(OE_UNIX, errno, "listen");
goto err;
}
return s;
err:
@ -200,20 +200,20 @@ backend_socket_init(clicon_handle h)
char *sock; /* unix path or ip address string */
if ((sock = clicon_sock_str(h)) == NULL){
clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set");
return -1;
clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set");
return -1;
}
switch (clicon_sock_family(h)){
case AF_UNIX:
return config_socket_init_unix(h, sock);
break;
return config_socket_init_unix(h, sock);
break;
case AF_INET:
return config_socket_init_ipv4(h, sock);
break;
return config_socket_init_ipv4(h, sock);
break;
default:
clicon_err(OE_UNIX, EINVAL, "No such address family: %d",
clicon_sock_family(h));
break;
clicon_err(OE_UNIX, EINVAL, "No such address family: %d",
clicon_sock_family(h));
break;
}
return -1;
}
@ -224,7 +224,7 @@ backend_socket_init(clicon_handle h)
*/
int
backend_accept_client(int fd,
void *arg)
void *arg)
{
int retval = -1;
clicon_handle h = (clicon_handle)arg;
@ -244,11 +244,11 @@ backend_accept_client(int fd,
clicon_debug(2, "%s", __FUNCTION__);
len = sizeof(from);
if ((s = accept(fd, &from, &len)) < 0){
clicon_err(OE_UNIX, errno, "accept");
goto done;
clicon_err(OE_UNIX, errno, "accept");
goto done;
}
if ((ce = backend_client_add(h, &from)) == NULL)
goto done;
goto done;
ce->ce_handle = h;
/*
@ -257,35 +257,35 @@ backend_accept_client(int fd,
switch (from.sa_family){
case AF_UNIX:
#if defined(HAVE_SO_PEERCRED)
clen = sizeof(cr);
if(getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cr, &clen) < 0){
clicon_err(OE_UNIX, errno, "getsockopt");
goto done;
}
if (uid2name(cr.uid, &name) < 0)
goto done;
clen = sizeof(cr);
if(getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cr, &clen) < 0){
clicon_err(OE_UNIX, errno, "getsockopt");
goto done;
}
if (uid2name(cr.uid, &name) < 0)
goto done;
#elif defined(HAVE_GETPEEREID)
if (getpeereid(s, &euid, &guid) < 0)
goto done;
if (uid2name(euid, &name) < 0)
goto done;
if (getpeereid(s, &euid, &guid) < 0)
goto done;
if (uid2name(euid, &name) < 0)
goto done;
#else
#error "Need getsockopt O_PEERCRED or getpeereid for unix socket peer cred"
#endif
if (name != NULL){
if ((ce->ce_username = name) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
name = NULL;
goto done;
}
name = NULL;
}
break;
case AF_INET:
break;
if (name != NULL){
if ((ce->ce_username = name) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
name = NULL;
goto done;
}
name = NULL;
}
break;
case AF_INET:
break;
case AF_INET6:
default:
break;
break;
}
ce->ce_s = s;
@ -293,10 +293,10 @@ backend_accept_client(int fd,
* Here we register callbacks for actual data socket
*/
if (clixon_event_reg_fd(s, from_client, (void*)ce, "local netconf client socket") < 0)
goto done;
goto done;
retval = 0;
done:
if (name)
free(name);
free(name);
return retval;
}

View file

@ -78,16 +78,16 @@
*/
static int
db_merge(clicon_handle h,
const char *db1,
const char *db2,
cbuf *cbret)
const char *db1,
const char *db2,
cbuf *cbret)
{
int retval = -1;
cxobj *xt = NULL;
/* Get data as xml from db1 */
if (xmldb_get0(h, (char*)db1, YB_MODULE, NULL, NULL, 0, &xt, NULL, NULL) < 0)
goto done;
goto done;
xml_name_set(xt, NETCONF_INPUT_CONFIG);
/* Merge xml into db2. Without commit */
retval = xmldb_put(h, (char*)db2, OP_MERGE, xt, clicon_username_get(h), cbret);
@ -129,8 +129,8 @@ startup --+-------------------------------------> BROKEN XML
*/
int
startup_mode_startup(clicon_handle h,
char *db,
cbuf *cbret)
char *db,
cbuf *cbret)
{
int retval = -1;
int ret = 0;
@ -138,13 +138,13 @@ startup_mode_startup(clicon_handle h,
yang_stmt *yspec = clicon_dbspec_yang(h);
if (strcmp(db, "running")==0){
clicon_err(OE_FATAL, 0, "Invalid startup db: %s", db);
goto done;
clicon_err(OE_FATAL, 0, "Invalid startup db: %s", db);
goto done;
}
/* If startup does not exist, create it empty */
if (xmldb_exists(h, db) != 1){ /* diff */
if (xmldb_create(h, db) < 0) /* diff */
return -1;
if (xmldb_create(h, db) < 0) /* diff */
return -1;
}
/* When a confirming-commit is issued, the confirmed-commit timeout
@ -159,7 +159,7 @@ startup_mode_startup(clicon_handle h,
clicon_err(OE_DAEMON, 0, "Error checking for the existence of the rollback database");
goto done;
}
if (rollback_exists == 1) {
if (rollback_exists == 1) {
ret = startup_commit(h, "rollback", cbret);
switch(ret) {
case -1:
@ -180,18 +180,18 @@ startup_mode_startup(clicon_handle h,
goto fail;
}
}
else {
if ((ret = startup_commit(h, db, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
}
else {
if ((ret = startup_commit(h, db, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
}
}
else {
if ((ret = startup_commit(h, db, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
if ((ret = startup_commit(h, db, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
}
ok:
retval = 1;
@ -209,9 +209,9 @@ startup_mode_startup(clicon_handle h,
*/
static int
load_extraxml(clicon_handle h,
char *filename,
const char *db,
cbuf *cbret)
char *filename,
const char *db,
cbuf *cbret)
{
int retval = -1;
cxobj *xt = NULL;
@ -221,38 +221,38 @@ load_extraxml(clicon_handle h,
int ret;
if (filename == NULL)
return 1;
return 1;
if ((fp = fopen(filename, "r")) == NULL){
clicon_err(OE_UNIX, errno, "open(%s)", filename);
goto done;
clicon_err(OE_UNIX, errno, "open(%s)", filename);
goto done;
}
yspec = clicon_dbspec_yang(h);
/* No yang check yet because it has <config> as top symbol, do it later after that is removed */
if (clixon_xml_parse_file(fp, YB_NONE, yspec, &xt, &xerr) < 0)
goto done;
goto done;
/* Replace parent w first child */
if (xml_rootchild(xt, 0, &xt) < 0)
goto done;
goto done;
/* Ensure edit-config "config" statement */
if (xt)
xml_name_set(xt, NETCONF_INPUT_CONFIG);
xml_name_set(xt, NETCONF_INPUT_CONFIG);
/* Now we can yang bind */
if ((ret = xml_bind_yang(xt, YB_MODULE, yspec, &xerr)) < 0)
goto done;
goto done;
if (ret == 0){
if (netconf_err2cb(xerr, cbret) < 0)
goto done;
retval = 0;
goto done;
if (netconf_err2cb(xerr, cbret) < 0)
goto done;
retval = 0;
goto done;
}
/* Merge user reset state */
retval = xmldb_put(h, (char*)db, OP_MERGE, xt, clicon_username_get(h), cbret);
done:
if (fp)
fclose(fp);
fclose(fp);
if (xt)
xml_free(xt);
xml_free(xt);
return retval;
}
@ -277,28 +277,28 @@ tmp |-------+-----+-----+
*/
int
startup_extraxml(clicon_handle h,
char *file,
cbuf *cbret)
char *file,
cbuf *cbret)
{
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;
goto done;
/* Application may define extra xml in its reset function */
if (clixon_plugin_reset_all(h, tmp_db) < 0)
goto done;
goto done;
/* Extra XML can also be added via file */
if (file){
/* Parse and load file into tmp db */
if ((ret = load_extraxml(h, file, tmp_db, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
/* Parse and load file into tmp db */
if ((ret = load_extraxml(h, file, tmp_db, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
}
/*
* Check if tmp db is empty.
@ -306,33 +306,33 @@ startup_extraxml(clicon_handle h,
* then skip validation.
*/
if (xmldb_get(h, tmp_db, NULL, NULL, &xt0) < 0)
goto done;
goto done;
if ((ret = xmldb_empty_get(h, tmp_db)) < 0)
goto done;
goto done;
if (ret == 1)
goto ok;
goto ok;
xt = NULL;
/* Validate the tmp db and return possibly upgraded xml in xt
*/
if ((ret = startup_validate(h, tmp_db, &xt, cbret)) < 0)
goto done;
goto done;
if (ret == 0)
goto fail;
goto fail;
if (xt==NULL || xml_child_nr(xt)==0)
goto ok;
goto ok;
/* Merge tmp into running (no commit) */
if ((ret = db_merge(h, tmp_db, "running", cbret)) < 0)
goto fail;
goto fail;
if (ret == 0)
goto fail;
goto fail;
ok:
retval = 1;
done:
if (xt0)
xml_free(xt0);
xml_free(xt0);
xmldb_get0_free(h, &xt);
if (xmldb_delete(h, tmp_db) != 0 && errno != ENOENT)
return -1;
return -1;
return retval;
fail:
retval = 0;
@ -347,25 +347,25 @@ startup_extraxml(clicon_handle h,
*/
int
startup_module_state(clicon_handle h,
yang_stmt *yspec)
yang_stmt *yspec)
{
int retval = -1;
cxobj *x = NULL;
int ret;
if (!clicon_option_bool(h, "CLICON_XMLDB_MODSTATE"))
goto ok;
goto ok;
/* 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;
goto done;
if (ret == 0)
goto fail;
goto fail;
ok:
retval = 1;
done:
if (x)
xml_free(x);
xml_free(x);
return retval;
fail:
retval = 0;

View file

@ -64,7 +64,7 @@ int cancel_rollback_event(clicon_handle h);
int cancel_confirmed_commit(clicon_handle h);
int handle_confirmed_commit(clicon_handle h, cxobj *xe);
int do_rollback(clicon_handle h, uint8_t *errs);
int from_client_cancel_commit(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_cancel_commit(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_confirmed_commit(clicon_handle h, cxobj *xe, uint32_t myid, cbuf *cbret);
/* backend_commit.c */
@ -73,7 +73,7 @@ int startup_commit(clicon_handle h, char *db, cbuf *cbret);
int candidate_validate(clicon_handle h, char *db, cbuf *cbret);
int candidate_commit(clicon_handle h, cxobj *xe, char *db, cbuf *cbret);
int from_client_commit(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_commit(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_discard_changes(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_validate(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_restart_one(clicon_handle h, clixon_plugin_t *cp, cbuf *cbret);

View file

@ -114,11 +114,11 @@ backend_handle_exit(clicon_handle h)
/* only delete client structs, not close sockets, etc, see backend_client_rm WHY NOT? */
while ((ce = backend_client_list(h)) != NULL){
if (ce->ce_s){
close(ce->ce_s);
ce->ce_s = 0;
}
backend_client_delete(h, ce);
if (ce->ce_s){
close(ce->ce_s);
ce->ce_s = 0;
}
backend_client_delete(h, ce);
}
clicon_handle_exit(h); /* frees h and options (and streams) */
return 0;
@ -132,14 +132,14 @@ backend_handle_exit(clicon_handle h)
*/
struct client_entry *
backend_client_add(clicon_handle h,
struct sockaddr *addr)
struct sockaddr *addr)
{
struct backend_handle *bh = handle(h);
struct client_entry *ce;
if ((ce = (struct client_entry *)malloc(sizeof(*ce))) == NULL){
clicon_err(OE_PLUGIN, errno, "malloc");
return NULL;
clicon_err(OE_PLUGIN, errno, "malloc");
return NULL;
}
memset(ce, 0, sizeof(*ce));
ce->ce_nr = bh->bh_ce_nr++; /* Session-id ? */
@ -168,7 +168,7 @@ backend_client_list(clicon_handle h)
*/
int
backend_client_delete(clicon_handle h,
struct client_entry *ce)
struct client_entry *ce)
{
struct client_entry *c;
struct client_entry **ce_prev;
@ -176,14 +176,14 @@ backend_client_delete(clicon_handle h,
ce_prev = &bh->bh_ce_list;
for (c = *ce_prev; c; c = c->ce_next){
if (c == ce){
*ce_prev = c->ce_next;
if (ce->ce_username)
free(ce->ce_username);
free(ce);
break;
}
ce_prev = &c->ce_next;
if (c == ce){
*ce_prev = c->ce_next;
if (ce->ce_username)
free(ce->ce_username);
free(ce);
break;
}
ce_prev = &c->ce_next;
}
return 0;
}
@ -194,18 +194,18 @@ backend_client_delete(clicon_handle h,
*/
int
backend_client_print(clicon_handle h,
FILE *f)
FILE *f)
{
struct backend_handle *bh = handle(h);
struct client_entry *ce;
for (ce = bh->bh_ce_list; ce; ce = ce->ce_next){
fprintf(f, "Client: %d\n", ce->ce_nr);
fprintf(f, " Session: %d\n", ce->ce_id);
fprintf(f, " Socket: %d\n", ce->ce_s);
fprintf(f, " Msgs in: %d\n", ce->ce_stat_in);
fprintf(f, " Msgs out: %d\n", ce->ce_stat_out);
fprintf(f, " Username: %s\n", ce->ce_username);
fprintf(f, "Client: %d\n", ce->ce_nr);
fprintf(f, " Session: %d\n", ce->ce_id);
fprintf(f, " Socket: %d\n", ce->ce_s);
fprintf(f, " Msgs in: %d\n", ce->ce_stat_in);
fprintf(f, " Msgs out: %d\n", ce->ce_stat_out);
fprintf(f, " Username: %s\n", ce->ce_username);
}
return 0;
}

View file

@ -99,13 +99,13 @@ int clixon_plugin_pre_daemon_all(clicon_handle h);
int clixon_plugin_daemon_all(clicon_handle h);
int clixon_plugin_statedata_all(clicon_handle h, yang_stmt *yspec, cvec *nsc, char *xpath,
cxobj **xtop);
cxobj **xtop);
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,
cxobj *xstate);
uint32_t offset, uint32_t limit,
cxobj *xstate);
int clixon_pagination_free(clicon_handle h);
transaction_data_t * transaction_new(void);

View file

@ -94,7 +94,7 @@ transaction_arg(transaction_data td)
*/
int
transaction_arg_set(transaction_data td,
void *arg)
void *arg)
{
((transaction_data_t *)td)->td_arg = arg;
return 0;
@ -206,7 +206,7 @@ transaction_clen(transaction_data td)
*/
int
transaction_print(FILE *f,
transaction_data th)
transaction_data th)
{
cxobj *xn;
int i;
@ -217,20 +217,20 @@ transaction_print(FILE *f,
fprintf(f, "Transaction id: 0x%" PRIu64 "\n", td->td_id);
fprintf(f, "Removed\n=========\n");
for (i=0; i<td->td_dlen; i++){
xn = td->td_dvec[i];
xml_print(f, xn);
xn = td->td_dvec[i];
xml_print(f, xn);
}
fprintf(f, "Added\n=========\n");
for (i=0; i<td->td_alen; i++){
xn = td->td_avec[i];
xml_print(f, xn);
xn = td->td_avec[i];
xml_print(f, xn);
}
fprintf(f, "Changed\n=========\n");
for (i=0; i<td->td_clen; i++){
xn = td->td_scvec[i];
xml_print(f, xn);
xn = td->td_tcvec[i];
xml_print(f, xn);
xn = td->td_scvec[i];
xml_print(f, xn);
xn = td->td_tcvec[i];
xml_print(f, xn);
}
return 0;
}
@ -240,9 +240,9 @@ transaction_print(FILE *f,
*/
int
transaction_log(clicon_handle h,
transaction_data th,
int level,
const char *op)
transaction_data th,
int level,
const char *op)
{
cxobj *xn;
int i;
@ -251,41 +251,41 @@ transaction_log(clicon_handle h,
td = (transaction_data_t *)th;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_CFG, errno, "cbuf_new");
goto done;
clicon_err(OE_CFG, errno, "cbuf_new");
goto done;
}
for (i=0; i<td->td_dlen; i++){
xn = td->td_dvec[i];
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
goto done;
xn = td->td_dvec[i];
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
goto done;
}
if (i)
clicon_log(level, "%s %" PRIu64 " %s del: %s",
__FUNCTION__, td->td_id, op, cbuf_get(cb));
clicon_log(level, "%s %" PRIu64 " %s del: %s",
__FUNCTION__, td->td_id, op, cbuf_get(cb));
cbuf_reset(cb);
for (i=0; i<td->td_alen; i++){
xn = td->td_avec[i];
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
goto done;
xn = td->td_avec[i];
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
goto done;
}
if (i)
clicon_log(level, "%s %" PRIu64 " %s add: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb));
clicon_log(level, "%s %" PRIu64 " %s add: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb));
cbuf_reset(cb);
for (i=0; i<td->td_clen; i++){
if (td->td_scvec){
xn = td->td_scvec[i];
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
goto done;
}
xn = td->td_tcvec[i];
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
goto done;
if (td->td_scvec){
xn = td->td_scvec[i];
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
goto done;
}
xn = td->td_tcvec[i];
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
goto done;
}
if (i)
clicon_log(level, "%s %" PRIu64 " %s change: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb));
clicon_log(level, "%s %" PRIu64 " %s change: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb));
done:
if (cb)
cbuf_free(cb);
cbuf_free(cb);
return 0;
}