diff --git a/.editorconfig b/.editorconfig
index b757fc37..572c8dff 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -3,3 +3,4 @@ root = true
[*.{c,h}]
indent_size = 4
indent_style = space
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 27cb1f34..772a93f9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,19 @@
## 6.0.0
Expected: End of 2022
+### New features
+
+* Confirmed-commit capability
+ * Standards
+ * RFC 4741 "NETCONF Configuration Protocol": Section 8.4
+ * RFC 6241 "Network Configuration Protocol (NETCONF)": Section 8.4
+ * Features
+ * `:confirmed-commit:1.0` capability
+ * `:confirmed-commit:1.1` capability
+ * Added support for relevant arguments to CLI commit
+ * See [example_cli.cli](https://github.com/clicon/clixon/blob/master/example/main/example_cli.cli)
+ * See [Netconf Confirmed Commit Capability](https://github.com/clicon/clixon/issues/255)
+
### API changes on existing protocol/config features
Users may have to change how they access the system
@@ -53,9 +66,29 @@ Developers may need to change their code
* C API changes
* Added `defaults` parameter to `clicon_rpc_get_pageable_list()`
+ * `clicon_rpc_commit()` and `cli_commit`
+ * Added `confirmed`, `cancel`, `timeout`, `persist-id`, and `persist-id-val` parameters to
+ * `clicon_rpc_commit()` and `clicon_rpc_validate`
+ * Added three-value return.
+ * Code need to be changed from: checking for `<0` to `<1` to keep same semantics
+
+### Minor features
+
+* [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
+* Added warning if modstate is not present in datastore if `CLICON_XMLDB_MODSTATE` is set.
### Corrected Bugs
+* Fixed: [Non-obvious behavior of clixon_snmp after snmpset command when transaction validation returns an error](https://github.com/clicon/clixon/issues/375)
+ * Fixed by validating writes on ACTION instead of COMMIT since libnetsnmp seems not to accept commit errors
+* Fixed: [YANG when condition evaluated as false combined with a mandatory leaf does not work](https://github.com/clicon/clixon/issues/380)
+* Fixed: [Trying to change the "read-only" node through snmpset](https://github.com/clicon/clixon/issues/376)
+* Fixed: [Trying to change the "config false" node through snmpset](https://github.com/clicon/clixon/issues/377)
+ * Fixed by returning `SNMP_ERR_NOTWRITABLE` when trying to reserve object
+* Fixed: [Non-obvious behavior of clixon_snmp after snmpset command when transaction validation returns an error](https://github.com/clicon/clixon/issues/375)
+* Fixed: [clixon_snmp module crashes on snmpwalk command](https://github.com/clicon/clixon/issues/378)
+* Fixed: [unneeded trailing zero character on SNMP strings](https://github.com/clicon/clixon/issues/367)
* Fixed: [message-id present on netconf app "hello"](https://github.com/clicon/clixon/issues/369)
* Fixed: [SNMP "smiv2" yang extension doesn't work on augmented nodes](https://github.com/clicon/clixon/issues/366)
diff --git a/apps/backend/Makefile.in b/apps/backend/Makefile.in
index 9bfa8d92..c5c2f409 100644
--- a/apps/backend/Makefile.in
+++ b/apps/backend/Makefile.in
@@ -100,6 +100,7 @@ APPOBJ = $(APPSRC:.c=.o)
LIBSRC = clixon_backend_transaction.c
LIBSRC += clixon_backend_handle.c
LIBSRC += backend_commit.c
+LIBSRC += backend_confirm.c
LIBSRC += backend_plugin.c
LIBOBJ = $(LIBSRC:.c=.o)
diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c
index 7164bca7..d434ffc6 100644
--- a/apps/backend/backend_client.c
+++ b/apps/backend/backend_client.c
@@ -78,13 +78,13 @@
*/
static struct client_entry *
ce_find_byid(struct client_entry *ce_list,
- uint32_t id)
+ uint32_t id)
{
struct client_entry *ce;
for (ce = ce_list; ce; ce = ce->ce_next)
- if (ce->ce_id == id)
- return ce;
+ if (ce->ce_id == id)
+ return ce;
return NULL;
}
@@ -97,26 +97,26 @@ ce_find_byid(struct client_entry *ce_list,
*/
int
ce_event_cb(clicon_handle h,
- int op,
- cxobj *event,
- void *arg)
+ int op,
+ cxobj *event,
+ void *arg)
{
struct client_entry *ce = (struct client_entry *)arg;
clicon_debug(1, "%s op:%d", __FUNCTION__, op);
switch (op){
case 1:
- /* Risk of recursion here */
- if (ce->ce_s)
- backend_client_rm(h, ce);
- break;
+ /* Risk of recursion here */
+ if (ce->ce_s)
+ backend_client_rm(h, ce);
+ break;
default:
- if (send_msg_notify_xml(h, ce->ce_s, event) < 0){
- if (errno == ECONNRESET || errno == EPIPE){
- clicon_log(LOG_WARNING, "client %d reset", ce->ce_nr);
- }
- break;
- }
+ if (send_msg_notify_xml(h, ce->ce_s, event) < 0){
+ if (errno == ECONNRESET || errno == EPIPE){
+ clicon_log(LOG_WARNING, "client %d reset", ce->ce_nr);
+ }
+ break;
+ }
}
return 0;
}
@@ -126,7 +126,7 @@ ce_event_cb(clicon_handle h,
*/
static int
release_all_dbs(clicon_handle h,
- uint32_t id)
+ uint32_t id)
{
int retval = -1;
char **keys = NULL;
@@ -136,21 +136,21 @@ release_all_dbs(clicon_handle h,
/* get all db:s */
if (clicon_hash_keys(clicon_db_elmnt(h), &keys, &klen) < 0)
- goto done;
+ goto done;
/* Identify the ones locked by client id */
for (i = 0; i < klen; i++) {
- if ((de = clicon_db_elmnt_get(h, keys[i])) != NULL &&
- de->de_id == id){
- de->de_id = 0; /* unlock */
- clicon_db_elmnt_set(h, keys[i], de);
- if (clixon_plugin_lockdb_all(h, keys[i], 0, id) < 0)
- goto done;
- }
+ if ((de = clicon_db_elmnt_get(h, keys[i])) != NULL &&
+ de->de_id == id){
+ de->de_id = 0; /* unlock */
+ clicon_db_elmnt_set(h, keys[i], de);
+ if (clixon_plugin_lockdb_all(h, keys[i], 0, id) < 0)
+ goto done;
+ }
}
retval = 0;
done:
if (keys)
- free(keys);
+ free(keys);
return retval;
}
@@ -159,15 +159,44 @@ release_all_dbs(clicon_handle h,
* Finally actually remove client struct in handle
* @param[in] h Clicon handle
* @param[in] ce Client handle
+ * @retval -1 Error (fatal)
+ * @retval 0 Ok
* @see backend_client_delete for actual deallocation of client entry struct
*/
int
backend_client_rm(clicon_handle h,
- struct client_entry *ce)
+ struct client_entry *ce)
{
struct client_entry *c;
struct client_entry *c0;
struct client_entry **ce_prev;
+ uint32_t myid = ce->ce_id;
+ yang_stmt *yspec;
+ int retval = -1;
+
+ /* If the confirmed-commit feature is enabled, rollback any ephemeral commit originated by this client */
+ if ((yspec = clicon_dbspec_yang(h)) == NULL) {
+ clicon_err(OE_YANG, ENOENT, "No yang spec");
+ goto done;
+ }
+
+ 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));
+
+ if (myid == confirmed_commit_session_id_get(h)) {
+ clicon_debug(1, "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
+ * ignored here.
+ */
+ cancel_rollback_event(h);
+ do_rollback(h, NULL);
+ }
+ }
+ }
clicon_debug(1, "%s", __FUNCTION__);
/* for all streams: XXX better to do it top-level? */
@@ -175,19 +204,22 @@ backend_client_rm(clicon_handle h,
c0 = backend_client_list(h);
ce_prev = &c0; /* this points to stack and is not real backpointer */
for (c = *ce_prev; c; c = c->ce_next){
- if (c == ce){
- if (ce->ce_s){
- clixon_event_unreg_fd(ce->ce_s, from_client);
- close(ce->ce_s);
- ce->ce_s = 0;
- if (release_all_dbs(h, ce->ce_id) < 0)
- return -1;
- }
- break;
- }
- ce_prev = &c->ce_next;
+ if (c == ce){
+ if (ce->ce_s){
+ clixon_event_unreg_fd(ce->ce_s, from_client);
+ close(ce->ce_s);
+ ce->ce_s = 0;
+ if (release_all_dbs(h, ce->ce_id) < 0)
+ return -1;
+ }
+ break;
+ }
+ ce_prev = &c->ce_next;
}
- return backend_client_delete(h, ce); /* actually purge it */
+ retval = backend_client_delete(h, ce); /* actually purge it */
+
+ done:
+ return retval;
}
/*! Get clixon per datastore stats
@@ -199,8 +231,8 @@ backend_client_rm(clicon_handle h,
*/
static int
clixon_stats_datastore_get(clicon_handle h,
- char *dbname,
- cbuf *cb)
+ char *dbname,
+ cbuf *cb)
{
int retval = -1;
cxobj *xt = NULL;
@@ -211,26 +243,26 @@ clixon_stats_datastore_get(clicon_handle h,
/* This is the db cache */
if ((xt = xmldb_cache_get(h, dbname)) == NULL){
- /* Trigger cache if no exist */
- if (xmldb_get(h, dbname, NULL, "/", &xn) < 0)
- goto done;
- xt = xmldb_cache_get(h, dbname);
+ /* Trigger cache if no exist */
+ if (xmldb_get(h, dbname, NULL, "/", &xn) < 0)
+ goto done;
+ xt = xmldb_cache_get(h, dbname);
}
if (xt == NULL){
- cprintf(cb, "%s 0 0 ",
- CLIXON_LIB_NS, dbname);
+ cprintf(cb, "%s 0 0 ",
+ CLIXON_LIB_NS, dbname);
}
else{
- if (xml_stats(xt, &nr, &sz) < 0)
- goto done;
- cprintf(cb, "%s %" PRIu64 " "
- "%zu ",
- CLIXON_LIB_NS, dbname, nr, sz);
+ if (xml_stats(xt, &nr, &sz) < 0)
+ goto done;
+ cprintf(cb, "%s %" PRIu64 " "
+ "%zu ",
+ CLIXON_LIB_NS, dbname, nr, sz);
}
retval = 0;
done:
if (xn)
- xml_free(xn);
+ xml_free(xn);
return retval;
}
@@ -243,8 +275,8 @@ clixon_stats_datastore_get(clicon_handle h,
*/
static int
clixon_stats_module_get(clicon_handle h,
- yang_stmt *ys,
- cbuf *cb)
+ yang_stmt *ys,
+ cbuf *cb)
{
int retval = -1;
uint64_t nr = 0;
@@ -252,16 +284,16 @@ clixon_stats_module_get(clicon_handle h,
cxobj *xn = NULL;
if (ys == NULL)
- return 0;
+ return 0;
if (yang_stats(ys, &nr, &sz) < 0)
- goto done;
+ goto done;
cprintf(cb, "%s %" PRIu64 " "
- "%zu ",
- CLIXON_LIB_NS, yang_argument_get(ys), nr, sz);
+ "%zu ",
+ CLIXON_LIB_NS, yang_argument_get(ys), nr, sz);
retval = 0;
done:
if (xn)
- xml_free(xn);
+ xml_free(xn);
return retval;
}
@@ -285,10 +317,10 @@ clixon_stats_module_get(clicon_handle h,
*/
static int
from_client_edit_config(clicon_handle h,
- cxobj *xn,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xn,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
struct client_entry *ce = (struct client_entry *)arg;
@@ -312,159 +344,187 @@ from_client_edit_config(clicon_handle h,
username = clicon_username_get(h);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No yang spec9");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "No yang spec9");
+ goto done;
}
if ((target = netconf_db_find(xn, "target")) == NULL){
- if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0)
- goto done;
- goto ok;
+ if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0)
+ goto done;
+ goto ok;
}
if ((cbx = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
if (xmldb_validate_db(target) < 0){
- cprintf(cbx, "No such database: %s", target);
- if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbx))< 0)
- goto done;
- goto ok;
+ cprintf(cbx, "No such database: %s", target);
+ if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbx))< 0)
+ goto done;
+ goto ok;
}
/* Check if target locked by other client */
iddb = xmldb_islocked(h, target);
if (iddb && myid != iddb){
- cprintf(cbx, "%u ", iddb);
- if (netconf_lock_denied(cbret, cbuf_get(cbx), "Operation failed, lock is already held") < 0)
- goto done;
- goto ok;
+ cprintf(cbx, "%u ", iddb);
+ if (netconf_lock_denied(cbret, cbuf_get(cbx), "Operation failed, lock is already held") < 0)
+ goto done;
+ goto ok;
}
if (xml_nsctx_node(xn, &nsc) < 0)
- goto done;
+ goto done;
/* Get prefix of netconf base namespace in the incoming message */
if (xml_nsctx_get_prefix(nsc, NETCONF_BASE_NAMESPACE, &prefix) == 0){
- cprintf(cbx, "No appropriate prefix exists for: %s", NETCONF_BASE_NAMESPACE);
- if (netconf_unknown_namespace(cbret, "protocol", xml_name(xn), cbuf_get(cbx)) < 0)
- goto done;
- goto ok;
+ cprintf(cbx, "No appropriate prefix exists for: %s", NETCONF_BASE_NAMESPACE);
+ if (netconf_unknown_namespace(cbret, "protocol", xml_name(xn), cbuf_get(cbx)) < 0)
+ goto done;
+ goto ok;
}
/* Get default-operation element */
if ((x = xpath_first(xn, nsc, "%s%sdefault-operation", prefix?prefix:"", prefix?":":"")) != NULL){
- if (xml_operation(xml_body(x), &operation) < 0){
- if (netconf_invalid_value(cbret, "protocol", "Wrong operation")< 0)
- goto done;
- goto ok;
- }
+ if (xml_operation(xml_body(x), &operation) < 0){
+ if (netconf_invalid_value(cbret, "protocol", "Wrong operation")< 0)
+ goto done;
+ goto ok;
+ }
}
/* Get config element */
if ((xc = xpath_first(xn, nsc, "%s%s%s",
- prefix?prefix:"",
- prefix?":":"",
- NETCONF_INPUT_CONFIG)) == NULL){
- cprintf(cbx, "Element not found, or mismatching prefix %s for namespace %s",
- prefix?prefix:"null", NETCONF_BASE_NAMESPACE);
- if (netconf_missing_element(cbret, "protocol", NETCONF_INPUT_CONFIG, cbuf_get(cbx)) < 0)
- goto done;
- goto ok;
+ prefix?prefix:"",
+ prefix?":":"",
+ NETCONF_INPUT_CONFIG)) == NULL){
+ cprintf(cbx, "Element not found, or mismatching prefix %s for namespace %s",
+ prefix?prefix:"null", NETCONF_BASE_NAMESPACE);
+ if (netconf_missing_element(cbret, "protocol", NETCONF_INPUT_CONFIG, cbuf_get(cbx)) < 0)
+ goto done;
+ goto ok;
}
/* yang spec may be set to anyxml by ingress yang check,...*/
if (xml_spec(xc) != NULL)
- xml_spec_set(xc, NULL);
+ xml_spec_set(xc, NULL);
/* Populate XML with Yang spec (why not do this in parser?)
*/
if ((ret = xml_bind_yang(xc, YB_MODULE, yspec, &xret)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- goto ok;
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ goto ok;
}
/* (Mark all nodes that are not configure data and) set return */
if ((ret = xml_non_config_data(xc, &xret)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- goto ok;
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ goto ok;
}
if (non_config){
- if (netconf_invalid_value(cbret, "protocol", "State data not allowed")< 0)
- goto done;
- goto ok;
+ if (netconf_invalid_value(cbret, "protocol", "State data not allowed")< 0)
+ goto done;
+ goto ok;
}
/* Limited validation of incoming payload
*/
if ((ret = xml_yang_minmax_recurse(xc, &xret)) < 0)
- goto done;
+ goto done;
/* xmldb_put (difflist handling) requires list keys */
if (ret==1 && (ret = xml_yang_validate_list_key_only(xc, &xret)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- goto ok;
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ goto ok;
}
/* Cant do this earlier since we dont have a yang spec to
* the upper part of the tree, until we get the "config" tree.
*/
if (xml_sort_recurse(xc) < 0)
- goto done;
+ goto done;
if ((ret = xmldb_put(h, target, operation, xc, username, cbret)) < 0){
- if (netconf_operation_failed(cbret, "protocol", clicon_err_reason)< 0)
- goto done;
- goto ok;
+ if (netconf_operation_failed(cbret, "protocol", clicon_err_reason)< 0)
+ goto done;
+ goto ok;
}
if (ret == 0)
- goto ok;
+ goto ok;
xmldb_modified_set(h, target, 1); /* mark as dirty */
/* Clixon extension: autocommit */
if ((attr = xml_find_value(xn, "autocommit")) != NULL &&
- strcmp(attr,"true")==0)
- autocommit = 1;
+ strcmp(attr,"true")==0)
+ autocommit = 1;
/* If autocommit option is set or requested by client */
if (clicon_autocommit(h) || autocommit) {
- if ((ret = candidate_commit(h, "candidate", cbret)) < 0){ /* Assume validation fail, nofatal */
- if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
- goto done;
- xmldb_copy(h, "running", "candidate");
- goto ok;
- }
- if (ret == 0){ /* discard */
- if (xmldb_copy(h, "running", "candidate") < 0){
- if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
- goto done;
- goto ok;
- }
- goto ok;
- }
+ /* if this is from a restconf client ...
+ * and, if there is an existing ephemeral commit, set is_valid_confirming_commit=1 such that
+ * candidate_commit will apply the configuration per RFC 8040 1.4:
+ * If a confirmed commit procedure is
+ * in progress by any NETCONF client, then any new commit will act as
+ * the confirming commit.
+ * and, if there is an existing persistent commit, netconf_operation_failed with "in-use", so
+ * that the restconf server will return "409 Conflict" per RFC 8040 1.4:
+ * If the NETCONF server is expecting a
+ * "persist-id" parameter to complete the confirmed commit procedure,
+ * then the RESTCONF edit operation MUST fail with a "409 Conflict"
+ * status-line. The error-tag "in-use" is used in this case.
+ */
+ if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) {
+ switch (confirmed_commit_state_get(h)){
+ case INACTIVE:
+ break;
+ case PERSISTENT:
+ if (netconf_in_use(cbret, "application", "Persistent commit is ongoing")< 0)
+ goto done;
+ goto ok;
+ break;
+ case EPHEMERAL:
+ case ROLLBACK:
+ cancel_confirmed_commit(h);
+ break;
+ }
+ }
+ if ((ret = candidate_commit(h, NULL, "candidate", cbret)) < 0){ /* Assume validation fail, nofatal */
+ if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
+ goto done;
+ xmldb_copy(h, "running", "candidate");
+ goto ok;
+ }
+ if (ret == 0){ /* discard */
+ if (xmldb_copy(h, "running", "candidate") < 0){
+ if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
+ goto done;
+ goto ok;
+ }
+ goto ok;
+ }
}
/* Clixon extension: copy */
if ((attr = xml_find_value(xn, "copystartup")) != NULL &&
- strcmp(attr,"true") == 0){
- if (xmldb_copy(h, "running", "startup") < 0){
- if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
- goto done;
- goto ok;
- }
+ strcmp(attr,"true") == 0){
+ if (xmldb_copy(h, "running", "startup") < 0){
+ if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
+ goto done;
+ goto ok;
+ }
}
if (cbuf_len(cbret) != 0){
- clicon_err(OE_NETCONF, EINVAL, "Internal error: cbret is not empty");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "Internal error: cbret is not empty");
+ goto done;
}
cprintf(cbret, " ");
ok:
retval = 0;
done:
if (nsc)
- cvec_free(nsc);
+ cvec_free(nsc);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (cbx)
- cbuf_free(cbx);
- clicon_debug(1, "%s done cbret:%s", __FUNCTION__, cbuf_get(cbret));
+ cbuf_free(cbx);
+ clicon_debug(1, "%s done cbret:%s", __FUNCTION__, cbuf_get(cbret));
return retval;
} /* from_client_edit_config */
@@ -484,10 +544,10 @@ from_client_edit_config(clicon_handle h,
*/
static int
from_client_copy_config(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
struct client_entry *ce = (struct client_entry *)arg;
@@ -499,48 +559,48 @@ from_client_copy_config(clicon_handle h,
cbuf *cbmsg = NULL;
if ((source = netconf_db_find(xe, "source")) == NULL){
- if (netconf_missing_element(cbret, "protocol", "source", NULL) < 0)
- goto done;
- goto ok;
+ if (netconf_missing_element(cbret, "protocol", "source", NULL) < 0)
+ goto done;
+ goto ok;
}
if ((cbx = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
if (xmldb_validate_db(source) < 0){
- cprintf(cbx, "No such database: %s", source);
- if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbx))< 0)
- goto done;
- goto ok;
+ cprintf(cbx, "No such database: %s", source);
+ if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbx))< 0)
+ goto done;
+ goto ok;
}
if ((target = netconf_db_find(xe, "target")) == NULL){
- if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0)
- goto done;
- goto ok;
+ if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0)
+ goto done;
+ goto ok;
}
if (xmldb_validate_db(target) < 0){
- cprintf(cbx, "No such database: %s", target);
- if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbx))< 0)
- goto done;
- goto ok;
+ cprintf(cbx, "No such database: %s", target);
+ if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbx))< 0)
+ goto done;
+ goto ok;
}
/* Check if target locked by other client */
iddb = xmldb_islocked(h, target);
if (iddb && myid != iddb){
- cprintf(cbx, "%u ", iddb);
- if (netconf_lock_denied(cbret, cbuf_get(cbx), "Copy failed, lock is already held") < 0)
- goto done;
- goto ok;
+ cprintf(cbx, "%u ", iddb);
+ if (netconf_lock_denied(cbret, cbuf_get(cbx), "Copy failed, lock is already held") < 0)
+ goto done;
+ goto ok;
}
if (xmldb_copy(h, source, target) < 0){
- if ((cbmsg = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cbmsg, "Copy %s datastore to %s: %s", source, target, clicon_err_reason);
- if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg))< 0)
- goto done;
- goto ok;
+ if ((cbmsg = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cbmsg, "Copy %s datastore to %s: %s", source, target, clicon_err_reason);
+ if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg))< 0)
+ goto done;
+ goto ok;
}
xmldb_modified_set(h, target, 1); /* mark as dirty */
cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
@@ -548,9 +608,9 @@ from_client_copy_config(clicon_handle h,
retval = 0;
done:
if (cbmsg)
- cbuf_free(cbmsg);
+ cbuf_free(cbmsg);
if (cbx)
- cbuf_free(cbx);
+ cbuf_free(cbx);
return retval;
}
@@ -565,10 +625,10 @@ from_client_copy_config(clicon_handle h,
*/
static int
from_client_delete_config(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
struct client_entry *ce = (struct client_entry *)arg;
@@ -580,48 +640,48 @@ from_client_delete_config(clicon_handle h,
/* XXX should use prefix cf edit_config */
if ((target = netconf_db_find(xe, "target")) == NULL ||
- strcmp(target, "running")==0){
- if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0)
- goto done;
- goto ok;
+ strcmp(target, "running")==0){
+ if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0)
+ goto done;
+ goto ok;
}
if ((cbx = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
if (xmldb_validate_db(target) < 0){
- cprintf(cbx, "No such database: %s", target);
- if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbx))< 0)
- goto done;
- goto ok;
+ cprintf(cbx, "No such database: %s", target);
+ if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbx))< 0)
+ goto done;
+ goto ok;
}
/* Check if target locked by other client */
iddb = xmldb_islocked(h, target);
if (iddb && myid != iddb){
- cprintf(cbx, "%u ", iddb);
- if (netconf_lock_denied(cbret, cbuf_get(cbx), "Operation failed, lock is already held") < 0)
- goto done;
- goto ok;
+ cprintf(cbx, "%u ", iddb);
+ if (netconf_lock_denied(cbret, cbuf_get(cbx), "Operation failed, lock is already held") < 0)
+ goto done;
+ goto ok;
}
if (xmldb_delete(h, target) < 0){
- if ((cbmsg = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cbmsg, "Delete %s datastore: %s", target, clicon_err_reason);
- if (netconf_operation_failed(cbret, "protocol", cbuf_get(cbmsg))< 0)
- goto done;
- goto ok;
+ if ((cbmsg = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cbmsg, "Delete %s datastore: %s", target, clicon_err_reason);
+ if (netconf_operation_failed(cbret, "protocol", cbuf_get(cbmsg))< 0)
+ goto done;
+ goto ok;
}
if (xmldb_create(h, target) < 0){
- if ((cbmsg = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cbmsg, "Create %s datastore: %s", target, clicon_err_reason);
- if (netconf_operation_failed(cbret, "protocol", cbuf_get(cbmsg))< 0)
- goto done;
- goto ok;
+ if ((cbmsg = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cbmsg, "Create %s datastore: %s", target, clicon_err_reason);
+ if (netconf_operation_failed(cbret, "protocol", cbuf_get(cbmsg))< 0)
+ goto done;
+ goto ok;
}
xmldb_modified_set(h, target, 1); /* mark as dirty */
cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
@@ -629,9 +689,9 @@ from_client_delete_config(clicon_handle h,
retval = 0;
done:
if (cbmsg)
- cbuf_free(cbmsg);
+ cbuf_free(cbmsg);
if (cbx)
- cbuf_free(cbx);
+ cbuf_free(cbx);
return retval;
}
@@ -647,64 +707,84 @@ from_client_delete_config(clicon_handle h,
*/
static int
from_client_lock(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
struct client_entry *ce = (struct client_entry *)arg;
uint32_t id = ce->ce_id;
uint32_t iddb;
+ uint32_t otherid;
char *db;
cbuf *cbx = NULL; /* Assist cbuf */
-
+ yang_stmt *yspec;
+
+ if ((yspec = clicon_dbspec_yang(h)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "No yang spec9");
+ goto done;
+ }
if ((db = netconf_db_find(xe, "target")) == NULL){
- if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0)
- goto done;
- goto ok;
+ if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0)
+ goto done;
+ goto ok;
}
if ((cbx = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
if (xmldb_validate_db(db) < 0){
- cprintf(cbx, "No such database: %s", db);
- if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbx))< 0)
- goto done;
- goto ok;
+ cprintf(cbx, "No such database: %s", db);
+ if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbx))< 0)
+ goto done;
+ goto ok;
}
/*
* 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.
*/
if ((iddb = xmldb_islocked(h, db)) != 0){
- cprintf(cbx, "%u ", iddb);
- if (netconf_lock_denied(cbret, cbuf_get(cbx), "Operation failed, lock is already held") < 0)
- goto done;
- goto ok;
+ cprintf(cbx, "%u ", iddb);
+ if (netconf_lock_denied(cbret, cbuf_get(cbx), "Operation failed, lock is already held") < 0)
+ goto done;
+ goto ok;
}
/* 2) The target configuration is , it has already been modified, and
* these changes have not been committed or rolled back.
*/
if (strcmp(db, "candidate") == 0 &&
- xmldb_modified_get(h, db)){
- if (netconf_lock_denied(cbret, "0 ",
- "Operation failed, candidate has already been modified and the changes have not been committed or rolled back (RFC 6241 7.5)") < 0)
- goto done;
- goto ok;
+ xmldb_modified_get(h, db)){
+ if (netconf_lock_denied(cbret, "0 ",
+ "Operation failed, candidate has already been modified and the changes have not been committed or rolled back (RFC 6241 7.5)") < 0)
+ goto done;
+ goto ok;
+ }
+ /* 3) The target configuration is , and another NETCONF
+ * session has an ongoing confirmed commi
+ */
+ if (strcmp(db, "running") == 0 &&
+ if_feature(yspec, "ietf-netconf", "confirmed-commit") &&
+ confirmed_commit_state_get(h) != INACTIVE){
+ if ((otherid = confirmed_commit_session_id_get(h)) != 0){
+ cprintf(cbx, "%u ", otherid);
+ if (netconf_lock_denied(cbret, cbuf_get(cbx),
+ "Operation failed, another session has an ongoing confirmed commit") < 0)
+ goto done;
+ goto ok;
+ }
}
if (xmldb_lock(h, db, id) < 0)
- goto done;
+ goto done;
/* user callback */
if (clixon_plugin_lockdb_all(h, db, 1, id) < 0)
- goto done;
+ goto done;
cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
ok:
retval = 0;
done:
if (cbx)
- cbuf_free(cbx);
+ cbuf_free(cbx);
return retval;
}
@@ -720,10 +800,10 @@ from_client_lock(clicon_handle h,
*/
static int
from_client_unlock(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
struct client_entry *ce = (struct client_entry *)arg;
@@ -733,19 +813,19 @@ from_client_unlock(clicon_handle h,
cbuf *cbx = NULL; /* Assist cbuf */
if ((db = netconf_db_find(xe, "target")) == NULL){
- if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0)
- goto done;
- goto ok;
+ if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0)
+ goto done;
+ goto ok;
}
if ((cbx = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
if (xmldb_validate_db(db) < 0){
- cprintf(cbx, "No such database: %s", db);
- if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbx))< 0)
- goto done;
- goto ok;
+ cprintf(cbx, "No such database: %s", db);
+ if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbx))< 0)
+ goto done;
+ goto ok;
}
iddb = xmldb_islocked(h, db);
/*
@@ -754,33 +834,33 @@ from_client_unlock(clicon_handle h,
* 1) the specified lock is not currently active
*/
if (iddb == 0){
- cprintf(cbx, "0 ");
- if (netconf_lock_denied(cbret, cbuf_get(cbx), "Unlock failed, lock is not currently active") < 0)
- goto done;
- goto ok;
+ cprintf(cbx, "0 ");
+ if (netconf_lock_denied(cbret, cbuf_get(cbx), "Unlock failed, lock is not currently active") < 0)
+ goto done;
+ goto ok;
}
/* 2) the session issuing the operation is not the same
* session that obtained the lock
*/
else if (iddb != id){
- cprintf(cbx, "%u ", iddb);
- if (netconf_lock_denied(cbret, cbuf_get(cbx), "Unlock failed, lock held by other session") < 0)
- goto done;
- goto ok;
+ cprintf(cbx, "%u ", iddb);
+ if (netconf_lock_denied(cbret, cbuf_get(cbx), "Unlock failed, lock held by other session") < 0)
+ goto done;
+ goto ok;
}
else{
- xmldb_unlock(h, db);
- /* user callback */
- if (clixon_plugin_lockdb_all(h, db, 0, id) < 0)
- goto done;
- if (cprintf(cbret, " ", NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ xmldb_unlock(h, db);
+ /* user callback */
+ if (clixon_plugin_lockdb_all(h, db, 0, id) < 0)
+ goto done;
+ if (cprintf(cbret, " ", NETCONF_BASE_NAMESPACE) < 0)
+ goto done;
}
ok:
retval = 0;
done:
if (cbx)
- cbuf_free(cbx);
+ cbuf_free(cbx);
return retval;
}
@@ -795,16 +875,16 @@ from_client_unlock(clicon_handle h,
*/
static int
from_client_close_session(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
struct client_entry *ce = (struct client_entry *)arg;
uint32_t id = ce->ce_id;
if (release_all_dbs(h, id) < 0)
- return -1;
+ return -1;
stream_ss_delete_all(h, ce_event_cb, (void*)ce);
cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
return 0;
@@ -822,10 +902,10 @@ from_client_close_session(clicon_handle h,
*/
static int
from_client_kill_session(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
uint32_t id; /* session id */
@@ -837,33 +917,33 @@ from_client_kill_session(clicon_handle h,
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)
- goto done;
- goto ok;
+ (str = xml_find_value(x, "body")) == NULL){
+ if (netconf_missing_element(cbret, "protocol", "session-id", NULL) < 0)
+ goto done;
+ goto ok;
}
if ((ret = netconf_parse_uint32("session-id", str, NULL, 0, cbret, &id)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto ok;
+ goto ok;
/* may or may not be in active client list, probably not */
if ((ce = ce_find_byid(backend_client_list(h), id)) != NULL){
- if (release_all_dbs(h, id) < 0)
- goto done;
- backend_client_rm(h, ce); /* Removes client struct */
+ if (release_all_dbs(h, id) < 0)
+ goto done;
+ backend_client_rm(h, ce); /* Removes client struct */
}
if (xmldb_islocked(h, db) == id){
- xmldb_unlock(h, db);
- /* user callback */
- if (clixon_plugin_lockdb_all(h, db, 0, id) < 0)
- goto done;
+ xmldb_unlock(h, db);
+ /* user callback */
+ if (clixon_plugin_lockdb_all(h, db, 0, id) < 0)
+ goto done;
}
cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
ok:
retval = 0;
done:
if (reason)
- free(reason);
+ free(reason);
return retval;
}
@@ -886,10 +966,10 @@ from_client_kill_session(clicon_handle h,
*/
static int
from_client_create_subscription(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
struct client_entry *ce = (struct client_entry *)arg;
@@ -906,47 +986,47 @@ from_client_create_subscription(clicon_handle h,
/* XXX should use prefix cf edit_config */
if ((nsc = xml_nsctx_init(NULL, EVENT_RFC5277_NAMESPACE)) == NULL)
- goto done;
+ goto done;
if ((x = xpath_first(xe, nsc, "//stream")) != NULL)
- stream = xml_find_value(x, "body");
+ stream = xml_find_value(x, "body");
if ((x = xpath_first(xe, nsc, "//stopTime")) != NULL){
- if ((stoptime = xml_find_value(x, "body")) != NULL &&
- str2time(stoptime, &stop) < 0){
- if (netconf_bad_element(cbret, "application", "stopTime", "Expected timestamp") < 0)
- goto done;
- goto ok;
- }
+ if ((stoptime = xml_find_value(x, "body")) != NULL &&
+ str2time(stoptime, &stop) < 0){
+ if (netconf_bad_element(cbret, "application", "stopTime", "Expected timestamp") < 0)
+ goto done;
+ goto ok;
+ }
}
if ((x = xpath_first(xe, nsc, "//startTime")) != NULL){
- if ((starttime = xml_find_value(x, "body")) != NULL &&
- str2time(starttime, &start) < 0){
- if (netconf_bad_element(cbret, "application", "startTime", "Expected timestamp") < 0)
- goto done;
- goto ok;
- }
+ if ((starttime = xml_find_value(x, "body")) != NULL &&
+ str2time(starttime, &start) < 0){
+ if (netconf_bad_element(cbret, "application", "startTime", "Expected timestamp") < 0)
+ goto done;
+ goto ok;
+ }
}
if ((xfilter = xpath_first(xe, nsc, "//filter")) != NULL){
- if ((ftype = xml_find_value(xfilter, "type")) != NULL){
- /* Only accept xpath as filter type */
- if (strcmp(ftype, "xpath") != 0){
- if (netconf_operation_failed(cbret, "application", "Only xpath filter type supported")< 0)
- goto done;
- goto ok;
- }
- if ((selector = xml_find_value(xfilter, "select")) == NULL)
- goto done;
- }
+ if ((ftype = xml_find_value(xfilter, "type")) != NULL){
+ /* Only accept xpath as filter type */
+ if (strcmp(ftype, "xpath") != 0){
+ if (netconf_operation_failed(cbret, "application", "Only xpath filter type supported")< 0)
+ goto done;
+ goto ok;
+ }
+ if ((selector = xml_find_value(xfilter, "select")) == NULL)
+ goto done;
+ }
}
if ((stream_find(h, stream)) == NULL){
- if (netconf_invalid_value(cbret, "application", "No such stream") < 0)
- goto done;
- goto ok;
+ if (netconf_invalid_value(cbret, "application", "No such stream") < 0)
+ goto done;
+ goto ok;
}
/* Add subscriber to stream - to make notifications for this client */
if (stream_ss_add(h, stream, selector,
- starttime?&start:NULL, stoptime?&stop:NULL,
- ce_event_cb, (void*)ce) < 0)
- goto done;
+ 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
* stop (if present).
* RFC 5277: If is not present, this is not a replay
@@ -954,15 +1034,15 @@ from_client_create_subscription(clicon_handle h,
* Schedule the replay to occur right after this RPC completes, eg "now"
*/
if (starttime){
- if (stream_replay_trigger(h, stream, ce_event_cb, (void*)ce) < 0)
- goto done;
+ if (stream_replay_trigger(h, stream, ce_event_cb, (void*)ce) < 0)
+ goto done;
}
cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
ok:
retval = 0;
done:
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
return retval;
}
@@ -977,19 +1057,19 @@ from_client_create_subscription(clicon_handle h,
*/
static int
from_client_debug(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
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;
- goto ok;
+ if (netconf_missing_element(cbret, "application", "level", NULL) < 0)
+ goto done;
+ goto ok;
}
level = atoi(valstr);
@@ -1014,10 +1094,10 @@ from_client_debug(clicon_handle h,
*/
static int
from_client_ping(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
return 0;
@@ -1034,10 +1114,10 @@ from_client_ping(clicon_handle h,
*/
static int
from_client_stats(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
uint64_t nr;
@@ -1054,25 +1134,25 @@ from_client_stats(clicon_handle h,
cprintf(cbret, "%" PRIu64 " ", nr);
cprintf(cbret, "");
if (clixon_stats_datastore_get(h, "running", cbret) < 0)
- goto done;
+ goto done;
if (clixon_stats_datastore_get(h, "candidate", cbret) < 0)
- goto done;
+ goto done;
if (clixon_stats_datastore_get(h, "startup", cbret) < 0)
- goto done;
+ goto done;
ym = NULL;
while ((ym = yn_each(clicon_config_yang(h), ym)) != NULL) {
- if (clixon_stats_module_get(h, ym, cbret) < 0)
- goto done;
+ if (clixon_stats_module_get(h, ym, cbret) < 0)
+ goto done;
}
ym = NULL;
while ((ym = yn_each(clicon_dbspec_yang(h), ym)) != NULL) {
- if (clixon_stats_module_get(h, ym, cbret) < 0)
- goto done;
+ if (clixon_stats_module_get(h, ym, cbret) < 0)
+ goto done;
}
ym = NULL;
while ((ym = yn_each(clicon_nacm_ext_yang(h), ym)) != NULL) {
- if (clixon_stats_module_get(h, ym, cbret) < 0)
- goto done;
+ if (clixon_stats_module_get(h, ym, cbret) < 0)
+ goto done;
}
cprintf(cbret, "");
retval = 0;
@@ -1091,10 +1171,10 @@ from_client_stats(clicon_handle h,
*/
static int
from_client_restart_plugin(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
char *name;
@@ -1105,25 +1185,25 @@ from_client_restart_plugin(clicon_handle h,
int ret;
if (xpath_vec(xe, NULL, "plugin", &vec, &veclen) < 0)
- goto done;
+ goto done;
for (i=0; i ", NETCONF_BASE_NAMESPACE);
ok:
retval = 0;
done:
if (vec)
- free(vec);
+ free(vec);
return retval;
}
@@ -1138,10 +1218,10 @@ from_client_restart_plugin(clicon_handle h,
*/
static int
from_client_process_control(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
cxobj *x;
@@ -1150,21 +1230,21 @@ from_client_process_control(clicon_handle h,
proc_operation op = PROC_OP_NONE;
if ((x = xml_find_type(xe, NULL, "name", CX_ELMNT)) != NULL)
- name = xml_body(x);
+ name = xml_body(x);
if ((x = xml_find_type(xe, NULL, "operation", CX_ELMNT)) != NULL){
- opstr = xml_body(x);
- op = clixon_process_op_str2int(opstr);
+ opstr = xml_body(x);
+ op = clixon_process_op_str2int(opstr);
}
/* Make the actual process operation (with wrap function enabled) */
if (op == PROC_OP_STATUS){
- if (clixon_process_status(h, name, cbret) < 0)
- goto done;
+ if (clixon_process_status(h, name, cbret) < 0)
+ goto done;
}
else{
- if (clixon_process_operation(h, name, op, 1) < 0)
- goto done;
- cprintf(cbret, " ",
- NETCONF_BASE_NAMESPACE, CLIXON_LIB_NS);
+ if (clixon_process_operation(h, name, op, 1) < 0)
+ goto done;
+ cprintf(cbret, " ",
+ NETCONF_BASE_NAMESPACE, CLIXON_LIB_NS);
}
retval = 0;
done:
@@ -1177,21 +1257,21 @@ from_client_process_control(clicon_handle h,
*/
static int
from_client_hello(clicon_handle h,
- cxobj *x,
- struct client_entry *ce,
- cbuf *cbret)
+ cxobj *x,
+ struct client_entry *ce,
+ cbuf *cbret)
{
int retval = -1;
uint32_t id;
if (clicon_session_id_get(h, &id) < 0){
- clicon_err(OE_NETCONF, ENOENT, "session_id not set");
- goto done;
+ clicon_err(OE_NETCONF, ENOENT, "session_id not set");
+ goto done;
}
id++;
clicon_session_id_set(h, id);
cprintf(cbret, "%u ",
- NETCONF_BASE_NAMESPACE, id);
+ NETCONF_BASE_NAMESPACE, id);
retval = 0;
done:
return retval;
@@ -1207,8 +1287,8 @@ from_client_hello(clicon_handle h,
*/
static int
from_client_msg(clicon_handle h,
- struct client_entry *ce,
- struct clicon_msg *msg)
+ struct client_entry *ce,
+ struct clicon_msg *msg)
{
int retval = -1;
cxobj *xt = NULL;
@@ -1237,191 +1317,191 @@ from_client_msg(clicon_handle h,
* as wither rpc-error or by positive response.
*/
if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
/* Decode msg from client -> xml top (ct) and session id
* Bind is a part of the decode function
*/
if ((ret = clicon_msg_decode(msg, yspec, &id, &xt, &xret)) < 0){
- if (netconf_malformed_message(cbret, "XML parse error") < 0)
- goto done;
- goto reply;
+ if (netconf_malformed_message(cbret, "XML parse error") < 0)
+ goto done;
+ goto reply;
}
if (ret == 0){
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- goto reply;
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ goto reply;
}
/* Check for empty frame (no mesaages), return empty message, not clear from RFC what to do */
if (xml_child_nr_type(xt, CX_ELMNT) == 0){
- if (netconf_malformed_message(cbret, "Empty message in netconf rpc frame")< 0)
- goto done;
- goto reply;
+ if (netconf_malformed_message(cbret, "Empty message in netconf rpc frame")< 0)
+ goto done;
+ goto reply;
}
/* Check for multi-messages in frame */
if (xml_child_nr_type(xt, CX_ELMNT) != 1){
- if (netconf_malformed_message(cbret, "More than one message in netconf rpc frame")< 0)
- goto done;
- goto reply;
+ if (netconf_malformed_message(cbret, "More than one message in netconf rpc frame")< 0)
+ goto done;
+ goto reply;
}
if ((x = xml_child_i_type(xt, 0, CX_ELMNT)) == NULL){ /* Shouldnt happen */
- clicon_err(OE_XML, EFAULT, "No xml req (shouldnt happen)");
- goto done;
+ clicon_err(OE_XML, EFAULT, "No xml req (shouldnt happen)");
+ goto done;
}
rpcname = xml_name(x);
rpcprefix = xml_prefix(x);
/* Note that this validation is also made in xml_yang_validate_rpc, but not for hello
*/
if (xml2ns(x, rpcprefix, &namespace) < 0)
- goto done;
+ goto done;
/* Only accept resolved NETCONF base namespace */
if (namespace == NULL){
- if (netconf_bad_element(cbret, "protocol", rpcname, "No namespace associated with prefix") < 0)
- goto done;
- goto reply;
+ if (netconf_bad_element(cbret, "protocol", rpcname, "No namespace associated with prefix") < 0)
+ goto done;
+ goto reply;
}
else if (strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){
- cbuf *cbmsg = NULL;
- if ((cbmsg = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cbmsg, "No appropriate namespace found for: %s %s", rpcprefix, rpcname);
- if (netconf_unknown_namespace(cbret, "protocol", namespace, cbuf_get(cbmsg)) < 0)
- goto done;
- cbuf_free(cbmsg);
- goto reply;
+ cbuf *cbmsg = NULL;
+ if ((cbmsg = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cbmsg, "No appropriate namespace found for: %s %s", rpcprefix, rpcname);
+ if (netconf_unknown_namespace(cbret, "protocol", namespace, cbuf_get(cbmsg)) < 0)
+ goto done;
+ cbuf_free(cbmsg);
+ goto reply;
}
if (strcmp(rpcname, "rpc") == 0){
- ; /* continue below */
+ ; /* continue below */
}
else if (strcmp(rpcname, "hello") == 0){
- if ((ret = from_client_hello(h, x, ce, cbret)) <0)
- goto done;
- goto reply;
+ if ((ret = from_client_hello(h, x, ce, cbret)) <0)
+ goto done;
+ goto reply;
}
else{
- if (netconf_unknown_element(cbret, "protocol", rpcname, "Unrecognized netconf operation")< 0)
- goto done;
- goto reply;
+ if (netconf_unknown_element(cbret, "protocol", rpcname, "Unrecognized netconf operation")< 0)
+ goto done;
+ goto reply;
}
ce->ce_id = id;
if ((ret = xml_yang_validate_rpc(h, x, &xret)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- goto reply;
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ goto reply;
}
xe = NULL;
username = xml_find_value(x, "username");
/* May be used by callbacks, etc */
clicon_username_set(h, username);
while ((xe = xml_child_each(x, xe, CX_ELMNT)) != NULL) {
- rpc = xml_name(xe);
- if ((ye = xml_spec(xe)) == NULL){
- if (netconf_operation_not_supported(cbret, "protocol", rpc) < 0)
- goto done;
- goto reply;
- }
- if ((ymod = ys_module(ye)) == NULL){
- clicon_err(OE_XML, ENOENT, "rpc yang does not have module");
- goto done;
- }
- module = yang_argument_get(ymod);
- clicon_debug(1, "%s module:%s rpc:%s", __FUNCTION__, module, rpc);
- /* Pre-NACM access step */
- xnacm = NULL;
+ rpc = xml_name(xe);
+ if ((ye = xml_spec(xe)) == NULL){
+ if (netconf_operation_not_supported(cbret, "protocol", rpc) < 0)
+ goto done;
+ goto reply;
+ }
+ if ((ymod = ys_module(ye)) == NULL){
+ clicon_err(OE_XML, ENOENT, "rpc yang does not have module");
+ goto done;
+ }
+ module = yang_argument_get(ymod);
+ clicon_debug(1, "%s module:%s rpc:%s", __FUNCTION__, module, rpc);
+ /* Pre-NACM access step */
+ xnacm = NULL;
- /* NACM intial pre- access control enforcements. Retval:
- * 0: Use NACM validation and xnacm is set.
- * 1: Permit, skip NACM
- * Therefore, xnacm=NULL means no NACM checks needed.
- */
- if ((ret = nacm_access_pre(h, ce->ce_username, username, &xnacm)) < 0)
- goto done;
- /* Cache XML NACM tree here. Use with caution, only valid on from_client_msg stack
- */
- if (clicon_nacm_cache_set(h, xnacm) < 0)
- goto done;
- if (ret == 0){ /* Do NACM RPC validation */
- creds = clicon_nacm_credentials(h);
- if ((ret = verify_nacm_user(h, creds, ce->ce_username, username, cbret)) < 0)
- goto done;
- if (ret == 0) /* credentials fail */
- goto reply;
- /* NACM rpc operation exec validation */
- if ((ret = nacm_rpc(rpc, module, username, xnacm, cbret)) < 0)
- goto done;
- if (ret == 0) /* Not permitted and cbret set */
- goto reply;
- }
- clicon_err_reset();
- if ((ret = rpc_callback_call(h, xe, ce, &nr, cbret)) < 0){
- if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
- goto done;
- clicon_log(LOG_NOTICE, "%s Error in rpc_callback_call:%s", __FUNCTION__, xml_name(xe));
- goto reply; /* Dont quit here on user callbacks */
- }
- if (ret == 0)
- goto reply;
- if (nr == 0){ /* not handled by callback */
- if (netconf_operation_not_supported(cbret, "application", "RPC operation not supported")< 0)
- goto done;
- goto reply;
- }
- if (xnacm){
- xml_free(xnacm);
- xnacm = NULL;
- if (clicon_nacm_cache_set(h, NULL) < 0)
- goto done;
- }
+ /* NACM intial pre- access control enforcements. Retval:
+ * 0: Use NACM validation and xnacm is set.
+ * 1: Permit, skip NACM
+ * Therefore, xnacm=NULL means no NACM checks needed.
+ */
+ if ((ret = nacm_access_pre(h, ce->ce_username, username, &xnacm)) < 0)
+ goto done;
+ /* Cache XML NACM tree here. Use with caution, only valid on from_client_msg stack
+ */
+ if (clicon_nacm_cache_set(h, xnacm) < 0)
+ goto done;
+ if (ret == 0){ /* Do NACM RPC validation */
+ creds = clicon_nacm_credentials(h);
+ if ((ret = verify_nacm_user(h, creds, ce->ce_username, username, cbret)) < 0)
+ goto done;
+ if (ret == 0) /* credentials fail */
+ goto reply;
+ /* NACM rpc operation exec validation */
+ if ((ret = nacm_rpc(rpc, module, username, xnacm, cbret)) < 0)
+ goto done;
+ if (ret == 0) /* Not permitted and cbret set */
+ goto reply;
+ }
+ clicon_err_reset();
+ if ((ret = rpc_callback_call(h, xe, ce, &nr, cbret)) < 0){
+ if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
+ goto done;
+ clicon_log(LOG_NOTICE, "%s Error in rpc_callback_call:%s", __FUNCTION__, xml_name(xe));
+ goto reply; /* Dont quit here on user callbacks */
+ }
+ if (ret == 0)
+ goto reply;
+ if (nr == 0){ /* not handled by callback */
+ if (netconf_operation_not_supported(cbret, "application", "RPC operation not supported")< 0)
+ goto done;
+ goto reply;
+ }
+ if (xnacm){
+ xml_free(xnacm);
+ xnacm = NULL;
+ if (clicon_nacm_cache_set(h, NULL) < 0)
+ goto done;
+ }
} /* while */
reply:
if (cbuf_len(cbret) == 0)
- if (netconf_operation_failed(cbret, "application", clicon_errno?clicon_err_reason:"unknown")< 0)
- goto done;
+ if (netconf_operation_failed(cbret, "application", clicon_errno?clicon_err_reason:"unknown")< 0)
+ goto done;
clicon_debug(1, "%s cbret:%s", __FUNCTION__, cbuf_get(cbret));
/* XXX problem here is that cbret has not been parsed so may contain
parse errors */
if (send_msg_reply(ce->ce_s, cbuf_get(cbret), cbuf_len(cbret)+1) < 0){
- switch (errno){
- case EPIPE:
- /* man (2) write:
- * EPIPE fd is connected to a pipe or socket whose reading end is
- * closed. When this happens the writing process will also receive
- * a SIGPIPE signal.
- * In Clixon this means a client, eg restconf, netconf or cli closes
- * the (UNIX domain) socket.
- */
- case ECONNRESET:
- clicon_log(LOG_WARNING, "client rpc reset");
- break;
- default:
- goto done;
- }
+ switch (errno){
+ case EPIPE:
+ /* man (2) write:
+ * EPIPE fd is connected to a pipe or socket whose reading end is
+ * closed. When this happens the writing process will also receive
+ * a SIGPIPE signal.
+ * In Clixon this means a client, eg restconf, netconf or cli closes
+ * the (UNIX domain) socket.
+ */
+ case ECONNRESET:
+ clicon_log(LOG_WARNING, "client rpc reset");
+ break;
+ default:
+ goto done;
+ }
}
// ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (xnacm){
- xml_free(xnacm);
- if (clicon_nacm_cache_set(h, NULL) < 0)
- goto done;
+ xml_free(xnacm);
+ if (clicon_nacm_cache_set(h, NULL) < 0)
+ goto done;
}
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (xt)
- xml_free(xt);
+ xml_free(xt);
if (cbret)
- cbuf_free(cbret);
+ cbuf_free(cbret);
/* Sanity: log if clicon_err() is not called ! */
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_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);
return retval;// -1 here terminates backend
}
@@ -1435,7 +1515,7 @@ from_client_msg(clicon_handle h,
*/
int
from_client(int s,
- void* arg)
+ void* arg)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -1445,21 +1525,21 @@ from_client(int s,
clicon_debug(1, "%s", __FUNCTION__);
if (s != ce->ce_s){
- clicon_err(OE_NETCONF, EINVAL, "Internal error: s != ce->ce_s");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "Internal error: s != ce->ce_s");
+ goto done;
}
if (clicon_msg_rcv(ce->ce_s, &msg, &eof) < 0)
- goto done;
+ goto done;
if (eof)
- backend_client_rm(h, ce);
+ backend_client_rm(h, ce);
else
- if (from_client_msg(h, ce, msg) < 0)
- goto done;
+ if (from_client_msg(h, ce, msg) < 0)
+ goto done;
retval = 0;
done:
clicon_debug(1, "%s retval=%d", __FUNCTION__, retval);
if (msg)
- free(msg);
+ free(msg);
return retval; /* -1 here terminates backend */
}
@@ -1476,70 +1556,70 @@ backend_rpc_init(clicon_handle h)
/* In backend_client.? RFC 6241 */
if (rpc_callback_register(h, from_client_get_config, NULL,
- NETCONF_BASE_NAMESPACE, "get-config") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "get-config") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_edit_config, NULL,
- NETCONF_BASE_NAMESPACE, "edit-config") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "edit-config") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_copy_config, NULL,
- NETCONF_BASE_NAMESPACE, "copy-config") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "copy-config") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_delete_config, NULL,
- NETCONF_BASE_NAMESPACE, "delete-config") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "delete-config") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_lock, NULL,
- NETCONF_BASE_NAMESPACE, "lock") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "lock") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_unlock, NULL,
- NETCONF_BASE_NAMESPACE, "unlock") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "unlock") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_get, NULL,
- NETCONF_BASE_NAMESPACE, "get") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "get") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_close_session, NULL,
- NETCONF_BASE_NAMESPACE, "close-session") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "close-session") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_kill_session, NULL,
- NETCONF_BASE_NAMESPACE, "kill-session") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "kill-session") < 0)
+ goto done;
if (rpc_callback_register(h, action_callback_call, NULL,
- YANG_XML_NAMESPACE, "action") < 0)
- goto done;
+ YANG_XML_NAMESPACE, "action") < 0)
+ goto done;
/* In backend_commit.? */
if (rpc_callback_register(h, from_client_commit, NULL,
- NETCONF_BASE_NAMESPACE, "commit") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "commit") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_discard_changes, NULL,
- NETCONF_BASE_NAMESPACE, "discard-changes") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "discard-changes") < 0)
+ goto done;
/* if-feature confirmed-commit */
if (rpc_callback_register(h, from_client_cancel_commit, NULL,
- NETCONF_BASE_NAMESPACE, "cancel-commit") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "cancel-commit") < 0)
+ goto done;
/* if-feature validate */
if (rpc_callback_register(h, from_client_validate, NULL,
- NETCONF_BASE_NAMESPACE, "validate") < 0)
- goto done;
+ NETCONF_BASE_NAMESPACE, "validate") < 0)
+ goto done;
/* In backend_client.? RPC from RFC 5277 */
if (rpc_callback_register(h, from_client_create_subscription, NULL,
- EVENT_RFC5277_NAMESPACE, "create-subscription") < 0)
- goto done;
+ EVENT_RFC5277_NAMESPACE, "create-subscription") < 0)
+ goto done;
/* Clixon RPC */
if (rpc_callback_register(h, from_client_debug, NULL,
- CLIXON_LIB_NS, "debug") < 0)
- goto done;
+ CLIXON_LIB_NS, "debug") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_ping, NULL,
- CLIXON_LIB_NS, "ping") < 0)
- goto done;
+ CLIXON_LIB_NS, "ping") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_stats, NULL,
- CLIXON_LIB_NS, "stats") < 0)
- goto done;
+ CLIXON_LIB_NS, "stats") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_restart_plugin, NULL,
- CLIXON_LIB_NS, "restart-plugin") < 0)
- goto done;
+ CLIXON_LIB_NS, "restart-plugin") < 0)
+ goto done;
if (rpc_callback_register(h, from_client_process_control, NULL,
- CLIXON_LIB_NS, "process-control") < 0)
- goto done;
+ CLIXON_LIB_NS, "process-control") < 0)
+ goto done;
retval =0;
done:
return retval;
diff --git a/apps/backend/backend_client.h b/apps/backend/backend_client.h
index 8aaf2244..18251e69 100644
--- a/apps/backend/backend_client.h
+++ b/apps/backend/backend_client.h
@@ -51,7 +51,7 @@ struct client_entry{
int ce_nr; /* Client number (for dbg/tracing) */
int ce_stat_in; /* Nr of received msgs from client */
int ce_stat_out;/* Nr of sent msgs to client */
- int ce_id; /* Session id */
+ uint32_t ce_id; /* Session id, accessor functions: clicon_session_id_get/set */
char *ce_username;/* Translated from peer user cred */
clicon_handle ce_handle; /* clicon config handle (all clients have same?) */
};
diff --git a/apps/backend/backend_commit.c b/apps/backend/backend_commit.c
index 969ba75f..7af3470e 100644
--- a/apps/backend/backend_commit.c
+++ b/apps/backend/backend_commit.c
@@ -32,7 +32,7 @@
the terms of any one of the Apache License version 2 or the GPL.
***** END LICENSE BLOCK *****
-
+ Commit and validate
*/
#ifdef HAVE_CONFIG_H
@@ -89,9 +89,9 @@
*/
static int
generic_validate(clicon_handle h,
- yang_stmt *yspec,
- transaction_data_t *td,
- cxobj **xret)
+ yang_stmt *yspec,
+ transaction_data_t *td,
+ cxobj **xret)
{
int retval = -1;
cxobj *x2;
@@ -101,31 +101,31 @@ generic_validate(clicon_handle h,
/* All entries */
if ((ret = xml_yang_validate_all_top(h, td->td_target, xret)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* changed entries */
for (i=0; itd_clen; i++){
- x2 = td->td_tcvec[i]; /* target changed */
- /* Should this be recursive? */
- if ((ret = xml_yang_validate_add(h, x2, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ x2 = td->td_tcvec[i]; /* target changed */
+ /* Should this be recursive? */
+ if ((ret = xml_yang_validate_add(h, x2, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
/* added entries */
for (i=0; itd_alen; i++){
- x2 = td->td_avec[i];
- if ((ret = xml_yang_validate_add(h, x2, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ x2 = td->td_avec[i];
+ if ((ret = xml_yang_validate_add(h, x2, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
// ok:
retval = 1;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
fail:
retval = 0;
@@ -156,9 +156,9 @@ generic_validate(clicon_handle h,
*/
static int
startup_common(clicon_handle h,
- char *db,
- transaction_data_t *td,
- cbuf *cbret)
+ char *db,
+ transaction_data_t *td,
+ cbuf *cbret)
{
int retval = -1;
yang_stmt *yspec;
@@ -173,149 +173,154 @@ startup_common(clicon_handle h,
* potentially non-matching module-state in msdiff
*/
if (clicon_option_bool(h, "CLICON_XMLDB_MODSTATE"))
- if ((msdiff = modstate_diff_new()) == NULL)
- goto done;
+ if ((msdiff = modstate_diff_new()) == NULL)
+ goto done;
clicon_debug(1, "Reading startup config from %s", db);
/* Get the startup datastore WITHOUT binding to YANG, sorting and default setting.
* It is done below, later in this function
*/
if (clicon_option_bool(h, "CLICON_XMLDB_UPGRADE_CHECKOLD")){
- if ((ret = xmldb_get0(h, db, YB_MODULE, NULL, "/", 0, &xt, msdiff, &xerr)) < 0)
- goto done;
- if (ret == 0){ /* ret should not be 0 */
- /* Print upgraded db: -q backend switch for debugging/ showing upgraded config only */
- 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
- * See similar clause below
- */
- }
- if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
- goto done;
- goto fail;
- }
+ if ((ret = xmldb_get0(h, db, YB_MODULE, NULL, "/", 0, &xt, msdiff, &xerr)) < 0)
+ goto done;
+ if (ret == 0){ /* ret should not be 0 */
+ /* Print upgraded db: -q backend switch for debugging/ showing upgraded config only */
+ 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
+ * See similar clause below
+ */
+ }
+ if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
+ goto done;
+ goto fail;
+ }
}
else {
- if (xmldb_get0(h, db, YB_NONE, NULL, "/", 0, &xt, msdiff, &xerr) < 0)
- goto done;
+ if (xmldb_get0(h, db, YB_NONE, NULL, "/", 0, &xt, msdiff, &xerr) < 0)
+ goto done;
+ }
+ 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"
+ "It may also be normal bootstrapping since module state will be written on next datastore save");
}
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_YANG, 0, "Yang spec not set");
- goto done;
+ clicon_err(OE_YANG, 0, "Yang spec not set");
+ goto done;
}
clicon_debug(1, "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));
+ (void*)(XML_FLAG_MARK|XML_FLAG_CHANGE));
/* Here xt is old syntax */
/* General purpose datastore upgrade */
if (clixon_plugin_datastore_upgrade_all(h, db, xt, msdiff) < 0)
goto done;
/* Module-specific upgrade callbacks */
if (msdiff){
- if ((ret = clixon_module_upgrade(h, xt, msdiff, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = clixon_module_upgrade(h, xt, msdiff, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
/* Print upgraded db: -q backend switch for debugging/ showing upgraded config only */
if (clicon_quit_upgrade_get(h) == 1){
- /* bind yang */
- if ((ret = xml_bind_yang(xt, YB_MODULE, yspec, &xret)) < 1){
- if (ret == 0){
- /* invalid */
- clicon_err(OE_XML, EFAULT, "invalid configuration");
- }
- else {
- /* error */
- xml_print(stderr, xret);
- clicon_err(OE_XML, 0, "%s: YANG binding error", __func__);
- }
- } /* sort yang */
- else if (xml_sort_recurse(xt) < 0) {
- clicon_err(OE_XML, EFAULT, "Yang sort error");
+ /* bind yang */
+ if ((ret = xml_bind_yang(xt, YB_MODULE, yspec, &xret)) < 1){
+ if (ret == 0){
+ /* invalid */
+ clicon_err(OE_XML, EFAULT, "invalid configuration");
+ }
+ else {
+ /* error */
+ xml_print(stderr, xret);
+ clicon_err(OE_XML, 0, "%s: YANG binding error", __func__);
+ }
+ } /* sort yang */
+ else if (xml_sort_recurse(xt) < 0) {
+ clicon_err(OE_XML, EFAULT, "Yang sort error");
}
- if (xmldb_dump(h, stdout, xt) < 0)
- goto done;
- exit(0); /* This is fairly abrupt , but need to avoid side-effects of rewinding
- stack. Alternative is to make a separate function stack for this. */
+ if (xmldb_dump(h, stdout, xt) < 0)
+ goto done;
+ exit(0); /* This is fairly abrupt , but need to avoid side-effects of rewinding
+ 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){
- td->td_target = xt;
- xt = NULL;
- goto ok;
+ td->td_target = xt;
+ xt = NULL;
+ goto ok;
}
/* After upgrading, XML tree needs to be sorted and yang spec populated */
if ((ret = xml_bind_yang(xt, YB_MODULE, yspec, &xret)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- goto fail;
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ goto fail;
}
/* After upgrade check no state data */
if ((ret = xml_non_config_data(xt, &xret)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- goto fail;
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ goto fail;
}
/* Sort xml */
if (xml_sort_recurse(xt) < 0)
- goto done;
+ goto done;
/* Add global defaults. */
if (xml_global_defaults(h, xt, NULL, NULL, yspec, 0) < 0)
- goto done;
+ goto done;
/* Apply default values (removed in clear function) */
if (xml_default_recurse(xt, 0) < 0)
- goto done;
+ goto done;
/* Handcraft transition with with only add tree */
td->td_target = xt;
xt = NULL;
x = NULL;
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)
- goto done;
+ 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)
+ goto done;
}
/* 4. Call plugin transaction start callbacks */
if (plugin_transaction_begin_all(h, td) < 0)
- goto done;
+ goto done;
/* 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);
if ((ret = generic_validate(h, yspec, td, &xret)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- goto fail; /* STARTUP_INVALID */
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ goto fail; /* STARTUP_INVALID */
}
/* 6. Call plugin transaction validate callbacks */
if (plugin_transaction_validate_all(h, td) < 0)
- goto done;
+ goto done;
/* 7. Call plugin transaction complete callbacks */
if (plugin_transaction_complete_all(h, td) < 0)
- goto done;
+ goto done;
ok:
retval = 1;
done:
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (xt)
- xml_free(xt);
+ xml_free(xt);
if (msdiff)
- modstate_diff_free(msdiff);
+ modstate_diff_free(msdiff);
return retval;
fail:
retval = 0;
@@ -334,9 +339,9 @@ startup_common(clicon_handle h,
*/
int
startup_validate(clicon_handle h,
- char *db,
- cxobj **xtr,
- cbuf *cbret)
+ char *db,
+ cxobj **xtr,
+ cbuf *cbret)
{
int retval = -1;
int ret;
@@ -344,28 +349,28 @@ startup_validate(clicon_handle h,
/* Handcraft a transition with only target and add trees */
if ((td = transaction_new()) == NULL)
- goto done;
+ goto done;
if ((ret = startup_common(h, db, td, cbret)) < 0){
- plugin_transaction_abort_all(h, td);
- goto done;
+ plugin_transaction_abort_all(h, td);
+ goto done;
}
if (ret == 0){
- plugin_transaction_abort_all(h, td);
- goto fail;
+ plugin_transaction_abort_all(h, td);
+ goto fail;
}
plugin_transaction_end_all(h, td);
/* Clear cached trees from default values and marking */
if (xmldb_get0_clear(h, td->td_target) < 0)
- goto done;
+ goto done;
if (xtr){
- *xtr = td->td_target;
- td->td_target = NULL;
+ *xtr = td->td_target;
+ td->td_target = NULL;
}
retval = 1;
done:
if (td){
- xmldb_get0_free(h, &td->td_target);
- transaction_free(td);
+ xmldb_get0_free(h, &td->td_target);
+ transaction_free(td);
}
return retval;
fail: /* cbret should be set */
@@ -385,64 +390,64 @@ startup_validate(clicon_handle h,
*/
int
startup_commit(clicon_handle h,
- char *db,
- cbuf *cbret)
+ char *db,
+ cbuf *cbret)
{
int retval = -1;
int ret;
transaction_data_t *td = NULL;
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;
}
/* Handcraft a transition with only target and add trees */
if ((td = transaction_new()) == NULL)
- goto done;
+ goto done;
if ((ret = startup_common(h, db, td, cbret)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* 8. Call plugin transaction commit callbacks */
if (plugin_transaction_commit_all(h, td) < 0)
- goto done;
+ goto done;
/* After commit, make a post-commit call (sure that all plugins have committed) */
if (plugin_transaction_commit_done_all(h, td) < 0)
- goto done;
+ goto done;
/* Clear cached trees from default values and marking */
if (xmldb_get0_clear(h, td->td_target) < 0)
- goto done;
+ goto done;
/* [Delete and] create running db */
if (xmldb_exists(h, "running") == 1){
- if (xmldb_delete(h, "running") != 0 && errno != ENOENT)
- goto done;;
+ if (xmldb_delete(h, "running") != 0 && errno != ENOENT)
+ goto done;;
}
if (xmldb_create(h, "running") < 0)
- goto done;
+ goto done;
/* 9, write (potentially modified) tree to running
* XXX note here startup is copied to candidate, which may confuse everything
* XXX default values are overwritten
*/
if (td->td_target)
- /* target is datastore, but is here transformed to mimic an incoming
- * edit-config
- */
- xml_name_set(td->td_target, NETCONF_INPUT_CONFIG);
+ /* target is datastore, but is here transformed to mimic an incoming
+ * edit-config
+ */
+ xml_name_set(td->td_target, NETCONF_INPUT_CONFIG);
if ((ret = xmldb_put(h, "running", OP_REPLACE, td->td_target,
- clicon_username_get(h), cbret)) < 0)
- goto done;
+ clicon_username_get(h), cbret)) < 0)
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* 10. Call plugin transaction end callbacks */
plugin_transaction_end_all(h, td);
retval = 1;
done:
if (td){
- if (retval < 1)
- plugin_transaction_abort_all(h, td);
- xmldb_get0_free(h, &td->td_target);
- transaction_free(td);
+ if (retval < 1)
+ plugin_transaction_abort_all(h, td);
+ xmldb_get0_free(h, &td->td_target);
+ transaction_free(td);
}
return retval;
fail: /* cbret should be set */
@@ -465,9 +470,9 @@ startup_commit(clicon_handle h,
*/
static int
validate_common(clicon_handle h,
- char *db,
- transaction_data_t *td,
- cxobj **xret)
+ char *db,
+ transaction_data_t *td,
+ cxobj **xret)
{
int retval = -1;
yang_stmt *yspec;
@@ -476,79 +481,79 @@ validate_common(clicon_handle h,
int ret;
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
- }
+ 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, &td->td_target, NULL, xret)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* 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));
+ (void*)(XML_FLAG_MARK|XML_FLAG_CHANGE));
/* 2. Parse xml trees
* This is the state we are going from */
if ((ret = xmldb_get0(h, "running", YB_MODULE, NULL, "/", 0, &td->td_src, NULL, xret)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* Clear flags xpath for get */
xml_apply0(td->td_src, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset,
- (void*)(XML_FLAG_MARK|XML_FLAG_CHANGE));
+ (void*)(XML_FLAG_MARK|XML_FLAG_CHANGE));
/* 3. Compute differences */
if (xml_diff(yspec,
- td->td_src,
- td->td_target,
- &td->td_dvec, /* removed: only in running */
- &td->td_dlen,
- &td->td_avec, /* added: only in candidate */
- &td->td_alen,
- &td->td_scvec, /* changed: original values */
- &td->td_tcvec, /* changed: wanted values */
- &td->td_clen) < 0)
- goto done;
+ td->td_src,
+ td->td_target,
+ &td->td_dvec, /* removed: only in running */
+ &td->td_dlen,
+ &td->td_avec, /* added: only in candidate */
+ &td->td_alen,
+ &td->td_scvec, /* changed: original values */
+ &td->td_tcvec, /* changed: wanted values */
+ &td->td_clen) < 0)
+ goto done;
if (clicon_debug_get()>1)
- transaction_print(stderr, td);
+ transaction_print(stderr, td);
/* Mark as changed in tree */
for (i=0; itd_dlen; i++){ /* Also down */
- xn = td->td_dvec[i];
- xml_flag_set(xn, XML_FLAG_DEL);
- xml_apply(xn, CX_ELMNT, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_DEL);
- xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
+ xn = td->td_dvec[i];
+ xml_flag_set(xn, XML_FLAG_DEL);
+ xml_apply(xn, CX_ELMNT, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_DEL);
+ xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
}
for (i=0; itd_alen; i++){ /* Also down */
- xn = td->td_avec[i];
- xml_flag_set(xn, XML_FLAG_ADD);
- xml_apply(xn, CX_ELMNT, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_ADD);
- xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
+ xn = td->td_avec[i];
+ xml_flag_set(xn, XML_FLAG_ADD);
+ xml_apply(xn, CX_ELMNT, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_ADD);
+ xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
}
for (i=0; itd_clen; i++){ /* Also up */
- xn = td->td_scvec[i];
- xml_flag_set(xn, XML_FLAG_CHANGE);
- xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
- xn = td->td_tcvec[i];
- xml_flag_set(xn, XML_FLAG_CHANGE);
- xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
+ xn = td->td_scvec[i];
+ xml_flag_set(xn, XML_FLAG_CHANGE);
+ xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
+ xn = td->td_tcvec[i];
+ xml_flag_set(xn, XML_FLAG_CHANGE);
+ xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
}
/* 4. Call plugin transaction start callbacks */
if (plugin_transaction_begin_all(h, td) < 0)
- goto done;
+ goto done;
/* 5. Make generic validation on all new or changed data.
Note this is only call that uses 3-values */
if ((ret = generic_validate(h, yspec, td, xret)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* 6. Call plugin transaction validate callbacks */
if (plugin_transaction_validate_all(h, td) < 0)
- goto done;
+ goto done;
/* 7. Call plugin transaction complete callbacks */
if (plugin_transaction_complete_all(h, td) < 0)
- goto done;
+ goto done;
retval = 1;
done:
return retval;
@@ -567,8 +572,8 @@ validate_common(clicon_handle h,
*/
int
candidate_validate(clicon_handle h,
- char *db,
- cbuf *cbret)
+ char *db,
+ cbuf *cbret)
{
int retval = -1;
transaction_data_t *td = NULL;
@@ -577,51 +582,51 @@ candidate_validate(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (db == NULL || cbret == NULL){
- clicon_err(OE_CFG, EINVAL, "db or cbret is NULL");
- goto done;
+ clicon_err(OE_CFG, EINVAL, "db or cbret is NULL");
+ goto done;
}
/* 1. Start transaction */
if ((td = transaction_new()) == NULL)
- goto done;
+ goto done;
/* Common steps (with commit) */
if ((ret = validate_common(h, db, td, &xret)) < 0){
- /* A little complex due to several sources of validation fails or errors.
- * (1) xerr is set -> translate to cbret; (2) cbret set use that; otherwise
- * use clicon_err.
- * TODO: -1 return should be fatal error, not failed validation
- */
- if (!cbuf_len(cbret) &&
- netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
- goto done;
- goto fail;
+ /* A little complex due to several sources of validation fails or errors.
+ * (1) xerr is set -> translate to cbret; (2) cbret set use that; otherwise
+ * use clicon_err.
+ * TODO: -1 return should be fatal error, not failed validation
+ */
+ if (!cbuf_len(cbret) &&
+ netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
+ goto done;
+ goto fail;
}
if (ret == 0){
- if (xret == NULL){
- clicon_err(OE_CFG, EINVAL, "xret is NULL");
- goto done;
- }
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- if (!cbuf_len(cbret) &&
- netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
- goto done;
- goto fail;
+ if (xret == NULL){
+ clicon_err(OE_CFG, EINVAL, "xret is NULL");
+ goto done;
+ }
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ if (!cbuf_len(cbret) &&
+ netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
+ goto done;
+ goto fail;
}
if (xmldb_get0_clear(h, td->td_src) < 0 ||
- xmldb_get0_clear(h, td->td_target) < 0)
- goto done;
+ xmldb_get0_clear(h, td->td_target) < 0)
+ goto done;
plugin_transaction_end_all(h, td);
retval = 1;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (td){
- if (retval < 1)
- plugin_transaction_abort_all(h, td);
- xmldb_get0_free(h, &td->td_target);
- xmldb_get0_free(h, &td->td_src);
- transaction_free(td);
+ if (retval < 1)
+ plugin_transaction_abort_all(h, td);
+ xmldb_get0_free(h, &td->td_target);
+ xmldb_get0_free(h, &td->td_src);
+ transaction_free(td);
}
return retval;
fail:
@@ -629,69 +634,97 @@ candidate_validate(clicon_handle h,
goto done;
}
+
/*! Do a diff between candidate and running, then start a commit transaction
*
* 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] db A candidate database, not necessarily "candidate"
- * @retval -1 Error - or validation failed
- * @retval 0 Validation failed (with cbret set)
- * @retval 1 Validation OK
+ * @param[in] h Clicon handle
+ * @param[in] xe Request: (or NULL)
+ * @param[in] session_id Client session id, only if xe
+ * @param[in] db A candidate database, not necessarily "candidate"
+ * @param[out] cbret Return xml tree, eg ..., td_target) < 0)
- goto done;
+ goto done;
if (xmldb_get0_clear(h, td->td_src) < 0)
- goto done;
+ goto done;
/* 8. Success: Copy candidate to running
*/
if (xmldb_copy(h, db, "running") < 0)
- goto done;
+ goto done;
xmldb_modified_set(h, db, 0); /* reset dirty bit */
/* Here pointers to old (source) tree are obsolete */
if (td->td_dvec){
- td->td_dlen = 0;
- free(td->td_dvec);
- td->td_dvec = NULL;
+ td->td_dlen = 0;
+ free(td->td_dvec);
+ td->td_dvec = NULL;
}
if (td->td_scvec){
- free(td->td_scvec);
- td->td_scvec = NULL;
+ free(td->td_scvec);
+ td->td_scvec = NULL;
}
/* 9. Call plugin transaction end callbacks */
@@ -701,20 +734,20 @@ candidate_commit(clicon_handle h,
done:
/* In case of failure (or error), call plugin transaction termination callbacks */
if (td){
- if (retval < 1)
- plugin_transaction_abort_all(h, td);
- xmldb_get0_free(h, &td->td_target);
- xmldb_get0_free(h, &td->td_src);
- transaction_free(td);
+ if (retval < 1)
+ plugin_transaction_abort_all(h, td);
+ xmldb_get0_free(h, &td->td_target);
+ xmldb_get0_free(h, &td->td_src);
+ transaction_free(td);
}
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
fail:
retval = 0;
goto done;
}
-
+
/*! Commit the candidate configuration as the device's new current configuration
*
* @param[in] h Clicon handle
@@ -728,13 +761,26 @@ candidate_commit(clicon_handle h,
* configuration datastore that are actually different and only check
* "create", "update", and "delete" access permissions for this set of
* nodes, which could be empty.
+ *
+ * Handling of the first phase of confirmed-commit:
+ * First, it must be determined if the given RPC constitutes a "confirming-commit", roughly meaning:
+ * 1) it was issued in the same session as a prior confirmed-commit
+ * 2) it bears a element matching the element that accompanied the prior confirmed-commit
+ *
+ * If it is a valid "confirming-commit" and this RPC does not bear another element, then the
+ * confirmed-commit is complete, the rollback event can be cancelled and the rollback database deleted.
+ *
+ * No further action is necessary as the candidate configuration was already copied to the running configuration.
+ *
+ * If the RPC does bear another element, that will be handled in phase two, from within the
+ * candidate_commit() method.
*/
int
from_client_commit(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
struct client_entry *ce = (struct client_entry *)arg;
@@ -742,33 +788,45 @@ from_client_commit(clicon_handle h,
uint32_t iddb;
cbuf *cbx = NULL; /* Assist cbuf */
int ret;
+ yang_stmt *yspec;
+
+ if ((yspec = clicon_dbspec_yang(h)) == NULL) {
+ clicon_err(OE_YANG, ENOENT, "No yang spec");
+ goto done;
+ }
+
+ if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) {
+ if ((ret = from_client_confirmed_commit(h, xe, myid, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto ok;
+ }
/* Check if target locked by other client */
iddb = xmldb_islocked(h, "running");
if (iddb && myid != iddb){
- if ((cbx = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- cprintf(cbx, "%u ", iddb);
- if (netconf_in_use(cbret, cbuf_get(cbx), "Operation failed, lock is already held") < 0)
- goto done;
- goto ok;
+ 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, "candidate", cbret)) < 0){ /* Assume validation fail, nofatal */
- clicon_debug(1, "Commit candidate failed");
- if (ret < 0)
- if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
- goto done;
+ if ((ret = candidate_commit(h, xe, "candidate", cbret)) < 0){ /* Assume validation fail, nofatal */
+ clicon_debug(1, "Commit candidate failed");
+ if (ret < 0)
+ if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
+ goto done;
goto ok;
}
if (ret == 1)
- cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
+ cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
ok:
retval = 0;
done:
if (cbx)
- cbuf_free(cbx);
+ cbuf_free(cbx);
return retval; /* may be zero if we ignoring errors from commit */
} /* from_client_commit */
@@ -786,10 +844,10 @@ from_client_commit(clicon_handle h,
*/
int
from_client_discard_changes(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
struct client_entry *ce = (struct client_entry *)arg;
@@ -800,19 +858,19 @@ from_client_discard_changes(clicon_handle h,
/* 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, "%u ", iddb);
- if (netconf_lock_denied(cbret, cbuf_get(cbx), "Operation failed, lock is already held") < 0)
- goto done;
- goto ok;
+ if ((cbx = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cbx, "%u ", iddb);
+ if (netconf_lock_denied(cbret, cbuf_get(cbx), "Operation failed, lock is already held") < 0)
+ goto done;
+ goto ok;
}
if (xmldb_copy(h, "running", "candidate") < 0){
- if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
- goto done;
- goto ok;
+ if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
+ goto done;
+ goto ok;
}
xmldb_modified_set(h, "candidate", 0); /* reset dirty bit */
cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
@@ -820,37 +878,10 @@ from_client_discard_changes(clicon_handle h,
retval = 0;
done:
if (cbx)
- cbuf_free(cbx);
+ cbuf_free(cbx);
return retval; /* may be zero if we ignoring errors from commit */
}
-/*! 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.
- *
- * @param[in] h Clicon handle
- * @param[in] xe Request:
- * @param[out] cbret Return xml tree, eg ...,
@@ -863,10 +894,10 @@ from_client_cancel_commit(clicon_handle h,
*/
int
from_client_validate(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
int ret;
@@ -874,14 +905,14 @@ from_client_validate(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if ((db = netconf_db_find(xe, "source")) == NULL){
- if (netconf_missing_element(cbret, "protocol", "source", NULL) < 0)
- goto done;
- goto ok;
+ if (netconf_missing_element(cbret, "protocol", "source", NULL) < 0)
+ goto done;
+ goto ok;
}
if ((ret = candidate_validate(h, db, cbret)) < 0)
- goto done;
+ goto done;
if (ret == 1)
- cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
+ cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
ok:
retval = 0;
done:
@@ -894,8 +925,8 @@ from_client_validate(clicon_handle h,
*/
int
from_client_restart_one(clicon_handle h,
- clixon_plugin_t *cp,
- cbuf *cbret)
+ clixon_plugin_t *cp,
+ cbuf *cbret)
{
int retval = -1;
char *db = "tmp";
@@ -910,100 +941,100 @@ from_client_restart_one(clicon_handle h,
yspec = clicon_dbspec_yang(h);
if (xmldb_db_reset(h, db) < 0)
- goto done;
+ goto done;
/* Application may define extra xml in its reset function*/
if ((resetfn = 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 ((retval = resetfn(h, db)) < 0) {
- clicon_debug(1, "plugin_start() failed");
- 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 ((retval = resetfn(h, db)) < 0) {
+ clicon_debug(1, "plugin_start() failed");
+ goto done;
+ }
+ if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
+ goto done;
}
/* 1. Start transaction */
if ((td = transaction_new()) == NULL)
- goto done;
+ goto done;
/* This is the state we are going to */
if (xmldb_get0(h, "running", YB_MODULE, NULL, "/", 0, &td->td_target, NULL, NULL) < 0)
- goto done;
+ goto done;
if ((ret = xml_yang_validate_all_top(h, td->td_target, &xerr)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
- goto done;
- goto fail;
+ if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
+ goto done;
+ goto fail;
}
/* This is the state we are going from */
if (xmldb_get0(h, db, YB_MODULE, NULL, "/", 0, &td->td_src, NULL, NULL) < 0)
- goto done;
+ goto done;
/* 3. Compute differences */
if (xml_diff(yspec,
- td->td_src,
- td->td_target,
- &td->td_dvec, /* removed: only in running */
- &td->td_dlen,
- &td->td_avec, /* added: only in candidate */
- &td->td_alen,
- &td->td_scvec, /* changed: original values */
- &td->td_tcvec, /* changed: wanted values */
- &td->td_clen) < 0)
- goto done;
+ td->td_src,
+ td->td_target,
+ &td->td_dvec, /* removed: only in running */
+ &td->td_dlen,
+ &td->td_avec, /* added: only in candidate */
+ &td->td_alen,
+ &td->td_scvec, /* changed: original values */
+ &td->td_tcvec, /* changed: wanted values */
+ &td->td_clen) < 0)
+ goto done;
/* Mark as changed in tree */
for (i=0; itd_dlen; i++){ /* Also down */
- xn = td->td_dvec[i];
- xml_flag_set(xn, XML_FLAG_DEL);
- xml_apply(xn, CX_ELMNT, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_DEL);
- xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
+ xn = td->td_dvec[i];
+ xml_flag_set(xn, XML_FLAG_DEL);
+ xml_apply(xn, CX_ELMNT, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_DEL);
+ xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
}
for (i=0; itd_alen; i++){ /* Also down */
- xn = td->td_avec[i];
- xml_flag_set(xn, XML_FLAG_ADD);
- xml_apply(xn, CX_ELMNT, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_ADD);
- xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
+ xn = td->td_avec[i];
+ xml_flag_set(xn, XML_FLAG_ADD);
+ xml_apply(xn, CX_ELMNT, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_ADD);
+ xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
}
for (i=0; itd_clen; i++){ /* Also up */
- xn = td->td_scvec[i];
- xml_flag_set(xn, XML_FLAG_CHANGE);
- xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
- xn = td->td_tcvec[i];
- xml_flag_set(xn, XML_FLAG_CHANGE);
- xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
+ xn = td->td_scvec[i];
+ xml_flag_set(xn, XML_FLAG_CHANGE);
+ xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
+ xn = td->td_tcvec[i];
+ xml_flag_set(xn, XML_FLAG_CHANGE);
+ xml_apply_ancestor(xn, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
}
/* Call plugin transaction start callbacks */
if (plugin_transaction_begin_one(cp, h, td) < 0)
- goto fail;
+ goto fail;
/* Make generic validation on all new or changed data.
Note this is only call that uses 3-values */
if ((ret = generic_validate(h, yspec, td, &xerr)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
- goto done;
- goto fail;
+ if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
+ goto done;
+ goto fail;
}
/* Call validate callback in this plugin */
if (plugin_transaction_validate_one(cp, h, td) < 0)
- goto fail;
+ goto fail;
if (plugin_transaction_complete_one(cp, h, td) < 0)
- goto fail;
+ goto fail;
/* Call commit callback in this plugin */
if (plugin_transaction_commit_one(cp, h, td) < 0)
- goto fail;
+ goto fail;
if (plugin_transaction_commit_done_one(cp, h, td) < 0)
- goto fail;
+ goto fail;
/* Finalize */
if (plugin_transaction_end_one(cp, h, td) < 0)
- goto fail;
+ goto fail;
retval = 1;
done:
if (td){
- xmldb_get0_free(h, &td->td_target);
- transaction_free(td);
+ xmldb_get0_free(h, &td->td_target);
+ transaction_free(td);
}
return retval;
fail:
@@ -1011,3 +1042,58 @@ from_client_restart_one(clicon_handle h,
goto done;
}
+/*! 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
+
+failsafe ----------------------+
+ reset \ commit
+running ----|-------+---------------> RUNNING FAILSAFE
+ \
+tmp |---------------------->
+ */
+int
+load_failsafe(clicon_handle h,
+ char *phase)
+{
+ int retval = -1;
+ int ret;
+ char *db = "failsafe";
+ cbuf *cbret = NULL;
+
+ phase = phase == NULL ? "(unknown)" : phase;
+
+ if ((cbret = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ if ((ret = xmldb_exists(h, db)) < 0)
+ goto done;
+ if (ret == 0){ /* No it does not exist, fail */
+ clicon_err(OE_DB, 0, "%s failed and no Failsafe database found, exiting", phase);
+ goto done;
+ }
+ /* Copy original running to tmp as backup (restore if error) */
+ if (xmldb_copy(h, "running", "tmp") < 0)
+ goto done;
+ if (xmldb_db_reset(h, "running") < 0)
+ goto done;
+ ret = candidate_commit(h, NULL, db, cbret);
+ if (ret != 1)
+ if (xmldb_copy(h, "tmp", "running") < 0)
+ goto done;
+ if (ret < 0)
+ goto done;
+ if (ret == 0){
+ clicon_err(OE_DB, 0, "%s failed, Failsafe database validation failed %s", phase, cbuf_get(cbret));
+ goto done;
+ }
+ clicon_log(LOG_NOTICE, "%s failed, Failsafe database loaded ", phase);
+ retval = 0;
+ done:
+ if (cbret)
+ cbuf_free(cbret);
+ return retval;
+}
diff --git a/apps/backend/backend_confirm.c b/apps/backend/backend_confirm.c
new file mode 100644
index 00000000..5a94268d
--- /dev/null
+++ b/apps/backend/backend_confirm.c
@@ -0,0 +1,809 @@
+/*
+ *
+ ***** BEGIN LICENSE BLOCK *****
+
+ Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
+ Copyright (C) 2017-2019 Olof Hagsand
+ Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC(Netgate)
+
+ This file is part of CLIXON.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ Alternatively, the contents of this file may be used under the terms of
+ the GNU General Public License Version 3 or later (the "GPL"),
+ in which case the provisions of the GPL are applicable instead
+ of those above. If you wish to allow use of your version of this file only
+ under the terms of the GPL, and not to allow others to
+ use your version of this file under the terms of Apache License version 2,
+ indicate your decision by deleting the provisions above and replace them with
+ the notice and other provisions required by the GPL. If you do not delete
+ the provisions above, a recipient may use your version of this file under
+ the terms of any one of the Apache License version 2 or the GPL.
+
+ ***** END LICENSE BLOCK *****
+ Commit-confirm
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "clixon_config.h" /* generated by config & autoconf */
+#endif
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/* cligen */
+#include
+
+/* clicon */
+#include
+
+#include "clixon_backend_transaction.h"
+#include "clixon_backend_plugin.h"
+#include "backend_handle.h"
+#include "clixon_backend_commit.h"
+#include "backend_client.h"
+
+/*
+ * Local types
+ */
+/* A struct to store the information necessary for tracking the status and relevant details of
+ * one or more overlapping confirmed-commit events.
+ */
+struct confirmed_commit {
+ enum confirmed_commit_state cc_state;
+ char *cc_persist_id; /* a value given by a client in the confirmed-commit */
+ uint32_t cc_session_id; /* the session_id of the client that gave no value */
+ int (*cc_fn)(int, void*); /* function pointer for rollback event (rollback_fn()) */
+ void *cc_arg; /* clicon_handle that will be passed to rollback_fn() */
+};
+
+int
+confirmed_commit_init(clicon_handle h)
+{
+ int retval = -1;
+ struct confirmed_commit *cc = NULL;
+
+ if ((cc = calloc(1, sizeof(*cc))) == NULL){
+ clicon_err(OE_UNIX, errno, "calloc");
+ goto done;
+ }
+ cc->cc_state = INACTIVE;
+ if (clicon_ptr_set(h, "confirmed-commit-struct", cc) < 0)
+ goto done;
+ retval = 0;
+ done:
+ return retval;
+}
+
+/*! If confirm commit persist-id exists, free it
+ * @param[in] h Clixon handle
+ * @retval 0 OK
+ */
+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)
+ free (cc->cc_persist_id);
+ free(cc);
+ }
+ clicon_ptr_del(h, "confirmed-commit-struct");
+ return 0;
+}
+
+/*
+ * Accessor functions
+ */
+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;
+}
+
+static int
+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;
+}
+
+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;
+}
+
+static int
+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);
+ if (persist_id){
+ if ((cc->cc_persist_id = strdup4(persist_id)) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup4");
+ return -1;
+ }
+ }
+ else
+ cc->cc_persist_id = NULL;
+ return 0;
+}
+
+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;
+}
+
+static int
+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;
+}
+
+static int
+confirmed_commit_fn_arg_get(clicon_handle h,
+ int (**fn)(int, void*),
+ void **arg)
+{
+ struct confirmed_commit *cc = NULL;
+
+ clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc);
+ *fn = cc->cc_fn;
+ *arg = cc->cc_arg;
+ return 0;
+}
+
+static int
+confirmed_commit_fn_arg_set(clicon_handle h,
+ int (*fn)(int, void*),
+ void *arg)
+{
+ struct confirmed_commit *cc = NULL;
+
+ clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc);
+ cc->cc_fn = fn;
+ cc->cc_arg = arg;
+ return 0;
+}
+
+/*! Return if confirmed tag found
+ * @param[in] xe Commit rpc xml
+ * @retval 1 Confirmed tag exists
+ * @retval 0 Confirmed tag does not exist
+ */
+static int
+xe_confirmed(cxobj *xe)
+{
+ return (xml_find_type(xe, NULL, "confirmed", CX_ELMNT) != NULL) ? 1 : 0;
+}
+
+/*! 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
+ * @retval 0 Persist field does not exist
+ */
+static int
+xe_persist(cxobj *xe,
+ char **str)
+{
+ cxobj *xml;
+
+ if ((xml = xml_find_type(xe, NULL, "persist", CX_ELMNT)) != NULL){
+ *str = xml_body(xml);
+ return 1;
+ }
+ *str = NULL;
+ return 0;
+}
+
+/*! Return if persist-id exists and its string value
+ *
+ * @param[in] xe Commit rpc xml
+ * @param[out] str Pointer to persist-id
+ * @retval 1 Persist-id exists
+ * @retval 0 Persist-id does not exist
+ */
+static int
+xe_persist_id(cxobj *xe,
+ char **str)
+{
+ cxobj *xml;
+
+ if ((xml = xml_find_type(xe, NULL, "persist-id", CX_ELMNT)) != NULL){
+ *str = xml_body(xml);
+ return 1;
+ }
+ *str = NULL;
+ return 0;
+}
+
+/*! Return timeout
+ * @param[in] xe Commit rpc xml
+ * @retval sec Timeout in seconds, can be 0 if no timeout exists or is zero
+ */
+static unsigned int
+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);
+ return 0;
+}
+
+/*! Cancel a scheduled rollback as previously registered by schedule_rollback_event()
+ *
+ * @param[in] h Clixon handle
+ * @retval 0 Rollback event successfully cancelled
+ * @retval -1 No Rollback event was found
+ */
+int
+cancel_rollback_event(clicon_handle h)
+{
+ int retval;
+ int (*fn)(int, void*) = NULL;
+ void *arg = NULL;
+
+ confirmed_commit_fn_arg_get(h, &fn, &arg);
+ if ((retval = clixon_event_unreg_timeout(fn, arg)) == 0) {
+ clicon_log(LOG_INFO, "a scheduled rollback event has been cancelled");
+ } else {
+ clicon_log(LOG_WARNING, "the specified scheduled rollback event was not found");
+ }
+
+ return retval;
+}
+
+/*! Apply the rollback configuration upon expiration of the confirm-timeout
+ *
+ * @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
+ * @see do_rollback()
+ */
+static int
+rollback_fn(int fd,
+ void *arg)
+{
+ clicon_handle h = arg;
+
+ clicon_log(LOG_CRIT, "a confirming-commit was not received before the confirm-timeout expired; rolling back");
+
+ return do_rollback(h, NULL);
+}
+
+/*! Schedule a rollback in case no confirming-commit is received before the confirm-timeout
+ *
+ * @param[in] h a clicon handle
+ * @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
+ */
+static int
+schedule_rollback_event(clicon_handle h,
+ uint32_t timeout)
+{
+ int retval = -1;
+
+ // register a new scheduled event
+ struct timeval t, t1;
+ if (gettimeofday(&t, NULL) < 0) {
+ clicon_err(OE_UNIX, 0, "failed to get time of day: %s", strerror(errno));
+ goto done;
+ };
+ t1.tv_sec = timeout; t1.tv_usec = 0;
+ timeradd(&t, &t1, &t);
+
+ /* The confirmed-commit is either:
+ * - ephemeral, and the client requesting the new confirmed-commit is on the same session, OR
+ * - persistent, and the client provided the persist-id in the new confirmed-commit
+ */
+
+ /* remember the function pointer and args so the confirming-commit can cancel the rollback */
+ confirmed_commit_fn_arg_set(h, rollback_fn, h);
+ if (clixon_event_reg_timeout(t, rollback_fn, h, "rollback after timeout") < 0) {
+ /* error is logged in called function */
+ goto done;
+ };
+
+ retval = 0;
+
+ done:
+ return retval;
+}
+
+/*! Cancel a confirming commit by removing rollback, and free state
+ * @param[in] h
+ * @param[out] cbret
+ * @retval 0 OK
+ */
+int
+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_state_set(h, INACTIVE);
+
+ if (xmldb_delete(h, "rollback") < 0)
+ clicon_err(OE_DB, 0, "Error deleting the rollback configuration");
+ return 0;
+}
+
+/*! Determine if the present commit RPC invocation constitutes a valid "confirming-commit".
+ *
+ * To be considered a valid confirming-commit, the must either:
+ * 1) be presented without a value, and on the same session as a prior confirmed-commit that itself was
+ * without a value, OR
+ * 2) be presented with a value that matches the value accompanying the prior confirmed-commit
+ *
+ * @param[in] h Clicon handle
+ * @param[in] xe Request:
+ * @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
+ */
+static int
+check_valid_confirming_commit(clicon_handle h,
+ 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;
+ }
+ 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) {
+ /* the RPC included a matching the prior confirming-commit's */
+ break; // valid
+ }
+ 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;
+ }
+ } 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;
+ }
+ case EPHEMERAL:
+ if (myid == confirmed_commit_session_id_get(h)) {
+ /* the RPC lacked a , the prior confirming-commit lacked , and both were issued
+ * on the same session.
+ */
+ break; // valid
+ }
+ 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;
+ default:
+ clicon_debug(1, "commit-confirmed state !? %d", confirmed_commit_state_get(h));
+ goto invalid;
+ }
+ retval = 1; // valid
+ done:
+ return retval;
+ invalid:
+ retval = 0;
+ goto done;
+}
+
+/*! Handle the second phase of confirmed-commit processing.
+ *
+ * In the first phase, the proper action was taken in the case of a valid confirming-commit, but no subsequent
+ * confirmed-commit.
+ *
+ * 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] xe Commit rpc xml or NULL
+ * @retval 0 OK
+ * @retval -1 Error
+ */
+int
+handle_confirmed_commit(clicon_handle h,
+ cxobj *xe)
+{
+ int retval = -1;
+ uint32_t session_id;
+ char *persist;
+ unsigned long confirm_timeout = 0L;
+ int cc_valid;
+ int db_exists;
+
+ if (xe == 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;
+ };
+ /* 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
+ * confirmed-commit must be handled once the transaction has begun and after all the plugins' validate callbacks
+ * have been called.
+ */
+ cc_valid = check_valid_confirming_commit(h, xe, session_id);
+ if (cc_valid) {
+ if (cancel_rollback_event(h) < 0) {
+ clicon_err(OE_DAEMON, 0, "A valid confirming-commit was received, but the corresponding rollback event was not found");
+ }
+
+ if (confirmed_commit_state_get(h) == PERSISTENT &&
+ confirmed_commit_persist_id_get(h) != NULL) {
+ confirmed_commit_persist_id_set(h, NULL);
+ }
+
+ 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)){
+ if (persist == NULL) {
+ confirmed_commit_persist_id_set(h, NULL);
+ }
+ else if (confirmed_commit_persist_id_set(h, persist) < 0){
+ goto done;
+ }
+
+ /* The client has passed ; the confirming-commit MUST now be accompanied by a matching
+ *
+ */
+ 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 {
+ /* The client did not pass a value for 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);
+
+ 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),
+ confirm_timeout);
+ }
+
+ /* The confirmed-commits and confirming-commits can overlap; the rollback database is created at the beginning
+ * of such a sequence and deleted at the end; hence its absence implies this is the first of a sequence. **
+ *
+ *
+ * | edit
+ * | | confirmed-commit
+ * | | copy t=0 running to rollback
+ * | | | edit
+ * | | | | both
+ * | | | | | edit
+ * | | | | | | both
+ * | | | | | | | confirming-commit
+ * | | | | | | | | delete rollback
+ * +----|-|-|-|-|-|-|-|---------------
+ * t=0 1 2 3 4 5 6 7 8
+ *
+ * edit = edit of the candidate configuration
+ * both = both a confirmed-commit and confirming-commit in the same RPC
+ *
+ * As shown, the rollback database created at t=2 is comprised of the running database from t=0
+ * Thus, if there is a rollback event at t=7, the t=0 configuration will be committed.
+ *
+ * ** the rollback database may be present at system startup if there was a crash during a confirmed-commit;
+ * in the case the system is configured to startup from running and the rollback database is present, the
+ * rollback database will be committed to running and then deleted. If the system is configured to use a
+ * startup configuration instead, any present rollback database will be deleted.
+ *
+ */
+
+ db_exists = xmldb_exists(h, "rollback");
+ if (db_exists == -1) {
+ clicon_err(OE_DAEMON, 0, "there was an error while checking existence of the rollback database");
+ goto done;
+ } else if (db_exists == 0) {
+ // db does not yet exists
+ if (xmldb_copy(h, "running", "rollback") < 0) {
+ clicon_err(OE_DAEMON, 0, "there was an error while copying the running configuration to rollback database.");
+ goto done;
+ };
+ }
+
+ if (schedule_rollback_event(h, confirm_timeout) < 0) {
+ clicon_err(OE_DAEMON, 0, "the rollback event could not be scheduled");
+ goto done;
+ };
+
+ }
+ else {
+ /* There was no subsequent confirmed-commit, meaning this is the end of the confirmed/confirming sequence;
+ * The new configuration is already committed to running and the rollback database can now be deleted
+ */
+ if (xmldb_delete(h, "rollback") < 0) {
+ clicon_err(OE_DB, 0, "Error deleting the rollback configuration");
+ goto done;
+ }
+ }
+ retval = 0;
+ done:
+ return retval;
+}
+
+/*! Do a rollback of the running configuration to the state prior to initiation of a confirmed-commit
+ *
+ * The "running" configuration prior to the first confirmed-commit was stored in another database named "rollback".
+ * Here, it is committed as if it is the candidate configuration.
+ *
+ * Execution has arrived here because do_rollback() was called by one of:
+ * 1. backend_client_rm() (client disconnected and confirmed-commit is ephemeral)
+ * 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
+ * @retval 0 Success
+ * @see backend_client_rm()
+ * @see from_client_cancel_commit()
+ * @see rollback_fn()
+ */
+int
+do_rollback(clicon_handle h,
+ uint8_t *errs)
+{
+ int retval = -1;
+ uint8_t errstate = 0;
+ cbuf *cbret;
+
+ if ((cbret = cbuf_new()) == NULL) {
+ clicon_err(OE_DAEMON, 0, "rollback was not performed. (cbuf_new: %s)", strerror(errno));
+ /* the rollback_db won't be deleted, so one can try recovery by:
+ * load rollback running
+ * restart the backend, which will try to load the rollback_db, and delete it if successful
+ * (otherwise it will load the failsafe)
+ */
+ clicon_log(LOG_CRIT, "An error occurred during rollback and the rollback_db wasn't deleted.");
+ errstate |= ROLLBACK_NOT_APPLIED | ROLLBACK_DB_NOT_DELETED;
+ goto done;
+ }
+
+ if (confirmed_commit_state_get(h) == PERSISTENT &&
+ 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 */
+ /* theoretically, this should never error, since the rollback database was previously active and therefore
+ * had itself been previously and successfully committed.
+ */
+ clicon_log(LOG_CRIT, "An error occurred committing the rollback database.");
+ errstate |= ROLLBACK_NOT_APPLIED;
+
+ /* Rename the errored rollback database */
+ if (xmldb_rename(h, "rollback", NULL, ".error") < 0) {
+ clicon_log(LOG_CRIT, "An error occurred renaming the rollback database.");
+ errstate |= ROLLBACK_DB_NOT_DELETED;
+ }
+
+ /* Attempt to load the failsafe config */
+
+ if (load_failsafe(h, "Rollback") < 0) {
+ clicon_log(LOG_CRIT, "An error occurred committing the failsafe database. Exiting.");
+ /* Invoke our own signal handler to exit */
+ raise(SIGINT);
+
+ /* should never make it here */
+ }
+
+ errstate |= ROLLBACK_FAILSAFE_APPLIED;
+ goto done;
+ }
+ cbuf_free(cbret);
+
+ if (xmldb_delete(h, "rollback") < 0) {
+ clicon_log(LOG_WARNING, "A rollback occurred but the rollback_db wasn't deleted.");
+ errstate |= ROLLBACK_DB_NOT_DELETED;
+ goto done;
+ };
+ retval = 0;
+ done:
+ confirmed_commit_state_set(h, INACTIVE);
+ if (errs)
+ *errs = errstate;
+ return retval;
+}
+
+/*! 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] xe Request:
+ * @param[out] cbret Return xml tree, eg ..., ", NETCONF_BASE_NAMESPACE);
+ clicon_log(LOG_INFO, "a confirmed-commit has been cancelled by client request");
+ }
+ retval = 0;
+ done:
+ return retval;
+}
+
+/*! Incoming commit handler for confirmed commit
+ * @param[in] h Clicon handle
+ * @param[in] xe Request:
+ * @param[in] myid Client-id
+ * @param[out] cbret Return xml tree
+ * @retval 1 OK
+ * @retval 0 OK, dont proceed with commit
+ * @retval -1 Error
+ */
+int
+from_client_confirmed_commit(clicon_handle h,
+ 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;
+ /* If 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, " ", NETCONF_BASE_NAMESPACE);
+ goto dontcommit;
+ }
+ retval = 1;
+ done:
+ return retval;
+ dontcommit:
+ retval = 0;
+ goto done;
+}
diff --git a/apps/backend/backend_get.c b/apps/backend/backend_get.c
index c60e19dd..c2996bc3 100644
--- a/apps/backend/backend_get.c
+++ b/apps/backend/backend_get.c
@@ -84,21 +84,21 @@
*/
static int
client_get_capabilities(clicon_handle h,
- yang_stmt *yspec,
- char *xpath,
- cxobj **xret)
+ yang_stmt *yspec,
+ char *xpath,
+ cxobj **xret)
{
int retval = -1;
cxobj *xrstate = NULL; /* xml restconf-state node */
cbuf *cb = NULL;
if ((xrstate = xpath_first(*xret, NULL, "restconf-state")) == NULL){
- clicon_err(OE_YANG, ENOENT, "restconf-state not found in config node");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "restconf-state not found in config node");
+ goto done;
}
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
cprintf(cb, "");
cprintf(cb, "urn:ietf:params:restconf:capability:defaults:1.0?basic-mode=explicit ");
@@ -106,11 +106,11 @@ client_get_capabilities(clicon_handle h,
cprintf(cb, "urn:ietf:params:restconf:capability:with-defaults:1.0 ");
cprintf(cb, " ");
if (clixon_xml_parse_string(cbuf_get(cb), YB_PARENT, NULL, &xrstate, NULL) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -127,11 +127,11 @@ client_get_capabilities(clicon_handle h,
*/
static int
client_get_streams(clicon_handle h,
- yang_stmt *yspec,
- char *xpath,
- yang_stmt *ymod,
- char *top,
- cxobj **xret)
+ yang_stmt *yspec,
+ char *xpath,
+ yang_stmt *ymod,
+ char *top,
+ cxobj **xret)
{
int retval = -1;
yang_stmt *yns = NULL; /* yang namespace */
@@ -140,36 +140,36 @@ client_get_streams(clicon_handle h,
int ret;
if ((yns = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL){
- clicon_err(OE_YANG, 0, "%s yang namespace not found", yang_argument_get(ymod));
- goto done;
+ clicon_err(OE_YANG, 0, "%s yang namespace not found", yang_argument_get(ymod));
+ goto done;
}
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
cprintf(cb, "<%s xmlns=\"%s\">", top, yang_argument_get(yns));
/* Second argument is a hack to have the same function for the
* RFC5277 and 8040 stream cases
*/
if (stream_get_xml(h, strcmp(top,"restconf-state")==0, cb) < 0)
- goto done;
+ goto done;
cprintf(cb,"%s>", top);
if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, &x, NULL) < 0){
- if (xret && netconf_operation_failed_xml(xret, "protocol", clicon_err_reason)< 0)
- goto done;
- goto fail;
+ if (xret && netconf_operation_failed_xml(xret, "protocol", clicon_err_reason)< 0)
+ goto done;
+ goto fail;
}
if ((ret = netconf_trymerge(x, yspec, xret)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
retval = 1;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (x)
- xml_free(x);
+ xml_free(x);
return retval;
fail:
retval = 0;
@@ -187,9 +187,9 @@ client_get_streams(clicon_handle h,
*/
static int
get_client_statedata(clicon_handle h,
- char *xpath,
- cvec *nsc,
- cxobj **xret)
+ char *xpath,
+ cvec *nsc,
+ cxobj **xret)
{
int retval = -1;
yang_stmt *yspec;
@@ -200,73 +200,73 @@ get_client_statedata(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No yang spec");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "No yang spec");
+ goto done;
}
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC5277")){
- if ((ymod = yang_find_module_by_name(yspec, "clixon-rfc5277")) == NULL){
- clicon_err(OE_YANG, ENOENT, "yang module clixon-rfc5277 not found");
- goto done;
- }
- if ((namespace = yang_find_mynamespace(ymod)) == NULL){
- clicon_err(OE_YANG, ENOENT, "clixon-rfc5277 namespace not found");
- goto done;
- }
- cprintf(cb, "", namespace);
- if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, xret, NULL) < 0)
- goto done;
- if ((ret = client_get_streams(h, yspec, xpath, ymod, "netconf", xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ymod = yang_find_module_by_name(yspec, "clixon-rfc5277")) == NULL){
+ clicon_err(OE_YANG, ENOENT, "yang module clixon-rfc5277 not found");
+ goto done;
+ }
+ if ((namespace = yang_find_mynamespace(ymod)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "clixon-rfc5277 namespace not found");
+ goto done;
+ }
+ cprintf(cb, "", namespace);
+ if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, xret, NULL) < 0)
+ goto done;
+ if ((ret = client_get_streams(h, yspec, xpath, ymod, "netconf", xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040")){
- if ((ymod = yang_find_module_by_name(yspec, "ietf-restconf-monitoring")) == NULL){
- clicon_err(OE_YANG, ENOENT, "yang module ietf-restconf-monitoring not found");
- goto done;
- }
- if ((namespace = yang_find_mynamespace(ymod)) == NULL){
- clicon_err(OE_YANG, ENOENT, "ietf-restconf-monitoring namespace not found");
- goto done;
- }
- cbuf_reset(cb);
- /* XXX This code does not filter state data with xpath */
- cprintf(cb, "", namespace);
- if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, xret, NULL) < 0)
- goto done;
- if ((ret = client_get_streams(h, yspec, xpath, ymod, "restconf-state", xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- if ((ret = client_get_capabilities(h, yspec, xpath, xret)) < 0)
- goto done;
+ if ((ymod = yang_find_module_by_name(yspec, "ietf-restconf-monitoring")) == NULL){
+ clicon_err(OE_YANG, ENOENT, "yang module ietf-restconf-monitoring not found");
+ goto done;
+ }
+ if ((namespace = yang_find_mynamespace(ymod)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "ietf-restconf-monitoring namespace not found");
+ goto done;
+ }
+ cbuf_reset(cb);
+ /* XXX This code does not filter state data with xpath */
+ cprintf(cb, "", namespace);
+ if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, xret, NULL) < 0)
+ goto done;
+ if ((ret = client_get_streams(h, yspec, xpath, ymod, "restconf-state", xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ if ((ret = client_get_capabilities(h, yspec, xpath, xret)) < 0)
+ goto done;
}
if (clicon_option_bool(h, "CLICON_YANG_LIBRARY")){
- if ((ret = yang_modules_state_get(h, yspec, xpath, nsc, 0, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = yang_modules_state_get(h, yspec, xpath, nsc, 0, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
/* Use plugin state callbacks */
if ((ret = clixon_plugin_statedata_all(h, yspec, nsc, xpath, xret)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* Add default state to config if present */
if (xml_default_recurse(*xret, 1) < 0)
- goto done;
+ goto done;
/* Add default global state */
if (xml_global_defaults(h, *xret, nsc, xpath, yspec, 1) < 0)
- goto done;
+ goto done;
retval = 1; /* OK */
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
fail:
retval = 0;
@@ -294,35 +294,35 @@ get_client_statedata(clicon_handle h,
*/
static int
filter_xpath_again(clicon_handle h,
- yang_stmt *yspec,
- cxobj *xret,
- cxobj **xvec,
- size_t xlen,
- char *xpath,
- cvec *nsc)
+ yang_stmt *yspec,
+ cxobj *xret,
+ cxobj **xvec,
+ size_t xlen,
+ char *xpath,
+ cvec *nsc)
{
int retval = -1;
int i;
if (xret == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "xret is NULL");
+ goto done;
}
/* If vectors are specified then mark the nodes found and
* then filter out everything else,
* otherwise return complete tree.
*/
if (xvec != NULL){
- for (i=0; i", NETCONF_BASE_NAMESPACE); /* OK */
if (xret==NULL)
- cprintf(cbret, " ");
+ cprintf(cbret, " ");
else{
- if (xml_name_set(xret, NETCONF_OUTPUT_DATA) < 0)
- goto done;
- /* Top level is data, so add 1 to depth if significant */
- if (clixon_xml2cbuf(cbret, xret, 0, 0, depth>0?depth+1:depth, 0) < 0)
- goto done;
+ if (xml_name_set(xret, NETCONF_OUTPUT_DATA) < 0)
+ goto done;
+ /* Top level is data, so add 1 to depth if significant */
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, depth>0?depth+1:depth, 0) < 0)
+ goto done;
}
cprintf(cbret, " ");
retval = 0;
@@ -393,52 +393,52 @@ get_nacm_and_reply(clicon_handle h,
*/
static int
element2value(clicon_handle h,
- cxobj *xe,
- char *name,
- char *defaultstr,
- cbuf *cbret,
- uint32_t *value)
+ cxobj *xe,
+ char *name,
+ char *defaultstr,
+ cbuf *cbret,
+ uint32_t *value)
{
char *valstr;
cxobj *x;
*value = 0;
if ((x = xml_find_type(xe, NULL, name, CX_ELMNT)) != NULL &&
- (valstr = xml_body(x)) != NULL){
- return netconf_parse_uint32(name, valstr, defaultstr, 0, cbret, value);
+ (valstr = xml_body(x)) != NULL){
+ return netconf_parse_uint32(name, valstr, defaultstr, 0, cbret, value);
}
return 1;
}
/*! Set flag on node having schema default value.
- * @param[in] x XML node
- * @param[in] flag Flag to be used
- * @retval 0 OK
+ * @param[in] x XML node
+ * @param[in] flag Flag to be used
+ * @retval 0 OK
*/
static int
xml_flag_default_value(cxobj *x,
- uint16_t flag)
+ uint16_t flag)
{
- yang_stmt *y;
- cg_var *cv;
- char *yv;
- char *xv;
+ yang_stmt *y;
+ cg_var *cv;
+ char *yv;
+ char *xv;
xml_flag_reset(x, flag); /* Assume not default value */
if ((xv = xml_body(x)) == NULL)
- goto done;
+ goto done;
if ((y = xml_spec(x)) == NULL)
- goto done;
+ goto done;
if ((cv = yang_cv_get(y)) == NULL)
- goto done;
+ goto done;
if ((cv = yang_cv_get(y)) == NULL)
- goto done;
+ goto done;
if (cv_name_get(cv) == NULL)
- goto done;
+ goto done;
if ((yv = cv2str_dup(cv)) == NULL)
- goto done;
+ goto done;
if (strcmp(xv, yv) == 0)
- xml_flag_set(x, flag); /* Actual value same as default value */
+ xml_flag_set(x, flag); /* Actual value same as default value */
free(yv);
done:
@@ -446,26 +446,26 @@ xml_flag_default_value(cxobj *x,
}
/*! Add default attribute to node with default value.
- * @param[in] x XML node
- * @param[in] flags Flags indicatiing default nodes
- * @retval 0 OK
- * @retval -1 Error
+ * @param[in] x XML node
+ * @param[in] flags Flags indicatiing default nodes
+ * @retval 0 OK
+ * @retval -1 Error
*/
static int
xml_add_default_tag(cxobj *x,
- uint16_t flags)
+ uint16_t flags)
{
int retval = -1;
cxobj *xattr;
if (xml_flag(x, flags)) {
- /* set default attribute */
- if ((xattr = xml_new("default", x, CX_ATTR)) == NULL)
- goto done;
- if (xml_value_set(xattr, "true") < 0)
- goto done;
- if (xml_prefix_set(xattr, IETF_NETCONF_WITH_DEFAULTS_ATTR_PREFIX) < 0)
- goto done;
+ /* set default attribute */
+ if ((xattr = xml_new("default", x, CX_ATTR)) == NULL)
+ goto done;
+ if (xml_value_set(xattr, "true") < 0)
+ goto done;
+ if (xml_prefix_set(xattr, IETF_NETCONF_WITH_DEFAULTS_ATTR_PREFIX) < 0)
+ goto done;
}
retval = 0;
done:
@@ -475,12 +475,12 @@ xml_add_default_tag(cxobj *x,
/*! Update XML return tree according to RFC6243: with-defaults
* @param[in] xe Request:
* @param[in] xret XML return tree to be updated
- * @retval 0 OK
- * @retval -1 Error
+ * @retval 0 OK
+ * @retval -1 Error
*/
static int
with_defaults(cxobj *xe,
- cxobj *xret)
+ cxobj *xret)
{
int retval = -1;
cxobj *xfind;
@@ -488,56 +488,56 @@ with_defaults(cxobj *xe,
cxobj *x;
if ((xfind = xml_find(xe, "with-defaults")) != NULL) {
- if ((mode = xml_find_value(xfind, "body")) == NULL)
- goto done;
+ if ((mode = xml_find_value(xfind, "body")) == NULL)
+ goto done;
- if (strcmp(mode, "explicit") == 0) {
- /* Clear marked nodes */
- if (xml_apply(xret, CX_ELMNT, (xml_applyfn_t*) xml_flag_reset,(void*) XML_FLAG_MARK) < 0)
- goto done;
- /* Mark state nodes */
- if (xml_non_config_data(xret, NULL) < 0)
- goto done;
- /* Remove default configuration nodes */
- if (xml_tree_prune_flags(xret, XML_FLAG_DEFAULT, XML_FLAG_MARK | XML_FLAG_DEFAULT) < 0)
- goto done;
- /* Remove empty containers */
- if (xml_defaults_nopresence(xret, 1) < 0)
- goto done;
- goto ok;
- }
- else if (strcmp(mode, "trim") == 0) {
- /* Remove default nodes from XML */
- if (xml_tree_prune_flags(xret, XML_FLAG_DEFAULT, XML_FLAG_DEFAULT) < 0)
- goto done;
- /* Mark and remove nodes having schema default values */
- if (xml_apply(xret, CX_ELMNT, (xml_applyfn_t*) xml_flag_default_value, (void*) XML_FLAG_MARK) < 0)
- goto done;
- if (xml_tree_prune_flags(xret, XML_FLAG_MARK, XML_FLAG_MARK)
- < 0)
- goto done;
- /* Remove empty containers */
- if (xml_defaults_nopresence(xret, 1) < 0)
- goto done;
- goto ok;
- }
- else if (strcmp(mode, "report-all-tagged") == 0) {
- x = NULL;
- while ((x = xml_child_each(xret, x, CX_ELMNT)) != NULL)
- if (xmlns_set(x, IETF_NETCONF_WITH_DEFAULTS_ATTR_PREFIX, IETF_NETCONF_WITH_DEFAULTS_ATTR_NAMESPACE) < 0)
- goto done;
- /* Mark nodes having default schema values */
- if (xml_apply(xret, CX_ELMNT, (xml_applyfn_t*) xml_flag_default_value, (void*) XML_FLAG_MARK) < 0)
- goto done;
- /* Add tag attributes to default nodes */
- if (xml_apply(xret, CX_ELMNT, (xml_applyfn_t*) xml_add_default_tag, (void*) (XML_FLAG_DEFAULT | XML_FLAG_MARK)) < 0)
- goto done;
- goto ok;
- }
- else if (strcmp(mode, "report-all") == 0) {
- /* Accept mode, do nothing */
- goto ok;
- }
+ if (strcmp(mode, "explicit") == 0) {
+ /* Clear marked nodes */
+ if (xml_apply(xret, CX_ELMNT, (xml_applyfn_t*) xml_flag_reset,(void*) XML_FLAG_MARK) < 0)
+ goto done;
+ /* Mark state nodes */
+ if (xml_non_config_data(xret, NULL) < 0)
+ goto done;
+ /* Remove default configuration nodes */
+ if (xml_tree_prune_flags(xret, XML_FLAG_DEFAULT, XML_FLAG_MARK | XML_FLAG_DEFAULT) < 0)
+ goto done;
+ /* Remove empty containers */
+ if (xml_defaults_nopresence(xret, 1) < 0)
+ goto done;
+ goto ok;
+ }
+ else if (strcmp(mode, "trim") == 0) {
+ /* Remove default nodes from XML */
+ if (xml_tree_prune_flags(xret, XML_FLAG_DEFAULT, XML_FLAG_DEFAULT) < 0)
+ goto done;
+ /* Mark and remove nodes having schema default values */
+ if (xml_apply(xret, CX_ELMNT, (xml_applyfn_t*) xml_flag_default_value, (void*) XML_FLAG_MARK) < 0)
+ goto done;
+ if (xml_tree_prune_flags(xret, XML_FLAG_MARK, XML_FLAG_MARK)
+ < 0)
+ goto done;
+ /* Remove empty containers */
+ if (xml_defaults_nopresence(xret, 1) < 0)
+ goto done;
+ goto ok;
+ }
+ else if (strcmp(mode, "report-all-tagged") == 0) {
+ x = NULL;
+ while ((x = xml_child_each(xret, x, CX_ELMNT)) != NULL)
+ if (xmlns_set(x, IETF_NETCONF_WITH_DEFAULTS_ATTR_PREFIX, IETF_NETCONF_WITH_DEFAULTS_ATTR_NAMESPACE) < 0)
+ goto done;
+ /* Mark nodes having default schema values */
+ if (xml_apply(xret, CX_ELMNT, (xml_applyfn_t*) xml_flag_default_value, (void*) XML_FLAG_MARK) < 0)
+ goto done;
+ /* Add tag attributes to default nodes */
+ if (xml_apply(xret, CX_ELMNT, (xml_applyfn_t*) xml_add_default_tag, (void*) (XML_FLAG_DEFAULT | XML_FLAG_MARK)) < 0)
+ goto done;
+ goto ok;
+ }
+ else if (strcmp(mode, "report-all") == 0) {
+ /* Accept mode, do nothing */
+ goto ok;
+ }
}
ok:
retval = 0;
@@ -565,17 +565,17 @@ with_defaults(cxobj *xe,
*/
static int
get_list_pagination(clicon_handle h,
- struct client_entry *ce,
- cxobj *xe,
- netconf_content content,
- char *db,
- int32_t depth,
- yang_stmt *yspec,
- char *xpath,
- cvec *nsc,
- char *username,
- cbuf *cbret
- )
+ struct client_entry *ce,
+ cxobj *xe,
+ netconf_content content,
+ char *db,
+ int32_t depth,
+ yang_stmt *yspec,
+ char *xpath,
+ cvec *nsc,
+ char *username,
+ cbuf *cbret
+ )
{
int retval = -1;
uint32_t offset = 0;
@@ -602,219 +602,219 @@ get_list_pagination(clicon_handle h,
/* Check if list/leaf-list */
if (yang_path_arg(yspec, xpath?xpath:"/", &ylist) < 0)
- goto done;
+ goto done;
if (ylist == NULL){
- if ((cbmsg = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- /* error reason should be in clicon_err_reason */
- cprintf(cbmsg, "Netconf get list-pagination: \"%s\" not found", xpath);
- if (netconf_invalid_value(cbret, "application", cbuf_get(cbmsg)) < 0)
- goto done;
- goto ok;
+ if ((cbmsg = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ /* error reason should be in clicon_err_reason */
+ cprintf(cbmsg, "Netconf get list-pagination: \"%s\" not found", xpath);
+ if (netconf_invalid_value(cbret, "application", cbuf_get(cbmsg)) < 0)
+ goto done;
+ goto ok;
}
if (yang_keyword_get(ylist) != Y_LIST &&
- yang_keyword_get(ylist) != Y_LEAF_LIST){
- if (netconf_invalid_value(cbret, "application", "list-pagination is enabled but target is not list or leaf-list") < 0)
- goto done;
- goto ok;
+ yang_keyword_get(ylist) != Y_LEAF_LIST){
+ if (netconf_invalid_value(cbret, "application", "list-pagination is enabled but target is not list or leaf-list") < 0)
+ goto done;
+ goto ok;
}
/* Sanity checks on state/config */
if ((list_config = yang_config_ancestor(ylist)) != 0){ /* config list */
- if (content == CONTENT_NONCONFIG){
- if (netconf_invalid_value(cbret, "application", "list-pagination targets a config list but content request is nonconfig") < 0)
- goto done;
- goto ok;
- }
+ if (content == CONTENT_NONCONFIG){
+ if (netconf_invalid_value(cbret, "application", "list-pagination targets a config list but content request is nonconfig") < 0)
+ goto done;
+ goto ok;
+ }
}
else { /* state list */
- if (content == CONTENT_CONFIG){
- if (netconf_invalid_value(cbret, "application", "list-pagination targets a state list but content request is config") < 0)
- goto done;
- goto ok;
- }
+ if (content == CONTENT_CONFIG){
+ if (netconf_invalid_value(cbret, "application", "list-pagination targets a state list but content request is config") < 0)
+ goto done;
+ goto ok;
+ }
}
/* offset */
if ((ret = element2value(h, xe, "offset", "none", cbret, &offset)) < 0)
- goto done;
+ goto done;
/* limit */
if (ret && (ret = element2value(h, xe, "limit", "unbounded", cbret, &limit)) < 0)
- goto done;
+ goto done;
#ifdef NOTYET
/* direction */
if (ret && (x = xml_find_type(xe, NULL, "direction", CX_ELMNT)) != NULL){
- direction = xml_body(x);
- if (strcmp(direction, "forward") != 0 && strcmp(direction, "reverse") != 0){
- if (netconf_bad_attribute(cbret, "application",
- "direction", "Unrecognized value of direction attribute") < 0)
- goto done;
- goto ok;
- }
+ direction = xml_body(x);
+ if (strcmp(direction, "forward") != 0 && strcmp(direction, "reverse") != 0){
+ if (netconf_bad_attribute(cbret, "application",
+ "direction", "Unrecognized value of direction attribute") < 0)
+ goto done;
+ goto ok;
+ }
}
/* sort */
if (ret && (x = xml_find_type(xe, NULL, "sort-by", CX_ELMNT)) != NULL)
- sort = xml_body(x);
+ sort = xml_body(x);
if (sort) {
- /* XXX: nothing yet */
+ /* XXX: nothing yet */
}
/* where */
if (ret && (x = xml_find_type(xe, NULL, "where", CX_ELMNT)) != NULL)
- where = xml_body(x);
+ where = xml_body(x);
#endif
/* Read config */
switch (content){
case CONTENT_CONFIG: /* config data only */
case CONTENT_ALL: /* both config and state */
- /* Build a "predicate" cbuf
- * This solution uses xpath predicates to translate "limit" and "offset" to
- * relational operators <>.
- */
- if ((cbpath = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- /* This uses xpath. Maybe limit should use parameters */
- if (xpath)
- cprintf(cbpath, "%s", xpath);
- else
- cprintf(cbpath, "/");
+ /* Build a "predicate" cbuf
+ * This solution uses xpath predicates to translate "limit" and "offset" to
+ * relational operators <>.
+ */
+ if ((cbpath = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ /* This uses xpath. Maybe limit should use parameters */
+ if (xpath)
+ cprintf(cbpath, "%s", xpath);
+ else
+ cprintf(cbpath, "/");
#ifdef NOTYET
- if (where)
- cprintf(cbpath, "[%s]", where);
+ if (where)
+ cprintf(cbpath, "[%s]", where);
#endif
- if (offset){
- cprintf(cbpath, "[%u <= position()", offset);
- if (limit)
- cprintf(cbpath, " and position() < %u", limit+offset);
- cprintf(cbpath, "]");
- }
- else if (limit)
- cprintf(cbpath, "[position() < %u]", limit);
+ if (offset){
+ cprintf(cbpath, "[%u <= position()", offset);
+ if (limit)
+ cprintf(cbpath, " and position() < %u", limit+offset);
+ cprintf(cbpath, "]");
+ }
+ else if (limit)
+ cprintf(cbpath, "[position() < %u]", limit);
- /* Append predicate to original xpath and replace it */
- xpath2 = cbuf_get(cbpath);
- /* specific xpath */
- if (xmldb_get0(h, db, YB_MODULE, nsc, xpath2?xpath2:"/", 1, &xret, NULL, NULL) < 0) {
- if ((cbmsg = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason);
- if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
- goto done;
- goto ok;
- }
- break;
+ /* Append predicate to original xpath and replace it */
+ xpath2 = cbuf_get(cbpath);
+ /* specific xpath */
+ if (xmldb_get0(h, db, YB_MODULE, nsc, xpath2?xpath2:"/", 1, &xret, NULL, NULL) < 0) {
+ if ((cbmsg = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason);
+ if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
+ goto done;
+ goto ok;
+ }
+ break;
case CONTENT_NONCONFIG: /* state data only */
- if ((xret = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)/* Only top tree */
- goto done;
- break;
+ if ((xret = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)/* Only top tree */
+ goto done;
+ break;
}/* switch content */
if (list_config){
#ifdef LIST_PAGINATION_REMAINING
- /* Get total/remaining
- * XXX: Works only for cache
- */
- if ((xcache = xmldb_cache_get(h, db)) != NULL){
- if (xpath_count(xcache, nsc, xpath, &total) < 0)
- goto done;
- if (total >= (offset + limit))
- remaining = total - (offset + limit);
- }
+ /* Get total/remaining
+ * XXX: Works only for cache
+ */
+ if ((xcache = xmldb_cache_get(h, db)) != NULL){
+ if (xpath_count(xcache, nsc, xpath, &total) < 0)
+ goto done;
+ if (total >= (offset + limit))
+ remaining = total - (offset + limit);
+ }
#endif
}
else {/* Check if running locked (by this session) */
- if ((iddb = xmldb_islocked(h, "running")) != 0 &&
- iddb == ce->ce_id)
- locked = 1;
- else
- locked = 0;
- if ((ret = clixon_pagination_cb_call(h, xpath, locked,
- offset, limit,
- xret)) < 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, pagination state callback invalid return : %s",
- clicon_err_reason);
- if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0)
- goto done;
- if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
- goto done;
- goto ok;
- }
+ if ((iddb = xmldb_islocked(h, "running")) != 0 &&
+ iddb == ce->ce_id)
+ locked = 1;
+ else
+ locked = 0;
+ if ((ret = clixon_pagination_cb_call(h, xpath, locked,
+ offset, limit,
+ xret)) < 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, pagination state callback invalid return : %s",
+ clicon_err_reason);
+ if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
+ goto done;
+ goto ok;
+ }
- /* System makes the binding */
- if ((ret = xml_bind_yang(xret, YB_MODULE, yspec, &xerr)) < 0)
- goto done;
- if (ret == 0){
- if (clicon_debug_get() && xret)
- clicon_log_xml(LOG_DEBUG, xret, "Yang bind pagination state");
- if (clixon_netconf_internal_error(xerr,
- ". Internal error, state callback returned invalid XML",
- NULL) < 0)
- goto done;
- if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
- goto done;
- goto ok;
- }
+ /* System makes the binding */
+ if ((ret = xml_bind_yang(xret, YB_MODULE, yspec, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ if (clicon_debug_get() && xret)
+ clicon_log_xml(LOG_DEBUG, xret, "Yang bind pagination state");
+ if (clixon_netconf_internal_error(xerr,
+ ". Internal error, state callback returned invalid XML",
+ NULL) < 0)
+ goto done;
+ if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
+ goto done;
+ goto ok;
+ }
}
if (with_defaults(xml_parent(xe), xret) < 0)
- goto done;
+ goto done;
if (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath?xpath:"/") < 0)
- goto done;
+ goto done;
/* Help function to filter out anything that is outside of xpath */
if (filter_xpath_again(h, yspec, xret, xvec, xlen, xpath, nsc) < 0)
- goto done;
+ goto done;
#ifdef LIST_PAGINATION_REMAINING
/* Add remaining attribute Sec 3.1.5:
Any list or leaf-list that is limited includes, on the first element in the result set,
a metadata value [RFC7952] called "remaining"*/
if (limit && x1){
- cxobj *xa;
- cbuf *cba = NULL;
+ cxobj *xa;
+ cbuf *cba = NULL;
- /* Add remaining attribute */
- if ((xa = xml_new("remaining", x1, CX_ATTR)) == NULL)
- goto done;
- if ((cba = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cba, "%u", remaining);
- if (xml_value_set(xa, cbuf_get(cba)) < 0)
- goto done;
- if (xml_prefix_set(xa, "cp") < 0)
- goto done;
- if (xmlns_set(x1, "cp", "http://clicon.org/clixon-netconf-list-pagination") < 0)
- goto done;
- if (cba)
- cbuf_free(cba);
+ /* Add remaining attribute */
+ if ((xa = xml_new("remaining", x1, CX_ATTR)) == NULL)
+ goto done;
+ if ((cba = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cba, "%u", remaining);
+ if (xml_value_set(xa, cbuf_get(cba)) < 0)
+ goto done;
+ if (xml_prefix_set(xa, "cp") < 0)
+ goto done;
+ if (xmlns_set(x1, "cp", "http://clicon.org/clixon-netconf-list-pagination") < 0)
+ goto done;
+ if (cba)
+ cbuf_free(cba);
}
#endif /* LIST_PAGINATION_REMAINING */
if (get_nacm_and_reply(h, xret, xvec, xlen, xpath, nsc, username, depth, cbret) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
if (xvec)
- free(xvec);
+ free(xvec);
if (cbmsg)
- cbuf_free(cbmsg);
+ cbuf_free(cbmsg);
if (cbpath)
- cbuf_free(cbpath);
+ cbuf_free(cbpath);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -833,12 +833,12 @@ get_list_pagination(clicon_handle h,
*/
static int
get_common(clicon_handle h,
- struct client_entry *ce,
- cxobj *xe,
- netconf_content content,
- char *db,
- cbuf *cbret
- )
+ struct client_entry *ce,
+ cxobj *xe,
+ netconf_content content,
+ char *db,
+ cbuf *cbret
+ )
{
int retval = -1;
cxobj *xfilter;
@@ -864,103 +864,103 @@ get_common(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
username = clicon_username_get(h);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No yang spec9");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "No yang spec9");
+ goto done;
}
if ((xfilter = xml_find(xe, "filter")) != NULL){
- if ((xpath0 = xml_find_value(xfilter, "select"))==NULL)
- xpath0 = "/";
- /* Create namespace context for xpath from
- * The set of namespace declarations are those in scope on the
- * element.
- */
- else
- if (xml_nsctx_node(xfilter, &nsc0) < 0)
- goto done;
- if ((ret = xpath2canonical(xpath0, nsc0, yspec, &xpath, &nsc, &cbreason)) < 0)
- goto done;
- if (ret == 0){
- if (netconf_bad_attribute(cbret, "application",
- "select", cbuf_get(cbreason)) < 0)
- goto done;
- goto ok;
- }
+ if ((xpath0 = xml_find_value(xfilter, "select"))==NULL)
+ xpath0 = "/";
+ /* Create namespace context for xpath from
+ * The set of namespace declarations are those in scope on the
+ * element.
+ */
+ else
+ if (xml_nsctx_node(xfilter, &nsc0) < 0)
+ goto done;
+ if ((ret = xpath2canonical(xpath0, nsc0, yspec, &xpath, &nsc, &cbreason)) < 0)
+ goto done;
+ if (ret == 0){
+ if (netconf_bad_attribute(cbret, "application",
+ "select", cbuf_get(cbreason)) < 0)
+ goto done;
+ goto ok;
+ }
}
/* Clixon extensions: depth */
if ((attr = xml_find_value(xe, "depth")) != NULL){
- if ((ret = parse_int32(attr, &depth, &reason)) < 0){
- clicon_err(OE_XML, errno, "parse_int32");
- goto done;
- }
- if (ret == 0){
- if (netconf_bad_attribute(cbret, "application",
- "depth", "Unrecognized value of depth attribute") < 0)
- goto done;
- goto ok;
- }
+ if ((ret = parse_int32(attr, &depth, &reason)) < 0){
+ clicon_err(OE_XML, errno, "parse_int32");
+ goto done;
+ }
+ if (ret == 0){
+ if (netconf_bad_attribute(cbret, "application",
+ "depth", "Unrecognized value of depth attribute") < 0)
+ goto done;
+ goto ok;
+ }
}
/* Check if list pagination */
if ((xfind = xml_find_type(xe, NULL, "list-pagination", CX_ELMNT)) != NULL)
- list_pagination = 1;
+ list_pagination = 1;
/* Sanity check for list pagination: path must be a list/leaf-list, if it is,
* check config/state
*/
if (list_pagination){
- if (get_list_pagination(h, ce,
- xfind,
- content, db,
- depth, yspec, xpath, nsc, username,
- cbret) < 0)
- goto done;
- goto ok;
+ if (get_list_pagination(h, ce,
+ xfind,
+ content, db,
+ depth, yspec, xpath, nsc, username,
+ cbret) < 0)
+ goto done;
+ goto ok;
}
/* Read configuration */
switch (content){
case CONTENT_CONFIG: /* config data only */
- /* specific xpath */
- if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, &xret, NULL, NULL) < 0) {
- if ((cbmsg = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason);
- if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
- goto done;
- goto ok;
- }
- break;
+ /* specific xpath */
+ if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, &xret, NULL, NULL) < 0) {
+ if ((cbmsg = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason);
+ if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
+ goto done;
+ goto ok;
+ }
+ break;
case CONTENT_ALL: /* both config and state */
case CONTENT_NONCONFIG: /* state data only */
- if (clicon_option_bool(h, "CLICON_VALIDATE_STATE_XML")){
- /* Whole config tree, for validate debug */
- if (xmldb_get0(h, "running", YB_MODULE, nsc, NULL, 1, &xret, NULL, NULL) < 0) {
- if ((cbmsg = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason);
- if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
- goto done;
- goto ok;
- }
- }
- else if (content == CONTENT_ALL){
- /* specific xpath */
- if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, &xret, NULL, NULL) < 0) {
- if ((cbmsg = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason);
- if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
- goto done;
- goto ok;
- }
- }
- /* CONTENT_NONCONFIG */
- else if ((xret = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)/* Only top tree */
- goto done;
- break;
+ if (clicon_option_bool(h, "CLICON_VALIDATE_STATE_XML")){
+ /* Whole config tree, for validate debug */
+ if (xmldb_get0(h, "running", YB_MODULE, nsc, NULL, 1, &xret, NULL, NULL) < 0) {
+ if ((cbmsg = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason);
+ if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
+ goto done;
+ goto ok;
+ }
+ }
+ else if (content == CONTENT_ALL){
+ /* specific xpath */
+ if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, &xret, NULL, NULL) < 0) {
+ if ((cbmsg = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason);
+ if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
+ goto done;
+ goto ok;
+ }
+ }
+ /* CONTENT_NONCONFIG */
+ else if ((xret = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)/* Only top tree */
+ goto done;
+ break;
}/* switch content */
/* If not only config,
* get state data from plugins as defined by plugin_statedata(), if any
@@ -968,83 +968,83 @@ get_common(clicon_handle h,
/* Read state */
switch (content){
case CONTENT_CONFIG: /* config data only */
- break;
+ break;
case CONTENT_ALL: /* both config and state */
case CONTENT_NONCONFIG: /* state data only */
- if ((ret = get_client_statedata(h, xpath?xpath:"/", nsc, &xret)) < 0)
- goto done;
- if (ret == 0){ /* Error from callback (error in xret) */
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- goto ok;
- }
- break;
+ if ((ret = get_client_statedata(h, xpath?xpath:"/", nsc, &xret)) < 0)
+ goto done;
+ if (ret == 0){ /* Error from callback (error in xret) */
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ goto ok;
+ }
+ break;
}
if (with_defaults(xe, xret) < 0)
- goto done;
+ goto done;
if (content != CONTENT_CONFIG &&
- clicon_option_bool(h, "CLICON_VALIDATE_STATE_XML")){
- /* Check XML by validating it. return internal error with error cause
- * Primarily intended for user-supplied state-data.
- * The whole config tree must be present in case the state data references config data
- */
- if ((ret = xml_yang_validate_all_top(h, xret, &xerr)) < 0)
- goto done;
- if (ret > 0 &&
- (ret = xml_yang_validate_add(h, xret, &xerr)) < 0)
- goto done;
- if (ret == 0){
- if (clicon_debug_get())
- clicon_log_xml(LOG_DEBUG, xret, "VALIDATE_STATE");
- if (clixon_netconf_internal_error(xerr,
- ". Internal error, state callback returned invalid XML",
- NULL) < 0)
- goto done;
- if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
- goto done;
- goto ok;
- }
+ clicon_option_bool(h, "CLICON_VALIDATE_STATE_XML")){
+ /* Check XML by validating it. return internal error with error cause
+ * Primarily intended for user-supplied state-data.
+ * The whole config tree must be present in case the state data references config data
+ */
+ if ((ret = xml_yang_validate_all_top(h, xret, &xerr)) < 0)
+ goto done;
+ if (ret > 0 &&
+ (ret = xml_yang_validate_add(h, xret, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ if (clicon_debug_get())
+ clicon_log_xml(LOG_DEBUG, xret, "VALIDATE_STATE");
+ if (clixon_netconf_internal_error(xerr,
+ ". Internal error, state callback returned invalid XML",
+ NULL) < 0)
+ goto done;
+ if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
+ goto done;
+ goto ok;
+ }
} /* CLICON_VALIDATE_STATE_XML */
if (content == CONTENT_NONCONFIG){ /* state only, all config should be removed now */
- /* Keep state data only, remove everything that is config. Note that state data
- * may be a sub-part in a config tree, we need to traverse to find all
- */
- if (xml_non_config_data(xret, NULL) < 0)
- goto done;
- if (xml_tree_prune_flagged_sub(xret, XML_FLAG_MARK, 1, NULL) < 0)
- goto done;
- if (xml_apply(xret, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)XML_FLAG_MARK) < 0)
- goto done;
+ /* Keep state data only, remove everything that is config. Note that state data
+ * may be a sub-part in a config tree, we need to traverse to find all
+ */
+ if (xml_non_config_data(xret, NULL) < 0)
+ goto done;
+ if (xml_tree_prune_flagged_sub(xret, XML_FLAG_MARK, 1, NULL) < 0)
+ goto done;
+ if (xml_apply(xret, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)XML_FLAG_MARK) < 0)
+ goto done;
}
if (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath?xpath:"/") < 0)
- goto done;
+ goto done;
if (filter_xpath_again(h, yspec, xret, xvec, xlen, xpath, nsc) < 0)
- goto done;
+ goto done;
if (get_nacm_and_reply(h, xret, xvec, xlen, xpath, nsc, username, depth, cbret) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (xvec)
- free(xvec);
+ free(xvec);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (cbreason)
- cbuf_free(cbreason);
+ cbuf_free(cbreason);
if (nsc0)
- xml_nsctx_free(nsc0);
+ xml_nsctx_free(nsc0);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (cbmsg)
- cbuf_free(cbmsg);
+ cbuf_free(cbmsg);
if (reason)
- free(reason);
+ free(reason);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (xpath)
- free(xpath);
+ free(xpath);
return retval;
}
@@ -1061,18 +1061,18 @@ get_common(clicon_handle h,
*/
int
from_client_get_config(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
char *db;
struct client_entry *ce = (struct client_entry *)arg;
if ((db = netconf_db_find(xe, "source")) == NULL){
- clicon_err(OE_XML, 0, "db not found");
- goto done;
+ clicon_err(OE_XML, 0, "db not found");
+ goto done;
}
retval = get_common(h, ce, xe, CONTENT_CONFIG, db, cbret);
done:
@@ -1093,10 +1093,10 @@ from_client_get_config(clicon_handle h,
*/
int
from_client_get(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
netconf_content content = CONTENT_ALL;
char *attr;
@@ -1104,6 +1104,6 @@ from_client_get(clicon_handle h,
/* Clixon extensions: content */
if ((attr = xml_find_value(xe, "content")) != NULL)
- content = netconf_content_str2int(attr);
+ content = netconf_content_str2int(attr);
return get_common(h, ce, xe, content, "running", cbret);
}
diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c
index ac8bc69d..7de8ac41 100644
--- a/apps/backend/backend_main.c
+++ b/apps/backend/backend_main.c
@@ -101,29 +101,30 @@ backend_terminate(clicon_handle h)
clicon_debug(1, "%s", __FUNCTION__);
if ((ss = clicon_socket_get(h)) != -1)
- close(ss);
+ close(ss);
/* Disconnect datastore */
xmldb_disconnect(h);
/* Clear module state caches */
if ((x = clicon_modst_cache_get(h, 0)) != NULL)
- xml_free(x);
+ xml_free(x);
if ((x = clicon_modst_cache_get(h, 1)) != NULL)
- xml_free(x);
+ xml_free(x);
/* Free changelog */
if ((x = clicon_xml_changelog_get(h)) != NULL)
- xml_free(x);
+ xml_free(x);
if ((yspec = clicon_dbspec_yang(h)) != NULL)
- ys_free(yspec);
+ ys_free(yspec);
if ((yspec = clicon_config_yang(h)) != NULL)
- ys_free(yspec);
+ ys_free(yspec);
if ((yspec = clicon_nacm_ext_yang(h)) != NULL)
- ys_free(yspec);
+ ys_free(yspec);
if ((nsctx = clicon_nsctx_global_get(h)) != NULL)
- cvec_free(nsctx);
+ cvec_free(nsctx);
if ((x = clicon_nacm_ext(h)) != NULL)
- xml_free(x);
+ xml_free(x);
if ((x = clicon_conf_xml(h)) != NULL)
- xml_free(x);
+ xml_free(x);
+ confirmed_commit_free(h);
stream_publish_exit();
/* Delete all plugins, RPC callbacks, and upgrade callbacks */
clixon_plugin_module_exit(h);
@@ -133,9 +134,9 @@ backend_terminate(clicon_handle h)
xpath_optimize_exit();
clixon_pagination_free(h);
if (pidfile)
- unlink(pidfile);
+ unlink(pidfile);
if (sockfamily==AF_UNIX && lstat(sockpath, &st) == 0)
- unlink(sockpath);
+ unlink(sockpath);
backend_handle_exit(h); /* Also deletes streams. Cannot use h after this. */
clixon_event_exit();
clicon_debug(1, "%s done", __FUNCTION__);
@@ -152,8 +153,8 @@ backend_sig_term(int arg)
static int i=0;
if (i++ == 0)
- clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d",
- __PROGRAM__, __FUNCTION__, getpid(), arg);
+ clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d",
+ __PROGRAM__, __FUNCTION__, getpid(), arg);
clixon_exit_set(1); /* checked in clixon_event_loop() */
}
@@ -180,12 +181,12 @@ backend_server_socket(clicon_handle h)
/* Open control socket */
if ((ss = backend_socket_init(h)) < 0)
- return -1;
+ return -1;
/* ss is a server socket that the clients connect to. The callback
therefore accepts clients on ss */
if (clixon_event_reg_fd(ss, backend_accept_client, h, "server socket") < 0) {
- close(ss);
- return -1;
+ close(ss);
+ return -1;
}
return ss;
}
@@ -204,63 +205,63 @@ nacm_load_external(clicon_handle h)
filename = clicon_option_str(h, "CLICON_NACM_FILE");
if (filename == NULL || strlen(filename)==0){
- clicon_err(OE_UNIX, errno, "CLICON_NACM_FILE not set in NACM external mode");
- goto done;
+ clicon_err(OE_UNIX, errno, "CLICON_NACM_FILE not set in NACM external mode");
+ goto done;
}
if (stat(filename, &st) < 0){
- clicon_err(OE_UNIX, errno, "%s", filename);
- goto done;
+ clicon_err(OE_UNIX, errno, "%s", filename);
+ goto done;
}
if (!S_ISREG(st.st_mode)){
- clicon_err(OE_UNIX, 0, "%s is not a regular file", filename);
- goto done;
+ clicon_err(OE_UNIX, 0, "%s is not a regular file", filename);
+ goto done;
}
if ((f = fopen(filename, "r")) == NULL) {
- clicon_err(OE_UNIX, errno, "configure file: %s", filename);
- return -1;
+ clicon_err(OE_UNIX, errno, "configure file: %s", filename);
+ return -1;
}
if ((yspec = yspec_new()) == NULL)
- goto done;
+ goto done;
if (yang_spec_parse_module(h, "ietf-netconf-acm", NULL, yspec) < 0)
- goto done;
+ goto done;
/* Read configfile */
if (clixon_xml_parse_file(f, YB_MODULE, yspec, &xt, NULL) < 0)
- goto done;
+ goto done;
if (xt == NULL){
- clicon_err(OE_XML, 0, "No xml tree in %s", filename);
- goto done;
+ clicon_err(OE_XML, 0, "No xml tree in %s", filename);
+ goto done;
}
if (clicon_nacm_ext_yang_set(h, yspec) < 0)
- goto done;
+ goto done;
if (clicon_nacm_ext_set(h, xt) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (f)
- fclose(f);
+ fclose(f);
return retval;
}
static int
xmldb_drop_priv(clicon_handle h,
- const char *db,
- uid_t uid,
- gid_t gid)
+ const char *db,
+ uid_t uid,
+ gid_t gid)
{
int retval = -1;
char *filename = NULL;
if (xmldb_db2file(h, db, &filename) < 0)
- goto done;
+ goto done;
if (chown(filename, uid, gid) < 0){
- clicon_err(OE_UNIX, errno, "chown");
- goto done;
+ clicon_err(OE_UNIX, errno, "chown");
+ goto done;
}
retval = 0;
done:
if (filename)
- free(filename);
+ free(filename);
return retval;
}
@@ -279,7 +280,8 @@ xmldb_drop_priv(clicon_handle h,
*/
static int
check_drop_priv(clicon_handle h,
- gid_t gid)
+ gid_t gid,
+ yang_stmt *yspec)
{
int retval = -1;
uid_t uid;
@@ -287,69 +289,76 @@ check_drop_priv(clicon_handle h,
enum priv_mode_t priv_mode = PM_NONE;
char *backend_user = NULL;
-
/* Get privileges mode (for dropping privileges) */
if ((priv_mode = clicon_backend_privileges_mode(h)) == PM_NONE)
- goto ok;
+ goto ok;
/* From here, drop privileges */
/* Check backend user exists */
if ((backend_user = clicon_backend_user(h)) == NULL){
- clicon_err(OE_DAEMON, EPERM, "Privileges cannot be dropped without specifying CLICON_BACKEND_USER\n");
- goto done;
+ clicon_err(OE_DAEMON, EPERM, "Privileges cannot be dropped without specifying CLICON_BACKEND_USER\n");
+ goto done;
}
/* Get (wanted) new backend user id */
if (name2uid(backend_user, &newuid) < 0){
- clicon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", backend_user);
- goto done;
+ clicon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", backend_user);
+ goto done;
}
/* get current backend userid, if already at this level OK */
if ((uid = getuid()) == newuid)
- goto ok;
+ goto ok;
if (uid != 0){
- clicon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid);
- goto done;
+ clicon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid);
+ goto done;
}
/* When dropping privileges, datastores are created if they do not exist.
* But when drops are not made, datastores are created on demand.
* XXX: move the creation to top-level so they are always created at init?
*/
if (xmldb_exists(h, "running") != 1)
- if (xmldb_create(h, "running") < 0)
- goto done;
+ if (xmldb_create(h, "running") < 0)
+ goto done;
if (xmldb_drop_priv(h, "running", newuid, gid) < 0)
- goto done;
+ goto done;
if (xmldb_exists(h, "candidate") != 1)
- if (xmldb_create(h, "candidate") < 0)
- goto done;
+ if (xmldb_create(h, "candidate") < 0)
+ goto done;
if (xmldb_drop_priv(h, "candidate", newuid, gid) < 0)
- goto done;
- if (xmldb_exists(h, "startup") != 1)
- if (xmldb_create(h, "startup") < 0)
- goto done;
- if (xmldb_drop_priv(h, "startup", newuid, gid) < 0)
- goto done;
-
+ goto done;
+ if (if_feature(yspec, "ietf-netconf", "startup")) {
+ if (xmldb_exists(h, "startup") != 1)
+ if (xmldb_create(h, "startup") < 0)
+ goto done;
+ if (xmldb_drop_priv(h, "startup", newuid, gid) < 0)
+ goto done;
+ }
+ if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) {
+ if (xmldb_exists(h, "rollback") != 1)
+ if (xmldb_create(h, "rollback") < 0)
+ goto done;
+ if (xmldb_drop_priv(h, "rollback", newuid, gid) < 0)
+ goto done;
+ }
if (setgid(gid) == -1) {
- clicon_err(OE_DAEMON, errno, "setgid %d", gid);
- goto done;
+ clicon_err(OE_DAEMON, errno, "setgid %d", gid);
+ goto done;
}
switch (priv_mode){
case PM_DROP_PERM:
- if (drop_priv_perm(newuid) < 0)
- goto done;
- /* Verify you cannot regain root privileges */
- if (setuid(0) != -1){
- clicon_err(OE_DAEMON, EPERM, "Could regain root privilieges");
- goto done;
- }
- break;
+ if (drop_priv_perm(newuid) < 0)
+ goto done;
+ /* Verify you cannot regain root privileges */
+ if (setuid(0) != -1){
+ clicon_err(OE_DAEMON, EPERM, "Could regain root privilieges");
+ goto done;
+ }
+ break;
case PM_DROP_TEMP:
- if (drop_priv_temp(newuid) < 0)
- goto done;
- break;
+ if (drop_priv_temp(newuid) < 0)
+ goto done;
+ break;
case PM_NONE:
- break; /* catched above */
+ break; /* catched above */
}
ok:
retval = 0;
@@ -374,25 +383,25 @@ check_drop_priv(clicon_handle h,
*/
static int
ret2status(int ret,
- enum startup_status *status)
+ enum startup_status *status)
{
int retval = -1;
switch (ret){
case -1:
- if (clicon_suberrno != XMLPARSE_ERRNO)
- goto done;
- clicon_err_reset();
- *status = STARTUP_ERR;
- break;
+ if (clicon_suberrno != XMLPARSE_ERRNO)
+ goto done;
+ clicon_err_reset();
+ *status = STARTUP_ERR;
+ break;
case 0:
- *status = STARTUP_INVALID;
- break;
+ *status = STARTUP_INVALID;
+ break;
case 1:
- *status = STARTUP_OK;
- break;
+ *status = STARTUP_OK;
+ break;
default:
- clicon_err(OE_CFG, EINVAL, "No such retval %d", retval);
+ clicon_err(OE_CFG, EINVAL, "No such retval %d", retval);
} /* switch */
retval = 0;
done:
@@ -403,7 +412,7 @@ ret2status(int ret,
/* Debug timer */
int
backend_timer_setup(int fd,
- void *arg)
+ void *arg)
{
int retval = -1;
clicon_handle h = (clicon_handle)arg;
@@ -421,10 +430,10 @@ backend_timer_setup(int fd,
/* Initiate new timer */
timeradd(&now, &t1, &t);
if (clixon_event_reg_timeout(t,
- backend_timer_setup, /* this function */
- h, /* clicon handle */
- "backend timer setup") < 0)
- goto done;
+ backend_timer_setup, /* this function */
+ h, /* clicon handle */
+ "backend timer setup") < 0)
+ goto done;
retval = 0;
done:
return retval;
@@ -443,35 +452,35 @@ usage(clicon_handle h,
char *group = clicon_sock_group(h);
fprintf(stderr, "usage:%s *\n"
- "where options are\n"
+ "where options are\n"
"\t-h\t\tHelp\n"
- "\t-D \tDebug level\n"
- "\t-f \tClixon config file\n"
- "\t-E \tExtra configuration file directory\n"
- "\t-l > \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (syslog is default)\n"
- "\t-d \tSpecify backend plugin directory (default: %s)\n"
- "\t-p \tAdd Yang directory path (see CLICON_YANG_DIR)\n"
- "\t-b \tSpecify datastore directory\n"
- "\t-F\t\tRun in foreground, do not run as daemon\n"
- "\t-z\t\tKill other backend daemon and exit\n"
- "\t-a UNIX|IPv4|IPv6 Internal backend socket family\n"
- "\t-u \tInternal socket domain path or IP addr (see -a)(default: %s)\n"
- "\t-P \tPid filename (default: %s)\n"
- "\t-1\t\tRun once and then quit (dont wait for events)\n"
- "\t-s \tSpecify backend startup mode: none|startup|running|init)\n"
- "\t-c \tLoad extra XML configuration file, but do not commit.\n"
- "\t-q \t\tQuit startup directly after upgrading and print result on stdout\n"
- "\t-U \tRun backend daemon as this user AND drop privileges permanently\n"
- "\t-g \tClient membership required to this group (default: %s)\n"
+ "\t-D \tDebug level\n"
+ "\t-f \tClixon config file\n"
+ "\t-E \tExtra configuration file directory\n"
+ "\t-l > \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (syslog is default)\n"
+ "\t-d \tSpecify backend plugin directory (default: %s)\n"
+ "\t-p \tAdd Yang directory path (see CLICON_YANG_DIR)\n"
+ "\t-b \tSpecify datastore directory\n"
+ "\t-F\t\tRun in foreground, do not run as daemon\n"
+ "\t-z\t\tKill other backend daemon and exit\n"
+ "\t-a UNIX|IPv4|IPv6 Internal backend socket family\n"
+ "\t-u \tInternal socket domain path or IP addr (see -a)(default: %s)\n"
+ "\t-P \tPid filename (default: %s)\n"
+ "\t-1\t\tRun once and then quit (dont wait for events)\n"
+ "\t-s \tSpecify backend startup mode: none|startup|running|init)\n"
+ "\t-c \tLoad extra XML configuration file, but do not commit.\n"
+ "\t-q \t\tQuit startup directly after upgrading and print result on stdout\n"
+ "\t-U \tRun backend daemon as this user AND drop privileges permanently\n"
+ "\t-g \tClient membership required to this group (default: %s)\n"
- "\t-y \tLoad yang spec file (override yang main module)\n"
- "\t-o \"=\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
- argv0,
- plgdir ? plgdir : "none",
- confsock ? confsock : "none",
- confpid ? confpid : "none",
- group ? group : "none"
- );
+ "\t-y \tLoad yang spec file (override yang main module)\n"
+ "\t-o \"=\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
+ argv0,
+ plgdir ? plgdir : "none",
+ confsock ? confsock : "none",
+ confpid ? confpid : "none",
+ group ? group : "none"
+ );
exit(-1);
}
@@ -515,7 +524,7 @@ main(int argc,
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
/* Initiate CLICON handle */
if ((h = backend_handle_init()) == NULL)
- return -1;
+ return -1;
foreground = 0;
once = 0;
zap = 0;
@@ -528,38 +537,38 @@ main(int argc,
opterr = 0;
optind = 1;
while ((c = getopt(argc, argv, BACKEND_OPTS)) != -1)
- switch (c) {
- case 'h':
- /* Defer the call to usage() to later. Reason is that for helpful
- text messages, default dirs, etc, are not set until later.
- But this measn that we need to check if 'help' is set before
- exiting, and then call usage() before exit.
- */
- help = 1;
- break;
- case 'D' : /* debug */
- if (sscanf(optarg, "%d", &dbg) != 1)
- usage(h, argv[0]);
- break;
- case 'f': /* config file */
- if (!strlen(optarg))
- usage(h, argv[0]);
- clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
- break;
- case 'E': /* extra config directory */
- if (!strlen(optarg))
- usage(h, argv[0]);
- clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
- break;
- case 'l': /* Log destination: s|e|o */
- if ((logdst = clicon_log_opt(optarg[0])) < 0)
- usage(h, argv[0]);
- if (logdst == CLICON_LOG_FILE &&
- strlen(optarg)>1 &&
- clicon_log_file(optarg+1) < 0)
- goto done;
- break;
- }
+ switch (c) {
+ case 'h':
+ /* Defer the call to usage() to later. Reason is that for helpful
+ text messages, default dirs, etc, are not set until later.
+ But this measn that we need to check if 'help' is set before
+ exiting, and then call usage() before exit.
+ */
+ help = 1;
+ break;
+ case 'D' : /* debug */
+ if (sscanf(optarg, "%d", &dbg) != 1)
+ usage(h, argv[0]);
+ break;
+ case 'f': /* config file */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
+ break;
+ case 'E': /* extra config directory */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
+ break;
+ case 'l': /* Log destination: s|e|o */
+ if ((logdst = clicon_log_opt(optarg[0])) < 0)
+ usage(h, argv[0]);
+ if (logdst == CLICON_LOG_FILE &&
+ strlen(optarg)>1 &&
+ clicon_log_file(optarg+1) < 0)
+ goto done;
+ break;
+ }
/*
* Here we have the debug flag settings, use that.
* Syslogs also to stderr, but later turn stderr off in daemon mode.
@@ -573,107 +582,107 @@ main(int argc,
/* Find and read configfile */
if (clicon_options_main(h) < 0){
- if (help)
- usage(h, argv[0]);
- goto done;
+ if (help)
+ usage(h, argv[0]);
+ goto done;
}
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
- goto done;
+ goto done;
/* Now run through the operational args */
opterr = 1;
optind = 1;
while ((c = getopt(argc, argv, BACKEND_OPTS)) != -1)
- switch (c) {
- case 'h' : /* help */
- case 'D' : /* debug */
- case 'f': /* config file */
- case 'E': /* extra config dir */
- case 'l' :
- break; /* see above */
- case 'd': /* Plugin directory */
- if (!strlen(optarg))
- usage(h, argv[0]);
- if (clicon_option_add(h, "CLICON_BACKEND_DIR", optarg) < 0)
- goto done;
- break;
- case 'b': /* XMLDB database directory */
- if (!strlen(optarg))
- usage(h, argv[0]);
- if (clicon_option_add(h, "CLICON_XMLDB_DIR", optarg) < 0)
- goto done;
- break;
- case 'p' : /* Add yang dir path */
- if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
- goto done;
- break;
- case 'F' : /* foreground */
- foreground = 1;
- break;
- case 'z': /* Zap other process */
- zap++;
- break;
- case 'a': /* internal backend socket address family */
- if (clicon_option_add(h, "CLICON_SOCK_FAMILY", optarg) < 0)
- goto done;
- break;
- case 'u': /* config unix domain path / ip address */
- if (!strlen(optarg))
- usage(h, argv[0]);
- if (clicon_option_add(h, "CLICON_SOCK", optarg) < 0)
- goto done;
- break;
- case 'P': /* pidfile */
- if (clicon_option_add(h, "CLICON_BACKEND_PIDFILE", optarg) < 0)
- goto done;
- break;
- case '1' : /* Quit after reading database once - dont wait for events */
- once = 1;
- break;
- case 'q': /* Quit directly after startup upgrading and print result on stdout */
- if (clicon_quit_upgrade_set(h, 1) < 0)
- goto done;
- break;
- case 's' : /* startup mode */
- if (clicon_option_add(h, "CLICON_STARTUP_MODE", optarg) < 0)
- goto done;
- if (clicon_startup_mode(h) < 0){
- fprintf(stderr, "Invalid startup mode: %s\n", optarg);
- usage(h, argv[0]);
- }
- break;
- case 'c': /* Load application config */
- extraxml_file = optarg;
- break;
- case 'U': /* config user (for socket and drop privileges) */
- if (clicon_username_set(h, optarg) < 0)
- goto done;
- if (clicon_option_add(h, "CLICON_BACKEND_PRIVILEGES", "drop_permanent") < 0)
- goto done;
- break;
- case 'g': /* config socket group */
- if (clicon_option_add(h, "CLICON_SOCK_GROUP", optarg) < 0)
- goto done;
- break;
- case 'y' : /* Load yang absolute filename */
- if (clicon_option_add(h, "CLICON_YANG_MAIN_FILE", optarg) < 0)
- goto done;
- break;
- case 'o':{ /* Configuration option */
- char *val;
- if ((val = index(optarg, '=')) == NULL)
- usage(h, argv0);
- *val++ = '\0';
- if (clicon_option_add(h, optarg, val) < 0)
- goto done;
- break;
- }
- default:
- usage(h, argv[0]);
- break;
- }
+ switch (c) {
+ case 'h' : /* help */
+ case 'D' : /* debug */
+ case 'f': /* config file */
+ case 'E': /* extra config dir */
+ case 'l' :
+ break; /* see above */
+ case 'd': /* Plugin directory */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ if (clicon_option_add(h, "CLICON_BACKEND_DIR", optarg) < 0)
+ goto done;
+ break;
+ case 'b': /* XMLDB database directory */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ if (clicon_option_add(h, "CLICON_XMLDB_DIR", optarg) < 0)
+ goto done;
+ break;
+ case 'p' : /* Add yang dir path */
+ if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
+ goto done;
+ break;
+ case 'F' : /* foreground */
+ foreground = 1;
+ break;
+ case 'z': /* Zap other process */
+ zap++;
+ break;
+ case 'a': /* internal backend socket address family */
+ if (clicon_option_add(h, "CLICON_SOCK_FAMILY", optarg) < 0)
+ goto done;
+ break;
+ case 'u': /* config unix domain path / ip address */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ if (clicon_option_add(h, "CLICON_SOCK", optarg) < 0)
+ goto done;
+ break;
+ case 'P': /* pidfile */
+ if (clicon_option_add(h, "CLICON_BACKEND_PIDFILE", optarg) < 0)
+ goto done;
+ break;
+ case '1' : /* Quit after reading database once - dont wait for events */
+ once = 1;
+ break;
+ case 'q': /* Quit directly after startup upgrading and print result on stdout */
+ if (clicon_quit_upgrade_set(h, 1) < 0)
+ goto done;
+ break;
+ case 's' : /* startup mode */
+ if (clicon_option_add(h, "CLICON_STARTUP_MODE", optarg) < 0)
+ goto done;
+ if (clicon_startup_mode(h) < 0){
+ fprintf(stderr, "Invalid startup mode: %s\n", optarg);
+ usage(h, argv[0]);
+ }
+ break;
+ case 'c': /* Load application config */
+ extraxml_file = optarg;
+ break;
+ case 'U': /* config user (for socket and drop privileges) */
+ if (clicon_username_set(h, optarg) < 0)
+ goto done;
+ if (clicon_option_add(h, "CLICON_BACKEND_PRIVILEGES", "drop_permanent") < 0)
+ goto done;
+ break;
+ case 'g': /* config socket group */
+ if (clicon_option_add(h, "CLICON_SOCK_GROUP", optarg) < 0)
+ goto done;
+ break;
+ case 'y' : /* Load yang absolute filename */
+ if (clicon_option_add(h, "CLICON_YANG_MAIN_FILE", optarg) < 0)
+ goto done;
+ break;
+ case 'o':{ /* Configuration option */
+ char *val;
+ if ((val = index(optarg, '=')) == NULL)
+ usage(h, argv0);
+ *val++ = '\0';
+ if (clicon_option_add(h, optarg, val) < 0)
+ goto done;
+ break;
+ }
+ default:
+ usage(h, argv[0]);
+ break;
+ }
argc -= optind;
argv += optind;
@@ -685,7 +694,7 @@ main(int argc,
/* Defer: Wait to the last minute to print help message */
if (help)
- usage(h, argv[0]);
+ usage(h, argv[0]);
/* Init cligen buffers */
cligen_buflen = clicon_option_int(h, "CLICON_CLI_BUF_START");
@@ -693,75 +702,75 @@ main(int argc,
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
- clicon_log_string_limit_set(sz);
+ clicon_log_string_limit_set(sz);
#ifndef HAVE_LIBXML2
if (clicon_yang_regexp(h) == REGEXP_LIBXML2){
- clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))");
- goto done;
+ clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))");
+ goto done;
}
#endif
/* Check pid-file, if zap kil the old daemon, else return here */
if ((pidfile = clicon_backend_pidfile(h)) == NULL){
- clicon_err(OE_FATAL, 0, "pidfile not set");
- goto done;
+ clicon_err(OE_FATAL, 0, "pidfile not set");
+ goto done;
}
sockfamily = clicon_sock_family(h);
if ((sock = clicon_sock_str(h)) == NULL){
- clicon_err(OE_FATAL, 0, "sock not set");
- goto done;
+ clicon_err(OE_FATAL, 0, "sock not set");
+ goto done;
}
if (pidfile_get(pidfile, &pid) < 0)
- return -1;
+ return -1;
if (zap){
- if (pid && pidfile_zapold(pid) < 0)
- return -1;
- if (lstat(pidfile, &st) == 0)
- unlink(pidfile);
- if (sockfamily==AF_UNIX && lstat(sock, &st) == 0)
- unlink(sock);
- backend_terminate(h);
- exit(0); /* OK */
+ if (pid && pidfile_zapold(pid) < 0)
+ return -1;
+ if (lstat(pidfile, &st) == 0)
+ unlink(pidfile);
+ if (sockfamily==AF_UNIX && lstat(sock, &st) == 0)
+ unlink(sock);
+ backend_terminate(h);
+ exit(0); /* OK */
}
else
- if (pid){
- clicon_err(OE_DAEMON, 0, "Daemon already running with pid %d\n(Try killing it with %s -z)",
- pid, argv0);
- return -1; /* goto done deletes pidfile */
- }
+ if (pid){
+ clicon_err(OE_DAEMON, 0, "Daemon already running with pid %d\n(Try killing it with %s -z)",
+ pid, argv0);
+ return -1; /* goto done deletes pidfile */
+ }
/* After this point we can goto done on error
* Here there is either no old process or we have killed it,..
*/
if (lstat(pidfile, &st) == 0)
- unlink(pidfile);
+ unlink(pidfile);
if (sockfamily==AF_UNIX && lstat(sock, &st) == 0)
- unlink(sock);
+ unlink(sock);
/* Sanity check: backend group exists */
if ((backend_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(backend_group, &gid) < 0){
- clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group.\n" /* \n required here due to multi-line log */
- "The config daemon requires a valid group to create a server UNIX socket\n"
- "Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n"
- "or create the group and add the user to it. Check documentation for how to do this on your platform",
- backend_group,
- clicon_configfile(h));
- goto done;
+ clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group.\n" /* \n required here due to multi-line log */
+ "The config daemon requires a valid group to create a server UNIX socket\n"
+ "Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n"
+ "or create the group and add the user to it. Check documentation for how to do this on your platform",
+ backend_group,
+ clicon_configfile(h));
+ goto done;
}
/* Publish stream on pubsub channels.
* CLICON_STREAM_PUB should be set to URL to where streams are published
* and configure should be run with --enable-publish
*/
if (clicon_option_exists(h, "CLICON_STREAM_PUB") &&
- stream_publish_init() < 0)
- goto done;
+ stream_publish_init() < 0)
+ goto done;
/* Connect to plugin to get a handle */
if (xmldb_connect(h) < 0)
- goto done;
+ goto done;
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
xml_nsctx_namespace_netconf_default(h);
@@ -770,292 +779,298 @@ main(int argc,
* Otherwise it is loaded in netconf_module_load below
*/
if (netconf_module_features(h) < 0)
- goto done;
+ goto done;
/* In case ietf-yang-metadata is loaded by application, handle annotation extension */
if (yang_metadata_init(h) < 0)
- goto done;
+ goto done;
/* External NACM file?
* Note, loads yang -> extensions -> plugins
*/
nacm_mode = clicon_option_str(h, "CLICON_NACM_MODE");
if (nacm_mode && strcmp(nacm_mode, "external") == 0)
- if (nacm_load_external(h) < 0)
- goto done;
+ if (nacm_load_external(h) < 0)
+ goto done;
/* Create top-level yang spec and store as option */
if ((yspec = yspec_new()) == NULL)
- goto done;
- clicon_dbspec_yang_set(h, yspec);
+ goto done;
+ clicon_dbspec_yang_set(h, yspec);
/* Load backend plugins before yangs are loaded (eg extension callbacks) */
if ((dir = clicon_backend_dir(h)) != NULL &&
- clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir,
- clicon_option_str(h, "CLICON_BACKEND_REGEXP")) < 0)
- goto done;
+ clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir,
+ clicon_option_str(h, "CLICON_BACKEND_REGEXP")) < 0)
+ goto done;
/* Load Yang modules
* 1. Load a yang module as a specific absolute filename */
if ((str = clicon_yang_main_file(h)) != NULL)
- if (yang_spec_parse_file(h, str, yspec) < 0)
- goto done;
+ if (yang_spec_parse_file(h, str, yspec) < 0)
+ goto done;
/* 2. Load a (single) main module */
if ((str = clicon_yang_module_main(h)) != NULL)
- if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
- yspec) < 0)
- goto done;
+ if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
+ yspec) < 0)
+ goto done;
/* 3. Load all modules in a directory (will not overwrite file loaded ^) */
if ((str = clicon_yang_main_dir(h)) != NULL)
- if (yang_spec_load_dir(h, str, yspec) < 0)
- goto done;
+ if (yang_spec_load_dir(h, str, yspec) < 0)
+ goto done;
/* Load clixon lib yang module */
if (yang_spec_parse_module(h, "clixon-lib", NULL, yspec) < 0)
- goto done;
+ goto done;
/* Load yang module library, RFC7895 */
if (yang_modules_init(h) < 0)
- goto done;
+ goto done;
/* Add generic yang specs, used by netconf client and as internal protocol
*/
if (netconf_module_load(h) < 0)
- goto done;
+ goto done;
/* Load yang restconf module */
if (yang_spec_parse_module(h, "ietf-restconf", NULL, yspec)< 0)
- goto done;
+ goto done;
/* Load yang YANG module state */
if (clicon_option_bool(h, "CLICON_XMLDB_MODSTATE") &&
- yang_spec_parse_module(h, "ietf-yang-library", NULL, yspec)< 0)
- goto done;
+ yang_spec_parse_module(h, "ietf-yang-library", NULL, yspec)< 0)
+ goto done;
/* Check restconf start/stop from backend */
if (clicon_option_bool(h, "CLICON_BACKEND_RESTCONF_PROCESS")){
- if (backend_plugin_restconf_register(h, yspec) < 0)
- goto done;
+ if (backend_plugin_restconf_register(h, yspec) < 0)
+ goto done;
}
/* Here all modules are loaded
* Compute and set canonical namespace context
*/
if (xml_nsctx_yangspec(yspec, &nsctx_global) < 0)
- goto done;
+ goto done;
if (clicon_nsctx_global_set(h, nsctx_global) < 0)
- goto done;
+ goto done;
/* Initialize server socket and save it to handle */
if (backend_rpc_init(h) < 0)
- goto done;
+ goto done;
/* Must be after netconf_module_load, but before startup code */
if (clicon_option_bool(h, "CLICON_XML_CHANGELOG"))
- if (clixon_xml_changelog_init(h) < 0)
- goto done;
-
+ if (clixon_xml_changelog_init(h) < 0)
+ goto done;
+ /* Init commit confirmed */
+ if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) {
+ if (confirmed_commit_init(h) < 0)
+ goto done;
+ }
/* Save modules state of the backend (server). Compare with startup XML */
if (startup_module_state(h, yspec) < 0)
- goto done;
+ goto done;
/* Startup mode needs to be defined, */
startup_mode = clicon_startup_mode(h);
- if ((int)startup_mode == -1){
- clicon_log(LOG_ERR, "Startup mode undefined. Specify option CLICON_STARTUP_MODE or specify -s option to clicon_backend.");
- goto done;
+ if ((int)startup_mode == -1){
+ clicon_log(LOG_ERR, "Startup mode undefined. Specify option CLICON_STARTUP_MODE or specify -s option to clicon_backend.");
+ goto done;
}
/* Check that netconf :startup is enabled */
if ((startup_mode == SM_STARTUP || startup_mode == SM_RUNNING_STARTUP) &&
- !if_feature(yspec, "ietf-netconf", "startup")){
- clicon_log(LOG_ERR, "Startup mode selected but Netconf :startup feature is not enabled. Enable with option: ietf-netconf:startup ");
- goto done;
+ !if_feature(yspec, "ietf-netconf", "startup")){
+ clicon_log(LOG_ERR, "Startup mode selected but Netconf :startup feature is not enabled. Enable with option: ietf-netconf:startup ");
+ goto done;
}
/* Init running db if it is not there
* change running_startup -> running or startup depending on if running exists or not
*/
if (xmldb_exists(h, "running") != 1){
- if (startup_mode == SM_RUNNING_STARTUP)
- startup_mode = SM_STARTUP;
- if (xmldb_create(h, "running") < 0)
- return -1;
+ if (startup_mode == SM_RUNNING_STARTUP)
+ startup_mode = SM_STARTUP;
+ if (xmldb_create(h, "running") < 0)
+ return -1;
}
else
- if (startup_mode == SM_RUNNING_STARTUP)
- startup_mode = SM_RUNNING;
+ if (startup_mode == SM_RUNNING_STARTUP)
+ startup_mode = SM_RUNNING;
xmldb_delete(h, "candidate");
/* If startup fails, lib functions report invalidation info in a cbuf */
if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
switch (startup_mode){
case SM_INIT: /* Scratch running and start from empty */
- /* [Delete and] create running db */
- if (xmldb_db_reset(h, "running") < 0)
- goto done;
+ /* Delete any rollback database, if it exists */
+ xmldb_delete(h, "rollback");
+ /* [Delete and] create running db */
+ if (xmldb_db_reset(h, "running") < 0)
+ goto done;
case SM_NONE: /* Fall through *
- * Load plugins and call plugin_init() */
- if (clixon_plugin_reset_all(h, "running") < 0)
- goto done;
- status = STARTUP_OK;
- break;
+ * Load plugins and call plugin_init() */
+ if (clixon_plugin_reset_all(h, "running") < 0)
+ goto done;
+ status = STARTUP_OK;
+ break;
case SM_RUNNING: /* Use running as startup */
- /* Copy original running to tmp as backup (restore if error) */
- if (xmldb_copy(h, "running", "tmp") < 0)
- goto done;
- ret = startup_mode_startup(h, "tmp", cbret);
- /* If ret fails, copy tmp back to running */
- if (ret != 1)
- if (xmldb_copy(h, "tmp", "running") < 0)
- goto done;
- if (ret2status(ret, &status) < 0)
- goto done;
- break;
+ /* Copy original running to tmp as backup (restore if error) */
+ if (xmldb_copy(h, "running", "tmp") < 0)
+ goto done;
+ ret = startup_mode_startup(h, "tmp", cbret);
+ /* If ret fails, copy tmp back to running */
+ if (ret != 1)
+ if (xmldb_copy(h, "tmp", "running") < 0)
+ goto done;
+ if (ret2status(ret, &status) < 0)
+ goto done;
+ break;
case SM_STARTUP:
- /* Copy original running to tmp as backup (restore if error) */
- if (xmldb_copy(h, "running", "tmp") < 0)
- goto done;
- /* Load and commit from startup */
- ret = startup_mode_startup(h, "startup", cbret);
- /* If ret fails, copy tmp back to running */
- if (ret != 1)
- if (xmldb_copy(h, "tmp", "running") < 0)
- goto done;
- /* clear startup dbcache */
- xmldb_clear(h, "startup");
- if (ret2status(ret, &status) < 0)
- goto done;
- /* if status = STARTUP_INVALID, cbret contains info */
- break;
+ /* Copy original running to tmp as backup (restore if error) */
+ if (xmldb_copy(h, "running", "tmp") < 0)
+ goto done;
+ /* Load and commit from startup */
+ ret = startup_mode_startup(h, "startup", cbret);
+ /* If ret fails, copy tmp back to running */
+ if (ret != 1)
+ if (xmldb_copy(h, "tmp", "running") < 0)
+ goto done;
+ /* clear startup dbcache */
+ xmldb_clear(h, "startup");
+ if (ret2status(ret, &status) < 0)
+ goto done;
+ /* if status = STARTUP_INVALID, cbret contains info */
+ break;
default:;
- break;
+ break;
}
/* Quit after upgrade catch-all, running/startup quits in upgrade code */
if (clicon_quit_upgrade_get(h) == 1)
- goto done;
+ goto done;
/*
* Disable unknown to anydata auto-creation after startup
*/
if (clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1){
- clicon_option_bool_set(h, "CLICON_YANG_UNKNOWN_ANYDATA", 0);
- xml_bind_yang_unknown_anydata(0);
+ clicon_option_bool_set(h, "CLICON_YANG_UNKNOWN_ANYDATA", 0);
+ xml_bind_yang_unknown_anydata(0);
}
/* Merge extra XML from file and reset function to running
*/
if (status == STARTUP_OK){
- if (startup_mode == SM_NONE){
- /* Special case for mode none: no commits are made therefore need to go through all processes
- * registered in plugins (specifically the restconf pseudo plugin)
- */
- if (clixon_process_start_all(h) < 0)
- goto done;
- }
- else {
- if ((ret = startup_extraxml(h, extraxml_file, cbret)) < 0)
- goto done;
- if (ret2status(ret, &status) < 0)
- goto done;
- /* if status = STARTUP_INVALID, cbret contains info */
- }
+ if (startup_mode == SM_NONE){
+ /* Special case for mode none: no commits are made therefore need to go through all processes
+ * registered in plugins (specifically the restconf pseudo plugin)
+ */
+ if (clixon_process_start_all(h) < 0)
+ goto done;
+ }
+ else {
+ if ((ret = startup_extraxml(h, extraxml_file, cbret)) < 0)
+ goto done;
+ if (ret2status(ret, &status) < 0)
+ goto done;
+ /* if status = STARTUP_INVALID, cbret contains info */
+ }
}
if (status != STARTUP_OK){
- if (cbuf_len(cbret))
- clicon_log(LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret));
- if (startup_failsafe(h) < 0){
- goto done;
- }
- status = STARTUP_OK;
- cbuf_reset(cbret); /* cbret contains error info */
+ if (cbuf_len(cbret))
+ clicon_log(LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret));
+ if (load_failsafe(h, "Startup") < 0){
+ goto done;
+ }
+ status = STARTUP_OK;
+ cbuf_reset(cbret); /* cbret contains error info */
}
/* Initiate the shared candidate. */
if (xmldb_copy(h, "running", "candidate") < 0)
- goto done;
+ goto done;
if (xmldb_modified_set(h, "candidate", 0) <0)
- goto done;
+ goto done;
/* Set startup status */
if (clicon_startup_status_set(h, status) < 0)
- goto done;
+ goto done;
if (status == STARTUP_INVALID && cbuf_len(cbret))
- clicon_log(LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret));
-
+ clicon_log(LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret));
+
/* Call backend plugin_start with user -- options */
if (clixon_plugin_start_all(h) < 0)
- goto done;
+ goto done;
/* -1 option to run only once */
if (once)
- goto ok;
+ goto ok;
/* Daemonize and initiate logging. Note error is initiated here to make
daemonized errors OK. Before this stage, errors are logged on stderr
also */
if (foreground==0){
- /* Call plugin callbacks just before fork/daemonization */
- if (clixon_plugin_pre_daemon_all(h) < 0)
+ /* Call plugin callbacks just before fork/daemonization */
+ if (clixon_plugin_pre_daemon_all(h) < 0)
goto done;
- clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO,
- logdst==CLICON_LOG_FILE?CLICON_LOG_FILE:CLICON_LOG_SYSLOG);
- if (daemon(0, 0) < 0){
- fprintf(stderr, "config: daemon");
- exit(-1);
- }
+ clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO,
+ logdst==CLICON_LOG_FILE?CLICON_LOG_FILE:CLICON_LOG_SYSLOG);
+ if (daemon(0, 0) < 0){
+ fprintf(stderr, "config: daemon");
+ exit(-1);
+ }
}
/* Call plugin callbacks when in background and before dropped privileges
* Possibly this should be within the foreground==0 clause after daemon?
*/
if (clixon_plugin_daemon_all(h) < 0)
- goto done;
+ goto done;
/* Write pid-file */
if (pidfile_write(pidfile) < 0)
- goto done;
+ goto done;
if (set_signal(SIGTERM, backend_sig_term, NULL) < 0){
- clicon_err(OE_DAEMON, errno, "Setting signal");
- goto done;
+ clicon_err(OE_DAEMON, errno, "Setting signal");
+ goto done;
}
if (set_signal(SIGINT, backend_sig_term, NULL) < 0){
- clicon_err(OE_DAEMON, errno, "Setting signal");
- goto done;
+ clicon_err(OE_DAEMON, errno, "Setting signal");
+ goto done;
}
/* This is in case restconf daemon forked using process-control API */
if (set_signal(SIGCHLD, backend_sig_child, NULL) < 0){
- clicon_err(OE_DAEMON, errno, "Setting signal");
- goto done;
+ clicon_err(OE_DAEMON, errno, "Setting signal");
+ goto done;
}
/* Client exit in the middle of a transaction, handled in clicon_msg_send */
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
- clicon_err(OE_DAEMON, errno, "Setting signal");
- goto done;
+ clicon_err(OE_DAEMON, errno, "Setting signal");
+ goto done;
}
/* Initialize server socket and save it to handle */
if ((ss = backend_server_socket(h)) < 0)
- goto done;
+ goto done;
if (clicon_socket_set(h, ss) < 0)
- goto done;
+ goto done;
if (dbg)
- clicon_option_dump(h, dbg);
+ clicon_option_dump(h, dbg);
/* Depending on configure setting, privileges may be dropped here after
* initializations */
- if (check_drop_priv(h, gid) < 0)
- goto done;
+ if (check_drop_priv(h, gid, yspec) < 0)
+ goto done;
/* Start session-id for clients */
clicon_session_id_set(h, 0);
#if 0 /* debug */
/* Enable this to get prints of datastore and session status */
if (0 && clicon_debug_get() &&
- backend_timer_setup(0, h) < 0)
- goto done;
+ backend_timer_setup(0, h) < 0)
+ goto done;
#endif
if (stream_timer_setup(0, h) < 0)
- goto done;
+ goto done;
/* Just before event-loop, after socket bind/listen */
clicon_log(LOG_NOTICE, "%s: %u Started", __PROGRAM__, getpid());
if (clixon_event_loop(h) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
if (cbret)
- cbuf_free(cbret);
+ cbuf_free(cbret);
clicon_log(LOG_NOTICE, "%s: %u Terminated retval:%d", __PROGRAM__, getpid(), retval);
backend_terminate(h); /* Cannot use h after this */
diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c
index 1f55099c..121a9499 100644
--- a/apps/backend/backend_plugin.c
+++ b/apps/backend/backend_plugin.c
@@ -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;
diff --git a/apps/backend/backend_plugin_restconf.c b/apps/backend/backend_plugin_restconf.c
index dbe4f8e5..0b681894 100644
--- a/apps/backend/backend_plugin_restconf.c
+++ b/apps/backend/backend_plugin_restconf.c
@@ -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 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 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 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;
diff --git a/apps/backend/backend_socket.c b/apps/backend/backend_socket.c
index 31405fa2..fa2ee9c1 100644
--- a/apps/backend/backend_socket.c
+++ b/apps/backend/backend_socket.c
@@ -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;
}
diff --git a/apps/backend/backend_startup.c b/apps/backend/backend_startup.c
index 0b065ae4..e256783c 100644
--- a/apps/backend/backend_startup.c
+++ b/apps/backend/backend_startup.c
@@ -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,25 +129,71 @@ startup --+-------------------------------------> BROKEN XML
*/
int
startup_mode_startup(clicon_handle h,
- char *db,
- cbuf *cbret)
+ char *db,
+ cbuf *cbret)
{
- int retval = -1;
- int ret;
+ int retval = -1;
+ 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;
+ 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;
}
- if ((ret = startup_commit(h, db, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+
+ /* When a confirming-commit is issued, the confirmed-commit timeout
+ * callback is removed and then the rollback database is deleted.
+ *
+ * The presence of a rollback database means that before the rollback
+ * database was deleted, either clixon_backend crashed or the machine
+ * rebooted.
+ */
+ if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) {
+ if ((rollback_exists = xmldb_exists(h, "rollback")) < 0) {
+ clicon_err(OE_DAEMON, 0, "Error checking for the existence of the rollback database");
+ goto done;
+ }
+ if (rollback_exists == 1) {
+ ret = startup_commit(h, "rollback", cbret);
+ switch(ret) {
+ case -1:
+ case 0:
+ /* validation failed, cbret set */
+ if ((ret = startup_commit(h, "failsafe", cbret)) < 0)
+ goto fail;
+
+ /* Rename the errored rollback database so that it is not tried on a subsequent startup */
+ xmldb_rename(h, db, NULL, ".error");
+ goto ok;
+ case 1:
+ /* validation ok */
+ xmldb_delete(h, "rollback");
+ goto ok;
+ default:
+ /* Unexpected response */
+ 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;
+ }
+ ok:
retval = 1;
done:
return retval;
@@ -163,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;
@@ -175,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 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;
}
@@ -231,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.
@@ -260,89 +306,39 @@ 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;
goto done;
}
-/*! Reset running and start in failsafe mode. If no failsafe then quit.
- Typically done when startup status is not OK so
-
-failsafe ----------------------+
- reset \ commit
-running ----|-------+---------------> RUNNING FAILSAFE
- \
-tmp |---------------------->
- */
-int
-startup_failsafe(clicon_handle h)
-{
- int retval = -1;
- int ret;
- char *db = "failsafe";
- cbuf *cbret = NULL;
-
- if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- if ((ret = xmldb_exists(h, db)) < 0)
- goto done;
- if (ret == 0){ /* No it does not exist, fail */
- clicon_err(OE_DB, 0, "Startup failed and no Failsafe database found, exiting");
- goto done;
- }
- /* Copy original running to tmp as backup (restore if error) */
- if (xmldb_copy(h, "running", "tmp") < 0)
- goto done;
- if (xmldb_db_reset(h, "running") < 0)
- goto done;
- ret = candidate_commit(h, db, cbret);
- if (ret != 1)
- if (xmldb_copy(h, "tmp", "running") < 0)
- goto done;
- if (ret < 0)
- goto done;
- if (ret == 0){
- clicon_err(OE_DB, 0, "Startup failed, Failsafe database validation failed %s", cbuf_get(cbret));
- goto done;
- }
- clicon_log(LOG_NOTICE, "Startup failed, Failsafe database loaded ");
- retval = 0;
- done:
- if (cbret)
- cbuf_free(cbret);
- return retval;
-}
-
/*! Init modules state of the backend (server). To compare with startup XML
* Set the modules state as setopt to the datastore module.
* Only if CLICON_XMLDB_MODSTATE is enabled
@@ -351,25 +347,25 @@ startup_failsafe(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;
diff --git a/apps/backend/backend_startup.h b/apps/backend/backend_startup.h
index 741bd2e0..7191f028 100644
--- a/apps/backend/backend_startup.h
+++ b/apps/backend/backend_startup.h
@@ -44,7 +44,6 @@
*/
int startup_mode_startup(clicon_handle h, char *db, cbuf *cbret);
int startup_extraxml(clicon_handle h, char *file, cbuf *cbret);
-int startup_failsafe(clicon_handle h);
int startup_module_state(clicon_handle h, yang_stmt *yspec);
#endif /* _BACKEND_STARTUP_H_ */
diff --git a/apps/backend/clixon_backend_commit.h b/apps/backend/clixon_backend_commit.h
index 8f630878..666f7562 100644
--- a/apps/backend/clixon_backend_commit.h
+++ b/apps/backend/clixon_backend_commit.h
@@ -39,18 +39,44 @@
#ifndef _CLIXON_BACKEND_COMMIT_H_
#define _CLIXON_BACKEND_COMMIT_H_
+#define ROLLBACK_NOT_APPLIED 1
+#define ROLLBACK_DB_NOT_DELETED 2
+#define ROLLBACK_FAILSAFE_APPLIED 4
+
+#define COMMIT_NOT_CONFIRMED "Commit was not confirmed; automatic rollback complete."
+
+enum confirmed_commit_state {
+ INACTIVE, // a confirmed-commit is not in progress
+ PERSISTENT, // a confirmed-commit is in progress and a persist value was given
+ EPHEMERAL, // a confirmed-commit is in progress and a persist value was not given
+ ROLLBACK
+};
+
/*
* Prototypes
- */
+ */
+/* backend_confirm.c */
+int confirmed_commit_init(clicon_handle h);
+int confirmed_commit_free(clicon_handle h);
+enum confirmed_commit_state confirmed_commit_state_get(clicon_handle h);
+uint32_t confirmed_commit_session_id_get(clicon_handle h);
+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_confirmed_commit(clicon_handle h, cxobj *xe, uint32_t myid, cbuf *cbret);
+
+/* backend_commit.c */
int startup_validate(clicon_handle h, char *db, cxobj **xtr, cbuf *cbret);
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, 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_cancel_commit(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);
+int load_failsafe(clicon_handle h, char *phase);
#endif /* _CLIXON_BACKEND_COMMIT_H_ */
diff --git a/apps/backend/clixon_backend_handle.c b/apps/backend/clixon_backend_handle.c
index a5d0fb43..4dd89fc3 100644
--- a/apps/backend/clixon_backend_handle.c
+++ b/apps/backend/clixon_backend_handle.c
@@ -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;
}
diff --git a/apps/backend/clixon_backend_plugin.h b/apps/backend/clixon_backend_plugin.h
index 85afb16f..4bbff766 100644
--- a/apps/backend/clixon_backend_plugin.h
+++ b/apps/backend/clixon_backend_plugin.h
@@ -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);
diff --git a/apps/backend/clixon_backend_transaction.c b/apps/backend/clixon_backend_transaction.c
index 3fccf089..868bf713 100644
--- a/apps/backend/clixon_backend_transaction.c
+++ b/apps/backend/clixon_backend_transaction.c
@@ -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; itd_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; itd_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; itd_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; itd_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; itd_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; itd_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;
}
diff --git a/apps/cli/cli_auto.c b/apps/cli/cli_auto.c
index 7502ec34..71ad99ab 100644
--- a/apps/cli/cli_auto.c
+++ b/apps/cli/cli_auto.c
@@ -87,13 +87,13 @@ co2apipath(cg_obj *co)
cg_var *cv;
if (co == NULL)
- return NULL;
+ return NULL;
if ((cb = co->co_callbacks) == NULL)
- return NULL;
+ return NULL;
if ((cvv = cb->cc_cvec) == NULL)
- return NULL;
+ return NULL;
if ((cv = cvec_i(cvv, 0)) == NULL)
- return NULL;
+ return NULL;
return cv_string_get(cv);
}
@@ -102,25 +102,25 @@ co2apipath(cg_obj *co)
*/
static cvec*
cvec_append(cvec *cvv0,
- cvec *cvv1)
+ cvec *cvv1)
{
cvec *cvv2 = NULL;
cg_var *cv;
if (cvv0 == NULL){
- if ((cvv2 = cvec_dup(cvv1)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_dup");
- return NULL;
- }
+ if ((cvv2 = cvec_dup(cvv1)) == NULL){
+ clicon_err(OE_UNIX, errno, "cvec_dup");
+ return NULL;
+ }
}
else{
- if ((cvv2 = cvec_dup(cvv0)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_dup");
- return NULL;
- }
- cv = NULL; /* Append cvv1 to cvv2 */
- while ((cv = cvec_each1(cvv1, cv)) != NULL)
- cvec_append_var(cvv2, cv);
+ if ((cvv2 = cvec_dup(cvv0)) == NULL){
+ clicon_err(OE_UNIX, errno, "cvec_dup");
+ return NULL;
+ }
+ cv = NULL; /* Append cvv1 to cvv2 */
+ while ((cv = cvec_each1(cvv1, cv)) != NULL)
+ cvec_append_var(cvv2, cv);
}
return cvv2;
}
@@ -137,8 +137,8 @@ cvec_append(cvec *cvv0,
*/
int
cli_auto_edit(clicon_handle h,
- cvec *cvv1,
- cvec *argv)
+ cvec *cvv1,
+ cvec *argv)
{
int retval = -1;
char *api_path_fmt; /* xml key format */
@@ -151,61 +151,61 @@ cli_auto_edit(clicon_handle h,
cvec *cvv2 = NULL; /* cvv2 = cvv0 + cvv1 */
if (cvec_len(argv) != 2){
- clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>, )", __FUNCTION__);
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>, )", __FUNCTION__);
+ goto done;
}
cv = cvec_i(argv, 1);
treename = cv_string_get(cv);
/* Find current cligen tree */
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
- clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
- goto done;
+ clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
+ goto done;
}
/* Find the matching cligen object
* Note, is complicated: either an instantiated tree (co_treeref_orig)
* or actual tree (co_ref)
*/
if ((co = cligen_co_match(cli_cligen(h))) != NULL){
- if ((coorig = co->co_treeref_orig) != NULL ||
- (coorig = co->co_ref) != NULL)
- cligen_ph_workpoint_set(ph, coorig);
- else {
- clicon_err(OE_YANG, EINVAL, "No workpoint found");
- goto done;
- }
+ if ((coorig = co->co_treeref_orig) != NULL ||
+ (coorig = co->co_ref) != NULL)
+ cligen_ph_workpoint_set(ph, coorig);
+ else {
+ clicon_err(OE_YANG, EINVAL, "No workpoint found");
+ goto done;
+ }
}
else{
- clicon_err(OE_YANG, EINVAL, "No workpoint found");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "No workpoint found");
+ goto done;
}
if ((cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1)) == NULL)
- goto done;
+ goto done;
/* API_path format */
if ((api_path_fmt = co2apipath(coorig)) == NULL){
- clicon_err(OE_YANG, EINVAL, "No apipath found");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "No apipath found");
+ goto done;
}
/* get api-path and xpath */
if (api_path_fmt2api_path(api_path_fmt, cvv2, &api_path, NULL) < 0)
- goto done;
+ goto done;
/* Store this as edit-mode */
if (clicon_data_set(h, "cli-edit-mode", api_path) < 0)
- goto done;
+ goto done;
if (clicon_data_cvec_set(h, "cli-edit-cvv", cvv2) < 0)
- goto done;
+ goto done;
if (co->co_filter){
- cvec *cvv3;
- if ((cvv3 = cvec_dup(co->co_filter)) == NULL){
- clicon_err(OE_YANG, errno, "cvec_dup");
- goto done;
- }
- if (clicon_data_cvec_set(h, "cli-edit-filter", cvv3) < 0)
- goto done;
+ cvec *cvv3;
+ if ((cvv3 = cvec_dup(co->co_filter)) == NULL){
+ clicon_err(OE_YANG, errno, "cvec_dup");
+ goto done;
+ }
+ if (clicon_data_cvec_set(h, "cli-edit-filter", cvv3) < 0)
+ goto done;
}
retval = 0;
done:
if (api_path)
- free(api_path);
+ free(api_path);
return retval;
}
@@ -218,8 +218,8 @@ cli_auto_edit(clicon_handle h,
*/
int
cli_auto_up(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
cg_var *cv;
@@ -238,41 +238,41 @@ cli_auto_up(clicon_handle h,
cvec *cvv_filter = NULL;
if (cvec_len(argv) != 1){
- clicon_err(OE_PLUGIN, EINVAL, "Usage: %s()", __FUNCTION__);
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Usage: %s()", __FUNCTION__);
+ goto done;
}
cv = cvec_i(argv, 0);
treename = cv_string_get(cv);
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
- clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
- goto done;
+ clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
+ goto done;
}
if ((co0 = cligen_ph_workpoint_get(ph)) == NULL)
- goto ok;
+ goto ok;
cvv_filter = clicon_data_cvec_get(h, "cli-edit-filter");
/* Find parent that has a callback, XXX has edit */
for (co1 = co_up(co0); co1; co1 = co_up(co1)){
- cg_obj *cot = NULL;
- if (co_terminal(co1, &cot)){
- if (cot == NULL)
- break; /* found top */
- if (cvv_filter){
- cv = NULL;
- while ((cv = cvec_each(cot->co_cvec, cv)) != NULL){
- if (co_isfilter(cvv_filter, cv_name_get(cv)))
- break;
- }
- if (cv == NULL)
- break; /* no filter match */
- }
- }
+ cg_obj *cot = NULL;
+ if (co_terminal(co1, &cot)){
+ if (cot == NULL)
+ break; /* found top */
+ if (cvv_filter){
+ cv = NULL;
+ while ((cv = cvec_each(cot->co_cvec, cv)) != NULL){
+ if (co_isfilter(cvv_filter, cv_name_get(cv)))
+ break;
+ }
+ if (cv == NULL)
+ break; /* no filter match */
+ }
+ }
}
cligen_ph_workpoint_set(ph, co1);
if (co1 == NULL){
- clicon_data_set(h, "cli-edit-mode", "");
- clicon_data_cvec_del(h, "cli-edit-cvv");
- clicon_data_cvec_del(h, "cli-edit-filter");
- goto ok;
+ clicon_data_set(h, "cli-edit-mode", "");
+ clicon_data_cvec_del(h, "cli-edit-cvv");
+ clicon_data_cvec_del(h, "cli-edit-filter");
+ goto ok;
}
/* get before and after api-path-fmt (as generated from yang) */
api_path_fmt0 = co2apipath(co0);
@@ -283,16 +283,16 @@ cli_auto_up(clicon_handle h,
j=0; /* count diffs */
len = strlen(api_path_fmt0);
for (i=strlen(api_path_fmt1); ico_callbacks && (cvv = co->co_callbacks->cc_cvec))
- if (strcmp(fa->fa_str, cv_string_get(cvec_i(cvv, 0))) == 0){
- fa->fa_co = co;
- return 1;
- }
+ if (strcmp(fa->fa_str, cv_string_get(cvec_i(cvv, 0))) == 0){
+ fa->fa_co = co;
+ return 1;
+ }
return 0;
}
@@ -477,8 +477,8 @@ cli_auto_findpt(cg_obj *co,
*/
int
cli_auto_sub_enter(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
char *api_path_fmt; /* Contains wildcards as %.. */
@@ -492,8 +492,8 @@ cli_auto_sub_enter(clicon_handle h,
struct findpt_arg fa = {0,};
if (cvec_len(argv) < 2){
- clicon_err(OE_PLUGIN, EINVAL, "Usage: %s( (,vars)*)", __FUNCTION__);
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Usage: %s( (,vars)*)", __FUNCTION__);
+ goto done;
}
/* First argv argument: treename */
cv = cvec_i(argv, 0);
@@ -511,48 +511,48 @@ cli_auto_sub_enter(clicon_handle h,
*/
/* Create a cvv with variables to add to api-path */
if ((cvv1 = cvec_new(0)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ goto done;
}
/* Append static variables (skip first treename) */
for (i=1; i 1 &&
- (yang_keyword_get(y) == Y_LEAF)){
- /* Add the body last if there is remaining element that was not used in the
- * earlier api-path transformation.
- * This is to handle differences between:
- * DELETE bar and DELETE
- * i.e., (1) deletion of a specific leaf entry vs (2) deletion of any entry
- * Discussion: one can claim (1) is "bad" usage but one could see cases where
- * you would want to delete a value if it has a specific value but not otherwise
- */
- if (cvv_i != cvec_len(cvv))
- if (dbxml_body(xbot, cvv) < 0)
- goto done;
- /* Loop over namespace context and add them to this leaf node */
- cv = NULL;
- while ((cv = cvec_each(nsctx, cv)) != NULL){
- char *ns = cv_string_get(cv);
- char *pf = cv_name_get(cv);
- if (ns && pf && xmlns_set(xbot, pf, ns) < 0)
- goto done;
- }
+ (yang_keyword_get(y) == Y_LEAF)){
+ /* Add the body last if there is remaining element that was not used in the
+ * earlier api-path transformation.
+ * This is to handle differences between:
+ * DELETE bar and DELETE
+ * i.e., (1) deletion of a specific leaf entry vs (2) deletion of any entry
+ * Discussion: one can claim (1) is "bad" usage but one could see cases where
+ * you would want to delete a value if it has a specific value but not otherwise
+ */
+ if (cvv_i != cvec_len(cvv))
+ if (dbxml_body(xbot, cvv) < 0)
+ goto done;
+ /* Loop over namespace context and add them to this leaf node */
+ cv = NULL;
+ while ((cv = cvec_each(nsctx, cv)) != NULL){
+ char *ns = cv_string_get(cv);
+ char *pf = cv_name_get(cv);
+ if (ns && pf && xmlns_set(xbot, pf, ns) < 0)
+ goto done;
+ }
}
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
if (clixon_xml2cbuf(cb, xtop, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
if (clicon_rpc_edit_config(h, "candidate", OP_NONE, cbuf_get(cb)) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (api_path)
- free(api_path);
+ free(api_path);
if (xtop)
- xml_free(xtop);
+ xml_free(xtop);
return retval;
}
@@ -349,13 +349,13 @@ cli_dbxml(clicon_handle h,
*/
int
cli_set(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
if (cli_dbxml(h, cvv, argv, OP_REPLACE, NULL) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -368,13 +368,13 @@ cli_set(clicon_handle h,
*/
int
cli_merge(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
if (cli_dbxml(h, cvv, argv, OP_MERGE, NULL) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -387,13 +387,13 @@ cli_merge(clicon_handle h,
*/
int
cli_create(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
if (cli_dbxml(h, cvv, argv, OP_CREATE, NULL) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -406,13 +406,13 @@ cli_create(clicon_handle h,
*/
int
cli_remove(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
if (cli_dbxml(h, cvv, argv, OP_REMOVE, NULL) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -425,13 +425,13 @@ cli_remove(clicon_handle h,
*/
int
cli_del(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
if (cli_dbxml(h, cvv, argv, OP_REMOVE, NULL) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -446,19 +446,19 @@ cli_del(clicon_handle h,
*/
int
cli_debug_cli(clicon_handle h,
- cvec *vars,
- cvec *argv)
+ cvec *vars,
+ cvec *argv)
{
int retval = -1;
cg_var *cv;
int level;
if ((cv = cvec_find_var(vars, "level")) == NULL){
- if (cvec_len(argv) != 1){
- clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
- goto done;
- }
- cv = cvec_i(argv, 0);
+ if (cvec_len(argv) != 1){
+ clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
+ goto done;
+ }
+ cv = cvec_i(argv, 0);
}
level = cv_int32_get(cv);
/* cli */
@@ -477,19 +477,19 @@ cli_debug_cli(clicon_handle h,
*/
int
cli_debug_backend(clicon_handle h,
- cvec *vars,
- cvec *argv)
+ cvec *vars,
+ cvec *argv)
{
int retval = -1;
cg_var *cv;
int level;
if ((cv = cvec_find_var(vars, "level")) == NULL){
- if (cvec_len(argv) != 1){
- clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
- goto done;
- }
- cv = cvec_i(argv, 0);
+ if (cvec_len(argv) != 1){
+ clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
+ goto done;
+ }
+ cv = cvec_i(argv, 0);
}
level = cv_int32_get(cv);
/* config daemon */
@@ -511,19 +511,19 @@ cli_debug_backend(clicon_handle h,
*/
int
cli_debug_restconf(clicon_handle h,
- cvec *vars,
- cvec *argv)
+ cvec *vars,
+ cvec *argv)
{
int retval = -1;
cg_var *cv;
int level;
if ((cv = cvec_find_var(vars, "level")) == NULL){
- if (cvec_len(argv) != 1){
- clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
- goto done;
- }
- cv = cvec_i(argv, 0);
+ if (cvec_len(argv) != 1){
+ clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
+ goto done;
+ }
+ cv = cvec_i(argv, 0);
}
level = cv_int32_get(cv);
/* restconf daemon */
@@ -537,15 +537,15 @@ cli_debug_restconf(clicon_handle h,
*/
int
cli_set_mode(clicon_handle h,
- cvec *vars,
- cvec *argv)
+ cvec *vars,
+ cvec *argv)
{
int retval = -1;
char *str = NULL;
if (cvec_len(argv) != 1){
- clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be cli mode");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be cli mode");
+ goto done;
}
str = cv_string_get(cvec_i(argv, 0));
cli_set_syntax_mode(h, str);
@@ -562,8 +562,8 @@ cli_set_mode(clicon_handle h,
*/
int
cli_start_shell(clicon_handle h,
- cvec *vars,
- cvec *argv)
+ cvec *vars,
+ cvec *argv)
{
char *cmd;
char *shcmd = "sh";
@@ -575,54 +575,54 @@ cli_start_shell(clicon_handle h,
struct sigaction oldsigaction[32] = {0,};
if (cvec_len(argv) > 1){
- clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: []",
- cvec_len(argv));
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: []",
+ cvec_len(argv));
+ goto done;
}
if (cvec_len(argv) == 1){
- shcmd = cv_string_get(cvec_i(argv, 0));
+ shcmd = cv_string_get(cvec_i(argv, 0));
}
cmd = (cvec_len(vars)>1 ? cv_string_get(cv1) : NULL);
if ((pw = getpwuid(getuid())) == NULL){
- clicon_err(OE_UNIX, errno, "getpwuid");
- goto done;
+ clicon_err(OE_UNIX, errno, "getpwuid");
+ goto done;
}
if (chdir(pw->pw_dir) < 0){
- clicon_err(OE_UNIX, errno, "chdir");
- endpwent();
- goto done;
+ clicon_err(OE_UNIX, errno, "chdir");
+ endpwent();
+ goto done;
}
endpwent();
if (clixon_signal_save(&oldsigset, oldsigaction) < 0)
- goto done;
+ goto done;
cli_signal_flush(h);
cli_signal_unblock(h);
if (cmd){
- snprintf(bcmd, 128, "%s -c \"%s\"", shcmd, cmd);
- if (system(bcmd) < 0){
- cli_signal_block(h);
- clicon_err(OE_UNIX, errno, "system(bash -c)");
- goto done;
- }
+ snprintf(bcmd, 128, "%s -c \"%s\"", shcmd, cmd);
+ if (system(bcmd) < 0){
+ cli_signal_block(h);
+ clicon_err(OE_UNIX, errno, "system(bash -c)");
+ goto done;
+ }
}
else{
- snprintf(bcmd, 128, "%s ", shcmd); /* -l (login shell) but is applicable to bash only */
- if (system(bcmd) < 0){
- cli_signal_block(h);
- clicon_err(OE_UNIX, errno, "system(bash)");
- goto done;
- }
+ snprintf(bcmd, 128, "%s ", shcmd); /* -l (login shell) but is applicable to bash only */
+ if (system(bcmd) < 0){
+ cli_signal_block(h);
+ clicon_err(OE_UNIX, errno, "system(bash)");
+ goto done;
+ }
}
cli_signal_block(h);
#if 0 /* Allow errcodes from bash */
if (retval != 0){
- clicon_err(OE_UNIX, errno, "system(%s) %d", cmd, retval);
- goto done;
+ clicon_err(OE_UNIX, errno, "system(%s) %d", cmd, retval);
+ goto done;
}
#endif
if (clixon_signal_restore(&oldsigset, oldsigaction) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -632,8 +632,8 @@ cli_start_shell(clicon_handle h,
*/
int
cli_quit(clicon_handle h,
- cvec *vars,
- cvec *argv)
+ cvec *vars,
+ cvec *argv)
{
cligen_exiting_set(cli_cligen(h), 1);
return 0;
@@ -644,13 +644,28 @@ cli_quit(clicon_handle h,
*/
int
cli_commit(clicon_handle h,
- cvec *vars,
- cvec *argv)
+ cvec *vars,
+ cvec *argv)
{
int retval = -1;
+ uint32_t timeout = 0; /* any non-zero value means "confirmed-commit" */
+ cg_var *timeout_var;
+ char *persist = NULL;
+ char *persist_id = NULL;
+
+ int confirmed = (cvec_find_str(vars, "confirmed") != NULL);
+ int cancel = (cvec_find_str(vars, "cancel") != NULL);
+
+ if ((timeout_var = cvec_find(vars, "timeout")) != NULL) {
+ timeout = cv_uint32_get(timeout_var);
+ clicon_debug(1, "commit confirmed with timeout %ul", timeout);
+ }
+
+ persist = cvec_find_str(vars, "persist-val");
+ persist_id = cvec_find_str(vars, "persist-id-val");
- if ((retval = clicon_rpc_commit(h)) < 0)
- goto done;
+ if (clicon_rpc_commit(h, confirmed, cancel, timeout, persist, persist_id) < 1)
+ goto done;
retval = 0;
done:
return retval;
@@ -660,13 +675,13 @@ cli_commit(clicon_handle h,
*/
int
cli_validate(clicon_handle h,
- cvec *vars,
- cvec *argv)
+ cvec *vars,
+ cvec *argv)
{
int retval = -1;
- if ((retval = clicon_rpc_validate(h, "candidate")) < 0)
- goto done;
+ if (clicon_rpc_validate(h, "candidate") < 1)
+ goto done;
retval = 0;
done:
return retval;
@@ -676,8 +691,8 @@ cli_validate(clicon_handle h,
*/
static int
compare_xmls(cxobj *xc1,
- cxobj *xc2,
- enum format_enum format)
+ cxobj *xc2,
+ enum format_enum format)
{
int fd;
FILE *f;
@@ -689,60 +704,60 @@ compare_xmls(cxobj *xc1,
snprintf(filename1, sizeof(filename1), "/tmp/cliconXXXXXX");
snprintf(filename2, sizeof(filename2), "/tmp/cliconXXXXXX");
if ((fd = mkstemp(filename1)) < 0){
- clicon_err(OE_UNDEF, errno, "tmpfile");
- goto done;
+ clicon_err(OE_UNDEF, errno, "tmpfile");
+ goto done;
}
if ((f = fdopen(fd, "w")) == NULL)
- goto done;
+ goto done;
switch(format){
case FORMAT_TEXT:
- if (clixon_txt2file(f, xc1, 0, cligen_output, 1, 1) < 0)
- goto done;
- break;
+ if (clixon_txt2file(f, xc1, 0, cligen_output, 1, 1) < 0)
+ goto done;
+ break;
case FORMAT_XML:
default:
- if (clixon_xml2file(f, xc1, 0, 1, cligen_output, 1, 1) < 0)
- goto done;
- break;
+ if (clixon_xml2file(f, xc1, 0, 1, cligen_output, 1, 1) < 0)
+ goto done;
+ break;
}
fclose(f);
close(fd);
if ((fd = mkstemp(filename2)) < 0){
- clicon_err(OE_UNDEF, errno, "mkstemp: %s", strerror(errno));
- goto done;
+ clicon_err(OE_UNDEF, errno, "mkstemp: %s", strerror(errno));
+ goto done;
}
if ((f = fdopen(fd, "w")) == NULL)
- goto done;
+ goto done;
switch(format){
case FORMAT_TEXT:
- if (clixon_txt2file(f, xc2, 0, cligen_output, 1, 1) < 0)
- goto done;
- break;
+ if (clixon_txt2file(f, xc2, 0, cligen_output, 1, 1) < 0)
+ goto done;
+ break;
case FORMAT_XML:
default:
- if (clixon_xml2file(f, xc2, 0, 1, cligen_output, 1, 1) < 0)
- goto done;
- break;
+ if (clixon_xml2file(f, xc2, 0, 1, cligen_output, 1, 1) < 0)
+ goto done;
+ break;
}
fclose(f);
close(fd);
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_CFG, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_CFG, errno, "cbuf_new");
+ goto done;
}
cprintf(cb, "diff -dU 1 %s %s | grep -v @@ | sed 1,2d",
- filename1, filename2);
+ filename1, filename2);
if (system(cbuf_get(cb)) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
unlink(filename1);
unlink(filename2);
return retval;
@@ -755,8 +770,8 @@ compare_xmls(cxobj *xc1,
*/
int
compare_dbs(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
cxobj *xc1 = NULL; /* running xml */
cxobj *xc2 = NULL; /* candidate xml */
@@ -765,33 +780,33 @@ compare_dbs(clicon_handle h,
enum format_enum format;
if (cvec_len(argv) > 1){
- clicon_err(OE_PLUGIN, EINVAL, "Requires 0 or 1 element. If given: astext flag 0|1");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Requires 0 or 1 element. If given: astext flag 0|1");
+ goto done;
}
if (cvec_len(argv) && cv_int32_get(cvec_i(argv, 0)) == 1)
- format = FORMAT_TEXT;
+ format = FORMAT_TEXT;
else
- format = FORMAT_XML;
+ format = FORMAT_XML;
if (clicon_rpc_get_config(h, NULL, "running", "/", NULL, NULL, &xc1) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xc1, NULL, "/rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Get configuration", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Get configuration", NULL);
+ goto done;
}
if (clicon_rpc_get_config(h, NULL, "candidate", "/", NULL, NULL, &xc2) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xc2, NULL, "/rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Get configuration", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Get configuration", NULL);
+ goto done;
}
if (compare_xmls(xc1, xc2, format) < 0) /* astext? */
- goto done;
+ goto done;
retval = 0;
done:
if (xc1)
- xml_free(xc1);
+ xml_free(xc1);
if (xc2)
- xml_free(xc2);
+ xml_free(xc2);
return retval;
}
@@ -815,8 +830,8 @@ compare_dbs(clicon_handle h,
*/
int
load_config_file(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int ret = -1;
struct stat st;
@@ -836,135 +851,135 @@ load_config_file(clicon_handle h,
char *lineptr = NULL;
if (cvec_len(argv) < 2 || cvec_len(argv) > 4){
- clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: ,[,]",
- cvec_len(argv));
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: ,[,]",
+ cvec_len(argv));
+ goto done;
}
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
if (cvec_len(argv) > 2){
- formatstr = cv_string_get(cvec_i(argv, 2));
- if ((int)(format = format_str2int(formatstr)) < 0){
- clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
- goto done;
- }
+ formatstr = cv_string_get(cvec_i(argv, 2));
+ if ((int)(format = format_str2int(formatstr)) < 0){
+ clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
+ goto done;
+ }
}
varstr = cv_string_get(cvec_i(argv, 0));
opstr = cv_string_get(cvec_i(argv, 1));
if (strcmp(opstr, "merge") == 0)
- replace = 0;
+ replace = 0;
else if (strcmp(opstr, "replace") == 0)
- replace = 1;
+ replace = 1;
else{
- clicon_err(OE_PLUGIN, 0, "No such op: %s, expected merge or replace", opstr);
- goto done;
+ clicon_err(OE_PLUGIN, 0, "No such op: %s, expected merge or replace", opstr);
+ goto done;
}
if ((cv = cvec_find(cvv, varstr)) == NULL){
- clicon_err(OE_PLUGIN, 0, "No such var name: %s", varstr);
- goto done;
+ clicon_err(OE_PLUGIN, 0, "No such var name: %s", varstr);
+ goto done;
}
filename = cv_string_get(cv);
if (stat(filename, &st) < 0){
- clicon_err(OE_UNIX, errno, "load_config: stat(%s)", filename);
- goto done;
+ clicon_err(OE_UNIX, errno, "load_config: stat(%s)", filename);
+ goto done;
}
/* Open and parse local file into xml */
if ((fp = fopen(filename, "r")) == NULL){
- clicon_err(OE_UNIX, errno, "fopen(%s)", filename);
- goto done;
+ clicon_err(OE_UNIX, errno, "fopen(%s)", filename);
+ goto done;
}
switch (format){
case FORMAT_XML:
- if ((ret = clixon_xml_parse_file(fp, YB_NONE, yspec, &xt, &xerr)) < 0)
- goto done;
- if (ret == 0){
- clixon_netconf_error(xerr, "Loading", filename);
- goto done;
- }
- break;
+ if ((ret = clixon_xml_parse_file(fp, YB_NONE, yspec, &xt, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ clixon_netconf_error(xerr, "Loading", filename);
+ goto done;
+ }
+ break;
case FORMAT_JSON:
- if ((ret = clixon_json_parse_file(fp, 1, YB_NONE, yspec, &xt, &xerr)) < 0)
- goto done;
- if (ret == 0){
- clixon_netconf_error(xerr, "Loading", filename);
- goto done;
- }
- break;
+ if ((ret = clixon_json_parse_file(fp, 1, YB_NONE, yspec, &xt, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ clixon_netconf_error(xerr, "Loading", filename);
+ goto done;
+ }
+ break;
case FORMAT_TEXT:
- /* text parser requires YANG and since load/save files have a "config" top-level
- * the yang-bind parameter must be YB_MODULE_NEXT
- */
- if ((ret = clixon_text_syntax_parse_file(fp, YB_MODULE_NEXT, yspec, &xt, &xerr)) < 0)
- goto done;
- if (ret == 0){
- clixon_netconf_error(xerr, "Loading", filename);
- goto done;
- }
- break;
+ /* text parser requires YANG and since load/save files have a "config" top-level
+ * the yang-bind parameter must be YB_MODULE_NEXT
+ */
+ if ((ret = clixon_text_syntax_parse_file(fp, YB_MODULE_NEXT, yspec, &xt, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ clixon_netconf_error(xerr, "Loading", filename);
+ goto done;
+ }
+ break;
case FORMAT_CLI:
- {
- char *mode = cli_syntax_mode(h);
- cligen_result result; /* match result */
- int evalresult = 0; /* if result == 1, calback result */
- size_t n;
+ {
+ char *mode = cli_syntax_mode(h);
+ cligen_result result; /* match result */
+ int evalresult = 0; /* if result == 1, calback result */
+ size_t n;
- while(!cligen_exiting(cli_cligen(h))) {
- lineptr = NULL; n = 0;
- if (getline(&lineptr, &n, fp) < 0){
- if (errno){
- clicon_err(OE_UNIX, errno, "getline");
- goto done;
- }
- goto ok; /* eof, skip backend rpc since this is done by cli code */
- }
- if (clicon_parse(h, lineptr, &mode, &result, &evalresult) < 0)
- goto done;
- if (result != 1) /* Not unique match */
- goto done;
- if (evalresult < 0)
- goto done;
- if (lineptr){
- free(lineptr);
- lineptr = NULL;
- }
- }
- break;
- }
+ while(!cligen_exiting(cli_cligen(h))) {
+ lineptr = NULL; n = 0;
+ if (getline(&lineptr, &n, fp) < 0){
+ if (errno){
+ clicon_err(OE_UNIX, errno, "getline");
+ goto done;
+ }
+ goto ok; /* eof, skip backend rpc since this is done by cli code */
+ }
+ if (clicon_parse(h, lineptr, &mode, &result, &evalresult) < 0)
+ goto done;
+ if (result != 1) /* Not unique match */
+ goto done;
+ if (evalresult < 0)
+ goto done;
+ if (lineptr){
+ free(lineptr);
+ lineptr = NULL;
+ }
+ }
+ break;
+ }
default:
- clicon_err(OE_PLUGIN, 0, "format: %s not implemented", formatstr);
- goto done;
- break;
+ clicon_err(OE_PLUGIN, 0, "format: %s not implemented", formatstr);
+ goto done;
+ break;
}
if (xt == NULL)
- goto done;
+ goto done;
if ((cbxml = cbuf_new()) == NULL)
- goto done;
+ goto done;
x = NULL;
while ((x = xml_child_each(xt, x, -1)) != NULL) {
- /* Read as datastore-top but transformed into an edit-config "config" */
- xml_name_set(x, NETCONF_INPUT_CONFIG);
+ /* Read as datastore-top but transformed into an edit-config "config" */
+ xml_name_set(x, NETCONF_INPUT_CONFIG);
}
if (clixon_xml2cbuf(cbxml, xt, 0, 0, -1, 1) < 0)
- goto done;
+ goto done;
if (clicon_rpc_edit_config(h, "candidate",
- replace?OP_REPLACE:OP_MERGE,
- cbuf_get(cbxml)) < 0)
- goto done;
+ replace?OP_REPLACE:OP_MERGE,
+ cbuf_get(cbxml)) < 0)
+ goto done;
ok:
ret = 0;
done:
if (cbxml)
- cbuf_free(cbxml);
+ cbuf_free(cbxml);
if (lineptr)
- free(lineptr);
+ free(lineptr);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (xt)
- xml_free(xt);
+ xml_free(xt);
if (fp)
- fclose(fp);
+ fclose(fp);
return ret;
}
@@ -987,8 +1002,8 @@ load_config_file(clicon_handle h,
*/
int
save_config_file(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
char *filename = NULL;
@@ -1004,82 +1019,82 @@ save_config_file(clicon_handle h,
int pretty = 1; /* XXX hardcoded */
if (cvec_len(argv) < 2 || cvec_len(argv) > 4){
- clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: ,[,]",
- cvec_len(argv));
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: ,[,]",
+ cvec_len(argv));
+ goto done;
}
if (cvec_len(argv) > 2){
- formatstr = cv_string_get(cvec_i(argv, 2));
- if ((int)(format = format_str2int(formatstr)) < 0){
- clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
- goto done;
- }
+ formatstr = cv_string_get(cvec_i(argv, 2));
+ if ((int)(format = format_str2int(formatstr)) < 0){
+ clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
+ goto done;
+ }
}
dbstr = cv_string_get(cvec_i(argv, 0));
if (strcmp(dbstr, "running") != 0 &&
- strcmp(dbstr, "candidate") != 0 &&
- strcmp(dbstr, "startup") != 0) {
- clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
- goto done;
+ strcmp(dbstr, "candidate") != 0 &&
+ strcmp(dbstr, "startup") != 0) {
+ clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
+ goto done;
}
varstr = cv_string_get(cvec_i(argv, 1));
if ((cv = cvec_find(cvv, varstr)) == NULL){
- clicon_err(OE_PLUGIN, 0, "No such var name: %s", varstr);
- goto done;
+ clicon_err(OE_PLUGIN, 0, "No such var name: %s", varstr);
+ goto done;
}
filename = cv_string_get(cv);
if (clicon_rpc_get_config(h, NULL, dbstr,"/", NULL, NULL, &xt) < 0)
- goto done;
+ goto done;
if (xt == NULL){
- clicon_err(OE_CFG, 0, "get config: empty tree"); /* Shouldnt happen */
- goto done;
+ clicon_err(OE_CFG, 0, "get config: empty tree"); /* Shouldnt happen */
+ goto done;
}
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Get configuration", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Get configuration", NULL);
+ goto done;
}
/* get-config returns a tree. Save as tree so it can be used
* as data-store.
*/
if (xml_name_set(xt, DATASTORE_TOP_SYMBOL) < 0)
- goto done;
+ goto done;
if ((f = fopen(filename, "w")) == NULL){
- clicon_err(OE_CFG, errno, "Creating file %s", filename);
- goto done;
+ clicon_err(OE_CFG, errno, "Creating file %s", filename);
+ goto done;
}
switch (format){
case FORMAT_XML:
- if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0, 1) < 0)
- goto done;
- break;
+ if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0, 1) < 0)
+ goto done;
+ break;
case FORMAT_JSON:
- if (clixon_json2file(f, xt, pretty, fprintf, 0, 1) < 0)
- goto done;
- break;
+ if (clixon_json2file(f, xt, pretty, fprintf, 0, 1) < 0)
+ goto done;
+ break;
case FORMAT_TEXT:
- if (clixon_txt2file(f, xt, 0, fprintf, 0, 1) < 0)
- goto done;
- break;
+ if (clixon_txt2file(f, xt, 0, fprintf, 0, 1) < 0)
+ goto done;
+ break;
case FORMAT_CLI:
- if (clixon_cli2file(h, f, xt, prefix, fprintf, 1) < 0)
- goto done;
- break;
+ if (clixon_cli2file(h, f, xt, prefix, fprintf, 1) < 0)
+ goto done;
+ break;
case FORMAT_NETCONF:
- fprintf(f, " ",
- NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
- fprintf(f, "\n");
- if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0, 1) < 0)
- goto done;
- fprintf(f, " ]]>]]>\n");
- break;
+ fprintf(f, " ",
+ NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
+ fprintf(f, "\n");
+ if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0, 1) < 0)
+ goto done;
+ fprintf(f, " ]]>]]>\n");
+ break;
} /* switch */
retval = 0;
/* Fall through */
done:
if (xt)
- xml_free(xt);
+ xml_free(xt);
if (f != NULL)
- fclose(f);
+ fclose(f);
return retval;
}
@@ -1088,25 +1103,25 @@ save_config_file(clicon_handle h,
*/
int
delete_all(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
char *dbstr;
int retval = -1;
if (cvec_len(argv) != 1){
- clicon_err(OE_PLUGIN, EINVAL, "Requires one element: dbname");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Requires one element: dbname");
+ goto done;
}
dbstr = cv_string_get(cvec_i(argv, 0));
if (strcmp(dbstr, "running") != 0 &&
- strcmp(dbstr, "candidate") != 0 &&
- strcmp(dbstr, "startup") != 0){
- clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
- goto done;
+ strcmp(dbstr, "candidate") != 0 &&
+ strcmp(dbstr, "startup") != 0){
+ clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
+ goto done;
}
if (clicon_rpc_delete_config(h, dbstr) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -1116,8 +1131,8 @@ delete_all(clicon_handle h,
*/
int
discard_changes(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
return clicon_rpc_discard_changes(h);
@@ -1127,8 +1142,8 @@ discard_changes(clicon_handle h,
*/
int
db_copy(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
char *db1;
char *db2;
@@ -1144,7 +1159,7 @@ db_copy(clicon_handle h,
*/
static int
cli_notification_cb(int s,
- void *arg)
+ void *arg)
{
struct clicon_msg *reply = NULL;
int eof;
@@ -1155,42 +1170,42 @@ cli_notification_cb(int s,
/* get msg (this is the reason this function is called) */
if (clicon_msg_rcv(s, &reply, &eof) < 0)
- goto done;
+ goto done;
if (eof){
- clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
- close(s);
- errno = ESHUTDOWN;
- clixon_event_unreg_fd(s, cli_notification_cb);
- goto done;
+ clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
+ close(s);
+ errno = ESHUTDOWN;
+ clixon_event_unreg_fd(s, cli_notification_cb);
+ goto done;
}
/* XXX pass yang_spec and use xerr*/
if ((ret = clicon_msg_decode(reply, NULL, NULL, &xt, NULL)) < 0)
- goto done;
+ goto done;
if (ret == 0){ /* will not happen since no yspec ^*/
- clicon_err(OE_NETCONF, EFAULT, "Notification malformed");
- goto done;
+ clicon_err(OE_NETCONF, EFAULT, "Notification malformed");
+ goto done;
}
switch (format){
case FORMAT_JSON:
- if (clixon_json2file(stdout, xt, 1, cligen_output, 1, 1) < 0)
- goto done;
+ if (clixon_json2file(stdout, xt, 1, cligen_output, 1, 1) < 0)
+ goto done;
case FORMAT_TEXT:
- if (clixon_txt2file(stdout, xt, 0, cligen_output, 1, 1) < 0)
- goto done;
- break;
+ if (clixon_txt2file(stdout, xt, 0, cligen_output, 1, 1) < 0)
+ goto done;
+ break;
case FORMAT_XML:
- if (clixon_xml2file(stdout, xt, 0, 1, cligen_output, 1, 1) < 0)
- goto done;
- break;
+ if (clixon_xml2file(stdout, xt, 0, 1, cligen_output, 1, 1) < 0)
+ goto done;
+ break;
default:
- break;
+ break;
}
retval = 0;
done:
if (xt)
- xml_free(xt);
+ xml_free(xt);
if (reply)
- free(reply);
+ free(reply);
return retval;
}
@@ -1209,8 +1224,8 @@ cli_notification_cb(int s,
*/
int
cli_notify(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
char *stream = NULL;
int retval = -1;
@@ -1219,23 +1234,23 @@ cli_notify(clicon_handle h,
enum format_enum format = FORMAT_TEXT;
if (cvec_len(argv) != 2 && cvec_len(argv) != 3){
- clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: []");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: []");
+ goto done;
}
stream = cv_string_get(cvec_i(argv, 0));
status = atoi(cv_string_get(cvec_i(argv, 1)));
if (cvec_len(argv) > 2){
- formatstr = cv_string_get(cvec_i(argv, 2));
- format = format_str2int(formatstr);
+ formatstr = cv_string_get(cvec_i(argv, 2));
+ format = format_str2int(formatstr);
}
if (cli_notification_register(h,
- stream,
- format,
- "",
- status,
- cli_notification_cb,
- (void*)format) < 0)
- goto done;
+ stream,
+ format,
+ "",
+ status,
+ cli_notification_cb,
+ (void*)format) < 0)
+ goto done;
retval = 0;
done:
@@ -1254,19 +1269,19 @@ cli_notify(clicon_handle h,
*/
int
cli_lock(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
char *db;
int retval = -1;
if (cvec_len(argv) != 1){
- clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: ");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: ");
+ goto done;
}
db = cv_string_get(cvec_i(argv, 0));
if (clicon_rpc_lock(h, db) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -1284,19 +1299,19 @@ cli_lock(clicon_handle h,
*/
int
cli_unlock(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
char *db;
int retval = -1;
if (cvec_len(argv) != 1){
- clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: ");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: ");
+ goto done;
}
db = cv_string_get(cvec_i(argv, 0));
if (clicon_rpc_unlock(h, db) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -1306,8 +1321,8 @@ cli_unlock(clicon_handle h,
*
* Works for objects that are items in a yang list with a keyname, eg as:
* list sender{
- * key name;
- * leaf name{...
+ * key name;
+ * leaf name{...
*
* @param[in] h CLICON handle
* @param[in] cvv Vector of variables from CLIgen command-line
@@ -1328,8 +1343,8 @@ cli_unlock(clicon_handle h,
*/
int
cli_copy_config(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
char *db;
@@ -1353,8 +1368,8 @@ cli_copy_config(clicon_handle h,
size_t len;
if (cvec_len(argv) != 6){
- clicon_err(OE_PLUGIN, EINVAL, "Requires 6 elements: ");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Requires 6 elements: ");
+ goto done;
}
/* First argv argument: Database */
db = cv_string_get(cvec_i(argv, 0));
@@ -1371,55 +1386,55 @@ cli_copy_config(clicon_handle h,
/* Get from variable -> cv -> from name */
if ((fromcv = cvec_find(cvv, fromvar)) == NULL){
- clicon_err(OE_PLUGIN, 0, "fromvar '%s' not found in cligen var list", fromvar);
- goto done;
+ clicon_err(OE_PLUGIN, 0, "fromvar '%s' not found in cligen var list", fromvar);
+ goto done;
}
/* Get from name from cv */
fromname = cv_string_get(fromcv);
/* Create xpath */
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_PLUGIN, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_PLUGIN, errno, "cbuf_new");
+ goto done;
}
/* Sanity check that xpath contains exactly two %s, ie [%s='%s'] */
len = strlen(xpath);
j = 0;
for (i=0; i cv -> to name */
if ((tocv = cvec_find(cvv, tovar)) == NULL){
- clicon_err(OE_PLUGIN, 0, "tovar '%s' not found in cligen var list", tovar);
- goto done;
+ clicon_err(OE_PLUGIN, 0, "tovar '%s' not found in cligen var list", tovar);
+ goto done;
}
toname = cv_string_get(tocv);
/* Create copy xml tree x2 */
if ((x2 = xml_new(NETCONF_INPUT_CONFIG, NULL, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (xml_copy(x1, x2) < 0)
- goto done;
+ goto done;
xml_name_set(x2, NETCONF_INPUT_CONFIG);
- cprintf(cb, "/%s", keyname);
+ cprintf(cb, "/%s", keyname);
if ((x = xpath_first(x2, nsc, "%s", cbuf_get(cb))) == NULL){
- clicon_err(OE_PLUGIN, 0, "Field %s not found in copy tree", keyname);
- goto done;
+ clicon_err(OE_PLUGIN, 0, "Field %s not found in copy tree", keyname);
+ goto done;
}
x = xml_find(x, "body");
xml_value_set(x, toname);
@@ -1427,19 +1442,19 @@ cli_copy_config(clicon_handle h,
cbuf_reset(cb);
/* create xml copy tree and merge it with database configuration */
if (clixon_xml2cbuf(cb, x2, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
if (clicon_rpc_edit_config(h, db, OP_MERGE, cbuf_get(cb)) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (x1 != NULL)
- xml_free(x1);
+ xml_free(x1);
if (x2 != NULL)
- xml_free(x2);
+ xml_free(x2);
return retval;
}
@@ -1464,19 +1479,19 @@ cli_help(clicon_handle h, cvec *vars, cvec *argv)
*/
int
cli_restart_plugin(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
cg_var *cv;
char *plugin;
if ((cv = cvec_find_var(cvv, "plugin")) == NULL){
- if (cvec_len(argv) != 1){
- clicon_err(OE_PLUGIN, EINVAL, "Requires plugin variable");
- goto done;
- }
- cv = cvec_i(argv, 0);
+ if (cvec_len(argv) != 1){
+ clicon_err(OE_PLUGIN, EINVAL, "Requires plugin variable");
+ goto done;
+ }
+ cv = cvec_i(argv, 0);
}
plugin = cv_string_get(cv);
retval = clicon_rpc_restart_plugin(h, plugin);
diff --git a/apps/cli/cli_generate.c b/apps/cli/cli_generate.c
index 436a9902..ac099faf 100644
--- a/apps/cli/cli_generate.c
+++ b/apps/cli/cli_generate.c
@@ -124,37 +124,37 @@ You can see which CLISPEC it generates via clixon_cli -D 2:
*/
static int
cli_expand_var_generate(clicon_handle h,
- yang_stmt *ys,
- char *cvtypestr,
- int options,
- uint8_t fraction_digits,
- int pre,
- cbuf *cb)
+ yang_stmt *ys,
+ char *cvtypestr,
+ int options,
+ uint8_t fraction_digits,
+ int pre,
+ cbuf *cb)
{
int retval = -1;
char *api_path_fmt = NULL;
int extvalue = 0;
if (yang_extension_value(ys, "hide", CLIXON_AUTOCLI_NS, &extvalue, NULL) < 0)
- goto done;
+ goto done;
if (extvalue) {
- retval = 1;
- goto done;
+ retval = 1;
+ goto done;
}
if (yang2api_path_fmt(ys, 1, &api_path_fmt) < 0)
- goto done;
+ goto done;
if (pre)
- cprintf(cb, "|");
+ cprintf(cb, "|");
cprintf(cb, "<%s:%s", yang_argument_get(ys), cvtypestr);
if (options & YANG_OPTIONS_FRACTION_DIGITS)
- cprintf(cb, " fraction-digits:%u", fraction_digits);
+ cprintf(cb, " fraction-digits:%u", fraction_digits);
cprintf(cb, " %s(\"candidate\",\"%s\")>",
- GENERATE_EXPAND_XMLDB,
- api_path_fmt);
+ GENERATE_EXPAND_XMLDB,
+ api_path_fmt);
retval = 0;
done:
if (api_path_fmt)
- free(api_path_fmt);
+ free(api_path_fmt);
return retval;
}
@@ -167,20 +167,20 @@ cli_expand_var_generate(clicon_handle h,
*/
static int
cli_callback_generate(clicon_handle h,
- yang_stmt *ys,
- cbuf *cb)
+ yang_stmt *ys,
+ cbuf *cb)
{
int retval = -1;
char *api_path_fmt = NULL;
if (yang2api_path_fmt(ys, 0, &api_path_fmt) < 0)
- goto done;
+ goto done;
cprintf(cb, ",%s(\"%s\")", GENERATE_CALLBACK,
- api_path_fmt);
+ api_path_fmt);
retval = 0;
done:
if (api_path_fmt)
- free(api_path_fmt);
+ free(api_path_fmt);
return retval;
}
@@ -190,10 +190,10 @@ cli_callback_generate(clicon_handle h,
*/
static int
yang2cli_helptext(cbuf *cb,
- char *helptext)
+ char *helptext)
{
if (helptext)
- cprintf(cb, "(\"%s\")", helptext);
+ cprintf(cb, "(\"%s\")", helptext);
return 0;
}
@@ -206,10 +206,10 @@ yang2cli_helptext(cbuf *cb,
*/
static int
yang2cli_var_identityref(yang_stmt *ys,
- yang_stmt *ytype,
- char *cvtypestr,
- char *helptext,
- cbuf *cb)
+ yang_stmt *ytype,
+ char *cvtypestr,
+ char *helptext,
+ cbuf *cb)
{
int retval = -1;
yang_stmt *ybaseref;
@@ -224,49 +224,49 @@ yang2cli_var_identityref(yang_stmt *ys,
yang_stmt *yspec;
if ((ybaseref = yang_find(ytype, Y_BASE, NULL)) == NULL)
- goto ok;
+ goto ok;
if ((ybaseid = yang_find_identity(ytype, yang_argument_get(ybaseref))) == NULL)
- goto ok;
+ goto ok;
idrefvec = yang_cvec_get(ybaseid);
if (cvec_len(idrefvec) > 0){
- /* Add a wildchar string first -let validate take it for default prefix */
- cprintf(cb, ">");
- yang2cli_helptext(cb, helptext);
- cprintf(cb, "|<%s:%s choice:", yang_argument_get(ys), cvtypestr);
- yspec = ys_spec(ys);
- i = 0;
- while ((cv = cvec_each(idrefvec, cv)) != NULL){
- if (nodeid_split(cv_name_get(cv), &prefix, &id) < 0)
- goto done;
- /* Translate from module-name(prefix) to global prefix
- * This is really a kludge for true identityref prefix handling
- * IDENTITYREF_KLUDGE
- * This is actually quite complicated: the cli needs to generate
- * a netconf statement with correct xmlns binding
- */
- if ((ymod = yang_find_module_by_name(yspec, prefix)) != NULL &&
- (yprefix = yang_find(ymod, Y_PREFIX, NULL)) != NULL){
- if (i++)
- cprintf(cb, "|");
- cprintf(cb, "%s:%s", yang_argument_get(yprefix), id);
- }
- if (prefix){
- free(prefix);
- prefix = NULL;
- }
- if (id){
- free(id);
- id = NULL;
- }
- }
+ /* Add a wildchar string first -let validate take it for default prefix */
+ cprintf(cb, ">");
+ yang2cli_helptext(cb, helptext);
+ cprintf(cb, "|<%s:%s choice:", yang_argument_get(ys), cvtypestr);
+ yspec = ys_spec(ys);
+ i = 0;
+ while ((cv = cvec_each(idrefvec, cv)) != NULL){
+ if (nodeid_split(cv_name_get(cv), &prefix, &id) < 0)
+ goto done;
+ /* Translate from module-name(prefix) to global prefix
+ * This is really a kludge for true identityref prefix handling
+ * IDENTITYREF_KLUDGE
+ * This is actually quite complicated: the cli needs to generate
+ * a netconf statement with correct xmlns binding
+ */
+ if ((ymod = yang_find_module_by_name(yspec, prefix)) != NULL &&
+ (yprefix = yang_find(ymod, Y_PREFIX, NULL)) != NULL){
+ if (i++)
+ cprintf(cb, "|");
+ cprintf(cb, "%s:%s", yang_argument_get(yprefix), id);
+ }
+ if (prefix){
+ free(prefix);
+ prefix = NULL;
+ }
+ if (id){
+ free(id);
+ id = NULL;
+ }
+ }
}
ok:
retval = 0;
done:
if (prefix)
- free(prefix);
+ free(prefix);
if (id)
- free(id);
+ free(id);
return retval;
}
@@ -296,9 +296,9 @@ yang2cli_var_identityref(yang_stmt *ys,
*/
static int
yang2cli_var_range(yang_stmt *ys,
- int options,
- cvec *cvv,
- cbuf *cb)
+ int options,
+ cvec *cvv,
+ cbuf *cb)
{
int retval = -1;
int i;
@@ -308,22 +308,22 @@ yang2cli_var_range(yang_stmt *ys,
/* Loop through range_min and range_min..range_max */
i = 0;
while (i");
yang2cli_helptext(cb, helptext);
if (type && strcmp(type, "identityref") == 0)
- cprintf(cb, ")");
+ cprintf(cb, ")");
retval = 0;
done:
return retval;
@@ -498,11 +498,11 @@ yang2cli_var_sub(clicon_handle h,
*/
static int
yang2cli_var_union_one(clicon_handle h,
- yang_stmt *ys,
- char *origtype,
- yang_stmt *ytsub,
- char *helptext,
- cbuf *cb)
+ yang_stmt *ys,
+ char *origtype,
+ yang_stmt *ytsub,
+ char *helptext,
+ cbuf *cb)
{
int retval = -1;
int options = 0;
@@ -514,36 +514,36 @@ yang2cli_var_union_one(clicon_handle h,
char *restype;
if ((patterns = cvec_new(0)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ goto done;
}
/* Resolve the sub-union type to a resolved type */
if (yang_type_resolve(ys, ys, ytsub, /* in */
- &ytype, &options, /* resolved type */
- &cvv, patterns, NULL, &fraction_digits) < 0)
- goto done;
+ &ytype, &options, /* resolved type */
+ &cvv, patterns, NULL, &fraction_digits) < 0)
+ goto done;
if (ytype == NULL){
- clicon_err(OE_YANG, 0, "result-type should not be NULL");
- goto done;
+ clicon_err(OE_YANG, 0, "result-type should not be NULL");
+ goto done;
}
restype = ytype?yang_argument_get(ytype):NULL;
if (restype && strcmp(restype, "union") == 0){ /* recursive union */
- if (yang2cli_var_union(h, ys, origtype, ytype, helptext, cb) < 0)
- goto done;
+ if (yang2cli_var_union(h, ys, origtype, ytype, helptext, cb) < 0)
+ goto done;
}
/* XXX leafref inside union ? */
else {
- if (clicon_type2cv(origtype, restype, ys, &cvtype) < 0)
- goto done;
- if ((retval = yang2cli_var_sub(h, ys, ytype, helptext, cvtype,
- options, cvv, patterns, fraction_digits, cb)) < 0)
- goto done;
+ if (clicon_type2cv(origtype, restype, ys, &cvtype) < 0)
+ goto done;
+ if ((retval = yang2cli_var_sub(h, ys, ytype, helptext, cvtype,
+ options, cvv, patterns, fraction_digits, cb)) < 0)
+ goto done;
}
retval = 0;
done:
if (patterns)
- cvec_free(patterns);
+ cvec_free(patterns);
return retval;
}
@@ -558,11 +558,11 @@ yang2cli_var_union_one(clicon_handle h,
*/
static int
yang2cli_var_union(clicon_handle h,
- yang_stmt *ys,
- char *origtype,
- yang_stmt *ytype,
- char *helptext,
- cbuf *cb)
+ yang_stmt *ys,
+ char *origtype,
+ yang_stmt *ytype,
+ char *helptext,
+ cbuf *cb)
{
int retval = -1;
yang_stmt *ytsub = NULL;
@@ -574,12 +574,12 @@ yang2cli_var_union(clicon_handle h,
* made in the union_one call.
*/
while ((ytsub = yn_each(ytype, ytsub)) != NULL){
- if (yang_keyword_get(ytsub) != Y_TYPE)
- continue;
- if (i++)
- cprintf(cb, "|");
- if (yang2cli_var_union_one(h, ys, origtype, ytsub, helptext, cb) < 0)
- goto done;
+ if (yang_keyword_get(ytsub) != Y_TYPE)
+ continue;
+ if (i++)
+ cprintf(cb, "|");
+ if (yang2cli_var_union_one(h, ys, origtype, ytsub, helptext, cb) < 0)
+ goto done;
}
retval = 0;
done:
@@ -588,15 +588,15 @@ yang2cli_var_union(clicon_handle h,
static int
yang2cli_var_leafref(clicon_handle h,
- yang_stmt *ys,
- yang_stmt *yrestype,
- char *helptext,
- enum cv_type cvtype,
- int options,
- cvec *cvv,
- cvec *patterns,
- uint8_t fraction_digits,
- cbuf *cb)
+ yang_stmt *ys,
+ yang_stmt *yrestype,
+ char *helptext,
+ enum cv_type cvtype,
+ int options,
+ cvec *cvv,
+ cvec *patterns,
+ uint8_t fraction_digits,
+ cbuf *cb)
{
int retval = -1;
char *type;
@@ -612,31 +612,31 @@ yang2cli_var_leafref(clicon_handle h,
type = yrestype?yang_argument_get(yrestype):NULL;
cvtypestr = cv_type2str(cvtype);
if (autocli_completion(h, &completionp) < 0)
- goto done;
+ goto done;
if (type && completionp){
- completionp = strcmp(type, "enumeration") != 0 &&
- strcmp(type, "identityref") != 0 &&
- strcmp(type, "bits") != 0;
+ completionp = strcmp(type, "enumeration") != 0 &&
+ strcmp(type, "identityref") != 0 &&
+ strcmp(type, "bits") != 0;
}
if (yang_extension_value(ys, "strict-expand", CLIXON_AUTOCLI_NS, &flag, NULL) < 0)
- goto done;
+ goto done;
regular_value = !flag;
if (completionp && regular_value)
- cprintf(cb, "(");
+ cprintf(cb, "(");
if (regular_value)
- if (yang2cli_var_sub(h, ys, yrestype, helptext, cvtype,
- options, cvv, patterns, fraction_digits, cb) < 0)
- goto done;
+ if (yang2cli_var_sub(h, ys, yrestype, helptext, cvtype,
+ options, cvv, patterns, fraction_digits, cb) < 0)
+ goto done;
if (completionp){
- if ((ret = cli_expand_var_generate(h, ys, cvtypestr,
- options, fraction_digits, regular_value,
- cb)) < 0)
- goto done;
- if (ret == 0)
- yang2cli_helptext(cb, helptext);
+ if ((ret = cli_expand_var_generate(h, ys, cvtypestr,
+ options, fraction_digits, regular_value,
+ cb)) < 0)
+ goto done;
+ if (ret == 0)
+ yang2cli_helptext(cb, helptext);
}
if (completionp && regular_value)
- cprintf(cb, ")");
+ cprintf(cb, ")");
retval = 0;
done:
return retval;
@@ -661,10 +661,10 @@ yang2cli_var_leafref(clicon_handle h,
*/
static int
yang2cli_var(clicon_handle h,
- yang_stmt *ys,
- yang_stmt *yreferred,
- char *helptext,
- cbuf *cb)
+ yang_stmt *ys,
+ yang_stmt *yreferred,
+ char *helptext,
+ cbuf *cb)
{
int retval = -1;
char *origtype = NULL;
@@ -680,80 +680,80 @@ yang2cli_var(clicon_handle h,
int completionp;
if ((patterns = cvec_new(0)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ goto done;
}
if (yang_type_get(yreferred, &origtype, &yrestype,
- &options, &cvv, patterns, NULL, &fraction_digits) < 0)
- goto done;
+ &options, &cvv, patterns, NULL, &fraction_digits) < 0)
+ goto done;
restype = yang_argument_get(yrestype);
if (strcmp(restype, "empty") == 0)
- goto ok;
+ goto ok;
if (clicon_type2cv(origtype, restype, yreferred, &cvtype) < 0)
- goto done;
+ goto done;
cvtypestr = cv_type2str(cvtype);
/* Note restype can be NULL here for example with unresolved hardcoded uuid */
if (strcmp(restype, "union") == 0){
- /* Union: loop over resolved type's sub-types (can also be recursive unions) */
- cprintf(cb, "(");
- if (yang2cli_var_union(h, ys, origtype, yrestype, helptext, cb) < 0)
- goto done;
- if (autocli_completion(h, &completionp) < 0)
- goto done;
- if (completionp){
- if ((result = cli_expand_var_generate(h, ys, cvtypestr,
- options, fraction_digits, 1, cb)) < 0)
- goto done;
- if (result == 0)
- yang2cli_helptext(cb, helptext);
- }
- cprintf(cb, ")");
+ /* Union: loop over resolved type's sub-types (can also be recursive unions) */
+ cprintf(cb, "(");
+ if (yang2cli_var_union(h, ys, origtype, yrestype, helptext, cb) < 0)
+ goto done;
+ if (autocli_completion(h, &completionp) < 0)
+ goto done;
+ if (completionp){
+ if ((result = cli_expand_var_generate(h, ys, cvtypestr,
+ options, fraction_digits, 1, cb)) < 0)
+ goto done;
+ if (result == 0)
+ yang2cli_helptext(cb, helptext);
+ }
+ cprintf(cb, ")");
}
else if (strcmp(restype,"leafref")==0){
- yang_stmt *ypath;
- char *path_arg;
- yang_stmt *yref = NULL;
+ yang_stmt *ypath;
+ char *path_arg;
+ yang_stmt *yref = NULL;
- if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){
- clicon_err(OE_YANG, 0, "No Y_PATH for leafref");
- goto done;
- }
- if ((path_arg = yang_argument_get(ypath)) == NULL){
- clicon_err(OE_YANG, 0, "No argument for Y_PATH");
- goto done;
- }
- if (yang_path_arg(yreferred, path_arg, &yref) < 0)
- goto done;
- if (yref == NULL){
- /* Give up: use yreferred
- */
- if (yang2cli_var_leafref(h, ys, yrestype, helptext, cvtype, options,
- cvv, patterns, fraction_digits, cb) < 0)
- goto done;
- }
- else {
- if (yreferred == yref){
- clicon_err(OE_YANG, 0, "Referred YANG node for leafref path %s points to self", path_arg);
- goto done;
- }
- /* recurse call with new referred node */
- if (yang2cli_var(h, ys, yref, helptext, cb) < 0)
- goto done;
- }
+ if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){
+ clicon_err(OE_YANG, 0, "No Y_PATH for leafref");
+ goto done;
+ }
+ if ((path_arg = yang_argument_get(ypath)) == NULL){
+ clicon_err(OE_YANG, 0, "No argument for Y_PATH");
+ goto done;
+ }
+ if (yang_path_arg(yreferred, path_arg, &yref) < 0)
+ goto done;
+ if (yref == NULL){
+ /* Give up: use yreferred
+ */
+ if (yang2cli_var_leafref(h, ys, yrestype, helptext, cvtype, options,
+ cvv, patterns, fraction_digits, cb) < 0)
+ goto done;
+ }
+ else {
+ if (yreferred == yref){
+ clicon_err(OE_YANG, 0, "Referred YANG node for leafref path %s points to self", path_arg);
+ goto done;
+ }
+ /* recurse call with new referred node */
+ if (yang2cli_var(h, ys, yref, helptext, cb) < 0)
+ goto done;
+ }
}
else{
- if (yang2cli_var_leafref(h, ys, yrestype, helptext, cvtype, options,
- cvv, patterns, fraction_digits, cb) < 0)
- goto done;
+ if (yang2cli_var_leafref(h, ys, yrestype, helptext, cvtype, options,
+ cvv, patterns, fraction_digits, cb) < 0)
+ goto done;
}
ok:
retval = 0;
done:
if (origtype)
- free(origtype);
+ free(origtype);
if (patterns)
- cvec_free(patterns);
+ cvec_free(patterns);
return retval;
}
@@ -770,11 +770,11 @@ yang2cli_var(clicon_handle h,
*/
static int
yang2cli_leaf(clicon_handle h,
- yang_stmt *ys,
- int level,
- int callback,
- int key_leaf,
- cbuf *cb)
+ yang_stmt *ys,
+ int level,
+ int callback,
+ int key_leaf,
+ cbuf *cb)
{
yang_stmt *yd; /* description */
int retval = -1;
@@ -787,73 +787,73 @@ yang2cli_leaf(clicon_handle h,
/* description */
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
- if ((helptext = strdup(yang_argument_get(yd))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- if ((s = strstr(helptext, "\n\n")) != NULL)
- *s = '\0';
+ if ((helptext = strdup(yang_argument_get(yd))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ if ((s = strstr(helptext, "\n\n")) != NULL)
+ *s = '\0';
}
cprintf(cb, "%*s", level*3, "");
/* Called a second time in yang2cli_var, room for optimization */
if (yang_type_get(ys, NULL, &yrestype,
- NULL, NULL, NULL, NULL, NULL) < 0)
- goto done;
+ NULL, NULL, NULL, NULL, NULL) < 0)
+ goto done;
if (key_leaf == 0 && strcmp(yang_argument_get(yrestype), "empty") != 0)
- extralevel = 1;
+ extralevel = 1;
if (autocli_list_keyword(h, &listkw) < 0)
- goto done;
+ goto done;
if (listkw == AUTOCLI_LISTKW_ALL ||
- (key_leaf==0 && listkw == AUTOCLI_LISTKW_NOKEY)){
- cprintf(cb, "%s", yang_argument_get(ys));
- yang2cli_helptext(cb, helptext);
- cprintf(cb, " ");
- if (yang_extension_value(ys, "hide", CLIXON_AUTOCLI_NS, &hideext, NULL) < 0)
- goto done;
- if (hideext)
- cprintf(cb, ", hide"); /* XXX ensure always { */
- if (extralevel){
- if (callback){
- if (cli_callback_generate(h, ys, cb) < 0)
- goto done;
- cprintf(cb, ", ac-leaf");
- cprintf(cb, ", act-leafconst");
- cprintf(cb, ";\n");
- }
- cprintf(cb, "{"); /* termleaf label + extra level around leaf */
- }
- if (yang2cli_var(h, ys, ys, helptext, cb) < 0)
- goto done;
+ (key_leaf==0 && listkw == AUTOCLI_LISTKW_NOKEY)){
+ cprintf(cb, "%s", yang_argument_get(ys));
+ yang2cli_helptext(cb, helptext);
+ cprintf(cb, " ");
+ if (yang_extension_value(ys, "hide", CLIXON_AUTOCLI_NS, &hideext, NULL) < 0)
+ goto done;
+ if (hideext)
+ cprintf(cb, ", hide"); /* XXX ensure always { */
+ if (extralevel){
+ if (callback){
+ if (cli_callback_generate(h, ys, cb) < 0)
+ goto done;
+ cprintf(cb, ", ac-leaf");
+ cprintf(cb, ", act-leafconst");
+ cprintf(cb, ";\n");
+ }
+ cprintf(cb, "{"); /* termleaf label + extra level around leaf */
+ }
+ if (yang2cli_var(h, ys, ys, helptext, cb) < 0)
+ goto done;
}
else{
- if (yang2cli_var(h, ys, ys, helptext, cb) < 0)
- goto done;
+ if (yang2cli_var(h, ys, ys, helptext, cb) < 0)
+ goto done;
}
if (callback){
- if (cli_callback_generate(h, ys, cb) < 0)
- goto done;
- switch (key_leaf){
- case 0:
- cprintf(cb, ", ac-leaf");
- cprintf(cb, ", act-leafvar");
- break;
- case 1:
- cprintf(cb, ", ac-leaf");
- cprintf(cb, ", act-prekey");
- break;
- case 2:
- /* Dont mark as leaf since it represents a (single) list entry */
- cprintf(cb, ", act-lastkey");
- break;
- }
- cprintf(cb, ";\n");
+ if (cli_callback_generate(h, ys, cb) < 0)
+ goto done;
+ switch (key_leaf){
+ case 0:
+ cprintf(cb, ", ac-leaf");
+ cprintf(cb, ", act-leafvar");
+ break;
+ case 1:
+ cprintf(cb, ", ac-leaf");
+ cprintf(cb, ", act-prekey");
+ break;
+ case 2:
+ /* Dont mark as leaf since it represents a (single) list entry */
+ cprintf(cb, ", act-lastkey");
+ break;
+ }
+ cprintf(cb, ";\n");
}
if (extralevel)
- cprintf(cb, "}\n");
+ cprintf(cb, "}\n");
retval = 0;
done:
if (helptext)
- free(helptext);
+ free(helptext);
return retval;
}
@@ -865,9 +865,9 @@ yang2cli_leaf(clicon_handle h,
*/
static int
yang2cli_container(clicon_handle h,
- yang_stmt *ys,
- int level,
- cbuf *cb)
+ yang_stmt *ys,
+ int level,
+ cbuf *cb)
{
yang_stmt *yc;
yang_stmt *yd;
@@ -879,54 +879,54 @@ yang2cli_container(clicon_handle h,
int extvalue = 0;
if (ys_real_module(ys, &ymod) < 0)
- goto done;
+ goto done;
/* If non-presence container && HIDE mode && only child is
* a list, then skip container keyword
* See also clixon_cli2file
*/
if (autocli_compress(h, ys, &compress) < 0)
- goto done;
+ goto done;
if (!compress){
- cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
- if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
- if ((helptext = strdup(yang_argument_get(yd))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- if ((s = strstr(helptext, "\n\n")) != NULL)
- *s = '\0';
- yang2cli_helptext(cb, helptext);
- }
- if (cli_callback_generate(h, ys, cb) < 0)
- goto done;
- if (yang_extension_value(ys, "hide", CLIXON_AUTOCLI_NS, &extvalue, NULL) < 0)
- goto done;
- if (extvalue)
- cprintf(cb, ", hide");
+ cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
+ if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
+ if ((helptext = strdup(yang_argument_get(yd))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ if ((s = strstr(helptext, "\n\n")) != NULL)
+ *s = '\0';
+ yang2cli_helptext(cb, helptext);
+ }
+ if (cli_callback_generate(h, ys, cb) < 0)
+ goto done;
+ if (yang_extension_value(ys, "hide", CLIXON_AUTOCLI_NS, &extvalue, NULL) < 0)
+ goto done;
+ if (extvalue)
+ cprintf(cb, ", hide");
#ifdef NYI /* This is for the mode extension, not yet supported */
- {
- int mode = 0;
- /* First see if extension mode, if not, check if default mode */
- if (yang_extension_value(ys, "mode", CLIXON_AUTOCLI_NS, &mode, NULL) < 0)
- goto done;
- if (mode == 0 && autocli_edit_mode(h, Y_CONTAINER, &mode) < 0)
- goto done;
- if (mode)
- cprintf(cb, ", mode");
- }
-#endif
- cprintf(cb, ", act-container;{\n");
+ {
+ int mode = 0;
+ /* First see if extension mode, if not, check if default mode */
+ if (yang_extension_value(ys, "mode", CLIXON_AUTOCLI_NS, &mode, NULL) < 0)
+ goto done;
+ if (mode == 0 && autocli_edit_mode(h, Y_CONTAINER, &mode) < 0)
+ goto done;
+ if (mode)
+ cprintf(cb, ", mode");
+ }
+#endif
+ cprintf(cb, ", act-container;{\n");
}
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL)
- if (yang2cli_stmt(h, yc, level+1, cb) < 0)
- goto done;
+ if (yang2cli_stmt(h, yc, level+1, cb) < 0)
+ goto done;
if (!compress)
- cprintf(cb, "%*s}\n", level*3, "");
+ cprintf(cb, "%*s}\n", level*3, "");
retval = 0;
done:
if (helptext)
- free(helptext);
+ free(helptext);
return retval;
}
@@ -938,9 +938,9 @@ yang2cli_container(clicon_handle h,
*/
static int
yang2cli_list(clicon_handle h,
- yang_stmt *ys,
- int level,
- cbuf *cb)
+ yang_stmt *ys,
+ int level,
+ cbuf *cb)
{
yang_stmt *yc;
yang_stmt *yd;
@@ -951,81 +951,81 @@ yang2cli_list(clicon_handle h,
int retval = -1;
char *helptext = NULL;
char *s;
- int last_key = 0;
+ int last_key = 0;
int exist = 0;
int keynr = 0;
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
- if ((helptext = strdup(yang_argument_get(yd))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- if ((s = strstr(helptext, "\n\n")) != NULL)
- *s = '\0';
- yang2cli_helptext(cb, helptext);
+ if ((helptext = strdup(yang_argument_get(yd))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ if ((s = strstr(helptext, "\n\n")) != NULL)
+ *s = '\0';
+ yang2cli_helptext(cb, helptext);
}
if (yang_extension_value(ys, "hide", CLIXON_AUTOCLI_NS, &exist, NULL) < 0)
- goto done;
+ goto done;
if (exist){
- cprintf(cb, ",hide");
+ cprintf(cb, ",hide");
}
/* Loop over all key variables */
cvk = yang_cvec_get(ys); /* Use Y_LIST cache, see ys_populate_list() */
cvi = NULL;
/* Iterate over individual keys */
while ((cvi = cvec_each(cvk, cvi)) != NULL) {
- keyname = cv_string_get(cvi);
- if ((yleaf = yang_find(ys, Y_LEAF, keyname)) == NULL){
- clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"",
- yang_argument_get(ys), keyname);
- goto done;
- }
- /* Print key variable now, and skip it in loop below
- * Note, only print callback on last statement
- */
- last_key = cvec_next(cvk, cvi)?0:1;
- if (cli_callback_generate(h, ys, cb) < 0)
- goto done;
- if (keynr == 0)
- cprintf(cb, ",act-list");
- else
- cprintf(cb, ",act-prekey");
- cprintf(cb, ";\n");
- cprintf(cb, "{\n");
- if (yang2cli_leaf(h, yleaf,
- level+1,
- last_key, /* callback */
- last_key?2:1, /* key_leaf */
- cb) < 0)
- goto done;
- keynr++;
+ keyname = cv_string_get(cvi);
+ if ((yleaf = yang_find(ys, Y_LEAF, keyname)) == NULL){
+ clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"",
+ yang_argument_get(ys), keyname);
+ goto done;
+ }
+ /* Print key variable now, and skip it in loop below
+ * Note, only print callback on last statement
+ */
+ last_key = cvec_next(cvk, cvi)?0:1;
+ if (cli_callback_generate(h, ys, cb) < 0)
+ goto done;
+ if (keynr == 0)
+ cprintf(cb, ",act-list");
+ else
+ cprintf(cb, ",act-prekey");
+ cprintf(cb, ";\n");
+ cprintf(cb, "{\n");
+ if (yang2cli_leaf(h, yleaf,
+ level+1,
+ last_key, /* callback */
+ last_key?2:1, /* key_leaf */
+ cb) < 0)
+ goto done;
+ keynr++;
}
cprintf(cb, "{\n");
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL) {
- /* cvk is a cvec of strings containing variable names
- yc is a leaf that may match one of the values of cvk.
- */
- cvi = NULL;
- while ((cvi = cvec_each(cvk, cvi)) != NULL) {
- keyname = cv_string_get(cvi);
- if (strcmp(keyname, yang_argument_get(yc)) == 0)
- break;
- }
- if (cvi != NULL)
- continue;
- if (yang2cli_stmt(h, yc, level+1, cb) < 0)
- goto done;
+ /* cvk is a cvec of strings containing variable names
+ yc is a leaf that may match one of the values of cvk.
+ */
+ cvi = NULL;
+ while ((cvi = cvec_each(cvk, cvi)) != NULL) {
+ keyname = cv_string_get(cvi);
+ if (strcmp(keyname, yang_argument_get(yc)) == 0)
+ break;
+ }
+ if (cvi != NULL)
+ continue;
+ if (yang2cli_stmt(h, yc, level+1, cb) < 0)
+ goto done;
}
cprintf(cb, "%*s}\n", level*3, "");
/* Close with } for each key */
while (keynr--)
- cprintf(cb, "%*s}\n", level*3, "");
+ cprintf(cb, "%*s}\n", level*3, "");
retval = 0;
done:
if (helptext)
- free(helptext);
+ free(helptext);
return retval;
}
@@ -1046,29 +1046,29 @@ yang2cli_list(clicon_handle h,
*/
static int
yang2cli_choice(clicon_handle h,
- yang_stmt *ys,
- int level,
- cbuf *cb)
+ yang_stmt *ys,
+ int level,
+ cbuf *cb)
{
int retval = -1;
yang_stmt *yc;
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL) {
- switch (yang_keyword_get(yc)){
- case Y_CASE:
- if (yang2cli_stmt(h, yc, level+2, cb) < 0)
- goto done;
- break;
- case Y_CONTAINER:
- case Y_LEAF:
- case Y_LEAF_LIST:
- case Y_LIST:
- default:
- if (yang2cli_stmt(h, yc, level+1, cb) < 0)
- goto done;
- break;
- }
+ switch (yang_keyword_get(yc)){
+ case Y_CASE:
+ if (yang2cli_stmt(h, yc, level+2, cb) < 0)
+ goto done;
+ break;
+ case Y_CONTAINER:
+ case Y_LEAF:
+ case Y_LEAF_LIST:
+ case Y_LIST:
+ default:
+ if (yang2cli_stmt(h, yc, level+1, cb) < 0)
+ goto done;
+ break;
+ }
}
retval = 0;
done:
@@ -1083,9 +1083,9 @@ yang2cli_choice(clicon_handle h,
*/
static int
yang2cli_stmt(clicon_handle h,
- yang_stmt *ys,
- int level,
- cbuf *cb)
+ yang_stmt *ys,
+ int level,
+ cbuf *cb)
{
yang_stmt *yc;
int retval = -1;
@@ -1093,40 +1093,40 @@ yang2cli_stmt(clicon_handle h,
/* Only produce autocli for YANG non-config only if autocli-treeref-state is true */
if (autocli_treeref_state(h, &treeref_state) < 0)
- goto done;
+ goto done;
if (treeref_state || yang_config(ys)){
- switch (yang_keyword_get(ys)){
- case Y_CONTAINER:
- if (yang2cli_container(h, ys, level, cb) < 0)
- goto done;
- break;
- case Y_LIST:
- if (yang2cli_list(h, ys, level, cb) < 0)
- goto done;
- break;
- case Y_CHOICE:
- if (yang2cli_choice(h, ys, level, cb) < 0)
- goto done;
- break;
- case Y_LEAF_LIST:
- case Y_LEAF:
- if (yang2cli_leaf(h, ys, level,
- 1, /* callback */
- 0, /* keyleaf */
- cb) < 0)
- goto done;
- break;
- case Y_CASE:
- case Y_SUBMODULE:
- case Y_MODULE:
- yc = NULL;
- while ((yc = yn_each(ys, yc)) != NULL)
- if (yang2cli_stmt(h, yc, level+1, cb) < 0)
- goto done;
- break;
- default: /* skip */
- break;
- }
+ switch (yang_keyword_get(ys)){
+ case Y_CONTAINER:
+ if (yang2cli_container(h, ys, level, cb) < 0)
+ goto done;
+ break;
+ case Y_LIST:
+ if (yang2cli_list(h, ys, level, cb) < 0)
+ goto done;
+ break;
+ case Y_CHOICE:
+ if (yang2cli_choice(h, ys, level, cb) < 0)
+ goto done;
+ break;
+ case Y_LEAF_LIST:
+ case Y_LEAF:
+ if (yang2cli_leaf(h, ys, level,
+ 1, /* callback */
+ 0, /* keyleaf */
+ cb) < 0)
+ goto done;
+ break;
+ case Y_CASE:
+ case Y_SUBMODULE:
+ case Y_MODULE:
+ yc = NULL;
+ while ((yc = yn_each(ys, yc)) != NULL)
+ if (yang2cli_stmt(h, yc, level+1, cb) < 0)
+ goto done;
+ break;
+ default: /* skip */
+ break;
+ }
}
retval = 0;
done:
@@ -1140,18 +1140,18 @@ yang2cli_stmt(clicon_handle h,
*/
static cvec*
cvec_add_name(cvec *cvv,
- char *name)
+ char *name)
{
cg_var *cv= NULL;
if (cvv == NULL &&
- (cvv = cvec_new(0)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_new");
- return NULL;
+ (cvv = cvec_new(0)) == NULL){
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ return NULL;
}
if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_add");
- return NULL;
+ clicon_err(OE_UNIX, errno, "cvec_add");
+ return NULL;
}
/* Filter out state data, use "nonconfig" as defined in RFC8040 4.8.1
*/
@@ -1189,12 +1189,12 @@ cvec_add_name(cvec *cvv,
*/
static int
yang2cli_post(clicon_handle h,
- cg_obj *cop,
- parse_tree *pt,
- int i0,
- yang_stmt *yp,
- yang_stmt *ykey,
- int *configp)
+ cg_obj *cop,
+ parse_tree *pt,
+ int i0,
+ yang_stmt *yp,
+ yang_stmt *ykey,
+ int *configp)
{
int retval = -1;
cg_obj *co;
@@ -1207,91 +1207,91 @@ yang2cli_post(clicon_handle h,
ypkeyword = yang_keyword_get(yp);
for (i = i0; ico_type == CO_EMPTY){
- char *name;
- cg_var *cv = NULL;
- int j=0;
-
- cv = NULL;
- while ((cv = cvec_each(cop->co_cvec, cv)) != NULL){
- name = cv_name_get(cv);
- if (strncmp(name, "act-", 4) == 0){
- if ((co->co_cvec = cvec_add_name(co->co_cvec, name)) == NULL)
- goto done;
- cv_reset(cv);
- cvec_del_i(cop->co_cvec, j);
- if (cvec_len(cop->co_cvec) == 0){
- cvec_free(cop->co_cvec);
- cop->co_cvec = NULL;
- }
- cv = NULL; // trigger rerun
- j = 0;
- }
- j++;
- }
- continue;
- }
- /* Filters out eg "name " second instance if kw-all / kw-nokey
- * But if only "" it passes
- */
- if ((yc = yang_find_datanode(yp, co->co_command)) == NULL){
+ if ((co = pt_vec_i_get(pt, i)) == NULL){
+ clicon_err(OE_YANG, 0, "Empty object in parsetreelist"); /* shouldnt happen */
+ goto done;
+ }
+ if (co->co_type == CO_EMPTY){
+ char *name;
+ cg_var *cv = NULL;
+ int j=0;
+
+ cv = NULL;
+ while ((cv = cvec_each(cop->co_cvec, cv)) != NULL){
+ name = cv_name_get(cv);
+ if (strncmp(name, "act-", 4) == 0){
+ if ((co->co_cvec = cvec_add_name(co->co_cvec, name)) == NULL)
+ goto done;
+ cv_reset(cv);
+ cvec_del_i(cop->co_cvec, j);
+ if (cvec_len(cop->co_cvec) == 0){
+ cvec_free(cop->co_cvec);
+ cop->co_cvec = NULL;
+ }
+ cv = NULL; // trigger rerun
+ j = 0;
+ }
+ j++;
+ }
+ continue;
+ }
+ /* Filters out eg "name " second instance if kw-all / kw-nokey
+ * But if only "" it passes
+ */
+ if ((yc = yang_find_datanode(yp, co->co_command)) == NULL){
#if 1
- /* XXX In case of compress, look at next level */
- yang_stmt *y = NULL;
- while ((y = yn_each(yp, y)) != NULL){
- if (yang_datanode(y)){
- if ((yc = yang_find_datanode(y, co->co_command)) != NULL)
- break;
- }
- }
- if (y == NULL)
- continue;
+ /* XXX In case of compress, look at next level */
+ yang_stmt *y = NULL;
+ while ((y = yn_each(yp, y)) != NULL){
+ if (yang_datanode(y)){
+ if ((yc = yang_find_datanode(y, co->co_command)) != NULL)
+ break;
+ }
+ }
+ if (y == NULL)
+ continue;
#endif
- }
- yciskey = ypkeyword == Y_LIST && yang_key_match(yp, co->co_command, NULL);
- /* If state: Add nonconfig label*/
- config = *configp;
- if (!yang_config(yc)){
- if ((co->co_cvec = cvec_add_name(co->co_cvec, "ac-state")) == NULL)
- goto done;
- config = 0;
- }
- /* If y is list and yc is key, then call with y */
- if (yciskey){
- if (yang2cli_post(h, co, co_pt_get(co), 0, yp, yc, &config) < 0) // note y not yc
- goto done;
- }
- else if (yang2cli_post(h, co, co_pt_get(co), 0, yc, NULL, &config) < 0)
- goto done;
- if (config){
- if ((co->co_cvec = cvec_add_name(co->co_cvec, "ac-config")) == NULL)
- goto done;
- }
- else
- state++;
+ }
+ yciskey = ypkeyword == Y_LIST && yang_key_match(yp, co->co_command, NULL);
+ /* If state: Add nonconfig label*/
+ config = *configp;
+ if (!yang_config(yc)){
+ if ((co->co_cvec = cvec_add_name(co->co_cvec, "ac-state")) == NULL)
+ goto done;
+ config = 0;
+ }
+ /* If y is list and yc is key, then call with y */
+ if (yciskey){
+ if (yang2cli_post(h, co, co_pt_get(co), 0, yp, yc, &config) < 0) // note y not yc
+ goto done;
+ }
+ else if (yang2cli_post(h, co, co_pt_get(co), 0, yc, NULL, &config) < 0)
+ goto done;
+ if (config){
+ if ((co->co_cvec = cvec_add_name(co->co_cvec, "ac-config")) == NULL)
+ goto done;
+ }
+ else
+ state++;
} /* for */
if (state)
- *configp = 0;
+ *configp = 0;
else { /* Clear all ac-config labels */
- for (i = i0; ico_cvec, cv)) != NULL){
- if (strcmp(cv_name_get(cv), "ac-config") == 0){
- cv_reset(cv);
- cvec_del_i(co->co_cvec, j);
- break;
- }
- j++;
- }
- }
+ co = pt_vec_i_get(pt, i);
+ cv = NULL;
+ while ((cv = cvec_each(co->co_cvec, cv)) != NULL){
+ if (strcmp(cv_name_get(cv), "ac-config") == 0){
+ cv_reset(cv);
+ cvec_del_i(co->co_cvec, j);
+ break;
+ }
+ j++;
+ }
+ }
}
retval = 0;
done:
@@ -1309,9 +1309,9 @@ yang2cli_post(clicon_handle h,
*/
int
yang2cli_yspec(clicon_handle h,
- yang_stmt *yspec,
- char *treename,
- int printgen)
+ yang_stmt *yspec,
+ char *treename,
+ int printgen)
{
int retval = -1;
parse_tree *pt0 = NULL;
@@ -1326,73 +1326,73 @@ yang2cli_yspec(clicon_handle h,
int config;
if ((pt0 = pt_new()) == NULL){
- clicon_err(OE_UNIX, errno, "pt_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "pt_new");
+ goto done;
}
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
/* Traverse YANG, loop through all modules and generate CLI */
ymod = NULL;
while ((ymod = yn_each(yspec, ymod)) != NULL){
- /* Filter module name according to cli_autocli.yang setting
- * Default is pass and ordering is significant
- */
- if (autocli_module(h, yang_argument_get(ymod), &enable) < 0)
- goto done;
- if (!enable)
- continue;
- cbuf_reset(cb);
- if (yang2cli_stmt(h, ymod, 0, cb) < 0)
- goto done;
- if (cbuf_len(cb) == 0)
- continue;
- /* Note Tie-break of same top-level symbol: prefix is NYI
- * Needs to move cligen_parse_str() call here instead of later
- */
- if ((prefix = yang_find_myprefix(ymod)) == NULL){
- clicon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ymod)); /* shouldnt happen */
- goto done;
- }
- if ((pt = pt_new()) == NULL){
- clicon_err(OE_UNIX, errno, "pt_new");
- goto done;
- }
+ /* Filter module name according to cli_autocli.yang setting
+ * Default is pass and ordering is significant
+ */
+ if (autocli_module(h, yang_argument_get(ymod), &enable) < 0)
+ goto done;
+ if (!enable)
+ continue;
+ cbuf_reset(cb);
+ if (yang2cli_stmt(h, ymod, 0, cb) < 0)
+ goto done;
+ if (cbuf_len(cb) == 0)
+ continue;
+ /* Note Tie-break of same top-level symbol: prefix is NYI
+ * Needs to move cligen_parse_str() call here instead of later
+ */
+ if ((prefix = yang_find_myprefix(ymod)) == NULL){
+ clicon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ymod)); /* shouldnt happen */
+ goto done;
+ }
+ if ((pt = pt_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "pt_new");
+ goto done;
+ }
- /* Parse the buffer using cligen parser. load cli syntax */
- if (cligen_parse_str(cli_cligen(h), cbuf_get(cb), "yang2cli", pt, NULL) < 0){
- fprintf(stderr, "%s\n", cbuf_get(cb));
- goto done;
- }
- /* Add prefix: assume new are appended */
- for (i=0; i, fn() cannot be set properly
- */
- config = 1;
- if (yang2cli_post(h, NULL, pt, 0, ymod, NULL, &config) < 0){
- goto done;
- }
- // pt_print(stderr,pt);
- clicon_debug(1, "%s Generated auto-cli for %s", __FUNCTION__, yang_argument_get(ymod));
- if (printgen)
- clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s",
- __FUNCTION__, treename, cbuf_get(cb));
- else
- clicon_debug(2, "%s: Top-level cli-spec %s:\n%s",
- __FUNCTION__, treename, cbuf_get(cb));
- if (cligen_parsetree_merge(pt0, NULL, pt) < 0){
- clicon_err(OE_YANG, errno, "cligen_parsetree_merge");
- goto done;
- }
- pt_free(pt, 1);
- pt = NULL;
+ /* Parse the buffer using cligen parser. load cli syntax */
+ if (cligen_parse_str(cli_cligen(h), cbuf_get(cb), "yang2cli", pt, NULL) < 0){
+ fprintf(stderr, "%s\n", cbuf_get(cb));
+ goto done;
+ }
+ /* Add prefix: assume new are appended */
+ for (i=0; i, fn() cannot be set properly
+ */
+ config = 1;
+ if (yang2cli_post(h, NULL, pt, 0, ymod, NULL, &config) < 0){
+ goto done;
+ }
+ // pt_print(stderr,pt);
+ clicon_debug(1, "%s Generated auto-cli for %s", __FUNCTION__, yang_argument_get(ymod));
+ if (printgen)
+ clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s",
+ __FUNCTION__, treename, cbuf_get(cb));
+ else
+ clicon_debug(2, "%s: Top-level cli-spec %s:\n%s",
+ __FUNCTION__, treename, cbuf_get(cb));
+ if (cligen_parsetree_merge(pt0, NULL, pt) < 0){
+ clicon_err(OE_YANG, errno, "cligen_parsetree_merge");
+ goto done;
+ }
+ pt_free(pt, 1);
+ pt = NULL;
} /* ymod */
/* Resolve the expand callback functions in the generated syntax.
* This "should" only be GENERATE_EXPAND_XMLDB
@@ -1400,27 +1400,27 @@ yang2cli_yspec(clicon_handle h,
* CLICON namespace, not in a cli frontend plugin.
*/
if (cligen_expandv_str2fn(pt0, (expandv_str2fn_t*)clixon_str2fn, NULL) < 0)
- goto done;
+ goto done;
/* Append cligen tree and name it */
if ((ph = cligen_ph_add(cli_cligen(h), treename)) == NULL)
- goto done;
+ goto done;
if (cligen_ph_parsetree_set(ph, pt0) < 0)
- goto done;
+ goto done;
pt0 = NULL;
#if 0
if (printgen){
- clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s", __FUNCTION__, treename);
- pt_print1(stderr, pt0, 0);
+ clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s", __FUNCTION__, treename);
+ pt_print1(stderr, pt0, 0);
}
#endif
retval = 0;
done:
if (pt)
- pt_free(pt, 1);
+ pt_free(pt, 1);
if (pt0)
- pt_free(pt0, 1);
+ pt_free(pt0, 1);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
diff --git a/apps/cli/cli_handle.c b/apps/cli/cli_handle.c
index a412794a..2ba72a95 100644
--- a/apps/cli/cli_handle.c
+++ b/apps/cli/cli_handle.c
@@ -87,7 +87,7 @@ struct cli_handle {
/* ------ end of common handle ------ */
cligen_handle cl_cligen; /* cligen handle */
- cli_syntax_t *cl_stx; /* CLI syntax structure */
+ cli_syntax_t *cl_stx; /* CLI syntax structure */
};
/*! Return a clicon handle for other CLICON API calls
@@ -100,11 +100,11 @@ cli_handle_init(void)
clicon_handle h = NULL;
if ((cl = (struct cli_handle *)clicon_handle_init0(sizeof(struct cli_handle))) == NULL)
- return NULL;
+ return NULL;
if ((clih = cligen_init()) == NULL){
- clicon_handle_exit((clicon_handle)cl);
- goto done;
+ clicon_handle_exit((clicon_handle)cl);
+ goto done;
}
cligen_userhandle_set(clih, cl);
cligen_eval_wrap_fn_set(clih, plugin_context_check, cl);
@@ -124,7 +124,7 @@ cli_handle_exit(clicon_handle h)
struct cli_handle *cl = handle(h);
if (cl->cl_stx)
- free(cl->cl_stx);
+ free(cl->cl_stx);
clicon_handle_exit(h); /* frees h and options */
cligen_exit(ch);
@@ -147,12 +147,12 @@ cli_syntax(clicon_handle h)
/*! Set current syntax-group */
int
cli_syntax_set(clicon_handle h,
- cli_syntax_t *stx)
+ cli_syntax_t *stx)
{
struct cli_handle *cl = handle(h);
if (cl->cl_stx)
- free(cl->cl_stx);
+ free(cl->cl_stx);
cl->cl_stx = stx;
return 0;
}
@@ -167,10 +167,10 @@ cli_cligen(clicon_handle h)
int
cli_parse_file(clicon_handle h,
- FILE *f,
- char *name, /* just for errs */
- parse_tree *pt,
- cvec *globals)
+ FILE *f,
+ char *name, /* just for errs */
+ parse_tree *pt,
+ cvec *globals)
{
cligen_handle ch = cligen(h);
@@ -179,7 +179,7 @@ cli_parse_file(clicon_handle h,
int
cli_susp_hook(clicon_handle h,
- cligen_susp_cb_t *fn)
+ cligen_susp_cb_t *fn)
{
cligen_handle ch = cligen(h);
@@ -188,7 +188,7 @@ cli_susp_hook(clicon_handle h,
}
int
cli_interrupt_hook(clicon_handle h,
- cligen_interrupt_cb_t *fn)
+ cligen_interrupt_cb_t *fn)
{
cligen_handle ch = cligen(h);
@@ -198,7 +198,7 @@ cli_interrupt_hook(clicon_handle h,
int
cli_prompt_set(clicon_handle h,
- char *prompt)
+ char *prompt)
{
cligen_handle ch = cligen(h);
return cligen_prompt_set(ch, prompt);
@@ -206,7 +206,7 @@ cli_prompt_set(clicon_handle h,
int
cli_logsyntax_set(clicon_handle h,
- int status)
+ int status)
{
cligen_handle ch = cligen(h);
return cligen_logsyntax_set(ch, status);
diff --git a/apps/cli/cli_handle.h b/apps/cli/cli_handle.h
index b9881ef8..8c71f5f0 100644
--- a/apps/cli/cli_handle.h
+++ b/apps/cli/cli_handle.h
@@ -44,10 +44,10 @@
* Internal prototypes. For exported functions see clixon_cli_api.h
*/
int cli_parse_file(clicon_handle h,
- FILE *f,
- char *name, /* just for errs */
- parse_tree *pt,
- cvec *globals);
+ FILE *f,
+ char *name, /* just for errs */
+ parse_tree *pt,
+ cvec *globals);
int cli_susp_hook(clicon_handle h, cligen_susp_cb_t *fn);
diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c
index 6a7a035f..347288ac 100644
--- a/apps/cli/cli_main.c
+++ b/apps/cli/cli_main.c
@@ -90,33 +90,33 @@ cli_history_load(clicon_handle h)
/* Get history size from clixon option, if not use cligen default. */
if (clicon_option_exists(h, "CLICON_CLI_HIST_SIZE"))
- lines = clicon_option_int(h,"CLICON_CLI_HIST_SIZE");
+ lines = clicon_option_int(h,"CLICON_CLI_HIST_SIZE");
else
- lines = CLIGEN_HISTSIZE_DEFAULT;
+ lines = CLIGEN_HISTSIZE_DEFAULT;
/* Re-init history with clixon lines (1st time was w cligen defaults) */
if (cligen_hist_init(cli_cligen(h), lines) < 0)
- goto done;
+ goto done;
if ((filename = clicon_option_str(h,"CLICON_CLI_HIST_FILE")) == NULL)
- goto ok; /* ignore */
+ goto ok; /* ignore */
if (wordexp(filename, &result, 0) < 0){
- clicon_err(OE_UNIX, errno, "wordexp");
- goto done;
+ clicon_err(OE_UNIX, errno, "wordexp");
+ goto done;
}
if ((f = fopen(result.we_wordv[0], "r")) == NULL){
- clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for reading: %s: %s",
- result.we_wordv[0], strerror(errno));
- goto ok;
+ clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for reading: %s: %s",
+ result.we_wordv[0], strerror(errno));
+ goto ok;
}
if (cligen_hist_file_load(cli_cligen(h), f) < 0){
- clicon_err(OE_UNIX, errno, "cligen_hist_file_load");
- goto done;
+ clicon_err(OE_UNIX, errno, "cligen_hist_file_load");
+ goto done;
}
ok:
retval = 0;
done:
wordfree(&result);
if (f)
- fclose(f);
+ fclose(f);
return retval;
}
@@ -133,26 +133,26 @@ cli_history_save(clicon_handle h)
wordexp_t result = {0,}; /* for tilde expansion */
if ((filename = clicon_option_str(h, "CLICON_CLI_HIST_FILE")) == NULL)
- goto ok; /* ignore */
+ goto ok; /* ignore */
if (wordexp(filename, &result, 0) < 0){
- clicon_err(OE_UNIX, errno, "wordexp");
- goto done;
+ clicon_err(OE_UNIX, errno, "wordexp");
+ goto done;
}
if ((f = fopen(result.we_wordv[0], "w+")) == NULL){
- clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for writing: %s: %s",
- result.we_wordv[0], strerror(errno));
- goto ok;
+ clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for writing: %s: %s",
+ result.we_wordv[0], strerror(errno));
+ goto ok;
}
if (cligen_hist_file_save(cli_cligen(h), f) < 0){
- clicon_err(OE_UNIX, errno, "cligen_hist_file_save");
- goto done;
+ clicon_err(OE_UNIX, errno, "cligen_hist_file_save");
+ goto done;
}
ok:
retval = 0;
done:
wordfree(&result);
if (f)
- fclose(f);
+ fclose(f);
return retval;
}
@@ -170,13 +170,13 @@ cli_terminate(clicon_handle h)
clicon_rpc_close_session(h);
if ((yspec = clicon_dbspec_yang(h)) != NULL)
- ys_free(yspec);
+ ys_free(yspec);
if ((yspec = clicon_config_yang(h)) != NULL)
- ys_free(yspec);
+ ys_free(yspec);
if ((nsctx = clicon_nsctx_global_get(h)) != NULL)
- cvec_free(nsctx);
+ cvec_free(nsctx);
if ((x = clicon_conf_xml(h)) != NULL)
- xml_free(x);
+ xml_free(x);
clicon_data_cvec_del(h, "cli-edit-cvv");;
clicon_data_cvec_del(h, "cli-edit-filter");;
xpath_optimize_exit();
@@ -198,7 +198,7 @@ static void
cli_sig_term(int arg)
{
clicon_log(LOG_NOTICE, "%s: %u Terminated (killed by sig %d)",
- __PROGRAM__, getpid(), arg);
+ __PROGRAM__, getpid(), arg);
exit(1);
}
@@ -211,12 +211,12 @@ cli_signal_init (clicon_handle h)
cli_signal_block(h);
if (set_signal(SIGTERM, cli_sig_term, NULL) < 0){
- clicon_err(OE_UNIX, errno, "Setting SIGTERM signal");
- goto done;
+ clicon_err(OE_UNIX, errno, "Setting SIGTERM signal");
+ goto done;
}
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
- clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
- goto done;
+ clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
+ goto done;
}
retval = 0;
done:
@@ -239,17 +239,17 @@ cli_interactive(clicon_handle h)
/* Loop through all commands */
while(!cligen_exiting(cli_cligen(h))) {
- new_mode = cli_syntax_mode(h);
- cmd = NULL;
- if (clicon_cliread(h, &cmd) < 0)
- goto done;
- if (cmd == NULL) { /* EOF */
- cligen_exiting_set(cli_cligen(h), 1);
- continue;
- }
- if (clicon_parse(h, cmd, &new_mode, &result, NULL) < 0)
- goto done;
- /* Why not check result? */
+ new_mode = cli_syntax_mode(h);
+ cmd = NULL;
+ if (clicon_cliread(h, &cmd) < 0)
+ goto done;
+ if (cmd == NULL) { /* EOF */
+ cligen_exiting_set(cli_cligen(h), 1);
+ continue;
+ }
+ if (clicon_parse(h, cmd, &new_mode, &result, NULL) < 0)
+ goto done;
+ /* Why not check result? */
}
retval = 0;
done:
@@ -270,89 +270,89 @@ autocli_trees_default(clicon_handle h)
/* Create backward compatible tree: @datamodel */
if ((ph = cligen_ph_add(cli_cligen(h), "datamodel")) == NULL)
- goto done;
+ goto done;
if ((pt = pt_new()) == NULL){
- clicon_err(OE_UNIX, errno, "pt_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "pt_new");
+ goto done;
}
if (cligen_parse_str(cli_cligen(h),
- "@basemodel, @remove:act-prekey, @remove:act-list, @remove:act-leafconst, @remove:ac-state;",
- "datamodel", pt, NULL) < 0)
- goto done;
+ "@basemodel, @remove:act-prekey, @remove:act-list, @remove:act-leafconst, @remove:ac-state;",
+ "datamodel", pt, NULL) < 0)
+ goto done;
if (cligen_ph_parsetree_set(ph, pt) < 0)
- goto done;
+ goto done;
/* Create backward compatible tree: @datamodelshow */
if ((ph = cligen_ph_add(cli_cligen(h), "datamodelshow")) == NULL)
- goto done;
+ goto done;
if ((pt = pt_new()) == NULL){
- clicon_err(OE_UNIX, errno, "pt_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "pt_new");
+ goto done;
}
if (cligen_parse_str(cli_cligen(h),
- "@basemodel, @remove:act-leafvar, @remove:ac-state;",
- "datamodelshow", pt, NULL) < 0)
- goto done;
+ "@basemodel, @remove:act-leafvar, @remove:ac-state;",
+ "datamodelshow", pt, NULL) < 0)
+ goto done;
if (cligen_ph_parsetree_set(ph, pt) < 0)
- goto done;
+ goto done;
/* Create backward compatible tree: @datamodelstate */
if ((ph = cligen_ph_add(cli_cligen(h), "datamodelstate")) == NULL)
- goto done;
+ goto done;
if ((pt = pt_new()) == NULL){
- clicon_err(OE_UNIX, errno, "pt_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "pt_new");
+ goto done;
}
if (cligen_parse_str(cli_cligen(h),
- "@basemodel, @remove:act-leafvar;",
- "datamodelstate", pt, NULL) < 0)
- goto done;
+ "@basemodel, @remove:act-leafvar;",
+ "datamodelstate", pt, NULL) < 0)
+ goto done;
if (cligen_ph_parsetree_set(ph, pt) < 0)
- goto done;
+ goto done;
/* Create new tree: @datamodelmode */
if ((ph = cligen_ph_add(cli_cligen(h), "datamodelmode")) == NULL)
- goto done;
+ goto done;
if ((pt = pt_new()) == NULL){
- clicon_err(OE_UNIX, errno, "pt_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "pt_new");
+ goto done;
}
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
cprintf(cb, "@basemodel, @remove:act-prekey, @remove:act-leafconst, @remove:ac-state");
/* Check if container and list are allowed edit modes */
mode = 0;
if (autocli_edit_mode(h, "container", &mode) < 0)
- goto done;
+ goto done;
if (mode == 0)
- cprintf(cb, ", @remove:act-container");
+ cprintf(cb, ", @remove:act-container");
mode = 0;
if (autocli_edit_mode(h, "listall", &mode) < 0)
- goto done;
+ goto done;
if (mode == 0)
- cprintf(cb, ", @remove:act-list");
+ cprintf(cb, ", @remove:act-list");
mode = 0;
if (autocli_edit_mode(h, "list", &mode) < 0)
- goto done;
+ goto done;
if (mode == 0)
- cprintf(cb, ", @remove:act-lastkey");
+ cprintf(cb, ", @remove:act-lastkey");
mode = 0;
if (autocli_edit_mode(h, "leaf", &mode) < 0)
- goto done;
+ goto done;
if (mode == 0)
- cprintf(cb, ", @remove:ac-leaf");
+ cprintf(cb, ", @remove:ac-leaf");
cprintf(cb, ";");
if (cligen_parse_str(cli_cligen(h), cbuf_get(cb), "datamodelmode", pt, NULL) < 0)
- goto done;
+ goto done;
if (cligen_ph_parsetree_set(ph, pt) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -369,7 +369,7 @@ autocli_trees_default(clicon_handle h)
*/
static int
autocli_start(clicon_handle h,
- int printgen)
+ int printgen)
{
int retval = -1;
yang_stmt *yspec;
@@ -384,21 +384,21 @@ autocli_start(clicon_handle h,
* is disable
*/
if (autocli_module(h, NULL, &enable) < 0)
- goto done;
+ goto done;
if (!enable){
- clicon_debug(1, "%s Autocli not enabled (clixon-autocli)", __FUNCTION__);
- goto ok;
+ clicon_debug(1, "%s Autocli not enabled (clixon-autocli)", __FUNCTION__);
+ goto ok;
}
/* Init yang2cli */
if (yang2cli_init(h) < 0)
- goto done;
+ goto done;
yspec = clicon_dbspec_yang(h);
/* The actual generating call from yang to clispec for the complete yang spec */
if (yang2cli_yspec(h, yspec, AUTOCLI_TREENAME, printgen) < 0)
- goto done;
+ goto done;
/* XXX Create pre-5.5 tree-refs for backward compatibility */
if (autocli_trees_default(h) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
@@ -412,30 +412,30 @@ usage(clicon_handle h,
char *plgdir = clicon_cli_dir(h);
fprintf(stderr, "usage:%s [options] [commands]\n"
- "where commands is a CLI command or options passed to the main plugin\n"
- "where options are\n"
+ "where commands is a CLI command or options passed to the main plugin\n"
+ "where options are\n"
"\t-h \t\tHelp\n"
- "\t-D \tDebug level\n"
- "\t-f \tConfig-file (mandatory)\n"
- "\t-E \tExtra configuration file directory\n"
- "\t-F \tRead commands from file (default stdin)\n"
- "\t-1\t\tDo not enter interactive mode\n"
- "\t-a UNIX|IPv4|IPv6\tInternal backend socket family\n"
- "\t-u \tInternal socket domain path or IP addr (see -a)\n"
- "\t-d \tSpecify plugin directory (default: %s)\n"
+ "\t-D \tDebug level\n"
+ "\t-f \tConfig-file (mandatory)\n"
+ "\t-E \tExtra configuration file directory\n"
+ "\t-F \tRead commands from file (default stdin)\n"
+ "\t-1\t\tDo not enter interactive mode\n"
+ "\t-a UNIX|IPv4|IPv6\tInternal backend socket family\n"
+ "\t-u \tInternal socket domain path or IP addr (see -a)\n"
+ "\t-d \tSpecify plugin directory (default: %s)\n"
"\t-m \tSpecify plugin syntax mode\n"
- "\t-q \t\tQuiet mode, dont print greetings or prompt, terminate on ctrl-C\n"
- "\t-p \tYang directory path (see CLICON_YANG_DIR)\n"
- "\t-G \t\tPrint auto-cli CLI syntax generated from YANG\n"
- "\t-L \t\tDebug print dynamic CLI syntax including completions and expansions\n"
- "\t-l > \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (stderr is default)\n"
- "\t-y \tOverride yang spec file (dont include .yang suffix)\n"
- "\t-c \tSpecify cli spec file.\n"
- "\t-U \tOver-ride unix user with a pseudo user for NACM.\n"
- "\t-o \"=\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
- argv0,
- plgdir ? plgdir : "none"
- );
+ "\t-q \t\tQuiet mode, dont print greetings or prompt, terminate on ctrl-C\n"
+ "\t-p \tYang directory path (see CLICON_YANG_DIR)\n"
+ "\t-G \t\tPrint auto-cli CLI syntax generated from YANG\n"
+ "\t-L \t\tDebug print dynamic CLI syntax including completions and expansions\n"
+ "\t-l > \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (stderr is default)\n"
+ "\t-y \tOverride yang spec file (dont include .yang suffix)\n"
+ "\t-c \tSpecify cli spec file.\n"
+ "\t-U \tOver-ride unix user with a pseudo user for NACM.\n"
+ "\t-o \"=\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
+ argv0,
+ plgdir ? plgdir : "none"
+ );
exit(1);
}
@@ -448,8 +448,8 @@ main(int argc,
int retval = -1;
int c;
int once;
- char *tmp;
- char *argv0 = argv[0];
+ char *tmp;
+ char *argv0 = argv[0];
clicon_handle h;
int printgen = 0;
int logclisyntax = 0;
@@ -474,17 +474,17 @@ main(int argc,
/* Initiate CLICON handle. CLIgen is also initialized */
if ((h = cli_handle_init()) == NULL)
- goto done;
+ goto done;
/* Set username to clicon handle. Use in all communication to backend
* Note, can be overridden by -U
*/
if ((pw = getpwuid(getuid())) == NULL){
- clicon_err(OE_UNIX, errno, "getpwuid");
- goto done;
+ clicon_err(OE_UNIX, errno, "getpwuid");
+ goto done;
}
if (clicon_username_set(h, pw->pw_name) < 0)
- goto done;
+ goto done;
cligen_comment_set(cli_cligen(h), '#'); /* Default to handle #! clicon_cli scripts */
cligen_lexicalorder_set(cli_cligen(h), 1);
@@ -495,38 +495,38 @@ main(int argc,
optind = 1;
opterr = 0;
while ((c = getopt(argc, argv, CLI_OPTS)) != -1)
- switch (c) {
- case 'h':
- /* Defer the call to usage() to later. Reason is that for helpful
- text messages, default dirs, etc, are not set until later.
- But this means that we need to check if 'help' is set before
- exiting, and then call usage() before exit.
- */
- help = 1;
- break;
- case 'D' : /* debug */
- if (sscanf(optarg, "%d", &dbg) != 1)
- usage(h, argv[0]);
- break;
- case 'f': /* config file */
- if (!strlen(optarg))
- usage(h, argv[0]);
- clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
- break;
- case 'E': /* extra config directory */
- if (!strlen(optarg))
- usage(h, argv[0]);
- clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
- break;
- case 'l': /* Log destination: s|e|o|f */
- if ((logdst = clicon_log_opt(optarg[0])) < 0)
- usage(h, argv[0]);
- if (logdst == CLICON_LOG_FILE &&
- strlen(optarg)>1 &&
- clicon_log_file(optarg+1) < 0)
- goto done;
- break;
- }
+ switch (c) {
+ case 'h':
+ /* Defer the call to usage() to later. Reason is that for helpful
+ text messages, default dirs, etc, are not set until later.
+ But this means that we need to check if 'help' is set before
+ exiting, and then call usage() before exit.
+ */
+ help = 1;
+ break;
+ case 'D' : /* debug */
+ if (sscanf(optarg, "%d", &dbg) != 1)
+ usage(h, argv[0]);
+ break;
+ case 'f': /* config file */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
+ break;
+ case 'E': /* extra config directory */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
+ break;
+ case 'l': /* Log destination: s|e|o|f */
+ if ((logdst = clicon_log_opt(optarg[0])) < 0)
+ usage(h, argv[0]);
+ if (logdst == CLICON_LOG_FILE &&
+ strlen(optarg)>1 &&
+ clicon_log_file(optarg+1) < 0)
+ goto done;
+ break;
+ }
/*
* Logs, error and debug to stderr or syslog, set debug level
*/
@@ -537,94 +537,94 @@ main(int argc,
/* Find, read and parse configfile */
if (clicon_options_main(h) < 0){
if (help)
- usage(h, argv[0]);
- goto done;
+ usage(h, argv[0]);
+ goto done;
}
/* Now rest of options */
opterr = 0;
optind = 1;
while ((c = getopt(argc, argv, CLI_OPTS)) != -1){
- switch (c) {
- case 'D' : /* debug */
- case 'f': /* config file */
- case 'E': /* extra config dir */
- case 'l': /* Log destination */
- break; /* see above */
- case 'F': /* read commands from file */
- if (freopen(optarg, "r", stdin) == NULL){
- fprintf(stderr, "freopen: %s\n", strerror(errno));
- return -1;
- }
- break;
- case '1' : /* Quit after reading database once - dont wait for events */
- once = 1;
- break;
- case 'a': /* internal backend socket address family */
- if (clicon_option_add(h, "CLICON_SOCK_FAMILY", optarg) < 0)
- goto done;
- break;
- case 'u': /* internal backend socket unix domain path or ip host */
- if (!strlen(optarg))
- usage(h, argv[0]);
- if (clicon_option_add(h, "CLICON_SOCK", optarg) < 0)
- goto done;
- break;
- case 'd': /* Plugin directory: overrides configfile */
- if (!strlen(optarg))
- usage(h, argv[0]);
- if (clicon_option_add(h, "CLICON_CLI_DIR", optarg) < 0)
- goto done;
- break;
- case 'm': /* CLI syntax mode */
- if (!strlen(optarg))
- usage(h, argv[0]);
- if (clicon_option_add(h, "CLICON_CLI_MODE", optarg) < 0)
- goto done;
- break;
- case 'q' : /* Quiet mode */
- clicon_quiet_mode_set(h, 1);
- break;
- case 'p' : /* yang dir path */
- if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
- goto done;
- break;
- case 'G' : /* Print generated CLI syntax */
- printgen++;
- break;
- case 'L' : /* Debug print dynamic CLI syntax */
- logclisyntax++;
- break;
- case 'y' : /* Load yang absolute filename */
- if (clicon_option_add(h, "CLICON_YANG_MAIN_FILE", optarg) < 0)
- goto done;
- break;
- case 'c' : /* Overwrite clispec with absolute filename */
- if (clicon_option_add(h, "CLICON_CLISPEC_FILE", optarg) < 0)
- goto done;
- break;
- case 'U': /* Clixon 'pseudo' user */
- if (clicon_username_set(h, optarg) < 0)
- goto done;
- break;
- case 'o':{ /* Configuration option */
- char *val;
- if ((val = index(optarg, '=')) == NULL)
- usage(h, argv0);
- *val++ = '\0';
- if (clicon_option_add(h, optarg, val) < 0)
- goto done;
- break;
- }
- default:
- usage(h, argv[0]);
- break;
- }
+ switch (c) {
+ case 'D' : /* debug */
+ case 'f': /* config file */
+ case 'E': /* extra config dir */
+ case 'l': /* Log destination */
+ break; /* see above */
+ case 'F': /* read commands from file */
+ if (freopen(optarg, "r", stdin) == NULL){
+ fprintf(stderr, "freopen: %s\n", strerror(errno));
+ return -1;
+ }
+ break;
+ case '1' : /* Quit after reading database once - dont wait for events */
+ once = 1;
+ break;
+ case 'a': /* internal backend socket address family */
+ if (clicon_option_add(h, "CLICON_SOCK_FAMILY", optarg) < 0)
+ goto done;
+ break;
+ case 'u': /* internal backend socket unix domain path or ip host */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ if (clicon_option_add(h, "CLICON_SOCK", optarg) < 0)
+ goto done;
+ break;
+ case 'd': /* Plugin directory: overrides configfile */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ if (clicon_option_add(h, "CLICON_CLI_DIR", optarg) < 0)
+ goto done;
+ break;
+ case 'm': /* CLI syntax mode */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ if (clicon_option_add(h, "CLICON_CLI_MODE", optarg) < 0)
+ goto done;
+ break;
+ case 'q' : /* Quiet mode */
+ clicon_quiet_mode_set(h, 1);
+ break;
+ case 'p' : /* yang dir path */
+ if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
+ goto done;
+ break;
+ case 'G' : /* Print generated CLI syntax */
+ printgen++;
+ break;
+ case 'L' : /* Debug print dynamic CLI syntax */
+ logclisyntax++;
+ break;
+ case 'y' : /* Load yang absolute filename */
+ if (clicon_option_add(h, "CLICON_YANG_MAIN_FILE", optarg) < 0)
+ goto done;
+ break;
+ case 'c' : /* Overwrite clispec with absolute filename */
+ if (clicon_option_add(h, "CLICON_CLISPEC_FILE", optarg) < 0)
+ goto done;
+ break;
+ case 'U': /* Clixon 'pseudo' user */
+ if (clicon_username_set(h, optarg) < 0)
+ goto done;
+ break;
+ case 'o':{ /* Configuration option */
+ char *val;
+ if ((val = index(optarg, '=')) == NULL)
+ usage(h, argv0);
+ *val++ = '\0';
+ if (clicon_option_add(h, optarg, val) < 0)
+ goto done;
+ break;
+ }
+ default:
+ usage(h, argv[0]);
+ break;
+ }
}
argc -= optind;
argv += optind;
#ifdef __AFL_HAVE_MANUAL_CONTROL
- __AFL_INIT();
+ __AFL_INIT();
#endif
/* Access the remaining argv/argc options (after --) w clicon-argv_get() */
@@ -632,7 +632,7 @@ main(int argc,
/* Defer: Wait to the last minute to print help message */
if (help)
- usage(h, argv[0]);
+ usage(h, argv[0]);
/* Init cligen buffers */
cligen_buflen = clicon_option_int(h, "CLICON_CLI_BUF_START");
@@ -641,17 +641,17 @@ main(int argc,
/* Init row numbers for raw terminals */
if (clicon_option_exists(h, "CLICON_CLI_LINES_DEFAULT")){
- nr = clicon_option_int(h, "CLICON_CLI_LINES_DEFAULT");
- cligen_terminal_rows_set(cli_cligen(h), nr);
+ nr = clicon_option_int(h, "CLICON_CLI_LINES_DEFAULT");
+ cligen_terminal_rows_set(cli_cligen(h), nr);
}
if (clicon_yang_regexp(h) == REGEXP_LIBXML2){
#ifdef HAVE_LIBXML2
- /* Enable XSD libxml2 regex engine */
- cligen_regex_xsd_set(cli_cligen(h), 1);
+ /* Enable XSD libxml2 regex engine */
+ cligen_regex_xsd_set(cli_cligen(h), 1);
#else
- clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))");
- goto done;
+ clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))");
+ goto done;
#endif
}
@@ -662,11 +662,11 @@ main(int argc,
cligen_helpstring_lines_set(cli_cligen(h), nr);
if ((nr = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
- clicon_log_string_limit_set(nr);
+ clicon_log_string_limit_set(nr);
/* Setup signal handlers */
if (cli_signal_init(h) < 0)
- goto done;
+ goto done;
/* Backward compatible mode, do not include keys in cgv-arrays in callbacks.
Should be 0 but default is 1 since all legacy apps use 1
@@ -676,16 +676,16 @@ main(int argc,
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
- goto done;
+ goto done;
#ifndef CLIXON_STATIC_PLUGINS
{
- char *dir;
- /* Load cli .so plugins before yangs are loaded (eg extension callbacks) and
- * before CLI is loaded by cli_syntax_load below */
- if ((dir = clicon_cli_dir(h)) != NULL &&
- clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
- goto done;
+ char *dir;
+ /* Load cli .so plugins before yangs are loaded (eg extension callbacks) and
+ * before CLI is loaded by cli_syntax_load below */
+ if ((dir = clicon_cli_dir(h)) != NULL &&
+ clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
+ goto done;
}
#endif
@@ -693,90 +693,90 @@ main(int argc,
* Otherwise it is loaded in netconf_module_load below
*/
if (netconf_module_features(h) < 0)
- goto done;
+ goto done;
/* In case ietf-yang-metadata is loaded by application, handle annotation extension */
if (yang_metadata_init(h) < 0)
- goto done;
+ goto done;
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
xml_nsctx_namespace_netconf_default(h);
/* Create top-level and store as option */
if ((yspec = yspec_new()) == NULL)
- goto done;
- clicon_dbspec_yang_set(h, yspec);
+ goto done;
+ clicon_dbspec_yang_set(h, yspec);
/* Load Yang modules
* 1. Load a yang module as a specific absolute filename */
if ((str = clicon_yang_main_file(h)) != NULL){
- if (yang_spec_parse_file(h, str, yspec) < 0)
- goto done;
+ if (yang_spec_parse_file(h, str, yspec) < 0)
+ goto done;
}
/* 2. Load a (single) main module */
if ((str = clicon_yang_module_main(h)) != NULL){
- if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
- yspec) < 0)
- goto done;
+ if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
+ yspec) < 0)
+ goto done;
}
/* 3. Load all modules in a directory */
if ((str = clicon_yang_main_dir(h)) != NULL){
- if (yang_spec_load_dir(h, str, yspec) < 0)
- goto done;
+ if (yang_spec_load_dir(h, str, yspec) < 0)
+ goto done;
}
/* Load clixon lib yang module */
if (yang_spec_parse_module(h, "clixon-lib", NULL, yspec) < 0)
- goto done;
+ goto done;
/* Load yang module library, RFC7895 */
if (yang_modules_init(h) < 0)
- goto done;
+ goto done;
/* Add netconf yang spec, used as internal protocol */
if (netconf_module_load(h) < 0)
- goto done;
+ goto done;
/* Here all modules are loaded
* Compute and set canonical namespace context
*/
if (xml_nsctx_yangspec(yspec, &nsctx_global) < 0)
- goto done;
+ goto done;
if (clicon_nsctx_global_set(h, nsctx_global) < 0)
- goto done;
+ goto done;
/* Create autocli from YANG */
if (autocli_start(h, printgen) < 0)
- goto done;
+ goto done;
/* Initialize cli syntax.
* Plugins have already been loaded by clixon_plugins_load above */
if (cli_syntax_load(h) < 0)
- goto done;
+ goto done;
/* Set syntax mode if specified from command-line or config-file. */
if (clicon_option_exists(h, "CLICON_CLI_MODE"))
- if ((tmp = clicon_cli_mode(h)) != NULL)
- if (cli_set_syntax_mode(h, tmp) == 0) {
- fprintf(stderr, "FATAL: Failed to set syntax mode '%s'\n", tmp);
- goto done;
- }
+ if ((tmp = clicon_cli_mode(h)) != NULL)
+ if (cli_set_syntax_mode(h, tmp) == 0) {
+ fprintf(stderr, "FATAL: Failed to set syntax mode '%s'\n", tmp);
+ goto done;
+ }
if (!cli_syntax_mode(h)){
- fprintf(stderr, "FATAL: No cli mode set (use -m or CLICON_CLI_MODE)\n");
- goto done;
+ fprintf(stderr, "FATAL: No cli mode set (use -m or CLICON_CLI_MODE)\n");
+ goto done;
}
if (cligen_ph_find(cli_cligen(h), cli_syntax_mode(h)) == NULL)
- clicon_log(LOG_WARNING, "No such cli mode: %s (Specify cli mode with CLICON_CLI_MODE in config file or -m on command line", cli_syntax_mode(h));
+ clicon_log(LOG_WARNING, "No such cli mode: %s (Specify cli mode with CLICON_CLI_MODE in config file or -m on command line", cli_syntax_mode(h));
/* CLIgen tab mode, ie how s behave */
if ((tabmode = clicon_cli_tab_mode(h)) < 0){
- fprintf(stderr, "FATAL: CLICON_CLI_TAB_MODE not set\n");
- goto done;
+ fprintf(stderr, "FATAL: CLICON_CLI_TAB_MODE not set\n");
+ goto done;
}
cligen_tabmode_set(cli_cligen(h), tabmode);
if (logclisyntax)
- cli_logsyntax_set(h, logclisyntax);
+ cli_logsyntax_set(h, logclisyntax);
if (dbg)
- clicon_option_dump(h, dbg);
+ clicon_option_dump(h, dbg);
/* Join rest of argv to a single command */
restarg = clicon_strjoin(argc, argv, " ");
@@ -793,42 +793,42 @@ main(int argc,
/* Call start function in all plugins before we go interactive
*/
if (clixon_plugin_start_all(h) < 0)
- goto done;
+ goto done;
cligen_line_scrolling_set(cli_cligen(h), clicon_option_int(h,"CLICON_CLI_LINESCROLLING"));
/*! Start CLI history and load from file */
if (cli_history_load(h) < 0)
- goto done;
+ goto done;
/* Experimental utf8 mode */
cligen_utf8_set(cli_cligen(h), clicon_option_int(h,"CLICON_CLI_UTF8"));
/* Launch interfactive event loop, unless -1 */
if (restarg != NULL && strlen(restarg)){
- char *mode = cli_syntax_mode(h);
- cligen_result result; /* match result */
- int evalresult = 0; /* if result == 1, calback result */
+ char *mode = cli_syntax_mode(h);
+ cligen_result result; /* match result */
+ int evalresult = 0; /* if result == 1, calback result */
- if (clicon_parse(h, restarg, &mode, &result, &evalresult) < 0)
- goto done;
- if (result != 1) /* Not unique match */
- goto done;
- if (evalresult < 0)
- goto done;
+ if (clicon_parse(h, restarg, &mode, &result, &evalresult) < 0)
+ goto done;
+ if (result != 1) /* Not unique match */
+ goto done;
+ if (evalresult < 0)
+ goto done;
}
/* Go into event-loop unless -1 command-line */
if (!once){
- retval = cli_interactive(h);
+ retval = cli_interactive(h);
}
else
- retval = 0;
+ retval = 0;
done:
if (restarg)
- free(restarg);
+ free(restarg);
// Gets in your face if we log on stderr
clicon_log_init(__PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */
clicon_log(LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid());
if (h)
- cli_terminate(h);
+ cli_terminate(h);
return retval;
}
diff --git a/apps/cli/cli_plugin.c b/apps/cli/cli_plugin.c
index 30f16b40..eed2884e 100644
--- a/apps/cli/cli_plugin.c
+++ b/apps/cli/cli_plugin.c
@@ -72,7 +72,7 @@
/*
* Constants
*/
-#define CLI_DEFAULT_PROMPT "cli> "
+#define CLI_DEFAULT_PROMPT "cli> "
/*
*
@@ -84,22 +84,22 @@
*/
static cli_syntaxmode_t *
syntax_mode_find(cli_syntax_t *stx,
- const char *mode,
- int create)
+ const char *mode,
+ int create)
{
cli_syntaxmode_t *csm;
csm = stx->stx_modes;
if (csm) {
- do {
- if (strcmp(csm->csm_name, mode) == 0)
- return csm;
- csm = NEXTQ(cli_syntaxmode_t *, csm);
- } while (csm && csm != stx->stx_modes);
+ do {
+ if (strcmp(csm->csm_name, mode) == 0)
+ return csm;
+ csm = NEXTQ(cli_syntaxmode_t *, csm);
+ } while (csm && csm != stx->stx_modes);
}
if (create == 0)
- return NULL;
+ return NULL;
if ((csm = malloc(sizeof(cli_syntaxmode_t))) == NULL) {
clicon_err(OE_UNIX, errno, "malloc");
@@ -107,16 +107,16 @@ syntax_mode_find(cli_syntax_t *stx,
}
memset(csm, 0, sizeof(*csm));
if ((csm->csm_name = strdup(mode)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- return NULL;
+ clicon_err(OE_UNIX, errno, "strdup");
+ return NULL;
}
if ((csm->csm_prompt = strdup(CLI_DEFAULT_PROMPT)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- return NULL;
+ clicon_err(OE_UNIX, errno, "strdup");
+ return NULL;
}
if ((csm->csm_pt = pt_new()) == NULL){
- clicon_err(OE_UNIX, errno, "pt_new");
- return NULL;
+ clicon_err(OE_UNIX, errno, "pt_new");
+ return NULL;
}
INSQ(csm, stx->stx_modes);
stx->stx_nmodes++;
@@ -130,15 +130,15 @@ syntax_mode_find(cli_syntax_t *stx,
*/
static int
gen_parse_tree(clicon_handle h,
- cli_syntaxmode_t *m)
+ cli_syntaxmode_t *m)
{
int retval = -1;
pt_head *ph;
if ((ph = cligen_ph_add(cli_cligen(h), m->csm_name)) == NULL)
- goto done;
+ goto done;
if (cligen_ph_parsetree_set(ph, m->csm_pt) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -149,17 +149,17 @@ gen_parse_tree(clicon_handle h,
*/
static int
syntax_append(clicon_handle h,
- cli_syntax_t *stx,
- const char *name,
- parse_tree *pt)
+ cli_syntax_t *stx,
+ const char *name,
+ parse_tree *pt)
{
cli_syntaxmode_t *csm;
if ((csm = syntax_mode_find(stx, name, 1)) == NULL)
- return -1;
+ return -1;
if (cligen_parsetree_merge(csm->csm_pt, NULL, pt) < 0){
- clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
- return -1;
+ clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
+ return -1;
}
return 0;
}
@@ -174,19 +174,19 @@ cli_syntax_unload(clicon_handle h)
cli_syntaxmode_t *csm;
if (stx == NULL)
- return 0;
+ return 0;
while (stx->stx_nmodes > 0) {
- csm = stx->stx_modes;
- DELQ(csm, stx->stx_modes, cli_syntaxmode_t *);
- if (csm){
- if (csm->csm_name)
- free(csm->csm_name);
- if (csm->csm_prompt)
- free(csm->csm_prompt);
- free(csm);
- }
- stx->stx_nmodes--;
+ csm = stx->stx_modes;
+ DELQ(csm, stx->stx_modes, cli_syntaxmode_t *);
+ if (csm){
+ if (csm->csm_name)
+ free(csm->csm_name);
+ if (csm->csm_prompt)
+ free(csm->csm_prompt);
+ free(csm);
+ }
+ stx->stx_nmodes--;
}
return 0;
}
@@ -208,37 +208,37 @@ cli_syntax_unload(clicon_handle h)
*/
void *
clixon_str2fn(char *name,
- void *handle,
- char **error)
+ void *handle,
+ char **error)
{
void *fn = NULL;
-
+
/* Reset error */
*error = NULL;
/* Special check for auto-cli. If the virtual callback is used, it should be overwritten later
* by a callback given in the clispec, eg: set @datamodel, cli_set();
*/
if (strcmp(name, GENERATE_CALLBACK) == 0)
- return NULL;
+ return NULL;
/* First check given plugin if any */
if (handle) {
- dlerror(); /* Clear any existing error */
- fn = dlsym(handle, name);
- if ((*error = (char*)dlerror()) == NULL)
- return fn; /* If no error we found the address of the callback */
+ dlerror(); /* Clear any existing error */
+ fn = dlsym(handle, name);
+ if ((*error = (char*)dlerror()) == NULL)
+ return fn; /* If no error we found the address of the callback */
}
/* Now check global namespace which includes any shared object loaded
* into the global namespace. I.e. all lib*.so as well as the
* master plugin if it exists
*/
- dlerror(); /* Clear any existing error */
+ dlerror(); /* Clear any existing error */
/* RTLD_DEFAULT instead of NULL for linux + FreeBSD:
* Use default search algorithm. Thanks jdl@netgate.com */
fn = dlsym(RTLD_DEFAULT, name);
if ((*error = (char*)dlerror()) == NULL)
- return fn; /* If no error we found the address of the callback */
+ return fn; /* If no error we found the address of the callback */
/* Return value not really relevant here as the error string is set to
* signal an error. However, just checking the function pointer for NULL
@@ -254,16 +254,16 @@ clixon_str2fn(char *name,
* Make a lookup of plugins already loaded and resolve callbacks from cligen trees to
* dl symbols in the plugin.
* @param[in] h Clixon handle
- * @param[in] filename Name of file where syntax is specified (in syntax-group dir)
- * @param[in] dir Name of dir, or NULL
+ * @param[in] filename Name of file where syntax is specified (in syntax-group dir)
+ * @param[in] dir Name of dir, or NULL
* @param[out] ptall Universal CLIgen parse tree: apply to all modes
* @see clixon_plugins_load Where .so plugin code has been loaded prior to this
*/
static int
cli_load_syntax_file(clicon_handle h,
- const char *filename,
- const char *dir,
- parse_tree *ptall)
+ const char *filename,
+ const char *dir,
+ parse_tree *ptall)
{
void *handle = NULL; /* Handle to plugin .so module */
char *mode = NULL; /* Name of syntax mode to append new syntax */
@@ -281,28 +281,28 @@ cli_load_syntax_file(clicon_handle h,
#endif
if ((pt = pt_new()) == NULL){
- clicon_err(OE_UNIX, errno, "pt_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "pt_new");
+ goto done;
}
if (dir)
- snprintf(filepath, MAXPATHLEN-1, "%s/%s", dir, filename);
+ snprintf(filepath, MAXPATHLEN-1, "%s/%s", dir, filename);
else
- snprintf(filepath, MAXPATHLEN-1, "%s", filename);
+ snprintf(filepath, MAXPATHLEN-1, "%s", filename);
if ((cvv = cvec_new(0)) == NULL){
- clicon_err(OE_PLUGIN, errno, "cvec_new");
- goto done;
+ clicon_err(OE_PLUGIN, errno, "cvec_new");
+ goto done;
}
/* Build parse tree from syntax spec. */
if ((f = fopen(filepath, "r")) == NULL){
- clicon_err(OE_PLUGIN, errno, "fopen %s", filepath);
- goto done;
+ clicon_err(OE_PLUGIN, errno, "fopen %s", filepath);
+ goto done;
}
/* Assuming this plugin is first in queue */
if (cli_parse_file(h, f, filepath, pt, cvv) < 0){
- clicon_err(OE_PLUGIN, 0, "failed to parse cli file %s", filepath);
- fclose(f);
- goto done;
+ clicon_err(OE_PLUGIN, 0, "failed to parse cli file %s", filepath);
+ fclose(f);
+ goto done;
}
fclose(f);
/* Get CLICON specific global variables:
@@ -320,70 +320,70 @@ cli_load_syntax_file(clicon_handle h,
#ifndef CLIXON_STATIC_PLUGINS
if (plgnam != NULL) { /* Find plugin for callback resolving */
- if ((cp = clixon_plugin_find(h, plgnam)) != NULL)
- handle = clixon_plugin_handle_get(cp);
- if (handle == NULL){
- clicon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s",
- plgnam, filename, plgnam,
- clicon_cli_dir(h));
- goto done;
- }
+ if ((cp = clixon_plugin_find(h, plgnam)) != NULL)
+ handle = clixon_plugin_handle_get(cp);
+ if (handle == NULL){
+ clicon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s",
+ plgnam, filename, plgnam,
+ clicon_cli_dir(h));
+ goto done;
+ }
}
#endif
/* Resolve callback names to function pointers. */
if (cligen_callbackv_str2fn(pt, (cgv_str2fn_t*)clixon_str2fn, handle) < 0){
- clicon_err(OE_PLUGIN, 0, "Mismatch between CLIgen file '%s' and CLI plugin file '%s'. Some possible errors:\n\t1. A function given in the CLIgen file does not exist in the plugin (ie link error)\n\t2. The CLIgen spec does not point to the correct plugin .so file (CLICON_PLUGIN=\"%s\" is wrong)",
- filename, plgnam, plgnam);
- goto done;
+ clicon_err(OE_PLUGIN, 0, "Mismatch between CLIgen file '%s' and CLI plugin file '%s'. Some possible errors:\n\t1. A function given in the CLIgen file does not exist in the plugin (ie link error)\n\t2. The CLIgen spec does not point to the correct plugin .so file (CLICON_PLUGIN=\"%s\" is wrong)",
+ filename, plgnam, plgnam);
+ goto done;
}
if (cligen_expandv_str2fn(pt, (expandv_str2fn_t*)clixon_str2fn, handle) < 0)
- goto done;
+ goto done;
/* Variable translation functions */
if (cligen_translate_str2fn(pt, (translate_str2fn_t*)clixon_str2fn, handle) < 0)
- goto done;
+ goto done;
/* Make sure we have a syntax mode specified */
if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
- mode = clicon_cli_mode(h);
- if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
- clicon_err(OE_PLUGIN, 0, "No syntax mode specified in %s", filepath);
- goto done;
- }
+ mode = clicon_cli_mode(h);
+ if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
+ clicon_err(OE_PLUGIN, 0, "No syntax mode specified in %s", filepath);
+ goto done;
+ }
}
/* Find all modes in CLICON_MODE string: where to append the pt syntax tree */
if ((vec = clicon_strsep(mode, ":", &nvec)) == NULL)
- goto done;
+ goto done;
if (nvec == 1 && strcmp(vec[0], "*") == 0){
- /* Special case: Add this to all modes. Add to special "universal" syntax
- * and add to all syntaxes after all files have been loaded. At this point
- * all modes may not be known (not yet loaded)
- */
- if (cligen_parsetree_merge(ptall, NULL, pt) < 0){
- clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
- goto done;
- }
+ /* Special case: Add this to all modes. Add to special "universal" syntax
+ * and add to all syntaxes after all files have been loaded. At this point
+ * all modes may not be known (not yet loaded)
+ */
+ if (cligen_parsetree_merge(ptall, NULL, pt) < 0){
+ clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
+ goto done;
+ }
}
else {
- for (i = 0; i < nvec; i++) {
- if (syntax_append(h,
- cli_syntax(h),
- vec[i],
- pt) < 0) {
- goto done;
- }
- if (prompt)
- cli_set_prompt(h, vec[i], prompt);
- }
+ for (i = 0; i < nvec; i++) {
+ if (syntax_append(h,
+ cli_syntax(h),
+ vec[i],
+ pt) < 0) {
+ goto done;
+ }
+ if (prompt)
+ cli_set_prompt(h, vec[i], prompt);
+ }
}
cligen_parsetree_free(pt, 1);
retval = 0;
done:
if (cvv)
- cvec_free(cvv);
+ cvec_free(cvv);
if (vec)
- free(vec);
+ free(vec);
return retval;
}
@@ -412,10 +412,10 @@ cli_syntax_load(clicon_handle h)
/* Syntax already loaded. XXX should we re-load?? */
if ((stx = cli_syntax(h)) != NULL)
- return 0;
+ return 0;
if ((ptall = pt_new()) == NULL){
- clicon_err(OE_UNIX, errno, "pt_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "pt_new");
+ goto done;
}
/* Format plugin directory path */
@@ -424,36 +424,36 @@ cli_syntax_load(clicon_handle h)
/* Allocate plugin group object */
if ((stx = malloc(sizeof(*stx))) == NULL) {
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
- memset(stx, 0, sizeof(*stx)); /* Zero out all */
+ memset(stx, 0, sizeof(*stx)); /* Zero out all */
cli_syntax_set(h, stx);
/* Load single specific clispec file */
if (clispec_file){
- if (cli_load_syntax_file(h, clispec_file, NULL, ptall) < 0)
- goto done;
+ if (cli_load_syntax_file(h, clispec_file, NULL, ptall) < 0)
+ goto done;
}
/* Load all clispec .cli files in directory */
if (clispec_dir){
- /* Get directory list of files */
- if ((ndp = clicon_file_dirent(clispec_dir, &dp, "(.cli)$", S_IFREG)) < 0)
- goto done;
- /* Load the syntax parse trees into cli_syntax stx structure */
- for (i = 0; i < ndp; i++) {
- clicon_debug(1, "DEBUG: Loading syntax '%.*s'",
- (int)strlen(dp[i].d_name)-4, dp[i].d_name);
- if (cli_load_syntax_file(h, dp[i].d_name, clispec_dir, ptall) < 0)
- goto done;
- }
+ /* Get directory list of files */
+ if ((ndp = clicon_file_dirent(clispec_dir, &dp, "(.cli)$", S_IFREG)) < 0)
+ goto done;
+ /* Load the syntax parse trees into cli_syntax stx structure */
+ for (i = 0; i < ndp; i++) {
+ clicon_debug(1, "DEBUG: Loading syntax '%.*s'",
+ (int)strlen(dp[i].d_name)-4, dp[i].d_name);
+ if (cli_load_syntax_file(h, dp[i].d_name, clispec_dir, ptall) < 0)
+ goto done;
+ }
}
/* Were any syntax modes successfully loaded? If not, leave */
if (stx->stx_nmodes <= 0) {
- retval = 0;
- goto done;
- }
+ retval = 0;
+ goto done;
+ }
/* Go thorugh all modes and :
* 1) Add the universal syntax
@@ -461,36 +461,36 @@ cli_syntax_load(clicon_handle h)
*/
m = stx->stx_modes;
do {
- if (cligen_parsetree_merge(m->csm_pt, NULL, ptall) < 0){
- clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
- goto done;
- }
- if (gen_parse_tree(h, m) != 0)
- goto done;
- m = NEXTQ(cli_syntaxmode_t *, m);
+ if (cligen_parsetree_merge(m->csm_pt, NULL, ptall) < 0){
+ clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
+ goto done;
+ }
+ if (gen_parse_tree(h, m) != 0)
+ goto done;
+ m = NEXTQ(cli_syntaxmode_t *, m);
} while (m && m != stx->stx_modes);
/* Set susp and interrupt callbacks into CLIgen */
cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
- if (fns==NULL && (fns = clixon_plugin_api_get(cp)->ca_suspend) != NULL)
- if (cli_susp_hook(h, fns) < 0)
- goto done;
- if (fni==NULL && (fni = clixon_plugin_api_get(cp)->ca_interrupt) != NULL)
- if (cli_interrupt_hook(h, fni) < 0)
- goto done;
+ if (fns==NULL && (fns = clixon_plugin_api_get(cp)->ca_suspend) != NULL)
+ if (cli_susp_hook(h, fns) < 0)
+ goto done;
+ if (fni==NULL && (fni = clixon_plugin_api_get(cp)->ca_interrupt) != NULL)
+ if (cli_interrupt_hook(h, fni) < 0)
+ goto done;
}
/* All good. We can now proudly return a new group */
retval = 0;
done:
if (retval != 0) {
- cli_syntax_unload(h);
- cli_syntax_set(h, NULL);
+ cli_syntax_unload(h);
+ cli_syntax_set(h, NULL);
}
cligen_parsetree_free(ptall, 1);
if (dp)
- free(dp);
+ free(dp);
return retval;
}
@@ -517,14 +517,14 @@ int
cli_handler_err(FILE *f)
{
if (clicon_errno &&
- (clicon_get_logflags() & CLICON_LOG_STDERR) == 0){
- fprintf(f, "%s: %s", clicon_strerror(clicon_errno), clicon_err_reason);
- if (clicon_suberrno)
- fprintf(f, ": %s", strerror(clicon_suberrno));
- fprintf(f, "\n");
+ (clicon_get_logflags() & CLICON_LOG_STDERR) == 0){
+ fprintf(f, "%s: %s", clicon_strerror(clicon_errno), clicon_err_reason);
+ if (clicon_suberrno)
+ fprintf(f, ": %s", strerror(clicon_suberrno));
+ fprintf(f, "\n");
}
else
- fprintf(f, "CLI command error\n");
+ fprintf(f, "CLI command error\n");
return 0;
}
@@ -537,7 +537,7 @@ cli_handler_err(FILE *f)
* the new mode string.
*
* @param[in] h Clicon handle
- * @param[in] cmd Command string
+ * @param[in] cmd Command string
* @param[in,out] modenamep Pointer to the mode string pointer
* @param[out] result CLIgen match result, < 0: errors, >=0 number of matches
* @param[out] evalres Evaluation result if result=1
@@ -546,10 +546,10 @@ cli_handler_err(FILE *f)
*/
int
clicon_parse(clicon_handle h,
- char *cmd,
- char **modenamep,
- cligen_result *result,
- int *evalres)
+ char *cmd,
+ char **modenamep,
+ cligen_result *result,
+ int *evalres)
{
int retval = -1;
char *modename;
@@ -566,79 +566,79 @@ clicon_parse(clicon_handle h,
ch = cli_cligen(h);
if (clicon_get_logflags()&CLICON_LOG_STDOUT)
- f = stdout;
+ f = stdout;
else
- f = stderr;
+ f = stderr;
stx = cli_syntax(h);
if ((modename = *modenamep) == NULL) {
- csm = stx->stx_active_mode;
- modename = csm->csm_name;
+ csm = stx->stx_active_mode;
+ modename = csm->csm_name;
}
else {
- if ((csm = syntax_mode_find(stx, modename, 0)) == NULL) {
- fprintf(f, "Can't find syntax mode '%s'\n", modename);
- goto done;
- }
+ if ((csm = syntax_mode_find(stx, modename, 0)) == NULL) {
+ fprintf(f, "Can't find syntax mode '%s'\n", modename);
+ goto done;
+ }
}
if (csm != NULL){
- if (cligen_ph_active_set_byname(ch, modename) < 0){
- fprintf(stderr, "No such parse-tree registered: %s\n", modename);
- goto done;
- }
- if ((pt = cligen_pt_active_get(ch)) == NULL){
- fprintf(stderr, "No such parse-tree registered: %s\n", modename);
- goto done;
- }
- if (cliread_parse(ch, cmd, pt, &match_obj, &cvv, &callbacks, result, &reason) < 0)
- goto done;
- /* Debug command and result code */
- clicon_debug(1, "%s result:%d command: \"%s\"", __FUNCTION__, *result, cmd);
- switch (*result) {
- case CG_EOF: /* eof */
- case CG_ERROR:
- fprintf(f, "CLI parse error: %s\n", cmd);
- break;
- case CG_NOMATCH: /* no match */
- fprintf(f, "CLI syntax error: \"%s\": %s\n", cmd, reason);
- break;
- case CG_MATCH:
- if (strcmp(modename, *modenamep)){ /* Command in different mode */
- *modenamep = modename;
- cli_set_syntax_mode(h, modename);
- }
- cli_output_reset();
- if (!cligen_exiting(ch)) {
- clicon_err_reset();
- if ((ret = cligen_eval(ch, match_obj, cvv, callbacks)) < 0) {
- cli_handler_err(stdout);
- if (clicon_suberrno == ESHUTDOWN)
- goto done;
- }
- }
- else
- ret = 0;
- if (evalres)
- *evalres = ret;
- break;
- default:
- fprintf(f, "CLI syntax error: \"%s\" is ambiguous\n", cmd);
- break;
- } /* switch result */
- if (cvv){
- cvec_free(cvv);
- cvv = NULL;
- }
+ if (cligen_ph_active_set_byname(ch, modename) < 0){
+ fprintf(stderr, "No such parse-tree registered: %s\n", modename);
+ goto done;
+ }
+ if ((pt = cligen_pt_active_get(ch)) == NULL){
+ fprintf(stderr, "No such parse-tree registered: %s\n", modename);
+ goto done;
+ }
+ if (cliread_parse(ch, cmd, pt, &match_obj, &cvv, &callbacks, result, &reason) < 0)
+ goto done;
+ /* Debug command and result code */
+ clicon_debug(1, "%s result:%d command: \"%s\"", __FUNCTION__, *result, cmd);
+ switch (*result) {
+ case CG_EOF: /* eof */
+ case CG_ERROR:
+ fprintf(f, "CLI parse error: %s\n", cmd);
+ break;
+ case CG_NOMATCH: /* no match */
+ fprintf(f, "CLI syntax error: \"%s\": %s\n", cmd, reason);
+ break;
+ case CG_MATCH:
+ if (strcmp(modename, *modenamep)){ /* Command in different mode */
+ *modenamep = modename;
+ cli_set_syntax_mode(h, modename);
+ }
+ cli_output_reset();
+ if (!cligen_exiting(ch)) {
+ clicon_err_reset();
+ if ((ret = cligen_eval(ch, match_obj, cvv, callbacks)) < 0) {
+ cli_handler_err(stdout);
+ if (clicon_suberrno == ESHUTDOWN)
+ goto done;
+ }
+ }
+ else
+ ret = 0;
+ if (evalres)
+ *evalres = ret;
+ break;
+ default:
+ fprintf(f, "CLI syntax error: \"%s\" is ambiguous\n", cmd);
+ break;
+ } /* switch result */
+ if (cvv){
+ cvec_free(cvv);
+ cvv = NULL;
+ }
}
retval = 0;
done:
if (callbacks)
- co_callbacks_free(&callbacks);
+ co_callbacks_free(&callbacks);
if (reason)
- free(reason);
+ free(reason);
if (cvv)
- cvec_free(cvv);
+ cvec_free(cvv);
if (match_obj)
- co_free(match_obj, 0);
+ co_free(match_obj, 0);
return retval;
}
@@ -650,7 +650,7 @@ done:
*/
static char *
cli_prompt_get(clicon_handle h,
- char *fmt)
+ char *fmt)
{
char *s = fmt;
char hname[1024];
@@ -662,79 +662,79 @@ cli_prompt_get(clicon_handle h,
char *str0;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
/* Start with empty string */
while(*s) {
- if (*s == '%' && *++s) {
- switch(*s) {
- case 'H': /* Hostname */
- if (gethostname(hname, sizeof(hname)) != 0)
- strncpy(hname, "unknown", sizeof(hname)-1);
- cprintf(cb, "%s", hname);
- break;
- case 'U': /* Username */
- tmp = getenv("USER");
- cprintf(cb, "%s", tmp?tmp:"nobody");
- break;
- case 'T': /* TTY */
- if(ttyname_r(fileno(stdin), tty, sizeof(tty)-1) < 0)
- strcpy(tty, "notty");
- cprintf(cb, "%s", tty);
- break;
- case 'W': /* Last element of working path */
- if (clicon_data_get(h, "cli-edit-mode", &path) == 0 &&
- strlen(path)){
- int i;
+ if (*s == '%' && *++s) {
+ switch(*s) {
+ case 'H': /* Hostname */
+ if (gethostname(hname, sizeof(hname)) != 0)
+ strncpy(hname, "unknown", sizeof(hname)-1);
+ cprintf(cb, "%s", hname);
+ break;
+ case 'U': /* Username */
+ tmp = getenv("USER");
+ cprintf(cb, "%s", tmp?tmp:"nobody");
+ break;
+ case 'T': /* TTY */
+ if(ttyname_r(fileno(stdin), tty, sizeof(tty)-1) < 0)
+ strcpy(tty, "notty");
+ cprintf(cb, "%s", tty);
+ break;
+ case 'W': /* Last element of working path */
+ if (clicon_data_get(h, "cli-edit-mode", &path) == 0 &&
+ strlen(path)){
+ int i;
- for (i=strlen(path)-1; i>=0; i--)
- if (path[i] == '/' || path[i] == ':')
- /* see yang2api_path_fmt_1() why occasional trailing / */
- if (i < strlen(path)-1)
- break;
- if (i >= 0)
- cprintf(cb, "%s", &path[i+1]);
- else
- cprintf(cb, "%s", path);
- }
- else
- cprintf(cb, "/");
- break;
- case 'w': /* Full Working edit path */
- if (clicon_data_get(h, "cli-edit-mode", &path) == 0 &&
- strlen(path))
- cprintf(cb, "%s", path);
- else
- cprintf(cb, "/");
- break;
- default:
- cprintf(cb, "%%");
- cprintf(cb, "%c", *s);
- }
- }
- else if (*s == '\\' && *++s) {
- switch(*s) {
- case 'n':
- cprintf(cb, "\n");
- break;
- default:
- cprintf(cb, "\\");
- cprintf(cb, "%c", *s);
- }
- }
- else
- cprintf(cb, "%c", *s);
- s++;
+ for (i=strlen(path)-1; i>=0; i--)
+ if (path[i] == '/' || path[i] == ':')
+ /* see yang2api_path_fmt_1() why occasional trailing / */
+ if (i < strlen(path)-1)
+ break;
+ if (i >= 0)
+ cprintf(cb, "%s", &path[i+1]);
+ else
+ cprintf(cb, "%s", path);
+ }
+ else
+ cprintf(cb, "/");
+ break;
+ case 'w': /* Full Working edit path */
+ if (clicon_data_get(h, "cli-edit-mode", &path) == 0 &&
+ strlen(path))
+ cprintf(cb, "%s", path);
+ else
+ cprintf(cb, "/");
+ break;
+ default:
+ cprintf(cb, "%%");
+ cprintf(cb, "%c", *s);
+ }
+ }
+ else if (*s == '\\' && *++s) {
+ switch(*s) {
+ case 'n':
+ cprintf(cb, "\n");
+ break;
+ default:
+ cprintf(cb, "\\");
+ cprintf(cb, "%c", *s);
+ }
+ }
+ else
+ cprintf(cb, "%c", *s);
+ s++;
}
str0 = cbuf_len(cb) ? cbuf_get(cb) : CLI_DEFAULT_PROMPT;
if ((promptstr = strdup(str0)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return promptstr;
}
@@ -746,7 +746,7 @@ cli_prompt_get(clicon_handle h,
*/
int
clicon_cliread(clicon_handle h,
- char **stringp)
+ char **stringp)
{
int retval = -1;
char *pfmt = NULL;
@@ -761,29 +761,29 @@ clicon_cliread(clicon_handle h,
/* Get prompt from plugin callback? */
cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
- if ((fn = clixon_plugin_api_get(cp)->ca_prompt) == NULL)
- continue;
- pfmt = fn(h, mode->csm_name);
- break;
+ if ((fn = clixon_plugin_api_get(cp)->ca_prompt) == NULL)
+ continue;
+ pfmt = fn(h, mode->csm_name);
+ break;
}
if (clicon_quiet_mode(h))
- cli_prompt_set(h, "");
+ cli_prompt_set(h, "");
else{
- if ((promptstr = cli_prompt_get(h, pfmt ? pfmt : mode->csm_prompt)) == NULL)
- goto done;
- cli_prompt_set(h, promptstr);
- free(promptstr);
+ if ((promptstr = cli_prompt_get(h, pfmt ? pfmt : mode->csm_prompt)) == NULL)
+ goto done;
+ cli_prompt_set(h, promptstr);
+ free(promptstr);
}
cligen_ph_active_set_byname(cli_cligen(h), mode->csm_name);
if (cliread(cli_cligen(h), stringp) < 0){
- clicon_err(OE_FATAL, errno, "CLIgen");
- goto done;
+ clicon_err(OE_FATAL, errno, "CLIgen");
+ goto done;
}
retval = 0;
done:
if (pfmt)
- free(pfmt);
+ free(pfmt);
return retval;
}
@@ -798,12 +798,12 @@ clicon_cliread(clicon_handle h,
*/
int
cli_set_syntax_mode(clicon_handle h,
- const char *name)
+ const char *name)
{
cli_syntaxmode_t *mode;
if ((mode = syntax_mode_find(cli_syntax(h), name, 1)) == NULL)
- return 0;
+ return 0;
cli_syntax(h)->stx_active_mode = mode;
return 1;
@@ -818,7 +818,7 @@ cli_syntax_mode(clicon_handle h)
cli_syntaxmode_t *csm;
if ((csm = cli_syntax(h)->stx_active_mode) == NULL)
- return NULL;
+ return NULL;
return csm->csm_name;
}
@@ -831,21 +831,21 @@ cli_syntax_mode(clicon_handle h)
*/
int
cli_set_prompt(clicon_handle h,
- const char *name,
- const char *prompt)
+ const char *name,
+ const char *prompt)
{
cli_syntaxmode_t *csm;
if ((csm = syntax_mode_find(cli_syntax(h), name, 1)) == NULL)
- return -1;
+ return -1;
if (csm->csm_prompt != NULL){
- free(csm->csm_prompt);
- csm->csm_prompt = NULL;
+ free(csm->csm_prompt);
+ csm->csm_prompt = NULL;
}
if ((csm->csm_prompt = strdup(prompt)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- return -1;
+ clicon_err(OE_UNIX, errno, "strdup");
+ return -1;
}
return 0;
}
diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c
index 4004ab3f..d3187123 100644
--- a/apps/cli/cli_show.c
+++ b/apps/cli/cli_show.c
@@ -90,9 +90,9 @@ traverse_canonical
*/
static int
xpath_append(cbuf *cb0,
- char *xpath1,
- yang_stmt *y,
- cvec *nsc)
+ char *xpath1,
+ yang_stmt *y,
+ cvec *nsc)
{
int retval = -1;
char **vec = NULL;
@@ -106,62 +106,62 @@ xpath_append(cbuf *cb0,
char *xpath0;
if (cb0 == NULL){
- clicon_err(OE_XML, EINVAL, "cb0 is NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "cb0 is NULL");
+ goto done;
}
if (xpath1 == NULL || strlen(xpath1)==0)
- goto ok;
+ goto ok;
if ((myprefix = yang_find_myprefix(y)) == NULL)
- goto done;
+ goto done;
if ((vec = clicon_strsep(xpath1, "/", &nvec)) == NULL)
- goto done;
+ goto done;
if (xpath1[0] == '/')
- cbuf_reset(cb0);
+ cbuf_reset(cb0);
xpath0 = cbuf_get(cb0);
for (i=0; i= 0; j--){
- if (xpath0[j] != '/')
- continue;
- cbuf_trunc(cb0, j);
- break;
- }
- }
- else{
- initialups = 0;
- cprintf(cb0, "/%s", id);
- }
- }
- else{
- initialups = 0;
- cprintf(cb0, "/%s:%s", prefix?prefix:myprefix, id);
- }
- if (prefix){
- free(prefix);
- prefix = NULL;
- }
- if (id){
- free(id);
- id = NULL;
- }
+ v = vec[i];
+ if (strlen(v) == 0)
+ continue;
+ if (nodeid_split(v, &prefix, &id) < 0)
+ goto done;
+ if (strcmp(id, ".") == 0)
+ initialups = 0;
+ else if (strcmp(id, "..") == 0){
+ if (initialups){
+ /* Subtract from xpath0 */
+ int j;
+ for (j=cbuf_len(cb0); j >= 0; j--){
+ if (xpath0[j] != '/')
+ continue;
+ cbuf_trunc(cb0, j);
+ break;
+ }
+ }
+ else{
+ initialups = 0;
+ cprintf(cb0, "/%s", id);
+ }
+ }
+ else{
+ initialups = 0;
+ cprintf(cb0, "/%s:%s", prefix?prefix:myprefix, id);
+ }
+ if (prefix){
+ free(prefix);
+ prefix = NULL;
+ }
+ if (id){
+ free(id);
+ id = NULL;
+ }
}
ok:
retval = 0;
done:
if (prefix)
- free(prefix);
+ free(prefix);
if (id)
- free(id);
+ free(id);
free(vec);
return retval;
}
@@ -182,11 +182,11 @@ xpath_append(cbuf *cb0,
*/
int
expand_dbvar(void *h,
- char *name,
- cvec *cvv,
- cvec *argv,
- cvec *commands,
- cvec *helptexts)
+ char *name,
+ cvec *cvv,
+ cvec *argv,
+ cvec *commands,
+ cvec *helptexts)
{
int retval = -1;
char *api_path_fmt;
@@ -216,27 +216,27 @@ expand_dbvar(void *h,
yang_stmt *ytype;
if (argv == NULL || cvec_len(argv) != 2){
- clicon_err(OE_PLUGIN, EINVAL, "requires arguments: ");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "requires arguments: ");
+ goto done;
}
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
if ((cv = cvec_i(argv, 0)) == NULL){
- clicon_err(OE_PLUGIN, 0, "Error when accessing argument ");
- goto done;
+ clicon_err(OE_PLUGIN, 0, "Error when accessing argument ");
+ goto done;
}
dbstr = cv_string_get(cv);
if (strcmp(dbstr, "running") != 0 &&
- strcmp(dbstr, "candidate") != 0 &&
- strcmp(dbstr, "startup") != 0){
- clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
- goto done;
+ strcmp(dbstr, "candidate") != 0 &&
+ strcmp(dbstr, "startup") != 0){
+ clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
+ goto done;
}
if ((cv = cvec_i(argv, 1)) == NULL){
- clicon_err(OE_PLUGIN, 0, "Error when accessing argument ");
- goto done;
+ clicon_err(OE_PLUGIN, 0, "Error when accessing argument ");
+ goto done;
}
api_path_fmt = cv_string_get(cv);
/* api_path_fmt = /interface/%s/address/%s
@@ -244,85 +244,85 @@ expand_dbvar(void *h,
* xpath: --> /interface/[name="eth0"]/address
*/
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path, &cvvi) < 0)
- goto done;
+ goto done;
/* Create config top-of-tree */
if ((xtop = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
xbot = xtop;
/* This is primarily to get "y",
* xpath2xml would have worked!!
* XXX: but y is just the first in this list, there could be other y:s?
*/
if (api_path){
- if ((ret = api_path2xml(api_path, yspec, xtop, YC_DATANODE, 0, &xbot, &y, &xerr)) < 0)
- goto done;
- if (ret == 0){
- clixon_netconf_error(xerr, "Expand datastore symbol", NULL);
- goto done;
- }
+ if ((ret = api_path2xml(api_path, yspec, xtop, YC_DATANODE, 0, &xbot, &y, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ clixon_netconf_error(xerr, "Expand datastore symbol", NULL);
+ goto done;
+ }
}
if (y==NULL)
- goto ok;
+ goto ok;
/* Transform api-path to xpath for netconf */
if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0)
- goto done;
+ goto done;
if (nsc != NULL){
- cvec_free(nsc);
- nsc = NULL;
+ cvec_free(nsc);
+ nsc = NULL;
}
if (xml_nsctx_yang(y, &nsc) < 0)
- goto done;
+ goto done;
if ((cbxpath = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
cprintf(cbxpath, "%s", xpath);
if (clicon_option_bool(h, "CLICON_CLI_EXPAND_LEAFREF") &&
- (ytype = yang_find(y, Y_TYPE, NULL)) != NULL &&
- strcmp(yang_argument_get(ytype), "leafref") == 0){
- /* Special case for leafref. Detect leafref via Yang-type,
- * Get Yang path element, tentatively add the new syntax to the whole
- * tree and apply the path to that.
- * Last, the reference point for the xpath code below is changed to
- * the point of the tentative new xml.
- * Here the whole syntax tree is loaded, and it would be better to offload
- * such operations to the datastore by a generic xpath function.
- */
+ (ytype = yang_find(y, Y_TYPE, NULL)) != NULL &&
+ strcmp(yang_argument_get(ytype), "leafref") == 0){
+ /* Special case for leafref. Detect leafref via Yang-type,
+ * Get Yang path element, tentatively add the new syntax to the whole
+ * tree and apply the path to that.
+ * Last, the reference point for the xpath code below is changed to
+ * the point of the tentative new xml.
+ * Here the whole syntax tree is loaded, and it would be better to offload
+ * such operations to the datastore by a generic xpath function.
+ */
- /*
- * The syntax for a path argument is a subset of the XPath abbreviated
- * syntax. Predicates are used only for constraining the values for the
- * key nodes for list entries. Each predicate consists of exactly one
- * equality test per key, and multiple adjacent predicates MAY be
- * present if a list has multiple keys. The syntax is formally defined
- * by the rule "path-arg" in Section 14.
- * The "path" XPath expression is conceptually evaluated in the
- * following context, in addition to the definition in Section 6.4.1:
- *
- * - If the "path" statement is defined within a typedef, the context
- * node is the leaf or leaf-list node in the data tree that
- * references the typedef.
- * - Otherwise, the context node is the node in the data tree for which
- * the "path" statement is defined.
- */
- if ((ypath = yang_find(ytype, Y_PATH, NULL)) == NULL){
- clicon_err(OE_DB, 0, "Leafref %s requires path statement", yang_argument_get(ytype));
- goto done;
- }
- /* Extend xpath with leafref path: Append yang_argument_get(ypath) to xpath
- */
- if (xpath_append(cbxpath, yang_argument_get(ypath), y, nsc) < 0)
- goto done;
+ /*
+ * The syntax for a path argument is a subset of the XPath abbreviated
+ * syntax. Predicates are used only for constraining the values for the
+ * key nodes for list entries. Each predicate consists of exactly one
+ * equality test per key, and multiple adjacent predicates MAY be
+ * present if a list has multiple keys. The syntax is formally defined
+ * by the rule "path-arg" in Section 14.
+ * The "path" XPath expression is conceptually evaluated in the
+ * following context, in addition to the definition in Section 6.4.1:
+ *
+ * - If the "path" statement is defined within a typedef, the context
+ * node is the leaf or leaf-list node in the data tree that
+ * references the typedef.
+ * - Otherwise, the context node is the node in the data tree for which
+ * the "path" statement is defined.
+ */
+ if ((ypath = yang_find(ytype, Y_PATH, NULL)) == NULL){
+ clicon_err(OE_DB, 0, "Leafref %s requires path statement", yang_argument_get(ytype));
+ goto done;
+ }
+ /* Extend xpath with leafref path: Append yang_argument_get(ypath) to xpath
+ */
+ if (xpath_append(cbxpath, yang_argument_get(ypath), y, nsc) < 0)
+ goto done;
}
/* Get configuration based on cbxpath */
if (clicon_rpc_get_config(h, NULL, dbstr, cbuf_get(cbxpath), nsc, NULL, &xt) < 0)
- goto done;
+ goto done;
if ((xe = xpath_first(xt, NULL, "/rpc-error")) != NULL){
- clixon_netconf_error(xe, "Get configuration", NULL);
- goto ok;
+ clixon_netconf_error(xe, "Get configuration", NULL);
+ goto ok;
}
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, cbuf_get(cbxpath)) < 0)
- goto done;
+ goto done;
/* Loop for inserting into commands cvec.
* Detect duplicates: for ordered-by system assume list is ordered, so you need
* just remember previous
@@ -330,74 +330,74 @@ expand_dbvar(void *h,
*/
bodystr0 = NULL;
for (i = 0; i < xlen; i++) {
- x = xvec[i];
- if (xml_type(x) == CX_BODY)
- bodystr = xml_value(x);
- else
- bodystr = xml_body(x);
- if (bodystr == NULL)
- continue; /* no body, cornercase */
- if ((y = xml_spec(x)) != NULL &&
- (yp = yang_parent_get(y)) != NULL &&
- yang_keyword_get(yp) == Y_LIST &&
- yang_find(yp, Y_ORDERED_BY, "user") != NULL){
- /* Detect duplicates linearly in existing values */
- {
- cg_var *cv = NULL;
- while ((cv = cvec_each(commands, cv)) != NULL)
- if (strcmp(cv_string_get(cv), bodystr) == 0)
- break;
- if (cv == NULL)
- cvec_add_string(commands, NULL, bodystr);
- }
- }
- else{
- if (bodystr0 && strcmp(bodystr, bodystr0) == 0)
- continue; /* duplicate, assume sorted */
- bodystr0 = bodystr;
- /* RFC3986 decode */
- cvec_add_string(commands, NULL, bodystr);
- }
+ x = xvec[i];
+ if (xml_type(x) == CX_BODY)
+ bodystr = xml_value(x);
+ else
+ bodystr = xml_body(x);
+ if (bodystr == NULL)
+ continue; /* no body, cornercase */
+ if ((y = xml_spec(x)) != NULL &&
+ (yp = yang_parent_get(y)) != NULL &&
+ yang_keyword_get(yp) == Y_LIST &&
+ yang_find(yp, Y_ORDERED_BY, "user") != NULL){
+ /* Detect duplicates linearly in existing values */
+ {
+ cg_var *cv = NULL;
+ while ((cv = cvec_each(commands, cv)) != NULL)
+ if (strcmp(cv_string_get(cv), bodystr) == 0)
+ break;
+ if (cv == NULL)
+ cvec_add_string(commands, NULL, bodystr);
+ }
+ }
+ else{
+ if (bodystr0 && strcmp(bodystr, bodystr0) == 0)
+ continue; /* duplicate, assume sorted */
+ bodystr0 = bodystr;
+ /* RFC3986 decode */
+ cvec_add_string(commands, NULL, bodystr);
+ }
}
ok:
retval = 0;
done:
if (cbxpath)
- cbuf_free(cbxpath);
+ cbuf_free(cbxpath);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (api_path)
- free(api_path);
+ free(api_path);
if (xvec)
- free(xvec);
+ free(xvec);
if (xtop)
- xml_free(xtop);
+ xml_free(xtop);
if (xt)
- xml_free(xt);
+ xml_free(xt);
if (xpath)
- free(xpath);
+ free(xpath);
return retval;
}
/*! CLI callback show yang spec. If arg given matches yang argument string */
int
show_yang(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
yang_stmt *yn;
char *str = NULL;
yang_stmt *yspec;
- yspec = clicon_dbspec_yang(h);
+ yspec = clicon_dbspec_yang(h);
if (cvec_len(argv) > 0){
- str = cv_string_get(cvec_i(argv, 0));
- yn = yang_find(yspec, 0, str);
+ str = cv_string_get(cvec_i(argv, 0));
+ yn = yang_find(yspec, 0, str);
}
else
- yn = yspec;
+ yn = yspec;
yang_print_cb(stdout, yn, cligen_output); /* Doesnt use cligen_output */
return 0;
}
@@ -418,17 +418,17 @@ show_yang(clicon_handle h,
*/
static int
cli_show_common(clicon_handle h,
- char *db,
- enum format_enum format,
- int pretty,
- int state,
- char *withdefault,
- char *extdefault,
- char *prefix,
- char *xpath,
- cvec *nsc,
- int skiproot
- )
+ char *db,
+ enum format_enum format,
+ int pretty,
+ int state,
+ char *withdefault,
+ char *extdefault,
+ char *prefix,
+ char *xpath,
+ cvec *nsc,
+ int skiproot
+ )
{
int retval = -1;
cxobj *xt = NULL;
@@ -441,100 +441,100 @@ cli_show_common(clicon_handle h,
int i;
if (state && strcmp(db, "running") != 0){
- clicon_err(OE_FATAL, 0, "Show state only for running database, not %s", db);
- goto done;
+ clicon_err(OE_FATAL, 0, "Show state only for running database, not %s", db);
+ goto done;
}
if (state == 0){ /* Get configuration-only from a database */
- if (clicon_rpc_get_config(h, NULL, db, xpath, nsc, withdefault, &xt) < 0)
- goto done;
+ if (clicon_rpc_get_config(h, NULL, db, xpath, nsc, withdefault, &xt) < 0)
+ goto done;
}
else { /* Get configuration and state from running */
- if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, withdefault, &xt) < 0)
- goto done;
+ if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, withdefault, &xt) < 0)
+ goto done;
}
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Get configuration", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Get configuration", NULL);
+ goto done;
}
/* Special tagged modes: strip wd:default=true attribute and (optionally) nodes associated with it */
if (extdefault &&
- (strcmp(extdefault, "report-all-tagged-strip") == 0 ||
- strcmp(extdefault, "report-all-tagged-default") == 0)){
- if (purge_tagged_nodes(xt, IETF_NETCONF_WITH_DEFAULTS_ATTR_NAMESPACE, "default", "true",
- strcmp(extdefault, "report-all-tagged-strip")
- ) < 0)
- goto done;
- /* Remove empty containers */
- if (xml_defaults_nopresence(xt, 2) < 0)
- goto done;
+ (strcmp(extdefault, "report-all-tagged-strip") == 0 ||
+ strcmp(extdefault, "report-all-tagged-default") == 0)){
+ if (purge_tagged_nodes(xt, IETF_NETCONF_WITH_DEFAULTS_ATTR_NAMESPACE, "default", "true",
+ strcmp(extdefault, "report-all-tagged-strip")
+ ) < 0)
+ goto done;
+ /* Remove empty containers */
+ if (xml_defaults_nopresence(xt, 2) < 0)
+ goto done;
}
if (xpath_vec(xt, nsc, "%s", &vec, &veclen, xpath) < 0)
- goto done;
+ goto done;
if (veclen){
- xp = vec[0]; /* First peek to see if it is special case yang list */
- if ((yp = xml_spec(xp)) != NULL)
- ys_keyword = yang_keyword_get(xml_spec(xp));
- else
- ys_keyword = 0;
- /* Special case LIST */
- if ((ys_keyword == Y_LIST || ys_keyword == Y_LEAF_LIST) && format == FORMAT_JSON){
- switch (format){
- case FORMAT_JSON:
- if (xml2json_vec(stdout, vec, veclen, pretty) < 0) // XXX cligen_output
- goto done;
- break;
- default:
- break;
- }
- }
- else /* Default */
- for (i=0; i",
- NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
- if (pretty)
- cligen_output(stdout, "\n");
- }
- if (clixon_xml2file(stdout, xp, 2, pretty, cligen_output, skiproot, 1) < 0)
- goto done;
- if (i == veclen-1)
- cligen_output(stdout, " ]]>]]>\n");
- break;
- }
- }
+ xp = vec[0]; /* First peek to see if it is special case yang list */
+ if ((yp = xml_spec(xp)) != NULL)
+ ys_keyword = yang_keyword_get(xml_spec(xp));
+ else
+ ys_keyword = 0;
+ /* Special case LIST */
+ if ((ys_keyword == Y_LIST || ys_keyword == Y_LEAF_LIST) && format == FORMAT_JSON){
+ switch (format){
+ case FORMAT_JSON:
+ if (xml2json_vec(stdout, vec, veclen, pretty) < 0) // XXX cligen_output
+ goto done;
+ break;
+ default:
+ break;
+ }
+ }
+ else /* Default */
+ for (i=0; i",
+ NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
+ if (pretty)
+ cligen_output(stdout, "\n");
+ }
+ if (clixon_xml2file(stdout, xp, 2, pretty, cligen_output, skiproot, 1) < 0)
+ goto done;
+ if (i == veclen-1)
+ cligen_output(stdout, " ]]>]]>\n");
+ break;
+ }
+ }
}
retval = 0;
done:
if (vec)
- free(vec);
+ free(vec);
if (xt)
- xml_free(xt);
+ xml_free(xt);
return retval;
}
@@ -548,16 +548,16 @@ done:
*/
static int
cli_show_option_format(cvec *argv,
- int argc,
- enum format_enum *format)
+ int argc,
+ enum format_enum *format)
{
int retval = -1;
char *formatstr;
formatstr = cv_string_get(cvec_i(argv, argc));
if ((int)(*format = format_str2int(formatstr)) < 0){
- clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
- goto done;
+ clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
+ goto done;
}
retval = 0;
done:
@@ -574,9 +574,9 @@ cli_show_option_format(cvec *argv,
*/
static int
cli_show_option_bool(cvec *argv,
- int argc,
- int *bool
- )
+ int argc,
+ int *bool
+ )
{
int retval = -1;
char *boolstr;
@@ -584,18 +584,18 @@ cli_show_option_bool(cvec *argv,
boolstr = cv_string_get(cvec_i(argv, argc));
if ((boolcv = cv_new(CGV_BOOL)) == NULL){
- clicon_err(OE_UNIX, errno, "cv_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cv_new");
+ goto done;
}
if (cv_parse(boolstr, boolcv) < 0){
- clicon_err(OE_UNIX, errno, "Parse boolean %s", boolstr);
- goto done;
+ clicon_err(OE_UNIX, errno, "Parse boolean %s", boolstr);
+ goto done;
}
*bool = cv_bool_get(boolcv);
retval = 0;
done:
if (boolcv)
- cv_free(boolcv);
+ cv_free(boolcv);
return retval;
}
@@ -614,9 +614,9 @@ cli_show_option_bool(cvec *argv,
*/
static int
cli_show_option_withdefault(cvec *argv,
- int argc,
- char **withdefault,
- char **extdefault)
+ int argc,
+ char **withdefault,
+ char **extdefault)
{
int retval = -1;
char *e;
@@ -624,22 +624,22 @@ cli_show_option_withdefault(cvec *argv,
e = cv_string_get(cvec_i(argv, argc));
/* From extended to RFC6243 withdefault modes */
if (strcmp(e, "report-all-tagged-strip") == 0)
- *withdefault = "report-all-tagged";
+ *withdefault = "report-all-tagged";
else if (strcmp(e, "report-all-tagged-default") == 0)
- *withdefault = "report-all-tagged";
+ *withdefault = "report-all-tagged";
else if (strcmp(e, "NULL") == 0){
- e = NULL;
- *withdefault = NULL;
+ e = NULL;
+ *withdefault = NULL;
}
else if (strcmp(e, "report-all") != 0 &&
- strcmp(e, "trim") != 0 &&
- strcmp(e, "explicit") != 0 &&
- strcmp(e, "report-all-tagged") != 0){
- clicon_err(OE_YANG, EINVAL, "Unexpected with-default option: %s", e);
- goto done;
+ strcmp(e, "trim") != 0 &&
+ strcmp(e, "explicit") != 0 &&
+ strcmp(e, "report-all-tagged") != 0){
+ clicon_err(OE_YANG, EINVAL, "Unexpected with-default option: %s", e);
+ goto done;
}
else
- *withdefault = e;
+ *withdefault = e;
*extdefault = e;
retval = 0;
done:
@@ -680,8 +680,8 @@ cli_show_option_withdefault(cvec *argv,
*/
int
cli_show_config(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
char *dbname;
@@ -698,47 +698,47 @@ cli_show_config(clicon_handle h,
char *namespace = NULL;
if (cvec_len(argv) < 2 || cvec_len(argv) > 8){
- clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: [ ]", cvec_len(argv));
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: [ ]", cvec_len(argv));
+ goto done;
}
dbname = cv_string_get(cvec_i(argv, argc++));
if (cvec_len(argv) > argc)
- if (cli_show_option_format(argv, argc++, &format) < 0)
- goto done;
+ if (cli_show_option_format(argv, argc++, &format) < 0)
+ goto done;
if (cvec_len(argv) > argc)
- xpath = cv_string_get(cvec_i(argv, argc++));
+ xpath = cv_string_get(cvec_i(argv, argc++));
if (cvec_len(argv) > argc){
- namespace = cv_string_get(cvec_i(argv, argc++));
- /* Special symbol NULL means no namespace */
- if (strcmp(namespace, "NULL") != 0)
- if ((nsc = xml_nsctx_init(NULL, namespace)) == NULL)
- goto done;
+ namespace = cv_string_get(cvec_i(argv, argc++));
+ /* Special symbol NULL means no namespace */
+ if (strcmp(namespace, "NULL") != 0)
+ if ((nsc = xml_nsctx_init(NULL, namespace)) == NULL)
+ goto done;
}
if (cvec_len(argv) > argc){
- if (cli_show_option_bool(argv, argc++, &pretty) < 0)
- goto done;
+ if (cli_show_option_bool(argv, argc++, &pretty) < 0)
+ goto done;
}
if (cvec_len(argv) > argc){
- if (cli_show_option_bool(argv, argc++, &state) < 0)
- goto done;
+ if (cli_show_option_bool(argv, argc++, &state) < 0)
+ goto done;
}
if (cvec_len(argv) > argc){
- if (cli_show_option_withdefault(argv, argc++,
- &withdefault,
- &extdefault) < 0)
- goto done;
+ if (cli_show_option_withdefault(argv, argc++,
+ &withdefault,
+ &extdefault) < 0)
+ goto done;
}
if (cvec_len(argv) > argc){
- prefix = cv_string_get(cvec_i(argv, argc++));
+ prefix = cv_string_get(cvec_i(argv, argc++));
}
if (cli_show_common(h, dbname, format, pretty, state,
- withdefault, extdefault,
- prefix, xpath, nsc, skiproot) < 0)
- goto done;
+ withdefault, extdefault,
+ prefix, xpath, nsc, skiproot) < 0)
+ goto done;
retval = 0;
done:
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
return retval;
}
@@ -764,8 +764,8 @@ cli_show_config(clicon_handle h,
*/
int
show_conf_xpath(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
char *dbname;
@@ -775,42 +775,42 @@ show_conf_xpath(clicon_handle h,
yang_stmt *yspec;
if (cvec_len(argv) != 1){
- clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be ");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be ");
+ goto done;
}
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
dbname = cv_string_get(cvec_i(argv, 0));
/* Look for xpath in command (kludge: cv must be called "xpath") */
if ((cv = cvec_find(cvv, "xpath")) == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "Requires one variable to be ");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Requires one variable to be ");
+ goto done;
}
xpath = cv_string_get(cv);
/* Create canonical namespace */
if (xml_nsctx_yangspec(yspec, &nsc) < 0)
- goto done;
+ goto done;
/* Look for and add default namespace variable in command */
if ((cv = cvec_find(cvv, "ns")) != NULL){
- if (xml_nsctx_add(nsc, NULL, cv_string_get(cv)) < 0)
- goto done;
+ if (xml_nsctx_add(nsc, NULL, cv_string_get(cv)) < 0)
+ goto done;
}
if (cli_show_common(h, dbname, FORMAT_XML, 1, 0,
- NULL, NULL,
- NULL, xpath, nsc, 0) < 0)
- goto done;
+ NULL, NULL,
+ NULL, xpath, nsc, 0) < 0)
+ goto done;
retval = 0;
done:
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
return retval;
}
int cli_show_version(clicon_handle h,
- cvec *vars,
- cvec *argv)
+ cvec *vars,
+ cvec *argv)
{
fprintf(stdout, "%s\n", CLIXON_VERSION_STRING);
return 0;
@@ -852,8 +852,8 @@ int cli_show_version(clicon_handle h,
*/
int
cli_show_auto(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
char *dbname;
@@ -873,55 +873,55 @@ cli_show_auto(clicon_handle h,
char *api_path_fmt; /* xml key format */
if (cvec_len(argv) < 2 || cvec_len(argv) > 7){
- clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: * [ ]", cvec_len(argv));
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: * [ ]", cvec_len(argv));
+ goto done;
}
api_path_fmt = cv_string_get(cvec_i(argv, argc++));
dbname = cv_string_get(cvec_i(argv, argc++));
if (cvec_len(argv) > argc)
- if (cli_show_option_format(argv, argc++, &format) < 0)
- goto done;
+ if (cli_show_option_format(argv, argc++, &format) < 0)
+ goto done;
if (cvec_len(argv) > argc){
- if (cli_show_option_bool(argv, argc++, &pretty) < 0)
- goto done;
+ if (cli_show_option_bool(argv, argc++, &pretty) < 0)
+ goto done;
}
if (cvec_len(argv) > argc){
- if (cli_show_option_bool(argv, argc++, &state) < 0)
- goto done;
+ if (cli_show_option_bool(argv, argc++, &state) < 0)
+ goto done;
}
if (cvec_len(argv) > argc){
- if (cli_show_option_withdefault(argv, argc++,
- &withdefault,
- &extdefault) < 0)
- goto done;
+ if (cli_show_option_withdefault(argv, argc++,
+ &withdefault,
+ &extdefault) < 0)
+ goto done;
}
if (cvec_len(argv) > argc){
- prefix = cv_string_get(cvec_i(argv, argc++));
+ prefix = cv_string_get(cvec_i(argv, argc++));
}
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path, &cvvi) < 0)
- goto done;
+ goto done;
if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0)
- goto done;
+ goto done;
if (xpath == NULL){
- clicon_err(OE_FATAL, 0, "Invalid api-path-fmt: %s", api_path_fmt);
- goto done;
+ clicon_err(OE_FATAL, 0, "Invalid api-path-fmt: %s", api_path_fmt);
+ goto done;
}
if (cli_show_common(h, dbname, format, pretty, state,
- withdefault, extdefault,
- prefix, xpath, nsc, skiproot) < 0)
- goto done;
+ withdefault, extdefault,
+ prefix, xpath, nsc, skiproot) < 0)
+ goto done;
retval = 0;
done:
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (xpath)
- free(xpath);
+ free(xpath);
if (api_path)
- free(api_path);
+ free(api_path);
return retval;
}
@@ -960,8 +960,8 @@ cli_show_auto(clicon_handle h,
*/
int
cli_show_auto_mode(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
char *dbname;
@@ -979,56 +979,56 @@ cli_show_auto_mode(clicon_handle h,
char *api_path = NULL;
if (cvec_len(argv) < 2 || cvec_len(argv) > 7){
- clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: [ ]", cvec_len(argv));
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: [ ]", cvec_len(argv));
+ goto done;
}
dbname = cv_string_get(cvec_i(argv, argc++));
if (cvec_len(argv) > argc)
- if (cli_show_option_format(argv, argc++, &format) < 0)
- goto done;
+ if (cli_show_option_format(argv, argc++, &format) < 0)
+ goto done;
if (cvec_len(argv) > argc){
- if (cli_show_option_bool(argv, argc++, &pretty) < 0)
- goto done;
+ if (cli_show_option_bool(argv, argc++, &pretty) < 0)
+ goto done;
}
if (cvec_len(argv) > argc){
- if (cli_show_option_bool(argv, argc++, &state) < 0)
- goto done;
+ if (cli_show_option_bool(argv, argc++, &state) < 0)
+ goto done;
}
if (cvec_len(argv) > argc){
- if (cli_show_option_withdefault(argv, argc++,
- &withdefault,
- &extdefault) < 0)
- goto done;
+ if (cli_show_option_withdefault(argv, argc++,
+ &withdefault,
+ &extdefault) < 0)
+ goto done;
}
if (cvec_len(argv) > argc){
- prefix = cv_string_get(cvec_i(argv, argc++));
+ prefix = cv_string_get(cvec_i(argv, argc++));
}
/* Store this as edit-mode */
if (clicon_data_get(h, "cli-edit-mode", &api_path) == 0 && strlen(api_path))
- ;
+ ;
else
- api_path = "/";
+ api_path = "/";
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0)
- goto done;
+ goto done;
if (xpath == NULL){
- clicon_err(OE_FATAL, 0, "Invalid api-path: %s", api_path);
- goto done;
+ clicon_err(OE_FATAL, 0, "Invalid api-path: %s", api_path);
+ goto done;
}
skiproot = (strcmp(xpath,"/") != 0);
if (cli_show_common(h, dbname, format, pretty, state,
- withdefault, extdefault,
- prefix, xpath, nsc, skiproot) < 0)
- goto done;
+ withdefault, extdefault,
+ prefix, xpath, nsc, skiproot) < 0)
+ goto done;
retval = 0;
done:
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (xpath)
- free(xpath);
+ free(xpath);
return retval;
}
@@ -1039,30 +1039,30 @@ cli_show_auto_mode(clicon_handle h,
*/
int
cli_auto_show(clicon_handle h,
- cvec *cvv,
- cvec *argv0)
+ cvec *cvv,
+ cvec *argv0)
{
int retval = -1;
cvec *argv1 = NULL;
cg_var *cv;
if ((argv1 = cvec_new(0)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ goto done;
}
cv = NULL;
while ((cv = cvec_each1(argv0, cv)) != NULL) {
- if (cvec_append_var(argv1, cv) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_append_var");
- goto done;
- }
+ if (cvec_append_var(argv1, cv) == NULL){
+ clicon_err(OE_UNIX, errno, "cvec_append_var");
+ goto done;
+ }
}
if (cli_show_auto_mode(h, cvv, argv1) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (argv1)
- cvec_free(argv1);
+ cvec_free(argv1);
return retval;
}
@@ -1070,8 +1070,8 @@ cli_auto_show(clicon_handle h,
*/
int
cli_show_options(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
clicon_hash_t *hash = clicon_options(h);
@@ -1083,43 +1083,43 @@ cli_show_options(clicon_handle h,
cxobj *x = NULL;
if (clicon_hash_keys(hash, &keys, &klen) < 0)
- goto done;
+ goto done;
for(i = 0; i < klen; i++) {
- val = clicon_hash_value(hash, keys[i], &vlen);
- if (vlen){
- if (((char*)val)[vlen-1]=='\0') /* assume string */
- fprintf(stdout, "%s: \"%s\"\n", keys[i], (char*)val);
- else
- fprintf(stdout, "%s: 0x%p , length %zu\n", keys[i], val, vlen);
- }
- else
- fprintf(stdout, "%s: NULL\n", keys[i]);
+ val = clicon_hash_value(hash, keys[i], &vlen);
+ if (vlen){
+ if (((char*)val)[vlen-1]=='\0') /* assume string */
+ fprintf(stdout, "%s: \"%s\"\n", keys[i], (char*)val);
+ else
+ fprintf(stdout, "%s: 0x%p , length %zu\n", keys[i], val, vlen);
+ }
+ else
+ fprintf(stdout, "%s: NULL\n", keys[i]);
}
/* Next print CLICON_FEATURE, CLICON_YANG_DIR and CLICON_SNMP_MIB from config tree
* Since they are lists they are placed in the config tree.
*/
x = NULL;
while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(x), "CLICON_YANG_DIR") != 0)
- continue;
- fprintf(stdout, "%s: \"%s\"\n", xml_name(x), xml_body(x));
+ if (strcmp(xml_name(x), "CLICON_YANG_DIR") != 0)
+ continue;
+ fprintf(stdout, "%s: \"%s\"\n", xml_name(x), xml_body(x));
}
x = NULL;
while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(x), "CLICON_FEATURE") != 0)
- continue;
- fprintf(stdout, "%s: \"%s\"\n", xml_name(x), xml_body(x));
+ if (strcmp(xml_name(x), "CLICON_FEATURE") != 0)
+ continue;
+ fprintf(stdout, "%s: \"%s\"\n", xml_name(x), xml_body(x));
}
x = NULL;
while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(x), "CLICON_SNMP_MIB") != 0)
- continue;
- fprintf(stdout, "%s: \"%s\"\n", xml_name(x), xml_body(x));
+ if (strcmp(xml_name(x), "CLICON_SNMP_MIB") != 0)
+ continue;
+ fprintf(stdout, "%s: \"%s\"\n", xml_name(x), xml_body(x));
}
retval = 0;
done:
if (keys)
- free(keys);
+ free(keys);
return retval;
}
@@ -1131,8 +1131,8 @@ cli_show_options(clicon_handle h,
*/
int
cli_pagination(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
cbuf *cb = NULL;
@@ -1154,104 +1154,104 @@ cli_pagination(clicon_handle h,
int locked = 0;
if (cvec_len(argv) != 5){
- clicon_err(OE_PLUGIN, 0, "Expected usage: ");
- goto done;
+ clicon_err(OE_PLUGIN, 0, "Expected usage: ");
+ goto done;
}
/* prefix:variable overrides argv */
if ((cv = cvec_find(cvv, "xpath")) != NULL)
- xpath = cv_string_get(cv);
+ xpath = cv_string_get(cv);
else
- xpath = cvec_i_str(argv, 0);
+ xpath = cvec_i_str(argv, 0);
prefix = cvec_i_str(argv, 1);
namespace = cvec_i_str(argv, 2);
str = cv_string_get(cvec_i(argv, 3)); /* Fourthformat: output format */
if ((int)(format = format_str2int(str)) < 0){
- clicon_err(OE_PLUGIN, 0, "Not valid format: %s", str);
- goto done;
+ clicon_err(OE_PLUGIN, 0, "Not valid format: %s", str);
+ goto done;
}
if ((str = cv_string_get(cvec_i(argv, 4))) != NULL){
- if (parse_uint32(str, &limit, NULL) < 1){
- clicon_err(OE_UNIX, errno, "error parsing limit:%s", str);
- goto done;
- }
+ if (parse_uint32(str, &limit, NULL) < 1){
+ clicon_err(OE_UNIX, errno, "error parsing limit:%s", str);
+ goto done;
+ }
}
if (limit == 0){
- clicon_err(OE_UNIX, EINVAL, "limit is 0");
- goto done;
+ clicon_err(OE_UNIX, EINVAL, "limit is 0");
+ goto done;
}
if ((nsc = xml_nsctx_init(prefix, namespace)) == NULL)
- goto done;
+ goto done;
if (clicon_rpc_lock(h, "running") < 0)
- goto done;
+ goto done;
locked++;
for (i = 0;; i++){
- if (clicon_rpc_get_pageable_list(h, "running", xpath, nsc,
- CONTENT_ALL,
- -1, /* depth */
- NULL, /* with-default */
- limit*i, /* offset */
- limit, /* limit */
- NULL, NULL, NULL, /* nyi */
- &xret) < 0){
- goto done;
- }
- if ((xerr = xpath_first(xret, NULL, "/rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Get configuration", NULL);
- goto done;
- }
- if (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath) < 0)
- goto done;
- for (j = 0; j netconf
+ ssh -s netconf
For more defails see [Clixon docs netconf](https://clixon-docs.readthedocs.io/en/latest/standards.html#netconf)
\ No newline at end of file
diff --git a/apps/netconf/clixon_netconf.h b/apps/netconf/clixon_netconf.h
index 576d5408..336f1f2b 100644
--- a/apps/netconf/clixon_netconf.h
+++ b/apps/netconf/clixon_netconf.h
@@ -46,9 +46,9 @@
* (Duplicated. Also in netconf_*.h)
*/
int netconf_xpath(cxobj *xsearch,
- cxobj *xfilter,
- cbuf *xf, cbuf *xf_err,
- cxobj *xt);
+ cxobj *xfilter,
+ cbuf *xf, cbuf *xf_err,
+ cxobj *xt);
#endif /* _CLIXON_NETCONF_H_ */
diff --git a/apps/netconf/netconf_filter.c b/apps/netconf/netconf_filter.c
index 57f43345..bee2a744 100644
--- a/apps/netconf/netconf_filter.c
+++ b/apps/netconf/netconf_filter.c
@@ -85,14 +85,14 @@ leafstring(cxobj *x)
cxobj *c;
if (xml_type(x) != CX_ELMNT)
- return NULL;
+ return NULL;
if (xml_child_nr(x) != 1)
- return NULL;
+ return NULL;
c = xml_child_i(x, 0);
if (xml_child_nr(c) != 0)
- return NULL;
+ return NULL;
if (xml_type(c) != CX_BODY)
- return NULL;
+ return NULL;
return xml_value(c);
}
@@ -106,8 +106,8 @@ leafstring(cxobj *x)
*/
static int
xml_filter_recursive(cxobj *xfilter,
- cxobj *xparent,
- int *remove_me)
+ cxobj *xparent,
+ int *remove_me)
{
cxobj *s;
cxobj *sprev;
@@ -123,63 +123,63 @@ xml_filter_recursive(cxobj *xfilter,
*remove_me = 0;
/* 1. Check selection */
if (xml_child_nr(xfilter) == 0)
- goto match;
+ goto match;
/* Count containment/selection nodes in filter */
f = NULL;
containments = 0;
while ((f = xml_child_each(xfilter, f, CX_ELMNT)) != NULL) {
- if (leafstring(f))
- continue;
- containments++;
+ if (leafstring(f))
+ continue;
+ containments++;
}
/* 2. Check attribute match */
attr = NULL;
while ((attr = xml_child_each(xfilter, attr, CX_ATTR)) != NULL) {
- af = xml_value(attr);
- an = xml_find_value(xfilter, xml_name(attr));
- if (af && an && strcmp(af, an)==0)
- ; // match
- else
- goto nomatch;
+ af = xml_value(attr);
+ an = xml_find_value(xfilter, xml_name(attr));
+ if (af && an && strcmp(af, an)==0)
+ ; // match
+ else
+ goto nomatch;
}
/* 3. Check content match */
f = NULL;
while ((f = xml_child_each(xfilter, f, CX_ELMNT)) != NULL) {
- if ((fstr = leafstring(f)) == NULL)
- continue;
- if ((s = xml_find(xparent, xml_name(f))) == NULL)
- goto nomatch;
- if ((sstr = leafstring(s)) == NULL)
- continue;
- if (strcmp(fstr, sstr))
- goto nomatch;
+ if ((fstr = leafstring(f)) == NULL)
+ continue;
+ if ((s = xml_find(xparent, xml_name(f))) == NULL)
+ goto nomatch;
+ if ((sstr = leafstring(s)) == NULL)
+ continue;
+ if (strcmp(fstr, sstr))
+ goto nomatch;
}
/* If filter has no further specifiers, accept */
if (!containments)
- goto match;
+ goto match;
/* Check recursively the rest of the siblings */
sprev = s = NULL;
while ((s = xml_child_each(xparent, s, CX_ELMNT)) != NULL) {
- if ((f = xml_find(xfilter, xml_name(s))) == NULL){
- xml_purge(s);
- s = sprev;
- continue;
- }
- if (leafstring(f)){
- sprev = s;
- continue; // unsure?sk=lf
- }
- // XXX: s can be removed itself in the recursive call !
- remove_s = 0;
- if (xml_filter_recursive(f, s, &remove_s) < 0)
- return -1;
- if (remove_s){
- xml_purge(s);
- s = sprev;
- }
- sprev = s;
+ if ((f = xml_find(xfilter, xml_name(s))) == NULL){
+ xml_purge(s);
+ s = sprev;
+ continue;
+ }
+ if (leafstring(f)){
+ sprev = s;
+ continue; // unsure?sk=lf
+ }
+ // XXX: s can be removed itself in the recursive call !
+ remove_s = 0;
+ if (xml_filter_recursive(f, s, &remove_s) < 0)
+ return -1;
+ if (remove_s){
+ xml_purge(s);
+ s = sprev;
+ }
+ sprev = s;
}
match:
@@ -198,15 +198,15 @@ xml_filter_recursive(cxobj *xfilter,
*/
int
xml_filter(cxobj *xfilter,
- cxobj *xconfig)
+ cxobj *xconfig)
{
int retval;
int remove_s;
/* Call recursive variant */
retval = xml_filter_recursive(xfilter,
- xconfig,
- &remove_s);
+ xconfig,
+ &remove_s);
return retval;
}
diff --git a/apps/netconf/netconf_main.c b/apps/netconf/netconf_main.c
index b6208acb..e2789db4 100644
--- a/apps/netconf/netconf_main.c
+++ b/apps/netconf/netconf_main.c
@@ -99,7 +99,7 @@ static int _netconf_hello_nr = 0;
*/
static int
netconf_add_request_attr(cxobj *xrpc,
- cxobj *xrep)
+ cxobj *xrep)
{
int retval = -1;
cxobj *xa;
@@ -107,13 +107,13 @@ netconf_add_request_attr(cxobj *xrpc,
xa = NULL;
while ((xa = xml_child_each(xrpc, xa, CX_ATTR)) != NULL){
- /* If attribute already exists, dont copy it */
- if (xml_find_type(xrep, NULL, xml_name(xa), CX_ATTR) != NULL)
- continue; /* Skip already present (dont overwrite) */
- if ((xa2 = xml_dup(xa)) ==NULL)
- goto done;
- if (xml_addsub(xrep, xa2) < 0)
- goto done;
+ /* If attribute already exists, dont copy it */
+ if (xml_find_type(xrep, NULL, xml_name(xa), CX_ATTR) != NULL)
+ continue; /* Skip already present (dont overwrite) */
+ if ((xa2 = xml_dup(xa)) ==NULL)
+ goto done;
+ if (xml_addsub(xrep, xa2) < 0)
+ goto done;
}
retval = 0;
done:
@@ -127,8 +127,8 @@ netconf_add_request_attr(cxobj *xrpc,
*/
static int
netconf_hello_msg(clicon_handle h,
- cxobj *xn,
- int *eof)
+ cxobj *xn,
+ int *eof)
{
int retval = -1;
cvec *nsc = NULL; // namespace context
@@ -142,39 +142,39 @@ netconf_hello_msg(clicon_handle h,
_netconf_hello_nr++;
if (xml_find_type(xn, NULL, "session-id", CX_ELMNT) != NULL) {
- clicon_err(OE_XML, errno, "Server received hello with session-id from client, terminating (see RFC 6241 Sec 8.1");
- goto done;
+ clicon_err(OE_XML, errno, "Server received hello with session-id from client, terminating (see RFC 6241 Sec 8.1");
+ goto done;
}
if (xpath_vec(xn, nsc, "capabilities/capability", &vec, &veclen) < 0)
- goto done;
+ goto done;
/* Each peer MUST send at least the base NETCONF capability, "urn:ietf:params:netconf:base:1.1"*/
if ((xcap = xml_find_type(xn, NULL, "capabilities", CX_ELMNT)) != NULL) {
- x = NULL;
- while ((x = xml_child_each(xcap, x, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(x), "capability") != 0)
- continue;
- if ((body = xml_body(x)) == NULL)
- continue;
- /* When comparing protocol version capability URIs, only the base part is used, in the
- * event any parameters are encoded at the end of the URI string. */
- if (strncmp(body, NETCONF_BASE_CAPABILITY_1_0, strlen(NETCONF_BASE_CAPABILITY_1_0)) == 0) /* RFC 4741 */
- foundbase_10++;
- else if (strncmp(body, NETCONF_BASE_CAPABILITY_1_1, strlen(NETCONF_BASE_CAPABILITY_1_1)) == 0 &&
- clicon_option_int(h, "CLICON_NETCONF_BASE_CAPABILITY") > 0){ /* RFC 6241 */
- foundbase_11++;
- clicon_option_int_set(h, "netconf-framing", NETCONF_SSH_CHUNKED); /* enable chunked enc */
- }
- }
+ x = NULL;
+ while ((x = xml_child_each(xcap, x, CX_ELMNT)) != NULL) {
+ if (strcmp(xml_name(x), "capability") != 0)
+ continue;
+ if ((body = xml_body(x)) == NULL)
+ continue;
+ /* When comparing protocol version capability URIs, only the base part is used, in the
+ * event any parameters are encoded at the end of the URI string. */
+ if (strncmp(body, NETCONF_BASE_CAPABILITY_1_0, strlen(NETCONF_BASE_CAPABILITY_1_0)) == 0) /* RFC 4741 */
+ foundbase_10++;
+ else if (strncmp(body, NETCONF_BASE_CAPABILITY_1_1, strlen(NETCONF_BASE_CAPABILITY_1_1)) == 0 &&
+ clicon_option_int(h, "CLICON_NETCONF_BASE_CAPABILITY") > 0){ /* RFC 6241 */
+ foundbase_11++;
+ clicon_option_int_set(h, "netconf-framing", NETCONF_SSH_CHUNKED); /* enable chunked enc */
+ }
+ }
}
if (foundbase_10 == 0 && foundbase_11 == 0){
- clicon_err(OE_XML, errno, "Server received hello without matching netconf base capability, terminating (see RFC 6241 Sec 8.1");
- *eof = 1;
- goto done;
+ clicon_err(OE_XML, errno, "Server received hello without matching netconf base capability, terminating (see RFC 6241 Sec 8.1");
+ *eof = 1;
+ goto done;
}
retval = 0;
done:
if (vec)
- free(vec);
+ free(vec);
return retval;
}
@@ -188,9 +188,9 @@ netconf_hello_msg(clicon_handle h,
*/
static int
netconf_rpc_message(clicon_handle h,
- cxobj *xrpc,
- yang_stmt *yspec,
- int *eof)
+ cxobj *xrpc,
+ yang_stmt *yspec,
+ int *eof)
{
int retval = -1;
cxobj *xret = NULL; /* Return (out) */
@@ -201,88 +201,88 @@ netconf_rpc_message(clicon_handle h,
framing = clicon_option_int(h, "netconf-framing");
if (_netconf_hello_nr == 0 &&
- clicon_option_bool(h, "CLICON_NETCONF_HELLO_OPTIONAL") == 0){
- if (netconf_operation_failed_xml(&xret, "rpc", "Client must send an hello element before any RPC")< 0)
- goto done;
- /* Copy attributes from incoming request to reply. Skip already present (dont overwrite) */
- if (netconf_add_request_attr(xrpc, xret) < 0)
- goto done;
- if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- if (netconf_output_encap(framing, cbret) < 0)
- goto done;
- if (netconf_output(1, cbret, "rpc-error") < 0)
- goto done;
- *eof = 1;
- goto ok;
+ clicon_option_bool(h, "CLICON_NETCONF_HELLO_OPTIONAL") == 0){
+ if (netconf_operation_failed_xml(&xret, "rpc", "Client must send an hello element before any RPC")< 0)
+ goto done;
+ /* Copy attributes from incoming request to reply. Skip already present (dont overwrite) */
+ if (netconf_add_request_attr(xrpc, xret) < 0)
+ goto done;
+ if ((cbret = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ if (netconf_output_encap(framing, cbret) < 0)
+ goto done;
+ if (netconf_output(1, cbret, "rpc-error") < 0)
+ goto done;
+ *eof = 1;
+ goto ok;
}
if ((ret = xml_bind_yang_rpc(xrpc, yspec, &xret)) < 0)
- goto done;
+ goto done;
if (ret > 0 &&
- (ret = xml_yang_validate_rpc(h, xrpc, &xret)) < 0)
- goto done;
+ (ret = xml_yang_validate_rpc(h, xrpc, &xret)) < 0)
+ goto done;
if (ret == 0){
- if (netconf_add_request_attr(xrpc, xret) < 0)
- goto done;
- if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- if (netconf_output_encap(framing, cbret) < 0)
- goto done;
- if (netconf_output(1, cbret, "rpc-error") < 0)
- goto done;
- goto ok;
+ if (netconf_add_request_attr(xrpc, xret) < 0)
+ goto done;
+ if ((cbret = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ if (netconf_output_encap(framing, cbret) < 0)
+ goto done;
+ if (netconf_output(1, cbret, "rpc-error") < 0)
+ goto done;
+ goto ok;
}
if (netconf_rpc_dispatch(h, xrpc, &xret, eof) < 0){
- goto done;
+ goto done;
}
/* Is there a return message in xret? */
if (xret == NULL){
- if (netconf_operation_failed_xml(&xret, "rpc", "Internal error: no xml return")< 0)
- goto done;
- if (netconf_add_request_attr(xrpc, xret) < 0)
- goto done;
- if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- if (netconf_output_encap(framing, cbret) < 0)
- goto done;
- if (netconf_output(1, cbret, "rpc-error") < 0)
- goto done;
- goto ok;
+ if (netconf_operation_failed_xml(&xret, "rpc", "Internal error: no xml return")< 0)
+ goto done;
+ if (netconf_add_request_attr(xrpc, xret) < 0)
+ goto done;
+ if ((cbret = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ if (netconf_output_encap(framing, cbret) < 0)
+ goto done;
+ if (netconf_output(1, cbret, "rpc-error") < 0)
+ goto done;
+ goto ok;
}
if ((xc = xml_child_i(xret, 0))!=NULL){
- /* Copy attributes from incoming request to reply. Skip already present (dont overwrite) */
- if (netconf_add_request_attr(xrpc, xc) < 0)
- goto done;
- if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- if (clixon_xml2cbuf(cbret, xml_child_i(xret,0), 0, 0, -1, 0) < 0)
- goto done;
- if (netconf_output_encap(framing, cbret) < 0)
- goto done;
- if (netconf_output(1, cbret, "rpc-reply") < 0)
- goto done;
+ /* Copy attributes from incoming request to reply. Skip already present (dont overwrite) */
+ if (netconf_add_request_attr(xrpc, xc) < 0)
+ goto done;
+ if ((cbret = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ if (clixon_xml2cbuf(cbret, xml_child_i(xret,0), 0, 0, -1, 0) < 0)
+ goto done;
+ if (netconf_output_encap(framing, cbret) < 0)
+ goto done;
+ if (netconf_output(1, cbret, "rpc-reply") < 0)
+ goto done;
}
ok:
retval = 0;
done:
if (cbret)
- cbuf_free(cbret);
+ cbuf_free(cbret);
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -297,9 +297,9 @@ netconf_rpc_message(clicon_handle h,
*/
static int
netconf_input_packet(clicon_handle h,
- cxobj *xreq,
- yang_stmt *yspec,
- int *eof)
+ cxobj *xreq,
+ yang_stmt *yspec,
+ int *eof)
{
int retval = -1;
cbuf *cbret = NULL;
@@ -314,50 +314,50 @@ netconf_input_packet(clicon_handle h,
rpcprefix = xml_prefix(xreq);
framing = clicon_option_int(h, "netconf-framing");
if (xml2ns(xreq, rpcprefix, &namespace) < 0)
- goto done;
+ goto done;
if (strcmp(rpcname, "rpc") == 0){
- /* Only accept resolved NETCONF base namespace */
- if (namespace == NULL || strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){
- if (netconf_unknown_namespace_xml(&xret, "protocol", rpcprefix, "No appropriate namespace associated with prefix")< 0)
- goto done;
- if (netconf_add_request_attr(xreq, xret) < 0)
- goto done;
- if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- if (netconf_output_encap(framing, cbret) < 0)
- goto done;
- if (netconf_output(1, cbret, "rpc-error") < 0)
- goto done;
- goto ok;
- }
- if (netconf_rpc_message(h, xreq, yspec, eof) < 0)
- goto done;
+ /* Only accept resolved NETCONF base namespace */
+ if (namespace == NULL || strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){
+ if (netconf_unknown_namespace_xml(&xret, "protocol", rpcprefix, "No appropriate namespace associated with prefix")< 0)
+ goto done;
+ if (netconf_add_request_attr(xreq, xret) < 0)
+ goto done;
+ if ((cbret = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ if (netconf_output_encap(framing, cbret) < 0)
+ goto done;
+ if (netconf_output(1, cbret, "rpc-error") < 0)
+ goto done;
+ goto ok;
+ }
+ if (netconf_rpc_message(h, xreq, yspec, eof) < 0)
+ goto done;
}
else if (strcmp(rpcname, "hello") == 0){
- /* Only accept resolved NETCONF base namespace -> terminate*/
- if (namespace == NULL || strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){
- *eof = 1;
- clicon_err(OE_XML, EFAULT, "No appropriate namespace associated with namespace:%s",
- namespace);
- goto done;
- }
- if (netconf_hello_msg(h, xreq, eof) < 0)
- goto done;
+ /* Only accept resolved NETCONF base namespace -> terminate*/
+ if (namespace == NULL || strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){
+ *eof = 1;
+ clicon_err(OE_XML, EFAULT, "No appropriate namespace associated with namespace:%s",
+ namespace);
+ goto done;
+ }
+ if (netconf_hello_msg(h, xreq, eof) < 0)
+ goto done;
}
else{ /* Shouldnt happen should be caught by yang bind check in netconf_input_frame */
- *eof = 1;
- clicon_err(OE_NETCONF, 0, "Unrecognized netconf operation %s", rpcname);
- goto done;
+ *eof = 1;
+ clicon_err(OE_NETCONF, 0, "Unrecognized netconf operation %s", rpcname);
+ goto done;
}
ok:
retval = 0;
done:
if (cbret)
- cbuf_free(cbret);
+ cbuf_free(cbret);
return retval;
}
@@ -382,8 +382,8 @@ netconf_input_packet(clicon_handle h,
*/
static int
netconf_input_frame(clicon_handle h,
- cbuf *cb,
- int *eof)
+ cbuf *cb,
+ int *eof)
{
int retval = -1;
char *str = NULL;
@@ -400,99 +400,99 @@ netconf_input_frame(clicon_handle h,
framing = clicon_option_int(h, "netconf-framing");
yspec = clicon_dbspec_yang(h);
if ((str = strdup(cbuf_get(cb))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
/* Special case: */
if (strlen(str) == 0){
- if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- if (netconf_operation_failed(cbret, "rpc", "Empty XML")< 0)
- goto done;
- if (netconf_output_encap(framing, cbret) < 0)
- goto done;
- if (netconf_output(1, cbret, "rpc-error") < 0)
- goto done;
- goto ok;
+ if ((cbret = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ if (netconf_operation_failed(cbret, "rpc", "Empty XML")< 0)
+ goto done;
+ if (netconf_output_encap(framing, cbret) < 0)
+ goto done;
+ if (netconf_output(1, cbret, "rpc-error") < 0)
+ goto done;
+ goto ok;
}
/* Parse incoming XML message */
if ((ret = clixon_xml_parse_string(str, YB_RPC, yspec, &xtop, &xret)) < 0){
- if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- if (netconf_operation_failed(cbret, "rpc", clicon_err_reason)< 0)
- goto done;
- if (netconf_output_encap(framing, cbret) < 0)
- goto done;
- if (netconf_output(1, cbret, "rpc-error") < 0)
- goto done;
- goto ok;
+ if ((cbret = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ if (netconf_operation_failed(cbret, "rpc", clicon_err_reason)< 0)
+ goto done;
+ if (netconf_output_encap(framing, cbret) < 0)
+ goto done;
+ if (netconf_output(1, cbret, "rpc-error") < 0)
+ goto done;
+ goto ok;
}
if (ret == 0){
- /* Note: xtop can be "hello" in which case one (maybe) should drop the session and log
- * However, its not until netconf_input_packet that rpc vs hello vs other identification is
- * actually made.
- * Actually, there are no error replies to hello messages according to any RFC, so
- * rpc error reply here is non-standard, but may be useful.
- */
- if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- if (netconf_output_encap(framing, cbret) < 0)
- goto done;
- if (netconf_output(1, cbret, "rpc-error") < 0)
- goto done;
- goto ok;
+ /* Note: xtop can be "hello" in which case one (maybe) should drop the session and log
+ * However, its not until netconf_input_packet that rpc vs hello vs other identification is
+ * actually made.
+ * Actually, there are no error replies to hello messages according to any RFC, so
+ * rpc error reply here is non-standard, but may be useful.
+ */
+ if ((cbret = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ if (netconf_output_encap(framing, cbret) < 0)
+ goto done;
+ if (netconf_output(1, cbret, "rpc-error") < 0)
+ goto done;
+ goto ok;
}
/* Check for empty frame (no mesaages), return empty message, not clear from RFC what to do */
if (xml_child_nr_type(xtop, CX_ELMNT) == 0){
- if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- if (netconf_output_encap(framing, cbret) < 0)
- goto done;
- if (netconf_output(1, cbret, "rpc-error") < 0)
- goto done;
- goto ok;
+ if ((cbret = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ if (netconf_output_encap(framing, cbret) < 0)
+ goto done;
+ if (netconf_output(1, cbret, "rpc-error") < 0)
+ goto done;
+ goto ok;
}
/* Check for multi-messages in frame */
if (xml_child_nr_type(xtop, CX_ELMNT) != 1){
- if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- if (netconf_malformed_message(cbret, "More than one message in netconf rpc frame")< 0)
- goto done;
- if (netconf_output_encap(framing, cbret) < 0)
- goto done;
- if (netconf_output(1, cbret, "rpc-error") < 0)
- goto done;
- goto ok;
+ if ((cbret = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ if (netconf_malformed_message(cbret, "More than one message in netconf rpc frame")< 0)
+ goto done;
+ if (netconf_output_encap(framing, cbret) < 0)
+ goto done;
+ if (netconf_output(1, cbret, "rpc-error") < 0)
+ goto done;
+ goto ok;
}
if ((xreq = xml_child_i_type(xtop, 0, CX_ELMNT)) == NULL){ /* Shouldnt happen */
- clicon_err(OE_XML, EFAULT, "No xml req (shouldnt happen)");
- goto done;
+ clicon_err(OE_XML, EFAULT, "No xml req (shouldnt happen)");
+ goto done;
}
if (netconf_input_packet(h, xreq, yspec, eof) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
if (str)
- free(str);
+ free(str);
if (xtop)
- xml_free(xtop);
+ xml_free(xtop);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (cbret)
- cbuf_free(cbret);
+ cbuf_free(cbret);
return retval;
}
@@ -509,7 +509,7 @@ netconf_input_frame(clicon_handle h,
*/
static int
netconf_input_cb(int s,
- void *arg)
+ void *arg)
{
int retval = -1;
unsigned char buf[BUFSIZ]; /* from stdio.h, typically 8K */
@@ -529,99 +529,99 @@ netconf_input_cb(int s,
if (clicon_option_exists(h, NETCONF_FRAME_STATE) == 0)
frame_state = 0;
else
- if ((frame_state = clicon_option_int(h, NETCONF_FRAME_STATE)) < 0)
- goto done;
+ if ((frame_state = clicon_option_int(h, NETCONF_FRAME_STATE)) < 0)
+ goto done;
if (clicon_option_exists(h, NETCONF_FRAME_SIZE) == 0)
- frame_size = 0;
+ frame_size = 0;
else
- if ((frame_size = clicon_option_int(h, NETCONF_FRAME_SIZE)) < 0)
- goto done;
+ if ((frame_size = clicon_option_int(h, NETCONF_FRAME_SIZE)) < 0)
+ goto done;
if ((ptr = clicon_hash_value(cdat, NETCONF_HASH_BUF, &cdatlen)) != NULL){
- if (cdatlen != sizeof(cb)){
- clicon_err(OE_XML, errno, "size mismatch %lu %lu",
- (unsigned long)cdatlen, (unsigned long)sizeof(cb));
- goto done;
- }
- cb = *(cbuf**)ptr;
- clicon_hash_del(cdat, NETCONF_HASH_BUF);
+ if (cdatlen != sizeof(cb)){
+ clicon_err(OE_XML, errno, "size mismatch %lu %lu",
+ (unsigned long)cdatlen, (unsigned long)sizeof(cb));
+ goto done;
+ }
+ cb = *(cbuf**)ptr;
+ clicon_hash_del(cdat, NETCONF_HASH_BUF);
}
else{
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
}
memset(buf, 0, sizeof(buf));
while (1){
- if ((len = read(s, buf, sizeof(buf))) < 0){
- if (errno == ECONNRESET)
- len = 0; /* emulate EOF */
- else{
- clicon_log(LOG_ERR, "%s: read: %s", __FUNCTION__, strerror(errno));
- goto done;
- }
- } /* read */
- if (len == 0){ /* EOF */
- clicon_debug(1, "%s len==0, closing", __FUNCTION__);
- clixon_event_unreg_fd(s, netconf_input_cb);
- close(s);
- clixon_exit_set(1);
- goto ok;
- }
- for (i=0; i]]>", buf[i], &frame_state)){
- frame_state = 0;
- /* OK, we have an xml string from a client */
- /* Remove trailer */
- *(((char*)cbuf_get(cb)) + cbuf_len(cb) - strlen("]]>]]>")) = '\0';
- if (netconf_input_frame(h, cb, &eof) < 0 &&
- !ignore_packet_errors) // default is to ignore errors
- goto done;
- if (eof)
- goto done;
- cbuf_reset(cb);
- }
- }
- }
- /* poll==1 if more, poll==0 if none */
- if ((poll = clixon_event_poll(s)) < 0)
- goto done;
- if (poll == 0){
- /* No data to read, save data and continue on next round */
- if (cbuf_len(cb) != 0){
- if (clicon_hash_add(cdat, NETCONF_HASH_BUF, &cb, sizeof(cb)) == NULL)
- goto done;
- cb = NULL;
- }
- break;
- }
+ if ((len = read(s, buf, sizeof(buf))) < 0){
+ if (errno == ECONNRESET)
+ len = 0; /* emulate EOF */
+ else{
+ clicon_log(LOG_ERR, "%s: read: %s", __FUNCTION__, strerror(errno));
+ goto done;
+ }
+ } /* read */
+ if (len == 0){ /* EOF */
+ clicon_debug(1, "%s len==0, closing", __FUNCTION__);
+ clixon_event_unreg_fd(s, netconf_input_cb);
+ close(s);
+ clixon_exit_set(1);
+ goto ok;
+ }
+ for (i=0; i]]>", buf[i], &frame_state)){
+ frame_state = 0;
+ /* OK, we have an xml string from a client */
+ /* Remove trailer */
+ *(((char*)cbuf_get(cb)) + cbuf_len(cb) - strlen("]]>]]>")) = '\0';
+ if (netconf_input_frame(h, cb, &eof) < 0 &&
+ !ignore_packet_errors) // default is to ignore errors
+ goto done;
+ if (eof)
+ goto done;
+ cbuf_reset(cb);
+ }
+ }
+ }
+ /* poll==1 if more, poll==0 if none */
+ if ((poll = clixon_event_poll(s)) < 0)
+ goto done;
+ if (poll == 0){
+ /* No data to read, save data and continue on next round */
+ if (cbuf_len(cb) != 0){
+ if (clicon_hash_add(cdat, NETCONF_HASH_BUF, &cb, sizeof(cb)) == NULL)
+ goto done;
+ cb = NULL;
+ }
+ break;
+ }
} /* while */
ok:
clicon_option_int_set(h, NETCONF_FRAME_STATE, frame_state);
@@ -629,7 +629,7 @@ netconf_input_cb(int s,
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -639,28 +639,28 @@ netconf_input_cb(int s,
*/
static int
send_hello(clicon_handle h,
- int s,
- uint32_t id)
+ int s,
+ uint32_t id)
{
int retval = -1;
cbuf *cb;
netconf_framing_type framing;
if ((cb = cbuf_new()) == NULL){
- clicon_log(LOG_ERR, "%s: cbuf_new", __FUNCTION__);
- goto done;
+ clicon_log(LOG_ERR, "%s: cbuf_new", __FUNCTION__);
+ goto done;
}
if (netconf_hello_server(h, cb, id) < 0)
- goto done;
+ goto done;
framing = clicon_option_int(h, "netconf-framing");
if (netconf_output_encap(framing, cb) < 0)
- goto done;
+ goto done;
if (netconf_output(s, cb, "hello") < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -679,13 +679,13 @@ netconf_terminate(clicon_handle h)
clixon_plugin_module_exit(h);
clicon_rpc_close_session(h);
if ((yspec = clicon_dbspec_yang(h)) != NULL)
- ys_free(yspec);
+ ys_free(yspec);
if ((yspec = clicon_config_yang(h)) != NULL)
- ys_free(yspec);
+ ys_free(yspec);
if ((nsctx = clicon_nsctx_global_get(h)) != NULL)
- cvec_free(nsctx);
+ cvec_free(nsctx);
if ((x = clicon_conf_xml(h)) != NULL)
- xml_free(x);
+ xml_free(x);
xpath_optimize_exit();
clixon_event_exit();
clicon_handle_exit(h);
@@ -703,8 +703,8 @@ netconf_signal_init (clicon_handle h)
int retval = -1;
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
- clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
- goto done;
+ clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
+ goto done;
}
retval = 0;
done:
@@ -713,7 +713,7 @@ netconf_signal_init (clicon_handle h)
static int
timeout_fn(int s,
- void *arg)
+ void *arg)
{
clicon_err(OE_EVENTS, ETIMEDOUT, "User request timeout");
return -1;
@@ -728,27 +728,27 @@ usage(clicon_handle h,
char *argv0)
{
fprintf(stderr, "usage:%s\n"
- "where options are\n"
+ "where options are\n"
"\t-h\t\tHelp\n"
- "\t-D \tDebug level\n"
- "\t-f \tConfiguration file (mandatory)\n"
- "\t-E \tExtra configuration file directory\n"
- "\t-l > \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (syslog is default)\n"
+ "\t-D \tDebug level\n"
+ "\t-f \tConfiguration file (mandatory)\n"
+ "\t-E \tExtra configuration file directory\n"
+ "\t-l > \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (syslog is default)\n"
"\t-q\t\tServer does not send hello message on startup\n"
- "\t-0 \t\tSet netconf base capability to 0, server does not expect hello, force EOM framing\n"
- "\t-1 \t\tSet netconf base capability to 1, server does not expect hello, force chunked framing\n"
- "\t-a UNIX|IPv4|IPv6 Internal backend socket family\n"
- "\t-u \tInternal socket domain path or IP addr (see -a)\n"
- "\t-d \tSpecify netconf plugin directory dir (default: %s)\n"
- "\t-p \tAdd Yang directory path (see CLICON_YANG_DIR)\n"
- "\t-y \tLoad yang spec file (override yang main module)\n"
- "\t-U \tOver-ride unix user with a pseudo user for NACM.\n"
- "\t-t \tTimeout in seconds. Quit after this time.\n"
- "\t-e \t\tDont ignore errors on packet input.\n"
- "\t-o \"=\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
- argv0,
- clicon_netconf_dir(h)
- );
+ "\t-0 \t\tSet netconf base capability to 0, server does not expect hello, force EOM framing\n"
+ "\t-1 \t\tSet netconf base capability to 1, server does not expect hello, force chunked framing\n"
+ "\t-a UNIX|IPv4|IPv6 Internal backend socket family\n"
+ "\t-u \tInternal socket domain path or IP addr (see -a)\n"
+ "\t-d \tSpecify netconf plugin directory dir (default: %s)\n"
+ "\t-p \tAdd Yang directory path (see CLICON_YANG_DIR)\n"
+ "\t-y \tLoad yang spec file (override yang main module)\n"
+ "\t-U \tOver-ride unix user with a pseudo user for NACM.\n"
+ "\t-t \tTimeout in seconds. Quit after this time.\n"
+ "\t-e \t\tDont ignore errors on packet input.\n"
+ "\t-o \"=\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
+ argv0,
+ clicon_netconf_dir(h)
+ );
exit(0);
}
@@ -776,45 +776,45 @@ main(int argc,
/* Create handle */
if ((h = clicon_handle_init()) == NULL)
- return -1;
+ return -1;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
/* Set username to clixon handle. Use in all communication to backend */
if ((pw = getpwuid(getuid())) == NULL){
- clicon_err(OE_UNIX, errno, "getpwuid");
- goto done;
+ clicon_err(OE_UNIX, errno, "getpwuid");
+ goto done;
}
if (clicon_username_set(h, pw->pw_name) < 0)
- goto done;
+ goto done;
while ((c = getopt(argc, argv, NETCONF_OPTS)) != -1)
- switch (c) {
- case 'h' : /* help */
- usage(h, argv[0]);
- break;
- case 'D' : /* debug */
- if (sscanf(optarg, "%d", &dbg) != 1)
- usage(h, argv[0]);
- break;
- case 'f': /* override config file */
- if (!strlen(optarg))
- usage(h, argv[0]);
- clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
- break;
- case 'E': /* extra config directory */
- if (!strlen(optarg))
- usage(h, argv[0]);
- clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
- break;
- case 'l': /* Log destination: s|e|o */
- if ((logdst = clicon_log_opt(optarg[0])) < 0)
- usage(h, argv[0]);
- if (logdst == CLICON_LOG_FILE &&
- strlen(optarg)>1 &&
- clicon_log_file(optarg+1) < 0)
- goto done;
- break;
- }
+ switch (c) {
+ case 'h' : /* help */
+ usage(h, argv[0]);
+ break;
+ case 'D' : /* debug */
+ if (sscanf(optarg, "%d", &dbg) != 1)
+ usage(h, argv[0]);
+ break;
+ case 'f': /* override config file */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
+ break;
+ case 'E': /* extra config directory */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
+ break;
+ case 'l': /* Log destination: s|e|o */
+ if ((logdst = clicon_log_opt(optarg[0])) < 0)
+ usage(h, argv[0]);
+ if (logdst == CLICON_LOG_FILE &&
+ strlen(optarg)>1 &&
+ clicon_log_file(optarg+1) < 0)
+ goto done;
+ break;
+ }
/*
* Logs, error and debug to stderr or syslog, set debug level
@@ -825,77 +825,77 @@ main(int argc,
/* Find, read and parse configfile */
if (clicon_options_main(h) < 0)
- goto done;
+ goto done;
/* Now rest of options */
optind = 1;
opterr = 0;
while ((c = getopt(argc, argv, NETCONF_OPTS)) != -1)
- switch (c) {
- case 'h' : /* help */
- case 'D' : /* debug */
- case 'f': /* config file */
- case 'E': /* extra config dir */
- case 'l': /* log */
- break; /* see above */
- case 'q': /* quiet: dont write hello */
- quiet++;
- break;
- case 'a': /* internal backend socket address family */
- clicon_option_str_set(h, "CLICON_SOCK_FAMILY", optarg);
- break;
- case 'u': /* internal backend socket unix domain path or ip host */
- if (!strlen(optarg))
- usage(h, argv[0]);
- clicon_option_str_set(h, "CLICON_SOCK", optarg);
- break;
- case 'd': /* Plugin directory */
- if (!strlen(optarg))
- usage(h, argv[0]);
- if (clicon_option_add(h, "CLICON_NETCONF_DIR", optarg) < 0)
- goto done;
- break;
- case 'p' : /* yang dir path */
- if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
- goto done;
- break;
- case 'y' : /* Load yang spec file (override yang main module) */
- if (clicon_option_add(h, "CLICON_YANG_MAIN_FILE", optarg) < 0)
- goto done;
- break;
- case 'U': /* Clixon 'pseudo' user */
- if (!strlen(optarg))
- usage(h, argv[0]);
- if (clicon_username_set(h, optarg) < 0)
- goto done;
- break;
- case 't': /* timeout in seconds */
- tv.tv_sec = atoi(optarg);
- break;
- case 'e': /* dont ignore packet errors */
- ignore_packet_errors = 0;
- break;
- case '0': /* Force EOM */
- clicon_option_int_set(h, "CLICON_NETCONF_BASE_CAPABILITY", 0);
- clicon_option_bool_set(h, "CLICON_NETCONF_HELLO_OPTIONAL", 1);
- break;
- case '1': /* Hello messages are optional */
- clicon_option_int_set(h, "CLICON_NETCONF_BASE_CAPABILITY", 1);
- clicon_option_bool_set(h, "CLICON_NETCONF_HELLO_OPTIONAL", 1);
- break;
- case 'o':{ /* Configuration option */
- char *val;
- if ((val = index(optarg, '=')) == NULL)
- usage(h, argv0);
- *val++ = '\0';
- if (clicon_option_add(h, optarg, val) < 0)
- goto done;
- break;
- }
- default:
- usage(h, argv[0]);
- break;
- }
+ switch (c) {
+ case 'h' : /* help */
+ case 'D' : /* debug */
+ case 'f': /* config file */
+ case 'E': /* extra config dir */
+ case 'l': /* log */
+ break; /* see above */
+ case 'q': /* quiet: dont write hello */
+ quiet++;
+ break;
+ case 'a': /* internal backend socket address family */
+ clicon_option_str_set(h, "CLICON_SOCK_FAMILY", optarg);
+ break;
+ case 'u': /* internal backend socket unix domain path or ip host */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ clicon_option_str_set(h, "CLICON_SOCK", optarg);
+ break;
+ case 'd': /* Plugin directory */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ if (clicon_option_add(h, "CLICON_NETCONF_DIR", optarg) < 0)
+ goto done;
+ break;
+ case 'p' : /* yang dir path */
+ if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
+ goto done;
+ break;
+ case 'y' : /* Load yang spec file (override yang main module) */
+ if (clicon_option_add(h, "CLICON_YANG_MAIN_FILE", optarg) < 0)
+ goto done;
+ break;
+ case 'U': /* Clixon 'pseudo' user */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ if (clicon_username_set(h, optarg) < 0)
+ goto done;
+ break;
+ case 't': /* timeout in seconds */
+ tv.tv_sec = atoi(optarg);
+ break;
+ case 'e': /* dont ignore packet errors */
+ ignore_packet_errors = 0;
+ break;
+ case '0': /* Force EOM */
+ clicon_option_int_set(h, "CLICON_NETCONF_BASE_CAPABILITY", 0);
+ clicon_option_bool_set(h, "CLICON_NETCONF_HELLO_OPTIONAL", 1);
+ break;
+ case '1': /* Hello messages are optional */
+ clicon_option_int_set(h, "CLICON_NETCONF_BASE_CAPABILITY", 1);
+ clicon_option_bool_set(h, "CLICON_NETCONF_HELLO_OPTIONAL", 1);
+ break;
+ case 'o':{ /* Configuration option */
+ char *val;
+ if ((val = index(optarg, '=')) == NULL)
+ usage(h, argv0);
+ *val++ = '\0';
+ if (clicon_option_add(h, optarg, val) < 0)
+ goto done;
+ break;
+ }
+ default:
+ usage(h, argv[0]);
+ break;
+ }
argc -= optind;
argv += optind;
@@ -908,7 +908,7 @@ main(int argc,
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
- clicon_log_string_limit_set(sz);
+ clicon_log_string_limit_set(sz);
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
xml_nsctx_namespace_netconf_default(h);
@@ -917,65 +917,65 @@ main(int argc,
* Otherwise it is loaded in netconf_module_load below
*/
if (netconf_module_features(h) < 0)
- goto done;
+ goto done;
/* Setup signal handlers, int particular PIPE that occurs if backend closes / restarts */
if (netconf_signal_init(h) < 0)
- goto done;
+ goto done;
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
- goto done;
+ goto done;
/* In case ietf-yang-metadata is loaded by application, handle annotation extension */
if (yang_metadata_init(h) < 0)
- goto done;
+ goto done;
/* Create top-level yang spec and store as option */
if ((yspec = yspec_new()) == NULL)
- goto done;
- clicon_dbspec_yang_set(h, yspec);
+ goto done;
+ clicon_dbspec_yang_set(h, yspec);
/* Load netconf plugins before yangs are loaded (eg extension callbacks) */
if ((dir = clicon_netconf_dir(h)) != NULL &&
- clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
- goto done;
+ clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
+ goto done;
/* Load Yang modules
* 1. Load a yang module as a specific absolute filename */
if ((str = clicon_yang_main_file(h)) != NULL){
- if (yang_spec_parse_file(h, str, yspec) < 0)
- goto done;
+ if (yang_spec_parse_file(h, str, yspec) < 0)
+ goto done;
}
/* 2. Load a (single) main module */
if ((str = clicon_yang_module_main(h)) != NULL){
- if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
- yspec) < 0)
- goto done;
+ if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
+ yspec) < 0)
+ goto done;
}
/* 3. Load all modules in a directory */
if ((str = clicon_yang_main_dir(h)) != NULL){
- if (yang_spec_load_dir(h, str, yspec) < 0)
- goto done;
+ if (yang_spec_load_dir(h, str, yspec) < 0)
+ goto done;
}
/* Load clixon lib yang module */
if (yang_spec_parse_module(h, "clixon-lib", NULL, yspec) < 0)
- goto done;
+ goto done;
/* Load yang module library, RFC7895 */
if (yang_modules_init(h) < 0)
- goto done;
+ goto done;
/* Add netconf yang spec, used by netconf client and as internal protocol */
if (netconf_module_load(h) < 0)
- goto done;
+ goto done;
/* Here all modules are loaded
* Compute and set canonical namespace context
*/
if (xml_nsctx_yangspec(yspec, &nsctx_global) < 0)
- goto done;
+ goto done;
if (clicon_nsctx_global_set(h, nsctx_global) < 0)
- goto done;
+ goto done;
/* Call start function is all plugins before we go interactive */
if (clixon_plugin_start_all(h) < 0)
- goto done;
+ goto done;
#if 1
/* XXX get session id from backend hello */
clicon_session_id_set(h, getpid());
@@ -987,7 +987,7 @@ main(int argc,
* each message sent to the backend.
*/
if (clicon_hello_req(h, &id) < 0)
- goto done;
+ goto done;
clicon_session_id_set(h, id);
/* Send hello to northbound client
@@ -995,31 +995,31 @@ main(int argc,
* When the NETCONF session is opened, each peer(both client and server) MUST send a "
- "operation-failed "
- "application "
- "error "
- "filtering "
- " ",
- NETCONF_BASE_NAMESPACE
- );
+ clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, ""
+ "operation-failed "
+ "application "
+ "error "
+ "filtering "
+ " ",
+ NETCONF_BASE_NAMESPACE
+ );
}
ok:
retval = 0;
@@ -114,20 +114,20 @@ ok:
* better performance and tested. Please use xpath.
*
*
- *
- * |
- *
+ *
+ * |
+ *
*
*
*
- *
- * |
- *
- *
- *
- *
- *
- *
+ *
+ * |
+ *
+ *
+ *
+ *
+ *
+ *
*
*
* Example:
@@ -156,8 +156,8 @@ ok:
*/
static int
netconf_get_config(clicon_handle h,
- cxobj *xn,
- cxobj **xret)
+ cxobj *xn,
+ cxobj **xret)
{
int retval = -1;
cxobj *xfilter; /* filter */
@@ -223,46 +223,46 @@ netconf_get_config(clicon_handle h,
*/
static int
get_edit_opts(cxobj *xn,
- enum test_option *testopt,
- enum error_option *erropt,
- cxobj **xret)
+ enum test_option *testopt,
+ enum error_option *erropt,
+ cxobj **xret)
{
int retval = -1;
cxobj *x;
char *optstr;
if ((x = xpath_first(xn, NULL, "test-option")) != NULL){
- if ((optstr = xml_body(x)) != NULL){
- if (strcmp(optstr, "test-then-set") == 0)
- *testopt = TEST_THEN_SET;
- else if (strcmp(optstr, "set") == 0)
- *testopt = SET;
- else if (strcmp(optstr, "test-only") == 0)
- *testopt = TEST_ONLY;
- else
- goto parerr;
- }
+ if ((optstr = xml_body(x)) != NULL){
+ if (strcmp(optstr, "test-then-set") == 0)
+ *testopt = TEST_THEN_SET;
+ else if (strcmp(optstr, "set") == 0)
+ *testopt = SET;
+ else if (strcmp(optstr, "test-only") == 0)
+ *testopt = TEST_ONLY;
+ else
+ goto parerr;
+ }
}
if ((x = xpath_first(xn, NULL, "error-option")) != NULL){
- if ((optstr = xml_body(x)) != NULL){
- if (strcmp(optstr, "stop-on-error") == 0)
- *erropt = STOP_ON_ERROR;
- else
- if (strcmp(optstr, "continue-on-error") == 0)
- *erropt = CONTINUE_ON_ERROR;
- else
- goto parerr;
- }
+ if ((optstr = xml_body(x)) != NULL){
+ if (strcmp(optstr, "stop-on-error") == 0)
+ *erropt = STOP_ON_ERROR;
+ else
+ if (strcmp(optstr, "continue-on-error") == 0)
+ *erropt = CONTINUE_ON_ERROR;
+ else
+ goto parerr;
+ }
}
retval = 1; /* hunky dory */
return retval;
parerr: /* parameter error, xret set */
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, ""
- "invalid-value "
- "protocol "
- "error "
- " ",
- NETCONF_BASE_NAMESPACE);
+ "invalid-value "
+ "protocol "
+ "error "
+ "",
+ NETCONF_BASE_NAMESPACE);
return 0;
}
@@ -317,8 +317,8 @@ CLIXON addition:
*/
static int
netconf_edit_config(clicon_handle h,
- cxobj *xn,
- cxobj **xret)
+ cxobj *xn,
+ cxobj **xret)
{
int retval = -1;
int optret;
@@ -326,25 +326,25 @@ netconf_edit_config(clicon_handle h,
enum error_option erropt = STOP_ON_ERROR; /* only supports this */
if ((optret = get_edit_opts(xn, &testopt, &erropt, xret)) < 0)
- goto done;
+ goto done;
if (optret == 0) /* error in opt parameters */
- goto ok;
+ goto ok;
/* These constraints are clixon-specific since :validate should
* support all testopts, and erropts should be supported
* And therefore extends the validation
* (implement the features before removing these checks)
*/
if (testopt!=TEST_THEN_SET || erropt!=STOP_ON_ERROR){
- clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, ""
- "operation-not-supported "
- "protocol "
- "error "
- " ",
- NETCONF_BASE_NAMESPACE);
- goto ok;
+ clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, ""
+ "operation-not-supported "
+ "protocol "
+ "error "
+ " ",
+ NETCONF_BASE_NAMESPACE);
+ goto ok;
}
if (clicon_rpc_netconf_xml(h, xml_parent(xn), xret, NULL) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
@@ -365,8 +365,8 @@ netconf_edit_config(clicon_handle h,
*/
static int
netconf_get(clicon_handle h,
- cxobj *xn,
- cxobj **xret)
+ cxobj *xn,
+ cxobj **xret)
{
int retval = -1;
cxobj *xfilter; /* filter */
@@ -409,7 +409,7 @@ netconf_get(clicon_handle h,
retval = 0;
done:
if(nsc)
- cvec_free(nsc);
+ cvec_free(nsc);
return retval;
}
@@ -437,7 +437,7 @@ netconf_get(clicon_handle h,
*/
static int
netconf_notification_cb(int s,
- void *arg)
+ void *arg)
{
struct clicon_msg *reply = NULL;
int eof;
@@ -454,43 +454,43 @@ netconf_notification_cb(int s,
clicon_debug(1, "%s", __FUNCTION__);
/* get msg (this is the reason this function is called) */
if (clicon_msg_rcv(s, &reply, &eof) < 0)
- goto done;
+ goto done;
/* handle close from remote end: this will exit the client */
if (eof){
- clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
- close(s);
- errno = ESHUTDOWN;
- clixon_event_unreg_fd(s, netconf_notification_cb);
- goto done;
+ clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
+ close(s);
+ errno = ESHUTDOWN;
+ clixon_event_unreg_fd(s, netconf_notification_cb);
+ goto done;
}
yspec = clicon_dbspec_yang(h);
if ((ret = clicon_msg_decode(reply, yspec, NULL, &xt, &xerr)) < 0)
- goto done;
+ goto done;
if (ret == 0){ /* XXX use xerr */
- clicon_err(OE_NETCONF, EFAULT, "Notification malformed");
- goto done;
+ clicon_err(OE_NETCONF, EFAULT, "Notification malformed");
+ goto done;
}
if ((nsc = xml_nsctx_init(NULL, NOTIFICATION_RFC5277_NAMESPACE)) == NULL)
- goto done;
+ goto done;
if ((xn = xpath_first(xt, nsc, "notification")) == NULL)
- goto ok;
+ goto ok;
/* create netconf message */
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_PLUGIN, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_PLUGIN, errno, "cbuf_new");
+ goto done;
}
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
/* Send it to listening client on stdout */
if (netconf_output_encap(clicon_option_int(h, "netconf-framing"), cb) < 0){
- goto done;
+ goto done;
}
if (netconf_output(1, cb, "notification") < 0){
- clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
- close(s);
- errno = ESHUTDOWN;
- clixon_event_unreg_fd(s, netconf_notification_cb);
- goto done;
+ clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
+ close(s);
+ errno = ESHUTDOWN;
+ clixon_event_unreg_fd(s, netconf_notification_cb);
+ goto done;
}
fflush(stdout);
ok:
@@ -498,15 +498,15 @@ netconf_notification_cb(int s,
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (xt != NULL)
- xml_free(xt);
+ xml_free(xt);
if (xerr != NULL)
- xml_free(xerr);
+ xml_free(xerr);
if (reply)
- free(reply);
+ free(reply);
return retval;
}
@@ -525,8 +525,8 @@ netconf_notification_cb(int s,
*/
static int
netconf_create_subscription(clicon_handle h,
- cxobj *xn,
- cxobj **xret)
+ cxobj *xn,
+ cxobj **xret)
{
int retval = -1;
cxobj *xfilter;
@@ -534,29 +534,29 @@ netconf_create_subscription(clicon_handle h,
char *ftype;
if ((xfilter = xpath_first(xn, NULL, "//filter")) != NULL){
- if ((ftype = xml_find_value(xfilter, "type")) != NULL){
- if (strcmp(ftype, "xpath") != 0){
- clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, ""
- "operation-failed "
- "application "
- "error "
- "only xpath filter type supported "
- "type "
- " ",
- NETCONF_BASE_NAMESPACE);
- goto ok;
- }
- }
+ if ((ftype = xml_find_value(xfilter, "type")) != NULL){
+ if (strcmp(ftype, "xpath") != 0){
+ clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, ""
+ "operation-failed "
+ "application "
+ "error "
+ "only xpath filter type supported "
+ "type "
+ " ",
+ NETCONF_BASE_NAMESPACE);
+ goto ok;
+ }
+ }
}
if (clicon_rpc_netconf_xml(h, xml_parent(xn), xret, &s) < 0)
- goto done;
+ goto done;
if (xpath_first(*xret, NULL, "rpc-reply/rpc-error") != NULL)
- goto ok;
+ goto ok;
if (clixon_event_reg_fd(s,
- netconf_notification_cb,
- h,
- "notification socket") < 0)
- goto done;
+ netconf_notification_cb,
+ h,
+ "notification socket") < 0)
+ goto done;
ok:
retval = 0;
done:
@@ -579,8 +579,8 @@ netconf_create_subscription(clicon_handle h,
*/
static int
netconf_application_rpc(clicon_handle h,
- cxobj *xn,
- cxobj **xret)
+ cxobj *xn,
+ cxobj **xret)
{
int retval = -1;
yang_stmt *yspec = NULL; /* application yspec */
@@ -596,85 +596,85 @@ netconf_application_rpc(clicon_handle h,
/* First check system / netconf RPC:s */
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, 0, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, 0, "cbuf_new");
+ goto done;
}
if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, 0, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, 0, "cbuf_new");
+ goto done;
}
/* Find yang rpc statement, return yang rpc statement if found
Check application RPC */
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No yang spec");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "No yang spec");
+ goto done;
}
cbuf_reset(cb);
if (ys_module_by_xml(yspec, xn, &ymod) < 0)
- goto done;
+ goto done;
if (ymod == NULL){
- clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, ""
- "operation-failed "
- "rpc "
- "error "
- "%s "
- "Not recognized module "
- " ",
- NETCONF_BASE_NAMESPACE, xml_name(xn));
- goto ok;
+ clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, ""
+ "operation-failed "
+ "rpc "
+ "error "
+ "%s "
+ "Not recognized module "
+ " ",
+ NETCONF_BASE_NAMESPACE, xml_name(xn));
+ goto ok;
}
yrpc = yang_find(ymod, Y_RPC, xml_name(xn));
/* Check if found */
if (yrpc != NULL){
- /* No need to check xn arguments with input statement since already bound and validated. */
- /* Look for local (client-side) netconf plugins. */
- if ((ret = rpc_callback_call(h, xn, NULL, &nr, cbret)) < 0)
- goto done;
- if (ret == 0){
- if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, xret, NULL) < 0)
- goto done;
- }
- else if (nr > 0){ /* Handled locally */
- if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, xret, NULL) < 0)
- goto done;
- }
- else /* Send to backend */
- if (clicon_rpc_netconf_xml(h, xml_parent(xn), xret, NULL) < 0)
- goto done;
- /* Sanity check of outgoing XML
- * For now, skip outgoing checks.
- * (1) Does not handle properly
- * (2) Uncertain how validation errors should be logged/handled
- */
- if (0)
- if ((youtput = yang_find(yrpc, Y_OUTPUT, NULL)) != NULL){
- xoutput=xpath_first(*xret, NULL, "/");
- xml_spec_set(xoutput, youtput); /* needed for xml_bind_yang */
- if ((ret = xml_bind_yang(xoutput, YB_MODULE, yspec, &xerr)) < 0)
- goto done;
- if (ret > 0 && (ret = xml_yang_validate_all_top(h, xoutput, &xerr)) < 0)
- goto done;
- if (ret > 0 && (ret = xml_yang_validate_add(h, xoutput, &xerr)) < 0)
- goto done;
- if (ret == 0){
- if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
- goto done;
- clicon_log(LOG_WARNING, "Errors in output netconf %s", cbuf_get(cbret));
- goto ok;
- }
- }
- retval = 1; /* handled by callback */
- goto done;
+ /* No need to check xn arguments with input statement since already bound and validated. */
+ /* Look for local (client-side) netconf plugins. */
+ if ((ret = rpc_callback_call(h, xn, NULL, &nr, cbret)) < 0)
+ goto done;
+ if (ret == 0){
+ if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, xret, NULL) < 0)
+ goto done;
+ }
+ else if (nr > 0){ /* Handled locally */
+ if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, xret, NULL) < 0)
+ goto done;
+ }
+ else /* Send to backend */
+ if (clicon_rpc_netconf_xml(h, xml_parent(xn), xret, NULL) < 0)
+ goto done;
+ /* Sanity check of outgoing XML
+ * For now, skip outgoing checks.
+ * (1) Does not handle properly
+ * (2) Uncertain how validation errors should be logged/handled
+ */
+ if (0)
+ if ((youtput = yang_find(yrpc, Y_OUTPUT, NULL)) != NULL){
+ xoutput=xpath_first(*xret, NULL, "/");
+ xml_spec_set(xoutput, youtput); /* needed for xml_bind_yang */
+ if ((ret = xml_bind_yang(xoutput, YB_MODULE, yspec, &xerr)) < 0)
+ goto done;
+ if (ret > 0 && (ret = xml_yang_validate_all_top(h, xoutput, &xerr)) < 0)
+ goto done;
+ if (ret > 0 && (ret = xml_yang_validate_add(h, xoutput, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
+ goto done;
+ clicon_log(LOG_WARNING, "Errors in output netconf %s", cbuf_get(cbret));
+ goto ok;
+ }
+ }
+ retval = 1; /* handled by callback */
+ goto done;
}
ok:
retval = 0;
done:
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (cbret)
- cbuf_free(cbret);
+ cbuf_free(cbret);
return retval;
}
@@ -690,9 +690,9 @@ netconf_application_rpc(clicon_handle h,
*/
int
netconf_rpc_dispatch(clicon_handle h,
- cxobj *xn,
- cxobj **xret,
- int *eof)
+ cxobj *xn,
+ cxobj **xret,
+ int *eof)
{
int retval = -1;
cxobj *xe;
@@ -704,10 +704,10 @@ netconf_rpc_dispatch(clicon_handle h,
* It may even be wrong if something else is done with the incoming message?
*/
if ((username = clicon_username_get(h)) != NULL){
- if ((xa = xml_new("username", xn, CX_ATTR)) == NULL)
- goto done;
- if (xml_value_set(xa, username) < 0)
- goto done;
+ if ((xa = xml_new("username", xn, CX_ATTR)) == NULL)
+ goto done;
+ if (xml_value_set(xa, username) < 0)
+ goto done;
}
/* Many of these calls are now calling generic clicon_rpc_netconf_xml
* directly, since the validation is generic and done before this place
@@ -716,65 +716,65 @@ netconf_rpc_dispatch(clicon_handle h,
*/
xe = NULL;
while ((xe = xml_child_each(xn, xe, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(xe), "copy-config") == 0 ||
- strcmp(xml_name(xe), "delete-config") == 0 ||
- strcmp(xml_name(xe), "lock") == 0 ||
- strcmp(xml_name(xe), "unlock") == 0 ||
- strcmp(xml_name(xe), "kill-session") == 0 ||
- strcmp(xml_name(xe), "validate") == 0 || /* :validate */
- strcmp(xml_name(xe), "commit") == 0 || /* :candidate */
- strcmp(xml_name(xe), "cancel-commit") == 0 ||
- strcmp(xml_name(xe), "discard-changes") == 0 ||
- strcmp(xml_name(xe), "action") == 0
- ){
- if (clicon_rpc_netconf_xml(h, xml_parent(xe), xret, NULL) < 0)
- goto done;
- }
- else if (strcmp(xml_name(xe), "get-config") == 0){
- if (netconf_get_config(h, xe, xret) < 0)
- goto done;
- }
- else if (strcmp(xml_name(xe), "edit-config") == 0){
- if (netconf_edit_config(h, xe, xret) < 0)
- goto done;
- }
- else if (strcmp(xml_name(xe), "get") == 0){
- if (netconf_get(h, xe, xret) < 0)
- goto done;
- }
- else if (strcmp(xml_name(xe), "close-session") == 0){
- *eof = 1; /* Pending close */
- if (clicon_rpc_netconf_xml(h, xml_parent(xe), xret, NULL) < 0)
- goto done;
- }
- /* RFC 5277 :notification */
- else if (strcmp(xml_name(xe), "create-subscription") == 0){
- if (netconf_create_subscription(h, xe, xret) < 0)
- goto done;
- }
- /* Others */
- else {
- /* Look for application-defined RPC. This may either be local
- client-side or backend. If backend send as netconf RPC. */
- if ((retval = netconf_application_rpc(h, xe, xret)) < 0)
- goto done;
- if (retval == 0){ /* not handled by callback */
- clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, ""
- "operation-failed "
- "rpc "
- "error "
- "%s "
- "Not recognized "
- " ",
- NETCONF_BASE_NAMESPACE, xml_name(xe));
- goto done;
- }
- }
+ if (strcmp(xml_name(xe), "copy-config") == 0 ||
+ strcmp(xml_name(xe), "delete-config") == 0 ||
+ strcmp(xml_name(xe), "lock") == 0 ||
+ strcmp(xml_name(xe), "unlock") == 0 ||
+ strcmp(xml_name(xe), "kill-session") == 0 ||
+ strcmp(xml_name(xe), "validate") == 0 || /* :validate */
+ strcmp(xml_name(xe), "commit") == 0 || /* :candidate */
+ strcmp(xml_name(xe), "cancel-commit") == 0 ||
+ strcmp(xml_name(xe), "discard-changes") == 0 ||
+ strcmp(xml_name(xe), "action") == 0
+ ){
+ if (clicon_rpc_netconf_xml(h, xml_parent(xe), xret, NULL) < 0)
+ goto done;
+ }
+ else if (strcmp(xml_name(xe), "get-config") == 0){
+ if (netconf_get_config(h, xe, xret) < 0)
+ goto done;
+ }
+ else if (strcmp(xml_name(xe), "edit-config") == 0){
+ if (netconf_edit_config(h, xe, xret) < 0)
+ goto done;
+ }
+ else if (strcmp(xml_name(xe), "get") == 0){
+ if (netconf_get(h, xe, xret) < 0)
+ goto done;
+ }
+ else if (strcmp(xml_name(xe), "close-session") == 0){
+ *eof = 1; /* Pending close */
+ if (clicon_rpc_netconf_xml(h, xml_parent(xe), xret, NULL) < 0)
+ goto done;
+ }
+ /* RFC 5277 :notification */
+ else if (strcmp(xml_name(xe), "create-subscription") == 0){
+ if (netconf_create_subscription(h, xe, xret) < 0)
+ goto done;
+ }
+ /* Others */
+ else {
+ /* Look for application-defined RPC. This may either be local
+ client-side or backend. If backend send as netconf RPC. */
+ if ((retval = netconf_application_rpc(h, xe, xret)) < 0)
+ goto done;
+ if (retval == 0){ /* not handled by callback */
+ clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, ""
+ "operation-failed "
+ "rpc "
+ "error "
+ "%s "
+ "Not recognized "
+ " ",
+ NETCONF_BASE_NAMESPACE, xml_name(xe));
+ goto done;
+ }
+ }
}
retval = 0;
done:
/* Username attribute added at top - otherwise it is returned to sender */
if ((xa = xml_find(xn, "username")) != NULL)
- xml_purge(xa);
+ xml_purge(xa);
return retval;
}
diff --git a/apps/netconf/netconf_rpc.h b/apps/netconf/netconf_rpc.h
index e4f3a416..348837e6 100644
--- a/apps/netconf/netconf_rpc.h
+++ b/apps/netconf/netconf_rpc.h
@@ -44,8 +44,8 @@
*/
int
netconf_rpc_dispatch(clicon_handle h,
- cxobj *xn,
- cxobj **xret,
- int *eof);
+ cxobj *xn,
+ cxobj **xret,
+ int *eof);
#endif /* _NETCONF_RPC_H_ */
diff --git a/apps/restconf/README.md b/apps/restconf/README.md
index dfe02905..c985400d 100644
--- a/apps/restconf/README.md
+++ b/apps/restconf/README.md
@@ -4,7 +4,7 @@
* [Nginx](#nginx)
* [Streams](#streams)
* [Nchan Streams](#nchan)
- * [Debugging](#debugging)
+ * [Debugging](#debugging)
There are two installation instructions: for native and nginx.
@@ -135,11 +135,11 @@ You may access a restconf streams using curl.
Add the following to extend the nginx configuration file with the following statements (for example):
```
- location /streams {
- fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
- include fastcgi_params;
- proxy_http_version 1.1;
- proxy_set_header Connection "";
+ location /streams {
+ fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
+ include fastcgi_params;
+ proxy_http_version 1.1;
+ proxy_set_header Connection "";
}
```
diff --git a/apps/restconf/clixon_http1_parse.h b/apps/restconf/clixon_http1_parse.h
index f0afd189..07e99f18 100644
--- a/apps/restconf/clixon_http1_parse.h
+++ b/apps/restconf/clixon_http1_parse.h
@@ -67,4 +67,4 @@ int clixon_http1_parselex(void *);
int clixon_http1_parseparse(void *);
void clixon_http1_parseerror(void *, char*);
-#endif /* _CLIXON_HTTP1_PARSE_H_ */
+#endif /* _CLIXON_HTTP1_PARSE_H_ */
diff --git a/apps/restconf/clixon_http1_parse.y b/apps/restconf/clixon_http1_parse.y
index 888a0b8e..cd869f8d 100644
--- a/apps/restconf/clixon_http1_parse.y
+++ b/apps/restconf/clixon_http1_parse.y
@@ -122,13 +122,13 @@
void
clixon_http1_parseerror(void *_hy,
- char *s)
+ char *s)
{
clicon_err(OE_RESTCONF, 0, "%s on line %d: %s at or before: '%s'",
- _HY->hy_name,
- _HY->hy_linenum ,
- s,
- clixon_http1_parsetext);
+ _HY->hy_name,
+ _HY->hy_linenum ,
+ s,
+ clixon_http1_parsetext);
return;
}
@@ -146,18 +146,18 @@ http1_parse_exit(clixon_http1_yacc *hy)
static int
http1_parse_query(clixon_http1_yacc *hy,
- char *query)
+ char *query)
{
int retval = -1;
restconf_stream_data *sd = NULL;
clicon_debug(1, "%s: ?%s ", __FUNCTION__, query);
if ((sd = restconf_stream_find(hy->hy_rc, 0)) == NULL){
- clicon_err(OE_RESTCONF, 0, "stream 0 not found");
- goto done;
+ clicon_err(OE_RESTCONF, 0, "stream 0 not found");
+ goto done;
}
if (uri_str2cvec(query, '&', '=', 1, &sd->sd_qvec) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -165,19 +165,19 @@ http1_parse_query(clixon_http1_yacc *hy,
static int
http1_body(clixon_http1_yacc *hy,
- char *body)
+ char *body)
{
int retval = -1;
restconf_stream_data *sd = NULL;
clicon_debug(1, "%s: %s ", __FUNCTION__, body);
if ((sd = restconf_stream_find(hy->hy_rc, 0)) == NULL){
- clicon_err(OE_RESTCONF, 0, "stream 0 not found");
- goto done;
+ clicon_err(OE_RESTCONF, 0, "stream 0 not found");
+ goto done;
}
if (cbuf_append_buf(sd->sd_indata, body, strlen(body)) < 0){
- clicon_err(OE_RESTCONF, errno, "cbuf_append_buf");
- goto done;
+ clicon_err(OE_RESTCONF, errno, "cbuf_append_buf");
+ goto done;
}
retval = 0;
done:
@@ -188,13 +188,13 @@ http1_body(clixon_http1_yacc *hy,
*/
static int
http1_parse_header_field(clixon_http1_yacc *hy,
- char *name,
- char *field)
+ char *name,
+ char *field)
{
int retval = -1;
if (restconf_convert_hdr(hy->hy_h, name, field) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -209,34 +209,34 @@ http1_parse_header_field(clixon_http1_yacc *hy,
*/
http_message : request_line header_fields CRLF body X_EOF
{
- if ($4) {
- if (http1_body(_HY, $4) < 0) YYABORT;
- free($4);
- }
- _PARSE_DEBUG("http-message -> request-line header-fields body");
- YYACCEPT;
- }
+ if ($4) {
+ if (http1_body(_HY, $4) < 0) YYABORT;
+ free($4);
+ }
+ _PARSE_DEBUG("http-message -> request-line header-fields body");
+ YYACCEPT;
+ }
;
body : body BODY
{
- if (($$ = clixon_string_del_join($1, "", $2)) == NULL) {
- free($2);
- YYABORT;
- }
- else
- free($2);
- _PARSE_DEBUG("body -> body BODY");
- }
+ if (($$ = clixon_string_del_join($1, "", $2)) == NULL) {
+ free($2);
+ YYABORT;
+ }
+ else
+ free($2);
+ _PARSE_DEBUG("body -> body BODY");
+ }
| ERROR { _PARSE_DEBUG("body -> ERROR"); YYABORT; /* shouldnt happen */ }
- | { _PARSE_DEBUG("body -> "); $$ = NULL; }
+ | { _PARSE_DEBUG("body -> "); $$ = NULL; }
;
/* request-line = method SP request-target SP HTTP-version CRLF */
request_line : method SP request_target SP HTTP_version CRLF
{
- _PARSE_DEBUG("request-line -> method request-target HTTP_version CRLF");
- }
+ _PARSE_DEBUG("request-line -> method request-target HTTP_version CRLF");
+ }
;
/*
@@ -246,11 +246,11 @@ The request methods defined by this specification can be found in
*/
method : TOKEN
{
- if (restconf_param_set(_HY->hy_h, "REQUEST_METHOD", $1) < 0)
- YYABORT;
- free($1);
- _PARSE_DEBUG("method -> TOKEN");
- }
+ if (restconf_param_set(_HY->hy_h, "REQUEST_METHOD", $1) < 0)
+ YYABORT;
+ free($1);
+ _PARSE_DEBUG("method -> TOKEN");
+ }
;
/* request-target = origin-form / absolute-form / authority-form / asterisk-form *
@@ -260,21 +260,21 @@ method : TOKEN
*/
request_target : absolute_paths1
{
- if (restconf_param_set(_HY->hy_h, "REQUEST_URI", cbuf_get($1)) < 0)
- YYABORT;
- cbuf_free($1);
- _PARSE_DEBUG("request-target -> absolute-paths1");
- }
- | absolute_paths1 QMARK QUERY
- {
- if (restconf_param_set(_HY->hy_h, "REQUEST_URI", cbuf_get($1)) < 0)
- YYABORT;
- cbuf_free($1);
- if (http1_parse_query(_HY, $3) < 0)
- YYABORT;
- free($3);
- _PARSE_DEBUG("request-target -> absolute-paths1 ? query");
- }
+ if (restconf_param_set(_HY->hy_h, "REQUEST_URI", cbuf_get($1)) < 0)
+ YYABORT;
+ cbuf_free($1);
+ _PARSE_DEBUG("request-target -> absolute-paths1");
+ }
+ | absolute_paths1 QMARK QUERY
+ {
+ if (restconf_param_set(_HY->hy_h, "REQUEST_URI", cbuf_get($1)) < 0)
+ YYABORT;
+ cbuf_free($1);
+ if (http1_parse_query(_HY, $3) < 0)
+ YYABORT;
+ free($3);
+ _PARSE_DEBUG("request-target -> absolute-paths1 ? query");
+ }
;
/* absolute-paths1 = absolute-paths ["/"]
@@ -283,27 +283,27 @@ request_target : absolute_paths1
absolute_paths1 : absolute_paths
{ $$ = $1;_PARSE_DEBUG("absolute-paths1 -> absolute-paths "); }
| absolute_paths SLASH
- { $$ = $1;_PARSE_DEBUG("absolute-paths1 -> absolute-paths / "); }
+ { $$ = $1;_PARSE_DEBUG("absolute-paths1 -> absolute-paths / "); }
;
/* absolute-path = 1*( "/" segment )
*/
absolute_paths : absolute_paths absolute_path
{
- $$ = $1;
- cprintf($$, "/");
- if ($2)
- cprintf($$, "%s", $2);
- _PARSE_DEBUG("absolute-paths -> absolute-paths absolute-path");
- }
+ $$ = $1;
+ cprintf($$, "/");
+ if ($2)
+ cprintf($$, "%s", $2);
+ _PARSE_DEBUG("absolute-paths -> absolute-paths absolute-path");
+ }
| absolute_path
- {
- if (($$ = cbuf_new()) == NULL){ YYABORT;}
- cprintf($$, "/");
- if ($1)
- cprintf($$, "%s", $1);
- _PARSE_DEBUG("absolute-paths -> absolute-path");
- }
+ {
+ if (($$ = cbuf_new()) == NULL){ YYABORT;}
+ cprintf($$, "/");
+ if ($1)
+ cprintf($$, "%s", $1);
+ _PARSE_DEBUG("absolute-paths -> absolute-path");
+ }
;
/* segment =
* segment = *pchar
@@ -315,25 +315,25 @@ absolute_paths : absolute_paths absolute_path
*/
absolute_path : SLASH PCHARS
{
- $$ = $2;
- _PARSE_DEBUG("absolute-path -> / PCHARS");
- }
+ $$ = $2;
+ _PARSE_DEBUG("absolute-path -> / PCHARS");
+ }
| SLASH
{
- $$ = NULL;
- _PARSE_DEBUG("absolute-path -> /");
- }
+ $$ = NULL;
+ _PARSE_DEBUG("absolute-path -> /");
+ }
;
/* HTTP-version = HTTP-name "/" DIGIT "." DIGIT */
HTTP_version : HTTP SLASH DIGIT DOT DIGIT
{
- /* make sanity check later */
- _HY->hy_rc->rc_proto_d1 = $3;
- _HY->hy_rc->rc_proto_d2 = $5;
- clicon_debug(1, "clixon_http1_parse: http/%d.%d", $3, $5);
- _PARSE_DEBUG("HTTP-version -> HTTP / DIGIT . DIGIT");
- }
+ /* make sanity check later */
+ _HY->hy_rc->rc_proto_d1 = $3;
+ _HY->hy_rc->rc_proto_d2 = $5;
+ clicon_debug(1, "clixon_http1_parse: http/%d.%d", $3, $5);
+ _PARSE_DEBUG("HTTP-version -> HTTP / DIGIT . DIGIT");
+ }
;
/*------------------------------------------ hdr fields
@@ -347,14 +347,14 @@ header_fields : header_fields header_field CRLF
field-name = token */
header_field : TOKEN COLON ows field_values ows
{
- if ($4){
- if (http1_parse_header_field(_HY, $1, $4) < 0)
- YYABORT;
- free($4);
- }
- free($1);
- _PARSE_DEBUG("header-field -> field-name : field-values");
- }
+ if ($4){
+ if (http1_parse_header_field(_HY, $1, $4) < 0)
+ YYABORT;
+ free($4);
+ }
+ free($1);
+ _PARSE_DEBUG("header-field -> field-name : field-values");
+ }
;
/* field-value = *( field-content / obs-fold )
@@ -362,24 +362,24 @@ header_field : TOKEN COLON ows field_values ows
field-vchar = VCHAR / obs-text */
field_values : field_vchars
{
- $$ = $1; // XXX is there more than one??
- _PARSE_DEBUG("field-values -> field-values field-vchars");
- }
+ $$ = $1; // XXX is there more than one??
+ _PARSE_DEBUG("field-values -> field-values field-vchars");
+ }
| { $$ = NULL; _PARSE_DEBUG("field-values -> "); }
;
field_vchars : field_vchars RWS VCHARS
{
- if (($$ = clixon_string_del_join($1, " ", $3)) == NULL) YYABORT;
- free($3);
- _PARSE_DEBUG("field-vchars -> field-vchars VCHARS");
- }
+ if (($$ = clixon_string_del_join($1, " ", $3)) == NULL) YYABORT;
+ free($3);
+ _PARSE_DEBUG("field-vchars -> field-vchars VCHARS");
+ }
| VCHARS
- {
- $$ = $1;
- _PARSE_DEBUG("field-vchars -> VCHARS");
- }
+ {
+ $$ = $1;
+ _PARSE_DEBUG("field-vchars -> VCHARS");
+ }
;
/* The OWS rule is used where zero or more linear whitespace octets
diff --git a/apps/restconf/clixon_http_data.c b/apps/restconf/clixon_http_data.c
index 70204aec..ccfc85cc 100644
--- a/apps/restconf/clixon_http_data.c
+++ b/apps/restconf/clixon_http_data.c
@@ -98,21 +98,21 @@ api_path_is_data(clicon_handle h)
char *http_data_path;
if (restconf_http_data_get(h) == 0)
- goto done;
+ goto done;
if ((path = restconf_uripath(h)) == NULL)
- goto done;
+ goto done;
if ((http_data_path = clicon_option_str(h, "CLICON_HTTP_DATA_PATH")) == NULL)
- goto done;
+ goto done;
if (strlen(path) < strlen(http_data_path))
- goto done;
+ goto done;
if (path[0] != '/')
- goto done;
+ goto done;
if (strncmp(path, http_data_path, strlen(http_data_path)) != 0)
- goto done;
+ goto done;
retval = 1;
done:
if (path)
- free(path);
+ free(path);
return retval;
}
@@ -124,19 +124,19 @@ api_path_is_data(clicon_handle h)
*/
static int
api_http_data_err(clicon_handle h,
- void *req,
- int code)
+ void *req,
+ int code)
{
int retval = -1;
cbuf *cb = NULL;
clicon_debug(1, "%s", __FUNCTION__);
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
if (restconf_reply_header(req, "Content-Type", "text/html") < 0)
- goto done;
+ goto done;
cprintf(cb, "\r\n");
cprintf(cb, "\r\n");
cprintf(cb, "%d %s \r\n", code, restconf_code2reason(code));
@@ -147,7 +147,7 @@ api_http_data_err(clicon_handle h,
#endif
cprintf(cb, "\r\n");
if (restconf_reply_send(req, code, cb, 0) < 0)
- goto done;
+ goto done;
cb = NULL;
// ok:
retval = 0;
@@ -172,11 +172,11 @@ api_http_data_err(clicon_handle h,
*/
static int
http_data_check_file_path(clicon_handle h,
- void *req,
- char *prefix,
- cbuf *cbpath,
- FILE **fp,
- off_t *fsz)
+ void *req,
+ char *prefix,
+ cbuf *cbpath,
+ FILE **fp,
+ off_t *fsz)
{
int retval = -1;
struct stat fstat;
@@ -186,71 +186,71 @@ http_data_check_file_path(clicon_handle h,
FILE *f;
if (prefix == NULL || cbpath == NULL || fp == NULL){
- clicon_err(OE_UNIX, EINVAL, "prefix, cbpath0 or fp is NULL");
- goto done;
+ clicon_err(OE_UNIX, EINVAL, "prefix, cbpath0 or fp is NULL");
+ goto done;
}
p = cbuf_get(cbpath);
clicon_debug(1, "%s %s", __FUNCTION__, p);
if (strncmp(prefix, p, strlen(prefix)) != 0){
- clicon_err(OE_UNIX, EINVAL, "prefix is not prefix of cbpath");
- goto done;
+ clicon_err(OE_UNIX, EINVAL, "prefix is not prefix of cbpath");
+ goto done;
}
for (i=strlen(prefix); istrlen(prefix) && p[i-1] == '.'){
- clicon_debug(1, "%s Error lstat(%s): .. not allowed in file path", __FUNCTION__, p);
- code = 403;
- goto invalid;
- }
+ if (p[i] == '/'){ /* Check valid dir */
+ p[i] = '\0';
+ /* Ensure not soft link */
+ if (lstat(p, &fstat) < 0){
+ clicon_debug(1, "%s Error lstat(%s):%s", __FUNCTION__, p, strerror(errno));
+ code = 404;
+ goto invalid;
+ }
+ if (!S_ISDIR(fstat.st_mode)){
+ clicon_debug(1, "%s Error lstat(%s): Not dir", __FUNCTION__, p);
+ code = 403;
+ goto invalid;
+ }
+ p[i] = '/';
+ }
+ else if (p[i] == '~'){
+ clicon_debug(1, "%s Error lstat(%s): ~ not allowed in file path", __FUNCTION__, p);
+ code = 403;
+ goto invalid;
+ }
+ else if (p[i] == '.' && i>strlen(prefix) && p[i-1] == '.'){
+ clicon_debug(1, "%s Error lstat(%s): .. not allowed in file path", __FUNCTION__, p);
+ code = 403;
+ goto invalid;
+ }
}
/* Resulting file (ensure not soft link) */
if (lstat(p, &fstat) < 0){
- clicon_debug(1, "%s Error lstat(%s):%s", __FUNCTION__, p, strerror(errno));
- code = 404;
- goto invalid;
+ clicon_debug(1, "%s Error lstat(%s):%s", __FUNCTION__, p, strerror(errno));
+ code = 404;
+ goto invalid;
}
#ifdef HTTP_DATA_INTERNAL_REDIRECT
/* If dir try redirect, not cbpath is extended */
if (S_ISDIR(fstat.st_mode)){
- cprintf(cbpath, "/%s", HTTP_DATA_INTERNAL_REDIRECT);
- p = cbuf_get(cbpath);
- clicon_debug(1, "%s internal redirect: %s", __FUNCTION__, p);
- if (lstat(p, &fstat) < 0){
- clicon_debug(1, "%s Error lstat(%s):%s", __FUNCTION__, p, strerror(errno));
- code = 404;
- goto invalid;
- }
+ cprintf(cbpath, "/%s", HTTP_DATA_INTERNAL_REDIRECT);
+ p = cbuf_get(cbpath);
+ clicon_debug(1, "%s internal redirect: %s", __FUNCTION__, p);
+ if (lstat(p, &fstat) < 0){
+ clicon_debug(1, "%s Error lstat(%s):%s", __FUNCTION__, p, strerror(errno));
+ code = 404;
+ goto invalid;
+ }
}
#endif
if (!S_ISREG(fstat.st_mode)){
- clicon_debug(1, "%s Error lstat(%s): Not regular file", __FUNCTION__, p);
- code = 403;
- goto invalid;
+ clicon_debug(1, "%s Error lstat(%s): Not regular file", __FUNCTION__, p);
+ code = 403;
+ goto invalid;
}
*fsz = fstat.st_size;
if ((f = fopen(p, "rb")) == NULL){
- clicon_debug(1, "%s Error fopen(%s) %s", __FUNCTION__, p, strerror(errno));
- code = 403;
- goto invalid;
+ clicon_debug(1, "%s Error fopen(%s) %s", __FUNCTION__, p, strerror(errno));
+ code = 403;
+ goto invalid;
}
*fp = f;
retval = 1; /* OK */
@@ -258,11 +258,11 @@ http_data_check_file_path(clicon_handle h,
return retval;
invalid:
if (api_http_data_err(h, req, code) < 0)
- goto done;
+ goto done;
retval = 0;
goto done;
}
-
+
/*! Read file data request
* @param[in] h Clicon handle
* @param[in] req Generic Www handle (can be part of clixon handle)
@@ -273,9 +273,9 @@ http_data_check_file_path(clicon_handle h,
*/
static int
api_http_data_file(clicon_handle h,
- void *req,
- char *pathname,
- int head)
+ void *req,
+ char *pathname,
+ int head)
{
int retval = -1;
cbuf *cbfile = NULL;
@@ -293,38 +293,38 @@ api_http_data_file(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if ((cbfile = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
if ((www_data_root = clicon_option_str(h, "CLICON_HTTP_DATA_ROOT")) == NULL){
- clicon_err(OE_RESTCONF, ENOENT, "CLICON_HTTP_DATA_ROOT missing");
- goto done;
+ clicon_err(OE_RESTCONF, ENOENT, "CLICON_HTTP_DATA_ROOT missing");
+ goto done;
}
cprintf(cbfile, "%s", www_data_root);
if (pathname){
- if (strlen(pathname) && pathname[0] != '/'){
- clicon_debug(1, "%s Error fopen(%s) pathname not prefixed with /",
- __FUNCTION__, pathname);
- if (api_http_data_err(h, req, 404) < 0)
- goto done;
- goto ok;
- }
- cprintf(cbfile, "%s", pathname); /* Assume pathname starts with '/' */
+ if (strlen(pathname) && pathname[0] != '/'){
+ clicon_debug(1, "%s Error fopen(%s) pathname not prefixed with /",
+ __FUNCTION__, pathname);
+ if (api_http_data_err(h, req, 404) < 0)
+ goto done;
+ goto ok;
+ }
+ cprintf(cbfile, "%s", pathname); /* Assume pathname starts with '/' */
}
if ((ret = http_data_check_file_path(h, req, www_data_root, cbfile, &f, &fsz)) < 0)
- goto done;
+ goto done;
if (ret == 0) /* Invalid, return code set */
- goto ok;
+ goto ok;
filename = cbuf_get(cbfile);
/* Find media from file suffix, note there may have been internal indirection */
if ((suffix = rindex(filename, '.')) == NULL){
- media = "application/octet-stream";
+ media = "application/octet-stream";
}
else {
- suffix++;
- if ((media = clicon_str2str(mime_map, suffix)) == NULL)
- media = "application/octet-stream";
+ suffix++;
+ if ((media = clicon_str2str(mime_map, suffix)) == NULL)
+ media = "application/octet-stream";
}
/* Size could have been taken from stat() but this reduces the race condition interval
* There is still one without flock
@@ -333,55 +333,55 @@ api_http_data_file(clicon_handle h,
fsize = ftell(f);
/* Extra sanity check, had some problems with wrong file types */
if (fsz != fsize){
- clicon_debug(1, "%s Error file %s size mismatch sz:%zu vs %li",
- __FUNCTION__, filename, (size_t)fsz, fsize);
- if (api_http_data_err(h, req, 500) < 0) /* Internal error? */
- goto done;
- goto ok;
+ clicon_debug(1, "%s Error file %s size mismatch sz:%zu vs %li",
+ __FUNCTION__, filename, (size_t)fsz, fsize);
+ if (api_http_data_err(h, req, 500) < 0) /* Internal error? */
+ goto done;
+ goto ok;
}
fseek(f, 0, SEEK_SET); /* same as rewind(f); */
if ((cbdata = cbuf_new_alloc(fsize+1)) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new_alloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new_alloc");
+ goto done;
}
/* Unoptimized, no direct read but requires an extra copy,
* the cligen buf API should have some mechanism for this case without the extra copy.
*/
if ((buf = malloc(fsize)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
if ((sz = fread(buf, fsize, 1, f)) < 0){
- clicon_err(OE_UNIX, errno, "fread");
- goto done;
+ clicon_err(OE_UNIX, errno, "fread");
+ goto done;
}
if (sz != 1){
- clicon_debug(1, "%s Error fread(%s) sz:%zu", __FUNCTION__, filename, sz);
- if (api_http_data_err(h, req, 500) < 0) /* Internal error? */
- goto done;
- goto ok;
+ clicon_debug(1, "%s Error fread(%s) sz:%zu", __FUNCTION__, filename, sz);
+ if (api_http_data_err(h, req, 500) < 0) /* Internal error? */
+ goto done;
+ goto ok;
}
if (cbuf_append_buf(cbdata, buf, fsize) < 0){
- clicon_err(OE_UNIX, errno, "cbuf_append_str");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_append_str");
+ goto done;
}
if (restconf_reply_header(req, "Content-Type", "%s", media) < 0)
- goto done;
+ goto done;
if (restconf_reply_send(req, 200, cbdata, head) < 0)
- goto done;
+ goto done;
cbdata = NULL; /* consumed by reply-send */
clicon_debug(1, "%s Read %s OK", __FUNCTION__, filename);
ok:
retval = 0;
done:
if (buf)
- free(buf);
+ free(buf);
if (f)
- fclose(f);
+ fclose(f);
if (cbfile)
- cbuf_free(cbfile);
+ cbuf_free(cbfile);
if (cbdata)
- cbuf_free(cbdata);
+ cbuf_free(cbdata);
return retval;
}
@@ -403,8 +403,8 @@ api_http_data_file(clicon_handle h,
*/
int
api_http_data(clicon_handle h,
- void *req,
- cvec *qvec)
+ void *req,
+ cvec *qvec)
{
int retval = -1;
char *request_method = NULL;
@@ -417,15 +417,15 @@ api_http_data(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (req == NULL){
- errno = EINVAL;
- goto done;
+ errno = EINVAL;
+ goto done;
}
/* 1. path: with stripped prefix, ultimately: dir/filename
*/
if (!api_path_is_data(h)){
- if (api_http_data_err(h, req, 404) < 0) /* not found */
- goto done;
- goto ok;
+ if (api_http_data_err(h, req, 404) < 0) /* not found */
+ goto done;
+ goto ok;
}
path = restconf_uripath(h);
/* 2. operation GET or HEAD */
@@ -433,63 +433,63 @@ api_http_data(clicon_handle h,
if (strcmp(request_method, "GET") == 0){
}
else if (strcmp(request_method, "HEAD") == 0){
- head = 1;
+ head = 1;
}
else if (strcmp(request_method, "OPTIONS") == 0){
- options = 1;
+ options = 1;
}
else {
- if (api_http_data_err(h, req, 405) < 0) /* method not allowed */
- goto done;
- goto ok;
+ if (api_http_data_err(h, req, 405) < 0) /* method not allowed */
+ goto done;
+ goto ok;
}
/* 3. query parameters not accepted */
if (qvec != NULL){
- if (api_http_data_err(h, req, 400) < 0) /* bad request */
- goto done;
- goto ok;
+ if (api_http_data_err(h, req, 400) < 0) /* bad request */
+ goto done;
+ goto ok;
}
/* 4. indata should be NULL (no write operations) */
if ((indata = restconf_get_indata(req)) == NULL) {
- clicon_err(OE_RESTCONF, ENOENT, "Unexpected no input cbuf");
- goto done;
+ clicon_err(OE_RESTCONF, ENOENT, "Unexpected no input cbuf");
+ goto done;
}
if (cbuf_len(indata)){
- if (api_http_data_err(h, req, 400) < 0) /* bad request */
- goto done;
- goto ok;
+ if (api_http_data_err(h, req, 400) < 0) /* bad request */
+ goto done;
+ goto ok;
}
/* 5. Accepted media_out: should check text/html, JavaScript, image, and css
*/
if ((media_str = restconf_param_get(h, "HTTP_ACCEPT")) == NULL){
}
else if (strcmp(media_str, "*/*") != 0 &&
- strcmp(media_str, "text/html") != 0){
+ strcmp(media_str, "text/html") != 0){
#ifdef NOTYET
- clicon_log(LOG_NOTICE, "%s: media error %s", __FUNCTION__, media_str);
- goto done;
+ clicon_log(LOG_NOTICE, "%s: media error %s", __FUNCTION__, media_str);
+ goto done;
#endif
}
/* 6. Authenticate
* Note, error handling may need change since it is restconf based
*/
if ((ret = restconf_authentication_cb(h, req, 1, 0 /*media_out */)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto ok;
+ goto ok;
if (options){
- if (restconf_reply_header(req, "Allow", "OPTIONS,HEAD,GET") < 0)
- goto done;
- if (restconf_reply_send(req, 200, NULL, 0) < 0)
- goto done;
+ if (restconf_reply_header(req, "Allow", "OPTIONS,HEAD,GET") < 0)
+ goto done;
+ if (restconf_reply_send(req, 200, NULL, 0) < 0)
+ goto done;
}
else if (api_http_data_file(h, req, path, head) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
if (path)
- free(path);
+ free(path);
clicon_debug(1, "%s %d", __FUNCTION__, retval);
return retval;
}
diff --git a/apps/restconf/clixon_restconf.h b/apps/restconf/clixon_restconf.h
index 1ec2e20f..2da13e8b 100644
--- a/apps/restconf/clixon_restconf.h
+++ b/apps/restconf/clixon_restconf.h
@@ -55,8 +55,8 @@ enum restconf_media{
YANG_PATCH_XML, /* "application/yang-patch+xml" */
YANG_PAGINATION_XML, /* draft-wwlh-netconf-list-pagination-rc-02.txt */
/* For JSON, the existing "application/yang-data+json" media type is
- sufficient, as the JSON format has built-in support for encoding
- arrays. */
+ sufficient, as the JSON format has built-in support for encoding
+ arrays. */
};
typedef enum restconf_media restconf_media;
diff --git a/apps/restconf/restconf_api_fcgi.c b/apps/restconf/restconf_api_fcgi.c
index a8a440e0..ae80aac0 100644
--- a/apps/restconf/restconf_api_fcgi.c
+++ b/apps/restconf/restconf_api_fcgi.c
@@ -93,9 +93,9 @@ restconf_reply_body_start(void *req0)
*/
int
restconf_reply_header(void *req0,
- const char *name,
- const char *vfmt,
- ...)
+ const char *name,
+ const char *vfmt,
+ ...)
{
FCGX_Request *req = (FCGX_Request *)req0;
int retval = -1;
@@ -104,30 +104,30 @@ restconf_reply_header(void *req0,
va_list ap;
if (req == NULL || name == NULL || vfmt == NULL){
- clicon_err(OE_CFG, EINVAL, "req, name or value is NULL");
- return -1;
+ clicon_err(OE_CFG, EINVAL, "req, name or value is NULL");
+ return -1;
}
va_start(ap, vfmt);
vlen = vsnprintf(NULL, 0, vfmt, ap);
va_end(ap);
/* allocate value string exactly fitting */
if ((value = malloc(vlen+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* second round: compute actual value */
va_start(ap, vfmt);
if (vsnprintf(value, vlen+1, vfmt, ap) < 0){
- clicon_err(OE_UNIX, errno, "vsnprintf");
- va_end(ap);
- goto done;
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ va_end(ap);
+ goto done;
}
va_end(ap);
FCGX_FPrintF(req->out, "%s: %s\r\n", name, value);
retval = 0;
done:
if (value)
- free(value);
+ free(value);
return retval;
}
@@ -139,9 +139,9 @@ restconf_reply_header(void *req0,
*/
int
restconf_reply_body_add(void *req0,
- size_t *content_len,
- char *bfmt,
- ...)
+ size_t *content_len,
+ char *bfmt,
+ ...)
{
FCGX_Request *req = (FCGX_Request *)req0;
int retval = -1;
@@ -151,35 +151,35 @@ restconf_reply_body_add(void *req0,
va_list ap;
if (req == NULL || bfmt == NULL){
- clicon_err(OE_CFG, EINVAL, "req or body is NULL");
- return -1;
+ clicon_err(OE_CFG, EINVAL, "req or body is NULL");
+ return -1;
}
va_start(ap, bfmt);
blen = vsnprintf(NULL, 0, bfmt, ap);
va_end(ap);
/* allocate body string exactly fitting */
if ((body = malloc(blen+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* second round: compute actual body */
va_start(ap, bfmt);
if (vsnprintf(body, blen+1, bfmt, ap) < 0){
- clicon_err(OE_UNIX, errno, "vsnprintf");
- va_end(ap);
- goto done;
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ va_end(ap);
+ goto done;
}
va_end(ap);
FCGX_FPrintF(req->out, "%s", body);
/* Increment in/out Content-Length parameter */
if (content_len){
- sz = strlen(body);
- *content_len += sz;
+ sz = strlen(body);
+ *content_len += sz;
}
retval = 0;
done:
if (body)
- free(body);
+ free(body);
return retval;
}
@@ -193,9 +193,9 @@ restconf_reply_body_add(void *req0,
*/
int
restconf_reply_send(void *req0,
- int code,
- cbuf *cb,
- int head)
+ int code,
+ cbuf *cb,
+ int head)
{
FCGX_Request *req = (FCGX_Request *)req0;
int retval = -1;
@@ -203,17 +203,17 @@ restconf_reply_send(void *req0,
FCGX_SetExitStatus(code, req->out);
if ((reason_phrase = restconf_code2reason(code)) == NULL)
- reason_phrase="";
+ reason_phrase="";
if (restconf_reply_header(req, "Status", "%d %s", code, reason_phrase) < 0)
- goto done;
+ goto done;
FCGX_FPrintF(req->out, "\r\n");
/* Write a body if cbuf is nonzero */
if (cb != NULL){
- if (!head && cbuf_len(cb)){
- FCGX_FPrintF(req->out, "%s", cbuf_get(cb));
- FCGX_FPrintF(req->out, "\r\n");
- }
- cbuf_free(cb);
+ if (!head && cbuf_len(cb)){
+ FCGX_FPrintF(req->out, "%s", cbuf_get(cb));
+ FCGX_FPrintF(req->out, "\r\n");
+ }
+ cbuf_free(cb);
}
FCGX_FFlush(req->out); /* Is this only for notification ? */
retval = 0;
@@ -235,8 +235,8 @@ restconf_get_indata(void *req0)
cbuf *cb = NULL;
if ((cb = cbuf_new()) == NULL)
- return NULL;
+ return NULL;
while ((c = FCGX_GetChar(req->in)) != -1)
- cprintf(cb, "%c", c);
+ cprintf(cb, "%c", c);
return cb;
}
diff --git a/apps/restconf/restconf_api_native.c b/apps/restconf/restconf_api_native.c
index 4d26fa7c..69b575e7 100644
--- a/apps/restconf/restconf_api_native.c
+++ b/apps/restconf/restconf_api_native.c
@@ -72,9 +72,9 @@
*/
int
restconf_reply_header(void *req0,
- const char *name,
- const char *vfmt,
- ...)
+ const char *name,
+ const char *vfmt,
+ ...)
{
int retval = -1;
restconf_stream_data *sd = (restconf_stream_data *)req0;
@@ -85,12 +85,12 @@ restconf_reply_header(void *req0,
clicon_debug(1, "%s %s", __FUNCTION__, name);
if (sd == NULL || name == NULL || vfmt == NULL){
- clicon_err(OE_CFG, EINVAL, "sd, name or value is NULL");
- goto done;
+ clicon_err(OE_CFG, EINVAL, "sd, name or value is NULL");
+ goto done;
}
if ((rc = sd->sd_conn) == NULL){
- clicon_err(OE_CFG, EINVAL, "rc is NULL");
- goto done;
+ clicon_err(OE_CFG, EINVAL, "rc is NULL");
+ goto done;
}
/* First round: compute vlen and allocate value */
va_start(ap, vfmt);
@@ -98,25 +98,25 @@ restconf_reply_header(void *req0,
va_end(ap);
/* allocate value string exactly fitting */
if ((value = malloc(vlen+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* Second round: compute actual value */
va_start(ap, vfmt);
if (vsnprintf(value, vlen+1, vfmt, ap) < 0){
- clicon_err(OE_UNIX, errno, "vsnprintf");
- va_end(ap);
- goto done;
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ va_end(ap);
+ goto done;
}
va_end(ap);
if (cvec_add_string(sd->sd_outp_hdrs, (char*)name, value) < 0){
- clicon_err(OE_RESTCONF, errno, "cvec_add_string");
- goto done;
+ clicon_err(OE_RESTCONF, errno, "cvec_add_string");
+ goto done;
}
retval = 0;
done:
if (value)
- free(value);
+ free(value);
return retval;
}
@@ -130,37 +130,37 @@ restconf_reply_header(void *req0,
*/
int
restconf_reply_send(void *req0,
- int code,
- cbuf *cb,
- int head)
+ int code,
+ cbuf *cb,
+ int head)
{
int retval = -1;
restconf_stream_data *sd = (restconf_stream_data *)req0;
clicon_debug(1, "%s code:%d", __FUNCTION__, code);
if (sd == NULL){
- clicon_err(OE_CFG, EINVAL, "sd is NULL");
- goto done;
+ clicon_err(OE_CFG, EINVAL, "sd is NULL");
+ goto done;
}
sd->sd_code = code;
if (cb != NULL){
- if (cbuf_len(cb)){
- sd->sd_body_len = cbuf_len(cb);
- if (head){
- cbuf_free(cb);
- }
- else{
- sd->sd_body = cb;
- sd->sd_body_offset = 0;
- }
- }
- else{
- cbuf_free(cb);
- sd->sd_body_len = 0;
- }
+ if (cbuf_len(cb)){
+ sd->sd_body_len = cbuf_len(cb);
+ if (head){
+ cbuf_free(cb);
+ }
+ else{
+ sd->sd_body = cb;
+ sd->sd_body_offset = 0;
+ }
+ }
+ else{
+ cbuf_free(cb);
+ sd->sd_body_len = 0;
+ }
}
else
- sd->sd_body_len = 0;
+ sd->sd_body_len = 0;
retval = 0;
done:
return retval;
@@ -177,8 +177,8 @@ restconf_get_indata(void *req0)
cbuf *cb = NULL;
if (sd == NULL){
- clicon_err(OE_CFG, EINVAL, "sd is NULL");
- goto done;
+ clicon_err(OE_CFG, EINVAL, "sd is NULL");
+ goto done;
}
cb = sd->sd_indata;
done:
diff --git a/apps/restconf/restconf_err.c b/apps/restconf/restconf_err.c
index 35c7277b..d93e060a 100644
--- a/apps/restconf/restconf_err.c
+++ b/apps/restconf/restconf_err.c
@@ -77,25 +77,25 @@
*/
int
restconf_method_notallowed(clicon_handle h,
- void *req,
- char *allow,
- int pretty,
- restconf_media media)
+ void *req,
+ char *allow,
+ int pretty,
+ restconf_media media)
{
int retval = -1;
cxobj *xerr = NULL;
if (netconf_operation_not_supported_xml(&xerr, "protocol", "Method not allowed") < 0)
- goto done;
+ goto done;
/* Assume not-supported mapped to Not Allowed with allow header */
if (restconf_reply_header(req, "Allow", "%s", allow) < 0)
- goto done;
+ goto done;
if (api_return_err0(h, req, xerr, pretty, YANG_DATA_JSON, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
return retval;
}
@@ -107,22 +107,22 @@ restconf_method_notallowed(clicon_handle h,
*/
int
restconf_unsupported_media(clicon_handle h,
- void *req,
- int pretty,
- restconf_media media)
+ void *req,
+ int pretty,
+ restconf_media media)
{
int retval = -1;
cxobj *xerr = NULL;
if (netconf_operation_not_supported_xml(&xerr, "protocol", "Unsupported Media Type") < 0)
- goto done;
+ goto done;
/* override with 415 netconf->restoconf translation which gives a 405 */
if (api_return_err0(h, req, xerr, pretty, media, 415) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
return retval;
}
@@ -135,20 +135,20 @@ restconf_unsupported_media(clicon_handle h,
*/
int
restconf_not_acceptable(clicon_handle h,
- void *req,
- int pretty,
- restconf_media media)
+ void *req,
+ int pretty,
+ restconf_media media)
{
int retval = -1;
cxobj *xerr = NULL;
if (netconf_operation_not_supported_xml(&xerr, "protocol", "Unacceptable output encoding") < 0)
- goto done;
+ goto done;
/* Override with 415 netconf->restoconf translation which gives a 405 */
if (api_return_err0(h, req, xerr, pretty, media, 415) < 0)
- goto done;
+ goto done;
if (restconf_reply_send(req, 415, NULL, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -159,22 +159,22 @@ restconf_not_acceptable(clicon_handle h,
*/
int
restconf_notimplemented(clicon_handle h,
- void *req,
- int pretty,
- restconf_media media)
+ void *req,
+ int pretty,
+ restconf_media media)
{
int retval = -1;
cxobj *xerr = NULL;
if (netconf_operation_not_supported_xml(&xerr, "protocol", "Not Implemented") < 0)
- goto done;
+ goto done;
/* Override with 501 Not Implemented netconf->restoconf translation which gives a 405 */
if (api_return_err0(h, req, xerr, pretty, YANG_DATA_JSON, 501) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
return retval;
}
@@ -191,130 +191,130 @@ restconf_notimplemented(clicon_handle h,
*/
int
api_return_err(clicon_handle h,
- void *req,
- cxobj *xerr,
- int pretty,
- restconf_media media,
- int code0)
+ void *req,
+ cxobj *xerr,
+ int pretty,
+ restconf_media media,
+ int code0)
{
int retval = -1;
cbuf *cb = NULL;
cbuf *cberr = NULL;
cxobj *xtag;
char *tagstr;
- int code;
+ int code;
cxobj *xerr2 = NULL;
cxobj *xmsg;
char *mb;
clicon_debug(1, "%s", __FUNCTION__);
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
/* A well-formed error message when entering here should look like:
* ...invalid-value
* Check this is so, otherwise generate an internal error.
*/
if (strcmp(xml_name(xerr), "rpc-error") != 0 ||
- (xtag = xpath_first(xerr, NULL, "error-tag")) == NULL){
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cberr, "Internal error, system returned invalid error message: ");
- if (netconf_err2cb(xerr, cberr) < 0)
- goto done;
- if (netconf_operation_failed_xml(&xerr2, "application",
- cbuf_get(cberr)) < 0)
- goto done;
- if ((xerr = xpath_first(xerr2, NULL, "rpc-error")) == NULL){
- clicon_err(OE_XML, 0, "Internal error, shouldnt happen");
- goto done;
- }
- if ((xtag = xpath_first(xerr, NULL, "error-tag")) == NULL){
- clicon_err(OE_XML, 0, "Internal error, shouldnt happen");
- goto done;
- }
+ (xtag = xpath_first(xerr, NULL, "error-tag")) == NULL){
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cberr, "Internal error, system returned invalid error message: ");
+ if (netconf_err2cb(xerr, cberr) < 0)
+ goto done;
+ if (netconf_operation_failed_xml(&xerr2, "application",
+ cbuf_get(cberr)) < 0)
+ goto done;
+ if ((xerr = xpath_first(xerr2, NULL, "rpc-error")) == NULL){
+ clicon_err(OE_XML, 0, "Internal error, shouldnt happen");
+ goto done;
+ }
+ if ((xtag = xpath_first(xerr, NULL, "error-tag")) == NULL){
+ clicon_err(OE_XML, 0, "Internal error, shouldnt happen");
+ goto done;
+ }
}
#if 1
if (clicon_debug_get())
- clicon_log_xml(LOG_DEBUG, xerr, "%s Send error:", __FUNCTION__);
+ clicon_log_xml(LOG_DEBUG, xerr, "%s Send error:", __FUNCTION__);
#endif
if (xml_name_set(xerr, "error") < 0)
- goto done;
+ goto done;
tagstr = xml_body(xtag);
if (code0 != 0)
- code = code0;
+ code = code0;
else{
- if ((code = restconf_err2code(tagstr)) < 0)
- code = 500; /* internal server error */
- if (code == 403){
- /* Special case: netconf only has "access denied" while restconf
- * differentiates between:
- * 401 Unauthorized If the RESTCONF client is not authenticated (sec 2.5)
- * 403 Forbidden If the user is not authorized to access a target resource or invoke
- * an operation
- */
- if ((xmsg = xpath_first(xerr, NULL, "error-message")) != NULL &&
- (mb = xml_body(xmsg)) != NULL &&
- strcmp(mb, "The requested URL was unauthorized") == 0)
- code = 401; /* Unauthorized */
- }
- /* Special case #2 */
- if (code == 400){
- if (strcmp(tagstr, "invalid-value") == 0 &&
- (xmsg = xpath_first(xerr, NULL, "error-message")) != NULL &&
- (mb = xml_body(xmsg)) != NULL &&
- strcmp(mb, "Invalid HTTP data method") == 0)
- code = 404; /* Not found */
- }
+ if ((code = restconf_err2code(tagstr)) < 0)
+ code = 500; /* internal server error */
+ if (code == 403){
+ /* Special case: netconf only has "access denied" while restconf
+ * differentiates between:
+ * 401 Unauthorized If the RESTCONF client is not authenticated (sec 2.5)
+ * 403 Forbidden If the user is not authorized to access a target resource or invoke
+ * an operation
+ */
+ if ((xmsg = xpath_first(xerr, NULL, "error-message")) != NULL &&
+ (mb = xml_body(xmsg)) != NULL &&
+ strcmp(mb, "The requested URL was unauthorized") == 0)
+ code = 401; /* Unauthorized */
+ }
+ /* Special case #2 */
+ if (code == 400){
+ if (strcmp(tagstr, "invalid-value") == 0 &&
+ (xmsg = xpath_first(xerr, NULL, "error-message")) != NULL &&
+ (mb = xml_body(xmsg)) != NULL &&
+ strcmp(mb, "Invalid HTTP data method") == 0)
+ code = 404; /* Not found */
+ }
}
if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media)) < 0) // XXX
- goto done;
+ goto done;
switch (media){
case YANG_DATA_XML:
case YANG_PATCH_XML:
case YANG_PAGINATION_XML:
- clicon_debug(1, "%s code:%d", __FUNCTION__, code);
- if (pretty){
- cprintf(cb, " \n");
- if (clixon_xml2cbuf(cb, xerr, 2, pretty, -1, 0) < 0)
- goto done;
- cprintf(cb, " \r\n");
- }
- else {
- cprintf(cb, "");
- if (clixon_xml2cbuf(cb, xerr, 2, pretty, -1, 0) < 0)
- goto done;
- cprintf(cb, " \r\n");
- }
- break;
+ clicon_debug(1, "%s code:%d", __FUNCTION__, code);
+ if (pretty){
+ cprintf(cb, " \n");
+ if (clixon_xml2cbuf(cb, xerr, 2, pretty, -1, 0) < 0)
+ goto done;
+ cprintf(cb, " \r\n");
+ }
+ else {
+ cprintf(cb, "");
+ if (clixon_xml2cbuf(cb, xerr, 2, pretty, -1, 0) < 0)
+ goto done;
+ cprintf(cb, " \r\n");
+ }
+ break;
case YANG_DATA_JSON:
case YANG_PATCH_JSON:
- clicon_debug(1, "%s code:%d", __FUNCTION__, code);
- if (pretty){
- cprintf(cb, "{\n\"ietf-restconf:errors\" : ");
- if (clixon_json2cbuf(cb, xerr, pretty, 0, 0) < 0)
- goto done;
- cprintf(cb, "\n}\r\n");
- }
- else{
- cprintf(cb, "{");
- cprintf(cb, "\"ietf-restconf:errors\":");
- if (clixon_json2cbuf(cb, xerr, pretty, 0, 0) < 0)
- goto done;
- cprintf(cb, "}\r\n");
- }
- break;
+ clicon_debug(1, "%s code:%d", __FUNCTION__, code);
+ if (pretty){
+ cprintf(cb, "{\n\"ietf-restconf:errors\" : ");
+ if (clixon_json2cbuf(cb, xerr, pretty, 0, 0) < 0)
+ goto done;
+ cprintf(cb, "\n}\r\n");
+ }
+ else{
+ cprintf(cb, "{");
+ cprintf(cb, "\"ietf-restconf:errors\":");
+ if (clixon_json2cbuf(cb, xerr, pretty, 0, 0) < 0)
+ goto done;
+ cprintf(cb, "}\r\n");
+ }
+ break;
default: /* Just ignore the body so that there is a reply */
- clicon_err(OE_YANG, EINVAL, "Invalid media type %d", media);
- goto done;
- break;
+ clicon_err(OE_YANG, EINVAL, "Invalid media type %d", media);
+ goto done;
+ break;
} /* switch media */
assert(cbuf_len(cb));
if (restconf_reply_send(req, code, cb, 0) < 0)
- goto done;
+ goto done;
cb = NULL;
// ok:
retval = 0;
@@ -342,21 +342,21 @@ api_return_err(clicon_handle h,
*/
int
api_return_err0(clicon_handle h,
- void *req,
- cxobj *xerr,
- int pretty,
- restconf_media media,
- int code)
+ void *req,
+ cxobj *xerr,
+ int pretty,
+ restconf_media media,
+ int code)
{
int retval = -1;
cxobj *xe;
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
- clicon_err(OE_XML, EINVAL, "Expected xml on the form ..");
- goto done;
+ clicon_err(OE_XML, EINVAL, "Expected xml on the form ..");
+ goto done;
}
if (api_return_err(h, req, xe, pretty, media, code) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
diff --git a/apps/restconf/restconf_handle.c b/apps/restconf/restconf_handle.c
index 65d6ca53..c231c8e7 100644
--- a/apps/restconf/restconf_handle.c
+++ b/apps/restconf/restconf_handle.c
@@ -119,7 +119,7 @@ restconf_handle_exit(clicon_handle h)
struct restconf_handle *rh = handle(h);
if (rh->rh_fcgi_socket)
- free(rh->rh_fcgi_socket);
+ free(rh->rh_fcgi_socket);
clicon_handle_exit(h); /* frees h and options (and streams) */
return 0;
}
@@ -132,12 +132,12 @@ restconf_handle_exit(clicon_handle h)
*/
char *
restconf_param_get(clicon_handle h,
- const char *param)
+ const char *param)
{
struct restconf_handle *rh = handle(h);
if (rh->rh_params == NULL)
- return NULL;
+ return NULL;
return (char*)clicon_hash_value(rh->rh_params, param, NULL);
}
@@ -151,15 +151,15 @@ restconf_param_get(clicon_handle h,
*/
int
restconf_param_set(clicon_handle h,
- const char *param,
- char *val)
+ const char *param,
+ char *val)
{
struct restconf_handle *rh = handle(h);
clicon_debug(1, "%s: %s=%s", __FUNCTION__, param, val);
if (rh->rh_params == NULL)
- if ((rh->rh_params = clicon_hash_init()) == NULL)
- return -1;
+ if ((rh->rh_params = clicon_hash_init()) == NULL)
+ return -1;
return clicon_hash_add(rh->rh_params, param, val, strlen(val)+1)==NULL?-1:0;
}
@@ -177,9 +177,9 @@ restconf_param_del_all(clicon_handle h)
struct restconf_handle *rh = handle(h);
if (rh->rh_params != NULL){
- if (clicon_hash_free(rh->rh_params) < 0)
- goto done;
- rh->rh_params = NULL;
+ if (clicon_hash_free(rh->rh_params) < 0)
+ goto done;
+ rh->rh_params = NULL;
}
retval = 0;
done:
@@ -208,7 +208,7 @@ restconf_auth_type_get(clicon_handle h)
*/
int
restconf_auth_type_set(clicon_handle h,
- clixon_auth_type_t type)
+ clixon_auth_type_t type)
{
struct restconf_handle *rh = handle(h);
@@ -236,7 +236,7 @@ restconf_pretty_get(clicon_handle h)
*/
int
restconf_pretty_set(clicon_handle h,
- int pretty)
+ int pretty)
{
struct restconf_handle *rh = handle(h);
@@ -264,7 +264,7 @@ restconf_http_data_get(clicon_handle h)
*/
int
restconf_http_data_set(clicon_handle h,
- int http_data)
+ int http_data)
{
struct restconf_handle *rh = handle(h);
@@ -294,13 +294,13 @@ restconf_fcgi_socket_get(clicon_handle h)
*/
int
restconf_fcgi_socket_set(clicon_handle h,
- char *socketpath)
+ char *socketpath)
{
struct restconf_handle *rh = handle(h);
if ((rh->rh_fcgi_socket = strdup(socketpath)) == NULL){
- clicon_err(OE_RESTCONF, errno, "strdup");
- return -1;
+ clicon_err(OE_RESTCONF, errno, "strdup");
+ return -1;
}
return 0;
}
diff --git a/apps/restconf/restconf_http1.c b/apps/restconf/restconf_http1.c
index db8cdf05..df85bbad 100644
--- a/apps/restconf/restconf_http1.c
+++ b/apps/restconf/restconf_http1.c
@@ -82,9 +82,9 @@
*/
static int
_http1_parse(clicon_handle h,
- restconf_conn *rc,
- char *str,
- const char *filename)
+ restconf_conn *rc,
+ char *str,
+ const char *filename)
{
int retval = -1;
clixon_http1_yacc hy = {0,};
@@ -92,29 +92,29 @@ _http1_parse(clicon_handle h,
clicon_debug(1, "%s:\n%s", __FUNCTION__, str);
if (strlen(str) == 0)
- goto ok;
+ goto ok;
hy.hy_parse_string = str;
hy.hy_name = filename;
hy.hy_h = h;
hy.hy_rc = rc;
hy.hy_linenum = 1;
if (http1_scan_init(&hy) < 0)
- goto done;
+ goto done;
if (http1_parse_init(&hy) < 0)
- goto done;
+ goto done;
ret = clixon_http1_parseparse(&hy); /* yacc returns 1 on error */
/* yacc/lex terminates parsing after headers.
* Look for body after headers assuming str terminating with \n\n\0 and then */
http1_parse_exit(&hy);
http1_scan_exit(&hy);
if (ret != 0){
- if (filename)
- clicon_log(LOG_NOTICE, "HTTP1 error: on line %d in %s", hy.hy_linenum, filename);
- else
- clicon_log(LOG_NOTICE, "HTTP1 error: on line %d", hy.hy_linenum);
- if (clicon_errno == 0)
- clicon_err(OE_RESTCONF, 0, "HTTP1 parser error with no error code (should not happen)");
- goto done;
+ if (filename)
+ clicon_log(LOG_NOTICE, "HTTP1 error: on line %d in %s", hy.hy_linenum, filename);
+ else
+ clicon_log(LOG_NOTICE, "HTTP1 error: on line %d", hy.hy_linenum);
+ if (clicon_errno == 0)
+ clicon_err(OE_RESTCONF, 0, "HTTP1 parser error with no error code (should not happen)");
+ goto done;
}
ok:
retval = 0;
@@ -134,9 +134,9 @@ _http1_parse(clicon_handle h,
*/
int
clixon_http1_parse_file(clicon_handle h,
- restconf_conn *rc,
- FILE *f,
- const char *filename)
+ restconf_conn *rc,
+ FILE *f,
+ const char *filename)
{
int retval = -1;
int ret;
@@ -149,43 +149,43 @@ clixon_http1_parse_file(clicon_handle h,
clicon_debug(1, "%s %s", __FUNCTION__, filename);
if (f == NULL){
- clicon_err(OE_RESTCONF, EINVAL, "f is NULL");
- goto done;
+ clicon_err(OE_RESTCONF, EINVAL, "f is NULL");
+ goto done;
}
if ((buf = malloc(buflen)) == NULL){
- clicon_err(OE_XML, errno, "malloc");
- goto done;
+ clicon_err(OE_XML, errno, "malloc");
+ goto done;
}
memset(buf, 0, buflen);
ptr = buf;
while (1){
- if ((ret = fread(&ch, 1, 1, f)) < 0){
- clicon_err(OE_XML, errno, "read");
- break;
- }
- if (ret != 0){
- buf[len++] = ch;
- }
- if (ret == 0) { /* buffer read */
- if (_http1_parse(h, rc, ptr, filename) < 0)
- goto done;
- break;
- }
- if (len >= buflen-1){ /* Space: one for the null character */
- oldbuflen = buflen;
- buflen *= 2;
- if ((buf = realloc(buf, buflen)) == NULL){
- clicon_err(OE_XML, errno, "realloc");
- goto done;
- }
- memset(buf+oldbuflen, 0, buflen-oldbuflen);
- ptr = buf;
- }
+ if ((ret = fread(&ch, 1, 1, f)) < 0){
+ clicon_err(OE_XML, errno, "read");
+ break;
+ }
+ if (ret != 0){
+ buf[len++] = ch;
+ }
+ if (ret == 0) { /* buffer read */
+ if (_http1_parse(h, rc, ptr, filename) < 0)
+ goto done;
+ break;
+ }
+ if (len >= buflen-1){ /* Space: one for the null character */
+ oldbuflen = buflen;
+ buflen *= 2;
+ if ((buf = realloc(buf, buflen)) == NULL){
+ clicon_err(OE_XML, errno, "realloc");
+ goto done;
+ }
+ memset(buf+oldbuflen, 0, buflen-oldbuflen);
+ ptr = buf;
+ }
} /* while */
retval = 0;
done:
if (buf)
- free(buf);
+ free(buf);
return retval;
}
@@ -199,8 +199,8 @@ clixon_http1_parse_file(clicon_handle h,
*/
int
clixon_http1_parse_string(clicon_handle h,
- restconf_conn *rc,
- char *str)
+ restconf_conn *rc,
+ char *str)
{
return _http1_parse(h, rc, str, "http1-parse");
}
@@ -219,16 +219,16 @@ clixon_http1_parse_string(clicon_handle h,
*/
int
clixon_http1_parse_buf(clicon_handle h,
- restconf_conn *rc,
- char *buf,
- size_t n)
+ restconf_conn *rc,
+ char *buf,
+ size_t n)
{
char *str = NULL;
int ret;
if ((str = malloc(n+1)) == NULL){
- clicon_err(OE_RESTCONF, errno, "malloc");
- return -1;
+ clicon_err(OE_RESTCONF, errno, "malloc");
+ return -1;
}
memcpy(str, buf, n);
str[n] = '\0';
@@ -250,43 +250,43 @@ clixon_http1_parse_buf(clicon_handle h,
*/
static int
http1_upgrade_http2(clicon_handle h,
- restconf_stream_data *sd)
+ restconf_stream_data *sd)
{
int retval = -1;
char *str;
char *settings;
cxobj *xerr = NULL;
-
+
if ((str = restconf_param_get(h, "HTTP_UPGRADE")) != NULL &&
- clicon_option_bool(h, "CLICON_RESTCONF_HTTP2_PLAIN") == 1){
- /* Only accept "h2c" */
- if (strcmp(str, "h2c") != 0){
- if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid upgrade token") < 0)
- goto done;
- if (api_return_err0(h, sd, xerr, 1, YANG_DATA_JSON, 0) < 0)
- goto done;
- if (xerr)
- xml_free(xerr);
- }
- else {
- if (restconf_reply_header(sd, "Connection", "Upgrade") < 0)
- goto done;
- if (restconf_reply_header(sd, "Upgrade", "h2c") < 0)
- goto done;
- if (restconf_reply_send(sd, 101, NULL, 0) < 0) /* Switch protocol */
- goto done;
- /* Signal http/2 upgrade to http/2 to upper restconf_connection handling */
- sd->sd_upgrade2 = 1;
- if ((settings = restconf_param_get(h, "HTTP_HTTP2_Settings")) != NULL &&
- (sd->sd_settings2 = (uint8_t*)strdup(settings)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- }
- retval = 0; /* Yes, upgrade or error */
+ clicon_option_bool(h, "CLICON_RESTCONF_HTTP2_PLAIN") == 1){
+ /* Only accept "h2c" */
+ if (strcmp(str, "h2c") != 0){
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid upgrade token") < 0)
+ goto done;
+ if (api_return_err0(h, sd, xerr, 1, YANG_DATA_JSON, 0) < 0)
+ goto done;
+ if (xerr)
+ xml_free(xerr);
+ }
+ else {
+ if (restconf_reply_header(sd, "Connection", "Upgrade") < 0)
+ goto done;
+ if (restconf_reply_header(sd, "Upgrade", "h2c") < 0)
+ goto done;
+ if (restconf_reply_send(sd, 101, NULL, 0) < 0) /* Switch protocol */
+ goto done;
+ /* Signal http/2 upgrade to http/2 to upper restconf_connection handling */
+ sd->sd_upgrade2 = 1;
+ if ((settings = restconf_param_get(h, "HTTP_HTTP2_Settings")) != NULL &&
+ (sd->sd_settings2 = (uint8_t*)strdup(settings)) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ }
+ retval = 0; /* Yes, upgrade or error */
}
else
- retval = 1; /* No upgrade, proceed with request */
+ retval = 1; /* No upgrade, proceed with request */
done:
return retval;
}
@@ -296,7 +296,7 @@ http1_upgrade_http2(clicon_handle h,
*/
static int
restconf_http1_reply(restconf_conn *rc,
- restconf_stream_data *sd)
+ restconf_stream_data *sd)
{
int retval = -1;
cg_var *cv;
@@ -310,32 +310,32 @@ restconf_http1_reply(restconf_conn *rc,
* [RFC7231]).
*/
if (sd->sd_code != 204 && sd->sd_code > 199)
- if (restconf_reply_header(sd, "Content-Length", "%zu", sd->sd_body_len) < 0)
- goto done;
+ if (restconf_reply_header(sd, "Content-Length", "%zu", sd->sd_body_len) < 0)
+ goto done;
/* Create reply and write headers */
#if 0 /* XXX need some keep-alive logic here */
/* protocol is HTTP/1.0 and clients wants to keep established */
if (restconf_reply_header(sd, "Connection", "keep-alive") < 0)
- goto done;
+ goto done;
#endif
cprintf(sd->sd_outp_buf, "HTTP/%u.%u %u %s\r\n",
- rc->rc_proto_d1,
- rc->rc_proto_d2,
- sd->sd_code,
- restconf_code2reason(sd->sd_code));
+ rc->rc_proto_d1,
+ rc->rc_proto_d2,
+ sd->sd_code,
+ restconf_code2reason(sd->sd_code));
/* Loop over headers */
cv = NULL;
while ((cv = cvec_each(sd->sd_outp_hdrs, cv)) != NULL)
- cprintf(sd->sd_outp_buf, "%s: %s\r\n", cv_name_get(cv), cv_string_get(cv));
+ cprintf(sd->sd_outp_buf, "%s: %s\r\n", cv_name_get(cv), cv_string_get(cv));
cprintf(sd->sd_outp_buf, "\r\n");
/* Write a body */
if (sd->sd_body){
- if (cbuf_append_buf(sd->sd_outp_buf, cbuf_get(sd->sd_body), cbuf_len(sd->sd_body)) < 0){
- clicon_err(OE_RESTCONF, errno, "cbuf_append_buf");
- goto done;
- }
- cbuf_free(sd->sd_body);
- sd->sd_body = NULL;
+ if (cbuf_append_buf(sd->sd_outp_buf, cbuf_get(sd->sd_body), cbuf_len(sd->sd_body)) < 0){
+ clicon_err(OE_RESTCONF, errno, "cbuf_append_buf");
+ goto done;
+ }
+ cbuf_free(sd->sd_body);
+ sd->sd_body = NULL;
}
retval = 0;
done:
@@ -348,7 +348,7 @@ restconf_http1_reply(restconf_conn *rc,
*/
int
restconf_http1_path_root(clicon_handle h,
- restconf_conn *rc)
+ restconf_conn *rc)
{
int retval = -1;
restconf_stream_data *sd = NULL;
@@ -364,68 +364,68 @@ restconf_http1_path_root(clicon_handle h,
clicon_debug(1, "------------");
pretty = restconf_pretty_get(h);
if ((sd = restconf_stream_find(rc, 0)) == NULL){
- clicon_err(OE_RESTCONF, EINVAL, "No stream_data");
- goto done;
+ clicon_err(OE_RESTCONF, EINVAL, "No stream_data");
+ goto done;
}
/* Sanity check */
if (restconf_param_get(h, "REQUEST_URI") == NULL){
- if (netconf_invalid_value_xml(&xerr, "protocol", "Missing REQUEST_URI ") < 0)
- goto done;
- /* Select json as default since content-type header may not be accessible yet */
- if (api_return_err0(h, sd, xerr, pretty, YANG_DATA_JSON, 0) < 0)
- goto done;
- goto fail;
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Missing REQUEST_URI ") < 0)
+ goto done;
+ /* Select json as default since content-type header may not be accessible yet */
+ if (api_return_err0(h, sd, xerr, pretty, YANG_DATA_JSON, 0) < 0)
+ goto done;
+ goto fail;
}
if ((rc->rc_proto != HTTP_10 && rc->rc_proto != HTTP_11) ||
- rc->rc_proto_d1 != 1 ||
- (rc->rc_proto_d2 != 0 && rc->rc_proto_d2 != 1)){
- if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid HTTP version number") < 0)
- goto done;
- /* Select json as default since content-type header may not be accessible yet */
- if (api_return_err0(h, sd, xerr, pretty, YANG_DATA_JSON, 0) < 0)
- goto done;
- goto fail;
+ rc->rc_proto_d1 != 1 ||
+ (rc->rc_proto_d2 != 0 && rc->rc_proto_d2 != 1)){
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid HTTP version number") < 0)
+ goto done;
+ /* Select json as default since content-type header may not be accessible yet */
+ if (api_return_err0(h, sd, xerr, pretty, YANG_DATA_JSON, 0) < 0)
+ goto done;
+ goto fail;
}
#if 1
/* XXX gives mem leak in multiple requests,
* but maybe the error is that sd is not freed.
*/
if (sd->sd_path != NULL){
- free(sd->sd_path);
- sd->sd_path = NULL;
+ free(sd->sd_path);
+ sd->sd_path = NULL;
}
#endif
if ((sd->sd_path = restconf_uripath(rc->rc_h)) == NULL)
- goto done; // XXX SHOULDNT EXIT if no REQUEST_URI
+ goto done; // XXX SHOULDNT EXIT if no REQUEST_URI
if (rc->rc_proto_d2 == 0 && rc->rc_proto == HTTP_11)
- rc->rc_proto = HTTP_10;
+ rc->rc_proto = HTTP_10;
else if (rc->rc_proto_d2 == 1 && rc->rc_proto != HTTP_10)
- rc->rc_proto = HTTP_11;
+ rc->rc_proto = HTTP_11;
if (rc->rc_ssl != NULL){
- /* Slightly awkward way of taking SSL cert subject and CN and add it to restconf parameters
- * instead of accessing it directly
- * SSL subject fields, eg CN (Common Name) , can add more here? */
- if (ssl_x509_name_oneline(rc->rc_ssl, &subject) < 0)
- goto done;
- if (subject != NULL) {
- if (uri_str2cvec(subject, '/', '=', 1, &cvv) < 0)
- goto done;
- if ((cn = cvec_find_str(cvv, "CN")) != NULL){
- if (restconf_param_set(h, "SSL_CN", cn) < 0)
- goto done;
- }
- }
+ /* Slightly awkward way of taking SSL cert subject and CN and add it to restconf parameters
+ * instead of accessing it directly
+ * SSL subject fields, eg CN (Common Name) , can add more here? */
+ if (ssl_x509_name_oneline(rc->rc_ssl, &subject) < 0)
+ goto done;
+ if (subject != NULL) {
+ if (uri_str2cvec(subject, '/', '=', 1, &cvv) < 0)
+ goto done;
+ if ((cn = cvec_find_str(cvv, "CN")) != NULL){
+ if (restconf_param_set(h, "SSL_CN", cn) < 0)
+ goto done;
+ }
+ }
}
/* Check sanity of session, eg ssl client cert validation, may set rc_exit */
if (restconf_connection_sanity(h, rc, sd) < 0)
- goto done;
+ goto done;
if (rc->rc_exit)
- goto fail;
+ goto fail;
#ifdef HAVE_LIBNGHTTP2
if ((ret = http1_upgrade_http2(h, sd)) < 0)
- goto done;
+ goto done;
if (ret == 0) /* upgrade */
- goto upgrade;
+ goto upgrade;
#endif
/* Matching algorithm:
* 1. try well-known
@@ -435,37 +435,37 @@ restconf_http1_path_root(clicon_handle h,
* This is for the situation where data is / and /restconf is more specific
*/
if (strcmp(sd->sd_path, RESTCONF_WELL_KNOWN) == 0){
- if (api_well_known(h, sd) < 0)
- goto done;
+ if (api_well_known(h, sd) < 0)
+ goto done;
}
else if (api_path_is_restconf(h)){
- if (api_root_restconf(h, sd, sd->sd_qvec) < 0)
- goto done;
+ if (api_root_restconf(h, sd, sd->sd_qvec) < 0)
+ goto done;
}
else if (api_path_is_data(h)){
- if (api_http_data(h, sd, sd->sd_qvec) < 0)
- goto done;
+ if (api_http_data(h, sd, sd->sd_qvec) < 0)
+ goto done;
}
else
- sd->sd_code = 404; /* catch all without body/media */
+ sd->sd_code = 404; /* catch all without body/media */
fail:
if (restconf_param_del_all(h) < 0)
- goto done;
+ goto done;
#ifdef HAVE_LIBNGHTTP2
upgrade:
#endif
if (sd->sd_code)
- if (restconf_http1_reply(rc, sd) < 0)
- goto done;
+ if (restconf_http1_reply(rc, sd) < 0)
+ goto done;
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
if (subject)
- free(subject);
+ free(subject);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (cvv)
- cvec_free(cvv);
+ cvec_free(cvv);
return retval;
}
@@ -481,21 +481,21 @@ restconf_http1_path_root(clicon_handle h,
*/
int
http1_check_expect(clicon_handle h,
- restconf_conn *rc,
- restconf_stream_data *sd)
+ restconf_conn *rc,
+ restconf_stream_data *sd)
{
int retval = -1;
char *val;
if ((val = restconf_param_get(h, "HTTP_EXPECT")) != NULL &&
- strcmp(val, "100-continue") == 0){ /* just drop if not well-formed */
- sd->sd_code = 100;
- if (restconf_http1_reply(rc, sd) < 0)
- goto done;
- retval = 1; /* send continue by flushing stream buffer after the call */
+ strcmp(val, "100-continue") == 0){ /* just drop if not well-formed */
+ sd->sd_code = 100;
+ if (restconf_http1_reply(rc, sd) < 0)
+ goto done;
+ retval = 1; /* send continue by flushing stream buffer after the call */
}
else
- retval = 0;
+ retval = 0;
done:
return retval;
}
@@ -515,21 +515,21 @@ http1_check_expect(clicon_handle h,
*/
int
http1_check_content_length(clicon_handle h,
- restconf_stream_data *sd,
- int *status)
+ restconf_stream_data *sd,
+ int *status)
{
int retval = -1;
char *val;
int len;
if ((val = restconf_param_get(h, "HTTP_CONTENT_LENGTH")) == NULL ||
- (len = atoi(val)) == 0)
- *status = 0;
+ (len = atoi(val)) == 0)
+ *status = 0;
else{
- if (cbuf_len(sd->sd_indata) < len)
- *status = 1;
- else
- *status = 2;
+ if (cbuf_len(sd->sd_indata) < len)
+ *status = 1;
+ else
+ *status = 2;
}
retval = 0;
return retval;
diff --git a/apps/restconf/restconf_http1.h b/apps/restconf/restconf_http1.h
index bca39373..8606ad99 100644
--- a/apps/restconf/restconf_http1.h
+++ b/apps/restconf/restconf_http1.h
@@ -46,4 +46,4 @@ int restconf_http1_path_root(clicon_handle h, restconf_conn *rc);
int http1_check_expect(clicon_handle h, restconf_conn *rc, restconf_stream_data *sd);
int http1_check_content_length(clicon_handle h, restconf_stream_data *sd, int *status);
-#endif /* _RESTCONF_HTTP1_H_ */
+#endif /* _RESTCONF_HTTP1_H_ */
diff --git a/apps/restconf/restconf_lib.c b/apps/restconf/restconf_lib.c
index 5f2fa131..63c005b8 100644
--- a/apps/restconf/restconf_lib.c
+++ b/apps/restconf/restconf_lib.c
@@ -270,9 +270,9 @@ restconf_content_type(clicon_handle h)
restconf_media m;
if ((str = restconf_param_get(h, "HTTP_CONTENT_TYPE")) == NULL)
- return -1;
+ return -1;
if ((int)(m = restconf_media_str2int(str)) == -1)
- return -1;
+ return -1;
return m;
}
@@ -281,8 +281,8 @@ restconf_content_type(clicon_handle h)
*/
int
restconf_convert_hdr(clicon_handle h,
- char *name,
- char *val)
+ char *name,
+ char *val)
{
int retval = -1;
cbuf *cb = NULL;
@@ -291,27 +291,27 @@ restconf_convert_hdr(clicon_handle h,
size_t len;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
/* convert key name */
cprintf(cb, "HTTP_");
len = strlen(name);
for (i=0; i []*/
- if ((p = rindex(xpath,'/')) == NULL)
- p = xpath;
- p = index(p, '[');
- cprintf(cb, "%s", p);
- }
- else{ /* LEAF_LIST */
- /* translate /../x[.='x'] --> x */
- if ((p = rindex(xpath,'\'')) == NULL){
- clicon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath);
- goto done;
- }
- *p = '\0';
- if ((p = rindex(xpath,'\'')) == NULL){
- clicon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath);
- goto done;
- }
- p++;
- cprintf(cb, "%s", p);
- }
- if (xml_value_set(xa, cbuf_get(cb)) < 0)
- goto done;
+ if (y == NULL){
+ clicon_err(OE_YANG, 0, "Cannot yang resolve %s", xml_name(xdata));
+ goto done;
+ }
+ if (yang_keyword_get(y) == Y_LIST)
+ attrname="key";
+ else
+ attrname="value";
+ /* Then add value/key attribute */
+ if ((xa = xml_new(attrname, xdata, CX_ATTR)) == NULL)
+ goto done;
+ if (xml_prefix_set(xa, "yang") < 0)
+ goto done;
+ if ((ret = api_path2xpath(pstr, ys_spec(y), &xpath, &nsc, NULL)) < 0)
+ goto done;
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ if (yang_keyword_get(y) == Y_LIST){
+ /* translate /../x[] --> []*/
+ if ((p = rindex(xpath,'/')) == NULL)
+ p = xpath;
+ p = index(p, '[');
+ cprintf(cb, "%s", p);
+ }
+ else{ /* LEAF_LIST */
+ /* translate /../x[.='x'] --> x */
+ if ((p = rindex(xpath,'\'')) == NULL){
+ clicon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath);
+ goto done;
+ }
+ *p = '\0';
+ if ((p = rindex(xpath,'\'')) == NULL){
+ clicon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath);
+ goto done;
+ }
+ p++;
+ cprintf(cb, "%s", p);
+ }
+ if (xml_value_set(xa, cbuf_get(cb)) < 0)
+ goto done;
}
/* Add prefix/namespaces used in attributes */
cv = NULL;
while ((cv = cvec_each(nsc, cv)) != NULL){
- char *ns = cv_string_get(cv);
- if (xmlns_set(xdata, cv_name_get(cv), ns) < 0)
- goto done;
+ char *ns = cv_string_get(cv);
+ if (xmlns_set(xdata, cv_name_get(cv), ns) < 0)
+ goto done;
}
if (nsc)
- xml_sort(xdata); /* Ensure attr is first */
+ xml_sort(xdata); /* Ensure attr is first */
cprintf(cb, "/>");
retval = 0;
done:
if (xpath)
- free(xpath);
+ free(xpath);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -512,8 +512,8 @@ restconf_insert_attributes(cxobj *xdata,
*/
int
restconf_main_extension_cb(clicon_handle h,
- yang_stmt *yext,
- yang_stmt *ys)
+ yang_stmt *yext,
+ yang_stmt *ys)
{
int retval = -1;
char *extname;
@@ -526,17 +526,17 @@ restconf_main_extension_cb(clicon_handle h,
modname = yang_argument_get(ymod);
extname = yang_argument_get(yext);
if (strcmp(modname, "ietf-restconf") != 0 || strcmp(extname, "yang-data") != 0)
- goto ok;
+ goto ok;
clicon_debug(1, "%s Enabled extension:%s:%s", __FUNCTION__, modname, extname);
if ((yc = yang_find(ys, 0, NULL)) == NULL)
- goto ok;
+ goto ok;
if ((yn = ys_dup(yc)) == NULL)
- goto done;
+ goto done;
/* yang-data extension: The list-stmt is not required to have a key-stmt defined.
*/
yang_flag_set(yn, YANG_FLAG_NOKEY);
if (yn_insert(yang_parent_get(ys), yn) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
@@ -557,15 +557,15 @@ restconf_uripath(clicon_handle h)
char *q;
if ((path = restconf_param_get(h, "REQUEST_URI")) == NULL){
- clicon_err(OE_RESTCONF, 0, "No REQUEST_URI");
- return NULL;
+ clicon_err(OE_RESTCONF, 0, "No REQUEST_URI");
+ return NULL;
}
if ((path2 = strdup(path)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- return NULL;
+ clicon_err(OE_UNIX, errno, "strdup");
+ return NULL;
}
if ((q = index(path2, '?')) != NULL)
- *q = '\0';
+ *q = '\0';
return path2;
}
@@ -587,60 +587,60 @@ restconf_drop_privileges(clicon_handle h)
clicon_debug(1, "%s", __FUNCTION__);
/* Sanity check: backend group exists */
if ((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(group, &gid) < 0){
- clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group." /* \n required here due to multi-line log */
- "The config daemon requires a valid group to create a server UNIX socket\n"
- "Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n"
- "or create the group and add the user to it. Check documentation for how to do this on your platform",
- group,
- clicon_configfile(h));
- goto done;
+ clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group." /* \n required here due to multi-line log */
+ "The config daemon requires a valid group to create a server UNIX socket\n"
+ "Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n"
+ "or create the group and add the user to it. Check documentation for how to do this on your platform",
+ group,
+ clicon_configfile(h));
+ goto done;
}
/* Get privileges mode (for dropping privileges) */
if ((priv_mode = clicon_restconf_privileges_mode(h)) == PM_NONE)
- goto ok;
+ goto ok;
if ((user = clicon_option_str(h, "CLICON_RESTCONF_USER")) == NULL)
- goto ok;
+ goto ok;
/* Get (wanted) new www user id */
if (name2uid(user, &newuid) < 0){
- clicon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", user);
- goto done;
+ clicon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", user);
+ goto done;
}
/* get current userid, if already at this level OK */
if ((uid = getuid()) == newuid)
- goto ok;
+ goto ok;
if (uid != 0){
- clicon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid);
- goto done;
+ clicon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid);
+ goto done;
}
if (setgid(gid) == -1) {
- clicon_err(OE_DAEMON, errno, "setgid %d", gid);
- goto done;
+ clicon_err(OE_DAEMON, errno, "setgid %d", gid);
+ goto done;
}
switch (priv_mode){
case PM_DROP_PERM:
- if (drop_priv_perm(newuid) < 0)
- goto done;
- /* Verify you cannot regain root privileges */
- if (setuid(0) != -1){
- clicon_err(OE_DAEMON, EPERM, "Could regain root privilieges");
- goto done;
- }
- break;
+ if (drop_priv_perm(newuid) < 0)
+ goto done;
+ /* Verify you cannot regain root privileges */
+ if (setuid(0) != -1){
+ clicon_err(OE_DAEMON, EPERM, "Could regain root privilieges");
+ goto done;
+ }
+ break;
case PM_DROP_TEMP:
- if (drop_priv_temp(newuid) < 0)
- goto done;
- break;
+ if (drop_priv_temp(newuid) < 0)
+ goto done;
+ break;
case PM_NONE:
- break; /* catched above */
+ break; /* catched above */
}
clicon_debug(1, "%s dropped privileges from root to %s(%d)",
- __FUNCTION__, user, newuid);
+ __FUNCTION__, user, newuid);
ok:
retval = 0;
done:
@@ -658,9 +658,9 @@ restconf_drop_privileges(clicon_handle h)
*/
int
restconf_authentication_cb(clicon_handle h,
- void *req,
- int pretty,
- restconf_media media_out)
+ void *req,
+ int pretty,
+ restconf_media media_out)
{
int retval = -1;
clixon_auth_type_t auth_type;
@@ -677,59 +677,59 @@ restconf_authentication_cb(clicon_handle h,
authenticated = 0;
/* ret: -1 Error, 0: Ignore/not handled, 1: OK see authenticated parameter */
if ((ret = clixon_plugin_auth_all(h, req,
- auth_type,
- &username)) < 0)
- goto done;
+ auth_type,
+ &username)) < 0)
+ goto done;
if (ret == 1){ /* OK, tag username to handle */
- if (username != NULL){
- authenticated = 1;
- clicon_username_set(h, username);
- }
+ if (username != NULL){
+ authenticated = 1;
+ clicon_username_set(h, username);
+ }
}
else { /* Default behaviour */
- switch (auth_type){
- case CLIXON_AUTH_NONE:
- /* if not handled by callback, use anonymous user */
- if ((anonymous = clicon_option_str(h, "CLICON_ANONYMOUS_USER")) == NULL){
- break; /* not authenticated */
- }
- clicon_username_set(h, anonymous);
- authenticated = 1;
- break;
- case CLIXON_AUTH_CLIENT_CERTIFICATE: {
- char *cn;
- /* Check for cert subject common name (CN) */
- if ((cn = restconf_param_get(h, "SSL_CN")) != NULL){
- clicon_username_set(h, cn);
- authenticated = 1;
- }
- break;
- }
- case CLIXON_AUTH_USER:
- authenticated = 0;
- break;
- }
+ switch (auth_type){
+ case CLIXON_AUTH_NONE:
+ /* if not handled by callback, use anonymous user */
+ if ((anonymous = clicon_option_str(h, "CLICON_ANONYMOUS_USER")) == NULL){
+ break; /* not authenticated */
+ }
+ clicon_username_set(h, anonymous);
+ authenticated = 1;
+ break;
+ case CLIXON_AUTH_CLIENT_CERTIFICATE: {
+ char *cn;
+ /* Check for cert subject common name (CN) */
+ if ((cn = restconf_param_get(h, "SSL_CN")) != NULL){
+ clicon_username_set(h, cn);
+ authenticated = 1;
+ }
+ break;
+ }
+ case CLIXON_AUTH_USER:
+ authenticated = 0;
+ break;
+ }
}
if (authenticated == 0){ /* Message is not authenticated (401 returned) */
- if (netconf_access_denied_xml(&xret, "protocol", "The requested URL was unauthorized") < 0)
- goto done;
- if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- if (api_return_err(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto notauth;
- }
- retval = 0;
- goto notauth;
+ if (netconf_access_denied_xml(&xret, "protocol", "The requested URL was unauthorized") < 0)
+ goto done;
+ if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
+ if (api_return_err(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto notauth;
+ }
+ retval = 0;
+ goto notauth;
}
/* If set but no user, set a dummy user */
retval = 1;
done:
clicon_debug(1, "%s retval:%d authenticated:%d user:%s",
- __FUNCTION__, retval, authenticated, clicon_username_get(h));
+ __FUNCTION__, retval, authenticated, clicon_username_get(h));
if (username)
- free(username);
+ free(username);
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
notauth:
retval = 0;
@@ -745,7 +745,7 @@ restconf_authentication_cb(clicon_handle h,
*/
int
restconf_config_init(clicon_handle h,
- cxobj *xrestconf)
+ cxobj *xrestconf)
{
int retval = -1;
char *enable;
@@ -757,59 +757,59 @@ restconf_config_init(clicon_handle h,
yang_stmt *y;
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
/* Apply default values (removed in clear function) */
if (xml_default_recurse(xrestconf, 0) < 0)
- goto done;
+ goto done;
if ((x = xpath_first(xrestconf, nsc, "enable")) != NULL &&
- (enable = xml_body(x)) != NULL){
- if (strcmp(enable, "false") == 0){
- clicon_debug(1, "%s restconf disabled", __FUNCTION__);
- goto disable;
- }
+ (enable = xml_body(x)) != NULL){
+ if (strcmp(enable, "false") == 0){
+ clicon_debug(1, "%s restconf disabled", __FUNCTION__);
+ goto disable;
+ }
}
/* get common fields */
if ((x = xpath_first(xrestconf, nsc, "auth-type")) != NULL &&
- (bstr = xml_body(x)) != NULL){
- if ((auth_type = clixon_auth_type_str2int(bstr)) < 0){
- clicon_err(OE_CFG, EFAULT, "Invalid restconf auth-type: %s", bstr);
- goto done;
- }
- restconf_auth_type_set(h, auth_type);
+ (bstr = xml_body(x)) != NULL){
+ if ((auth_type = clixon_auth_type_str2int(bstr)) < 0){
+ clicon_err(OE_CFG, EFAULT, "Invalid restconf auth-type: %s", bstr);
+ goto done;
+ }
+ restconf_auth_type_set(h, auth_type);
}
if ((x = xpath_first(xrestconf, nsc, "pretty")) != NULL &&
- (bstr = xml_body(x)) != NULL){
- if (strcmp(bstr, "true") == 0)
- restconf_pretty_set(h, 1);
- else if (strcmp(bstr, "false") == 0)
- restconf_pretty_set(h, 0);
+ (bstr = xml_body(x)) != NULL){
+ if (strcmp(bstr, "true") == 0)
+ restconf_pretty_set(h, 1);
+ else if (strcmp(bstr, "false") == 0)
+ restconf_pretty_set(h, 0);
}
/* Check if enable-http-data is true and that feature is enabled
* It is protected by if-feature http-data, which means if the feature is not enabled, its
* YANG spec will exist but by ANYDATA
*/
if ((x = xpath_first(xrestconf, nsc, "enable-http-data")) != NULL &&
- (y = xml_spec(x)) != NULL &&
- yang_keyword_get(y) != Y_ANYDATA &&
- (bstr = xml_body(x)) != NULL &&
- strcmp(bstr, "true") == 0) {
- restconf_http_data_set(h, 1);
+ (y = xml_spec(x)) != NULL &&
+ yang_keyword_get(y) != Y_ANYDATA &&
+ (bstr = xml_body(x)) != NULL &&
+ strcmp(bstr, "true") == 0) {
+ restconf_http_data_set(h, 1);
}
else
- restconf_http_data_set(h, 0);
+ restconf_http_data_set(h, 0);
/* Check if fcgi-socket is true and that feature is enabled
* It is protected by if-feature fcgi, which means if the feature is not enabled, then
* YANG spec will exist but by ANYDATA
*/
if ((x = xpath_first(xrestconf, nsc, "fcgi-socket")) != NULL &&
- (y = xml_spec(x)) != NULL &&
- yang_keyword_get(y) != Y_ANYDATA &&
- (bstr = xml_body(x)) != NULL){
- if (restconf_fcgi_socket_set(h, bstr) < 0)
- goto done;
+ (y = xml_spec(x)) != NULL &&
+ yang_keyword_get(y) != Y_ANYDATA &&
+ (bstr = xml_body(x)) != NULL){
+ if (restconf_fcgi_socket_set(h, bstr) < 0)
+ goto done;
}
retval = 1;
done:
@@ -832,12 +832,12 @@ restconf_config_init(clicon_handle h,
*/
int
restconf_socket_init(const char *netns0,
- const char *addrstr,
- const char *addrtype,
- uint16_t port,
- int backlog,
- int flags,
- int *ss)
+ const char *addrstr,
+ const char *addrtype,
+ uint16_t port,
+ int backlog,
+ int flags,
+ int *ss)
{
int retval = -1;
struct sockaddr_in6 sin6 = {0,}; // because its larger than sin and sa
@@ -848,13 +848,13 @@ restconf_socket_init(const char *netns0,
clicon_debug(1, "%s %s %s %s %hu", __FUNCTION__, netns0, addrtype, addrstr, port);
/* netns default -> NULL */
if (netns0 != NULL && strcmp(netns0, RESTCONF_NETNS_DEFAULT)==0)
- netns = NULL;
+ netns = NULL;
else
- netns = netns0;
+ netns = netns0;
if (clixon_inet2sin(addrtype, addrstr, port, sa, &sa_len) < 0)
- goto done;
+ goto done;
if (clixon_netns_socket(netns, sa, sa_len, backlog, flags, addrstr, ss) < 0)
- goto done;
+ goto done;
clicon_debug(1, "%s ss=%d", __FUNCTION__, *ss);
retval = 0;
done:
diff --git a/apps/restconf/restconf_main_fcgi.c b/apps/restconf/restconf_main_fcgi.c
index a5d0faf0..36e2c880 100644
--- a/apps/restconf/restconf_main_fcgi.c
+++ b/apps/restconf/restconf_main_fcgi.c
@@ -97,7 +97,7 @@
*/
static int
fcgi_params_set(clicon_handle h,
- char **envp)
+ char **envp)
{
int retval = -1;
int i;
@@ -106,18 +106,18 @@ fcgi_params_set(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
for (i = 0; envp[i] != NULL; i++){ /* on the form = */
- if (clixon_strsplit(envp[i], '=', ¶m, &val) < 0)
- goto done;
- if (restconf_param_set(h, param, val) < 0)
- goto done;
- if (param){
- free(param);
- param = NULL;
- }
- if (val){
- free(val);
- val = NULL;
- }
+ if (clixon_strsplit(envp[i], '=', ¶m, &val) < 0)
+ goto done;
+ if (restconf_param_set(h, param, val) < 0)
+ goto done;
+ if (param){
+ free(param);
+ param = NULL;
+ }
+ if (val){
+ free(val);
+ val = NULL;
+ }
}
retval = 0;
done:
@@ -129,8 +129,8 @@ fcgi_params_set(clicon_handle h,
*/
static int
restconf_main_config(clicon_handle h,
- yang_stmt *yspec,
- const char *inline_config)
+ yang_stmt *yspec,
+ const char *inline_config)
{
int retval = -1;
struct passwd *pw;
@@ -144,68 +144,68 @@ restconf_main_config(clicon_handle h,
/* 1. try inline configure option */
if (inline_config != NULL && strlen(inline_config)){
- clicon_debug(1, "restconf_main_fcgi using restconf inline config");
- if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0)
- goto done;
- if (ret == 0){
- clixon_netconf_error(xerr, "Inline restconf config", NULL);
- goto done;
- }
- /* Replace parent w first child */
- if (xml_rootchild(xrestconf, 0, &xrestconf) < 0)
- goto done;
+ clicon_debug(1, "restconf_main_fcgi using restconf inline config");
+ if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ clixon_netconf_error(xerr, "Inline restconf config", NULL);
+ goto done;
+ }
+ /* Replace parent w first child */
+ if (xml_rootchild(xrestconf, 0, &xrestconf) < 0)
+ goto done;
}
else if (clicon_option_bool(h, "CLICON_BACKEND_RESTCONF_PROCESS") == 0){
- /* 2. If not read from backend, try to get restconf config from local config-file */
- xrestconf = clicon_conf_restconf(h);
+ /* 2. If not read from backend, try to get restconf config from local config-file */
+ xrestconf = clicon_conf_restconf(h);
}
/* 3. If no local config, or it is disabled, try to query backend of config. */
else {
- /* Loop to wait for backend starting, try again if not done */
- while (1){
- if (clicon_hello_req(h, &id) < 0){
- if (errno == ENOENT){
- fprintf(stderr, "waiting");
- sleep(1);
- continue;
- }
- clicon_err(OE_UNIX, errno, "clicon_session_id_get");
- goto done;
- }
- clicon_session_id_set(h, id);
- break;
- }
- if ((nsc = xml_nsctx_init(NULL, CLIXON_RESTCONF_NS)) == NULL)
- goto done;
- if ((pw = getpwuid(getuid())) == NULL){
- clicon_err(OE_UNIX, errno, "getpwuid");
- goto done;
- }
- if (clicon_rpc_get_config(h, pw->pw_name, "running", "/restconf", nsc, NULL, &xconfig) < 0)
- goto done;
- if ((xerr = xpath_first(xconfig, NULL, "/rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Get backend restconf config", NULL);
- goto done;
- }
- /* Extract restconf configuration */
- xrestconf = xpath_first(xconfig, nsc, "restconf");
+ /* Loop to wait for backend starting, try again if not done */
+ while (1){
+ if (clicon_hello_req(h, &id) < 0){
+ if (errno == ENOENT){
+ fprintf(stderr, "waiting");
+ sleep(1);
+ continue;
+ }
+ clicon_err(OE_UNIX, errno, "clicon_session_id_get");
+ goto done;
+ }
+ clicon_session_id_set(h, id);
+ break;
+ }
+ if ((nsc = xml_nsctx_init(NULL, CLIXON_RESTCONF_NS)) == NULL)
+ goto done;
+ if ((pw = getpwuid(getuid())) == NULL){
+ clicon_err(OE_UNIX, errno, "getpwuid");
+ goto done;
+ }
+ if (clicon_rpc_get_config(h, pw->pw_name, "running", "/restconf", nsc, NULL, &xconfig) < 0)
+ goto done;
+ if ((xerr = xpath_first(xconfig, NULL, "/rpc-error")) != NULL){
+ clixon_netconf_error(xerr, "Get backend restconf config", NULL);
+ goto done;
+ }
+ /* Extract restconf configuration */
+ xrestconf = xpath_first(xconfig, nsc, "restconf");
}
configure_done = 0;
if (xrestconf != NULL &&
- (configure_done = restconf_config_init(h, xrestconf)) < 0)
- goto done;
+ (configure_done = restconf_config_init(h, xrestconf)) < 0)
+ goto done;
if (!configure_done){ /* Query backend of config. */
- clicon_err(OE_DAEMON, EFAULT, "Restconf daemon config not found or disabled");
- goto done;
+ clicon_err(OE_DAEMON, EFAULT, "Restconf daemon config not found or disabled");
+ goto done;
}
retval = 0;
done:
if (nsc)
- cvec_free(nsc);
+ cvec_free(nsc);
if (inline_config != NULL && strlen(inline_config) && xrestconf)
- xml_free(xrestconf);
+ xml_free(xrestconf);
if (xconfig)
- xml_free(xconfig);
+ xml_free(xconfig);
return retval;
}
@@ -226,11 +226,11 @@ restconf_sig_term(int arg)
clicon_debug(1, "%s", __FUNCTION__);
if (i++ == 0)
- clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d",
- __PROGRAM__, __FUNCTION__, getpid(), arg);
+ clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d",
+ __PROGRAM__, __FUNCTION__, getpid(), arg);
else{
- clicon_debug(1, "%s done", __FUNCTION__);
- exit(-1);
+ clicon_debug(1, "%s done", __FUNCTION__);
+ exit(-1);
}
/* This should ensure no more accepts or incoming packets are processed because next time eventloop
@@ -251,7 +251,7 @@ restconf_sig_child(int arg)
int pid;
if ((pid = waitpid(-1, &status, 0)) != -1 && WIFEXITED(status))
- stream_child_free(_CLICON_HANDLE, pid);
+ stream_child_free(_CLICON_HANDLE, pid);
}
/*! Usage help routine
@@ -263,23 +263,23 @@ usage(clicon_handle h,
char *argv0)
{
fprintf(stderr, "usage:%s [options]\n"
- "where options are\n"
+ "where options are\n"
"\t-h \t\t Help\n"
- "\t-D \t Debug level\n"
- "\t-f \t Configuration file (mandatory)\n"
- "\t-E \t Extra configuration file directory\n"
- "\t-l > \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (syslog is default)\n"
- "\t-p \t Yang directory path (see CLICON_YANG_DIR)\n"
- "\t-y \t Load yang spec file (override yang main module)\n"
- "\t-a UNIX|IPv4|IPv6 Internal backend socket family\n"
+ "\t-D \t Debug level\n"
+ "\t-f \t Configuration file (mandatory)\n"
+ "\t-E \t Extra configuration file directory\n"
+ "\t-l > \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (syslog is default)\n"
+ "\t-p \t Yang directory path (see CLICON_YANG_DIR)\n"
+ "\t-y \t Load yang spec file (override yang main module)\n"
+ "\t-a UNIX|IPv4|IPv6 Internal backend socket family\n"
- "\t-u \t Internal socket domain path or IP addr (see -a)\n"
- "\t-r \t\t Do not drop privileges if run as root\n"
- "\t-W \t Run restconf daemon as this user, drop according to CLICON_RESTCONF_PRIVILEGES\n"
- "\t-R \t Restconf configuration in-line overriding config file\n"
- "\t-o \"=\" Give configuration option overriding config file (see clixon-config.yang)\n",
- argv0
- );
+ "\t-u \t Internal socket domain path or IP addr (see -a)\n"
+ "\t-r \t\t Do not drop privileges if run as root\n"
+ "\t-W \t Run restconf daemon as this user, drop according to CLICON_RESTCONF_PRIVILEGES\n"
+ "\t-R \t Restconf configuration in-line overriding config file\n"
+ "\t-o \"=\" Give configuration option overriding config file (see clixon-config.yang)\n",
+ argv0
+ );
exit(0);
}
@@ -291,7 +291,7 @@ main(int argc,
{
int retval = -1;
int sock;
- char *argv0 = argv[0];
+ char *argv0 = argv[0];
FCGX_Request request;
FCGX_Request *req = &request;
int c;
@@ -320,38 +320,38 @@ main(int argc,
/* Create handle */
if ((h = restconf_handle_init()) == NULL)
- goto done;
+ goto done;
_CLICON_HANDLE = h; /* for termination handling */
while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1)
- switch (c) {
- case 'h':
- usage(h, argv[0]);
- break;
- case 'D' : /* debug */
- if (sscanf(optarg, "%d", &dbg) != 1)
- usage(h, argv[0]);
- break;
- case 'f': /* override config file */
- if (!strlen(optarg))
- usage(h, argv[0]);
- clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
- break;
- case 'E': /* extra config directory */
- if (!strlen(optarg))
- usage(h, argv[0]);
- clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
- break;
- case 'l': /* Log destination: s|e|o */
- if ((logdst = clicon_log_opt(optarg[0])) < 0)
- usage(h, argv[0]);
- if (logdst == CLICON_LOG_FILE &&
- strlen(optarg)>1 &&
- clicon_log_file(optarg+1) < 0)
- goto done;
- break;
- } /* switch getopt */
+ switch (c) {
+ case 'h':
+ usage(h, argv[0]);
+ break;
+ case 'D' : /* debug */
+ if (sscanf(optarg, "%d", &dbg) != 1)
+ usage(h, argv[0]);
+ break;
+ case 'f': /* override config file */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
+ break;
+ case 'E': /* extra config directory */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
+ break;
+ case 'l': /* Log destination: s|e|o */
+ if ((logdst = clicon_log_opt(optarg[0])) < 0)
+ usage(h, argv[0]);
+ if (logdst == CLICON_LOG_FILE &&
+ strlen(optarg)>1 &&
+ clicon_log_file(optarg+1) < 0)
+ goto done;
+ break;
+ } /* switch getopt */
/*
* Logs, error and debug to stderr or syslog, set debug level
@@ -361,70 +361,70 @@ main(int argc,
clicon_debug_init(dbg, NULL);
clicon_log(LOG_NOTICE, "%s fcgi: %u Started", __PROGRAM__, getpid());
if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){
- clicon_err(OE_DAEMON, errno, "Setting signal");
- goto done;
+ clicon_err(OE_DAEMON, errno, "Setting signal");
+ goto done;
}
if (set_signal(SIGINT, restconf_sig_term, NULL) < 0){
- clicon_err(OE_DAEMON, errno, "Setting signal");
- goto done;
+ clicon_err(OE_DAEMON, errno, "Setting signal");
+ goto done;
}
if (set_signal(SIGCHLD, restconf_sig_child, NULL) < 0){
- clicon_err(OE_DAEMON, errno, "Setting signal");
- goto done;
+ clicon_err(OE_DAEMON, errno, "Setting signal");
+ goto done;
}
yang_init(h);
/* Find and read configfile */
if (clicon_options_main(h) < 0)
- goto done;
+ goto done;
/* Now rest of options, some overwrite option file */
optind = 1;
opterr = 0;
while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1)
- switch (c) {
- case 'h' : /* help */
- case 'D' : /* debug */
- case 'f': /* config file */
- case 'E': /* extra config dir */
- case 'l': /* log */
- break; /* taken care of in earlier getopt above */
- case 'p' : /* yang dir path */
- if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
- goto done;
- break;
- case 'y' : /* Load yang spec file (override yang main module) */
- clicon_option_str_set(h, "CLICON_YANG_MAIN_FILE", optarg);
- break;
- case 'a': /* internal backend socket address family */
- clicon_option_str_set(h, "CLICON_SOCK_FAMILY", optarg);
- break;
- case 'u': /* internal backend socket unix domain path or ip host */
- if (!strlen(optarg))
- usage(h, argv[0]);
- clicon_option_str_set(h, "CLICON_SOCK", optarg);
- break;
- case 'r':{ /* Do not drop privileges if run as root */
- if (clicon_option_add(h, "CLICON_RESTCONF_PRIVILEGES", "none") < 0)
- goto done;
- break;
- }
- case 'R': /* Restconf on-line config */
- inline_config = optarg;
- break;
- case 'o':{ /* Configuration option */
- char *val;
- if ((val = index(optarg, '=')) == NULL)
- usage(h, argv0);
- *val++ = '\0';
- if (clicon_option_add(h, optarg, val) < 0)
- goto done;
- break;
- }
+ switch (c) {
+ case 'h' : /* help */
+ case 'D' : /* debug */
+ case 'f': /* config file */
+ case 'E': /* extra config dir */
+ case 'l': /* log */
+ break; /* taken care of in earlier getopt above */
+ case 'p' : /* yang dir path */
+ if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
+ goto done;
+ break;
+ case 'y' : /* Load yang spec file (override yang main module) */
+ clicon_option_str_set(h, "CLICON_YANG_MAIN_FILE", optarg);
+ break;
+ case 'a': /* internal backend socket address family */
+ clicon_option_str_set(h, "CLICON_SOCK_FAMILY", optarg);
+ break;
+ case 'u': /* internal backend socket unix domain path or ip host */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ clicon_option_str_set(h, "CLICON_SOCK", optarg);
+ break;
+ case 'r':{ /* Do not drop privileges if run as root */
+ if (clicon_option_add(h, "CLICON_RESTCONF_PRIVILEGES", "none") < 0)
+ goto done;
+ break;
+ }
+ case 'R': /* Restconf on-line config */
+ inline_config = optarg;
+ break;
+ case 'o':{ /* Configuration option */
+ char *val;
+ if ((val = index(optarg, '=')) == NULL)
+ usage(h, argv0);
+ *val++ = '\0';
+ if (clicon_option_add(h, optarg, val) < 0)
+ goto done;
+ break;
+ }
default:
usage(h, argv[0]);
break;
- }
+ }
argc -= optind;
argv += optind;
@@ -440,7 +440,7 @@ main(int argc,
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
- clicon_log_string_limit_set(sz);
+ clicon_log_string_limit_set(sz);
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
xml_nsctx_namespace_netconf_default(h);
@@ -449,58 +449,58 @@ main(int argc,
* Otherwise it is loaded in netconf_module_load below
*/
if (netconf_module_features(h) < 0)
- goto done;
+ goto done;
/* Create top-level yang spec and store as option */
if ((yspec = yspec_new()) == NULL)
- goto done;
+ goto done;
clicon_dbspec_yang_set(h, yspec);
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
- goto done;
+ goto done;
/* In case ietf-yang-metadata is loaded by application, handle annotation extension */
if (yang_metadata_init(h) < 0)
- goto done;
+ goto done;
/* Load restconf plugins before yangs are loaded (eg extension callbacks) */
if ((dir = clicon_restconf_dir(h)) != NULL)
- if (clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
- return -1;
+ if (clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
+ return -1;
/* Create a pseudo-plugin to create extension callback to set the ietf-routing
* yang-data extension for api-root top-level restconf function.
*/
if (clixon_pseudo_plugin(h, "pseudo restconf", &cp) < 0)
- goto done;
+ goto done;
clixon_plugin_api_get(cp)->ca_extension = restconf_main_extension_cb;
/* Load Yang modules
* 1. Load a yang module as a specific absolute filename */
if ((str = clicon_yang_main_file(h)) != NULL){
- if (yang_spec_parse_file(h, str, yspec) < 0)
- goto done;
+ if (yang_spec_parse_file(h, str, yspec) < 0)
+ goto done;
}
/* 2. Load a (single) main module */
if ((str = clicon_yang_module_main(h)) != NULL){
- if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
- yspec) < 0)
- goto done;
+ if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
+ yspec) < 0)
+ goto done;
}
/* 3. Load all modules in a directory */
if ((str = clicon_yang_main_dir(h)) != NULL){
- if (yang_spec_load_dir(h, str, yspec) < 0)
- goto done;
+ if (yang_spec_load_dir(h, str, yspec) < 0)
+ goto done;
}
/* Load clixon lib yang module */
if (yang_spec_parse_module(h, "clixon-lib", NULL, yspec) < 0)
- goto done;
+ goto done;
/* Load yang module library, RFC7895 */
if (yang_modules_init(h) < 0)
- goto done;
+ goto done;
/* Load yang restconf module */
if (yang_spec_parse_module(h, "ietf-restconf", NULL, yspec)< 0)
- goto done;
+ goto done;
#ifdef CLIXON_YANG_PATCH
/* Load yang restconf patch module */
@@ -510,47 +510,47 @@ main(int argc,
/* Add netconf yang spec, used as internal protocol */
if (netconf_module_load(h) < 0)
- goto done;
+ goto done;
/* Add system modules */
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040") &&
- yang_spec_parse_module(h, "ietf-restconf-monitoring", NULL, yspec)< 0)
- goto done;
+ yang_spec_parse_module(h, "ietf-restconf-monitoring", NULL, yspec)< 0)
+ goto done;
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC5277") &&
- yang_spec_parse_module(h, "clixon-rfc5277", NULL, yspec)< 0)
- goto done;
+ yang_spec_parse_module(h, "clixon-rfc5277", NULL, yspec)< 0)
+ goto done;
/* Here all modules are loaded
* Compute and set canonical namespace context
*/
if (xml_nsctx_yangspec(yspec, &nsctx_global) < 0)
- goto done;
+ goto done;
if (clicon_nsctx_global_set(h, nsctx_global) < 0)
- goto done;
+ goto done;
/* Dump configuration options on debug */
if (dbg)
- clicon_option_dump(h, dbg);
+ clicon_option_dump(h, dbg);
/* Call start function in all plugins before we go interactive */
if (clixon_plugin_start_all(h) < 0)
- goto done;
+ goto done;
/* Try to get config: inline, config-file or query backend */
if (restconf_main_config(h, yspec, inline_config) < 0)
- goto done;
+ goto done;
if ((sockpath = restconf_fcgi_socket_get(h)) == NULL){
- clicon_err(OE_CFG, 0, "No restconf fcgi-socket (have you set FEATURE fcgi in config?)");
- goto done;
+ clicon_err(OE_CFG, 0, "No restconf fcgi-socket (have you set FEATURE fcgi in config?)");
+ goto done;
}
if (FCGX_Init() != 0){ /* How to cleanup memory after this? */
- clicon_err(OE_CFG, errno, "FCGX_Init");
- goto done;
+ clicon_err(OE_CFG, errno, "FCGX_Init");
+ goto done;
}
clicon_debug(1, "restconf_main: Opening FCGX socket: %s", sockpath);
if ((sock = FCGX_OpenSocket(sockpath, 10)) < 0){
- clicon_err(OE_CFG, errno, "FCGX_OpenSocket");
- goto done;
+ clicon_err(OE_CFG, errno, "FCGX_OpenSocket");
+ goto done;
}
_MYSOCK = sock;
/* Change group of fcgi sock fronting reverse proxy to CLICON_RESTCONF_USER,
@@ -558,106 +558,106 @@ main(int argc,
gid_t wgid = -1;
wwwuser = clicon_option_str(h, "CLICON_RESTCONF_USER");
if (group_name2gid(wwwuser, &wgid) < 0){
- clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group.", wwwuser);
- goto done;
+ clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group.", wwwuser);
+ goto done;
}
if (chown(sockpath, -1, wgid) < 0){
- clicon_err(OE_CFG, errno, "chown");
- goto done;
+ clicon_err(OE_CFG, errno, "chown");
+ goto done;
}
if (clicon_socket_set(h, sock) < 0)
- goto done;
+ goto done;
/* umask settings may interfer: we want group to write: this is 774 */
if (chmod(sockpath, S_IRWXU|S_IRWXG|S_IROTH) < 0){
- clicon_err(OE_UNIX, errno, "chmod");
- goto done;
+ clicon_err(OE_UNIX, errno, "chmod");
+ goto done;
}
/* Drop privileges if started as root to CLICON_RESTCONF_USER
* and use drop mode: CLICON_RESTCONF_PRIVILEGES
*/
if (restconf_drop_privileges(h) < 0)
- goto done;
+ goto done;
if (FCGX_InitRequest(req, sock, 0) != 0){
- clicon_err(OE_CFG, errno, "FCGX_InitRequest");
- goto done;
+ clicon_err(OE_CFG, errno, "FCGX_InitRequest");
+ goto done;
}
while (1) {
- finish = 1; /* If zero, dont finish request, initiate new */
+ finish = 1; /* If zero, dont finish request, initiate new */
- if (FCGX_Accept_r(req) < 0) {
- clicon_err(OE_CFG, errno, "FCGX_Accept_r");
- goto done;
- }
- clicon_debug(1, "------------");
+ if (FCGX_Accept_r(req) < 0) {
+ clicon_err(OE_CFG, errno, "FCGX_Accept_r");
+ goto done;
+ }
+ clicon_debug(1, "------------");
- /* Translate from FCGI parameter form to Clixon runtime data
- * XXX: potential name collision?
- */
- if (fcgi_params_set(h, req->envp) < 0)
- goto done;
- if ((path = restconf_param_get(h, "REQUEST_URI")) == NULL){
- clicon_debug(1, "NULL URI");
- }
- else {
- /* Matching algorithm:
- * 1. try well-known
- * 2. try /restconf
- * 3. try /stream
- * 4. return error
- */
- query = NULL;
- qvec = NULL;
- if (strcmp(path, RESTCONF_WELL_KNOWN) == 0){
- if (api_well_known(h, req) < 0)
- goto done;
- }
- else if (api_path_is_restconf(h)){
- query = restconf_param_get(h, "QUERY_STRING");
- if (query != NULL && strlen(query))
- if (uri_str2cvec(query, '&', '=', 1, &qvec) < 0)
- goto done;
- if (api_root_restconf(h, req, qvec) < 0)
- goto done;
- }
- else if (api_path_is_stream(h)){
- query = restconf_param_get(h, "QUERY_STRING");
- if (query != NULL && strlen(query))
- if (uri_str2cvec(query, '&', '=', 1, &qvec) < 0)
- goto done;
- /* XXX doing goto done on error causes test errors */
- (void)api_stream(h, req, qvec, &finish);
- }
- else{
- clicon_debug(1, "top-level %s not found", path);
- if (netconf_invalid_value_xml(&xerr, "protocol", "Top-level path not found") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, 1, YANG_DATA_JSON, 0) < 0)
- goto done;
- if (xerr){
- xml_free(xerr);
- xerr = NULL;
- }
- }
- if (qvec){
- cvec_free(qvec);
- qvec = NULL;
- }
- }
- if (restconf_param_del_all(h) < 0)
- goto done;
- if (finish)
- FCGX_Finish_r(req);
- else if (clixon_exit_get()){
- FCGX_Finish_r(req);
- break;
- }
- else{ /* A handler is forked so we initiate a new request after instead
- of finishing the old */
- if (FCGX_InitRequest(req, sock, 0) != 0){
- clicon_err(OE_CFG, errno, "FCGX_InitRequest");
- goto done;
- }
- }
+ /* Translate from FCGI parameter form to Clixon runtime data
+ * XXX: potential name collision?
+ */
+ if (fcgi_params_set(h, req->envp) < 0)
+ goto done;
+ if ((path = restconf_param_get(h, "REQUEST_URI")) == NULL){
+ clicon_debug(1, "NULL URI");
+ }
+ else {
+ /* Matching algorithm:
+ * 1. try well-known
+ * 2. try /restconf
+ * 3. try /stream
+ * 4. return error
+ */
+ query = NULL;
+ qvec = NULL;
+ if (strcmp(path, RESTCONF_WELL_KNOWN) == 0){
+ if (api_well_known(h, req) < 0)
+ goto done;
+ }
+ else if (api_path_is_restconf(h)){
+ query = restconf_param_get(h, "QUERY_STRING");
+ if (query != NULL && strlen(query))
+ if (uri_str2cvec(query, '&', '=', 1, &qvec) < 0)
+ goto done;
+ if (api_root_restconf(h, req, qvec) < 0)
+ goto done;
+ }
+ else if (api_path_is_stream(h)){
+ query = restconf_param_get(h, "QUERY_STRING");
+ if (query != NULL && strlen(query))
+ if (uri_str2cvec(query, '&', '=', 1, &qvec) < 0)
+ goto done;
+ /* XXX doing goto done on error causes test errors */
+ (void)api_stream(h, req, qvec, &finish);
+ }
+ else{
+ clicon_debug(1, "top-level %s not found", path);
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Top-level path not found") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, 1, YANG_DATA_JSON, 0) < 0)
+ goto done;
+ if (xerr){
+ xml_free(xerr);
+ xerr = NULL;
+ }
+ }
+ if (qvec){
+ cvec_free(qvec);
+ qvec = NULL;
+ }
+ }
+ if (restconf_param_del_all(h) < 0)
+ goto done;
+ if (finish)
+ FCGX_Finish_r(req);
+ else if (clixon_exit_get()){
+ FCGX_Finish_r(req);
+ break;
+ }
+ else{ /* A handler is forked so we initiate a new request after instead
+ of finishing the old */
+ if (FCGX_InitRequest(req, sock, 0) != 0){
+ clicon_err(OE_CFG, errno, "FCGX_InitRequest");
+ goto done;
+ }
+ }
} /* while */
retval = 0;
done:
diff --git a/apps/restconf/restconf_main_native.c b/apps/restconf/restconf_main_native.c
index ef7602f9..f607a156 100644
--- a/apps/restconf/restconf_main_native.c
+++ b/apps/restconf/restconf_main_native.c
@@ -185,7 +185,7 @@ static int session_id_context = 1;
*/
static int
restconf_native_handle_set(clicon_handle h,
- restconf_native_handle *rh)
+ restconf_native_handle *rh)
{
clicon_hash_t *cdat = clicon_data(h);
@@ -193,7 +193,7 @@ restconf_native_handle_set(clicon_handle h,
so we send a ptr to the ptr to indicate what to copy.
*/
if (clicon_hash_add(cdat, "restconf-native-handle", &rh, sizeof(rh)) == NULL)
- return -1;
+ return -1;
return 0;
}
@@ -212,8 +212,8 @@ print_cb(const char *str, size_t len, void *cb)
*/
static int
clixon_openssl_log_cb(void *handle,
- int suberr,
- cbuf *cb)
+ int suberr,
+ cbuf *cb)
{
clicon_debug(1, "%s", __FUNCTION__);
ERR_print_errors_cb(print_cb, cb);
@@ -233,8 +233,8 @@ init_openssl(void)
/* This isn't strictly necessary... OpenSSL performs RAND_poll
* automatically on first use of random number generator. */
if (RAND_poll() != 1) {
- clicon_err(OE_SSL, errno, "Random generator has not been seeded with enough data");
- goto done;
+ clicon_err(OE_SSL, errno, "Random generator has not been seeded with enough data");
+ goto done;
}
retval = 0;
done:
@@ -250,7 +250,7 @@ init_openssl(void)
*/
static int
restconf_verify_certs(int preverify_ok,
- X509_STORE_CTX *store)
+ X509_STORE_CTX *store)
{
char buf[256];
X509 *err_cert;
@@ -268,14 +268,14 @@ restconf_verify_certs(int preverify_ok,
X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256);
switch (err){
case X509_V_ERR_HOSTNAME_MISMATCH:
- clicon_debug(1, "%s X509_V_ERR_HOSTNAME_MISMATCH", __FUNCTION__);
- break;
+ clicon_debug(1, "%s X509_V_ERR_HOSTNAME_MISMATCH", __FUNCTION__);
+ break;
case X509_V_ERR_CERT_HAS_EXPIRED:
- clicon_debug(1, "%s X509_V_ERR_CERT_HAS_EXPIRED", __FUNCTION__);
- break;
+ clicon_debug(1, "%s X509_V_ERR_CERT_HAS_EXPIRED", __FUNCTION__);
+ break;
case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
- clicon_debug(1, "%s X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT", __FUNCTION__);
- break;
+ clicon_debug(1, "%s X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT", __FUNCTION__);
+ break;
}
/* Catch a too long certificate chain. should be +1 in SSL_CTX_set_verify_depth() */
if (depth > VERIFY_DEPTH + 1) {
@@ -284,7 +284,7 @@ restconf_verify_certs(int preverify_ok,
X509_STORE_CTX_set_error(store, err);
}
else{
- /* Verify the CA name */
+ /* Verify the CA name */
}
// h = SSL_get_app_data(ssl);
/* Different schemes for return values if failure detected:
@@ -300,16 +300,16 @@ restconf_verify_certs(int preverify_ok,
*/
static int
alpn_proto_dump(const char *label,
- const char *inp,
- int len)
+ const char *inp,
+ int len)
{
int retval = -1;
char *str = NULL;
if ((str = malloc(len+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
strncpy(str, inp, len);
str[len] = '\0';
@@ -327,11 +327,11 @@ alpn_proto_dump(const char *label,
*/
static int
alpn_select_proto_cb(SSL *ssl,
- const unsigned char **out,
- unsigned char *outlen,
- const unsigned char *in,
- unsigned int inlen,
- void *arg)
+ const unsigned char **out,
+ unsigned char *outlen,
+ const unsigned char *in,
+ unsigned int inlen,
+ void *arg)
{
unsigned char *inp;
unsigned char len;
@@ -341,29 +341,29 @@ alpn_select_proto_cb(SSL *ssl,
/* select http/1.1 */
inp = (unsigned char*)in;
while ((inp-in) < inlen) {
- len = *inp;
- inp++;
- if (clicon_debug_get()) /* debug print the protoocol */
- alpn_proto_dump(__FUNCTION__, (const char*)inp, len);
+ len = *inp;
+ inp++;
+ if (clicon_debug_get()) /* debug print the protoocol */
+ alpn_proto_dump(__FUNCTION__, (const char*)inp, len);
#ifdef HAVE_HTTP1
- if (pref < 10 && len == 8 && strncmp((char*)inp, "http/1.1", len) == 0){
- *outlen = len;
- *out = inp;
- pref = 10;
- }
+ if (pref < 10 && len == 8 && strncmp((char*)inp, "http/1.1", len) == 0){
+ *outlen = len;
+ *out = inp;
+ pref = 10;
+ }
#endif
#ifdef HAVE_LIBNGHTTP2
- /* Higher pref than http/1.1 */
- if (pref < 20 && len == 2 && strncmp((char*)inp, "h2", len) == 0){
- *outlen = len;
- *out = inp;
- pref = 20;
- }
+ /* Higher pref than http/1.1 */
+ if (pref < 20 && len == 2 && strncmp((char*)inp, "h2", len) == 0){
+ *outlen = len;
+ *out = inp;
+ pref = 20;
+ }
#endif
- inp += len;
+ inp += len;
}
if (pref == 0)
- return SSL_TLSEXT_ERR_NOACK;
+ return SSL_TLSEXT_ERR_NOACK;
alpn_proto_dump("ALPN selected:", (const char*)*out, *outlen);
return SSL_TLSEXT_ERR_OK;
}
@@ -379,8 +379,8 @@ restconf_ssl_context_create(clicon_handle h)
method = TLS_server_method();
if ((ctx = SSL_CTX_new(method)) == NULL) {
- clicon_err(OE_SSL, 0, "SSL_CTX_new");
- goto done;
+ clicon_err(OE_SSL, 0, "SSL_CTX_new");
+ goto done;
}
/* Options
* As of OpenSSL 1.0.2g the SSL_OP_NO_SSLv2 option is set by default. *
@@ -407,10 +407,10 @@ restconf_ssl_context_create(clicon_handle h)
*/
static int
restconf_ssl_context_configure(clixon_handle h,
- SSL_CTX *ctx,
- const char *server_cert_path,
- const char *server_key_path,
- const char *server_ca_cert_path)
+ SSL_CTX *ctx,
+ const char *server_cert_path,
+ const char *server_key_path,
+ const char *server_ca_cert_path)
{
int retval = -1;
@@ -423,13 +423,13 @@ restconf_ssl_context_configure(clixon_handle h,
* find out the reason.
*/
if (server_ca_cert_path){
- if (SSL_CTX_load_verify_locations(ctx, server_ca_cert_path, NULL) != 1){
- clicon_err(OE_SSL, 0, "SSL_CTX_load_verify_locations(%s)", server_ca_cert_path);
- goto done;
- }
- SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER /*| SSL_VERIFY_FAIL_IF_NO_PEER_CERT */,
- restconf_verify_certs);
- SSL_CTX_set_verify_depth(ctx, VERIFY_DEPTH+1);
+ if (SSL_CTX_load_verify_locations(ctx, server_ca_cert_path, NULL) != 1){
+ clicon_err(OE_SSL, 0, "SSL_CTX_load_verify_locations(%s)", server_ca_cert_path);
+ goto done;
+ }
+ SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER /*| SSL_VERIFY_FAIL_IF_NO_PEER_CERT */,
+ restconf_verify_certs);
+ SSL_CTX_set_verify_depth(ctx, VERIFY_DEPTH+1);
}
@@ -442,14 +442,14 @@ restconf_ssl_context_configure(clixon_handle h,
/* Set the key and cert */
if (SSL_CTX_use_certificate_chain_file(ctx, server_cert_path) != 1) {
ERR_print_errors_fp(stderr);
- goto done;
+ goto done;
}
if (SSL_CTX_use_PrivateKey_file(ctx,
- server_key_path,
- SSL_FILETYPE_PEM) <= 0 ) {
+ server_key_path,
+ SSL_FILETYPE_PEM) <= 0 ) {
ERR_print_errors_fp(stderr);
- goto done;
+ goto done;
}
retval = 0;
@@ -469,17 +469,17 @@ restconf_listcerts(SSL *ssl)
clicon_debug(1, "%s get peer certificates:", __FUNCTION__);
if ((cert = SSL_get_peer_certificate(ssl)) != NULL) { /* Get certificates (if available) */
if ((line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0)) != NULL){
- clicon_debug(1, "Subject: %s", line);
- free(line);
- }
- if ((line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0)) != NULL){
- clicon_debug(1, "Issuer: %s", line);
- free(line);
- }
+ clicon_debug(1, "Subject: %s", line);
+ free(line);
+ }
+ if ((line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0)) != NULL){
+ clicon_debug(1, "Issuer: %s", line);
+ free(line);
+ }
if ((line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0)) != NULL){
- clicon_debug(1, "Subject: %s", line);
- free(line);
- }
+ clicon_debug(1, "Subject: %s", line);
+ free(line);
+ }
X509_free(cert);
}
return 0;
@@ -496,8 +496,8 @@ restconf_listcerts(SSL *ssl)
*/
static int
restconf_checkcert_file(cxobj *xrestconf,
- const char *name,
- char **var)
+ const char *name,
+ char **var)
{
int retval = -1;
cxobj *x;
@@ -506,16 +506,16 @@ restconf_checkcert_file(cxobj *xrestconf,
char *filename;
if ((x = xpath_first(xrestconf, nsc, "%s", name)) == NULL){
- clicon_err(OE_FATAL, EFAULT, "cert '%s' not found in config", name);
- goto done;
+ clicon_err(OE_FATAL, EFAULT, "cert '%s' not found in config", name);
+ goto done;
}
if ((filename = xml_body(x)) == NULL){
- clicon_err(OE_FATAL, EFAULT, "cert '%s' NULL value in config", name);
- goto done;
+ clicon_err(OE_FATAL, EFAULT, "cert '%s' NULL value in config", name);
+ goto done;
}
if (stat(filename, &fstat) < 0) {
- clicon_err(OE_FATAL, errno, "cert '%s'", filename);
- goto done;
+ clicon_err(OE_FATAL, errno, "cert '%s'", filename);
+ goto done;
}
*var = filename;
retval = 0;
@@ -530,7 +530,7 @@ restconf_checkcert_file(cxobj *xrestconf,
*/
static int
restconf_accept_client(int fd,
- void *arg)
+ void *arg)
{
int retval = -1;
@@ -543,27 +543,27 @@ restconf_accept_client(int fd,
clicon_debug(1, "%s %d", __FUNCTION__, fd);
if ((rsock = (restconf_socket *)arg) == NULL){
- clicon_err(OE_YANG, EINVAL, "rsock is NULL");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "rsock is NULL");
+ goto done;
}
clicon_debug(1, "%s type:%s addr:%s port:%hu", __FUNCTION__,
- rsock->rs_addrtype,
- rsock->rs_addrstr,
- rsock->rs_port);
+ rsock->rs_addrtype,
+ rsock->rs_addrstr,
+ rsock->rs_port);
h = rsock->rs_h;
len = sizeof(from);
if ((s = accept(rsock->rs_ss, &from, &len)) < 0){
- clicon_err(OE_UNIX, errno, "accept");
- goto done;
+ clicon_err(OE_UNIX, errno, "accept");
+ goto done;
}
/* Accept SSL */
if (restconf_ssl_accept_client(h, s, rsock, NULL) < 0)
- goto done;
+ goto done;
retval = 0;
done:
clicon_debug(1, "%s retval %d", __FUNCTION__, retval);
if (name)
- free(name);
+ free(name);
return retval;
} /* restconf_accept_client */
@@ -578,34 +578,34 @@ restconf_native_terminate(clicon_handle h)
clicon_debug(1, "%s", __FUNCTION__);
if ((rn = restconf_native_handle_get(h)) != NULL){
- while ((rsock = rn->rn_sockets) != NULL){
- while ((rc = rsock->rs_conns) != NULL){
- if (rc->rc_s != -1){
- clixon_event_unreg_fd(rc->rc_s, restconf_connection);
- close(rc->rc_s);
- }
- DELQ(rc, rsock->rs_conns, restconf_conn *);
- restconf_close_ssl_socket(rc, __FUNCTION__, 0);
- }
- if (rsock->rs_callhome){
- restconf_callhome_timer_unreg(rsock);
- }
- else if (rsock->rs_ss != -1){
- clixon_event_unreg_fd(rsock->rs_ss, restconf_accept_client);
- close(rsock->rs_ss);
- }
- DELQ(rsock, rn->rn_sockets, restconf_socket *);
- if (rsock->rs_description)
- free(rsock->rs_description);
- if (rsock->rs_addrstr)
- free(rsock->rs_addrstr);
- if (rsock->rs_addrtype)
- free(rsock->rs_addrtype);
- free(rsock);
- }
- if (rn->rn_ctx)
- SSL_CTX_free(rn->rn_ctx);
- free(rn);
+ while ((rsock = rn->rn_sockets) != NULL){
+ while ((rc = rsock->rs_conns) != NULL){
+ if (rc->rc_s != -1){
+ clixon_event_unreg_fd(rc->rc_s, restconf_connection);
+ close(rc->rc_s);
+ }
+ DELQ(rc, rsock->rs_conns, restconf_conn *);
+ restconf_close_ssl_socket(rc, __FUNCTION__, 0);
+ }
+ if (rsock->rs_callhome){
+ restconf_callhome_timer_unreg(rsock);
+ }
+ else if (rsock->rs_ss != -1){
+ clixon_event_unreg_fd(rsock->rs_ss, restconf_accept_client);
+ close(rsock->rs_ss);
+ }
+ DELQ(rsock, rn->rn_sockets, restconf_socket *);
+ if (rsock->rs_description)
+ free(rsock->rs_description);
+ if (rsock->rs_addrstr)
+ free(rsock->rs_addrstr);
+ if (rsock->rs_addrtype)
+ free(rsock->rs_addrtype);
+ free(rsock);
+ }
+ if (rn->rn_ctx)
+ SSL_CTX_free(rn->rn_ctx);
+ free(rn);
}
EVP_cleanup();
return 0;
@@ -621,7 +621,7 @@ restconf_native_terminate(clicon_handle h)
*/
static int
restconf_clixon_backend(clicon_handle h,
- cxobj **xrestconfp)
+ cxobj **xrestconfp)
{
int retval = -1;
uint32_t id = 0; /* Session id, to poll backend up */
@@ -634,47 +634,47 @@ restconf_clixon_backend(clicon_handle h,
/* Loop to wait for backend starting, try again if not done */
while (1){
- if (clicon_hello_req(h, &id) < 0){
- if (errno == ENOENT){
- fprintf(stderr, "waiting");
- sleep(1);
- continue;
- }
- clicon_err(OE_UNIX, errno, "clicon_session_id_get");
- goto done;
- }
- clicon_session_id_set(h, id);
- break;
+ if (clicon_hello_req(h, &id) < 0){
+ if (errno == ENOENT){
+ fprintf(stderr, "waiting");
+ sleep(1);
+ continue;
+ }
+ clicon_err(OE_UNIX, errno, "clicon_session_id_get");
+ goto done;
+ }
+ clicon_session_id_set(h, id);
+ break;
}
if ((nsc = xml_nsctx_init(NULL, CLIXON_RESTCONF_NS)) == NULL)
- goto done;
+ goto done;
if ((pw = getpwuid(getuid())) == NULL){
- clicon_err(OE_UNIX, errno, "getpwuid");
- goto done;
+ clicon_err(OE_UNIX, errno, "getpwuid");
+ goto done;
}
/* XXX xconfig leaked */
if (clicon_rpc_get_config(h, pw->pw_name, "running", "/restconf", nsc, NULL, &xconfig) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xconfig, NULL, "/rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Get backend restconf config", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Get backend restconf config", NULL);
+ goto done;
}
/* Extract restconf configuration */
if ((xrestconf = xpath_first(xconfig, nsc, "restconf")) == NULL)
- goto fail;
+ goto fail;
if ((ret = restconf_config_init(h, xrestconf)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
if (xml_rm(xrestconf) < 0)
- goto done;
+ goto done;
*xrestconfp = xrestconf;
retval = 1;
done:
if (nsc)
- cvec_free(nsc);
+ cvec_free(nsc);
if (xconfig)
- xml_free(xconfig);
+ xml_free(xconfig);
return retval;
fail:
retval = 0;
@@ -690,8 +690,8 @@ restconf_clixon_backend(clicon_handle h,
*/
static int
openssl_init_socket(clicon_handle h,
- cxobj *xs,
- cvec *nsc)
+ cxobj *xs,
+ cvec *nsc)
{
int retval = -1;
char *netns = NULL;
@@ -709,8 +709,8 @@ openssl_init_socket(clicon_handle h,
* See restconf_native_terminate for freeing
*/
if ((rsock = malloc(sizeof *rsock)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(rsock, 0, sizeof *rsock);
rsock->rs_h = h;
@@ -718,52 +718,52 @@ openssl_init_socket(clicon_handle h,
rsock->rs_start = now.tv_sec;
/* Extract socket parameters from single socket config: ns, addr, port, ssl */
if (restconf_socket_extract(h, xs, nsc, rsock, &netns, &address, &addrtype, &port) < 0)
- goto done;
+ goto done;
if (rsock->rs_callhome){
- if (!rsock->rs_ssl){
- clicon_err(OE_SSL, EINVAL, "Restconf callhome requires SSL");
- goto done;
- }
+ if (!rsock->rs_ssl){
+ clicon_err(OE_SSL, EINVAL, "Restconf callhome requires SSL");
+ goto done;
+ }
}
else { /* listen/accept */
- /* Open restconf socket and bind for later accept */
- if (restconf_socket_init(netns, address, addrtype, port,
- SOCKET_LISTEN_BACKLOG,
+ /* Open restconf socket and bind for later accept */
+ if (restconf_socket_init(netns, address, addrtype, port,
+ SOCKET_LISTEN_BACKLOG,
#ifdef RESTCONF_OPENSSL_NONBLOCKING
- SOCK_NONBLOCK, /* Also 0 is possible */
+ SOCK_NONBLOCK, /* Also 0 is possible */
#else /* blocking */
- 0,
+ 0,
#endif
- &ss
- ) < 0)
- goto done;
+ &ss
+ ) < 0)
+ goto done;
}
if ((rn = restconf_native_handle_get(h)) == NULL){
- clicon_err(OE_XML, EFAULT, "No openssl handle");
- goto done;
+ clicon_err(OE_XML, EFAULT, "No openssl handle");
+ goto done;
}
if ((rsock->rs_addrstr = strdup(address)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
if ((rsock->rs_addrtype = strdup(addrtype)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
rsock->rs_port = port;
INSQ(rsock, rn->rn_sockets);
if (rsock->rs_callhome){
- rsock->rs_ss = -1; /* Not applicable from callhome */
- if (restconf_callhome_timer(rsock, 0) < 0)
- goto done;
+ rsock->rs_ss = -1; /* Not applicable from callhome */
+ if (restconf_callhome_timer(rsock, 0) < 0)
+ goto done;
}
else {
- /* ss is a server socket that the clients connect to. The callback
- therefore accepts clients on ss */
- rsock->rs_ss = ss;
- if (clixon_event_reg_fd(rsock->rs_ss, restconf_accept_client, rsock, "restconf socket") < 0)
- goto done;
+ /* ss is a server socket that the clients connect to. The callback
+ therefore accepts clients on ss */
+ rsock->rs_ss = ss;
+ if (clixon_event_reg_fd(rsock->rs_ss, restconf_accept_client, rsock, "restconf socket") < 0)
+ goto done;
}
retval = 0;
done:
@@ -781,8 +781,8 @@ openssl_init_socket(clicon_handle h,
*/
int
restconf_openssl_init(clicon_handle h,
- int dbg0,
- cxobj *xrestconf)
+ int dbg0,
+ cxobj *xrestconf)
{
int retval = -1;
SSL_CTX *ctx; /* SSL context */
@@ -807,68 +807,68 @@ restconf_openssl_init(clicon_handle h,
auth_type = restconf_auth_type_get(h);
/* Only set debug from config if not set manually */
if (dbg0 == 0 &&
- (x = xpath_first(xrestconf, nsc, "debug")) != NULL &&
- (bstr = xml_body(x)) != NULL){
- dbg = atoi(bstr);
- clicon_debug_init(dbg, NULL);
- /* If debug was enabled here from config and not initially,
- * print clixn options and loaded yang files
- */
- if (dbg) {
- clicon_option_dump(h, dbg);
- yang_spec_dump(clicon_dbspec_yang(h), dbg);
- }
+ (x = xpath_first(xrestconf, nsc, "debug")) != NULL &&
+ (bstr = xml_body(x)) != NULL){
+ dbg = atoi(bstr);
+ clicon_debug_init(dbg, NULL);
+ /* If debug was enabled here from config and not initially,
+ * print clixn options and loaded yang files
+ */
+ if (dbg) {
+ clicon_option_dump(h, dbg);
+ yang_spec_dump(clicon_dbspec_yang(h), dbg);
+ }
}
if ((x = xpath_first(xrestconf, nsc, "enable-core-dump")) != NULL) {
- /* core dump is enabled on RESTCONF process */
- struct rlimit rlp;
- if (strcmp(xml_body(x), "true") == 0) {
- rlp.rlim_cur = RLIM_INFINITY;
- rlp.rlim_max = RLIM_INFINITY;
- } else {
- rlp.rlim_cur = 0;
- rlp.rlim_max = 0;
- }
- int status = setrlimit(RLIMIT_CORE, &rlp);
- if (status != 0) {
- clicon_log(LOG_INFO, "%s: setrlimit() failed, %s", __FUNCTION__, strerror(errno));
- }
+ /* core dump is enabled on RESTCONF process */
+ struct rlimit rlp;
+ if (strcmp(xml_body(x), "true") == 0) {
+ rlp.rlim_cur = RLIM_INFINITY;
+ rlp.rlim_max = RLIM_INFINITY;
+ } else {
+ rlp.rlim_cur = 0;
+ rlp.rlim_max = 0;
+ }
+ int status = setrlimit(RLIMIT_CORE, &rlp);
+ if (status != 0) {
+ clicon_log(LOG_INFO, "%s: setrlimit() failed, %s", __FUNCTION__, strerror(errno));
+ }
}
if (init_openssl() < 0)
- goto done;
+ goto done;
if ((ctx = restconf_ssl_context_create(h)) == NULL)
- goto done;
+ goto done;
/* Check certs */
if (ssl_enable){
- if (restconf_checkcert_file(xrestconf, "server-cert-path", &server_cert_path) < 0)
- goto done;
- if (restconf_checkcert_file(xrestconf, "server-key-path", &server_key_path) < 0)
- goto done;
- if (auth_type == CLIXON_AUTH_CLIENT_CERTIFICATE)
- if (restconf_checkcert_file(xrestconf, "server-ca-cert-path", &server_ca_cert_path) < 0)
- goto done;
- if (restconf_ssl_context_configure(h, ctx, server_cert_path, server_key_path, server_ca_cert_path) < 0)
- goto done;
+ if (restconf_checkcert_file(xrestconf, "server-cert-path", &server_cert_path) < 0)
+ goto done;
+ if (restconf_checkcert_file(xrestconf, "server-key-path", &server_key_path) < 0)
+ goto done;
+ if (auth_type == CLIXON_AUTH_CLIENT_CERTIFICATE)
+ if (restconf_checkcert_file(xrestconf, "server-ca-cert-path", &server_ca_cert_path) < 0)
+ goto done;
+ if (restconf_ssl_context_configure(h, ctx, server_cert_path, server_key_path, server_ca_cert_path) < 0)
+ goto done;
}
rn = restconf_native_handle_get(h);
rn->rn_ctx = ctx;
/* get the list of socket config-data */
if (xpath_vec(xrestconf, nsc, "socket", &vec, &veclen) < 0)
- goto done;
+ goto done;
for (i=0; ica_extension = restconf_main_extension_cb;
/* Load Yang modules
* 1. Load a yang module as a specific absolute filename */
if ((str = clicon_yang_main_file(h)) != NULL){
- if (yang_spec_parse_file(h, str, yspec) < 0)
- goto done;
+ if (yang_spec_parse_file(h, str, yspec) < 0)
+ goto done;
}
/* 2. Load a (single) main module */
if ((str = clicon_yang_module_main(h)) != NULL){
- if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
- yspec) < 0)
- goto done;
+ if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
+ yspec) < 0)
+ goto done;
}
/* 3. Load all modules in a directory */
if ((str = clicon_yang_main_dir(h)) != NULL){
- if (yang_spec_load_dir(h, str, yspec) < 0)
- goto done;
+ if (yang_spec_load_dir(h, str, yspec) < 0)
+ goto done;
}
/* Load clixon lib yang module */
if (yang_spec_parse_module(h, "clixon-lib", NULL, yspec) < 0)
- goto done;
+ goto done;
/* Load yang module library, RFC7895 */
if (yang_modules_init(h) < 0)
- goto done;
+ goto done;
/* Load yang restconf module */
if (yang_spec_parse_module(h, "ietf-restconf", NULL, yspec)< 0)
- goto done;
+ goto done;
#ifdef CLIXON_YANG_PATCH
/* Load yang restconf patch module */
@@ -975,73 +975,73 @@ restconf_clixon_init(clicon_handle h,
/* Add netconf yang spec, used as internal protocol */
if (netconf_module_load(h) < 0)
- goto done;
+ goto done;
/* Add system modules */
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040") &&
- yang_spec_parse_module(h, "ietf-restconf-monitoring", NULL, yspec)< 0)
- goto done;
+ yang_spec_parse_module(h, "ietf-restconf-monitoring", NULL, yspec)< 0)
+ goto done;
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC5277") &&
- yang_spec_parse_module(h, "clixon-rfc5277", NULL, yspec)< 0)
- goto done;
+ yang_spec_parse_module(h, "clixon-rfc5277", NULL, yspec)< 0)
+ goto done;
/* Here all modules are loaded
* Compute and set canonical namespace context
*/
if (xml_nsctx_yangspec(yspec, &nsctx_global) < 0)
- goto done;
+ goto done;
if (clicon_nsctx_global_set(h, nsctx_global) < 0)
- goto done;
+ goto done;
if (inline_config != NULL && strlen(inline_config)){
- clicon_debug(1, "%s reading from inline config", __FUNCTION__);
- if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0)
- goto done;
- if (ret == 0){
- clixon_netconf_error(xerr, "Inline restconf config", NULL);
- goto done;
- }
- /* Replace parent w first child */
- if (xml_rootchild(xrestconf, 0, &xrestconf) < 0)
- goto done;
- if ((ret = restconf_config_init(h, xrestconf)) < 0)
- goto done;
- /* ret == 1 means this config is OK */
- if (ret == 0){
- xml_free(xrestconf);
- xrestconf = NULL;
- }
- else
- if ((*xrestconfp = xrestconf) == NULL)
- goto done;
+ clicon_debug(1, "%s reading from inline config", __FUNCTION__);
+ if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ clixon_netconf_error(xerr, "Inline restconf config", NULL);
+ goto done;
+ }
+ /* Replace parent w first child */
+ if (xml_rootchild(xrestconf, 0, &xrestconf) < 0)
+ goto done;
+ if ((ret = restconf_config_init(h, xrestconf)) < 0)
+ goto done;
+ /* ret == 1 means this config is OK */
+ if (ret == 0){
+ xml_free(xrestconf);
+ xrestconf = NULL;
+ }
+ else
+ if ((*xrestconfp = xrestconf) == NULL)
+ goto done;
}
else if (clicon_option_bool(h, "CLICON_BACKEND_RESTCONF_PROCESS") == 0){
- clicon_debug(1, "%s reading from clixon config", __FUNCTION__);
- /* If not read from backend, try to get restconf config from local config-file */
- if ((xrestconf = clicon_conf_restconf(h)) != NULL){
- /*! Basic config init, set auth-type, pretty, etc ret 0 means disabled */
- if ((ret = restconf_config_init(h, xrestconf)) < 0)
- goto done;
- /* ret == 1 means this config is OK */
- if (ret == 0){
- xrestconf = NULL; /* Dont free since it is part of conf tree */
- }
- else
- if ((*xrestconfp = xml_dup(xrestconf)) == NULL)
- goto done;
- }
+ clicon_debug(1, "%s reading from clixon config", __FUNCTION__);
+ /* If not read from backend, try to get restconf config from local config-file */
+ if ((xrestconf = clicon_conf_restconf(h)) != NULL){
+ /*! Basic config init, set auth-type, pretty, etc ret 0 means disabled */
+ if ((ret = restconf_config_init(h, xrestconf)) < 0)
+ goto done;
+ /* ret == 1 means this config is OK */
+ if (ret == 0){
+ xrestconf = NULL; /* Dont free since it is part of conf tree */
+ }
+ else
+ if ((*xrestconfp = xml_dup(xrestconf)) == NULL)
+ goto done;
+ }
}
/* If no local config, or it is disabled, try to query backend of config.
*/
else {
- clicon_debug(1, "%s reading from backend datastore config", __FUNCTION__);
- if ((ret = restconf_clixon_backend(h, xrestconfp)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ clicon_debug(1, "%s reading from backend datastore config", __FUNCTION__);
+ if ((ret = restconf_clixon_backend(h, xrestconfp)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
retval = 1;
done:
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
return retval;
fail:
retval = 0;
@@ -1057,9 +1057,9 @@ restconf_sig_term(int arg)
static int i=0;
clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d",
- __PROGRAM__, __FUNCTION__, getpid(), arg);
+ __PROGRAM__, __FUNCTION__, getpid(), arg);
if (i++ > 0) /* Allow one sigterm before proper exit */
- exit(-1);
+ exit(-1);
/* This should ensure no more accepts or incoming packets are processed because next time eventloop
* is entered, it will terminate.
* However there may be a case of sockets closing rather abruptly for clients
@@ -1076,23 +1076,23 @@ usage(clicon_handle h,
char *argv0)
{
fprintf(stderr, "usage:%s [options]\n"
- "where options are\n"
+ "where options are\n"
"\t-h \t\t Help\n"
- "\t-D \t Debug level, overrides any config debug setting\n"
- "\t-f \t Configuration file (mandatory)\n"
- "\t-E \t Extra configuration file directory\n"
- "\t-l > \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (syslog is default)\n"
- "\t-p \t Yang directory path (see CLICON_YANG_DIR)\n"
- "\t-y \t Load yang spec file (override yang main module)\n"
- "\t-a UNIX|IPv4|IPv6 Internal backend socket family\n"
- "\t-u \t Internal socket domain path or IP addr (see -a)\n"
- "\t-r \t\t Do not drop privileges if run as root\n"
- "\t-W \t Run restconf daemon as this user, drop according to CLICON_RESTCONF_PRIVILEGES\n"
- "\t-R \t Restconf configuration in-line overriding config file\n"
- "\t-o = Set configuration option overriding config file (see clixon-config.yang)\n"
- ,
- argv0
- );
+ "\t-D \t Debug level, overrides any config debug setting\n"
+ "\t-f \t Configuration file (mandatory)\n"
+ "\t-E \t Extra configuration file directory\n"
+ "\t-l > \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (syslog is default)\n"
+ "\t-p \t Yang directory path (see CLICON_YANG_DIR)\n"
+ "\t-y \t Load yang spec file (override yang main module)\n"
+ "\t-a UNIX|IPv4|IPv6 Internal backend socket family\n"
+ "\t-u \t Internal socket domain path or IP addr (see -a)\n"
+ "\t-r \t\t Do not drop privileges if run as root\n"
+ "\t-W \t Run restconf daemon as this user, drop according to CLICON_RESTCONF_PRIVILEGES\n"
+ "\t-R \t Restconf configuration in-line overriding config file\n"
+ "\t-o = Set configuration option overriding config file (see clixon-config.yang)\n"
+ ,
+ argv0
+ );
exit(0);
}
@@ -1101,7 +1101,7 @@ main(int argc,
char **argv)
{
int retval = -1;
- char *argv0 = argv[0];
+ char *argv0 = argv[0];
int c;
clicon_handle h;
int dbg = 0;
@@ -1116,36 +1116,36 @@ main(int argc,
/* Create handle */
if ((h = restconf_handle_init()) == NULL)
- goto done;
+ goto done;
while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1)
- switch (c) {
- case 'h':
- usage(h, argv0);
- break;
- case 'D' : /* debug. Note this overrides any setting in the config */
- if (sscanf(optarg, "%d", &dbg) != 1)
- usage(h, argv0);
- break;
- case 'f': /* override config file */
- if (!strlen(optarg))
- usage(h, argv0);
- clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
- break;
- case 'E': /* extra config directory */
- if (!strlen(optarg))
- usage(h, argv[0]);
- clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
- break;
- case 'l': /* Log destination: s|e|o */
- if ((logdst = clicon_log_opt(optarg[0])) < 0)
- usage(h, argv0);
- if (logdst == CLICON_LOG_FILE &&
- strlen(optarg)>1 &&
- clicon_log_file(optarg+1) < 0)
- goto done;
- break;
- } /* switch getopt */
+ switch (c) {
+ case 'h':
+ usage(h, argv0);
+ break;
+ case 'D' : /* debug. Note this overrides any setting in the config */
+ if (sscanf(optarg, "%d", &dbg) != 1)
+ usage(h, argv0);
+ break;
+ case 'f': /* override config file */
+ if (!strlen(optarg))
+ usage(h, argv0);
+ clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
+ break;
+ case 'E': /* extra config directory */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
+ break;
+ case 'l': /* Log destination: s|e|o */
+ if ((logdst = clicon_log_opt(optarg[0])) < 0)
+ usage(h, argv0);
+ if (logdst == CLICON_LOG_FILE &&
+ strlen(optarg)>1 &&
+ clicon_log_file(optarg+1) < 0)
+ goto done;
+ break;
+ } /* switch getopt */
/*
* Logs, error and debug to stderr or syslog, set debug level
@@ -1156,90 +1156,90 @@ main(int argc,
* Register error category and error/log callbacks for openssl special error handling
*/
if (clixon_err_cat_reg(OE_SSL, /* category */
- h, /* handle (can be NULL) */
- clixon_openssl_log_cb /* log fn */
- ) < 0)
- goto done;
+ h, /* handle (can be NULL) */
+ clixon_openssl_log_cb /* log fn */
+ ) < 0)
+ goto done;
#ifdef HAVE_LIBNGHTTP2
/*
* Register error category and error/log callbacks for openssl special error handling
*/
if (clixon_err_cat_reg(OE_NGHTTP2, /* category */
- h, /* handle (can be NULL) */
- clixon_nghttp2_log_cb /* log fn */
- ) < 0)
- goto done;
+ h, /* handle (can be NULL) */
+ clixon_nghttp2_log_cb /* log fn */
+ ) < 0)
+ goto done;
#endif
clicon_debug_init(dbg, NULL);
clicon_log(LOG_NOTICE, "%s native %u Started", __PROGRAM__, getpid());
if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){
- clicon_err(OE_DAEMON, errno, "Setting signal");
- goto done;
+ clicon_err(OE_DAEMON, errno, "Setting signal");
+ goto done;
}
if (set_signal(SIGINT, restconf_sig_term, NULL) < 0){
- clicon_err(OE_DAEMON, errno, "Setting signal");
- goto done;
+ clicon_err(OE_DAEMON, errno, "Setting signal");
+ goto done;
}
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
- clicon_err(OE_DAEMON, errno, "Setting signal");
- goto done;
+ clicon_err(OE_DAEMON, errno, "Setting signal");
+ goto done;
}
yang_init(h);
/* Find and read configfile */
if (clicon_options_main(h) < 0)
- goto done;
+ goto done;
// stream_path = clicon_option_str(h, "CLICON_STREAM_PATH");
/* Now rest of options, some overwrite option file */
optind = 1;
opterr = 0;
while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1)
- switch (c) {
- case 'h' : /* help */
- case 'D' : /* debug */
- case 'f': /* config file */
- case 'E': /* extra config dir */
- case 'l': /* log */
- break; /* see above */
- case 'p' : /* yang dir path */
- if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
- goto done;
- break;
- case 'y' : /* Load yang spec file (override yang main module) */
- clicon_option_str_set(h, "CLICON_YANG_MAIN_FILE", optarg);
- break;
- case 'a': /* internal backend socket address family */
- clicon_option_str_set(h, "CLICON_SOCK_FAMILY", optarg);
- break;
- case 'u': /* internal backend socket unix domain path or ip host */
- if (!strlen(optarg))
- usage(h, argv0);
- clicon_option_str_set(h, "CLICON_SOCK", optarg);
- break;
- case 'r': /* Do not drop privileges if run as root */
- if (clicon_option_add(h, "CLICON_RESTCONF_PRIVILEGES", "none") < 0)
- goto done;
- break;
- case 'W': /* Run restconf daemon as this user (afetr drop) */
- if (clicon_option_add(h, "CLICON_RESTCONF_USER", optarg) < 0)
- goto done;
- break;
- case 'R': /* Restconf on-line config */
- inline_config = optarg;
- break;
- case 'o':{ /* Configuration option */
- char *val;
- if ((val = index(optarg, '=')) == NULL)
- usage(h, argv0);
- *val++ = '\0';
- if (clicon_option_add(h, optarg, val) < 0)
- goto done;
- break;
- }
+ switch (c) {
+ case 'h' : /* help */
+ case 'D' : /* debug */
+ case 'f': /* config file */
+ case 'E': /* extra config dir */
+ case 'l': /* log */
+ break; /* see above */
+ case 'p' : /* yang dir path */
+ if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
+ goto done;
+ break;
+ case 'y' : /* Load yang spec file (override yang main module) */
+ clicon_option_str_set(h, "CLICON_YANG_MAIN_FILE", optarg);
+ break;
+ case 'a': /* internal backend socket address family */
+ clicon_option_str_set(h, "CLICON_SOCK_FAMILY", optarg);
+ break;
+ case 'u': /* internal backend socket unix domain path or ip host */
+ if (!strlen(optarg))
+ usage(h, argv0);
+ clicon_option_str_set(h, "CLICON_SOCK", optarg);
+ break;
+ case 'r': /* Do not drop privileges if run as root */
+ if (clicon_option_add(h, "CLICON_RESTCONF_PRIVILEGES", "none") < 0)
+ goto done;
+ break;
+ case 'W': /* Run restconf daemon as this user (afetr drop) */
+ if (clicon_option_add(h, "CLICON_RESTCONF_USER", optarg) < 0)
+ goto done;
+ break;
+ case 'R': /* Restconf on-line config */
+ inline_config = optarg;
+ break;
+ case 'o':{ /* Configuration option */
+ char *val;
+ if ((val = index(optarg, '=')) == NULL)
+ usage(h, argv0);
+ *val++ = '\0';
+ if (clicon_option_add(h, optarg, val) < 0)
+ goto done;
+ break;
+ }
default:
usage(h, argv0);
break;
- }
+ }
argc -= optind;
argv += optind;
@@ -1251,48 +1251,48 @@ main(int argc,
/* Dump configuration options on debug */
if (dbg)
- clicon_option_dump(h, dbg);
+ clicon_option_dump(h, dbg);
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
- goto done;
+ goto done;
/* Call start function in all plugins before we go interactive */
if (clixon_plugin_start_all(h) < 0)
- goto done;
+ goto done;
/* Clixon inits / configs */
if ((ret = restconf_clixon_init(h, inline_config, &xrestconf)) < 0)
- goto done;
+ goto done;
if (ret == 0){ /* restconf disabled */
- clicon_debug(1, "restconf configuration not found or disabled");
- retval = 0;
- goto done;
+ clicon_debug(1, "restconf configuration not found or disabled");
+ retval = 0;
+ goto done;
}
/* Create and stroe global openssl handle */
if ((rn = malloc(sizeof *rn)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(rn, 0, sizeof *rn);
if (restconf_native_handle_set(h, rn) < 0)
- goto done;
+ goto done;
/* Openssl inits */
if (restconf_openssl_init(h, dbg, xrestconf) < 0)
- goto done;
+ goto done;
/* Drop privileges if started as root to CLICON_RESTCONF_USER
* and use drop mode: CLICON_RESTCONF_PRIVILEGES
*/
if (restconf_drop_privileges(h) < 0)
- goto done;
+ goto done;
/* Main event loop */
if (clixon_event_loop(h) < 0)
- goto done;
+ goto done;
retval = 0;
done:
clicon_debug(1, "restconf_main_openssl done");
if (xrestconf)
- xml_free(xrestconf);
+ xml_free(xrestconf);
restconf_native_terminate(h);
restconf_terminate(h);
return retval;
diff --git a/apps/restconf/restconf_methods.c b/apps/restconf/restconf_methods.c
index 2b370313..9c1fbebc 100644
--- a/apps/restconf/restconf_methods.c
+++ b/apps/restconf/restconf_methods.c
@@ -92,17 +92,17 @@
*/
int
api_data_options(clicon_handle h,
- void *req)
+ void *req)
{
int retval = -1;
clicon_debug(1, "%s", __FUNCTION__);
if (restconf_reply_header(req, "Allow", "OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE") < 0)
- goto done;
+ goto done;
if (restconf_reply_header(req, "Accept-Patch", "application/yang-data+xml,application/yang-data+json") < 0)
- goto done;
+ goto done;
if (restconf_reply_send(req, 200, NULL, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -128,8 +128,8 @@ api_data_options(clicon_handle h,
*/
static int
match_list_keys(yang_stmt *y,
- cxobj *x1,
- cxobj *x2)
+ cxobj *x1,
+ cxobj *x2)
{
int retval = -1;
cvec *cvk = NULL; /* vector of index keys */
@@ -143,32 +143,32 @@ match_list_keys(yang_stmt *y,
clicon_debug(1, "%s", __FUNCTION__);
switch (yang_keyword_get(y)){
case Y_LIST:
- cvk = yang_cvec_get(y); /* Use Y_LIST cache, see ys_populate_list() */
- cvi = NULL;
- while ((cvi = cvec_each(cvk, cvi)) != NULL) {
- keyname = cv_string_get(cvi);
- if ((xkey2 = xml_find(x2, keyname)) == NULL)
- goto done; /* No key in api-path */
- if ((key2 = xml_body(xkey2)) == NULL)
- goto done;
- if ((xkey1 = xml_find(x1, keyname)) == NULL)
- goto done; /* No key in data */
- if ((key1 = xml_body(xkey1)) == NULL)
- goto done;
- if (strcmp(key2, key1) != 0)
- goto done; /* keys dont match */
- }
- break;
+ cvk = yang_cvec_get(y); /* Use Y_LIST cache, see ys_populate_list() */
+ cvi = NULL;
+ while ((cvi = cvec_each(cvk, cvi)) != NULL) {
+ keyname = cv_string_get(cvi);
+ if ((xkey2 = xml_find(x2, keyname)) == NULL)
+ goto done; /* No key in api-path */
+ if ((key2 = xml_body(xkey2)) == NULL)
+ goto done;
+ if ((xkey1 = xml_find(x1, keyname)) == NULL)
+ goto done; /* No key in data */
+ if ((key1 = xml_body(xkey1)) == NULL)
+ goto done;
+ if (strcmp(key2, key1) != 0)
+ goto done; /* keys dont match */
+ }
+ break;
case Y_LEAF_LIST:
- if ((key2 = xml_body(x2)) == NULL)
- goto done; /* No key in api-path */
- if ((key1 = xml_body(x1)) == NULL)
- goto done; /* No key in data */
- if (strcmp(key2, key1) != 0)
- goto done; /* keys dont match */
- break;
+ if ((key2 = xml_body(x2)) == NULL)
+ goto done; /* No key in api-path */
+ if ((key1 = xml_body(x1)) == NULL)
+ goto done; /* No key in data */
+ if (strcmp(key2, key1) != 0)
+ goto done; /* keys dont match */
+ break;
default:
- goto ok;
+ goto ok;
}
ok:
retval = 0;
@@ -189,16 +189,16 @@ match_list_keys(yang_stmt *y,
*/
int
api_data_write(clicon_handle h,
- void *req,
- char *api_path0,
- int pi,
- cvec *qvec,
- char *data,
- int pretty,
- restconf_media media_in,
- restconf_media media_out,
- int plain_patch,
- ietf_ds_t ds)
+ void *req,
+ char *api_path0,
+ int pi,
+ cvec *qvec,
+ char *data,
+ int pretty,
+ restconf_media media_in,
+ restconf_media media_out,
+ int plain_patch,
+ ietf_ds_t ds)
{
int retval = -1;
enum operation_type op;
@@ -229,89 +229,89 @@ api_data_write(clicon_handle h,
yang_bind yb;
char *xpath = NULL;
char *attr;
-
+
clicon_debug(1, "%s api_path:\"%s\"", __FUNCTION__, api_path0);
clicon_debug(1, "%s data:\"%s\"", __FUNCTION__, data);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
api_path=api_path0;
/* strip /... from start */
for (i=0; i */
- else
- yb = YB_MODULE; /* data is eg: */
+ if (api_path==NULL)
+ yb = YB_MODULE_NEXT; /* data is eg: */
+ else
+ yb = YB_MODULE; /* data is eg: */
}
else
- yb = YB_PARENT;
+ yb = YB_PARENT;
/* Parse input data as json or xml into xml
* Note that in POST (api_data_post) the new object is grafted on xbot, since it is a new
@@ -321,48 +321,48 @@ api_data_write(clicon_handle h,
*/
switch (media_in){
case YANG_DATA_XML:
- if ((ret = clixon_xml_parse_string(data, yb, yspec, &xdata0, &xerr)) < 0){
- if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
- }
- if (ret == 0){
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
- }
- break;
+ if ((ret = clixon_xml_parse_string(data, yb, yspec, &xdata0, &xerr)) < 0){
+ if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
+ if (ret == 0){
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
+ break;
case YANG_DATA_JSON:
- if ((ret = clixon_json_parse_string(data, 1, yb, yspec, &xdata0, &xerr)) < 0){
- if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
- }
- if (ret == 0){
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
- }
- break;
+ if ((ret = clixon_json_parse_string(data, 1, yb, yspec, &xdata0, &xerr)) < 0){
+ if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
+ if (ret == 0){
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
+ break;
default:
- restconf_unsupported_media(h, req, pretty, media_out);
- goto ok;
- break;
+ restconf_unsupported_media(h, req, pretty, media_out);
+ goto ok;
+ break;
} /* switch media_in */
/* The message-body MUST contain exactly one instance of the
* expected data resource.
*/
if (xml_child_nr_type(xdata0, CX_ELMNT) != 1){
- if (netconf_malformed_message_xml(&xerr, "The message-body MUST contain exactly one instance of the expected data resource") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (netconf_malformed_message_xml(&xerr, "The message-body MUST contain exactly one instance of the expected data resource") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
xdata = xml_child_i_type(xdata0, 0, CX_ELMNT);
/* If the api-path (above) defines a module, then xdata must have a prefix
@@ -370,158 +370,158 @@ api_data_write(clicon_handle h,
* This does not apply if api-path is / (no module)
*/
if (ys_module_by_xml(yspec, xdata, &ymoddata) < 0)
- goto done;
+ goto done;
if (ymoddata && ymodapi){
- if (ymoddata != ymodapi){
- if (netconf_malformed_message_xml(&xerr, "Data is not prefixed with matching namespace") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
- }
+ if (ymoddata != ymodapi){
+ if (netconf_malformed_message_xml(&xerr, "Data is not prefixed with matching namespace") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
}
/* Add operation create as attribute. If that fails with Conflict, then
* try "replace" (see comment in function header)
*/
if ((xa = xml_new("operation", xdata, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (xml_prefix_set(xa, NETCONF_BASE_PREFIX) < 0)
- goto done;
+ goto done;
if (xml_value_set(xa, xml_operation2str(op)) < 0) /* XXX here is where op is used */
- goto done;
+ goto done;
if ((xa = xml_new("objectcreate", xdata, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (plain_patch){
- /* RFC 8040 4.6. PATCH:
- * If the target resource instance does not exist, the server MUST NOT create it.
- */
- if (xml_value_set(xa, "false") < 0)
- goto done;
+ /* RFC 8040 4.6. PATCH:
+ * If the target resource instance does not exist, the server MUST NOT create it.
+ */
+ if (xml_value_set(xa, "false") < 0)
+ goto done;
}
else
- if (xml_value_set(xa, "true") < 0)
- goto done;
+ if (xml_value_set(xa, "true") < 0)
+ goto done;
/* Top-of tree, no api-path
* Replace xparent with x, ie bottom of api-path with data
- */
+ */
dname = xml_name(xdata);
if (api_path==NULL) {
- if (strcmp(dname, NETCONF_OUTPUT_DATA)!=0){
- if (netconf_bad_element_xml(&xerr, "application", dname,
- "Data element does not match top-level data") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
- }
- if (xml_addsub(NULL, xdata) < 0)
- goto done;
- if (xtop) /* also xbot */
- xml_free(xtop);
- xtop = xdata;
- xml_name_set(xtop, NETCONF_INPUT_CONFIG);
- /* remove default namespace */
- if ((xa = xml_find_type(xtop, NULL, "xmlns", CX_ATTR)) != NULL){
- if (xml_rm(xa) < 0)
- goto done;
- if (xml_free(xa) < 0)
- goto done;
- }
+ if (strcmp(dname, NETCONF_OUTPUT_DATA)!=0){
+ if (netconf_bad_element_xml(&xerr, "application", dname,
+ "Data element does not match top-level data") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
+ if (xml_addsub(NULL, xdata) < 0)
+ goto done;
+ if (xtop) /* also xbot */
+ xml_free(xtop);
+ xtop = xdata;
+ xml_name_set(xtop, NETCONF_INPUT_CONFIG);
+ /* remove default namespace */
+ if ((xa = xml_find_type(xtop, NULL, "xmlns", CX_ATTR)) != NULL){
+ if (xml_rm(xa) < 0)
+ goto done;
+ if (xml_free(xa) < 0)
+ goto done;
+ }
}
else { /* api-path != NULL */
- /* There is an api-path that defines an element in the datastore tree.
- * Not top-of-tree.
- */
- clicon_debug(1, "%s Comparing bottom-of api-path (%s) with top-of-data (%s)",__FUNCTION__, xml_name(xbot), dname);
+ /* There is an api-path that defines an element in the datastore tree.
+ * Not top-of-tree.
+ */
+ clicon_debug(1, "%s Comparing bottom-of api-path (%s) with top-of-data (%s)",__FUNCTION__, xml_name(xbot), dname);
- /* Check same symbol in api-path as data */
- if (strcmp(dname, xml_name(xbot))){
- if (netconf_bad_element_xml(&xerr, "application", dname,
- "Data element does not match api-path") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
- }
- /* If list or leaf-list, api-path keys must match data keys
- * There are two cases, either the object is the list element itself,
- * eg xpath:obj=a data:b
- * or the object is the key element:
- * eg xpath:obj=a/key data:b
- * That is why the conditional is somewhat hairy
- */
- xparent = xml_parent(xbot);
- if (ybot){
- /* Ensure list keys match between uri and data. That is:
- * If data is on the form: -d {"a":{"k":1}} where a is list or leaf-list
- * then uri-path must be ../a=1
- * match_list_key() checks if this is true
- */
- if (match_list_keys(ybot, xdata, xbot) < 0){
- if (netconf_operation_failed_xml(&xerr, "protocol", "api-path keys do not match data keys") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
- }
- /* Ensure keys in lists are not changed. That is:
- * If data is on the form: -d {"k":1} and its parent is a list "a"
- * then the uri-path must be "../a=1 (you cannot change a's key)"
- */
- if ((yp = yang_parent_get(ybot)) != NULL &&
- yang_keyword_get(yp) == Y_LIST){
- if ((ret = yang_key_match(yp, dname, NULL)) < 0)
- goto done;
- if (ret == 1){ /* Match: xdata is a key */
- char *parbod = xml_find_body(xparent, dname);
- /* Check if the key is different from the one in uri-path,
- * or does not exist
- */
- if (parbod == NULL || strcmp(parbod, xml_body(xdata))){
- if (netconf_operation_failed_xml(&xerr, "protocol", "api-path keys do not match data keys") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
- }
- }
- }
- }
- if (xtop != xbot) /* Should always be true */
- xml_purge(xbot);
- if (xml_addsub(xparent, xdata) < 0)
- goto done;
- /* If restconf insert/point attributes are present, translate to netconf */
- if (restconf_insert_attributes(xdata, qvec) < 0)
- goto done;
- /* If we already have that default namespace, remove it in child */
- if ((xa = xml_find_type(xdata, NULL, "xmlns", CX_ATTR)) != NULL){
- if (xml2ns(xparent, NULL, &namespace) < 0){
- clicon_debug(1, "%s G done", __FUNCTION__);
- goto done;
- }
- if (namespace == NULL){
- clicon_log_xml(LOG_DEBUG, xparent, "%s xparent:", __FUNCTION__);
- /* XXX */
- }
- /* Set xmlns="" default namespace attribute (if diff from default) */
- if (namespace && strcmp(namespace, xml_value(xa))==0)
- xml_purge(xa);
- }
+ /* Check same symbol in api-path as data */
+ if (strcmp(dname, xml_name(xbot))){
+ if (netconf_bad_element_xml(&xerr, "application", dname,
+ "Data element does not match api-path") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
+ /* If list or leaf-list, api-path keys must match data keys
+ * There are two cases, either the object is the list element itself,
+ * eg xpath:obj=a data:b
+ * or the object is the key element:
+ * eg xpath:obj=a/key data:b
+ * That is why the conditional is somewhat hairy
+ */
+ xparent = xml_parent(xbot);
+ if (ybot){
+ /* Ensure list keys match between uri and data. That is:
+ * If data is on the form: -d {"a":{"k":1}} where a is list or leaf-list
+ * then uri-path must be ../a=1
+ * match_list_key() checks if this is true
+ */
+ if (match_list_keys(ybot, xdata, xbot) < 0){
+ if (netconf_operation_failed_xml(&xerr, "protocol", "api-path keys do not match data keys") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
+ /* Ensure keys in lists are not changed. That is:
+ * If data is on the form: -d {"k":1} and its parent is a list "a"
+ * then the uri-path must be "../a=1 (you cannot change a's key)"
+ */
+ if ((yp = yang_parent_get(ybot)) != NULL &&
+ yang_keyword_get(yp) == Y_LIST){
+ if ((ret = yang_key_match(yp, dname, NULL)) < 0)
+ goto done;
+ if (ret == 1){ /* Match: xdata is a key */
+ char *parbod = xml_find_body(xparent, dname);
+ /* Check if the key is different from the one in uri-path,
+ * or does not exist
+ */
+ if (parbod == NULL || strcmp(parbod, xml_body(xdata))){
+ if (netconf_operation_failed_xml(&xerr, "protocol", "api-path keys do not match data keys") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
+ }
+ }
+ }
+ if (xtop != xbot) /* Should always be true */
+ xml_purge(xbot);
+ if (xml_addsub(xparent, xdata) < 0)
+ goto done;
+ /* If restconf insert/point attributes are present, translate to netconf */
+ if (restconf_insert_attributes(xdata, qvec) < 0)
+ goto done;
+ /* If we already have that default namespace, remove it in child */
+ if ((xa = xml_find_type(xdata, NULL, "xmlns", CX_ATTR)) != NULL){
+ if (xml2ns(xparent, NULL, &namespace) < 0){
+ clicon_debug(1, "%s G done", __FUNCTION__);
+ goto done;
+ }
+ if (namespace == NULL){
+ clicon_log_xml(LOG_DEBUG, xparent, "%s xparent:", __FUNCTION__);
+ /* XXX */
+ }
+ /* Set xmlns="" default namespace attribute (if diff from default) */
+ if (namespace && strcmp(namespace, xml_value(xa))==0)
+ xml_purge(xa);
+ }
} /* api-path != NULL */
/* For internal XML protocol: add username attribute for access control
*/
username = clicon_username_get(h);
/* Create text buffer for transfer to backend */
if ((cbx = cbuf_new()) == NULL)
- goto done;
+ goto done;
cprintf(cbx, "",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_BASE_PREFIX,
- NETCONF_BASE_NAMESPACE, /* bind nc to netconf namespace */
- NETCONF_MESSAGE_ID_ATTR);
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_BASE_PREFIX,
+ NETCONF_BASE_NAMESPACE, /* bind nc to netconf namespace */
+ NETCONF_MESSAGE_ID_ATTR);
cprintf(cbx, " ");
cprintf(cbx, "none ");
if (clixon_xml2cbuf(cbx, xtop, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
cprintf(cbx, " ");
clicon_debug(1, "%s xml: %s api_path:%s",__FUNCTION__, cbuf_get(cbx), api_path);
if (clicon_rpc_netconf(h, cbuf_get(cbx), &xret, NULL) < 0)
- goto done;
+ goto done;
if ((xe = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
if ((xe = xpath_first(xret, NULL, "//ok")) != NULL &&
- (attr = xml_find_value(xe, "objectexisted")) != NULL &&
- strcmp(attr, "false")==0){
- if (restconf_reply_send(req, 201, NULL, 0) < 0) /* Created */
- goto done;
+ (attr = xml_find_value(xe, "objectexisted")) != NULL &&
+ strcmp(attr, "false")==0){
+ if (restconf_reply_send(req, 201, NULL, 0) < 0) /* Created */
+ goto done;
}
else
- if (restconf_reply_send(req, 204, NULL, 0) < 0) /* No content */
- goto done;
+ if (restconf_reply_send(req, 204, NULL, 0) < 0) /* No content */
+ goto done;
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (xpath)
- free(xpath);
+ free(xpath);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (xretcom)
- xml_free(xretcom);
+ xml_free(xretcom);
if (xretdis)
- xml_free(xretdis);
+ xml_free(xretdis);
if (xtop)
- xml_free(xtop);
+ xml_free(xtop);
if (xdata0)
- xml_free(xdata0);
+ xml_free(xdata0);
if (cbx)
- cbuf_free(cbx);
+ cbuf_free(cbx);
return retval;
} /* api_data_write */
@@ -618,20 +618,20 @@ api_data_write(clicon_handle h,
*/
int
api_data_put(clicon_handle h,
- void *req,
- char *api_path0,
- int pi,
- cvec *qvec,
- char *data,
- int pretty,
- restconf_media media_out,
- ietf_ds_t ds)
+ void *req,
+ char *api_path0,
+ int pi,
+ cvec *qvec,
+ char *data,
+ int pretty,
+ restconf_media media_out,
+ ietf_ds_t ds)
{
restconf_media media_in;
media_in = restconf_content_type(h);
return api_data_write(h, req, api_path0, pi, qvec, data, pretty,
- media_in, media_out, 0, ds);
+ media_in, media_out, 0, ds);
}
/*! Generic REST PATCH method for plain patch
@@ -653,14 +653,14 @@ api_data_put(clicon_handle h,
*/
int
api_data_patch(clicon_handle h,
- void *req,
- char *api_path0,
- int pi,
- cvec *qvec,
- char *data,
- int pretty,
- restconf_media media_out,
- ietf_ds_t ds)
+ void *req,
+ char *api_path0,
+ int pi,
+ cvec *qvec,
+ char *data,
+ int pretty,
+ restconf_media media_out,
+ ietf_ds_t ds)
{
restconf_media media_in;
int ret = -1;
@@ -668,23 +668,23 @@ api_data_patch(clicon_handle h,
media_in = restconf_content_type(h);
switch (media_in){
case YANG_DATA_XML:
- case YANG_DATA_JSON: /* plain patch */
- ret = api_data_write(h, req, api_path0, pi, qvec, data, pretty,
- media_in, media_out, 1, ds);
- break;
- case YANG_PATCH_JSON: /* RFC 8072 patch */
+ case YANG_DATA_JSON: /* plain patch */
+ ret = api_data_write(h, req, api_path0, pi, qvec, data, pretty,
+ media_in, media_out, 1, ds);
+ break;
+ case YANG_PATCH_JSON: /* RFC 8072 patch */
case YANG_PATCH_XML:
#ifdef CLIXON_YANG_PATCH
- ret = api_data_yang_patch(h, req, api_path0, pcvec, pi, qvec, data, pretty,
- media_in, media_out, ds);
+ ret = api_data_yang_patch(h, req, api_path0, pcvec, pi, qvec, data, pretty,
+ media_in, media_out, ds);
#else
- ret = restconf_notimplemented(h, req, pretty, media_out);
+ ret = restconf_notimplemented(h, req, pretty, media_out);
#endif
- break;
+ break;
break;
default:
- ret = restconf_unsupported_media(h, req, pretty, media_out);
- break;
+ ret = restconf_unsupported_media(h, req, pretty, media_out);
+ break;
}
return ret;
}
@@ -704,12 +704,12 @@ api_data_patch(clicon_handle h,
*/
int
api_data_delete(clicon_handle h,
- void *req,
- char *api_path,
- int pi,
- int pretty,
- restconf_media media_out,
- ietf_ds_t ds)
+ void *req,
+ char *api_path,
+ int pi,
+ int pretty,
+ restconf_media media_out,
+ ietf_ds_t ds)
{
int retval = -1;
int i;
@@ -730,42 +730,42 @@ api_data_delete(clicon_handle h,
clicon_debug(1, "%s api_path:%s", __FUNCTION__, api_path);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
for (i=0; i",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_BASE_PREFIX,
- NETCONF_BASE_NAMESPACE,
- NETCONF_MESSAGE_ID_ATTR); /* bind nc to netconf namespace */
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_BASE_PREFIX,
+ NETCONF_BASE_NAMESPACE,
+ NETCONF_MESSAGE_ID_ATTR); /* bind nc to netconf namespace */
cprintf(cbx, " ");
cprintf(cbx, "none ");
if (clixon_xml2cbuf(cbx, xtop, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
cprintf(cbx, " ");
if (clicon_rpc_netconf(h, cbuf_get(cbx), &xret, NULL) < 0)
- goto done;
+ goto done;
if ((xe = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
if (restconf_reply_send(req, 204, NULL, 0) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
if (cbx)
- cbuf_free(cbx);
+ cbuf_free(cbx);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (xretcom)
- xml_free(xretcom);
+ xml_free(xretcom);
if (xretdis)
- xml_free(xretdis);
+ xml_free(xretdis);
if (xtop)
- xml_free(xtop);
+ xml_free(xtop);
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
return retval;
}
diff --git a/apps/restconf/restconf_methods.h b/apps/restconf/restconf_methods.h
index df33c0d4..5fbe2bf0 100644
--- a/apps/restconf/restconf_methods.h
+++ b/apps/restconf/restconf_methods.h
@@ -44,22 +44,22 @@
*/
int api_data_options(clicon_handle h, void *req);
int api_data_write(clicon_handle h, void *req, char *api_path0,
- int pi,
- cvec *qvec, char *data,
- int pretty, restconf_media media_in, restconf_media media_out,
- int plain_patch, ietf_ds_t ds);
+ int pi,
+ cvec *qvec, char *data,
+ int pretty, restconf_media media_in, restconf_media media_out,
+ int plain_patch, ietf_ds_t ds);
int api_data_put(clicon_handle h, void *req, char *api_path,
- int pi,
- cvec *qvec, char *data,
- int pretty, restconf_media media_out, ietf_ds_t ds);
+ int pi,
+ cvec *qvec, char *data,
+ int pretty, restconf_media media_out, ietf_ds_t ds);
int api_data_patch(clicon_handle h, void *req, char *api_path,
- int pi,
- cvec *qvec, char *data, int pretty,
- restconf_media media_out, ietf_ds_t ds);
+ int pi,
+ cvec *qvec, char *data, int pretty,
+ restconf_media media_out, ietf_ds_t ds);
int api_data_delete(clicon_handle h, void *req, char *api_path, int pi,
- int pretty, restconf_media media_out, ietf_ds_t ds);
+ int pretty, restconf_media media_out, ietf_ds_t ds);
#endif /* _RESTCONF_METHODS_H_ */
diff --git a/apps/restconf/restconf_methods_get.c b/apps/restconf/restconf_methods_get.c
index a82e11dd..82dd059e 100644
--- a/apps/restconf/restconf_methods_get.c
+++ b/apps/restconf/restconf_methods_get.c
@@ -96,13 +96,13 @@ static int api_data_pagination(clicon_handle h, void *req, char *api_path, int p
*/
static int
api_data_get2(clicon_handle h,
- void *req,
- char *api_path,
- int pi,
- cvec *qvec,
- int pretty,
- restconf_media media_out,
- int head)
+ void *req,
+ char *api_path,
+ int pi,
+ cvec *qvec,
+ int pretty,
+ restconf_media media_out,
+ int head)
{
int retval = -1;
char *xpath = NULL;
@@ -128,196 +128,196 @@ api_data_get2(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
/* strip /... from start */
for (i=0; i0
- * Out: {"example:x": {"0"}}
- */
- if (xml2json_cbuf_vec(cbx, xvec, xlen, pretty) < 0)
- goto done;
- break;
- default:
- break;
- }
+ if (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath) < 0){
+ if (netconf_operation_failed_xml(&xerr, "application", clicon_err_reason) < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
+ /* Check if not exists */
+ if (xlen == 0){
+ /* 4.3: If a retrieval request for a data resource represents an
+ instance that does not exist, then an error response containing
+ a "404 Not Found" status-line MUST be returned by the server.
+ The error-tag value "invalid-value" is used in this case. */
+ if (netconf_invalid_value_xml(&xerr, "application", "Instance does not exist") < 0)
+ goto done;
+ /* override invalid-value default 400 with 404 */
+ if (api_return_err0(h, req, xerr, pretty, media_out, 404) < 0)
+ goto done;
+ goto ok;
+ }
+ switch (media_out){
+ case YANG_DATA_XML:
+ for (i=0; i0
+ * Out: {"example:x": {"0"}}
+ */
+ if (xml2json_cbuf_vec(cbx, xvec, xlen, pretty) < 0)
+ goto done;
+ break;
+ default:
+ break;
+ }
}
clicon_debug(1, "%s cbuf:%s", __FUNCTION__, cbuf_get(cbx));
if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0)
- goto done;
+ goto done;
if (restconf_reply_header(req, "Cache-Control", "no-cache") < 0)
- goto done;
+ goto done;
if (restconf_reply_send(req, 200, cbx, head) < 0)
- goto done;
+ goto done;
cbx = NULL;
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (xpath)
- free(xpath);
+ free(xpath);
if (nscd)
- cvec_free(nscd);
+ cvec_free(nscd);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (xtop)
xml_free(xtop);
if (cbx)
cbuf_free(cbx);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (xvec)
- free(xvec);
+ free(xvec);
return retval;
}
@@ -341,12 +341,12 @@ api_data_get2(clicon_handle h,
*/
static int
api_data_pagination(clicon_handle h,
- void *req,
- char *api_path,
- int pi,
- cvec *qvec,
- int pretty,
- restconf_media media_out)
+ void *req,
+ char *api_path,
+ int pi,
+ cvec *qvec,
+ int pretty,
+ restconf_media media_out)
{
int retval = -1;
char *xpath = NULL;
@@ -378,145 +378,145 @@ api_data_pagination(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
/* strip /... from start */
for (i=0; i");
- break;
+ cprintf(cbx, "");
+ break;
case YANG_DATA_JSON:
- if (pretty)
- cprintf(cbx, "{\"operations\": {\n");
- else
- cprintf(cbx, "{\"operations\":{");
- break;
+ if (pretty)
+ cprintf(cbx, "{\"operations\": {\n");
+ else
+ cprintf(cbx, "{\"operations\":{");
+ break;
default:
- break;
+ break;
}
ymod = NULL;
i = 0;
while ((ymod = yn_each(yspec, ymod)) != NULL) {
- namespace = yang_find_mynamespace(ymod);
- yc = NULL;
- while ((yc = yn_each(ymod, yc)) != NULL) {
- if (yang_keyword_get(yc) != Y_RPC)
- continue;
- switch (media_out){
- case YANG_DATA_XML:
- cprintf(cbx, "<%s xmlns=\"%s\"/>", yang_argument_get(yc), namespace);
- break;
- case YANG_DATA_JSON:
- if (i++){
- cprintf(cbx, ",");
- if (pretty)
- cprintf(cbx, "\n\t");
- }
- if (pretty)
- cprintf(cbx, "\"%s:%s\": [null]", yang_argument_get(ymod), yang_argument_get(yc));
- else
- cprintf(cbx, "\"%s:%s\":[null]", yang_argument_get(ymod), yang_argument_get(yc));
- break;
- default:
- break;
- }
- }
+ namespace = yang_find_mynamespace(ymod);
+ yc = NULL;
+ while ((yc = yn_each(ymod, yc)) != NULL) {
+ if (yang_keyword_get(yc) != Y_RPC)
+ continue;
+ switch (media_out){
+ case YANG_DATA_XML:
+ cprintf(cbx, "<%s xmlns=\"%s\"/>", yang_argument_get(yc), namespace);
+ break;
+ case YANG_DATA_JSON:
+ if (i++){
+ cprintf(cbx, ",");
+ if (pretty)
+ cprintf(cbx, "\n\t");
+ }
+ if (pretty)
+ cprintf(cbx, "\"%s:%s\": [null]", yang_argument_get(ymod), yang_argument_get(yc));
+ else
+ cprintf(cbx, "\"%s:%s\":[null]", yang_argument_get(ymod), yang_argument_get(yc));
+ break;
+ default:
+ break;
+ }
+ }
}
switch (media_out){
case YANG_DATA_XML:
- cprintf(cbx, " ");
- break;
+ cprintf(cbx, "");
+ break;
case YANG_DATA_JSON:
- if (pretty)
- cprintf(cbx, "}\n}");
- else
- cprintf(cbx, "}}");
- break;
+ if (pretty)
+ cprintf(cbx, "}\n}");
+ else
+ cprintf(cbx, "}}");
+ break;
default:
- break;
+ break;
}
if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0)
- goto done;
+ goto done;
if (restconf_reply_header(req, "Cache-Control", "no-cache") < 0)
- goto done;
+ goto done;
if (restconf_reply_send(req, 200, cbx, 0) < 0)
- goto done;
+ goto done;
cbx = NULL;
// ok:
retval = 0;
@@ -782,7 +782,7 @@ api_operations_get(clicon_handle h,
if (cbx)
cbuf_free(cbx);
if (xt)
- xml_free(xt);
+ xml_free(xt);
return retval;
}
diff --git a/apps/restconf/restconf_methods_get.h b/apps/restconf/restconf_methods_get.h
index 6c6a40db..4fae4dcf 100644
--- a/apps/restconf/restconf_methods_get.h
+++ b/apps/restconf/restconf_methods_get.h
@@ -42,11 +42,11 @@
* Prototypes
*/
int api_data_head(clicon_handle h, void *req, char *api_path, int pi,
- cvec *qvec, int pretty, restconf_media media_out, ietf_ds_t ds);
+ cvec *qvec, int pretty, restconf_media media_out, ietf_ds_t ds);
int api_data_get(clicon_handle h, void *req, char *api_path, int pi,
- cvec *qvec, int pretty, restconf_media media_out, ietf_ds_t ds);
+ cvec *qvec, int pretty, restconf_media media_out, ietf_ds_t ds);
int api_operations_get(clicon_handle h, void *req,
- char *api_path, int pi, cvec *qvec, char *data,
- int pretty, restconf_media media_out);
+ char *api_path, int pi, cvec *qvec, char *data,
+ int pretty, restconf_media media_out);
#endif /* _RESTCONF_METHODS_GET_H_ */
diff --git a/apps/restconf/restconf_methods_patch.c b/apps/restconf/restconf_methods_patch.c
index 56e9531b..66ea35e8 100644
--- a/apps/restconf/restconf_methods_patch.c
+++ b/apps/restconf/restconf_methods_patch.c
@@ -114,13 +114,13 @@ yang_patch_xml2json_modified_cbuf(cxobj *x_simple_patch)
char *json_simple_patch_tmp;
int brace_count = 0;
size_t len;
-
+
json_simple_patch = cbuf_new();
if (json_simple_patch == NULL)
return NULL;
cb = cbuf_new();
if (clixon_json2cbuf(cb, x_simple_patch, 0, 0) < 0)
- goto done;
+ goto done;
// Insert a '[' after the first '{' to get the JSON to match what api_data_post/write() expect
json_simple_patch_tmp = cbuf_get(cb);
@@ -141,9 +141,9 @@ yang_patch_xml2json_modified_cbuf(cxobj *x_simple_patch)
char c = cbuf_get(json_simple_patch)[l];
if (c == '}') {
// Truncate and add a string, as there is not a function to insert a char into a cbuf
- cbuf_trunc(json_simple_patch, l);
- cbuf_append_str(json_simple_patch, "]}");
- break;
+ cbuf_trunc(json_simple_patch, l);
+ cbuf_append_str(json_simple_patch, "]}");
+ break;
}
}
cbuf_free(cb);
@@ -172,16 +172,16 @@ yang_patch_strip_after_last_slash(char* val)
cbuf_append_str(val_tmp, val);
idx = cbuf_len(val_tmp);
for (int l = cbuf_len(val_tmp) - 1; l>= 0; l--) {
- if (cbuf_get(val_tmp)[l] == '/') {
- idx = l;
- break;
- }
+ if (cbuf_get(val_tmp)[l] == '/') {
+ idx = l;
+ break;
+ }
}
if (idx == cbuf_len(val_tmp)) // Didn't find a slash in the loop above
- return NULL;
+ return NULL;
cbuf_trunc(val_tmp, idx + 1);
if (cbuf_append_str(cb, cbuf_get(val_tmp)) < 0)
- return NULL;
+ return NULL;
cbuf_free(val_tmp);
return cb;
}
@@ -202,18 +202,18 @@ yang_patch_strip_after_last_slash(char* val)
*/
static int
yang_patch_do_replace(clicon_handle h,
- void *req,
- int pi,
- cvec *qvec,
- int pretty,
- restconf_media media_out,
- ietf_ds_t ds,
- cbuf *simple_patch_request_uri,
- char *target_val,
- int value_vec_len,
- cxobj **value_vec,
- cxobj *x_simple_patch
- )
+ void *req,
+ int pi,
+ cvec *qvec,
+ int pretty,
+ restconf_media media_out,
+ ietf_ds_t ds,
+ cbuf *simple_patch_request_uri,
+ char *target_val,
+ int value_vec_len,
+ cxobj **value_vec,
+ cxobj *x_simple_patch
+ )
{
int retval = -1;
cxobj *value_vec_tmp = NULL;
@@ -222,67 +222,67 @@ yang_patch_do_replace(clicon_handle h,
cbuf *json_simple_patch = NULL;
if ((delete_req_uri = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
if ((json_simple_patch = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
// Make delete_req_uri something like "/restconf/data/ietf-interfaces:interfaces"
if (cbuf_append_str(delete_req_uri, cbuf_get(simple_patch_request_uri)) < 0){
- clicon_err(OE_UNIX, errno, "cbuf_append_str");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_append_str");
+ goto done;
}
// Add the target to delete_req_uri,
// so it's something like "/restconf/data/ietf-interfaces:interfaces/interface=eth2"
if (cbuf_append_str(delete_req_uri, target_val) < 0){
- clicon_err(OE_UNIX, errno, "cbuf_append_str");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_append_str");
+ goto done;
}
// Delete the object with the old values
if (api_data_delete(h, req, cbuf_get(delete_req_uri), pi, pretty, YANG_DATA_JSON, ds) < 0)
- goto done;
+ goto done;
// Now set up for the post request.
// Strip /... from end of target val
// so that e.g. "/interface=eth2" becomes "/"
// or "/interface_list=mylist/interface=eth2" becomes "/interface_list=mylist/"
if ((post_req_uri = yang_patch_strip_after_last_slash(target_val)) == NULL)
- goto done;
+ goto done;
// Make post_req_uri something like "/restconf/data/ietf-interfaces:interfaces"
if (cbuf_append_str(simple_patch_request_uri, cbuf_get(post_req_uri)) < 0){
- clicon_err(OE_UNIX, errno, "cbuf_append_str");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_append_str");
+ goto done;
}
// Now insert the new values into the data
// (which will include the key value and all other mandatory values)
for (int k = 0; k < value_vec_len; k++) {
- if (value_vec[k] != NULL) {
- value_vec_tmp = xml_dup(value_vec[k]);
- xml_addsub(x_simple_patch, value_vec_tmp);
- }
+ if (value_vec[k] != NULL) {
+ value_vec_tmp = xml_dup(value_vec[k]);
+ xml_addsub(x_simple_patch, value_vec_tmp);
+ }
}
// Convert the data to json
if (clixon_json2cbuf(json_simple_patch, x_simple_patch, 0, 0) < 0)
- goto done;
+ goto done;
// Send the POST request
if (api_data_post(h, req, cbuf_get(simple_patch_request_uri), pi, qvec, cbuf_get(json_simple_patch), pretty, YANG_DATA_JSON, media_out, ds ) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (post_req_uri)
- cbuf_free(post_req_uri);
+ cbuf_free(post_req_uri);
if (delete_req_uri)
- cbuf_free(delete_req_uri);
+ cbuf_free(delete_req_uri);
if (json_simple_patch)
- cbuf_free(json_simple_patch);
+ cbuf_free(json_simple_patch);
if (value_vec_tmp)
- xml_free(value_vec_tmp);
+ xml_free(value_vec_tmp);
return retval;
}
@@ -301,17 +301,17 @@ yang_patch_do_replace(clicon_handle h,
*/
static int
yang_patch_do_create(clicon_handle h,
- void *req,
- int pi,
- cvec *qvec,
- int pretty,
- restconf_media media_out,
- ietf_ds_t ds,
- cbuf *simple_patch_request_uri,
- int value_vec_len,
- cxobj **value_vec,
- cxobj *x_simple_patch
- )
+ void *req,
+ int pi,
+ cvec *qvec,
+ int pretty,
+ restconf_media media_out,
+ ietf_ds_t ds,
+ cbuf *simple_patch_request_uri,
+ int value_vec_len,
+ cxobj **value_vec,
+ cxobj *x_simple_patch
+ )
{
int retval = -1;
cxobj *value_vec_tmp = NULL;
@@ -319,26 +319,26 @@ yang_patch_do_create(clicon_handle h,
// Send the POST request
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
for (int k = 0; k < value_vec_len; k++) {
- if (value_vec[k] != NULL) {
- if ((value_vec_tmp = xml_dup(value_vec[k])) == NULL)
- goto done;
- xml_addsub(x_simple_patch, value_vec_tmp);
- }
+ if (value_vec[k] != NULL) {
+ if ((value_vec_tmp = xml_dup(value_vec[k])) == NULL)
+ goto done;
+ xml_addsub(x_simple_patch, value_vec_tmp);
+ }
}
if (clixon_json2cbuf(cb, x_simple_patch, 0, 0) < 0)
- goto done;
+ goto done;
if (api_data_post(h, req, cbuf_get(simple_patch_request_uri),
- pi, qvec,
- cbuf_get(cb), pretty, YANG_DATA_JSON, media_out, ds) < 0)
- goto done;
+ pi, qvec,
+ cbuf_get(cb), pretty, YANG_DATA_JSON, media_out, ds) < 0)
+ goto done;
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -359,19 +359,19 @@ yang_patch_do_create(clicon_handle h,
*/
static int
yang_patch_do_insert(clicon_handle h,
- void *req,
- int pi,
- int pretty,
- restconf_media media_out,
- ietf_ds_t ds,
- cbuf *simple_patch_request_uri,
- int value_vec_len,
- cxobj **value_vec,
- cxobj *x_simple_patch,
- char *where_val,
- char *api_path,
- char *point_val
- )
+ void *req,
+ int pi,
+ int pretty,
+ restconf_media media_out,
+ ietf_ds_t ds,
+ cbuf *simple_patch_request_uri,
+ int value_vec_len,
+ cxobj **value_vec,
+ cxobj *x_simple_patch,
+ char *where_val,
+ char *api_path,
+ char *point_val
+ )
{
int retval = -1;
cxobj *value_vec_tmp = NULL;
@@ -381,52 +381,52 @@ yang_patch_do_insert(clicon_handle h,
cvec *qvec_tmp = NULL;
if ((point_str = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
if ((qvec_tmp = cvec_new(0)) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
// Loop through the XML, and get each value
for (int k = 0; k < value_vec_len; k++) {
- if (value_vec[k] != NULL) {
- value_vec_tmp = xml_dup(value_vec[k]);
- xml_addsub(x_simple_patch, value_vec_tmp);
- }
+ if (value_vec[k] != NULL) {
+ value_vec_tmp = xml_dup(value_vec[k]);
+ xml_addsub(x_simple_patch, value_vec_tmp);
+ }
}
if ((json_simple_patch = yang_patch_xml2json_modified_cbuf(x_simple_patch)) == NULL)
- goto done;
+ goto done;
// Set the insert attributes
if ((cv = cvec_add(qvec_tmp, CGV_STRING)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_add");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_add");
+ goto done;
}
cv_name_set(cv, "insert");
if (where_val)
- cv_string_set(cv, where_val);
+ cv_string_set(cv, where_val);
cbuf_append_str(point_str, api_path);
if (point_val)
- cbuf_append_str(point_str, point_val);
+ cbuf_append_str(point_str, point_val);
if ((cv = cvec_add(qvec_tmp, CGV_STRING)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_add");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_add");
+ goto done;
}
cv_name_set(cv, "point");
cv_string_set(cv, cbuf_get(point_str));
// Send the POST request
if (api_data_post(h, req, cbuf_get(simple_patch_request_uri), pi, qvec_tmp, cbuf_get(json_simple_patch), pretty, YANG_DATA_JSON, media_out, ds)< 0)
- goto done;
+ goto done;
retval = 0;
done:
if (qvec_tmp)
- cvec_free(qvec_tmp);
+ cvec_free(qvec_tmp);
if (point_str)
- cbuf_free(point_str);
+ cbuf_free(point_str);
if (json_simple_patch)
- cbuf_free(json_simple_patch);
+ cbuf_free(json_simple_patch);
return retval;
}
@@ -447,57 +447,57 @@ yang_patch_do_insert(clicon_handle h,
*/
static int
yang_patch_do_merge(clicon_handle h,
- void *req,
- int pi,
- cvec *qvec,
- int pretty,
- restconf_media media_out,
- ietf_ds_t ds,
- cbuf *simple_patch_request_uri,
- int value_vec_len,
- cxobj **value_vec,
- cxobj *x_simple_patch,
- cxobj *key_xn
- )
+ void *req,
+ int pi,
+ cvec *qvec,
+ int pretty,
+ restconf_media media_out,
+ ietf_ds_t ds,
+ cbuf *simple_patch_request_uri,
+ int value_vec_len,
+ cxobj **value_vec,
+ cxobj *x_simple_patch,
+ cxobj *key_xn
+ )
{
int retval = -1;
cxobj *value_vec_tmp = NULL;
cbuf *cb = NULL;
cbuf *json_simple_patch = NULL;
-
+
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
if (key_xn != NULL)
- xml_addsub(x_simple_patch, key_xn);
+ xml_addsub(x_simple_patch, key_xn);
// Loop through the XML, create JSON from each one, and submit a simple patch
for (int k = 0; k < value_vec_len; k++) {
- if (value_vec[k] != NULL) {
- value_vec_tmp = xml_dup(value_vec[k]);
- xml_addsub(x_simple_patch, value_vec_tmp);
- }
- cbuf_reset(cb); /* reuse cb */
- if (clixon_json2cbuf(cb, x_simple_patch, 0, 0) < 0)
- goto done;
+ if (value_vec[k] != NULL) {
+ value_vec_tmp = xml_dup(value_vec[k]);
+ xml_addsub(x_simple_patch, value_vec_tmp);
+ }
+ cbuf_reset(cb); /* reuse cb */
+ if (clixon_json2cbuf(cb, x_simple_patch, 0, 0) < 0)
+ goto done;
if ((json_simple_patch = yang_patch_xml2json_modified_cbuf(x_simple_patch)) == NULL)
- goto done;
- // Send the simple patch request
- if (api_data_write(h, req, cbuf_get(simple_patch_request_uri), pi, qvec, cbuf_get(json_simple_patch), pretty, YANG_DATA_JSON, media_out, 1, ds ) < 0)
- goto done;
- if (json_simple_patch){
- cbuf_free(json_simple_patch);
- json_simple_patch = NULL;
- }
+ goto done;
+ // Send the simple patch request
+ if (api_data_write(h, req, cbuf_get(simple_patch_request_uri), pi, qvec, cbuf_get(json_simple_patch), pretty, YANG_DATA_JSON, media_out, 1, ds ) < 0)
+ goto done;
+ if (json_simple_patch){
+ cbuf_free(json_simple_patch);
+ json_simple_patch = NULL;
+ }
}
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (json_simple_patch)
- cbuf_free(json_simple_patch);
+ cbuf_free(json_simple_patch);
return retval;
}
@@ -509,22 +509,22 @@ yang_patch_do_merge(clicon_handle h,
*/
static int
yang_patch_do_value(clicon_handle h,
- void *req,
- int pi,
- cvec *qvec,
- int pretty,
- restconf_media media_out,
- ietf_ds_t ds,
- cxobj *xn,
- char *modname,
- yang_patch_op_t operation,
- char *where_val,
- char *point_val,
- cbuf *simple_patch_request_uri,
- char *target_val,
- char *api_path,
- cxobj *key_xn
- )
+ void *req,
+ int pi,
+ cvec *qvec,
+ int pretty,
+ restconf_media media_out,
+ ietf_ds_t ds,
+ cxobj *xn,
+ char *modname,
+ yang_patch_op_t operation,
+ char *where_val,
+ char *point_val,
+ cbuf *simple_patch_request_uri,
+ char *target_val,
+ char *api_path,
+ cxobj *key_xn
+ )
{
int retval = -1;
cxobj **values_child_vec;
@@ -538,40 +538,40 @@ yang_patch_do_value(clicon_handle h,
key_node_id = xml_name(*values_child_vec);
/* Create cbufs:s */
if ((patch_header = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
cprintf(patch_header, "%s:%s", modname, key_node_id);
if ((x_simple_patch = xml_new(cbuf_get(patch_header), NULL, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
value_vec_len = xml_child_nr(*values_child_vec);
value_vec = xml_childvec_get(*values_child_vec);
switch (operation){
case YANG_PATCH_OP_REPLACE:
- if (yang_patch_do_replace(h, req, pi, qvec, pretty, media_out, ds, simple_patch_request_uri, target_val, value_vec_len, value_vec, x_simple_patch) < 0)
- goto done;
- break;
+ if (yang_patch_do_replace(h, req, pi, qvec, pretty, media_out, ds, simple_patch_request_uri, target_val, value_vec_len, value_vec, x_simple_patch) < 0)
+ goto done;
+ break;
case YANG_PATCH_OP_CREATE:
- if (yang_patch_do_create(h, req, pi, qvec, pretty, media_out, ds, simple_patch_request_uri, value_vec_len, value_vec, x_simple_patch) < 0)
- goto done;
- break;
+ if (yang_patch_do_create(h, req, pi, qvec, pretty, media_out, ds, simple_patch_request_uri, value_vec_len, value_vec, x_simple_patch) < 0)
+ goto done;
+ break;
case YANG_PATCH_OP_INSERT:
- if (yang_patch_do_insert(h, req, pi, pretty, media_out, ds, simple_patch_request_uri, value_vec_len, value_vec, x_simple_patch, where_val, api_path, point_val) < 0)
- goto done;
- break;
+ if (yang_patch_do_insert(h, req, pi, pretty, media_out, ds, simple_patch_request_uri, value_vec_len, value_vec, x_simple_patch, where_val, api_path, point_val) < 0)
+ goto done;
+ break;
case YANG_PATCH_OP_MERGE:
- if (yang_patch_do_merge(h, req, pi, qvec, pretty, media_out, ds, simple_patch_request_uri, value_vec_len, value_vec, x_simple_patch, key_xn) < 0)
- goto done;
- break;
+ if (yang_patch_do_merge(h, req, pi, qvec, pretty, media_out, ds, simple_patch_request_uri, value_vec_len, value_vec, x_simple_patch, key_xn) < 0)
+ goto done;
+ break;
default:
- break;
+ break;
}
retval = 0;
done:
if (x_simple_patch)
- xml_free(x_simple_patch);
+ xml_free(x_simple_patch);
if (patch_header)
- cbuf_free(patch_header);
+ cbuf_free(patch_header);
return retval;
}
@@ -589,17 +589,17 @@ yang_patch_do_value(clicon_handle h,
*/
static int
yang_patch_do_edit(clicon_handle h,
- void *req,
- int pi,
- cvec *qvec,
- int pretty,
- restconf_media media_out,
- ietf_ds_t ds,
- yang_stmt *yspec,
- cxobj *xn,
- char *uripath0,
- char *api_path
- )
+ void *req,
+ int pi,
+ cvec *qvec,
+ int pretty,
+ restconf_media media_out,
+ ietf_ds_t ds,
+ yang_stmt *yspec,
+ cxobj *xn,
+ char *uripath0,
+ char *api_path
+ )
{
int retval = -1;
cxobj **vec = NULL;
@@ -626,100 +626,100 @@ yang_patch_do_edit(clicon_handle h,
clicon_log_xml(LOG_DEBUG, xn, "%s %d xn:", __FUNCTION__, __LINE__);
/* Create cbufs:s */
if ((simple_patch_request_uri = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
if ((api_path_target = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
if ((x = xpath_first(xn, NULL, "target")) == NULL){
- clicon_err(OE_YANG, 0, "target mandatory element not found");
- goto done;
+ clicon_err(OE_YANG, 0, "target mandatory element not found");
+ goto done;
}
target_val = xml_body(x);
if ((x = xpath_first(xn, NULL, "operation")) == NULL){
- clicon_err(OE_YANG, 0, "operation mandatory element not found");
- goto done;
+ clicon_err(OE_YANG, 0, "operation mandatory element not found");
+ goto done;
}
operation = yang_patch_op2int(xml_body(x));
/* target and operation are mandatory */
if (target_val == NULL){
- clicon_err(OE_YANG, 0, "operation/target: mandatory element not found");
- goto done;
+ clicon_err(OE_YANG, 0, "operation/target: mandatory element not found");
+ goto done;
}
if (operation == YANG_PATCH_OP_INSERT){
- if ((x = xpath_first(xn, NULL, "point")) != NULL)
- point_val = xml_body(x);
- if ((x = xpath_first(xn, NULL, "where")) != NULL)
- where_val = xml_body(x);
- if (point_val == NULL || where_val == NULL){
- clicon_err(OE_YANG, 0, "point/where: expected element not found");
- goto done;
- }
+ if ((x = xpath_first(xn, NULL, "point")) != NULL)
+ point_val = xml_body(x);
+ if ((x = xpath_first(xn, NULL, "where")) != NULL)
+ where_val = xml_body(x);
+ if (point_val == NULL || where_val == NULL){
+ clicon_err(OE_YANG, 0, "point/where: expected element not found");
+ goto done;
+ }
}
// Construct request URI
cprintf(simple_patch_request_uri, "%s", uripath0);
cprintf(api_path_target, "%s", api_path);
if (operation == YANG_PATCH_OP_MERGE) {
- cbuf_append_str(api_path_target, target_val);
- cbuf_append_str(simple_patch_request_uri, target_val);
+ cbuf_append_str(api_path_target, target_val);
+ cbuf_append_str(simple_patch_request_uri, target_val);
}
if ((xtop = xml_new(NETCONF_INPUT_CONFIG, NULL, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
// Get key field
/* Translate api_path to xml in the form of xtop/xbot */
xbot = xtop;
if ((ret = api_path2xml(cbuf_get(api_path_target), yspec, xtop, YC_DATANODE, 1, &xbot, &ybot, &xerr)) < 0)
- goto done;
+ goto done;
if (ret == 0){ /* validation failed */
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
/* Get module name */
if (ys_real_module(ybot, &ymod) < 0)
- goto done;
+ goto done;
modname = yang_argument_get(ymod);
// XXX this seems to be hardcoded to a yang list?
if ((key_vec = xml_childvec_get(xbot)) != NULL)
- key_xn = key_vec[0];
+ key_xn = key_vec[0];
// Get values (for "delete" and "remove", there are no values)
xpath_vec(xn, NULL, "value", &vec, &veclen);
// Loop through the values
for (i = 0; i < veclen; i++) {
- if (yang_patch_do_value(h, req, pi, qvec, pretty, media_out, ds,
- vec[i], modname,
- operation, where_val, point_val, simple_patch_request_uri, target_val,
- api_path, key_xn) < 0)
- goto done;
+ if (yang_patch_do_value(h, req, pi, qvec, pretty, media_out, ds,
+ vec[i], modname,
+ operation, where_val, point_val, simple_patch_request_uri, target_val,
+ api_path, key_xn) < 0)
+ goto done;
}
if (operation == YANG_PATCH_OP_DELETE ||
- operation == YANG_PATCH_OP_REMOVE){
- cbuf_append_str(simple_patch_request_uri, target_val);
- if (operation == YANG_PATCH_OP_DELETE) {
- // TODO - send error
- } else {
- // TODO - do not send error
- }
- api_data_delete(h, req, cbuf_get(simple_patch_request_uri), pi, pretty, YANG_DATA_JSON, ds);
+ operation == YANG_PATCH_OP_REMOVE){
+ cbuf_append_str(simple_patch_request_uri, target_val);
+ if (operation == YANG_PATCH_OP_DELETE) {
+ // TODO - send error
+ } else {
+ // TODO - do not send error
+ }
+ api_data_delete(h, req, cbuf_get(simple_patch_request_uri), pi, pretty, YANG_DATA_JSON, ds);
}
ok:
retval = 0;
done:
if (vec)
- free(vec);
+ free(vec);
if (simple_patch_request_uri)
- cbuf_free(simple_patch_request_uri);
+ cbuf_free(simple_patch_request_uri);
if (api_path_target)
- cbuf_free(api_path_target);
+ cbuf_free(api_path_target);
if (xtop)
- xml_free(xtop);
+ xml_free(xtop);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
return retval;
}
@@ -744,15 +744,15 @@ yang_patch_do_edit(clicon_handle h,
*/
int
api_data_yang_patch(clicon_handle h,
- void *req,
- char *api_path0,
- int pi,
- cvec *qvec,
- char *data,
- int pretty,
- restconf_media media_in,
- restconf_media media_out,
- ietf_ds_t ds)
+ void *req,
+ char *api_path0,
+ int pi,
+ cvec *qvec,
+ char *data,
+ int pretty,
+ restconf_media media_in,
+ restconf_media media_out,
+ ietf_ds_t ds)
{
int retval = -1;
int i;
@@ -767,80 +767,80 @@ api_data_yang_patch(clicon_handle h,
clicon_debug(1, "%s api_path:\"%s\"", __FUNCTION__, api_path0);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
api_path=api_path0;
/* strip /... from start */
for (i=0; i",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_BASE_PREFIX,
- NETCONF_BASE_NAMESPACE,
- NETCONF_MESSAGE_ID_ATTR); /* bind nc to netconf namespace */
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_BASE_PREFIX,
+ NETCONF_BASE_NAMESPACE,
+ NETCONF_MESSAGE_ID_ATTR); /* bind nc to netconf namespace */
cprintf(cbx, " ");
cprintf(cbx, "none ");
if (clixon_xml2cbuf(cbx, xtop, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
cprintf(cbx, " ");
clicon_debug(1, "%s xml: %s api_path:%s",__FUNCTION__, cbuf_get(cbx), api_path);
if (clicon_rpc_netconf(h, cbuf_get(cbx), &xret, NULL) < 0)
- goto done;
+ goto done;
if ((xe = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
if (http_location_header(h, req, xdata) < 0)
- goto done;
+ goto done;
if (restconf_reply_send(req, 201, NULL, 0) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (xretcom)
- xml_free(xretcom);
+ xml_free(xretcom);
if (xretdis)
- xml_free(xretdis);
+ xml_free(xretdis);
if (xtop)
- xml_free(xtop);
+ xml_free(xtop);
if (cbx)
- cbuf_free(cbx);
+ cbuf_free(cbx);
return retval;
} /* api_data_post */
@@ -417,13 +417,13 @@ api_data_post(clicon_handle h,
*/
static int
api_operations_post_input(clicon_handle h,
- void *req,
- char *data,
- yang_stmt *yspec,
- yang_stmt *yrpc,
- cxobj *xrpc,
- int pretty,
- restconf_media media_out)
+ void *req,
+ char *data,
+ yang_stmt *yspec,
+ yang_stmt *yrpc,
+ cxobj *xrpc,
+ int pretty,
+ restconf_media media_out)
{
int retval = -1;
cxobj *xdata = NULL;
@@ -436,48 +436,48 @@ api_operations_post_input(clicon_handle h,
clicon_debug(1, "%s %s", __FUNCTION__, data);
if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, 0, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, 0, "cbuf_new");
+ goto done;
}
/* Parse input data as json or xml into xml */
media_in = restconf_content_type(h);
switch (media_in){
case YANG_DATA_XML:
- /* XXX: Here data is on the form: and has no proper yang binding
- * support */
- if ((ret = clixon_xml_parse_string(data, YB_NONE, yspec, &xdata, &xerr)) < 0){
- if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto fail;
- }
- if (ret == 0){
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto fail;
- }
- break;
+ /* XXX: Here data is on the form: and has no proper yang binding
+ * support */
+ if ((ret = clixon_xml_parse_string(data, YB_NONE, yspec, &xdata, &xerr)) < 0){
+ if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto fail;
+ }
+ if (ret == 0){
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto fail;
+ }
+ break;
case YANG_DATA_JSON:
- /* XXX: Here data is on the form: {"clixon-example:input":null} and has no proper yang binding
- * support */
- if ((ret = clixon_json_parse_string(data, 1, YB_NONE, yspec, &xdata, &xerr)) < 0){
- if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto fail;
- }
- if (ret == 0){
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto fail;
- }
- break;
+ /* XXX: Here data is on the form: {"clixon-example:input":null} and has no proper yang binding
+ * support */
+ if ((ret = clixon_json_parse_string(data, 1, YB_NONE, yspec, &xdata, &xerr)) < 0){
+ if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto fail;
+ }
+ if (ret == 0){
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto fail;
+ }
+ break;
default:
- restconf_unsupported_media(h, req, pretty, media_out);
- goto fail;
- break;
+ restconf_unsupported_media(h, req, pretty, media_out);
+ goto fail;
+ break;
} /* switch media_in */
xml_name_set(xdata, NETCONF_OUTPUT_DATA);
/* Here xdata is:
@@ -485,30 +485,30 @@ api_operations_post_input(clicon_handle h,
*/
#if 1
if (clicon_debug_get())
- clicon_log_xml(LOG_DEBUG, xdata, "%s xdata:", __FUNCTION__);
+ clicon_log_xml(LOG_DEBUG, xdata, "%s xdata:", __FUNCTION__);
#endif
/* Validate that exactly only tag */
if ((xinput = xml_child_i_type(xdata, 0, CX_ELMNT)) == NULL ||
- strcmp(xml_name(xinput),"input") != 0 ||
- xml_child_nr_type(xdata, CX_ELMNT) != 1){
+ strcmp(xml_name(xinput),"input") != 0 ||
+ xml_child_nr_type(xdata, CX_ELMNT) != 1){
- if (xml_child_nr_type(xdata, CX_ELMNT) == 0){
- if (netconf_malformed_message_xml(&xerr, "restconf RPC does not have input statement") < 0)
- goto done;
- }
- else
- if (netconf_malformed_message_xml(&xerr, "restconf RPC has malformed input statement (multiple or not called input)") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto fail;
+ if (xml_child_nr_type(xdata, CX_ELMNT) == 0){
+ if (netconf_malformed_message_xml(&xerr, "restconf RPC does not have input statement") < 0)
+ goto done;
+ }
+ else
+ if (netconf_malformed_message_xml(&xerr, "restconf RPC has malformed input statement (multiple or not called input)") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto fail;
}
// clicon_debug(1, "%s input validation passed", __FUNCTION__);
/* Add all input under path */
x = NULL;
while ((x = xml_child_i_type(xinput, 0, CX_ELMNT)) != NULL)
- if (xml_addsub(xrpc, x) < 0)
- goto done;
+ if (xml_addsub(xrpc, x) < 0)
+ goto done;
/* Here xrpc is: 42
*/
// ok:
@@ -516,11 +516,11 @@ api_operations_post_input(clicon_handle h,
done:
clicon_debug(1, "%s retval: %d", __FUNCTION__, retval);
if (cbret)
- cbuf_free(cbret);
+ cbuf_free(cbret);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (xdata)
- xml_free(xdata);
+ xml_free(xdata);
return retval;
fail:
retval = 0;
@@ -543,14 +543,14 @@ api_operations_post_input(clicon_handle h,
*/
static int
api_operations_post_output(clicon_handle h,
- void *req,
- cxobj *xret,
- yang_stmt *yspec,
- yang_stmt *youtput,
- char *namespace,
- int pretty,
- restconf_media media_out,
- cxobj **xoutputp)
+ void *req,
+ cxobj *xret,
+ yang_stmt *yspec,
+ yang_stmt *youtput,
+ char *namespace,
+ int pretty,
+ restconf_media media_out,
+ cxobj **xoutputp)
{
int retval = -1;
@@ -564,18 +564,18 @@ api_operations_post_output(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
/* Validate that exactly only tag with exactly one element child */
if ((xoutput = xml_child_i_type(xret, 0, CX_ELMNT)) == NULL ||
- strcmp(xml_name(xoutput),"rpc-reply") != 0
- /* See https://github.com/clicon/clixon/issues/158
- * This is an internal error, they should not be double but the error should not be detected
- * here, it should be detected in the backend plugin caller.
- || xml_child_nr_type(xrpc, CX_ELMNT) != 1 XXX backend can have multiple callbacks
- */
- ){
- if (netconf_malformed_message_xml(&xerr, "restconf RPC does not have single input") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto fail;
+ strcmp(xml_name(xoutput),"rpc-reply") != 0
+ /* See https://github.com/clicon/clixon/issues/158
+ * This is an internal error, they should not be double but the error should not be detected
+ * here, it should be detected in the backend plugin caller.
+ || xml_child_nr_type(xrpc, CX_ELMNT) != 1 XXX backend can have multiple callbacks
+ */
+ ){
+ if (netconf_malformed_message_xml(&xerr, "restconf RPC does not have single input") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto fail;
}
/* xoutput should now look: 0 */
/* 9. Translate to restconf RPC data */
@@ -583,12 +583,12 @@ api_operations_post_output(clicon_handle h,
/* xoutput should now look: 0 */
#if 1
if (clicon_debug_get())
- clicon_log_xml(LOG_DEBUG, xoutput, "%s xoutput:", __FUNCTION__);
+ clicon_log_xml(LOG_DEBUG, xoutput, "%s xoutput:", __FUNCTION__);
#endif
/* Remove original netconf default namespace. Somewhat unsure what "output" belongs to? */
if ((xa = xml_find_type(xoutput, NULL, "xmlns", CX_ATTR)) != NULL)
- if (xml_purge(xa) < 0)
- goto done;
+ if (xml_purge(xa) < 0)
+ goto done;
/* Sanity check of outgoing XML
* For now, skip outgoing checks.
@@ -596,20 +596,20 @@ api_operations_post_output(clicon_handle h,
* (2) Uncertain how validation errors should be logged/handled
*/
if (youtput != NULL){
- xml_spec_set(xoutput, youtput); /* needed for xml_bind_yang */
+ xml_spec_set(xoutput, youtput); /* needed for xml_bind_yang */
#ifdef notyet
- if ((ret = xml_bind_yang(xoutput, YB_MODULE, yspec, &xerr)) < 0)
- goto done;
- if (ret > 0 && (ret = xml_yang_validate_all(xoutput, &xerr)) < 0)
- goto done;
- if (ret == 1 &&
- (ret = xml_yang_validate_add(h, xoutput, &xerr)) < 0)
- goto done;
- if (ret == 0){ /* validation failed */
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto fail;
- }
+ if ((ret = xml_bind_yang(xoutput, YB_MODULE, yspec, &xerr)) < 0)
+ goto done;
+ if (ret > 0 && (ret = xml_yang_validate_all(xoutput, &xerr)) < 0)
+ goto done;
+ if (ret == 1 &&
+ (ret = xml_yang_validate_add(h, xoutput, &xerr)) < 0)
+ goto done;
+ if (ret == 0){ /* validation failed */
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto fail;
+ }
#endif
}
/* Special case, no yang output (single - or empty body?)
@@ -622,31 +622,31 @@ api_operations_post_output(clicon_handle h,
* status-line instead.
*/
isempty = xml_child_nr_type(xoutput, CX_ELMNT) == 0 ||
- (xml_child_nr_type(xoutput, CX_ELMNT) == 1 &&
- (xok = xml_child_i_type(xoutput, 0, CX_ELMNT)) != NULL &&
- strcmp(xml_name(xok),"ok")==0);
+ (xml_child_nr_type(xoutput, CX_ELMNT) == 1 &&
+ (xok = xml_child_i_type(xoutput, 0, CX_ELMNT)) != NULL &&
+ strcmp(xml_name(xok),"ok")==0);
if (isempty) {
- /* Internal error - invalid output from rpc handler */
- if (restconf_reply_send(req, 204, NULL, 0) < 0)
- goto done;
- goto fail;
+ /* Internal error - invalid output from rpc handler */
+ if (restconf_reply_send(req, 204, NULL, 0) < 0)
+ goto done;
+ goto fail;
}
/* Clear namespace of parameters */
x = NULL;
while ((x = xml_child_each(xoutput, x, CX_ELMNT)) != NULL) {
- if ((xa = xml_find_type(x, NULL, "xmlns", CX_ATTR)) != NULL)
- if (xml_purge(xa) < 0)
- goto done;
+ if ((xa = xml_find_type(x, NULL, "xmlns", CX_ATTR)) != NULL)
+ if (xml_purge(xa) < 0)
+ goto done;
}
/* Set namespace on output */
if (xmlns_set(xoutput, NULL, namespace) < 0)
- goto done;
+ goto done;
*xoutputp = xoutput;
retval = 1;
done:
clicon_debug(1, "%s retval: %d", __FUNCTION__, retval);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
return retval;
fail:
retval = 0;
@@ -684,13 +684,13 @@ api_operations_post_output(clicon_handle h,
*/
int
api_operations_post(clicon_handle h,
- void *req,
- char *api_path,
- int pi,
- cvec *qvec,
- char *data,
- int pretty,
- restconf_media media_out)
+ void *req,
+ char *api_path,
+ int pi,
+ cvec *qvec,
+ char *data,
+ int pretty,
+ restconf_media media_out)
{
int retval = -1;
int i;
@@ -717,21 +717,21 @@ api_operations_post(clicon_handle h,
clicon_debug(1, "%s json:\"%s\" path:\"%s\"", __FUNCTION__, data, api_path);
/* 1. Initialize */
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, 0, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, 0, "cbuf_new");
+ goto done;
}
for (i=0; i
@@ -740,42 +740,42 @@ api_operations_post(clicon_handle h,
* string for the desired operation.
*/
if (nodeid_split(oppath+1, &prefix, &id) < 0) /* +1 skip / */
- goto done;
+ goto done;
if ((ys = yang_find(yspec, Y_MODULE, prefix)) == NULL){
- if (netconf_operation_failed_xml(&xerr, "protocol", "yang module not found") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (netconf_operation_failed_xml(&xerr, "protocol", "yang module not found") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
if ((yrpc = yang_find(ys, Y_RPC, id)) == NULL){
- if (netconf_missing_element_xml(&xerr, "application", id, "RPC not defined") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (netconf_missing_element_xml(&xerr, "application", id, "RPC not defined") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
/* 3. Build xml tree with user and rpc:
*
*/
if ((username = clicon_username_get(h)) != NULL){
- if (clixon_xml_parse_va(YB_NONE, NULL, &xtop, NULL, " ",
- NETCONF_BASE_NAMESPACE, username, NETCONF_MESSAGE_ID_ATTR) < 0)
- goto done;
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xtop, NULL, " ",
+ NETCONF_BASE_NAMESPACE, username, NETCONF_MESSAGE_ID_ATTR) < 0)
+ goto done;
}
else
- if (clixon_xml_parse_va(YB_NONE, NULL, &xtop, NULL, " ",
- NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR) < 0)
- goto done;
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xtop, NULL, " ",
+ NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR) < 0)
+ goto done;
if (xml_rootchild(xtop, 0, &xtop) < 0)
- goto done;
+ goto done;
xbot = xtop;
if ((ret = api_path2xml(oppath, yspec, xtop, YC_SCHEMANODE, 1, &xbot, &y, &xerr)) < 0)
- goto done;
+ goto done;
if (ret == 0){ /* validation failed */
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
/* Here xtop is:
* xbot is
@@ -786,39 +786,39 @@ api_operations_post(clicon_handle h,
namespace = xml_find_type_value(xbot, NULL, "xmlns", CX_ATTR);
clicon_debug(1, "%s : 4. Parse input data: %s", __FUNCTION__, data);
if (data && strlen(data)){
- if ((ret = api_operations_post_input(h, req, data, yspec, yrpc, xbot,
- pretty, media_out)) < 0)
- goto done;
- if (ret == 0)
- goto ok;
+ if ((ret = api_operations_post_input(h, req, data, yspec, yrpc, xbot,
+ pretty, media_out)) < 0)
+ goto done;
+ if (ret == 0)
+ goto ok;
}
/* Here xtop is:
42 */
#if 1
if (clicon_debug_get())
- clicon_log_xml(LOG_DEBUG, xtop, "%s 5. Translate input args:", __FUNCTION__);
+ clicon_log_xml(LOG_DEBUG, xtop, "%s 5. Translate input args:", __FUNCTION__);
#endif
/* 6. Validate outgoing RPC and fill in defaults */
if ((ret = xml_bind_yang_rpc(xtop, yspec, &xerr)) < 0) /* */
- goto done;
+ goto done;
if (ret == 0){
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
if ((ret = xml_yang_validate_rpc(h, xtop, &xerr)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
/* Here xtop is (default values):
* 42 99
*/
#if 0
if (clicon_debug_get())
- clicon_log_xml(LOG_DEBUG, xtop, "%s 6. Validate and defaults:", __FUNCTION__);
+ clicon_log_xml(LOG_DEBUG, xtop, "%s 6. Validate and defaults:", __FUNCTION__);
#endif
/* 7. Send to RPC handler, either local or backend
* Note (1) xtop is xbot is
@@ -828,82 +828,82 @@ api_operations_post(clicon_handle h,
* -1:Error, 0:OK local, 1:OK backend
*/
if ((ret = rpc_callback_call(h, xbot, req, &nr, cbret)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, &xe, NULL) < 0)
- goto done;
- if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, &xe, NULL) < 0)
+ goto done;
+ if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
else if (nr > 0){ /* Handled locally */
- if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, &xret, NULL) < 0)
- goto done;
- /* Local error: return it and quit */
- if ((xe = xpath_first(xret, NULL, "rpc-reply/rpc-error")) != NULL){
- if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
- }
+ if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, &xret, NULL) < 0)
+ goto done;
+ /* Local error: return it and quit */
+ if ((xe = xpath_first(xret, NULL, "rpc-reply/rpc-error")) != NULL){
+ if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
}
else { /* Send to backend */
- if (clicon_rpc_netconf_xml(h, xtop, &xret, NULL) < 0)
- goto done;
- if ((xe = xpath_first(xret, NULL, "rpc-reply/rpc-error")) != NULL){
- if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
- }
+ if (clicon_rpc_netconf_xml(h, xtop, &xret, NULL) < 0)
+ goto done;
+ if ((xe = xpath_first(xret, NULL, "rpc-reply/rpc-error")) != NULL){
+ if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
}
/* 8. Receive reply from local/backend handler as Netconf RPC
* 0
*/
#if 1
if (clicon_debug_get())
- clicon_log_xml(LOG_DEBUG, xret, "%s Receive reply:", __FUNCTION__);
+ clicon_log_xml(LOG_DEBUG, xret, "%s Receive reply:", __FUNCTION__);
#endif
youtput = yang_find(yrpc, Y_OUTPUT, NULL);
if ((ret = api_operations_post_output(h, req, xret, yspec, youtput, namespace,
- pretty, media_out, &xoutput)) < 0)
- goto done;
+ pretty, media_out, &xoutput)) < 0)
+ goto done;
if (ret == 0)
- goto ok;
+ goto ok;
/* xoutput should now look: 0 */
if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0)
- goto done;
+ goto done;
cbuf_reset(cbret);
switch (media_out){
case YANG_DATA_XML:
- if (clixon_xml2cbuf(cbret, xoutput, 0, pretty, -1, 0) < 0)
- goto done;
- /* xoutput should now look: 0 */
- break;
+ if (clixon_xml2cbuf(cbret, xoutput, 0, pretty, -1, 0) < 0)
+ goto done;
+ /* xoutput should now look: 0 */
+ break;
case YANG_DATA_JSON:
- if (clixon_json2cbuf(cbret, xoutput, pretty, 0, 0) < 0)
- goto done;
- /* xoutput should now look: {"example:output": {"x":0,"y":42}} */
- break;
+ if (clixon_json2cbuf(cbret, xoutput, pretty, 0, 0) < 0)
+ goto done;
+ /* xoutput should now look: {"example:output": {"x":0,"y":42}} */
+ break;
default:
- break;
+ break;
}
if (restconf_reply_send(req, 200, cbret, 0) < 0)
- goto done;
+ goto done;
cbret = NULL;
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (prefix)
- free(prefix);
+ free(prefix);
if (id)
- free(id);
+ free(id);
if (xtop)
- xml_free(xtop);
+ xml_free(xtop);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (cbret)
- cbuf_free(cbret);
+ cbuf_free(cbret);
return retval;
}
diff --git a/apps/restconf/restconf_methods_post.h b/apps/restconf/restconf_methods_post.h
index 05116bd2..5c61fd44 100644
--- a/apps/restconf/restconf_methods_post.h
+++ b/apps/restconf/restconf_methods_post.h
@@ -42,13 +42,13 @@
* Prototypes
*/
int api_data_post(clicon_handle h, void *req, char *api_path,
- int pi, cvec *qvec, char *data,
- int pretty,
- restconf_media media_in,
- restconf_media media_out, ietf_ds_t ds);
+ int pi, cvec *qvec, char *data,
+ int pretty,
+ restconf_media media_in,
+ restconf_media media_out, ietf_ds_t ds);
int api_operations_post(clicon_handle h, void *req, char *api_path,
- int pi, cvec *qvec, char *data,
- int pretty, restconf_media media_out);
+ int pi, cvec *qvec, char *data,
+ int pretty, restconf_media media_out);
#endif /* _RESTCONF_METHODS_POST_H_ */
diff --git a/apps/restconf/restconf_native.c b/apps/restconf/restconf_native.c
index d3d788e2..2c8e05cf 100644
--- a/apps/restconf/restconf_native.c
+++ b/apps/restconf/restconf_native.c
@@ -86,32 +86,32 @@ static int restconf_idle_cb(int fd, void *arg);
*/
restconf_stream_data *
restconf_stream_data_new(restconf_conn *rc,
- int32_t stream_id)
+ int32_t stream_id)
{
restconf_stream_data *sd;
if ((sd = malloc(sizeof(restconf_stream_data))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- return NULL;
+ clicon_err(OE_UNIX, errno, "malloc");
+ return NULL;
}
memset(sd, 0, sizeof(restconf_stream_data));
sd->sd_stream_id = stream_id;
sd->sd_fd = -1;
if ((sd->sd_inbuf = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- return NULL;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ return NULL;
}
if ((sd->sd_indata = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- return NULL;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ return NULL;
}
if ((sd->sd_outp_hdrs = cvec_new(0)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_new");
- return NULL;
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ return NULL;
}
if ((sd->sd_outp_buf = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- return NULL;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ return NULL;
}
sd->sd_conn = rc;
INSQ(sd, rc->rc_streams);
@@ -123,16 +123,16 @@ restconf_stream_data_new(restconf_conn *rc,
*/
restconf_stream_data *
restconf_stream_find(restconf_conn *rc,
- int32_t id)
+ int32_t id)
{
restconf_stream_data *sd;
if ((sd = rc->rc_streams) != NULL) {
- do {
- if (sd->sd_stream_id == id)
- return sd;
- sd = NEXTQ(restconf_stream_data *, sd);
- } while (sd && sd != rc->rc_streams);
+ do {
+ if (sd->sd_stream_id == id)
+ return sd;
+ sd = NEXTQ(restconf_stream_data *, sd);
+ } while (sd && sd != rc->rc_streams);
}
return NULL;
}
@@ -144,24 +144,24 @@ int
restconf_stream_free(restconf_stream_data *sd)
{
if (sd->sd_fd != -1) {
- close(sd->sd_fd);
+ close(sd->sd_fd);
}
if (sd->sd_inbuf)
- cbuf_free(sd->sd_inbuf);
+ cbuf_free(sd->sd_inbuf);
if (sd->sd_indata)
- cbuf_free(sd->sd_indata);
+ cbuf_free(sd->sd_indata);
if (sd->sd_outp_hdrs)
- cvec_free(sd->sd_outp_hdrs);
+ cvec_free(sd->sd_outp_hdrs);
if (sd->sd_outp_buf)
- cbuf_free(sd->sd_outp_buf);
+ cbuf_free(sd->sd_outp_buf);
if (sd->sd_body)
- cbuf_free(sd->sd_body);
+ cbuf_free(sd->sd_body);
if (sd->sd_path)
- free(sd->sd_path);
+ free(sd->sd_path);
if (sd->sd_settings2)
- free(sd->sd_settings2);
+ free(sd->sd_settings2);
if (sd->sd_qvec)
- cvec_free(sd->sd_qvec);
+ cvec_free(sd->sd_qvec);
free(sd);
return 0;
}
@@ -175,14 +175,14 @@ restconf_stream_free(restconf_stream_data *sd)
*/
restconf_conn *
restconf_conn_new(clicon_handle h,
- int s,
- restconf_socket *rsock)
+ int s,
+ restconf_socket *rsock)
{
restconf_conn *rc;
if ((rc = (restconf_conn*)malloc(sizeof(restconf_conn))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- return NULL;
+ clicon_err(OE_UNIX, errno, "malloc");
+ return NULL;
}
memset(rc, 0, sizeof(restconf_conn));
rc->rc_h = h;
@@ -207,30 +207,30 @@ restconf_conn_free(restconf_conn *rc)
clicon_debug(1, "%s", __FUNCTION__);
if (rc == NULL){
- clicon_err(OE_RESTCONF, EINVAL, "rc is NULL");
- goto done;
+ clicon_err(OE_RESTCONF, EINVAL, "rc is NULL");
+ goto done;
}
clicon_debug(1, "%s %p", __FUNCTION__, rc);
#ifdef HAVE_LIBNGHTTP2
if (rc->rc_ngsession)
- nghttp2_session_del(rc->rc_ngsession);
+ nghttp2_session_del(rc->rc_ngsession);
#endif
/* Free all streams */
while ((sd = rc->rc_streams) != NULL) {
- DELQ(sd, rc->rc_streams, restconf_stream_data *);
- if (sd)
- restconf_stream_free(sd);
+ DELQ(sd, rc->rc_streams, restconf_stream_data *);
+ if (sd)
+ restconf_stream_free(sd);
}
/* Free connect from server sock */
if ((rsock = rc->rc_socket) != NULL &&
- (rc1 = rsock->rs_conns) != NULL){
- do {
- if (rc == rc1){
- DELQ(rc, rsock->rs_conns, restconf_conn *);
- break;
- }
- rc1 = NEXTQ(restconf_conn *, rc1);
- } while (rc1 && rc1 != rsock->rs_conns);
+ (rc1 = rsock->rs_conns) != NULL){
+ do {
+ if (rc == rc1){
+ DELQ(rc, rsock->rs_conns, restconf_conn *);
+ break;
+ }
+ rc1 = NEXTQ(restconf_conn *, rc1);
+ } while (rc1 && rc1 != rsock->rs_conns);
}
free(rc);
retval = 0;
@@ -244,7 +244,7 @@ restconf_conn_free(restconf_conn *rc)
*/
int
ssl_x509_name_oneline(SSL *ssl,
- char **oneline)
+ char **oneline)
{
int retval = -1;
char *p = NULL;
@@ -252,26 +252,26 @@ ssl_x509_name_oneline(SSL *ssl,
X509_NAME *name;
if (ssl == NULL || oneline == NULL) {
- clicon_err(OE_RESTCONF, EINVAL, "ssl or cn is NULL");
- goto done;
+ clicon_err(OE_RESTCONF, EINVAL, "ssl or cn is NULL");
+ goto done;
}
if ((cert = SSL_get_peer_certificate(ssl)) == NULL)
- goto ok;
+ goto ok;
if ((name = X509_get_subject_name(cert)) == NULL)
- goto ok;
+ goto ok;
if ((p = X509_NAME_oneline(name, NULL, 0)) == NULL)
- goto ok;
+ goto ok;
if ((*oneline = strdup(p)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
ok:
retval = 0;
done:
if (p)
- OPENSSL_free(p);
+ OPENSSL_free(p);
if (cert)
- X509_free(cert);
+ X509_free(cert);
return retval;
}
@@ -294,8 +294,8 @@ ssl_x509_name_oneline(SSL *ssl,
*/
int
restconf_connection_sanity(clicon_handle h,
- restconf_conn *rc,
- restconf_stream_data *sd)
+ restconf_conn *rc,
+ restconf_stream_data *sd)
{
int retval = -1;
cxobj *xerr = NULL;
@@ -307,59 +307,59 @@ restconf_connection_sanity(clicon_handle h,
/* 1) Check if http/2 non-tls is disabled */
if (rc->rc_ssl == NULL &&
- rc->rc_proto == HTTP_2 &&
- clicon_option_bool(h, "CLICON_RESTCONF_HTTP2_PLAIN") == 0){
- if (netconf_invalid_value_xml(&xerr, "protocol", "Only HTTP/2 with TLS is enabled, plain http/2 is disabled") < 0)
- goto done;
- if ((media_str = restconf_param_get(h, "HTTP_ACCEPT")) == NULL){
- media_out = YANG_DATA_JSON;
- }
- else if ((int)(media_out = restconf_media_str2int(media_str)) == -1){
- if (strcmp(media_str, "*/*") == 0) /* catch-all */
- media_out = YANG_DATA_JSON;
- }
- if (api_return_err0(h, sd, xerr, 1, media_out, 0) < 0)
- goto done;
- rc->rc_exit = 1;
+ rc->rc_proto == HTTP_2 &&
+ clicon_option_bool(h, "CLICON_RESTCONF_HTTP2_PLAIN") == 0){
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Only HTTP/2 with TLS is enabled, plain http/2 is disabled") < 0)
+ goto done;
+ if ((media_str = restconf_param_get(h, "HTTP_ACCEPT")) == NULL){
+ media_out = YANG_DATA_JSON;
+ }
+ else if ((int)(media_out = restconf_media_str2int(media_str)) == -1){
+ if (strcmp(media_str, "*/*") == 0) /* catch-all */
+ media_out = YANG_DATA_JSON;
+ }
+ if (api_return_err0(h, sd, xerr, 1, media_out, 0) < 0)
+ goto done;
+ rc->rc_exit = 1;
}
/* 2) Check if ssl client cert is valid */
else if (rc->rc_ssl != NULL &&
- (code = SSL_get_verify_result(rc->rc_ssl)) != 0){
- /* Syslog cert failure */
- if (ssl_x509_name_oneline(rc->rc_ssl, &oneline) < 0)
- goto done;
- if (oneline)
- clicon_log(LOG_NOTICE, "Cert error: %s: %s", oneline, X509_verify_cert_error_string(code));
- else
- clicon_log(LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(code));
- /* Send return error message */
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cberr, "HTTP cert verification failed: %s[%ld]",
- X509_verify_cert_error_string(code), code);
- if (netconf_invalid_value_xml(&xerr, "protocol", cbuf_get(cberr)) < 0)
- goto done;
- if ((media_str = restconf_param_get(h, "HTTP_ACCEPT")) == NULL){
- media_out = YANG_DATA_JSON;
- }
- else if ((int)(media_out = restconf_media_str2int(media_str)) == -1){
- if (strcmp(media_str, "*/*") == 0) /* catch-all */
- media_out = YANG_DATA_JSON;
- }
- if (api_return_err0(sd->sd_conn->rc_h, sd, xerr, 1, media_out, 0) < 0)
- goto done;
- rc->rc_exit = 1;
+ (code = SSL_get_verify_result(rc->rc_ssl)) != 0){
+ /* Syslog cert failure */
+ if (ssl_x509_name_oneline(rc->rc_ssl, &oneline) < 0)
+ goto done;
+ if (oneline)
+ clicon_log(LOG_NOTICE, "Cert error: %s: %s", oneline, X509_verify_cert_error_string(code));
+ else
+ clicon_log(LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(code));
+ /* Send return error message */
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cberr, "HTTP cert verification failed: %s[%ld]",
+ X509_verify_cert_error_string(code), code);
+ if (netconf_invalid_value_xml(&xerr, "protocol", cbuf_get(cberr)) < 0)
+ goto done;
+ if ((media_str = restconf_param_get(h, "HTTP_ACCEPT")) == NULL){
+ media_out = YANG_DATA_JSON;
+ }
+ else if ((int)(media_out = restconf_media_str2int(media_str)) == -1){
+ if (strcmp(media_str, "*/*") == 0) /* catch-all */
+ media_out = YANG_DATA_JSON;
+ }
+ if (api_return_err0(sd->sd_conn->rc_h, sd, xerr, 1, media_out, 0) < 0)
+ goto done;
+ rc->rc_exit = 1;
}
retval = 0;
done:
if (oneline)
- free(oneline);
+ free(oneline);
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
return retval;
}
@@ -376,10 +376,10 @@ restconf_connection_sanity(clicon_handle h,
*/
static int
native_buf_write(clicon_handle h,
- char *buf,
- size_t buflen,
- restconf_conn *rc,
- const char *callfn)
+ char *buf,
+ size_t buflen,
+ restconf_conn *rc,
+ const char *callfn)
{
int retval = -1;
ssize_t len;
@@ -388,8 +388,8 @@ native_buf_write(clicon_handle h,
SSL *ssl;
if (rc == NULL){
- clicon_err(OE_RESTCONF, EINVAL, "rc is NULL");
- goto done;
+ clicon_err(OE_RESTCONF, EINVAL, "rc is NULL");
+ goto done;
}
ssl = rc->rc_ssl;
/* Two problems with debugging buffers that this fixes:
@@ -397,67 +397,67 @@ native_buf_write(clicon_handle h,
* 2. they are often very long
*/
if (clicon_debug_get()) {
- char *dbgstr = NULL;
- size_t sz;
- sz = buflen>256?256:buflen; /* Truncate to 256 */
- if ((dbgstr = malloc(sz+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
- }
- memcpy(dbgstr, buf, sz);
- dbgstr[sz] = '\0';
- clicon_debug(1, "%s %s buflen:%zu buf:\n%s", __FUNCTION__, callfn, buflen, dbgstr);
- free(dbgstr);
+ char *dbgstr = NULL;
+ size_t sz;
+ sz = buflen>256?256:buflen; /* Truncate to 256 */
+ if ((dbgstr = malloc(sz+1)) == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
+ }
+ memcpy(dbgstr, buf, sz);
+ dbgstr[sz] = '\0';
+ clicon_debug(1, "%s %s buflen:%zu buf:\n%s", __FUNCTION__, callfn, buflen, dbgstr);
+ free(dbgstr);
}
while (totlen < buflen){
- if (ssl){
- if ((len = SSL_write(ssl, buf+totlen, buflen-totlen)) <= 0){
- er = errno;
- switch (SSL_get_error(ssl, len)){
- case SSL_ERROR_SYSCALL: /* 5 */
- if (er == ECONNRESET || /* Connection reset by peer */
- er == EPIPE) { /* Reading end of socket is closed */
- goto closed; /* Close socket and ssl */
- }
- else if (er == EAGAIN){
- clicon_debug(1, "%s write EAGAIN", __FUNCTION__);
- usleep(10000);
- continue;
- }
- else{
- clicon_err(OE_RESTCONF, er, "SSL_write %d", er);
- goto done;
- }
- break;
- default:
- clicon_err(OE_SSL, 0, "SSL_write");
- goto done;
- break;
- }
- goto done;
- }
- }
- else{
- if ((len = write(rc->rc_s, buf+totlen, buflen-totlen)) < 0){
- switch (errno){
- case EAGAIN: /* Operation would block */
- clicon_debug(1, "%s write EAGAIN", __FUNCTION__);
- usleep(10000);
- continue;
- break;
- // case EBADF: // XXX if this happens there is some larger error
- case ECONNRESET: /* Connection reset by peer */
- case EPIPE: /* Broken pipe */
- goto closed; /* Close socket and ssl */
- break;
- default:
- clicon_err(OE_UNIX, errno, "write %d", errno);
- goto done;
- break;
- }
- }
- }
- totlen += len;
+ if (ssl){
+ if ((len = SSL_write(ssl, buf+totlen, buflen-totlen)) <= 0){
+ er = errno;
+ switch (SSL_get_error(ssl, len)){
+ case SSL_ERROR_SYSCALL: /* 5 */
+ if (er == ECONNRESET || /* Connection reset by peer */
+ er == EPIPE) { /* Reading end of socket is closed */
+ goto closed; /* Close socket and ssl */
+ }
+ else if (er == EAGAIN){
+ clicon_debug(1, "%s write EAGAIN", __FUNCTION__);
+ usleep(10000);
+ continue;
+ }
+ else{
+ clicon_err(OE_RESTCONF, er, "SSL_write %d", er);
+ goto done;
+ }
+ break;
+ default:
+ clicon_err(OE_SSL, 0, "SSL_write");
+ goto done;
+ break;
+ }
+ goto done;
+ }
+ }
+ else{
+ if ((len = write(rc->rc_s, buf+totlen, buflen-totlen)) < 0){
+ switch (errno){
+ case EAGAIN: /* Operation would block */
+ clicon_debug(1, "%s write EAGAIN", __FUNCTION__);
+ usleep(10000);
+ continue;
+ break;
+ // case EBADF: // XXX if this happens there is some larger error
+ case ECONNRESET: /* Connection reset by peer */
+ case EPIPE: /* Broken pipe */
+ goto closed; /* Close socket and ssl */
+ break;
+ default:
+ clicon_err(OE_UNIX, errno, "write %d", errno);
+ goto done;
+ break;
+ }
+ }
+ }
+ totlen += len;
} /* while */
retval = 1;
done:
@@ -480,32 +480,32 @@ native_buf_write(clicon_handle h,
*/
static int
native_send_badrequest(clicon_handle h,
- char *media,
- char *body,
- restconf_conn *rc)
+ char *media,
+ char *body,
+ restconf_conn *rc)
{
int retval = -1;
cbuf *cb = NULL;
clicon_debug(1, "%s", __FUNCTION__);
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
cprintf(cb, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n");
if (body){
- cprintf(cb, "Content-Type: %s\r\n", media);
- cprintf(cb, "Content-Length: %zu\r\n", strlen(body)+2); /* for \r\n */
+ cprintf(cb, "Content-Type: %s\r\n", media);
+ cprintf(cb, "Content-Length: %zu\r\n", strlen(body)+2); /* for \r\n */
}
else
- cprintf(cb, "Content-Length: 0\r\n");
+ cprintf(cb, "Content-Length: 0\r\n");
cprintf(cb, "\r\n");
if (body)
- cprintf(cb, "%s\r\n", body);
+ cprintf(cb, "%s\r\n", body);
retval = native_buf_write(h, cbuf_get(cb), cbuf_len(cb), rc, __FUNCTION__);
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -520,17 +520,17 @@ native_send_badrequest(clicon_handle h,
*/
static int
http1_native_clear_input(clicon_handle h,
- restconf_stream_data *sd)
+ restconf_stream_data *sd)
{
int retval = -1;
cbuf_reset(sd->sd_indata);
if (sd->sd_qvec){
- cvec_free(sd->sd_qvec);
- sd->sd_qvec = NULL;
+ cvec_free(sd->sd_qvec);
+ sd->sd_qvec = NULL;
}
if (restconf_param_del_all(h) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -549,36 +549,36 @@ http1_native_clear_input(clicon_handle h,
*/
static int
read_ssl(restconf_conn *rc,
- char *buf,
- size_t sz,
- ssize_t *np,
- int *again)
+ char *buf,
+ size_t sz,
+ ssize_t *np,
+ int *again)
{
int retval = -1;
int sslerr;
if ((*np = SSL_read(rc->rc_ssl, buf, sz)) <= 0){
- sslerr = SSL_get_error(rc->rc_ssl, *np);
- clicon_debug(1, "%s SSL_read() n:%zd errno:%d sslerr:%d", __FUNCTION__, *np, errno, sslerr);
- switch (sslerr){
- case SSL_ERROR_WANT_READ: /* 2 */
- /* SSL_ERROR_WANT_READ is returned when the last operation was a read operation
- * from a nonblocking BIO.
- * That is, it can happen if restconf_socket_init() below is called
- * with SOCK_NONBLOCK
- */
- clicon_debug(1, "%s SSL_read SSL_ERROR_WANT_READ", __FUNCTION__);
- usleep(1000);
- *again = 1;
- break;
- case SSL_ERROR_ZERO_RETURN:
- *np = 0; /* should already be zero */
- break;
- default:
- clicon_log(LOG_WARNING, "%s SSL_read(): %s sslerr:%d", __FUNCTION__, strerror(errno), sslerr);
- *np = 0;
- break;
- } /* switch */
+ sslerr = SSL_get_error(rc->rc_ssl, *np);
+ clicon_debug(1, "%s SSL_read() n:%zd errno:%d sslerr:%d", __FUNCTION__, *np, errno, sslerr);
+ switch (sslerr){
+ case SSL_ERROR_WANT_READ: /* 2 */
+ /* SSL_ERROR_WANT_READ is returned when the last operation was a read operation
+ * from a nonblocking BIO.
+ * That is, it can happen if restconf_socket_init() below is called
+ * with SOCK_NONBLOCK
+ */
+ clicon_debug(1, "%s SSL_read SSL_ERROR_WANT_READ", __FUNCTION__);
+ usleep(1000);
+ *again = 1;
+ break;
+ case SSL_ERROR_ZERO_RETURN:
+ *np = 0; /* should already be zero */
+ break;
+ default:
+ clicon_log(LOG_WARNING, "%s SSL_read(): %s sslerr:%d", __FUNCTION__, strerror(errno), sslerr);
+ *np = 0;
+ break;
+ } /* switch */
}
retval = 0;
// done:
@@ -602,32 +602,32 @@ read_ssl(restconf_conn *rc,
*/
static int
read_regular(restconf_conn *rc,
- char *buf,
- size_t sz,
- ssize_t *np,
- int *again)
+ char *buf,
+ size_t sz,
+ ssize_t *np,
+ int *again)
{
int retval = -1;
if ((*np = read(rc->rc_s, buf, sz)) < 0){ /* XXX atomicio ? */
- switch(errno){
- case ECONNRESET:/* Connection reset by peer */
- clicon_debug(1, "%s %d Connection reset by peer", __FUNCTION__, rc->rc_s);
- if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
- goto done;
- retval = 0; /* Close socket and ssl */
- goto done;
- break;
- case EAGAIN:
- clicon_debug(1, "%s read EAGAIN", __FUNCTION__);
- usleep(1000);
- *again = 1;
- break;
- default:;
- clicon_err(OE_XML, errno, "read");
- goto done;
- break;
- }
+ switch(errno){
+ case ECONNRESET:/* Connection reset by peer */
+ clicon_debug(1, "%s %d Connection reset by peer", __FUNCTION__, rc->rc_s);
+ if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
+ goto done;
+ retval = 0; /* Close socket and ssl */
+ goto done;
+ break;
+ case EAGAIN:
+ clicon_debug(1, "%s read EAGAIN", __FUNCTION__);
+ usleep(1000);
+ *again = 1;
+ break;
+ default:;
+ clicon_err(OE_XML, errno, "read");
+ goto done;
+ break;
+ }
}
retval = 1;
done:
@@ -648,9 +648,9 @@ read_regular(restconf_conn *rc,
*/
static int
restconf_http1_process(restconf_conn *rc,
- char *buf,
- size_t n,
- int *readmore)
+ char *buf,
+ size_t n,
+ int *readmore)
{
int retval = -1;
restconf_stream_data *sd;
@@ -661,8 +661,8 @@ restconf_http1_process(restconf_conn *rc,
h = rc->rc_h;
if ((sd = restconf_stream_find(rc, 0)) == NULL){
- clicon_err(OE_RESTCONF, EINVAL, "restconf stream not found");
- goto done;
+ clicon_err(OE_RESTCONF, EINVAL, "restconf stream not found");
+ goto done;
}
/* Two states for reading:
* 1) Initial reading of headers, parse from start
@@ -677,65 +677,65 @@ restconf_http1_process(restconf_conn *rc,
* 2: Content-Length found and matches body length. No more bytes to read
*/
if ((ret = http1_check_content_length(h, sd, &status)) < 0)
- goto done;
- if (status == 1){ /* Next read: keep header state and only append inbody */
- if (cbuf_append_buf(sd->sd_indata, buf, n) < 0){
- clicon_err(OE_UNIX, errno, "cbuf_append");
- goto done;
- }
+ goto done;
+ if (status == 1){ /* Next read: keep header state and only append inbody */
+ if (cbuf_append_buf(sd->sd_indata, buf, n) < 0){
+ clicon_err(OE_UNIX, errno, "cbuf_append");
+ goto done;
+ }
}
else {
- /* multi-buffer for multiple reads
- * This is different from sd_indata that it is before and includes headers
- */
- if (cbuf_append_buf(sd->sd_inbuf, buf, n) < 0){
- clicon_err(OE_UNIX, errno, "cbuf_append");
- goto done;
- }
- if (clixon_http1_parse_string(h, rc, cbuf_get(sd->sd_inbuf)) < 0){
- /* XXX This does not work for SSL */
- if (rc->rc_ssl){
- ret = SSL_pending(rc->rc_ssl);
- }
- else if ((ret = clixon_event_poll(rc->rc_s)) < 0)
- goto done;
- if (ret > 0){
- if (http1_native_clear_input(h, sd) < 0)
- goto done;
- (*readmore)++;
- goto ok;
- }
- /* Return error. Honestly, the sender could just e slow, it should really be a
- * timeout here.
- */
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cberr, "protocol malformed-message %s ", clicon_err_reason);
- if ((ret = native_send_badrequest(h, "application/yang-data+xml", cbuf_get(cberr), rc)) < 0)
- goto done;
- goto ok;
- }
- /* Check for Continue and if so reply with 100 Continue
- * ret == 1: send reply
- */
- if ((ret = http1_check_expect(h, rc, sd)) < 0)
- goto done;
- if (ret == 1){
- if ((ret = native_buf_write(h, cbuf_get(sd->sd_outp_buf), cbuf_len(sd->sd_outp_buf),
- rc, __FUNCTION__)) < 0)
- goto done;
- cvec_reset(sd->sd_outp_hdrs);
- cbuf_reset(sd->sd_outp_buf);
- if (ret == 0){
- if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
- goto done;
- rc = NULL;
- retval = 0;
- goto done;
- }
- }
+ /* multi-buffer for multiple reads
+ * This is different from sd_indata that it is before and includes headers
+ */
+ if (cbuf_append_buf(sd->sd_inbuf, buf, n) < 0){
+ clicon_err(OE_UNIX, errno, "cbuf_append");
+ goto done;
+ }
+ if (clixon_http1_parse_string(h, rc, cbuf_get(sd->sd_inbuf)) < 0){
+ /* XXX This does not work for SSL */
+ if (rc->rc_ssl){
+ ret = SSL_pending(rc->rc_ssl);
+ }
+ else if ((ret = clixon_event_poll(rc->rc_s)) < 0)
+ goto done;
+ if (ret > 0){
+ if (http1_native_clear_input(h, sd) < 0)
+ goto done;
+ (*readmore)++;
+ goto ok;
+ }
+ /* Return error. Honestly, the sender could just e slow, it should really be a
+ * timeout here.
+ */
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cberr, "protocol malformed-message %s ", clicon_err_reason);
+ if ((ret = native_send_badrequest(h, "application/yang-data+xml", cbuf_get(cberr), rc)) < 0)
+ goto done;
+ goto ok;
+ }
+ /* Check for Continue and if so reply with 100 Continue
+ * ret == 1: send reply
+ */
+ if ((ret = http1_check_expect(h, rc, sd)) < 0)
+ goto done;
+ if (ret == 1){
+ if ((ret = native_buf_write(h, cbuf_get(sd->sd_outp_buf), cbuf_len(sd->sd_outp_buf),
+ rc, __FUNCTION__)) < 0)
+ goto done;
+ cvec_reset(sd->sd_outp_hdrs);
+ cbuf_reset(sd->sd_outp_buf);
+ if (ret == 0){
+ if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
+ goto done;
+ rc = NULL;
+ retval = 0;
+ goto done;
+ }
+ }
}
/* Check whole message is read.
* Only way this could happen is that body is read
@@ -746,42 +746,42 @@ restconf_http1_process(restconf_conn *rc,
* 2: Content-Length found and matches body length. No more bytes to read
*/
if ((ret = http1_check_content_length(h, sd, &status)) < 0)
- goto done;
+ goto done;
if (status == 1){
- (*readmore)++;
- goto ok;
+ (*readmore)++;
+ goto ok;
}
/* nginx compatible, set HTTPS parameter if SSL */
if (rc->rc_ssl)
- if (restconf_param_set(h, "HTTPS", "https") < 0)
- goto done;
+ if (restconf_param_set(h, "HTTPS", "https") < 0)
+ goto done;
/* main restconf processing */
if (restconf_http1_path_root(h, rc) < 0)
- goto done;
+ goto done;
if ((ret = native_buf_write(h, cbuf_get(sd->sd_outp_buf), cbuf_len(sd->sd_outp_buf),
- rc, __FUNCTION__)) < 0)
- goto done;
+ rc, __FUNCTION__)) < 0)
+ goto done;
cvec_reset(sd->sd_outp_hdrs); /* Can be done in native_send_reply */
cbuf_reset(sd->sd_outp_buf);
cbuf_reset(sd->sd_inbuf);
cbuf_reset(sd->sd_indata);
if (sd->sd_body)
- cbuf_reset(sd->sd_body);
+ cbuf_reset(sd->sd_body);
if (sd->sd_qvec){
- cvec_free(sd->sd_qvec);
- sd->sd_qvec = NULL;
+ cvec_free(sd->sd_qvec);
+ sd->sd_qvec = NULL;
}
if (ret == 0 || rc->rc_exit){ /* Server-initiated exit */
- if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
- goto done;
- retval = 0;
- goto done;
+ if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
+ goto done;
+ retval = 0;
+ goto done;
}
ok:
retval = 1;
done:
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
return retval;
}
#endif
@@ -795,51 +795,51 @@ restconf_http2_upgrade(restconf_conn *rc)
restconf_stream_data *sd;
if ((sd = restconf_stream_find(rc, 0)) == NULL){
- clicon_err(OE_RESTCONF, EINVAL, "restconf stream not found");
- goto done;
+ clicon_err(OE_RESTCONF, EINVAL, "restconf stream not found");
+ goto done;
}
if (sd->sd_upgrade2){
- nghttp2_error ngerr;
+ nghttp2_error ngerr;
- /* Switch to http/2 according to RFC 7540 Sec 3.2 and RFC 7230 Sec 6.7 */
- rc->rc_proto = HTTP_2;
- if (http2_session_init(rc) < 0){
- restconf_close_ssl_socket(rc, __FUNCTION__, 0);
- goto done;
- }
- /* The HTTP/1.1 request that is sent prior to upgrade is assigned a
- * stream identifier of 1 (see Section 5.1.1) with default priority
- */
- sd->sd_stream_id = 1;
- /* The first HTTP/2 frame sent by the server MUST be a server connection
- * preface (Section 3.5) consisting of a SETTINGS frame (Section 6.5).
- */
- if ((ngerr = nghttp2_session_upgrade2(rc->rc_ngsession,
- sd->sd_settings2,
- sd->sd_settings2?strlen((const char*)sd->sd_settings2):0,
- 0, /* XXX: 1 if HEAD */
- NULL)) < 0){
- clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_upgrade2");
- goto done;
- }
- if (http2_send_server_connection(rc) < 0){
- restconf_close_ssl_socket(rc, __FUNCTION__, 0);
- goto done;
- }
- /* Use params from original http/1 session to http/2 stream */
- if (http2_exec(rc, sd, rc->rc_ngsession, 1) < 0)
- goto done;
- /*
- * Very special case for http/1->http/2 upgrade and restconf "restart"
- * That is, the restconf daemon is restarted under the hood, and the session
- * is closed in mid-step: it needs a couple of extra rounds to complete the http/2
- * settings before it completes.
- * Maybe a more precise way would be to encode that semantics using recieved http/2
- * frames instead of just postponing nrof events?
- */
- if (clixon_exit_get() == 1){
- clixon_exit_set(3);
- }
+ /* Switch to http/2 according to RFC 7540 Sec 3.2 and RFC 7230 Sec 6.7 */
+ rc->rc_proto = HTTP_2;
+ if (http2_session_init(rc) < 0){
+ restconf_close_ssl_socket(rc, __FUNCTION__, 0);
+ goto done;
+ }
+ /* The HTTP/1.1 request that is sent prior to upgrade is assigned a
+ * stream identifier of 1 (see Section 5.1.1) with default priority
+ */
+ sd->sd_stream_id = 1;
+ /* The first HTTP/2 frame sent by the server MUST be a server connection
+ * preface (Section 3.5) consisting of a SETTINGS frame (Section 6.5).
+ */
+ if ((ngerr = nghttp2_session_upgrade2(rc->rc_ngsession,
+ sd->sd_settings2,
+ sd->sd_settings2?strlen((const char*)sd->sd_settings2):0,
+ 0, /* XXX: 1 if HEAD */
+ NULL)) < 0){
+ clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_upgrade2");
+ goto done;
+ }
+ if (http2_send_server_connection(rc) < 0){
+ restconf_close_ssl_socket(rc, __FUNCTION__, 0);
+ goto done;
+ }
+ /* Use params from original http/1 session to http/2 stream */
+ if (http2_exec(rc, sd, rc->rc_ngsession, 1) < 0)
+ goto done;
+ /*
+ * Very special case for http/1->http/2 upgrade and restconf "restart"
+ * That is, the restconf daemon is restarted under the hood, and the session
+ * is closed in mid-step: it needs a couple of extra rounds to complete the http/2
+ * settings before it completes.
+ * Maybe a more precise way would be to encode that semantics using recieved http/2
+ * frames instead of just postponing nrof events?
+ */
+ if (clixon_exit_get() == 1){
+ clixon_exit_set(3);
+ }
}
retval = 0;
@@ -860,9 +860,9 @@ restconf_http2_upgrade(restconf_conn *rc)
*/
static int
restconf_http2_process(restconf_conn *rc,
- char *buf,
- size_t n,
- int *readmore)
+ char *buf,
+ size_t n,
+ int *readmore)
{
int retval = -1;
int ret;
@@ -870,28 +870,28 @@ restconf_http2_process(restconf_conn *rc,
clicon_debug(1, "%s", __FUNCTION__);
if (rc->rc_exit){ /* Server-initiated exit for http/2 */
- if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, 0)) < 0){
- clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr);
- goto done; // XXX not here in original?
- }
+ if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, 0)) < 0){
+ clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr);
+ goto done; // XXX not here in original?
+ }
}
else {
- if ((ret = http2_recv(rc, (unsigned char *)buf, n)) < 0)
- goto done;
- if (ret == 0){
- if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
- goto done;
- retval = 0;
- goto done;
- }
- /* Check if read more data frames */
- ret = 0;
- if (rc->rc_ssl)
- ret = SSL_pending(rc->rc_ssl);
- else if ((ret = clixon_event_poll(rc->rc_s)) < 0)
- goto done;
- if (ret > 0)
- (*readmore)++;
+ if ((ret = http2_recv(rc, (unsigned char *)buf, n)) < 0)
+ goto done;
+ if (ret == 0){
+ if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
+ goto done;
+ retval = 0;
+ goto done;
+ }
+ /* Check if read more data frames */
+ ret = 0;
+ if (rc->rc_ssl)
+ ret = SSL_pending(rc->rc_ssl);
+ else if ((ret = clixon_event_poll(rc->rc_s)) < 0)
+ goto done;
+ if (ret > 0)
+ (*readmore)++;
}
retval = 1;
done:
@@ -912,7 +912,7 @@ restconf_native_handle_get(clicon_handle h)
void *p;
if ((p = clicon_hash_value(cdat, "restconf-native-handle", &len)) != NULL)
- return *(restconf_native_handle **)p;
+ return *(restconf_native_handle **)p;
return NULL;
}
@@ -933,7 +933,7 @@ restconf_native_handle_get(clicon_handle h)
*/
int
restconf_connection(int s,
- void *arg)
+ void *arg)
{
int retval = -1;
restconf_conn *rc = NULL;
@@ -944,67 +944,67 @@ restconf_connection(int s,
clicon_debug(1, "%s %d", __FUNCTION__, s);
if ((rc = (restconf_conn*)arg) == NULL){
- clicon_err(OE_RESTCONF, EINVAL, "arg is NULL");
- goto done;
+ clicon_err(OE_RESTCONF, EINVAL, "arg is NULL");
+ goto done;
}
if (s != rc->rc_s){
- clicon_err(OE_RESTCONF, EINVAL, "s != rc->rc_s");
- goto done;
+ clicon_err(OE_RESTCONF, EINVAL, "s != rc->rc_s");
+ goto done;
}
gettimeofday(&rc->rc_t, NULL); /* activity timer */
while (readmore) {
- clicon_debug(1, "%s readmore", __FUNCTION__);
- readmore = 0;
- /* Example: curl -Ssik -u wilma:bar -X GET https://localhost/restconf/data/example:x */
- if (rc->rc_ssl){
- if (read_ssl(rc, buf, sizeof(buf), &n, &readmore) < 0)
- goto done;
- }
- else{ /* Not SSL */
- if ((ret = read_regular(rc, buf, sizeof(buf), &n, &readmore)) < 0)
- goto done;
- if (ret == 0)
- goto ok; /* abort here */
- }
- clicon_debug(1, "%s read:%zd", __FUNCTION__, n);
- if (readmore)
- continue;
- if (n == 0){
- clicon_debug(1, "%s n=0 closing socket", __FUNCTION__);
- if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
- goto done;
- rc = NULL;
- goto ok;
- }
- switch (rc->rc_proto){
+ clicon_debug(1, "%s readmore", __FUNCTION__);
+ readmore = 0;
+ /* Example: curl -Ssik -u wilma:bar -X GET https://localhost/restconf/data/example:x */
+ if (rc->rc_ssl){
+ if (read_ssl(rc, buf, sizeof(buf), &n, &readmore) < 0)
+ goto done;
+ }
+ else{ /* Not SSL */
+ if ((ret = read_regular(rc, buf, sizeof(buf), &n, &readmore)) < 0)
+ goto done;
+ if (ret == 0)
+ goto ok; /* abort here */
+ }
+ clicon_debug(1, "%s read:%zd", __FUNCTION__, n);
+ if (readmore)
+ continue;
+ if (n == 0){
+ clicon_debug(1, "%s n=0 closing socket", __FUNCTION__);
+ if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
+ goto done;
+ rc = NULL;
+ goto ok;
+ }
+ switch (rc->rc_proto){
#ifdef HAVE_HTTP1
- case HTTP_10:
- case HTTP_11:
- if ((ret = restconf_http1_process(rc, buf, n, &readmore)) < 0)
- goto done;
- gettimeofday(&rc->rc_t, NULL); /* activity timer */
- if (ret == 0)
- goto ok;
- if (readmore)
- continue;
+ case HTTP_10:
+ case HTTP_11:
+ if ((ret = restconf_http1_process(rc, buf, n, &readmore)) < 0)
+ goto done;
+ gettimeofday(&rc->rc_t, NULL); /* activity timer */
+ if (ret == 0)
+ goto ok;
+ if (readmore)
+ continue;
#ifdef HAVE_LIBNGHTTP2
- if (restconf_http2_upgrade(rc) < 0)
- goto done;
+ if (restconf_http2_upgrade(rc) < 0)
+ goto done;
#endif /* HAVE_LIBNGHTTP2 */
- break;
+ break;
#endif /* HAVE_HTTP1 */
#ifdef HAVE_LIBNGHTTP2
- case HTTP_2:
- if ((ret = restconf_http2_process(rc, buf, n, &readmore)) < 0)
- goto done;
- gettimeofday(&rc->rc_t, NULL); /* activity timer */
- if (ret == 0)
- goto ok;
- break;
+ case HTTP_2:
+ if ((ret = restconf_http2_process(rc, buf, n, &readmore)) < 0)
+ goto done;
+ gettimeofday(&rc->rc_t, NULL); /* activity timer */
+ if (ret == 0)
+ goto ok;
+ break;
#endif /* HAVE_LIBNGHTTP2 */
- default:
- break;
- } /* switch rc_proto */
+ default:
+ break;
+ } /* switch rc_proto */
} /* while readmore */
ok:
retval = 0;
@@ -1026,22 +1026,22 @@ restconf_connection_close1(restconf_conn *rc)
restconf_socket *rsock;
if (rc == NULL){
- clicon_err(OE_RESTCONF, EINVAL, "rc is NULL");
- goto done;
+ clicon_err(OE_RESTCONF, EINVAL, "rc is NULL");
+ goto done;
}
rsock = rc->rc_socket;
clicon_debug(1, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
if (close(rc->rc_s) < 0){
- clicon_err(OE_UNIX, errno, "close");
- goto done;
+ clicon_err(OE_UNIX, errno, "close");
+ goto done;
}
clixon_event_unreg_fd(rc->rc_s, restconf_connection);
/* re-set timer */
if (rc->rc_callhome){
- if (rsock->rs_periodic)
- restconf_idle_timer_unreg(rc);
- if (restconf_callhome_timer(rsock, 1) < 0)
- goto done;
+ if (rsock->rs_periodic)
+ restconf_idle_timer_unreg(rc);
+ if (restconf_callhome_timer(rsock, 1) < 0)
+ goto done;
}
retval = 0;
done:
@@ -1058,8 +1058,8 @@ restconf_connection_close1(restconf_conn *rc)
*/
int
restconf_close_ssl_socket(restconf_conn *rc,
- const char *callfn,
- int dontshutdown)
+ const char *callfn,
+ int dontshutdown)
{
int retval = -1;
int ret;
@@ -1068,36 +1068,36 @@ restconf_close_ssl_socket(restconf_conn *rc,
clicon_debug(1, "%s %s", __FUNCTION__, callfn);
if (rc->rc_ssl != NULL){
- if (!dontshutdown &&
- (ret = SSL_shutdown(rc->rc_ssl)) < 0){
- er = errno;
- sslerr = SSL_get_error(rc->rc_ssl, ret);
- clicon_debug(1, "%s errno:%d sslerr:%d", __FUNCTION__, er, sslerr);
- // case SSL_ERROR_ZERO_RETURN: /* 6 */
- // Note that in this case SSL_ERROR_ZERO_RETURN does not necessarily indicate that the underlying transport has been closed.
- if (sslerr == SSL_ERROR_SSL){ /* 1 */
-
- }
- else if (sslerr == SSL_ERROR_SYSCALL){ /* 5 */
- /* Some non-recoverable, fatal I/O error occurred. The OpenSSL error queue
- may contain more information on the error. For socket I/O on Unix systems,
- consult errno for details. If this error occurs then no further I/O
- operations should be performed on the connection and SSL_shutdown() must
- not be called.*/
- /* Ignore eg EBADF/ECONNRESET/EPIPE */
- }
- else{
- clicon_err(OE_SSL, sslerr, "SSL_shutdown, %s err:%d %d", callfn, sslerr, er);
- goto done;
- }
- }
- SSL_free(rc->rc_ssl);
- rc->rc_ssl = NULL;
+ if (!dontshutdown &&
+ (ret = SSL_shutdown(rc->rc_ssl)) < 0){
+ er = errno;
+ sslerr = SSL_get_error(rc->rc_ssl, ret);
+ clicon_debug(1, "%s errno:%d sslerr:%d", __FUNCTION__, er, sslerr);
+ // case SSL_ERROR_ZERO_RETURN: /* 6 */
+ // Note that in this case SSL_ERROR_ZERO_RETURN does not necessarily indicate that the underlying transport has been closed.
+ if (sslerr == SSL_ERROR_SSL){ /* 1 */
+
+ }
+ else if (sslerr == SSL_ERROR_SYSCALL){ /* 5 */
+ /* Some non-recoverable, fatal I/O error occurred. The OpenSSL error queue
+ may contain more information on the error. For socket I/O on Unix systems,
+ consult errno for details. If this error occurs then no further I/O
+ operations should be performed on the connection and SSL_shutdown() must
+ not be called.*/
+ /* Ignore eg EBADF/ECONNRESET/EPIPE */
+ }
+ else{
+ clicon_err(OE_SSL, sslerr, "SSL_shutdown, %s err:%d %d", callfn, sslerr, er);
+ goto done;
+ }
+ }
+ SSL_free(rc->rc_ssl);
+ rc->rc_ssl = NULL;
}
if (restconf_connection_close1(rc) < 0)
- goto done;
+ goto done;
if (restconf_conn_free(rc) < 0)
- goto done;
+ goto done;
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
@@ -1114,10 +1114,10 @@ restconf_close_ssl_socket(restconf_conn *rc,
*/
static int
ssl_alpn_check(clicon_handle h,
- const unsigned char *alpn,
- unsigned int alpnlen,
- restconf_conn *rc,
- restconf_http_proto *proto)
+ const unsigned char *alpn,
+ unsigned int alpnlen,
+ restconf_conn *rc,
+ restconf_http_proto *proto)
{
int retval = -1;
cbuf *cberr = NULL;
@@ -1125,42 +1125,42 @@ ssl_alpn_check(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
/* Alternatively, call restconf_str2proto but alpn is not a proper string */
if (alpn && alpnlen == 8 && memcmp("http/1.1", alpn, 8) == 0){
- *proto = HTTP_11;
- retval = 1; /* http/1.1 */
- goto done;
+ *proto = HTTP_11;
+ retval = 1; /* http/1.1 */
+ goto done;
}
#ifdef HAVE_LIBNGHTTP2
else if (alpn && alpnlen == 2 && memcmp("h2", alpn, 2) == 0){
- *proto = HTTP_2;
- retval = 1; /* http/2 */
- goto done;
+ *proto = HTTP_2;
+ retval = 1; /* http/2 */
+ goto done;
}
#endif
else {
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- if (alpn != NULL){
- cprintf(cberr, "protocol malformed-message ALPN: protocol not recognized: %s ", alpn);
- clicon_log(LOG_INFO, "%s Warning: %s", __FUNCTION__, cbuf_get(cberr));
- if (native_send_badrequest(h,
- "application/yang-data+xml",
- cbuf_get(cberr), rc) < 0)
- goto done;
- }
- else{
- /* XXX Sending badrequest here gives a segv in SSL_shutdown() later or a SIGPIPE here */
- clicon_log(LOG_INFO, "%s Warning: ALPN: No protocol selected, or no ALPN?", __FUNCTION__);
- }
- if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
- goto done;
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ if (alpn != NULL){
+ cprintf(cberr, "protocol malformed-message ALPN: protocol not recognized: %s ", alpn);
+ clicon_log(LOG_INFO, "%s Warning: %s", __FUNCTION__, cbuf_get(cberr));
+ if (native_send_badrequest(h,
+ "application/yang-data+xml",
+ cbuf_get(cberr), rc) < 0)
+ goto done;
+ }
+ else{
+ /* XXX Sending badrequest here gives a segv in SSL_shutdown() later or a SIGPIPE here */
+ clicon_log(LOG_INFO, "%s Warning: ALPN: No protocol selected, or no ALPN?", __FUNCTION__);
+ }
+ if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
+ goto done;
}
retval = 0; /* ALPN not OK */
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
return retval;
} /* ssl_alpn_check */
@@ -1176,9 +1176,9 @@ ssl_alpn_check(clicon_handle h,
*/
int
restconf_ssl_accept_client(clicon_handle h,
- int s,
- restconf_socket *rsock,
- restconf_conn **rcp)
+ int s,
+ restconf_socket *rsock,
+ restconf_conn **rcp)
{
int retval = -1;
restconf_native_handle *rn = NULL;
@@ -1199,173 +1199,173 @@ restconf_ssl_accept_client(clicon_handle h,
#endif
#endif
if ((rn = restconf_native_handle_get(h)) == NULL){
- clicon_err(OE_XML, EFAULT, "No openssl handle");
- goto done;
+ clicon_err(OE_XML, EFAULT, "No openssl handle");
+ goto done;
}
/*
* Register callbacks for actual data socket
*/
if ((rc = restconf_conn_new(h, s, rsock)) == NULL)
- goto done;
+ goto done;
clicon_debug(1, "%s s:%d", __FUNCTION__, rc->rc_s);
if (rsock->rs_ssl){
- if ((rc->rc_ssl = SSL_new(rn->rn_ctx)) == NULL){
- clicon_err(OE_SSL, 0, "SSL_new");
- goto done;
- }
- clicon_debug(1, "%s SSL_new(%p)", __FUNCTION__, rc->rc_ssl);
- /* CCL_CTX_set_verify already set, need not call SSL_set_verify again for this server
- */
- /* X509_CHECK_FLAG_NO_WILDCARDS disables wildcard expansion */
- SSL_set_hostflags(rc->rc_ssl, X509_CHECK_FLAG_NO_WILDCARDS);
+ if ((rc->rc_ssl = SSL_new(rn->rn_ctx)) == NULL){
+ clicon_err(OE_SSL, 0, "SSL_new");
+ goto done;
+ }
+ clicon_debug(1, "%s SSL_new(%p)", __FUNCTION__, rc->rc_ssl);
+ /* CCL_CTX_set_verify already set, need not call SSL_set_verify again for this server
+ */
+ /* X509_CHECK_FLAG_NO_WILDCARDS disables wildcard expansion */
+ SSL_set_hostflags(rc->rc_ssl, X509_CHECK_FLAG_NO_WILDCARDS);
#if 0
- /* XXX This code is kept for the time being just for reference, it does not belong here.
- * If you want to restrict client certs to a specific set.
- * Otherwise this is done in restcon ca-auth callback and ultimately NACM
- * SSL_set1_host() sets the expected DNS hostname to name
- C = SE
- L = Stockholm
- O = Clixon
- OU = clixon
- CN = ca <---
- emailAddress = olof@hagsand.se
- */
- if (SSL_set1_host(rc->rc_ssl, "andy") != 1) { /* for peer cert */
- clicon_err(OE_SSL, 0, "SSL_set1_host");
- goto done;
- }
- if (SSL_add1_host(rc->rc_ssl, "olof") != 1) { /* for peer cert */
- clicon_err(OE_SSL, 0, "SSL_set1_host");
- goto done;
- }
+ /* XXX This code is kept for the time being just for reference, it does not belong here.
+ * If you want to restrict client certs to a specific set.
+ * Otherwise this is done in restcon ca-auth callback and ultimately NACM
+ * SSL_set1_host() sets the expected DNS hostname to name
+ C = SE
+ L = Stockholm
+ O = Clixon
+ OU = clixon
+ CN = ca <---
+ emailAddress = olof@hagsand.se
+ */
+ if (SSL_set1_host(rc->rc_ssl, "andy") != 1) { /* for peer cert */
+ clicon_err(OE_SSL, 0, "SSL_set1_host");
+ goto done;
+ }
+ if (SSL_add1_host(rc->rc_ssl, "olof") != 1) { /* for peer cert */
+ clicon_err(OE_SSL, 0, "SSL_set1_host");
+ goto done;
+ }
#endif
- if (SSL_set_fd(rc->rc_ssl, rc->rc_s) != 1){
- clicon_err(OE_SSL, 0, "SSL_set_fd");
- goto done;
- }
- readmore = 1;
- while (readmore){
- readmore = 0;
- /* 1: OK, -1 fatal, 0: TLS/SSL handshake was not successful
- * Both error cases: Call SSL_get_error() with the return value ret
- */
- if ((ret = SSL_accept(rc->rc_ssl)) != 1) {
- clicon_debug(1, "%s SSL_accept() ret:%d errno:%d", __FUNCTION__, ret, er=errno);
- e = SSL_get_error(rc->rc_ssl, ret);
- switch (e){
- case SSL_ERROR_SSL: /* 1 */
- clicon_debug(1, "%s SSL_ERROR_SSL (non-ssl message on ssl socket)", __FUNCTION__);
+ if (SSL_set_fd(rc->rc_ssl, rc->rc_s) != 1){
+ clicon_err(OE_SSL, 0, "SSL_set_fd");
+ goto done;
+ }
+ readmore = 1;
+ while (readmore){
+ readmore = 0;
+ /* 1: OK, -1 fatal, 0: TLS/SSL handshake was not successful
+ * Both error cases: Call SSL_get_error() with the return value ret
+ */
+ if ((ret = SSL_accept(rc->rc_ssl)) != 1) {
+ clicon_debug(1, "%s SSL_accept() ret:%d errno:%d", __FUNCTION__, ret, er=errno);
+ e = SSL_get_error(rc->rc_ssl, ret);
+ switch (e){
+ case SSL_ERROR_SSL: /* 1 */
+ clicon_debug(1, "%s SSL_ERROR_SSL (non-ssl message on ssl socket)", __FUNCTION__);
#ifdef HTTP_ON_HTTPS_REPLY
- SSL_free(rc->rc_ssl);
- rc->rc_ssl = NULL;
- if (native_send_badrequest(h, "application/yang-data+xml",
- "protocol malformed-message The plain HTTP request was sent to HTTPS port ", rc) < 0)
- goto done;
+ SSL_free(rc->rc_ssl);
+ rc->rc_ssl = NULL;
+ if (native_send_badrequest(h, "application/yang-data+xml",
+ "protocol malformed-message The plain HTTP request was sent to HTTPS port ", rc) < 0)
+ goto done;
#endif
- if (restconf_close_ssl_socket(rc, __FUNCTION__, 1) < 0)
- goto done;
- goto closed;
- break;
- case SSL_ERROR_SYSCALL: /* 5 */
- /* Some non-recoverable, fatal I/O error occurred. The OpenSSL error queue
- may contain more information on the error. For socket I/O on Unix systems,
- consult errno for details. If this error occurs then no further I/O
- operations should be performed on the connection and SSL_shutdown() must
- not be called.*/
- clicon_debug(1, "%s SSL_accept() SSL_ERROR_SYSCALL %d", __FUNCTION__, er);
- if (restconf_close_ssl_socket(rc, __FUNCTION__, 1) < 0)
- goto done;
- rc = NULL;
- goto closed;
- break;
- case SSL_ERROR_WANT_READ: /* 2 */
- case SSL_ERROR_WANT_WRITE: /* 3 */
- /* SSL_ERROR_WANT_READ is returned when the last operation was a read operation
- * from a nonblocking BIO.
- * That is, it can happen if restconf_socket_init() below is called
- * with SOCK_NONBLOCK
- */
- clicon_debug(1, "%s write SSL_ERROR_WANT_READ", __FUNCTION__);
- usleep(10000);
- readmore = 1;
- break;
- case SSL_ERROR_NONE: /* 0 */
- case SSL_ERROR_ZERO_RETURN: /* 6 */
- case SSL_ERROR_WANT_CONNECT: /* 7 */
- case SSL_ERROR_WANT_ACCEPT: /* 8 */
- case SSL_ERROR_WANT_X509_LOOKUP: /* 4 */
- case SSL_ERROR_WANT_ASYNC: /* 8 */
- case SSL_ERROR_WANT_ASYNC_JOB: /* 10 */
+ if (restconf_close_ssl_socket(rc, __FUNCTION__, 1) < 0)
+ goto done;
+ goto closed;
+ break;
+ case SSL_ERROR_SYSCALL: /* 5 */
+ /* Some non-recoverable, fatal I/O error occurred. The OpenSSL error queue
+ may contain more information on the error. For socket I/O on Unix systems,
+ consult errno for details. If this error occurs then no further I/O
+ operations should be performed on the connection and SSL_shutdown() must
+ not be called.*/
+ clicon_debug(1, "%s SSL_accept() SSL_ERROR_SYSCALL %d", __FUNCTION__, er);
+ if (restconf_close_ssl_socket(rc, __FUNCTION__, 1) < 0)
+ goto done;
+ rc = NULL;
+ goto closed;
+ break;
+ case SSL_ERROR_WANT_READ: /* 2 */
+ case SSL_ERROR_WANT_WRITE: /* 3 */
+ /* SSL_ERROR_WANT_READ is returned when the last operation was a read operation
+ * from a nonblocking BIO.
+ * That is, it can happen if restconf_socket_init() below is called
+ * with SOCK_NONBLOCK
+ */
+ clicon_debug(1, "%s write SSL_ERROR_WANT_READ", __FUNCTION__);
+ usleep(10000);
+ readmore = 1;
+ break;
+ case SSL_ERROR_NONE: /* 0 */
+ case SSL_ERROR_ZERO_RETURN: /* 6 */
+ case SSL_ERROR_WANT_CONNECT: /* 7 */
+ case SSL_ERROR_WANT_ACCEPT: /* 8 */
+ case SSL_ERROR_WANT_X509_LOOKUP: /* 4 */
+ case SSL_ERROR_WANT_ASYNC: /* 8 */
+ case SSL_ERROR_WANT_ASYNC_JOB: /* 10 */
#ifdef SSL_ERROR_WANT_CLIENT_HELLO_CB
- case SSL_ERROR_WANT_CLIENT_HELLO_CB: /* 11 */
+ case SSL_ERROR_WANT_CLIENT_HELLO_CB: /* 11 */
#endif
- default:
- clicon_err(OE_SSL, 0, "SSL_accept:%d", e);
- goto done;
- break;
- }
- } /* SSL_accept */
- } /* while(readmore) */
- /* Sets data and len to point to the client's requested protocol for this connection. */
+ default:
+ clicon_err(OE_SSL, 0, "SSL_accept:%d", e);
+ goto done;
+ break;
+ }
+ } /* SSL_accept */
+ } /* while(readmore) */
+ /* Sets data and len to point to the client's requested protocol for this connection. */
#ifndef OPENSSL_NO_NEXTPROTONEG
- SSL_get0_next_proto_negotiated(rc->rc_ssl, &alpn, &alpnlen);
+ SSL_get0_next_proto_negotiated(rc->rc_ssl, &alpn, &alpnlen);
#endif /* !OPENSSL_NO_NEXTPROTONEG */
- if (alpn == NULL) {
- /* Returns a pointer to the selected protocol in data with length len. */
- SSL_get0_alpn_selected(rc->rc_ssl, &alpn, &alpnlen);
- }
- if ((ret = ssl_alpn_check(h, alpn, alpnlen, rc, &proto)) < 0)
- goto done;
- if (ret == 0)
- goto closed;
- clicon_debug(1, "%s proto:%s", __FUNCTION__, restconf_proto2str(proto));
+ if (alpn == NULL) {
+ /* Returns a pointer to the selected protocol in data with length len. */
+ SSL_get0_alpn_selected(rc->rc_ssl, &alpn, &alpnlen);
+ }
+ if ((ret = ssl_alpn_check(h, alpn, alpnlen, rc, &proto)) < 0)
+ goto done;
+ if (ret == 0)
+ goto closed;
+ clicon_debug(1, "%s proto:%s", __FUNCTION__, restconf_proto2str(proto));
#if 0 /* Seems too early to fail here, instead let authentication callback deal with this */
- /* For client-cert authentication, check if any certs are present,
- * if not, send bad request
- * Alt: set SSL_CTX_set_verify(ctx, SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
- * but then SSL_accept fails.
- */
- if (restconf_auth_type_get(h) == CLIXON_AUTH_CLIENT_CERTIFICATE){
- X509 *peercert;
+ /* For client-cert authentication, check if any certs are present,
+ * if not, send bad request
+ * Alt: set SSL_CTX_set_verify(ctx, SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
+ * but then SSL_accept fails.
+ */
+ if (restconf_auth_type_get(h) == CLIXON_AUTH_CLIENT_CERTIFICATE){
+ X509 *peercert;
- if ((peercert = SSL_get_peer_certificate(rc->rc_ssl)) != NULL){
- X509_free(peercert);
- }
- else { /* Get certificates (if available) */
- if (proto != HTTP_2 &&
- native_send_badrequest(h, rc->rc_s, rc->rc_ssl, "application/yang-data+xml",
- "protocol malformed-message Peer certificate required ", rc->rc_socket, rc) < 0)
- goto done;
- if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
- goto done;
- goto closed;
- }
- }
+ if ((peercert = SSL_get_peer_certificate(rc->rc_ssl)) != NULL){
+ X509_free(peercert);
+ }
+ else { /* Get certificates (if available) */
+ if (proto != HTTP_2 &&
+ native_send_badrequest(h, rc->rc_s, rc->rc_ssl, "application/yang-data+xml",
+ "protocol malformed-message Peer certificate required ", rc->rc_socket, rc) < 0)
+ goto done;
+ if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
+ goto done;
+ goto closed;
+ }
+ }
#endif
- /* Get the actual peer, XXX this maybe could be done in ca-auth client-cert code ?
- * Note this _only_ works if SSL_set1_host() was set previously,...
- */
- if ((ret = SSL_get_verify_result(rc->rc_ssl)) == X509_V_OK) { /* for peer cert */
- const char *peername = SSL_get0_peername(rc->rc_ssl);
- if (peername != NULL) {
- /* Name checks were in scope and matched the peername */
- clicon_debug(1, "%s peername:%s", __FUNCTION__, peername);
- }
- }
+ /* Get the actual peer, XXX this maybe could be done in ca-auth client-cert code ?
+ * Note this _only_ works if SSL_set1_host() was set previously,...
+ */
+ if ((ret = SSL_get_verify_result(rc->rc_ssl)) == X509_V_OK) { /* for peer cert */
+ const char *peername = SSL_get0_peername(rc->rc_ssl);
+ if (peername != NULL) {
+ /* Name checks were in scope and matched the peername */
+ clicon_debug(1, "%s peername:%s", __FUNCTION__, peername);
+ }
+ }
#if 0
- else{
- clicon_log(LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(ret));
- /* Maybe should return already here, but to get proper return message need to
- * continue to http/1 or http/2 handling
- * @see restconf_connection_sanity
- */
+ else{
+ clicon_log(LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(ret));
+ /* Maybe should return already here, but to get proper return message need to
+ * continue to http/1 or http/2 handling
+ * @see restconf_connection_sanity
+ */
- }
+ }
#endif
#if 0 /* debug */
- if (clicon_debug_get())
- restconf_listcerts(rc->rc_ssl);
+ if (clicon_debug_get())
+ restconf_listcerts(rc->rc_ssl);
#endif
} /* if ssl */
rc->rc_proto = proto;
@@ -1373,37 +1373,37 @@ restconf_ssl_accept_client(clicon_handle h,
#ifdef HAVE_HTTP1
case HTTP_10:
case HTTP_11:
- /* Create a default stream for http/1 */
- if (restconf_stream_data_new(rc, 0) == NULL)
- goto done;
- break;
+ /* Create a default stream for http/1 */
+ if (restconf_stream_data_new(rc, 0) == NULL)
+ goto done;
+ break;
#endif /* HAVE_HTTP1 */
#ifdef HAVE_LIBNGHTTP2
case HTTP_2:{
- if (http2_session_init(rc) < 0){
- restconf_close_ssl_socket(rc, __FUNCTION__, 0);
- goto done;
- }
- if (http2_send_server_connection(rc) < 0){
- restconf_close_ssl_socket(rc, __FUNCTION__, 0);
- goto done;
- }
- break;
+ if (http2_session_init(rc) < 0){
+ restconf_close_ssl_socket(rc, __FUNCTION__, 0);
+ goto done;
+ }
+ if (http2_send_server_connection(rc) < 0){
+ restconf_close_ssl_socket(rc, __FUNCTION__, 0);
+ goto done;
+ }
+ break;
}
#endif /* HAVE_LIBNGHTTP2 */
default:
- break;
+ break;
} /* switch proto */
gettimeofday(&rc->rc_t, NULL); /* activity timer */
if (clixon_event_reg_fd(rc->rc_s, restconf_connection, (void*)rc, "restconf client socket") < 0)
- goto done;
+ goto done;
if (rcp)
- *rcp = rc;
+ *rcp = rc;
retval = 1; /* OK, up */
done:
clicon_debug(1, "%s retval %d", __FUNCTION__, retval);
if (name)
- free(name);
+ free(name);
return retval;
closed:
retval = 0; /* OK, closed */
@@ -1412,26 +1412,26 @@ restconf_ssl_accept_client(clicon_handle h,
static int
restconf_idle_timer_set(struct timeval t,
- void *arg,
- char *descr)
+ void *arg,
+ char *descr)
{
int retval = -1;
cbuf *cb = NULL;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
cprintf(cb, "restconf idle timer %s", descr);
if (clixon_event_reg_timeout(t,
- restconf_idle_cb,
- arg,
- cbuf_get(cb)) < 0)
- goto done;
+ restconf_idle_cb,
+ arg,
+ cbuf_get(cb)) < 0)
+ goto done;
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -1451,7 +1451,7 @@ restconf_idle_timer_set(struct timeval t,
*/
static int
restconf_idle_cb(int fd,
- void *arg)
+ void *arg)
{
int retval = -1;
restconf_socket *rsock;
@@ -1462,29 +1462,29 @@ restconf_idle_cb(int fd,
struct timeval to = {0,};
if ((rc = (restconf_conn *)arg) == NULL){
- clicon_err(OE_YANG, EINVAL, "rc is NULL");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "rc is NULL");
+ goto done;
}
if ((rsock = rc->rc_socket) == NULL){
- clicon_err(OE_YANG, EINVAL, "rsock is NULL");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "rsock is NULL");
+ goto done;
}
clicon_debug(1, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
if (rc->rc_callhome && rsock->rs_periodic && rc->rc_s > 0 && rsock->rs_idle_timeout){
- gettimeofday(&now, NULL);
- timersub(&now, &rc->rc_t, &td); /* Last packet timestamp */
- if (td.tv_sec >= rsock->rs_idle_timeout){
- if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
- goto done;
- }
- else{
- to.tv_sec = rsock->rs_idle_timeout;
- timeradd(&now, &to, &tn);
- clicon_debug(1, "%s now:%lu timeout:%lu.%lu", __FUNCTION__,
- now.tv_sec, tn.tv_sec, tn.tv_usec);
- if (restconf_idle_timer_set(tn, rc, rsock->rs_description) < 0)
- goto done;
- }
+ gettimeofday(&now, NULL);
+ timersub(&now, &rc->rc_t, &td); /* Last packet timestamp */
+ if (td.tv_sec >= rsock->rs_idle_timeout){
+ if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
+ goto done;
+ }
+ else{
+ to.tv_sec = rsock->rs_idle_timeout;
+ timeradd(&now, &to, &tn);
+ clicon_debug(1, "%s now:%lu timeout:%lu.%lu", __FUNCTION__,
+ now.tv_sec, tn.tv_sec, tn.tv_usec);
+ if (restconf_idle_timer_set(tn, rc, rsock->rs_description) < 0)
+ goto done;
+ }
}
retval = 0;
done:
@@ -1517,20 +1517,20 @@ restconf_idle_timer(restconf_conn *rc)
restconf_socket *rsock;
if (rc == NULL || !rc->rc_callhome){
- clicon_err(OE_RESTCONF, EINVAL, "rc is NULL or not callhome");
- goto done;
+ clicon_err(OE_RESTCONF, EINVAL, "rc is NULL or not callhome");
+ goto done;
}
rsock = rc->rc_socket;
if (rsock == NULL || !rsock->rs_periodic || rsock->rs_idle_timeout==0){
- clicon_err(OE_YANG, EINVAL, "rsock is NULL or not periodic");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "rsock is NULL or not periodic");
+ goto done;
}
clicon_debug(1, "%s \"%s\" register", __FUNCTION__, rsock->rs_description);
gettimeofday(&now, NULL);
to.tv_sec = rsock->rs_idle_timeout;
timeradd(&now, &to, &t);
if (restconf_idle_timer_set(t, rc, rsock->rs_description) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -1546,7 +1546,7 @@ restconf_idle_timer(restconf_conn *rc)
*/
static int
restconf_callhome_cb(int fd,
- void *arg)
+ void *arg)
{
int retval = -1;
clicon_handle h;
@@ -1560,36 +1560,36 @@ restconf_callhome_cb(int fd,
rsock = (restconf_socket *)arg;
if (rsock == NULL || !rsock->rs_callhome){
- clicon_err(OE_YANG, EINVAL, "rsock is NULL");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "rsock is NULL");
+ goto done;
}
clicon_debug(1, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
h = rsock->rs_h;
/* Already computed in restconf_socket_init, could be saved in rsock? */
if (clixon_inet2sin(rsock->rs_addrtype, rsock->rs_addrstr, rsock->rs_port, sa, &sa_len) < 0)
- goto done;
+ goto done;
if ((s = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
- clicon_err(OE_UNIX, errno, "socket");
- goto done;
+ clicon_err(OE_UNIX, errno, "socket");
+ goto done;
}
if (connect(s, sa, sa_len) < 0){
- clicon_debug(1, "%s connect %hu fail:%d %s", __FUNCTION__, rsock->rs_port, errno, strerror(errno));
- close(s);
- rsock->rs_attempts++;
- /* Fail: Initiate new timer */
- if (restconf_callhome_timer(rsock, 0) < 0)
- goto done;
+ clicon_debug(1, "%s connect %hu fail:%d %s", __FUNCTION__, rsock->rs_port, errno, strerror(errno));
+ close(s);
+ rsock->rs_attempts++;
+ /* Fail: Initiate new timer */
+ if (restconf_callhome_timer(rsock, 0) < 0)
+ goto done;
}
else {
- clicon_debug(1, "%s connect %hu OK", __FUNCTION__, rsock->rs_port);
- rsock->rs_attempts = 0;
- if ((ret = restconf_ssl_accept_client(h, s, rsock, &rc)) < 0)
- goto done;
- /* ret == 0 means already closed */
- if (ret == 1 && rsock->rs_periodic && rsock->rs_idle_timeout){
- if (restconf_idle_timer(rc) < 0)
- goto done;
- }
+ clicon_debug(1, "%s connect %hu OK", __FUNCTION__, rsock->rs_port);
+ rsock->rs_attempts = 0;
+ if ((ret = restconf_ssl_accept_client(h, s, rsock, &rc)) < 0)
+ goto done;
+ /* ret == 0 means already closed */
+ if (ret == 1 && rsock->rs_periodic && rsock->rs_idle_timeout){
+ if (restconf_idle_timer(rc) < 0)
+ goto done;
+ }
}
retval = 0;
done:
@@ -1612,7 +1612,7 @@ restconf_callhome_timer_unreg(restconf_socket *rsock)
*/
int
restconf_callhome_timer(restconf_socket *rsock,
- int status)
+ int status)
{
int retval = -1;
struct timeval now;
@@ -1621,51 +1621,51 @@ restconf_callhome_timer(restconf_socket *rsock,
cbuf *cb = NULL;
if (rsock == NULL || !rsock->rs_callhome){
- clicon_err(OE_YANG, EINVAL, "rsock is NULL or not callhome");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "rsock is NULL or not callhome");
+ goto done;
}
clicon_debug(1, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
if (!rsock->rs_callhome)
- goto ok; /* shouldnt happen */
+ goto ok; /* shouldnt happen */
gettimeofday(&now, NULL);
if (rsock->rs_periodic){
- if ((status == 1) || rsock->rs_attempts >= rsock->rs_max_attempts){
- rsock->rs_period_nr++;
- rsock->rs_attempts = 0;
- t1.tv_sec = rsock->rs_start + rsock->rs_period_nr*rsock->rs_period;
- while (t1.tv_sec < now.tv_sec)
- t1.tv_sec += rsock->rs_period;
- t = t1;
- }
- else {
- t1.tv_sec = 1;
- timeradd(&now, &t1, &t);
- }
+ if ((status == 1) || rsock->rs_attempts >= rsock->rs_max_attempts){
+ rsock->rs_period_nr++;
+ rsock->rs_attempts = 0;
+ t1.tv_sec = rsock->rs_start + rsock->rs_period_nr*rsock->rs_period;
+ while (t1.tv_sec < now.tv_sec)
+ t1.tv_sec += rsock->rs_period;
+ t = t1;
+ }
+ else {
+ t1.tv_sec = 1;
+ timeradd(&now, &t1, &t);
+ }
}
else{ /* persistent: try again: attempts? */
- t1.tv_sec = 1;
- timeradd(&now, &t1, &t);
+ t1.tv_sec = 1;
+ timeradd(&now, &t1, &t);
}
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
cprintf(cb, "restconf callhome timer %s", rsock->rs_description);
if (rsock->rs_description)
- clicon_debug(1, "%s registering \"%s\": +%lu", __FUNCTION__, rsock->rs_description, t.tv_sec-now.tv_sec);
+ clicon_debug(1, "%s registering \"%s\": +%lu", __FUNCTION__, rsock->rs_description, t.tv_sec-now.tv_sec);
else
- clicon_debug(1, "%s: %lu", __FUNCTION__, t.tv_sec);
+ clicon_debug(1, "%s: %lu", __FUNCTION__, t.tv_sec);
/* Should be only place restconf_callhome_cb is registered */
if (clixon_event_reg_timeout(t,
- restconf_callhome_cb,
- rsock,
- cbuf_get(cb)) < 0)
- goto done;
+ restconf_callhome_cb,
+ rsock,
+ cbuf_get(cb)) < 0)
+ goto done;
ok:
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -1681,13 +1681,13 @@ restconf_callhome_timer(restconf_socket *rsock,
*/
int
restconf_socket_extract(clicon_handle h,
- cxobj *xs,
- cvec *nsc,
- restconf_socket *rsock,
- char **namespace,
- char **address,
- char **addrtype,
- uint16_t *port)
+ cxobj *xs,
+ cvec *nsc,
+ restconf_socket *rsock,
+ char **namespace,
+ char **address,
+ char **addrtype,
+ uint16_t *port)
{
int retval = -1;
cxobj *x;
@@ -1700,19 +1700,19 @@ restconf_socket_extract(clicon_handle h,
yang_stmt *ysub = NULL;
if ((x = xpath_first(xs, nsc, "namespace")) == NULL){
- clicon_err(OE_XML, EINVAL, "Mandatory namespace not given");
- goto done;
+ clicon_err(OE_XML, EINVAL, "Mandatory namespace not given");
+ goto done;
}
*namespace = xml_body(x);
if ((x = xpath_first(xs, nsc, "description")) != NULL){
- if ((rsock->rs_description = strdup(xml_body(x))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
+ if ((rsock->rs_description = strdup(xml_body(x))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
}
if ((x = xpath_first(xs, nsc, "address")) == NULL){
- clicon_err(OE_XML, EINVAL, "Mandatory address not given");
- goto done;
+ clicon_err(OE_XML, EINVAL, "Mandatory address not given");
+ goto done;
}
/* address is a union type and needs a special investigation to see which type (ipv4 or ipv6)
* the address is
@@ -1720,26 +1720,26 @@ restconf_socket_extract(clicon_handle h,
body = xml_body(x);
y = xml_spec(x);
if ((cv = cv_dup(yang_cv_get(y))) == NULL){
- clicon_err(OE_UNIX, errno, "cv_dup");
- goto done;
+ clicon_err(OE_UNIX, errno, "cv_dup");
+ goto done;
}
if ((ret = cv_parse1(body, cv, &reason)) < 0){
- clicon_err(OE_XML, errno, "cv_parse1");
- goto done;
+ clicon_err(OE_XML, errno, "cv_parse1");
+ goto done;
}
if (ret == 0){
- clicon_err(OE_XML, EFAULT, "%s", reason);
- goto done;
+ clicon_err(OE_XML, EFAULT, "%s", reason);
+ goto done;
}
if ((ret = ys_cv_validate(h, cv, y, &ysub, &reason)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- clicon_err(OE_XML, EFAULT, "Validation os address: %s", reason);
- goto done;
+ clicon_err(OE_XML, EFAULT, "Validation os address: %s", reason);
+ goto done;
}
if (ysub == NULL){
- clicon_err(OE_XML, EFAULT, "No address union type");
- goto done;
+ clicon_err(OE_XML, EFAULT, "No address union type");
+ goto done;
}
*address = body;
/* This is YANG type name of ip-address:
@@ -1751,76 +1751,76 @@ restconf_socket_extract(clicon_handle h,
*/
*addrtype = yang_argument_get(ysub);
if ((x = xpath_first(xs, nsc, "port")) != NULL &&
- (str = xml_body(x)) != NULL){
- if ((ret = parse_uint16(str, port, &reason)) < 0){
- clicon_err(OE_XML, errno, "parse_uint16");
- goto done;
- }
- if (ret == 0){
- clicon_err(OE_XML, EINVAL, "Unrecognized value of port: %s", str);
- goto done;
- }
+ (str = xml_body(x)) != NULL){
+ if ((ret = parse_uint16(str, port, &reason)) < 0){
+ clicon_err(OE_XML, errno, "parse_uint16");
+ goto done;
+ }
+ if (ret == 0){
+ clicon_err(OE_XML, EINVAL, "Unrecognized value of port: %s", str);
+ goto done;
+ }
}
if ((x = xpath_first(xs, nsc, "ssl")) != NULL &&
- (str = xml_body(x)) != NULL){
- /* XXX use parse_bool but it is legacy static */
- if (strcmp(str, "false") == 0)
- rsock->rs_ssl = 0;
- else if (strcmp(str, "true") == 0)
- rsock->rs_ssl = 1;
- else {
- clicon_err(OE_XML, EINVAL, "Unrecognized value of ssl: %s", str);
- goto done;
- }
+ (str = xml_body(x)) != NULL){
+ /* XXX use parse_bool but it is legacy static */
+ if (strcmp(str, "false") == 0)
+ rsock->rs_ssl = 0;
+ else if (strcmp(str, "true") == 0)
+ rsock->rs_ssl = 1;
+ else {
+ clicon_err(OE_XML, EINVAL, "Unrecognized value of ssl: %s", str);
+ goto done;
+ }
}
if (xpath_first(xs, nsc, "call-home") != NULL){
- rsock->rs_callhome = 1;
- if (xpath_first(xs, nsc, "call-home/connection-type/persistent") != NULL){
- rsock->rs_periodic = 0;
- }
- else if (xpath_first(xs, nsc, "call-home/connection-type/periodic") != NULL){
- rsock->rs_periodic = 1;
- if ((x = xpath_first(xs, nsc, "call-home/connection-type/periodic/period")) != NULL &&
- (str = xml_body(x)) != NULL){
- if ((ret = parse_uint32(str, &rsock->rs_period, &reason)) < 0){
- clicon_err(OE_XML, errno, "parse_uint16");
- goto done;
- }
- if (ret == 0){
- clicon_err(OE_XML, EINVAL, "Unrecognized value of period: %s", str);
- goto done;
- }
- }
- if ((x = xpath_first(xs, nsc, "call-home/connection-type/periodic/idle-timeout")) != NULL &&
- (str = xml_body(x)) != NULL){
- if ((ret = parse_uint16(str, &rsock->rs_idle_timeout, &reason)) < 0){
- clicon_err(OE_XML, errno, "parse_uint16");
- goto done;
- }
- if (ret == 0){
- clicon_err(OE_XML, EINVAL, "Unrecognized value of idle-timeout: %s", str);
- goto done;
- }
- }
- }
- if ((x = xpath_first(xs, nsc, "call-home/reconnect-strategy/max-attempts")) != NULL &&
- (str = xml_body(x)) != NULL){
- if ((ret = parse_uint8(str, &rsock->rs_max_attempts, &reason)) < 0){
- clicon_err(OE_XML, errno, "parse_uint8");
- goto done;
- }
- if (ret == 0){
- clicon_err(OE_XML, EINVAL, "Unrecognized value of max-attempts: %s", str);
- goto done;
- }
- }
+ rsock->rs_callhome = 1;
+ if (xpath_first(xs, nsc, "call-home/connection-type/persistent") != NULL){
+ rsock->rs_periodic = 0;
+ }
+ else if (xpath_first(xs, nsc, "call-home/connection-type/periodic") != NULL){
+ rsock->rs_periodic = 1;
+ if ((x = xpath_first(xs, nsc, "call-home/connection-type/periodic/period")) != NULL &&
+ (str = xml_body(x)) != NULL){
+ if ((ret = parse_uint32(str, &rsock->rs_period, &reason)) < 0){
+ clicon_err(OE_XML, errno, "parse_uint16");
+ goto done;
+ }
+ if (ret == 0){
+ clicon_err(OE_XML, EINVAL, "Unrecognized value of period: %s", str);
+ goto done;
+ }
+ }
+ if ((x = xpath_first(xs, nsc, "call-home/connection-type/periodic/idle-timeout")) != NULL &&
+ (str = xml_body(x)) != NULL){
+ if ((ret = parse_uint16(str, &rsock->rs_idle_timeout, &reason)) < 0){
+ clicon_err(OE_XML, errno, "parse_uint16");
+ goto done;
+ }
+ if (ret == 0){
+ clicon_err(OE_XML, EINVAL, "Unrecognized value of idle-timeout: %s", str);
+ goto done;
+ }
+ }
+ }
+ if ((x = xpath_first(xs, nsc, "call-home/reconnect-strategy/max-attempts")) != NULL &&
+ (str = xml_body(x)) != NULL){
+ if ((ret = parse_uint8(str, &rsock->rs_max_attempts, &reason)) < 0){
+ clicon_err(OE_XML, errno, "parse_uint8");
+ goto done;
+ }
+ if (ret == 0){
+ clicon_err(OE_XML, EINVAL, "Unrecognized value of max-attempts: %s", str);
+ goto done;
+ }
+ }
}
retval = 0;
done:
if (cv)
cv_free(cv);
if (reason)
- free(reason);
+ free(reason);
return retval;
}
diff --git a/apps/restconf/restconf_native.h b/apps/restconf/restconf_native.h
index f6c8c44d..38e1a149 100644
--- a/apps/restconf/restconf_native.h
+++ b/apps/restconf/restconf_native.h
@@ -120,7 +120,7 @@ typedef struct restconf_conn {
#endif
restconf_socket *rc_socket; /* Backpointer to restconf_socket needed for callhome */
struct timeval rc_t; /* Timestamp of last read/write activity, used by callhome
- idle-timeout algorithm */
+ idle-timeout algorithm */
} restconf_conn;
/* Restconf per socket handle
@@ -136,9 +136,9 @@ typedef struct restconf_socket{
char *rs_description; /* Description */
int rs_callhome; /* 0: listen, 1: callhome */
int rs_ss; /* Listen: Server socket, ready for accept
- * XXXCallhome: connect socket (same as restconf_conn->rc_s)
- * Callhome: No-op, see restconf_conn->rc_s
- */
+ * XXXCallhome: connect socket (same as restconf_conn->rc_s)
+ * Callhome: No-op, see restconf_conn->rc_s
+ */
int rs_ssl; /* 0: Not SSL socket, 1:SSL socket */
char *rs_addrtype; /* Address type according to ietf-inet-types:
eg inet:ipv4-address or inet:ipv6-address */
@@ -150,10 +150,10 @@ typedef struct restconf_socket{
uint16_t rs_idle_timeout; /* Max underlying TCP session remains idle (if callhome and periodic) (in seconds)*/
uint64_t rs_start; /* First period start, next is start+periods*period */
uint64_t rs_period_nr; /* Dynamic succeeding or timed out periods.
- Set in restconf_callhome_timer*/
+ Set in restconf_callhome_timer*/
uint8_t rs_attempts; /* Dynamic connect attempts in this round (if callhome)
- * Set in restconf_callhome_cb
- */
+ * Set in restconf_callhome_cb
+ */
restconf_conn *rs_conns; /* List of transient connect sockets */
} restconf_socket;
@@ -185,7 +185,7 @@ int restconf_idle_timer(restconf_conn *rc);
int restconf_callhome_timer_unreg(restconf_socket *rsock);
int restconf_callhome_timer(restconf_socket *rsock, int status);
int restconf_socket_extract(clicon_handle h, cxobj *xs, cvec *nsc, restconf_socket *rsock,
- char **namespace, char **address, char **addrtype, uint16_t *port);
+ char **namespace, char **address, char **addrtype, uint16_t *port);
#endif /* _RESTCONF_NATIVE_H_ */
diff --git a/apps/restconf/restconf_nghttp2.c b/apps/restconf/restconf_nghttp2.c
index 65e1b44c..35faf0f5 100644
--- a/apps/restconf/restconf_nghttp2.c
+++ b/apps/restconf/restconf_nghttp2.c
@@ -116,8 +116,8 @@ static const map_str2int nghttp2_frame_type_map[] = {
*/
int
clixon_nghttp2_log_cb(void *handle,
- int suberr,
- cbuf *cb)
+ int suberr,
+ cbuf *cb)
{
clicon_debug(1, "%s", __FUNCTION__);
cprintf(cb, "Fatal error: %s", nghttp2_strerror(suberr));
@@ -127,9 +127,9 @@ clixon_nghttp2_log_cb(void *handle,
#ifdef NOTUSED
static void
nghttp2_print_header(const uint8_t *name,
- size_t namelen,
- const uint8_t *value,
- size_t valuelen)
+ size_t namelen,
+ const uint8_t *value,
+ size_t valuelen)
{
clicon_debug(1, "%s %s", name, value);
}
@@ -139,7 +139,7 @@ nghttp2_print_header(const uint8_t *name,
octets, therefore they may contain non-printable characters. */
static void
nghttp2_print_headers(nghttp2_nv *nva,
- size_t nvlen)
+ size_t nvlen)
{
size_t i;
@@ -160,10 +160,10 @@ nghttp2_print_headers(nghttp2_nv *nva,
*/
static ssize_t
session_send_callback(nghttp2_session *session,
- const uint8_t *buf,
- size_t buflen,
- int flags,
- void *user_data)
+ const uint8_t *buf,
+ size_t buflen,
+ int flags,
+ void *user_data)
{
int retval = NGHTTP2_ERR_CALLBACK_FAILURE;
restconf_conn *rc = (restconf_conn *)user_data;
@@ -176,76 +176,76 @@ session_send_callback(nghttp2_session *session,
clicon_debug(1, "%s buflen:%zu", __FUNCTION__, buflen);
s = rc->rc_s;
while (totlen < buflen){
- if (rc->rc_ssl){
- if ((len = SSL_write(rc->rc_ssl, buf+totlen, buflen-totlen)) <= 0){
- er = errno;
- sslerr = SSL_get_error(rc->rc_ssl, len);
- clicon_debug(1, "%s errno:%d sslerr:%d", __FUNCTION__, er, sslerr);
- switch (sslerr){
- case SSL_ERROR_WANT_WRITE: /* 3 */
- clicon_debug(1, "%s write SSL_ERROR_WANT_WRITE", __FUNCTION__);
- usleep(1000);
- continue;
- break;
- case SSL_ERROR_SYSCALL: /* 5 */
- if (er == ECONNRESET || /* Connection reset by peer */
- er == EPIPE) { /* Reading end of socket is closed */
- goto done; /* Cleanup in http2_recv() */
- }
- else if (er == EAGAIN){
- /* same as want_write above, but different behaviour on different
- * platforms, linux here, freebsd want_write, or possibly differnt
- * ssl lib versions?
- */
- clicon_debug(1, "%s write EAGAIN", __FUNCTION__);
- usleep(1000);
- continue;
- }
- else{
- clicon_err(OE_RESTCONF, er, "SSL_write %d", sslerr);
- goto done;
- }
- break;
- default:
- clicon_err(OE_SSL, 0, "SSL_write");
- goto done;
- break;
- }
- goto done;
- }
- }
- else{
- if ((len = write(s, buf+totlen, buflen-totlen)) < 0){
- if (errno == EAGAIN){
- clicon_debug(1, "%s write EAGAIN", __FUNCTION__);
- usleep(10000);
- continue;
- }
+ if (rc->rc_ssl){
+ if ((len = SSL_write(rc->rc_ssl, buf+totlen, buflen-totlen)) <= 0){
+ er = errno;
+ sslerr = SSL_get_error(rc->rc_ssl, len);
+ clicon_debug(1, "%s errno:%d sslerr:%d", __FUNCTION__, er, sslerr);
+ switch (sslerr){
+ case SSL_ERROR_WANT_WRITE: /* 3 */
+ clicon_debug(1, "%s write SSL_ERROR_WANT_WRITE", __FUNCTION__);
+ usleep(1000);
+ continue;
+ break;
+ case SSL_ERROR_SYSCALL: /* 5 */
+ if (er == ECONNRESET || /* Connection reset by peer */
+ er == EPIPE) { /* Reading end of socket is closed */
+ goto done; /* Cleanup in http2_recv() */
+ }
+ else if (er == EAGAIN){
+ /* same as want_write above, but different behaviour on different
+ * platforms, linux here, freebsd want_write, or possibly differnt
+ * ssl lib versions?
+ */
+ clicon_debug(1, "%s write EAGAIN", __FUNCTION__);
+ usleep(1000);
+ continue;
+ }
+ else{
+ clicon_err(OE_RESTCONF, er, "SSL_write %d", sslerr);
+ goto done;
+ }
+ break;
+ default:
+ clicon_err(OE_SSL, 0, "SSL_write");
+ goto done;
+ break;
+ }
+ goto done;
+ }
+ }
+ else{
+ if ((len = write(s, buf+totlen, buflen-totlen)) < 0){
+ if (errno == EAGAIN){
+ clicon_debug(1, "%s write EAGAIN", __FUNCTION__);
+ usleep(10000);
+ continue;
+ }
#if 1
- else if (errno == ECONNRESET) {/* Connection reset by peer */
- close(s);
- // XXXUnclear why this is commented, maybe should call
- // restconf_connection_close?
- // clixon_event_unreg_fd(s, restconf_connection);
+ else if (errno == ECONNRESET) {/* Connection reset by peer */
+ close(s);
+ // XXXUnclear why this is commented, maybe should call
+ // restconf_connection_close?
+ // clixon_event_unreg_fd(s, restconf_connection);
- goto ok; /* Close socket and ssl */
- }
+ goto ok; /* Close socket and ssl */
+ }
#endif
- else{
- clicon_err(OE_UNIX, errno, "write");
- goto done;
- }
- }
- assert(len != 0);
- }
- totlen += len;
+ else{
+ clicon_err(OE_UNIX, errno, "write");
+ goto done;
+ }
+ }
+ assert(len != 0);
+ }
+ totlen += len;
} /* while */
ok:
retval = 0;
done:
if (retval < 0){
- clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
- return retval;
+ clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
+ return retval;
}
clicon_debug(1, "%s retval:%zd", __FUNCTION__, totlen);
return retval == 0 ? totlen : retval;
@@ -255,10 +255,10 @@ session_send_callback(nghttp2_session *session,
*/
static ssize_t
recv_callback(nghttp2_session *session,
- uint8_t *buf,
- size_t length,
- int flags,
- void *user_data)
+ uint8_t *buf,
+ size_t length,
+ int flags,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -289,60 +289,60 @@ restconf_nghttp2_path(restconf_stream_data *sd)
clicon_debug(1, "------------");
rc = sd->sd_conn;
if ((h = rc->rc_h) == NULL){
- clicon_err(OE_RESTCONF, EINVAL, "arg is NULL");
- goto done;
+ clicon_err(OE_RESTCONF, EINVAL, "arg is NULL");
+ goto done;
}
if (rc->rc_ssl != NULL){
- /* Slightly awkward way of taking SSL cert subject and CN and add it to restconf parameters
- * instead of accessing it directly
- * SSL subject fields, eg CN (Common Name) , can add more here? */
- if (ssl_x509_name_oneline(rc->rc_ssl, &oneline) < 0)
- goto done;
- if (oneline != NULL) {
- if (uri_str2cvec(oneline, '/', '=', 1, &cvv) < 0)
- goto done;
- if ((cn = cvec_find_str(cvv, "CN")) != NULL){
- if (restconf_param_set(h, "SSL_CN", cn) < 0)
- goto done;
- }
- }
+ /* Slightly awkward way of taking SSL cert subject and CN and add it to restconf parameters
+ * instead of accessing it directly
+ * SSL subject fields, eg CN (Common Name) , can add more here? */
+ if (ssl_x509_name_oneline(rc->rc_ssl, &oneline) < 0)
+ goto done;
+ if (oneline != NULL) {
+ if (uri_str2cvec(oneline, '/', '=', 1, &cvv) < 0)
+ goto done;
+ if ((cn = cvec_find_str(cvv, "CN")) != NULL){
+ if (restconf_param_set(h, "SSL_CN", cn) < 0)
+ goto done;
+ }
+ }
}
/* Check sanity of session, eg ssl client cert validation, may set rc_exit */
if (restconf_connection_sanity(h, rc, sd) < 0)
- goto done;
+ goto done;
if (!rc->rc_exit){
- /* Matching algorithm:
- * 1. try well-known
- * 2. try /restconf
- * 3. try /data
- * 4. call restconf anyway (because it handles errors)
- * This is for the situation where data is / and /restconf is more specific
- */
- if (strcmp(sd->sd_path, RESTCONF_WELL_KNOWN) == 0){
- if (api_well_known(h, sd) < 0)
- goto done;
- }
- else if (api_path_is_restconf(h)){
- if (api_root_restconf(h, sd, sd->sd_qvec) < 0)
- goto done;
- }
- else if (api_path_is_data(h)){
- if (api_http_data(h, sd, sd->sd_qvec) < 0)
- goto done;
- }
- else if (api_root_restconf(h, sd, sd->sd_qvec) < 0) /* error handling */
- goto done;
+ /* Matching algorithm:
+ * 1. try well-known
+ * 2. try /restconf
+ * 3. try /data
+ * 4. call restconf anyway (because it handles errors)
+ * This is for the situation where data is / and /restconf is more specific
+ */
+ if (strcmp(sd->sd_path, RESTCONF_WELL_KNOWN) == 0){
+ if (api_well_known(h, sd) < 0)
+ goto done;
+ }
+ else if (api_path_is_restconf(h)){
+ if (api_root_restconf(h, sd, sd->sd_qvec) < 0)
+ goto done;
+ }
+ else if (api_path_is_data(h)){
+ if (api_http_data(h, sd, sd->sd_qvec) < 0)
+ goto done;
+ }
+ else if (api_root_restconf(h, sd, sd->sd_qvec) < 0) /* error handling */
+ goto done;
}
/* Clear (fcgi) paramaters from this request */
if (restconf_param_del_all(h) < 0)
- goto done;
+ goto done;
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
if (cvv)
- cvec_free(cvv);
+ cvec_free(cvv);
if (oneline)
- free(oneline);
+ free(oneline);
return retval; /* void */
}
@@ -351,12 +351,12 @@ restconf_nghttp2_path(restconf_stream_data *sd)
*/
static ssize_t
restconf_sd_read(nghttp2_session *session,
- int32_t stream_id,
- uint8_t *buf,
- size_t length,
- uint32_t *data_flags,
- nghttp2_data_source *source,
- void *user_data)
+ int32_t stream_id,
+ uint8_t *buf,
+ size_t length,
+ uint32_t *data_flags,
+ nghttp2_data_source *source,
+ void *user_data)
{
restconf_stream_data *sd = (restconf_stream_data *)source->ptr;
cbuf *cb;
@@ -364,16 +364,16 @@ restconf_sd_read(nghttp2_session *session,
size_t remain;
if ((cb = sd->sd_body) == NULL){ /* shouldnt happen */
- *data_flags |= NGHTTP2_DATA_FLAG_EOF;
- return 0;
+ *data_flags |= NGHTTP2_DATA_FLAG_EOF;
+ return 0;
}
#if 0
if (cbuf_len(cb) <= length){
- len = remain;
- *data_flags |= NGHTTP2_DATA_FLAG_EOF;
+ len = remain;
+ *data_flags |= NGHTTP2_DATA_FLAG_EOF;
}
else{
- len = length;
+ len = length;
}
memcpy(buf, cbuf_get(cb) + sd->sd_body_offset, len);
*data_flags |= NGHTTP2_DATA_FLAG_EOF;
@@ -382,18 +382,18 @@ restconf_sd_read(nghttp2_session *session,
assert(cbuf_len(cb) > sd->sd_body_offset);
remain = cbuf_len(cb) - sd->sd_body_offset;
clicon_debug(1, "%s length:%zu totlen:%zu, offset:%zu remain:%zu",
- __FUNCTION__,
- length,
- cbuf_len(cb),
- sd->sd_body_offset,
- remain);
+ __FUNCTION__,
+ length,
+ cbuf_len(cb),
+ sd->sd_body_offset,
+ remain);
if (remain <= length){
- len = remain;
- *data_flags |= NGHTTP2_DATA_FLAG_EOF;
+ len = remain;
+ *data_flags |= NGHTTP2_DATA_FLAG_EOF;
}
else{
- len = length;
+ len = length;
}
memcpy(buf, cbuf_get(cb) + sd->sd_body_offset, len);
sd->sd_body_offset += len;
@@ -403,9 +403,9 @@ restconf_sd_read(nghttp2_session *session,
static int
restconf_submit_response(nghttp2_session *session,
- restconf_conn *rc,
- int stream_id,
- restconf_stream_data *sd)
+ restconf_conn *rc,
+ int stream_id,
+ restconf_stream_data *sd)
{
int retval = -1;
nghttp2_data_provider data_prd;
@@ -419,8 +419,8 @@ restconf_submit_response(nghttp2_session *session,
data_prd.source.ptr = sd;
data_prd.read_callback = restconf_sd_read;
if ((hdrs = (nghttp2_nv*)calloc(1+cvec_len(sd->sd_outp_hdrs), sizeof(nghttp2_nv))) == NULL){
- clicon_err(OE_UNIX, errno, "calloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "calloc");
+ goto done;
}
hdr = &hdrs[i++];
hdr->name = (uint8_t*)":status";
@@ -433,26 +433,26 @@ restconf_submit_response(nghttp2_session *session,
cv = NULL;
while ((cv = cvec_each(sd->sd_outp_hdrs, cv)) != NULL){
- hdr = &hdrs[i++];
- hdr->name = (uint8_t*)cv_name_get(cv);
- clicon_debug(1, "%s hdr: %s", __FUNCTION__, hdr->name);
- hdr->value = (uint8_t*)cv_string_get(cv);
- hdr->namelen = strlen(cv_name_get(cv));
- hdr->valuelen = strlen(cv_string_get(cv));
- hdr->flags = 0;
+ hdr = &hdrs[i++];
+ hdr->name = (uint8_t*)cv_name_get(cv);
+ clicon_debug(1, "%s hdr: %s", __FUNCTION__, hdr->name);
+ hdr->value = (uint8_t*)cv_string_get(cv);
+ hdr->namelen = strlen(cv_name_get(cv));
+ hdr->valuelen = strlen(cv_string_get(cv));
+ hdr->flags = 0;
}
if ((ngerr = nghttp2_submit_response(session,
- stream_id,
- hdrs, i,
- (data_prd.source.ptr != NULL)?&data_prd:NULL)) < 0){
- clicon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_response");
- goto done;
+ stream_id,
+ hdrs, i,
+ (data_prd.source.ptr != NULL)?&data_prd:NULL)) < 0){
+ clicon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_response");
+ goto done;
}
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (hdrs)
- free(hdrs);
+ free(hdrs);
return retval;
}
@@ -460,31 +460,31 @@ restconf_submit_response(nghttp2_session *session,
*/
int
http2_exec(restconf_conn *rc,
- restconf_stream_data *sd,
- nghttp2_session *session,
- int32_t stream_id)
+ restconf_stream_data *sd,
+ nghttp2_session *session,
+ int32_t stream_id)
{
int retval = -1;
clicon_debug(1, "%s", __FUNCTION__);
if (sd->sd_path){
- free(sd->sd_path);
- sd->sd_path = NULL;
+ free(sd->sd_path);
+ sd->sd_path = NULL;
}
if ((sd->sd_path = restconf_uripath(rc->rc_h)) == NULL)
- goto done;
+ goto done;
sd->sd_proto = HTTP_2; /* XXX is this necessary? */
if (strcmp(sd->sd_path, RESTCONF_WELL_KNOWN) == 0
- || api_path_is_restconf(rc->rc_h)
- || api_path_is_data(rc->rc_h)){
- if (restconf_nghttp2_path(sd) < 0)
- goto done;
+ || api_path_is_restconf(rc->rc_h)
+ || api_path_is_data(rc->rc_h)){
+ if (restconf_nghttp2_path(sd) < 0)
+ goto done;
}
else{
- sd->sd_code = 404; /* not found */
+ sd->sd_code = 404; /* not found */
}
if (restconf_param_del_all(rc->rc_h) < 0) // XXX
- goto done;
+ goto done;
/* If body, add a content-length header
* A server MUST NOT send a Content-Length header field in any response
@@ -494,14 +494,14 @@ http2_exec(restconf_conn *rc,
* [RFC7231]).
*/
if (sd->sd_code != 204 && sd->sd_code > 199 && sd->sd_body_len)
- if (restconf_reply_header(sd, "Content-Length", "%zu", sd->sd_body_len) < 0)
- goto done;
+ if (restconf_reply_header(sd, "Content-Length", "%zu", sd->sd_body_len) < 0)
+ goto done;
if (sd->sd_code){
- if (restconf_submit_response(session, rc, stream_id, sd) < 0)
- goto done;
+ if (restconf_submit_response(session, rc, stream_id, sd) < 0)
+ goto done;
}
else {
- /* 500 Internal server error ? */
+ /* 500 Internal server error ? */
}
retval = 0;
done:
@@ -513,8 +513,8 @@ http2_exec(restconf_conn *rc,
*/
static int
on_frame_recv_callback(nghttp2_session *session,
- const nghttp2_frame *frame,
- void *user_data)
+ const nghttp2_frame *frame,
+ void *user_data)
{
int retval = -1;
restconf_conn *rc = (restconf_conn *)user_data;
@@ -522,32 +522,32 @@ on_frame_recv_callback(nghttp2_session *session,
char *query;
clicon_debug(1, "%s %s %d", __FUNCTION__,
- clicon_int2str(nghttp2_frame_type_map, frame->hd.type),
- frame->hd.stream_id);
+ clicon_int2str(nghttp2_frame_type_map, frame->hd.type),
+ frame->hd.stream_id);
switch (frame->hd.type) {
case NGHTTP2_DATA:
case NGHTTP2_HEADERS:
- /* Check that the client request has finished */
- if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
- /* For DATA and HEADERS frame, this callback may be called after
- * on_stream_close_callback. Check that stream still alive.
- */
- if ((sd = nghttp2_session_get_stream_user_data(session, frame->hd.stream_id)) == NULL)
- return 0;
- /* Query vector, ie the ?a=x&b=y stuff */
- query = restconf_param_get(rc->rc_h, "REQUEST_URI");
- if ((query = index(query, '?')) != NULL){
- query++;
- if (strlen(query) &&
- uri_str2cvec(query, '&', '=', 1, &sd->sd_qvec) < 0)
- goto done;
- }
- if (http2_exec(rc, sd, session, frame->hd.stream_id) < 0)
- goto done;
- }
- break;
+ /* Check that the client request has finished */
+ if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
+ /* For DATA and HEADERS frame, this callback may be called after
+ * on_stream_close_callback. Check that stream still alive.
+ */
+ if ((sd = nghttp2_session_get_stream_user_data(session, frame->hd.stream_id)) == NULL)
+ return 0;
+ /* Query vector, ie the ?a=x&b=y stuff */
+ query = restconf_param_get(rc->rc_h, "REQUEST_URI");
+ if ((query = index(query, '?')) != NULL){
+ query++;
+ if (strlen(query) &&
+ uri_str2cvec(query, '&', '=', 1, &sd->sd_qvec) < 0)
+ goto done;
+ }
+ if (http2_exec(rc, sd, session, frame->hd.stream_id) < 0)
+ goto done;
+ }
+ break;
default:
- break;
+ break;
}
retval = 0;
done:
@@ -558,9 +558,9 @@ on_frame_recv_callback(nghttp2_session *session,
*/
static int
on_invalid_frame_recv_callback(nghttp2_session *session,
- const nghttp2_frame *frame,
- int lib_error_code,
- void *user_data)
+ const nghttp2_frame *frame,
+ int lib_error_code,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -576,18 +576,18 @@ on_invalid_frame_recv_callback(nghttp2_session *session,
*/
static int
on_data_chunk_recv_callback(nghttp2_session *session,
- uint8_t flags,
- int32_t stream_id,
- const uint8_t *data,
- size_t len,
- void *user_data)
+ uint8_t flags,
+ int32_t stream_id,
+ const uint8_t *data,
+ size_t len,
+ void *user_data)
{
restconf_conn *rc = (restconf_conn *)user_data;
restconf_stream_data *sd;
- clicon_debug(1, "%s %d", __FUNCTION__, stream_id);
+ clicon_debug(1, "%s %d", __FUNCTION__, stream_id);
if ((sd = restconf_stream_find(rc, stream_id)) != NULL){
- cbuf_append_buf(sd->sd_indata, (void*)data, len);
+ cbuf_append_buf(sd->sd_indata, (void*)data, len);
}
return 0;
}
@@ -596,8 +596,8 @@ on_data_chunk_recv_callback(nghttp2_session *session,
*/
static int
before_frame_send_callback(nghttp2_session *session,
- const nghttp2_frame *frame,
- void *user_data)
+ const nghttp2_frame *frame,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -608,8 +608,8 @@ before_frame_send_callback(nghttp2_session *session,
*/
static int
on_frame_send_callback(nghttp2_session *session,
- const nghttp2_frame *frame,
- void *user_data)
+ const nghttp2_frame *frame,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -620,9 +620,9 @@ on_frame_send_callback(nghttp2_session *session,
*/
static int
on_frame_not_send_callback(nghttp2_session *session,
- const nghttp2_frame *frame,
- int lib_error_code,
- void *user_data)
+ const nghttp2_frame *frame,
+ int lib_error_code,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -633,17 +633,17 @@ on_frame_not_send_callback(nghttp2_session *session,
*/
static int
on_stream_close_callback(nghttp2_session *session,
- int32_t stream_id,
- nghttp2_error_code error_code,
- void *user_data)
+ int32_t stream_id,
+ nghttp2_error_code error_code,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s %d %s", __FUNCTION__, error_code, nghttp2_strerror(error_code));
#if 0 // NOTNEEDED /* XXX think this is not necessary? */
if (error_code){
- if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
- return -1;
+ if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
+ return -1;
}
#endif
return 0;
@@ -653,17 +653,17 @@ on_stream_close_callback(nghttp2_session *session,
*/
static int
on_begin_headers_callback(nghttp2_session *session,
- const nghttp2_frame *frame,
- void *user_data)
+ const nghttp2_frame *frame,
+ void *user_data)
{
restconf_conn *rc = (restconf_conn *)user_data;
restconf_stream_data *sd;
clicon_debug(1, "%s %s", __FUNCTION__, clicon_int2str(nghttp2_frame_type_map, frame->hd.type));
if (frame->hd.type == NGHTTP2_HEADERS &&
- frame->headers.cat == NGHTTP2_HCAT_REQUEST) {
- sd = restconf_stream_data_new(rc, frame->hd.stream_id);
- nghttp2_session_set_stream_user_data(session, frame->hd.stream_id, sd);
+ frame->headers.cat == NGHTTP2_HCAT_REQUEST) {
+ sd = restconf_stream_data_new(rc, frame->hd.stream_id);
+ nghttp2_session_set_stream_user_data(session, frame->hd.stream_id, sd);
}
return 0;
}
@@ -673,31 +673,31 @@ on_begin_headers_callback(nghttp2_session *session,
*/
static int
nghttp2_hdr2clixon(clicon_handle h,
- char *name,
- char *value)
+ char *name,
+ char *value)
{
int retval = -1;
if (strcmp(name, ":path") == 0){
- /* Including ?args, call restconf_uripath() to get only path */
- if (restconf_param_set(h, "REQUEST_URI", value) < 0)
- goto done;
+ /* Including ?args, call restconf_uripath() to get only path */
+ if (restconf_param_set(h, "REQUEST_URI", value) < 0)
+ goto done;
}
else if (strcmp(name, ":method") == 0){
- if (restconf_param_set(h, "REQUEST_METHOD", value) < 0)
- goto done;
+ if (restconf_param_set(h, "REQUEST_METHOD", value) < 0)
+ goto done;
}
else if (strcmp(name, ":scheme") == 0){
- if (strcmp(value, "https") == 0 &&
- restconf_param_set(h, "HTTPS", "https") < 0) /* some string or NULL */
- goto done;
+ if (strcmp(value, "https") == 0 &&
+ restconf_param_set(h, "HTTPS", "https") < 0) /* some string or NULL */
+ goto done;
}
else if (strcmp(name, ":authority") == 0){
- if (restconf_param_set(h, "HTTP_HOST", value) < 0)
- goto done;
+ if (restconf_param_set(h, "HTTP_HOST", value) < 0)
+ goto done;
}
else if (restconf_convert_hdr(h, name, value) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -711,27 +711,27 @@ nghttp2_hdr2clixon(clicon_handle h,
*/
static int
on_header_callback(nghttp2_session *session,
- const nghttp2_frame *frame,
- const uint8_t *name,
- size_t namelen,
- const uint8_t *value,
- size_t valuelen,
- uint8_t flags,
- void *user_data)
+ const nghttp2_frame *frame,
+ const uint8_t *name,
+ size_t namelen,
+ const uint8_t *value,
+ size_t valuelen,
+ uint8_t flags,
+ void *user_data)
{
int retval = -1;
restconf_conn *rc = (restconf_conn *)user_data;
switch (frame->hd.type){
case NGHTTP2_HEADERS:
- assert (frame->headers.cat == NGHTTP2_HCAT_REQUEST);
- clicon_debug(1, "%s HEADERS %s %s", __FUNCTION__, name, value);
- if (nghttp2_hdr2clixon(rc->rc_h, (char*)name, (char*)value) < 0)
- goto done;
- break;
+ assert (frame->headers.cat == NGHTTP2_HCAT_REQUEST);
+ clicon_debug(1, "%s HEADERS %s %s", __FUNCTION__, name, value);
+ if (nghttp2_hdr2clixon(rc->rc_h, (char*)name, (char*)value) < 0)
+ goto done;
+ break;
default:
- clicon_debug(1, "%s %s %s", __FUNCTION__, clicon_int2str(nghttp2_frame_type_map, frame->hd.type), name);
- break;
+ clicon_debug(1, "%s %s %s", __FUNCTION__, clicon_int2str(nghttp2_frame_type_map, frame->hd.type), name);
+ break;
}
retval = 0;
done:
@@ -743,9 +743,9 @@ on_header_callback(nghttp2_session *session,
*/
static ssize_t
select_padding_callback(nghttp2_session *session,
- const nghttp2_frame *frame,
- size_t max_payloadlen,
- void *user_data)
+ const nghttp2_frame *frame,
+ size_t max_payloadlen,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -756,12 +756,12 @@ select_padding_callback(nghttp2_session *session,
*/
static ssize_t
data_source_read_length_callback(nghttp2_session *session,
- uint8_t frame_type,
- int32_t stream_id,
- int32_t session_remote_window_size,
- int32_t stream_remote_window_size,
- uint32_t remote_max_frame_size,
- void *user_data)
+ uint8_t frame_type,
+ int32_t stream_id,
+ int32_t session_remote_window_size,
+ int32_t stream_remote_window_size,
+ uint32_t remote_max_frame_size,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -775,13 +775,13 @@ data_source_read_length_callback(nghttp2_session *session,
*/
static int
on_begin_frame_callback(nghttp2_session *session,
- const nghttp2_frame_hd *hd,
- void *user_data)
+ const nghttp2_frame_hd *hd,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s %s", __FUNCTION__, clicon_int2str(nghttp2_frame_type_map, hd->type));
if (hd->type == NGHTTP2_CONTINUATION)
- assert(0);
+ assert(0);
return 0;
}
@@ -792,10 +792,10 @@ on_begin_frame_callback(nghttp2_session *session,
*/
static int
send_data_callback(nghttp2_session *session,
- nghttp2_frame *frame,
- const uint8_t *framehd, size_t length,
- nghttp2_data_source *source,
- void *user_data)
+ nghttp2_frame *frame,
+ const uint8_t *framehd, size_t length,
+ nghttp2_data_source *source,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -807,9 +807,9 @@ send_data_callback(nghttp2_session *session,
*/
static ssize_t
pack_extension_callback(nghttp2_session *session,
- uint8_t *buf, size_t len,
- const nghttp2_frame *frame,
- void *user_data)
+ uint8_t *buf, size_t len,
+ const nghttp2_frame *frame,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -820,9 +820,9 @@ pack_extension_callback(nghttp2_session *session,
*/
static int
unpack_extension_callback(nghttp2_session *session,
- void **payload,
- const nghttp2_frame_hd *hd,
- void *user_data)
+ void **payload,
+ const nghttp2_frame_hd *hd,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -834,10 +834,10 @@ unpack_extension_callback(nghttp2_session *session,
*/
static int
on_extension_chunk_recv_callback(nghttp2_session *session,
- const nghttp2_frame_hd *hd,
- const uint8_t *data,
- size_t len,
- void *user_data)
+ const nghttp2_frame_hd *hd,
+ const uint8_t *data,
+ size_t len,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -848,9 +848,9 @@ on_extension_chunk_recv_callback(nghttp2_session *session,
*/
static int
error_callback(nghttp2_session *session,
- const char *msg,
- size_t len,
- void *user_data)
+ const char *msg,
+ size_t len,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -862,10 +862,10 @@ error_callback(nghttp2_session *session,
*/
static int
error_callback2(nghttp2_session *session,
- int lib_error_code,
- const char *msg,
- size_t len,
- void *user_data)
+ int lib_error_code,
+ const char *msg,
+ size_t len,
+ void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
@@ -885,34 +885,34 @@ error_callback2(nghttp2_session *session,
*/
int
http2_recv(restconf_conn *rc,
- const unsigned char *buf,
- size_t n)
+ const unsigned char *buf,
+ size_t n)
{
int retval = -1;
nghttp2_error ngerr;
clicon_debug(1, "%s", __FUNCTION__);
if (rc->rc_ngsession == NULL){
- /* http2_session_init not called */
- clicon_err(OE_RESTCONF, EINVAL, "No nghttp2 session");
- goto done;
+ /* http2_session_init not called */
+ clicon_err(OE_RESTCONF, EINVAL, "No nghttp2 session");
+ goto done;
}
/* may make additional pending frames */
if ((ngerr = nghttp2_session_mem_recv(rc->rc_ngsession, buf, n)) < 0){
- if (ngerr == NGHTTP2_ERR_BAD_CLIENT_MAGIC){
- /* :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC`
- * Invalid client magic was detected. This error only returns
- * when |session| was configured as server and
- * `nghttp2_option_set_no_recv_client_magic()` is not used with
- * nonzero value. */
- clicon_log(LOG_INFO, "%s Received bad client magic byte strin", __FUNCTION__);
- /* unsure if this does anything, byt does not seem to hurt */
- if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, ngerr)) < 0)
- clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr);
- goto fail;
- }
- clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_mem_recv");
- goto done;
+ if (ngerr == NGHTTP2_ERR_BAD_CLIENT_MAGIC){
+ /* :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC`
+ * Invalid client magic was detected. This error only returns
+ * when |session| was configured as server and
+ * `nghttp2_option_set_no_recv_client_magic()` is not used with
+ * nonzero value. */
+ clicon_log(LOG_INFO, "%s Received bad client magic byte strin", __FUNCTION__);
+ /* unsure if this does anything, byt does not seem to hurt */
+ if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, ngerr)) < 0)
+ clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr);
+ goto fail;
+ }
+ clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_mem_recv");
+ goto done;
}
/* sends highest prio frame from outbound queue to remote peer. It does this as
* many as possible until user callback :type:`nghttp2_send_callback` returns
@@ -921,10 +921,10 @@ http2_recv(restconf_conn *rc,
*/
clicon_err_reset();
if ((ngerr = nghttp2_session_send(rc->rc_ngsession)) != 0){
- if (clicon_errno)
- goto done;
- else
- goto fail; /* Not fatal error */
+ if (clicon_errno)
+ goto done;
+ else
+ goto fail; /* Not fatal error */
}
retval = 1; /* OK */
done:
@@ -942,20 +942,20 @@ http2_send_server_connection(restconf_conn *rc)
{
int retval = -1;
nghttp2_settings_entry iv[2] = {{NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100}
- ,{NGHTTP2_SETTINGS_ENABLE_PUSH, 0}};
+ ,{NGHTTP2_SETTINGS_ENABLE_PUSH, 0}};
nghttp2_error ngerr;
clicon_debug(1, "%s", __FUNCTION__);
if ((ngerr = nghttp2_submit_settings(rc->rc_ngsession,
- NGHTTP2_FLAG_NONE,
- iv,
- ARRLEN(iv))) != 0){
- clicon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_settings");
- goto done;
+ NGHTTP2_FLAG_NONE,
+ iv,
+ ARRLEN(iv))) != 0){
+ clicon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_settings");
+ goto done;
}
if ((ngerr = nghttp2_session_send(rc->rc_ngsession)) != 0){
- clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_send");
- goto done;
+ clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_send");
+ goto done;
}
retval = 0;
done:
@@ -1004,8 +1004,8 @@ http2_session_init(restconf_conn *rc)
/* Create session for server use, register callbacks */
if ((ngerr = nghttp2_session_server_new3(&session, callbacks, rc, NULL, NULL)) < 0){
- clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_server_new");
- goto done;
+ clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_server_new");
+ goto done;
}
nghttp2_session_callbacks_del(callbacks);
rc->rc_ngsession = session;
diff --git a/apps/restconf/restconf_root.c b/apps/restconf/restconf_root.c
index 1cb8730f..92a09a53 100644
--- a/apps/restconf/restconf_root.c
+++ b/apps/restconf/restconf_root.c
@@ -85,7 +85,7 @@ api_path_is_restconf(clicon_handle h)
if ((path = restconf_uripath(h)) == NULL)
goto done;
if ((restconf_api_path = clicon_option_str(h, "CLICON_RESTCONF_API_ROOT")) == NULL)
- goto done;
+ goto done;
if (strlen(path) < strlen(restconf_api_path)) /* "/" + restconf */
goto done;
if (strncmp(path, restconf_api_path, strlen(restconf_api_path)) != 0)
@@ -93,7 +93,7 @@ api_path_is_restconf(clicon_handle h)
retval = 1;
done:
if (path)
- free(path);
+ free(path);
return retval;
}
@@ -106,7 +106,7 @@ api_path_is_restconf(clicon_handle h)
*/
int
api_well_known(clicon_handle h,
- void *req)
+ void *req)
{
int retval = -1;
char *request_method;
@@ -115,37 +115,37 @@ api_well_known(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (req == NULL){
- errno = EINVAL;
- goto done;
+ errno = EINVAL;
+ goto done;
}
request_method = restconf_param_get(h, "REQUEST_METHOD");
head = strcmp(request_method, "HEAD") == 0;
if (!head && strcmp(request_method, "GET") != 0){
- if (restconf_method_notallowed(h, req, "GET,HEAD", restconf_pretty_get(h), YANG_DATA_JSON) < 0)
- goto done;
- goto ok;
+ if (restconf_method_notallowed(h, req, "GET,HEAD", restconf_pretty_get(h), YANG_DATA_JSON) < 0)
+ goto done;
+ goto ok;
}
if (restconf_reply_header(req, "Content-Type", "application/xrd+xml") < 0)
- goto done;
+ goto done;
if (restconf_reply_header(req, "Cache-Control", "no-cache") < 0)
- goto done;
+ goto done;
/* Create body */
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
cprintf(cb, "\n");
cprintf(cb, " \n");
cprintf(cb, " \r\n");
if (restconf_reply_send(req, 200, cb, head) < 0)
- goto done;
+ goto done;
cb = NULL;
ok:
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -162,10 +162,10 @@ api_well_known(clicon_handle h,
*/
static int
api_root_restconf_exact(clicon_handle h,
- void *req,
- char *request_method,
- int pretty,
- restconf_media media_out)
+ void *req,
+ char *request_method,
+ int pretty,
+ restconf_media media_out)
{
int retval = -1;
@@ -177,46 +177,46 @@ api_root_restconf_exact(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
head = strcmp(request_method, "HEAD") == 0;
if (!head && strcmp(request_method, "GET") != 0){
- if (restconf_method_notallowed(h, req, "GET", pretty, media_out) < 0)
- goto done;
- goto ok;
+ if (restconf_method_notallowed(h, req, "GET", pretty, media_out) < 0)
+ goto done;
+ goto ok;
}
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0)
- goto done;
+ goto done;
if (restconf_reply_header(req, "Cache-Control", "no-cache") < 0)
- goto done;
+ goto done;
if (clixon_xml_parse_string(" "
- "" IETF_YANG_LIBRARY_REVISION
- " ",
- YB_MODULE, yspec, &xt, NULL) < 0)
- goto done;
+ "" IETF_YANG_LIBRARY_REVISION
+ " ",
+ YB_MODULE, yspec, &xt, NULL) < 0)
+ goto done;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
if (xml_rootchild(xt, 0, &xt) < 0)
- goto done;
+ goto done;
switch (media_out){
case YANG_DATA_XML:
case YANG_PATCH_XML:
- if (clixon_xml2cbuf(cb, xt, 0, pretty, -1, 0) < 0)
- goto done;
- break;
+ if (clixon_xml2cbuf(cb, xt, 0, pretty, -1, 0) < 0)
+ goto done;
+ break;
case YANG_DATA_JSON:
- case YANG_PATCH_JSON:
- if (clixon_json2cbuf(cb, xt, pretty, 0, 0) < 0)
- goto done;
- break;
+ case YANG_PATCH_JSON:
+ if (clixon_json2cbuf(cb, xt, pretty, 0, 0) < 0)
+ goto done;
+ break;
default:
- break;
+ break;
}
if (restconf_reply_send(req, 200, cb, head) < 0)
- goto done;
+ goto done;
cb = NULL;
ok:
retval = 0;
@@ -224,7 +224,7 @@ api_root_restconf_exact(clicon_handle h,
if (cb)
cbuf_free(cb);
if (xt)
- xml_free(xt);
+ xml_free(xt);
return retval;
}
@@ -237,10 +237,10 @@ api_root_restconf_exact(clicon_handle h,
*/
static int
api_operational_state(clicon_handle h,
- void *req,
- char *request_method,
- int pretty,
- restconf_media media_out)
+ void *req,
+ char *request_method,
+ int pretty,
+ restconf_media media_out)
{
clicon_debug(1, "%s request method:%s", __FUNCTION__, request_method);
@@ -257,9 +257,9 @@ api_operational_state(clicon_handle h,
*/
static int
api_yang_library_version(clicon_handle h,
- void *req,
- int pretty,
- restconf_media media_out)
+ void *req,
+ int pretty,
+ restconf_media media_out)
{
int retval = -1;
@@ -269,45 +269,45 @@ api_yang_library_version(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0)
- goto done;
+ goto done;
if (restconf_reply_header(req, "Cache-Control", "no-cache") < 0)
- goto done;
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xt, NULL,
- "%s ",
- IETF_YANG_LIBRARY_REVISION) < 0)
- goto done;
+ "%s ",
+ IETF_YANG_LIBRARY_REVISION) < 0)
+ goto done;
if (xml_rootchild(xt, 0, &xt) < 0)
- goto done;
+ goto done;
yspec = clicon_dbspec_yang(h);
if (xml_bind_special(xt, yspec, "/rc:restconf/yang-library-version") < 0)
- goto done;
+ goto done;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
switch (media_out){
case YANG_DATA_XML:
case YANG_PATCH_XML:
- if (clixon_xml2cbuf(cb, xt, 0, pretty, -1, 0) < 0)
- goto done;
- break;
+ if (clixon_xml2cbuf(cb, xt, 0, pretty, -1, 0) < 0)
+ goto done;
+ break;
case YANG_DATA_JSON:
case YANG_PATCH_JSON:
- if (clixon_json2cbuf(cb, xt, pretty, 0, 0) < 0)
- goto done;
- break;
+ if (clixon_json2cbuf(cb, xt, pretty, 0, 0) < 0)
+ goto done;
+ break;
default:
- break;
+ break;
}
if (restconf_reply_send(req, 200, cb, 0) < 0)
- goto done;
+ goto done;
cb = NULL;
retval = 0;
done:
if (cb)
cbuf_free(cb);
if (xt)
- xml_free(xt);
+ xml_free(xt);
return retval;
}
@@ -324,15 +324,15 @@ api_yang_library_version(clicon_handle h,
*/
static int
api_data(clicon_handle h,
- void *req,
- char *api_path,
- cvec *pcvec,
- int pi,
- cvec *qvec,
- char *data,
- int pretty,
- restconf_media media_out,
- ietf_ds_t ds)
+ void *req,
+ char *api_path,
+ cvec *pcvec,
+ int pi,
+ cvec *qvec,
+ char *data,
+ int pretty,
+ restconf_media media_out,
+ ietf_ds_t ds)
{
int retval = -1;
int read_only = 0, dynamic = 0;
@@ -346,53 +346,53 @@ api_data(clicon_handle h,
/* https://tools.ietf.org/html/rfc8527#section-3.2 */
/* We assume that dynamic datastores are read only at this time 20201105 */
if (IETF_DS_DYNAMIC == ds)
- dynamic = 1;
+ dynamic = 1;
if ((IETF_DS_INTENDED == ds) || (IETF_DS_RUNNING == ds)
|| (IETF_DS_DYNAMIC == ds) || (IETF_DS_OPERATIONAL == ds)) {
- read_only = 1;
+ read_only = 1;
}
if (strcmp(request_method, "OPTIONS")==0)
- retval = api_data_options(h, req);
+ retval = api_data_options(h, req);
else if (strcmp(request_method, "HEAD")==0) {
- if (dynamic)
+ if (dynamic)
retval = restconf_method_notallowed(h, req, "GET,POST", pretty, media_out);
- else
- retval = api_data_head(h, req, api_path, pi, qvec, pretty, media_out, ds);
+ else
+ retval = api_data_head(h, req, api_path, pi, qvec, pretty, media_out, ds);
}
else if (strcmp(request_method, "GET")==0) {
- retval = api_data_get(h, req, api_path, pi, qvec, pretty, media_out, ds);
+ retval = api_data_get(h, req, api_path, pi, qvec, pretty, media_out, ds);
}
else if (strcmp(request_method, "POST")==0) {
- retval = api_data_post(h, req, api_path, pi, qvec, data, pretty, restconf_content_type(h), media_out, ds);
+ retval = api_data_post(h, req, api_path, pi, qvec, data, pretty, restconf_content_type(h), media_out, ds);
}
else if (strcmp(request_method, "PUT")==0) {
- if (read_only)
+ if (read_only)
retval = restconf_method_notallowed(h, req, "GET,POST", pretty, media_out);
- else
- retval = api_data_put(h, req, api_path, pi, qvec, data, pretty, media_out, ds);
+ else
+ retval = api_data_put(h, req, api_path, pi, qvec, data, pretty, media_out, ds);
}
else if (strcmp(request_method, "PATCH")==0) {
- if (read_only) {
+ if (read_only) {
retval = restconf_method_notallowed(h, req, "GET,POST", pretty, media_out);
- }
- retval = api_data_patch(h, req, api_path, pi, qvec, data, pretty, media_out, ds);
+ }
+ retval = api_data_patch(h, req, api_path, pi, qvec, data, pretty, media_out, ds);
}
else if (strcmp(request_method, "DELETE")==0) {
- if (read_only)
+ if (read_only)
retval = restconf_method_notallowed(h, req, "GET,POST", pretty, media_out);
- else
- retval = api_data_delete(h, req, api_path, pi, pretty, media_out, ds);
+ else
+ retval = api_data_delete(h, req, api_path, pi, pretty, media_out, ds);
}
else{
- if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid HTTP data method") < 0)
- goto done;
- retval = api_return_err0(h, req, xerr, pretty, media_out, 0);
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid HTTP data method") < 0)
+ goto done;
+ retval = api_return_err0(h, req, xerr, pretty, media_out, 0);
}
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
done:
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
return retval;
}
@@ -409,33 +409,33 @@ api_data(clicon_handle h,
*/
static int
api_operations(clicon_handle h,
- void *req,
- char *request_method,
- char *path,
- cvec *pcvec,
- int pi,
- cvec *qvec,
- char *data,
- int pretty,
- restconf_media media_out)
+ void *req,
+ char *request_method,
+ char *path,
+ cvec *pcvec,
+ int pi,
+ cvec *qvec,
+ char *data,
+ int pretty,
+ restconf_media media_out)
{
int retval = -1;
cxobj *xerr = NULL;
clicon_debug(1, "%s", __FUNCTION__);
if (strcmp(request_method, "GET")==0)
- retval = api_operations_get(h, req, path, pi, qvec, data, pretty, media_out);
+ retval = api_operations_get(h, req, path, pi, qvec, data, pretty, media_out);
else if (strcmp(request_method, "POST")==0)
- retval = api_operations_post(h, req, path, pi, qvec, data,
- pretty, media_out);
+ retval = api_operations_post(h, req, path, pi, qvec, data,
+ pretty, media_out);
else{
- if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid HTTP operations method") < 0)
- goto done;
- retval = api_return_err0(h, req, xerr, pretty, media_out, 0);
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid HTTP operations method") < 0)
+ goto done;
+ retval = api_return_err0(h, req, xerr, pretty, media_out, 0);
}
done:
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
return retval;
}
@@ -447,8 +447,8 @@ api_operations(clicon_handle h,
*/
int
api_root_restconf(clicon_handle h,
- void *req,
- cvec *qvec)
+ void *req,
+ cvec *qvec)
{
int retval = -1;
char *request_method = NULL; /* GET,.. */
@@ -468,12 +468,12 @@ api_root_restconf(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (req == NULL){
- errno = EINVAL;
- goto done;
+ errno = EINVAL;
+ goto done;
}
request_method = restconf_param_get(h, "REQUEST_METHOD");
if ((path = restconf_uripath(h)) == NULL)
- goto done;
+ goto done;
pretty = restconf_pretty_get(h);
/* Get media for output (proactive negotiation) RFC7231 by using
* Accept:. This is for methods that have output, such as GET,
@@ -482,57 +482,57 @@ api_root_restconf(clicon_handle h,
*/
if ((media_str = restconf_param_get(h, "HTTP_ACCEPT")) == NULL){
#if 0 /* Use default +json */
- if (restconf_not_acceptable(h, r, pretty, media_out) < 0)
- goto done;
- goto ok;
+ if (restconf_not_acceptable(h, r, pretty, media_out) < 0)
+ goto done;
+ goto ok;
#endif
}
else if ((int)(media_out = restconf_media_str2int(media_str)) == -1){
- if (strcmp(media_str, "*/*") == 0) /* catch-all */
- media_out = YANG_DATA_JSON;
- else{
- if (restconf_not_acceptable(h, req, pretty, YANG_DATA_JSON) < 0)
- goto done;
- goto ok;
- }
+ if (strcmp(media_str, "*/*") == 0) /* catch-all */
+ media_out = YANG_DATA_JSON;
+ else{
+ if (restconf_not_acceptable(h, req, pretty, YANG_DATA_JSON) < 0)
+ goto done;
+ goto ok;
+ }
}
clicon_debug(1, "%s ACCEPT: %s %s", __FUNCTION__, media_str, restconf_media_int2str(media_out));
if ((pvec = clicon_strsep(path, "/", &pn)) == NULL)
- goto done;
+ goto done;
/* Sanity check of path. Should be /restconf/ */
if (pn < 2){
- if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, /restconf/ expected") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, /restconf/ expected") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
if (strlen(pvec[0]) != 0){
- if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, restconf api root expected") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, restconf api root expected") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
if (pn == 2){
- retval = api_root_restconf_exact(h, req, request_method, pretty, media_out);
- goto done;
+ retval = api_root_restconf_exact(h, req, request_method, pretty, media_out);
+ goto done;
}
if ((api_resource = pvec[2]) == NULL){
- if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, /restconf/ expected") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, /restconf/ expected") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
clicon_debug(1, "%s: api_resource=%s", __FUNCTION__, api_resource);
if (uri_str2cvec(path, '/', '=', 1, &pcvec) < 0) /* rest url eg /album=ricky/foo */
goto done;
/* data */
if ((cb = restconf_get_indata(req)) == NULL) /* XXX NYI ACTUALLY not always needed, do this later? */
- goto done;
+ goto done;
indata = cbuf_get(cb);
clicon_debug(1, "%s DATA=%s", __FUNCTION__, indata);
@@ -544,69 +544,69 @@ api_root_restconf(clicon_handle h,
* See RFC 8040 section 2.5
*/
if ((ret = restconf_authentication_cb(h, req, pretty, media_out)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto ok;
+ goto ok;
if (strcmp(api_resource, "yang-library-version")==0){
- if (api_yang_library_version(h, req, pretty, media_out) < 0)
- goto done;
+ if (api_yang_library_version(h, req, pretty, media_out) < 0)
+ goto done;
}
else if (strcmp(api_resource, NETCONF_OUTPUT_DATA) == 0){ /* restconf, skip /api/data */
- if (api_data(h, req, path, pcvec, 2, qvec, indata,
- pretty, media_out, IETF_DS_NONE) < 0)
- goto done;
+ if (api_data(h, req, path, pcvec, 2, qvec, indata,
+ pretty, media_out, IETF_DS_NONE) < 0)
+ goto done;
}
else if (strcmp(api_resource, "ds") == 0) {
- /* We should really be getting the supported datastore types from the
- * application model, but at this time the datastore model of startup/
- * running/cadidate is hardcoded into the clixon implementation. 20201104 */
- ietf_ds_t ds = IETF_DS_NONE;
+ /* We should really be getting the supported datastore types from the
+ * application model, but at this time the datastore model of startup/
+ * running/cadidate is hardcoded into the clixon implementation. 20201104 */
+ ietf_ds_t ds = IETF_DS_NONE;
- if (4 > pn) { /* Malformed request, no "ietf-datastores:" component */
- if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, No ietf-datastores: component") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (4 > pn) { /* Malformed request, no "ietf-datastores:" component */
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, No ietf-datastores: component") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
- /* Assign ds; See https://tools.ietf.org/html/rfc8342#section-7 */
- if (0 == strcmp(pvec[3], "ietf-datastores:running"))
- ds = IETF_DS_RUNNING;
+ /* Assign ds; See https://tools.ietf.org/html/rfc8342#section-7 */
+ if (0 == strcmp(pvec[3], "ietf-datastores:running"))
+ ds = IETF_DS_RUNNING;
else if (0 == strcmp(pvec[3], "ietf-datastores:candidate"))
- ds = IETF_DS_CANDIDATE;
+ ds = IETF_DS_CANDIDATE;
else if (0 == strcmp(pvec[3], "ietf-datastores:startup"))
- ds = IETF_DS_STARTUP;
+ ds = IETF_DS_STARTUP;
else if (0 == strcmp(pvec[3], "ietf-datastores:operational")) {
/* See https://tools.ietf.org/html/rfc8527#section-3.1
- * https://tools.ietf.org/html/rfc8342#section-5.3 */
- if (0 > api_operational_state(h, req, request_method, pretty, media_out)) {
+ * https://tools.ietf.org/html/rfc8342#section-5.3 */
+ if (0 > api_operational_state(h, req, request_method, pretty, media_out)) {
goto done;
}
- goto ok;
+ goto ok;
}
else { /* Malformed request, unsupported datastore type */
- if (netconf_invalid_value_xml(&xerr, "protocol", "Unsupported datastore type") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
- }
- /* ds is assigned at this point */
- if (0 > api_data(h, req, path, pcvec, 3, qvec, indata, pretty, media_out, ds))
- goto done;
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Unsupported datastore type") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
+ }
+ /* ds is assigned at this point */
+ if (0 > api_data(h, req, path, pcvec, 3, qvec, indata, pretty, media_out, ds))
+ goto done;
}
else if (strcmp(api_resource, "operations") == 0){ /* rpc */
- if (api_operations(h, req, request_method, path, pcvec, 2, qvec, indata,
- pretty, media_out) < 0)
- goto done;
+ if (api_operations(h, req, request_method, path, pcvec, 2, qvec, indata,
+ pretty, media_out) < 0)
+ goto done;
}
else{
- if (netconf_invalid_value_xml(&xerr, "protocol", "API-resource type") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (netconf_invalid_value_xml(&xerr, "protocol", "API-resource type") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
ok:
retval = 0;
@@ -614,18 +614,18 @@ api_root_restconf(clicon_handle h,
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
#ifdef WITH_RESTCONF_FCGI
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
#endif
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (username)
- free(username);
+ free(username);
if (pcvec)
- cvec_free(pcvec);
+ cvec_free(pcvec);
if (pvec)
- free(pvec);
+ free(pvec);
if (path)
- free(path);
+ free(path);
return retval;
}
diff --git a/apps/restconf/restconf_stream_fcgi.c b/apps/restconf/restconf_stream_fcgi.c
index 45014309..449ebffa 100644
--- a/apps/restconf/restconf_stream_fcgi.c
+++ b/apps/restconf/restconf_stream_fcgi.c
@@ -143,7 +143,7 @@ api_path_is_stream(clicon_handle h)
retval = 1;
done:
if (path)
- free(path);
+ free(path);
return retval;
}
@@ -157,20 +157,20 @@ api_path_is_stream(clicon_handle h)
*/
int
stream_child_free(clicon_handle h,
- int pid)
+ int pid)
{
struct stream_child *sc;
if ((sc = STREAM_CHILD) != NULL){
- do {
- if (pid == sc->sc_pid){
- DELQ(sc, STREAM_CHILD, struct stream_child *);
- FCGX_Free(&sc->sc_r, 0); /* XXX pointer to actual copied struct */
- free(sc);
- goto done;
- }
- sc = NEXTQ(struct stream_child *, sc);
- } while (sc && sc != STREAM_CHILD);
+ do {
+ if (pid == sc->sc_pid){
+ DELQ(sc, STREAM_CHILD, struct stream_child *);
+ FCGX_Free(&sc->sc_r, 0); /* XXX pointer to actual copied struct */
+ free(sc);
+ goto done;
+ }
+ sc = NEXTQ(struct stream_child *, sc);
+ } while (sc && sc != STREAM_CHILD);
}
done:
return 0;
@@ -185,9 +185,9 @@ stream_child_freeall(clicon_handle h)
struct stream_child *sc;
while ((sc = STREAM_CHILD) != NULL){
- DELQ(sc, STREAM_CHILD, struct stream_child *);
- FCGX_Free(&sc->sc_r, 1); /* XXX pointer to actual copied struct */
- free(sc);
+ DELQ(sc, STREAM_CHILD, struct stream_child *);
+ FCGX_Free(&sc->sc_r, 1); /* XXX pointer to actual copied struct */
+ free(sc);
}
return 0;
}
@@ -199,7 +199,7 @@ stream_child_freeall(clicon_handle h)
*/
static int
restconf_stream_cb(int s,
- void *arg)
+ void *arg)
{
int retval = -1;
FCGX_Request *r = (FCGX_Request *)arg;
@@ -214,48 +214,48 @@ restconf_stream_cb(int s,
clicon_debug(1, "%s", __FUNCTION__);
/* get msg (this is the reason this function is called) */
if (clicon_msg_rcv(s, &reply, &eof) < 0){
- clicon_debug(1, "%s msg_rcv error", __FUNCTION__);
- goto done;
+ clicon_debug(1, "%s msg_rcv error", __FUNCTION__);
+ goto done;
}
clicon_debug(1, "%s msg: %s", __FUNCTION__, reply?reply->op_body:"null");
/* handle close from remote end: this will exit the client */
if (eof){
- clicon_debug(1, "%s eof", __FUNCTION__);
- clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
- errno = ESHUTDOWN;
- FCGX_FPrintF(r->out, "SHUTDOWN\r\n");
- FCGX_FPrintF(r->out, "\r\n");
- FCGX_FFlush(r->out);
- clixon_exit_set(1);
- goto done;
+ clicon_debug(1, "%s eof", __FUNCTION__);
+ clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
+ errno = ESHUTDOWN;
+ FCGX_FPrintF(r->out, "SHUTDOWN\r\n");
+ FCGX_FPrintF(r->out, "\r\n");
+ FCGX_FFlush(r->out);
+ clixon_exit_set(1);
+ goto done;
}
if ((ret = clicon_msg_decode(reply, NULL, NULL, &xtop, NULL)) < 0) /* XXX pass yang_spec */
- goto done;
+ goto done;
if (ret == 0){
- clicon_err(OE_XML, EFAULT, "Invalid notification");
- goto done;
+ clicon_err(OE_XML, EFAULT, "Invalid notification");
+ goto done;
}
/* create event */
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_PLUGIN, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_PLUGIN, errno, "cbuf_new");
+ goto done;
}
if ((xn = xpath_first(xtop, NULL, "notification")) == NULL)
- goto ok;
+ goto ok;
#ifdef notused
xt = xpath_first(xn, NULL, "eventTime");
if ((xe = xpath_first(xn, NULL, "event")) == NULL) /* event can depend on yang? */
- goto ok;
+ goto ok;
if (xt)
- FCGX_FPrintF(r->out, "M#id: %s\r\n", xml_body(xt));
+ FCGX_FPrintF(r->out, "M#id: %s\r\n", xml_body(xt));
else{ /* XXX */
- gettimeofday(&tv, NULL);
- FCGX_FPrintF(r->out, "M#id: %02d:0\r\n", tv.tv_sec);
+ gettimeofday(&tv, NULL);
+ FCGX_FPrintF(r->out, "M#id: %02d:0\r\n", tv.tv_sec);
}
#endif
if (clixon_xml2cbuf(cb, xn, 0, pretty, -1, 0) < 0)
- goto done;
+ goto done;
FCGX_FPrintF(r->out, "data: %s\r\n", cbuf_get(cb));
FCGX_FPrintF(r->out, "\r\n");
FCGX_FFlush(r->out);
@@ -264,11 +264,11 @@ restconf_stream_cb(int s,
done:
clicon_debug(1, "%s retval: %d", __FUNCTION__, retval);
if (xtop != NULL)
- xml_free(xtop);
+ xml_free(xtop);
if (reply)
- free(reply);
+ free(reply);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -283,12 +283,12 @@ restconf_stream_cb(int s,
*/
static int
restconf_stream(clicon_handle h,
- void *req,
- char *name,
- cvec *qvec,
- int pretty,
- restconf_media media_out,
- int *sp)
+ void *req,
+ char *name,
+ cvec *qvec,
+ int pretty,
+ restconf_media media_out,
+ int *sp)
{
int retval = -1;
cxobj *xret = NULL;
@@ -302,55 +302,55 @@ restconf_stream(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
*sp = -1;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
cprintf(cb, "%s ",
- NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR, EVENT_RFC5277_NAMESPACE, name);
+ NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR, EVENT_RFC5277_NAMESPACE, name);
/* Print all fields */
for (i=0; i");
- cv2cbuf(cv, cb);
- cprintf(cb, " ");
- }
- else if (strcmp(vname, "stop-time") == 0){
- cprintf(cb, "");
- cv2cbuf(cv, cb);
- cprintf(cb, " ");
- }
+ vname = cv_name_get(cv);
+ if (strcmp(vname, "start-time") == 0){
+ cprintf(cb, "");
+ cv2cbuf(cv, cb);
+ cprintf(cb, " ");
+ }
+ else if (strcmp(vname, "stop-time") == 0){
+ cprintf(cb, "");
+ cv2cbuf(cv, cb);
+ cprintf(cb, " ");
+ }
}
cprintf(cb, "]]>]]>");
if (clicon_rpc_netconf(h, cbuf_get(cb), &xret, &s) < 0)
- goto done;
+ goto done;
if ((xe = xpath_first(xret, NULL, "rpc-reply/rpc-error")) != NULL){
- if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
/* Setting up stream */
if (restconf_reply_header(req, "Content-Type", "text/event-stream") < 0)
- goto done;
+ goto done;
if (restconf_reply_header(req, "Cache-Control", "no-cache") < 0)
- goto done;
+ goto done;
if (restconf_reply_header(req, "Connection", "keep-alive") < 0)
- goto done;
+ goto done;
if (restconf_reply_header(req, "X-Accel-Buffering", "no") < 0)
- goto done;
+ goto done;
if (restconf_reply_send(req, 201, NULL, 0) < 0)
- goto done;
+ goto done;
*sp = s;
ok:
retval = 0;
done:
clicon_debug(1, "%s retval: %d", __FUNCTION__, retval);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -364,21 +364,21 @@ restconf_stream(clicon_handle h,
*/
static int
stream_checkuplink(int s,
- void *arg)
+ void *arg)
{
FCGX_Request *r = (FCGX_Request *)arg;
clicon_debug(1, "%s", __FUNCTION__);
if (FCGX_GetError(r->out) != 0){ /* break loop */
- clicon_debug(1, "%s FCGX_GetError upstream", __FUNCTION__);
- clixon_exit_set(1);
+ clicon_debug(1, "%s FCGX_GetError upstream", __FUNCTION__);
+ clixon_exit_set(1);
}
return 0;
}
int
stream_timeout(int s,
- void *arg)
+ void *arg)
{
struct timeval t;
struct timeval t1;
@@ -386,14 +386,14 @@ stream_timeout(int s,
clicon_debug(1, "%s", __FUNCTION__);
if (FCGX_GetError(r->out) != 0){ /* break loop */
- clicon_debug(1, "%s FCGX_GetError upstream", __FUNCTION__);
- clixon_exit_set(1);
+ clicon_debug(1, "%s FCGX_GetError upstream", __FUNCTION__);
+ clixon_exit_set(1);
}
else{
- gettimeofday(&t, NULL);
- t1.tv_sec = 1; t1.tv_usec = 0;
- timeradd(&t, &t1, &t);
- clixon_event_reg_timeout(t, stream_timeout, arg, "Stream timeout");
+ gettimeofday(&t, NULL);
+ t1.tv_sec = 1; t1.tv_usec = 0;
+ timeradd(&t, &t1, &t);
+ clixon_event_reg_timeout(t, stream_timeout, arg, "Stream timeout");
}
return 0;
}
@@ -402,13 +402,13 @@ stream_timeout(int s,
* @param[in] h Clicon handle
* @param[in] req Generic Www handle (can be part of clixon handle)
* @param[in] qvec Query parameters, ie the ?=&= stuff
- * @param[out] finish Set to zero, if request should not be finnished by upper layer
+ * @param[out] finish Set to zero, if request should not be finnished by upper layer
*/
int
api_stream(clicon_handle h,
- void *req,
- cvec *qvec,
- int *finish)
+ void *req,
+ cvec *qvec,
+ int *finish)
{
int retval = -1;
FCGX_Request *rfcgi = (FCGX_Request *)req; /* XXX */
@@ -434,46 +434,46 @@ api_stream(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
streampath = clicon_option_str(h, "CLICON_STREAM_PATH");
if ((path = restconf_uripath(h)) == NULL)
- goto done;
+ goto done;
pretty = restconf_pretty_get(h);
if ((pvec = clicon_strsep(path, "/", &pn)) == NULL)
- goto done;
+ goto done;
/* Sanity check of path. Should be /stream/ */
if (pn != 3){
- if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, /stream/ expected") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, /stream/ expected") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
if (strlen(pvec[0]) != 0){
- if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, /stream/ expected") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, /stream/ expected") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
if (strcmp(pvec[1], streampath)){
- if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, /stream/ expected") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, /stream/ expected") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
if ((method = pvec[2]) == NULL){
- if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, /stream/ expected") < 0)
- goto done;
- if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
- goto done;
- goto ok;
+ if (netconf_invalid_value_xml(&xerr, "protocol", "Invalid path, /stream/ expected") < 0)
+ goto done;
+ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
+ goto done;
+ goto ok;
}
clicon_debug(1, "%s: method=%s", __FUNCTION__, method);
if (uri_str2cvec(path, '/', '=', 1, &pcvec) < 0) /* rest url eg /album=ricky/foo */
- goto done;
+ goto done;
/* data */
if ((cb = restconf_get_indata(req)) == NULL)
- goto done;
+ goto done;
indata = cbuf_get(cb);
clicon_debug(1, "%s DATA=%s", __FUNCTION__, indata);
@@ -481,71 +481,71 @@ api_stream(clicon_handle h,
* See RFC 8040 section 2.5
*/
if ((ret = restconf_authentication_cb(h, req, pretty, media_out)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto ok;
+ goto ok;
if (restconf_stream(h, req, method, qvec, pretty, media_out, &s) < 0)
- goto done;
+ goto done;
if (s != -1){
#ifdef STREAM_FORK
- if ((pid = fork()) == 0){ /* child */
- if (pvec)
- free(pvec);
- if (qvec)
- cvec_free(qvec);
- if (pcvec)
- cvec_free(pcvec);
- if (cb)
- cbuf_free(cb);
- if (cbret)
- cbuf_free(cbret);
+ if ((pid = fork()) == 0){ /* child */
+ if (pvec)
+ free(pvec);
+ if (qvec)
+ cvec_free(qvec);
+ if (pcvec)
+ cvec_free(pcvec);
+ if (cb)
+ cbuf_free(cb);
+ if (cbret)
+ cbuf_free(cbret);
#endif /* STREAM_FORK */
- /* Listen to backend socket */
- if (clixon_event_reg_fd(s,
- restconf_stream_cb,
- req,
- "stream socket") < 0)
- goto done;
- if (clixon_event_reg_fd(rfcgi->listen_sock,
- stream_checkuplink,
- req,
- "stream socket") < 0)
- goto done;
- clicon_debug(1, "%s before loop", __FUNCTION__);
- /* Poll upstream errors */
- stream_timeout(0, req);
- /* Start loop */
- clixon_event_loop(h);
- clicon_debug(1, "%s after loop", __FUNCTION__);
- clicon_rpc_close_session(h);
- clixon_event_unreg_fd(s, restconf_stream_cb);
- close(s);
- clixon_event_unreg_fd(rfcgi->listen_sock,
- restconf_stream_cb);
- clixon_event_unreg_timeout(stream_timeout, (void*)req);
- clixon_exit_set(0); /* reset */
+ /* Listen to backend socket */
+ if (clixon_event_reg_fd(s,
+ restconf_stream_cb,
+ req,
+ "stream socket") < 0)
+ goto done;
+ if (clixon_event_reg_fd(rfcgi->listen_sock,
+ stream_checkuplink,
+ req,
+ "stream socket") < 0)
+ goto done;
+ clicon_debug(1, "%s before loop", __FUNCTION__);
+ /* Poll upstream errors */
+ stream_timeout(0, req);
+ /* Start loop */
+ clixon_event_loop(h);
+ clicon_debug(1, "%s after loop", __FUNCTION__);
+ clicon_rpc_close_session(h);
+ clixon_event_unreg_fd(s, restconf_stream_cb);
+ close(s);
+ clixon_event_unreg_fd(rfcgi->listen_sock,
+ restconf_stream_cb);
+ clixon_event_unreg_timeout(stream_timeout, (void*)req);
+ clixon_exit_set(0); /* reset */
#ifdef STREAM_FORK
#if 0 /* Seems to be a global resource, but there is till some timing error here */
- FCGX_Finish_r(rfcgi);
- FCGX_Free(rfcgi, 0);
+ FCGX_Finish_r(rfcgi);
+ FCGX_Free(rfcgi, 0);
#endif
- restconf_terminate(h);
- exit(0);
- }
- /* parent */
- /* Create stream_child struct and store pid and FCGI data, when child
- * killed, call FCGX_Free
- */
- if ((sc = malloc(sizeof(struct stream_child))) == NULL){
- clicon_err(OE_XML, errno, "malloc");
- goto done;
- }
- memset(sc, 0, sizeof(struct stream_child));
- sc->sc_pid = pid;
- sc->sc_r = *rfcgi; /* XXX by value */
+ restconf_terminate(h);
+ exit(0);
+ }
+ /* parent */
+ /* Create stream_child struct and store pid and FCGI data, when child
+ * killed, call FCGX_Free
+ */
+ if ((sc = malloc(sizeof(struct stream_child))) == NULL){
+ clicon_err(OE_XML, errno, "malloc");
+ goto done;
+ }
+ memset(sc, 0, sizeof(struct stream_child));
+ sc->sc_pid = pid;
+ sc->sc_r = *rfcgi; /* XXX by value */
- ADDQ(sc, STREAM_CHILD);
- *finish = 0; /* If spawn child, we should not finish this stream */
+ ADDQ(sc, STREAM_CHILD);
+ *finish = 0; /* If spawn child, we should not finish this stream */
#endif /* STREAM_FORK */
}
ok:
@@ -553,16 +553,16 @@ api_stream(clicon_handle h,
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (pvec)
- free(pvec);
+ free(pvec);
if (pcvec)
- cvec_free(pcvec);
+ cvec_free(pcvec);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (cbret)
- cbuf_free(cbret);
+ cbuf_free(cbret);
if (path)
- free(path);
+ free(path);
return retval;
}
diff --git a/apps/snmp/snmp_handler.c b/apps/snmp/snmp_handler.c
index c113214d..4eca4ff2 100644
--- a/apps/snmp/snmp_handler.c
+++ b/apps/snmp/snmp_handler.c
@@ -44,7 +44,6 @@
#include
#include
#include
-#include
/* net-snmp */
#include
@@ -75,51 +74,51 @@
*/
static int
snmp_common_handler(netsnmp_mib_handler *handler,
- netsnmp_handler_registration *nhreg,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *request,
- int tablehandler,
- clixon_snmp_handle **shp)
+ netsnmp_handler_registration *nhreg,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *request,
+ int tablehandler,
+ clixon_snmp_handle **shp)
{
int retval = -1;
netsnmp_variable_list *requestvb; /* sub of request */
cbuf *cb = NULL;
if (request == NULL || shp == NULL){
- clicon_err(OE_XML, EINVAL, "request or shp is null");
- goto done;
+ clicon_err(OE_XML, EINVAL, "request or shp is null");
+ goto done;
}
requestvb = request->requestvb;
if ((*shp = (clixon_snmp_handle*)handler->myvoid) == NULL){
- clicon_err(OE_XML, 0, "No myvoid handler");
- goto done;
+ clicon_err(OE_XML, 0, "No myvoid handler");
+ goto done;
}
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
oid_cbuf(cb, (*shp)->sh_oid, (*shp)->sh_oidlen);
if (oid_eq(requestvb->name, requestvb->name_length,
- (*shp)->sh_oid, (*shp)->sh_oidlen) == 0){ /* equal */
- clicon_debug(1, "%s \"%s\" %s inclusive:%d %s", __FUNCTION__,
- cbuf_get(cb),
- snmp_msg_int2str(reqinfo->mode),
- request->inclusive, tablehandler?"table":"scalar");
+ (*shp)->sh_oid, (*shp)->sh_oidlen) == 0){ /* equal */
+ clicon_debug(1, "%s \"%s\" %s inclusive:%d %s", __FUNCTION__,
+ cbuf_get(cb),
+ snmp_msg_int2str(reqinfo->mode),
+ request->inclusive, tablehandler?"table":"scalar");
}
else{ /* not equal */
- cprintf(cb, " (");
- oid_cbuf(cb, requestvb->name, requestvb->name_length);
- cprintf(cb, ")");
- // nhreg->rootoid same as shp
- clicon_debug(1, "%s \"%s\" %s inclusive:%d %s", __FUNCTION__,
- cbuf_get(cb),
- snmp_msg_int2str(reqinfo->mode),
- request->inclusive, tablehandler?"table":"scalar");
+ cprintf(cb, " (");
+ oid_cbuf(cb, requestvb->name, requestvb->name_length);
+ cprintf(cb, ")");
+ // nhreg->rootoid same as shp
+ clicon_debug(1, "%s \"%s\" %s inclusive:%d %s", __FUNCTION__,
+ cbuf_get(cb),
+ snmp_msg_int2str(reqinfo->mode),
+ request->inclusive, tablehandler?"table":"scalar");
}
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -131,81 +130,82 @@ snmp_common_handler(netsnmp_mib_handler *handler,
*/
static int
snmp_scalar_return(cxobj *xs,
- yang_stmt *ys,
- oid *oidc,
- size_t oidclen,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *request)
+ yang_stmt *ys,
+ oid *oidc,
+ size_t oidclen,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *request)
{
int retval = -1;
int asn1type;
- char *xmlstr = NULL;
+ char *xmlstr = NULL;
char *defaultval = NULL;
u_char *snmpval = NULL;
size_t snmplen = 0;
char *reason = NULL;
netsnmp_variable_list *requestvb = request->requestvb;
int ret;
+ char *body = NULL;
/* SMI default value, How is this different from yang defaults?
*/
if (yang_extension_value(ys, "defval", IETF_YANG_SMIV2_NS, NULL, &defaultval) < 0)
- goto done;
- if (xs != NULL){
- if ((ret = type_xml2snmp_pre(xml_body(xs), ys, &xmlstr)) < 0)
- goto done;
- if (ret == 0){
- if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
- goto done;
- }
- goto ok;
- }
+ goto done;
+ if (xs != NULL && (body = xml_body(xs)) != NULL){
+ if ((ret = type_xml2snmp_pre(body, ys, &xmlstr)) < 0) // XXX <---
+ goto done;
+ if (ret == 0){
+ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){
+ clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
+ goto done;
+ }
+ goto ok;
+ }
}
else if (defaultval != NULL){
- if ((xmlstr = strdup(defaultval)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
+ if ((xmlstr = strdup(defaultval)) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
}
else{
- if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
- goto done;
- }
- goto ok;
+ if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){
+ clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
+ goto done;
+ }
+ goto ok;
}
if (type_yang2asn1(ys, &asn1type, 1) < 0)
- goto done;
+ goto done;
if ((ret = type_xml2snmp(xmlstr, &asn1type, &snmpval, &snmplen, &reason)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- clicon_debug(1, "%s %s", __FUNCTION__, reason);
- if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
- goto done;
- }
- goto ok;
+ clicon_debug(1, "%s %s", __FUNCTION__, reason);
+ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
+ clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
+ goto done;
+ }
+ goto ok;
}
/* see snmplib/snmp_client. somewhat indirect
*/
if ((ret = snmp_set_var_typed_value(requestvb, asn1type, snmpval, snmplen)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "snmp_set_var_typed_value");
- goto done;
+ clicon_err(OE_SNMP, ret, "snmp_set_var_typed_value");
+ goto done;
}
if ((ret = snmp_set_var_objid(requestvb, oidc, oidclen)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "snmp_set_var_objid");
- goto done;
+ clicon_err(OE_SNMP, ret, "snmp_set_var_objid");
+ goto done;
}
ok:
retval = 0;
done:
if (xmlstr)
- free(xmlstr);
+ free(xmlstr);
if (snmpval)
- free(snmpval);
+ free(snmpval);
if (reason)
- free(reason);
+ free(reason);
return retval;
}
@@ -222,11 +222,11 @@ snmp_scalar_return(cxobj *xs,
*/
static int
snmp_scalar_get(clicon_handle h,
- yang_stmt *ys,
- cvec *cvk,
- char *defaultval,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *request)
+ yang_stmt *ys,
+ cvec *cvk,
+ char *defaultval,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *request)
{
int retval = -1;
cvec *nsc = NULL;
@@ -242,90 +242,90 @@ snmp_scalar_get(clicon_handle h,
char *reason = NULL;
netsnmp_variable_list *requestvb = request->requestvb;
cxobj *xcache = NULL;
+ char *body = NULL;
clicon_debug(1, "%s", __FUNCTION__);
/* Prepare backend call by constructing namespace context */
if (xml_nsctx_yang(ys, &nsc) < 0)
- goto done;
+ goto done;
/* Create xpath from yang */
if (snmp_yang2xpath(ys, cvk, &xpath) < 0)
- goto done;
+ goto done;
if (type_yang2asn1(ys, &asn1type, 1) < 0)
- goto done;
+ goto done;
/* First try cache */
clicon_ptr_get(h, "snmp-rowstatus-tree", (void**)&xcache);
if (xcache==NULL || (x = xpath_first(xcache, nsc, "%s", xpath)) == NULL){
- /* If not found do the backend call */
- if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, NULL, &xt) < 0)
- goto done;
- /* Detect error XXX Error handling could improve */
- if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
- clixon_netconf_error(xerr, "clicon_rpc_get", NULL);
- goto done;
- }
- x = xpath_first(xt, nsc, "%s", xpath);
+ /* If not found do the backend call */
+ if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, NULL, &xt) < 0)
+ goto done;
+ /* Detect error XXX Error handling could improve */
+ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
+ clixon_netconf_error(xerr, "clicon_rpc_get", NULL);
+ goto done;
+ }
+ x = xpath_first(xt, nsc, "%s", xpath);
}
/*
* The xml to snmp value conversion is done in two steps:
* 1. From XML to SNMP string, there is a special case for enumeration, and for default value
* 2. From SNMP string to SNMP binary value which invloves parsing
*/
- if (x != NULL){
- assert(xml_spec(x) == ys);
- if ((ret = type_xml2snmp_pre(xml_body(x), ys, &xmlstr)) < 0)
- goto done;
- if (ret == 0){
- if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
- goto done;
- }
- goto ok;
- }
+ if (x != NULL && (body = xml_body(x)) != NULL){
+ if ((ret = type_xml2snmp_pre(body, ys, &xmlstr)) < 0)
+ goto done;
+ if (ret == 0){
+ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){
+ clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
+ goto done;
+ }
+ goto ok;
+ }
}
else if (defaultval != NULL){
- if ((xmlstr = strdup(defaultval)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
+ if ((xmlstr = strdup(defaultval)) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
}
else{
- if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
- goto done;
- }
- goto ok;
+ if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){
+ clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
+ goto done;
+ }
+ goto ok;
}
if ((ret = type_xml2snmp(xmlstr, &asn1type, &snmpval, &snmplen, &reason)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- clicon_debug(1, "%s %s", __FUNCTION__, reason);
- if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
- goto done;
- }
- goto ok;
+ clicon_debug(1, "%s %s", __FUNCTION__, reason);
+ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
+ clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
+ goto done;
+ }
+ goto ok;
}
/* see snmplib/snmp_client. somewhat indirect
*/
if ((ret = snmp_set_var_typed_value(requestvb, asn1type, snmpval, snmplen)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "snmp_set_var_typed_value");
- goto done;
+ clicon_err(OE_SNMP, ret, "snmp_set_var_typed_value");
+ goto done;
}
ok:
retval = 0;
done:
if (reason)
- free(reason);
+ free(reason);
if (xmlstr)
- free(xmlstr);
+ free(xmlstr);
if (snmpval)
- free(snmpval);
+ free(snmpval);
if (xt)
- xml_free(xt);
+ xml_free(xt);
if (xpath)
- free(xpath);
+ free(xpath);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
return retval;
}
@@ -333,9 +333,9 @@ snmp_scalar_get(clicon_handle h,
*/
int
snmp_yang2xml(cxobj *xtop,
- yang_stmt *ys,
- cvec *cvk,
- cxobj **xbot)
+ yang_stmt *ys,
+ cvec *cvk,
+ cxobj **xbot)
{
int retval = -1;
cvec *cvk1 = NULL;
@@ -347,30 +347,30 @@ snmp_yang2xml(cxobj *xtop,
yspec = ys_spec(ys);
if (yang2api_path_fmt(ys, 0, &api_path_fmt) < 0)
- goto done;
+ goto done;
/* Need to prepend an element to fit api_path_fmt2api_path cvv parameter */
if ((cvk1 = cvec_new(1)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ goto done;
}
for (i=0; i active, createAndWait -> notInService
- */
- if (strcmp(valstr, "createAndGo") == 0){
- free(valstr);
- if ((valstr = strdup("active")) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- }
- else if (strcmp(valstr, "createAndWait") == 0){
- free(valstr);
- if ((valstr = strdup("notInService")) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- }
- else if (strcmp(valstr, "active") == 0){
- if (rowstatus == 5) /* createAndWait */
- if (snmp_cache_row_op(h, yang_parent_get(ys), cvk, "merge", 1) < 0)
- goto done;
- }
- else if (strcmp(valstr, "destroy") == 0){
- clicon_debug(1, "%s %d", __FUNCTION__, rowstatus);
- /* Dont send delete to backend if notInService(2) */
- if (snmp_cache_row_op(h, yang_parent_get(ys), cvk, "delete", rowstatus!=2) < 0)
- goto done;
- }
+ /* Special case translation of rowstatus values:
+ * createAndGo -> active, createAndWait -> notInService
+ */
+ if (strcmp(valstr, "createAndGo") == 0){
+ free(valstr);
+ if ((valstr = strdup("active")) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ }
+ else if (strcmp(valstr, "createAndWait") == 0){
+ free(valstr);
+ if ((valstr = strdup("notInService")) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ }
+ else if (strcmp(valstr, "active") == 0){
+ if (rowstatus == 5) /* createAndWait */
+ if (snmp_cache_row_op(h, yang_parent_get(ys), cvk, "merge", 1) < 0)
+ goto done;
+ }
+ else if (strcmp(valstr, "destroy") == 0){
+ clicon_debug(1, "%s %d", __FUNCTION__, rowstatus);
+ /* Dont send delete to backend if notInService(2) */
+ if (snmp_cache_row_op(h, yang_parent_get(ys), cvk, "delete", rowstatus!=2) < 0)
+ goto done;
+ }
}
if (xml_value_set(xb, valstr) < 0)
- goto done;
+ goto done;
clicon_ptr_get(h, "snmp-rowstatus-tree", (void**)&xcache);
if (xcache == NULL){
- if ((xcache = xml_new(NETCONF_INPUT_CONFIG, NULL, CX_ELMNT)) == NULL)
- goto done;
- clicon_ptr_set(h, "snmp-rowstatus-tree", xcache);
+ if ((xcache = xml_new(NETCONF_INPUT_CONFIG, NULL, CX_ELMNT)) == NULL)
+ goto done;
+ clicon_ptr_set(h, "snmp-rowstatus-tree", xcache);
}
if (!isrowstatus || strcmp(valstr, "destroy") != 0)
- if (xml_merge(xcache, xtop, yspec, NULL) < 0)
- goto done;
+ if (xml_merge(xcache, xtop, yspec, NULL) < 0)
+ goto done;
/* Special case: push active to clixon */
if (isrowstatus && strcmp(valstr, "active") == 0){
- if (snmp_scalar_set(h, ys,
- cvk,
- valstr,
- reqinfo,
- request) < 0)
- goto done;
+ if (snmp_scalar_set(h, ys,
+ cvk,
+ valstr,
+ reqinfo,
+ request) < 0)
+ goto done;
}
ok:
retval = 0;
done:
if (xtop)
- xml_free(xtop);
+ xml_free(xtop);
if (valstr)
- free(valstr);
+ free(valstr);
return retval;
}
@@ -644,10 +644,10 @@ snmp_cache_set(clicon_handle h,
*/
static int
snmp_table_rowstatus_get(clicon_handle h,
- yang_stmt *ys,
- yang_stmt *yrestype,
- cvec *cvk,
- int32_t *rowstatus)
+ yang_stmt *ys,
+ yang_stmt *yrestype,
+ cvec *cvk,
+ int32_t *rowstatus)
{
int retval = -1;
cvec *nsc = NULL;
@@ -662,38 +662,38 @@ snmp_table_rowstatus_get(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
/* Prepare backend call by constructing namespace context */
if (xml_nsctx_yang(ys, &nsc) < 0)
- goto done;
+ goto done;
/* Create xpath from yang */
if (snmp_yang2xpath(ys, cvk, &xpath) < 0)
- goto done;
+ goto done;
clicon_ptr_get(h, "snmp-rowstatus-tree", (void**)&xt);
if (xt && (xr = xpath_first(xt, nsc, "%s", xpath)) != NULL &&
- (body = xml_body(xr)) != NULL) {
- if ((ret = yang_enum2valstr(yrestype, body, &intstr)) < 0)
- goto done;
- if (ret == 0){
- clicon_debug(1, "%s %s invalid or not found", __FUNCTION__, body);
- *rowstatus = 0;
- }
- else {
- if ((ret = parse_int32(intstr, rowstatus, &reason)) < 0)
- goto done;
- if (ret == 0){
- clicon_debug(1, "%s parse_int32: %s", __FUNCTION__, reason);
- *rowstatus = 0;
- }
- }
+ (body = xml_body(xr)) != NULL) {
+ if ((ret = yang_enum2valstr(yrestype, body, &intstr)) < 0)
+ goto done;
+ if (ret == 0){
+ clicon_debug(1, "%s %s invalid or not found", __FUNCTION__, body);
+ *rowstatus = 0;
+ }
+ else {
+ if ((ret = parse_int32(intstr, rowstatus, &reason)) < 0)
+ goto done;
+ if (ret == 0){
+ clicon_debug(1, "%s parse_int32: %s", __FUNCTION__, reason);
+ *rowstatus = 0;
+ }
+ }
}
else
- *rowstatus = 0;
+ *rowstatus = 0;
retval = 0;
done:
if (xpath)
- free(xpath);
+ free(xpath);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (reason)
- free(reason);
+ free(reason);
return retval;
}
@@ -708,9 +708,9 @@ snmp_table_rowstatus_get(clicon_handle h,
*/
static int
clixon_snmp_scalar_handler1(netsnmp_mib_handler *handler,
- netsnmp_handler_registration *nhreg,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *request)
+ netsnmp_handler_registration *nhreg,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *request)
{
int retval = -1;
clixon_snmp_handle *sh = NULL;
@@ -720,49 +720,74 @@ clixon_snmp_scalar_handler1(netsnmp_mib_handler *handler,
clicon_debug(2, "%s", __FUNCTION__);
if (snmp_common_handler(handler, nhreg, reqinfo, request, 0, &sh) < 0)
- goto done;
+ goto done;
/* see net-snmp/agent/snmp_agent.h / net-snmp/library/snmp.h */
switch (reqinfo->mode) {
case MODE_GET: /* 160 */
- if (snmp_scalar_get(sh->sh_h, sh->sh_ys, sh->sh_cvk_orig,
- sh->sh_default, reqinfo, request) < 0)
- goto done;
+ if (snmp_scalar_get(sh->sh_h, sh->sh_ys, sh->sh_cvk_orig,
+ sh->sh_default, reqinfo, request) < 0)
+ goto done;
break;
case MODE_GETNEXT: /* 161 */
- assert(0); // Not seen?
- break;
+ break;
case MODE_SET_RESERVE1: /* 0 */
- /* Translate from YANG ys leaf type to SNMP asn1.1 type ids (not value), also cvtype */
- if (type_yang2asn1(sh->sh_ys, &asn1_type, 0) < 0)
- goto done;
+ if (!yang_config_ancestor(sh->sh_ys) ||
+ nhreg->modes == HANDLER_CAN_RONLY){
+ netsnmp_request_set_error(request, SNMP_ERR_NOTWRITABLE);
+ goto done;
+ }
+ /* Translate from YANG ys leaf type to SNMP asn1.1 type ids (not value), also cvtype */
+ if (type_yang2asn1(sh->sh_ys, &asn1_type, 0) < 0)
+ goto done;
if (requestvb->type != asn1_type){
- clicon_debug(1, "%s Expected type:%d, got: %d", __FUNCTION__, requestvb->type, asn1_type);
- if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
- goto ok;
- }
- }
+ clicon_debug(1, "%s Expected type:%d, got: %d", __FUNCTION__, requestvb->type, asn1_type);
+ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
+ clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
+ goto ok;
+ }
+ }
break;
case MODE_SET_RESERVE2: /* 1 */
break;
case MODE_SET_ACTION: /* 2 */
- if (snmp_scalar_set(sh->sh_h, sh->sh_ys, NULL, NULL, reqinfo, request) < 0)
- goto done;
+ if (snmp_scalar_set(sh->sh_h, sh->sh_ys, NULL, NULL, reqinfo, request) < 0)
+ goto done;
+ /*
+ * There does not seem to be a separate validation action and commit does not
+ * return an error.
+ * Therefore validation is done here directly as well as discard if it fails.
+ */
+ if ((ret = clicon_rpc_validate(sh->sh_h, "candidate")) < 0)
+ goto done;
+ if (ret == 0){
+ clicon_rpc_discard_changes(sh->sh_h);
+ netsnmp_request_set_error(request, SNMP_ERR_COMMITFAILED);
+ goto done;
+ }
break;
case MODE_SET_COMMIT: /* 3 */
- if (clicon_rpc_commit(sh->sh_h) < 0)
- goto done;
- break;
+ if ((ret = clicon_rpc_commit(sh->sh_h, 0, 0, 0, NULL, NULL)) < 0)
+ goto done;
+ if (ret == 0){
+ /* Note that error given in commit is not propagated to the snmp client,
+ * therefore validation is in the ACTION instead
+ */
+ clicon_rpc_discard_changes(sh->sh_h);
+ netsnmp_request_set_error(request, SNMP_ERR_COMMITFAILED);
+ goto done;
+ }
+ break;
case MODE_SET_FREE: /* 4 */
break;
case MODE_SET_UNDO: /* 5 */
- if (clicon_rpc_discard_changes(sh->sh_h) < 0)
- goto done;
+ if (clicon_rpc_discard_changes(sh->sh_h) < 0)
+ goto done;
break;
}
ok:
retval = SNMP_ERR_NOERROR;
done:
+ clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
return retval;
}
@@ -776,9 +801,9 @@ clixon_snmp_scalar_handler1(netsnmp_mib_handler *handler,
*/
int
clixon_snmp_scalar_handler(netsnmp_mib_handler *handler,
- netsnmp_handler_registration *nhreg,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *requests)
+ netsnmp_handler_registration *nhreg,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
{
int retval = -1;
netsnmp_request_info *req;
@@ -786,12 +811,12 @@ clixon_snmp_scalar_handler(netsnmp_mib_handler *handler,
clicon_debug(1, "%s", __FUNCTION__);
for (req = requests; req; req = req->next){
- ret = clixon_snmp_scalar_handler1(handler, nhreg, reqinfo, req);
- if (ret != SNMP_ERR_NOERROR){
- retval = ret;
- goto done;
- break;
- }
+ ret = clixon_snmp_scalar_handler1(handler, nhreg, reqinfo, req);
+ if (ret != SNMP_ERR_NOERROR){
+ retval = ret;
+ goto done;
+ break;
+ }
}
retval = SNMP_ERR_NOERROR;
done:
@@ -817,13 +842,13 @@ clixon_snmp_scalar_handler(netsnmp_mib_handler *handler,
*/
static int
snmp_table_get(clicon_handle h,
- yang_stmt *yt,
- oid *oidt,
- size_t oidtlen,
- oid *oids,
- size_t oidslen,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *request)
+ yang_stmt *yt,
+ oid *oidt,
+ size_t oidtlen,
+ oid *oids,
+ size_t oidslen,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *request)
{
int retval = -1;
oid oidleaf[MAX_OID_LEN] = {0,}; /* Leaf */
@@ -843,69 +868,69 @@ snmp_table_get(clicon_handle h,
/* Get yang of leaf from first part of OID */
ys = NULL;
while ((ys = yn_each(yt, ys)) != NULL) {
- if (yang_keyword_get(ys) != Y_LEAF)
- continue;
- /* reset oid */
- oidleaflen = MAX_OID_LEN;
- if ((ret = yangext_oid_get(ys, oidleaf, &oidleaflen, NULL)) < 0)
- goto done;
- if (ret == 0)
- goto done;
- if (oidtlen + 1 != oidleaflen) /* Indexes may be from other OID scope, skip those */
- continue;
- if (oids[oidleaflen-1] == oidleaf[oidleaflen-1])
- break;
+ if (yang_keyword_get(ys) != Y_LEAF)
+ continue;
+ /* reset oid */
+ oidleaflen = MAX_OID_LEN;
+ if ((ret = yangext_oid_get(ys, oidleaf, &oidleaflen, NULL)) < 0)
+ goto done;
+ if (ret == 0)
+ goto done;
+ if (oidtlen + 1 != oidleaflen) /* Indexes may be from other OID scope, skip those */
+ continue;
+ if (oids[oidleaflen-1] == oidleaf[oidleaflen-1])
+ break;
}
if (ys == NULL){
- /* No leaf with matching OID */
- goto fail;
+ /* No leaf with matching OID */
+ goto fail;
}
/* SMI default value, How is this different from yang defaults?
*/
if (yang_extension_value(ys, "defval", IETF_YANG_SMIV2_NS, NULL, &defaultval) < 0)
- goto done;
+ goto done;
/* Create xpath with right keys from later part of OID
* Inverse of snmp_str2oid
*/
if ((cvk_orig = yang_cvec_get(yt)) == NULL){
- clicon_err(OE_YANG, 0, "No keys");
- goto done;
+ clicon_err(OE_YANG, 0, "No keys");
+ goto done;
}
if ((cvk_val = cvec_dup(cvk_orig)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_dup");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_dup");
+ goto done;
}
/* read through keys and create cvk */
oidilen = oidslen-(oidtlen+1);
oidi = oids+oidtlen+1;
/* Add keys */
for (i=0; irequestvb;
if (requestvb->type != asn1_type){
- clicon_debug(1, "%s Expected type:%d, got: %d", __FUNCTION__, requestvb->type, asn1_type);
- if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
- goto ok;
- }
+ clicon_debug(1, "%s Expected type:%d, got: %d", __FUNCTION__, requestvb->type, asn1_type);
+ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
+ clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
+ goto ok;
+ }
}
/* Create xpath with right keys from later part of OID
* Inverse of snmp_str2oid
*/
if ((cvk_orig = yang_cvec_get(yt)) == NULL){
- clicon_err(OE_YANG, 0, "No keys");
- goto done;
+ clicon_err(OE_YANG, 0, "No keys");
+ goto done;
}
if ((cvk_val = cvec_dup(cvk_orig)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_dup");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_dup");
+ goto done;
}
/* read through keys and create cvk */
oidilen = oidslen-(oidtlen+1);
oidi = oids+oidtlen+1;
/* Add keys */
for (i=0; i 0 &&
- oid_eq(oidc, oidclen, oidnext, oidnextlen) < 0){
- memcpy(oidnext, oidc, oidclen*sizeof(*oidnext));
- oidnextlen = oidclen;
- xnext = xcol;
- ynext = ycol;
- found++;
- }
- } /* while xcol */
- } /* while xrow */
+ /* Make a clone of key-list, but replace names with values */
+ if ((cvk_name = yang_cvec_get(ylist)) == NULL){
+ clicon_err(OE_YANG, 0, "No keys");
+ goto done;
+ }
+ xrow = NULL;
+ while ((xrow = xml_child_each(xtable, xrow, CX_ELMNT)) != NULL) {
+ /* Get key part of OID from XML list entry */
+ if ((ret = snmp_xmlkey2val_oid(xrow, cvk_name, NULL, /*&cvk_oid,*/ oidk, &oidklen)) < 0)
+ goto done;
+ if (ret == 0)
+ continue; /* skip row, not all indexes */
+ xcol = NULL;
+ while ((xcol = xml_child_each(xrow, xcol, CX_ELMNT)) != NULL) {
+ if ((ycol = xml_spec(xcol)) == NULL)
+ continue;
+ if (yang_keyword_get(ycol) != Y_LEAF)
+ continue;
+ if ((ret = yangext_oid_get(ycol, oidc, &oidclen, NULL)) < 0)
+ goto done;
+ /* Append key oid */
+ if (oid_append(oidc, &oidclen, oidk, oidklen) < 0)
+ goto done;
+ /* Get smallest larger */
+ if (oid_eq(oidc, oidclen, oids, oidslen) > 0 &&
+ oid_eq(oidc, oidclen, oidnext, oidnextlen) < 0){
+ memcpy(oidnext, oidc, oidclen*sizeof(*oidnext));
+ oidnextlen = oidclen;
+ xnext = xcol;
+ ynext = ycol;
+ found++;
+ }
+ } /* while xcol */
+ } /* while xrow */
}
if (found){
- if (snmp_scalar_return(xnext, ynext, oidnext, oidnextlen, reqinfo, request) < 0)
- goto done;
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- oid_cbuf(cb, oidnext, oidnextlen);
- clicon_debug(1, "%s next: %s", __FUNCTION__, cbuf_get(cb));
+ if (snmp_scalar_return(xnext, ynext, oidnext, oidnextlen, reqinfo, request) < 0)
+ goto done;
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ oid_cbuf(cb, oidnext, oidnextlen);
+ clicon_debug(1, "%s next: %s", __FUNCTION__, cbuf_get(cb));
}
retval = found;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (xpath)
- free(xpath);
+ free(xpath);
if (xt)
xml_free(xt);
if (nsc)
@@ -1224,16 +1271,16 @@ snmp_table_getnext(clicon_handle h,
/*! SNMP table operation handler
*
- * @param[in] handler Registered MIB handler structure
- * @param[in] nhreg Root registration info.
- * @param[in] reqinfo Agent transaction request structure
- * @param[in] request The netsnmp request info structure.
+ * @param[in] handler Registered MIB handler structure
+ * @param[in] nhreg Root registration info.
+ * @param[in] reqinfo Agent transaction request structure
+ * @param[in] request The netsnmp request info structure.
*/
static int
clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
- netsnmp_handler_registration *nhreg,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *request)
+ netsnmp_handler_registration *nhreg,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *request)
{
int retval = -1;
clixon_snmp_handle *sh = NULL;
@@ -1242,75 +1289,96 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
cbuf *cb = NULL;
int ret;
netsnmp_variable_list *requestvb;
+ int err = 0;
clicon_debug(2, "%s", __FUNCTION__);
if ((ret = snmp_common_handler(handler, nhreg, reqinfo, request, 1, &sh)) < 0)
- goto done;
+ goto done;
if (sh->sh_ys == NULL){
- clicon_debug(1, "%s Error table not registered", __FUNCTION__);
- goto ok;
+ clicon_debug(1, "%s Error table not registered", __FUNCTION__);
+ goto ok;
}
requestvb = request->requestvb;
switch(reqinfo->mode){
case MODE_GET: // 160
- /* Create xpath from YANG table OID + 1 + n + cvk/key = requestvb->name
- */
- if ((ret = snmp_table_get(sh->sh_h, sh->sh_ys,
- sh->sh_oid2, sh->sh_oid2len,
- requestvb->name, requestvb->name_length,
- reqinfo, request)) < 0)
- goto done;
- if (ret == 0){
- if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
- goto done;
- }
- clicon_debug(1, "%s Nosuchinstance", __FUNCTION__);
- }
- break;
+ /* Create xpath from YANG table OID + 1 + n + cvk/key = requestvb->name
+ */
+ if ((ret = snmp_table_get(sh->sh_h, sh->sh_ys,
+ sh->sh_oid2, sh->sh_oid2len,
+ requestvb->name, requestvb->name_length,
+ reqinfo, request)) < 0)
+ goto done;
+ if (ret == 0){
+ if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){
+ clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
+ goto done;
+ }
+ clicon_debug(1, "%s Nosuchinstance", __FUNCTION__);
+ }
+ break;
case MODE_GETNEXT: // 161
- /* Register table sub-oid:s of existing entries in clixon */
- if ((ret = snmp_table_getnext(sh->sh_h, sh->sh_ys,
- requestvb->name, requestvb->name_length,
- reqinfo, request)) < 0)
- goto done;
- if (ret == 0){
- // if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHOBJECT)) != SNMPERR_SUCCESS){
- if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHOBJECT)) != SNMPERR_SUCCESS){
+ /* Register table sub-oid:s of existing entries in clixon */
+ if ((ret = snmp_table_getnext(sh->sh_h, sh->sh_ys,
+ requestvb->name, requestvb->name_length,
+ reqinfo, request)) < 0)
+ goto done;
+ if (ret == 0){
+ if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHOBJECT)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
- goto done;
- }
- clicon_debug(1, "%s No such object", __FUNCTION__);
- }
+ clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
+ goto done;
+ }
+ clicon_debug(1, "%s No such object", __FUNCTION__);
+ }
break;
case MODE_SET_RESERVE1: // 0
- // Check types: compare type in requestvb to yang type (or do later)
- break;
+ if (!yang_config_ancestor(sh->sh_ys)){
+ netsnmp_request_set_error(request, SNMP_ERR_NOTWRITABLE);
+ goto done;;
+ }
+ // Check types: compare type in requestvb to yang type (or do later)
+ break;
case MODE_SET_RESERVE2: // 1
- break;
+ break;
case MODE_SET_ACTION: // 2
- if ((ret = snmp_table_set(sh->sh_h, sh->sh_ys,
- requestvb->name, requestvb->name_length,
- reqinfo, request)) < 0)
- goto done;
- if (ret == 0){
- if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
- goto done;
- }
- clicon_debug(1, "%s Nosuchinstance", __FUNCTION__);
- }
- break;
+ if ((ret = snmp_table_set(sh->sh_h, sh->sh_ys,
+ requestvb->name, requestvb->name_length,
+ reqinfo, request, &err)) < 0)
+ goto done;
+ if (ret == 0){
+ if ((ret = netsnmp_request_set_error(request, err)) != SNMPERR_SUCCESS){
+ clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
+ goto done;
+ }
+ clicon_debug(1, "%s Nosuchinstance", __FUNCTION__);
+ }
+ /*
+ * There does not seem to be a separate validation action and commit does not
+ * return an error.
+ * Therefore validation is done here directly as well as discard if it fails.
+ */
+ if ((ret = clicon_rpc_validate(sh->sh_h, "candidate")) < 0)
+ goto done;
+ if (ret == 0){
+ clicon_rpc_discard_changes(sh->sh_h);
+ netsnmp_request_set_error(request, SNMP_ERR_COMMITFAILED);
+ goto done;
+ }
+ break;
case MODE_SET_COMMIT: // 3
- if (clicon_rpc_commit(sh->sh_h) < 0)
- goto done;
- break;
+ if ((ret = clicon_rpc_commit(sh->sh_h, 0, 0, 0, NULL, NULL)) < 0)
+ goto done;
+ if (ret == 0){
+ clicon_rpc_discard_changes(sh->sh_h);
+ netsnmp_request_set_error(request, SNMP_ERR_COMMITFAILED);
+ goto done;
+ }
+ break;
case MODE_SET_FREE: // 4
- break;
+ break;
case MODE_SET_UNDO : // 5
- if (clicon_rpc_discard_changes(sh->sh_h) < 0)
- goto done;
+ if (clicon_rpc_discard_changes(sh->sh_h) < 0)
+ goto done;
break;
}
ok:
@@ -1335,9 +1403,9 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
*/
int
clixon_snmp_table_handler(netsnmp_mib_handler *handler,
- netsnmp_handler_registration *nhreg,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *requests)
+ netsnmp_handler_registration *nhreg,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
{
int retval = -1;
netsnmp_request_info *req;
@@ -1345,12 +1413,12 @@ clixon_snmp_table_handler(netsnmp_mib_handler *handler,
clicon_debug(1, "%s", __FUNCTION__);
for (req = requests; req; req = req->next){
- ret = clixon_snmp_table_handler1(handler, nhreg, reqinfo, req);
- if (ret != SNMP_ERR_NOERROR){
- retval = ret;
- goto done;
- break;
- }
+ ret = clixon_snmp_table_handler1(handler, nhreg, reqinfo, req);
+ if (ret != SNMP_ERR_NOERROR){
+ retval = ret;
+ goto done;
+ break;
+ }
}
retval = SNMP_ERR_NOERROR;
done:
diff --git a/apps/snmp/snmp_handler.h b/apps/snmp/snmp_handler.h
index 69c8ae30..d5924bcd 100644
--- a/apps/snmp/snmp_handler.h
+++ b/apps/snmp/snmp_handler.h
@@ -45,13 +45,13 @@ extern "C" {
* Prototypes
*/
int clixon_snmp_table_handler(netsnmp_mib_handler *handler,
- netsnmp_handler_registration *nhreg,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *requests);
+ netsnmp_handler_registration *nhreg,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
int clixon_snmp_scalar_handler(netsnmp_mib_handler *handler,
- netsnmp_handler_registration *nhreg,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *requests);
+ netsnmp_handler_registration *nhreg,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
#endif /* _SNMP_HANDLER_H_ */
diff --git a/apps/snmp/snmp_lib.c b/apps/snmp/snmp_lib.c
index cbd2eabc..7567db25 100644
--- a/apps/snmp/snmp_lib.c
+++ b/apps/snmp/snmp_lib.c
@@ -38,7 +38,7 @@
* smiv2:oid "1.3.6.1.4.1.8072.2.1.1";
* smiv2:defval "42"; (not always)
* 2. container, list
- * smiv2:oid "1.3.6.1.4.1.8072.2.1";
+ * smiv2:oid "1.3.6.1.4.1.8072.2.1";
* 3. module level
* smiv2:alias "netSnmpExamples" {
* smiv2:oid "1.3.6.1.4.1.8072.2";
@@ -178,20 +178,20 @@ oid_eq(const oid *objid0,
int ret;
if (objid0len < objid1len)
- min = objid0len;
+ min = objid0len;
else
- min = objid1len;
+ min = objid1len;
/* First compare common prefix */
ret = memcmp(objid0, objid1, min*sizeof(*objid0));
if (ret != 0)
- return ret;
+ return ret;
/* If equal, check lengths */
if (objid0len < objid1len)
- return -1;
+ return -1;
else if (objid0len > objid1len)
- return 1;
+ return 1;
else
- return 0;
+ return 0;
}
/*! Append a second OID to a first
@@ -205,17 +205,17 @@ oid_eq(const oid *objid0,
*/
int
oid_append(const oid *objid0,
- size_t *objid0len,
- const oid *objid1,
- size_t objid1len)
+ size_t *objid0len,
+ const oid *objid1,
+ size_t objid1len)
{
void *dst;
dst = (void*)objid0;
dst += (*objid0len)*sizeof(*objid0);
if (memcpy(dst, objid1, objid1len*sizeof(*objid0)) < 0){
- clicon_err(OE_UNIX, errno, "memcpy");
- return -1;
+ clicon_err(OE_UNIX, errno, "memcpy");
+ return -1;
}
*objid0len += objid1len;
return 0;
@@ -226,27 +226,27 @@ oid_append(const oid *objid0,
*/
int
oid_cbuf(cbuf *cb,
- const oid *objid,
- size_t objidlen)
+ const oid *objid,
+ size_t objidlen)
{
size_t i;
for (i=0; ish_cvk_orig &&
- (sh1->sh_cvk_orig = cvec_dup(sh0->sh_cvk_orig)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_dup");
- return NULL;
+ (sh1->sh_cvk_orig = cvec_dup(sh0->sh_cvk_orig)) == NULL){
+ clicon_err(OE_UNIX, errno, "cvec_dup");
+ return NULL;
}
return (void*)sh1;
}
@@ -400,15 +400,15 @@ snmp_handle_free(void *arg)
clixon_snmp_handle *sh = (clixon_snmp_handle *)arg;
if (sh != NULL){
- if (sh->sh_cvk_orig)
- cvec_free(sh->sh_cvk_orig);
- if (sh->sh_table_info){
- if (sh->sh_table_info->indexes){
- snmp_free_varbind(sh->sh_table_info->indexes);
- }
- free(sh->sh_table_info);
- }
- free(sh);
+ if (sh->sh_cvk_orig)
+ cvec_free(sh->sh_cvk_orig);
+ if (sh->sh_table_info){
+ if (sh->sh_table_info->indexes){
+ snmp_free_varbind(sh->sh_table_info->indexes);
+ }
+ free(sh->sh_table_info);
+ }
+ free(sh);
}
}
@@ -425,8 +425,8 @@ snmp_handle_free(void *arg)
*/
int
type_yang2asn1(yang_stmt *ys,
- int *asn1_type,
- int extended)
+ int *asn1_type,
+ int extended)
{
int retval = -1;
char *restype; /* resolved type */
@@ -436,36 +436,38 @@ type_yang2asn1(yang_stmt *ys,
/* Get yang type of leaf and translate to ASN.1 */
if (snmp_yang_type_get(ys, NULL, &origtype, &yrestype, &restype) < 0)
- goto done;
+ goto done;
/* Translate to asn.1
* First try original type, first type
*/
if ((at = clicon_str2int(snmp_orig_map, origtype)) >= 0 &&
- (extended || (at < CLIXON_ASN_EXTRAS))){
- ;
+ (extended || (at < CLIXON_ASN_EXTRAS))){
+ ;
}
/* Then try fully resolved type */
else if ((at = clicon_str2int(snmp_type_map, restype)) < 0){
- clicon_err(OE_YANG, 0, "No snmp translation for YANG %s type:%s",
- yang_argument_get(ys), restype);
- goto done;
+ clicon_err(OE_YANG, 0, "No snmp translation for YANG %s type:%s",
+ yang_argument_get(ys), restype);
+ goto done;
}
if (extended && at == ASN_OCTET_STR && yrestype){
- yang_stmt *yrp;
- char *display_hint = NULL;
- yrp = yang_parent_get(yrestype);
- if (yang_extension_value(yrp, "display-hint", IETF_YANG_SMIV2_NS, NULL, &display_hint) < 0)
- goto done;
- /* RFC2578/2579 but maybe all strings with display-hint should use this, eg exist>0? */
- if (display_hint && strcmp(display_hint, "255t")==0)
- at = CLIXON_ASN_FIXED_STRING;
+ yang_stmt *yrp;
+ char *display_hint = NULL;
+ yrp = yang_parent_get(yrestype);
+ if (yang_extension_value(yrp, "display-hint", IETF_YANG_SMIV2_NS, NULL, &display_hint) < 0)
+ goto done;
+ /* RFC2578/2579 but maybe all strings with display-hint should use this, eg exist>0? */
+ if (display_hint &&
+ (strcmp(display_hint, "255a")==0 ||
+ strcmp(display_hint, "255t")==0))
+ at = CLIXON_ASN_FIXED_STRING;
}
if (asn1_type)
- *asn1_type = at;
+ *asn1_type = at;
retval = 0;
done:
if (origtype)
- free(origtype);
+ free(origtype);
return retval;
}
@@ -483,11 +485,11 @@ type_yang2asn1(yang_stmt *ys,
*/
int
type_snmp2xml(yang_stmt *ys,
- int *asn1type,
- netsnmp_variable_list *requestvb,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *request,
- char **valstr)
+ int *asn1type,
+ netsnmp_variable_list *requestvb,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *request,
+ char **valstr)
{
int retval = -1;
char *cvstr;
@@ -500,107 +502,107 @@ type_snmp2xml(yang_stmt *ys,
clicon_debug(1, "%s", __FUNCTION__);
if (valstr == NULL){
- clicon_err(OE_UNIX, EINVAL, "valstr is NULL");
- goto done;
+ clicon_err(OE_UNIX, EINVAL, "valstr is NULL");
+ goto done;
}
if ((cvstr = (char*)clicon_int2str(snmp_type_map, requestvb->type)) == NULL){
- clicon_err(OE_XML, 0, "No mapping for snmp type %d", requestvb->type);
- goto done;
+ clicon_err(OE_XML, 0, "No mapping for snmp type %d", requestvb->type);
+ goto done;
}
/* Get yang type of leaf and trasnslate to ASN.1 */
if (snmp_yang_type_get(ys, NULL, &origtype, &yrestype, &restype) < 0)
- goto done;
+ goto done;
/* special case for enum */
if (strcmp(cvstr, "int32")==0 && strcmp(restype, "enumeration") == 0)
- cvstr = "string";
+ cvstr = "string";
else if (strcmp(cvstr, "int32")==0 && strcmp(restype, "boolean") == 0)
- cvstr = "string";
+ cvstr = "string";
cvtype = cv_str2type(cvstr);
if ((cv = cv_new(cvtype)) == NULL){
- clicon_err(OE_UNIX, errno, "cv_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cv_new");
+ goto done;
}
switch (*asn1type){
case CLIXON_ASN_ROWSTATUS:
- *asn1type = ASN_INTEGER;
- /* fall through */
+ *asn1type = ASN_INTEGER;
+ /* fall through */
case ASN_TIMETICKS: // 67
case ASN_INTEGER: // 2
- if (cvtype == CGV_STRING){ /* special case for enum */
- char *xmlstr;
- cbuf *cb = NULL;
+ if (cvtype == CGV_STRING){ /* special case for enum */
+ char *xmlstr;
+ cbuf *cb = NULL;
- if (strcmp(restype, "enumeration") == 0){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "%ld", *requestvb->val.integer);
- if (yang_valstr2enum(yrestype, cbuf_get(cb), &xmlstr) < 0)
- goto done;
- cbuf_free(cb);
- }
- else if (strcmp(restype, "boolean") == 0){
- if (*requestvb->val.integer == 1)
- xmlstr = "true";
- else
- xmlstr = "false";
- }
- cv_string_set(cv, xmlstr);
- }
- else
- cv_int32_set(cv, *requestvb->val.integer);
- break;
+ if (strcmp(restype, "enumeration") == 0){
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "%ld", *requestvb->val.integer);
+ if (yang_valstr2enum(yrestype, cbuf_get(cb), &xmlstr) < 0)
+ goto done;
+ cbuf_free(cb);
+ }
+ else if (strcmp(restype, "boolean") == 0){
+ if (*requestvb->val.integer == 1)
+ xmlstr = "true";
+ else
+ xmlstr = "false";
+ }
+ cv_string_set(cv, xmlstr);
+ }
+ else
+ cv_int32_set(cv, *requestvb->val.integer);
+ break;
case ASN_GAUGE: // 0x42
- cv_uint32_set(cv, *requestvb->val.integer);
- break;
+ cv_uint32_set(cv, *requestvb->val.integer);
+ break;
case ASN_IPADDRESS:{
- struct in_addr addr;
- memcpy(&addr.s_addr, requestvb->val.string, 4);
- cv_string_set(cv, inet_ntoa(addr));
- break;
+ struct in_addr addr;
+ memcpy(&addr.s_addr, requestvb->val.string, 4);
+ cv_string_set(cv, inet_ntoa(addr));
+ break;
}
case CLIXON_ASN_FIXED_STRING:
- cv_string_set(cv, (char*)requestvb->val.string);
- *asn1type = ASN_OCTET_STR;
- break;
+ cv_string_set(cv, (char*)requestvb->val.string);
+ *asn1type = ASN_OCTET_STR;
+ break;
case CLIXON_ASN_PHYS_ADDR:
- cv_string_set(cv, ether_ntoa((const struct ether_addr *)requestvb->val.string));
- *asn1type = ASN_OCTET_STR;
- break;
+ cv_string_set(cv, ether_ntoa((const struct ether_addr *)requestvb->val.string));
+ *asn1type = ASN_OCTET_STR;
+ break;
case ASN_OCTET_STR: // 4
- cv_string_set(cv, (char*)requestvb->val.string);
- break;
+ cv_string_set(cv, (char*)requestvb->val.string);
+ break;
case ASN_COUNTER64:{ // 0x46 / 70
- uint64_t u64;
- struct counter64 *c64;
- c64 = requestvb->val.counter64;
- u64 = c64->low;
- u64 += c64->high*0x100000000;
- cv_uint64_set(cv, u64);
- break;
+ uint64_t u64;
+ struct counter64 *c64;
+ c64 = requestvb->val.counter64;
+ u64 = c64->low;
+ u64 += c64->high*0x100000000;
+ cv_uint64_set(cv, u64);
+ break;
}
default:
- assert(0); // XXX
- clicon_debug(1, "%s %s not supported", __FUNCTION__, cv_type2str(cvtype));
- if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
- goto done;
- }
- goto fail;
- break;
+ assert(0); // XXX
+ clicon_debug(1, "%s %s not supported", __FUNCTION__, cv_type2str(cvtype));
+ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
+ clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
+ goto done;
+ }
+ goto fail;
+ break;
}
if ((*valstr = cv2str_dup(cv)) == NULL){
- clicon_err(OE_UNIX, errno, "cv2str_dup");
- goto done;
+ clicon_err(OE_UNIX, errno, "cv2str_dup");
+ goto done;
}
retval = 1;
done:
clicon_debug(2, "%s %d", __FUNCTION__, retval);
if (origtype)
- free(origtype);
+ free(origtype);
if (cv)
- cv_free(cv);
+ cv_free(cv);
return retval;
fail:
retval = 0;
@@ -621,8 +623,8 @@ type_snmp2xml(yang_stmt *ys,
*/
int
type_xml2snmp_pre(char *xmlstr0,
- yang_stmt *ys,
- char **xmlstr1)
+ yang_stmt *ys,
+ char **xmlstr1)
{
int retval = -1;
@@ -631,38 +633,38 @@ type_xml2snmp_pre(char *xmlstr0,
char *str = NULL;
int ret;
- if (xmlstr1 == NULL){
- clicon_err(OE_UNIX, EINVAL, "xmlstr1");
- goto done;
+ if (xmlstr0 == NULL || xmlstr1 == NULL){
+ clicon_err(OE_UNIX, EINVAL, "xmlstr0/1 is NULL");
+ goto done;
}
/* Get yang type of leaf and trasnslate to ASN.1 */
if (snmp_yang_type_get(ys, NULL, NULL, &yrestype, &restype) < 0) // XXX yrestype
- goto done;
- if (strcmp(restype, "enumeration") == 0){ /* special case for enum */
- if ((ret = yang_enum2valstr(yrestype, xmlstr0, &str)) < 0)
- goto done;
- if (ret == 0){
- clicon_debug(1, "Invalid enum valstr %s", xmlstr0);
- goto fail;
- }
+ goto done;
+ if (strcmp(restype, "enumeration") == 0){ /* special case for enum */
+ if ((ret = yang_enum2valstr(yrestype, xmlstr0, &str)) < 0)
+ goto done;
+ if (ret == 0){
+ clicon_debug(1, "Invalid enum valstr %s", xmlstr0);
+ goto fail;
+ }
}
/* special case for bool: although smidump translates TruthValue to boolean
* and there is an ASN_BOOLEAN constant:
* 1) there is no code for ASN_BOOLEAN and
* 2) Truthvalue actually translates to enum true(1)/false(0)
*/
- else if (strcmp(restype, "boolean") == 0){
- if (strcmp(xmlstr0, "false")==0)
- str = "0";
- else
- str = "1";
+ else if (strcmp(restype, "boolean") == 0){
+ if (strcmp(xmlstr0, "false")==0)
+ str = "0";
+ else
+ str = "1";
}
else{
- str = xmlstr0;
+ str = xmlstr0;
}
if ((*xmlstr1 = strdup(str)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
retval = 1;
done:
@@ -688,124 +690,124 @@ type_xml2snmp_pre(char *xmlstr0,
*/
int
type_xml2snmp(char *snmpstr,
- int *asn1type,
- u_char **snmpval,
- size_t *snmplen,
- char **reason)
+ int *asn1type,
+ u_char **snmpval,
+ size_t *snmplen,
+ char **reason)
{
int retval = -1;
int ret;
if (snmpval == NULL || snmplen == NULL){
- clicon_err(OE_UNIX, EINVAL, "snmpval or snmplen is NULL");
- goto done;
+ clicon_err(OE_UNIX, EINVAL, "snmpval or snmplen is NULL");
+ goto done;
}
switch (*asn1type){
case CLIXON_ASN_ROWSTATUS:
- *asn1type = ASN_INTEGER;
- /* fall through */
+ *asn1type = ASN_INTEGER;
+ /* fall through */
case ASN_INTEGER: // 2
- *snmplen = 4;
- if ((*snmpval = malloc(*snmplen)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
- }
- if ((ret = parse_int32(snmpstr, (int32_t*)*snmpval, reason)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- break;
+ *snmplen = 4;
+ if ((*snmpval = malloc(*snmplen)) == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
+ }
+ if ((ret = parse_int32(snmpstr, (int32_t*)*snmpval, reason)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ break;
case ASN_TIMETICKS:
case ASN_COUNTER: // 0x41
case ASN_GAUGE: // 0x42
- *snmplen = 4;
- if ((*snmpval = malloc(*snmplen)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
- }
- if ((ret = parse_uint32(snmpstr, (uint32_t*)*snmpval, reason)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ *snmplen = 4;
+ if ((*snmpval = malloc(*snmplen)) == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
+ }
+ if ((ret = parse_uint32(snmpstr, (uint32_t*)*snmpval, reason)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
- break;
+ break;
case ASN_OBJECT_ID:{ // 6
- oid oid1[MAX_OID_LEN] = {0,};
- size_t sz1 = MAX_OID_LEN;
- if (snmp_parse_oid(snmpstr, oid1, &sz1) == NULL){
- clicon_debug(1, "Failed to parse OID %s", snmpstr);
- goto fail;
- }
- *snmplen = sizeof(oid)*sz1;
- if ((*snmpval = malloc(*snmplen)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
- }
- memcpy(*snmpval, oid1, *snmplen);
- break;
+ oid oid1[MAX_OID_LEN] = {0,};
+ size_t sz1 = MAX_OID_LEN;
+ if (snmp_parse_oid(snmpstr, oid1, &sz1) == NULL){
+ clicon_debug(1, "Failed to parse OID %s", snmpstr);
+ goto fail;
+ }
+ *snmplen = sizeof(oid)*sz1;
+ if ((*snmpval = malloc(*snmplen)) == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
+ }
+ memcpy(*snmpval, oid1, *snmplen);
+ break;
}
case ASN_OCTET_STR: // 4
- *snmplen = strlen(snmpstr)+1;
- if ((*snmpval = (u_char*)strdup((snmpstr))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- break;
+ *snmplen = strlen(snmpstr)+1;
+ if ((*snmpval = (u_char*)strdup((snmpstr))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ break;
case ASN_COUNTER64:{ // 0x46 / 70
- uint64_t u64;
- struct counter64 *c64;
- *snmplen = sizeof(struct counter64); // 16!
- if ((*snmpval = malloc(*snmplen)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
- }
- memset(*snmpval, 0, *snmplen);
- if ((ret = parse_uint64(snmpstr, &u64, reason)) < 0)
- goto done;
- c64 = (struct counter64 *)*snmpval;
- c64->low = u64&0xffffffff;
- c64->high = u64/0x100000000;
- if (ret == 0)
- goto fail;
+ uint64_t u64;
+ struct counter64 *c64;
+ *snmplen = sizeof(struct counter64); // 16!
+ if ((*snmpval = malloc(*snmplen)) == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
+ }
+ memset(*snmpval, 0, *snmplen);
+ if ((ret = parse_uint64(snmpstr, &u64, reason)) < 0)
+ goto done;
+ c64 = (struct counter64 *)*snmpval;
+ c64->low = u64&0xffffffff;
+ c64->high = u64/0x100000000;
+ if (ret == 0)
+ goto fail;
}
- break;
+ break;
case ASN_IPADDRESS:{
- in_addr_t saddr;
- *snmplen = 4;
- if ((*snmpval = malloc(*snmplen)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
- }
- saddr = (int32_t)inet_addr(snmpstr);
- memcpy(*snmpval, &saddr, 4);
- break;
+ in_addr_t saddr;
+ *snmplen = 4;
+ if ((*snmpval = malloc(*snmplen)) == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
+ }
+ saddr = (int32_t)inet_addr(snmpstr);
+ memcpy(*snmpval, &saddr, 4);
+ break;
}
case CLIXON_ASN_PHYS_ADDR:{
- struct ether_addr *eaddr;
- *snmplen = sizeof(*eaddr);
- if ((*snmpval = malloc(*snmplen + 1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
- }
- memset(*snmpval, 0, *snmplen + 1);
- if ((eaddr = ether_aton(snmpstr)) == NULL){
- clicon_debug(1, "ether_aton(%s)", snmpstr);
- goto fail;
- }
- memcpy(*snmpval, eaddr, sizeof(*eaddr));
- *asn1type = ASN_OCTET_STR;
- break;
+ struct ether_addr *eaddr;
+ *snmplen = sizeof(*eaddr);
+ if ((*snmpval = malloc(*snmplen + 1)) == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
+ }
+ memset(*snmpval, 0, *snmplen + 1);
+ if ((eaddr = ether_aton(snmpstr)) == NULL){
+ clicon_debug(1, "ether_aton(%s)", snmpstr);
+ goto fail;
+ }
+ memcpy(*snmpval, eaddr, sizeof(*eaddr));
+ *asn1type = ASN_OCTET_STR;
+ break;
}
case CLIXON_ASN_FIXED_STRING: /* OCTET-STRING with decrement length */
- *snmplen = strlen(snmpstr);
- if ((*snmpval = (u_char*)strdup((snmpstr))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- *asn1type = ASN_OCTET_STR;
- break;
+ *snmplen = strlen(snmpstr);
+ if ((*snmpval = (u_char*)strdup((snmpstr))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ *asn1type = ASN_OCTET_STR;
+ break;
default:
- assert(0);
+ assert(0);
}
retval = 1;
done:
@@ -827,8 +829,8 @@ type_xml2snmp(char *snmpstr,
*/
static int
snmp_yang2xpath_cb(yang_stmt *ys,
- cvec *keyvec,
- cbuf *cb)
+ cvec *keyvec,
+ cbuf *cb)
{
yang_stmt *yp; /* parent */
int i;
@@ -837,43 +839,43 @@ snmp_yang2xpath_cb(yang_stmt *ys,
char *prefix = NULL;
if ((yp = yang_parent_get(ys)) == NULL){
- clicon_err(OE_YANG, EINVAL, "yang expected parent %s", yang_argument_get(ys));
- goto done;
+ clicon_err(OE_YANG, EINVAL, "yang expected parent %s", yang_argument_get(ys));
+ goto done;
}
if (yp != NULL && /* XXX rm */
- yang_keyword_get(yp) != Y_MODULE &&
- yang_keyword_get(yp) != Y_SUBMODULE){
- if (snmp_yang2xpath_cb(yp, keyvec, cb) < 0) /* recursive call */
- goto done;
- if (yang_keyword_get(yp) != Y_CHOICE && yang_keyword_get(yp) != Y_CASE){
- cprintf(cb, "/");
- }
+ yang_keyword_get(yp) != Y_MODULE &&
+ yang_keyword_get(yp) != Y_SUBMODULE){
+ if (snmp_yang2xpath_cb(yp, keyvec, cb) < 0) /* recursive call */
+ goto done;
+ if (yang_keyword_get(yp) != Y_CHOICE && yang_keyword_get(yp) != Y_CASE){
+ cprintf(cb, "/");
+ }
}
prefix = yang_find_myprefix(ys);
if (yang_keyword_get(ys) != Y_CHOICE && yang_keyword_get(ys) != Y_CASE){
- if (prefix)
- cprintf(cb, "%s:", prefix);
- cprintf(cb, "%s", yang_argument_get(ys));
+ if (prefix)
+ cprintf(cb, "%s:", prefix);
+ cprintf(cb, "%s", yang_argument_get(ys));
}
switch (yang_keyword_get(ys)){
case Y_LIST:
- cvk = yang_cvec_get(ys); /* Use Y_LIST cache, see ys_populate_list() */
- /* Iterate over individual keys */
- assert(keyvec && cvec_len(cvk) == cvec_len(keyvec));
- for (i=0; iname_a, tree1->namelen)==0){
- retval = 1;
+ oid_eq(oid0, oid0len, tree1->name_a, tree1->namelen)==0){
+ retval = 1;
}
else
- retval = 0;
+ retval = 0;
// done:
return retval;
}
diff --git a/apps/snmp/snmp_lib.h b/apps/snmp/snmp_lib.h
index ca5a286c..dae6ed1e 100644
--- a/apps/snmp/snmp_lib.h
+++ b/apps/snmp/snmp_lib.h
@@ -74,7 +74,7 @@ struct clixon_snmp_handle {
char *sh_default; /* MIB default value leaf only */
cvec *sh_cvk_orig; /* Index/Key variable values (original) */
netsnmp_table_registration_info *sh_table_info; /* To mimic table-handler in libnetsnmp code
- * save only to free properly */
+ * save only to free properly */
};
typedef struct clixon_snmp_handle clixon_snmp_handle;
@@ -93,11 +93,11 @@ void *snmp_handle_clone(void *arg);
void snmp_handle_free(void *arg);
int type_yang2asn1(yang_stmt *ys, int *asn1_type, int extended);
int type_snmp2xml(yang_stmt *ys,
- int *asn1type,
- netsnmp_variable_list *requestvb,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *requests,
- char **valstr);
+ int *asn1type,
+ netsnmp_variable_list *requestvb,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests,
+ char **valstr);
int type_xml2snmp_pre(char *xmlstr, yang_stmt *ys, char **snmpstr);
int type_xml2snmp(char *snmpstr, int *asn1type, u_char **snmpval, size_t *snmplen, char **reason);
int snmp_yang2xpath(yang_stmt *ys, cvec *keyvec, char **xpath);
diff --git a/apps/snmp/snmp_main.c b/apps/snmp/snmp_main.c
index 28fb9321..b826bd48 100644
--- a/apps/snmp/snmp_main.c
+++ b/apps/snmp/snmp_main.c
@@ -90,7 +90,7 @@ static void
clixon_snmp_sig_term(int arg)
{
clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d",
- __PROGRAM__, __FUNCTION__, getpid(), arg);
+ __PROGRAM__, __FUNCTION__, getpid(), arg);
/* This should ensure no more accepts or incoming packets are processed because next time eventloop
* is entered, it will terminate.
* However there may be a case of sockets closing rather abruptly for clients
@@ -114,25 +114,25 @@ snmp_terminate(clicon_handle h)
shutdown_agent();
clixon_snmp_api_agent_cleanup();
if (clicon_ptr_get(h, "snmp-rowstatus-tree", (void**)&x) == 0 && x){
- xml_free(x);
- x = NULL;
+ xml_free(x);
+ x = NULL;
}
clicon_rpc_close_session(h);
if ((yspec = clicon_dbspec_yang(h)) != NULL)
- ys_free(yspec);
+ ys_free(yspec);
if ((yspec = clicon_config_yang(h)) != NULL)
- ys_free(yspec);
+ ys_free(yspec);
if ((nsctx = clicon_nsctx_global_get(h)) != NULL)
- cvec_free(nsctx);
+ cvec_free(nsctx);
if ((x = clicon_conf_xml(h)) != NULL)
- xml_free(x);
+ xml_free(x);
xpath_optimize_exit();
clixon_event_exit();
clicon_handle_exit(h);
clixon_err_exit();
clicon_log_exit();
if (pidfile)
- unlink(pidfile);
+ unlink(pidfile);
return 0;
}
@@ -148,7 +148,7 @@ snmp_terminate(clicon_handle h)
*/
static int
clixon_snmp_fdset_register(clicon_handle h,
- int regfd)
+ int regfd)
{
int retval = -1;
int numfds = 0;
@@ -160,23 +160,23 @@ clixon_snmp_fdset_register(clicon_handle h,
FD_ZERO(&readfds);
if ((nr = snmp_sess_select_info(NULL, &numfds, &readfds, &timeout, &block)) < 0){
- clicon_err(OE_XML, errno, "snmp_select_error");
- goto done;
+ clicon_err(OE_XML, errno, "snmp_select_error");
+ goto done;
}
/* eg 4, 6, 8 */
for (s=0; s\tDebug level\n"
- "\t-f \tConfiguration file (mandatory)\n"
- "\t-l (e|o|s|f) Log on std(e)rr, std(o)ut, (s)yslog(default), (f)ile\n"
- "\t-z\t\tKill other %s daemon and exit\n"
- "\t-o \"=\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
- argv0, argv0
- );
+ "\t-D \tDebug level (>1 for extensive libnetsnmp debug)\n"
+ "\t-f \tConfiguration file (mandatory)\n"
+ "\t-l (e|o|s|f) Log on std(e)rr, std(o)ut, (s)yslog(default), (f)ile\n"
+ "\t-z\t\tKill other %s daemon and exit\n"
+ "\t-o \"=\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
+ argv0, argv0
+ );
exit(0);
}
@@ -344,88 +344,90 @@ main(int argc,
/* Create handle */
if ((h = clicon_handle_init()) == NULL)
- return -1;
+ return -1;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
/* Set username to clixon handle. Use in all communication to backend */
if ((pw = getpwuid(getuid())) == NULL){
- clicon_err(OE_UNIX, errno, "getpwuid");
- goto done;
+ clicon_err(OE_UNIX, errno, "getpwuid");
+ goto done;
}
if (clicon_username_set(h, pw->pw_name) < 0)
- goto done;
+ goto done;
while ((c = getopt(argc, argv, SNMP_OPTS)) != -1)
- switch (c) {
- case 'h' : /* help */
- usage(h, argv[0]);
- break;
- case 'D' : /* debug */
- if (sscanf(optarg, "%d", &dbg) != 1)
- usage(h, argv[0]);
- break;
- case 'f': /* override config file */
- if (!strlen(optarg))
- usage(h, argv[0]);
- clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
- break;
- case 'l': /* Log destination: s|e|o */
- if ((logdst = clicon_log_opt(optarg[0])) < 0)
- usage(h, argv[0]);
- if (logdst == CLICON_LOG_FILE &&
- strlen(optarg)>1 &&
- clicon_log_file(optarg+1) < 0)
- goto done;
- break;
- }
+ switch (c) {
+ case 'h' : /* help */
+ usage(h, argv[0]);
+ break;
+ case 'D' : /* debug */
+ if (sscanf(optarg, "%d", &dbg) != 1)
+ usage(h, argv[0]);
+ break;
+ case 'f': /* override config file */
+ if (!strlen(optarg))
+ usage(h, argv[0]);
+ clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
+ break;
+ case 'l': /* Log destination: s|e|o */
+ if ((logdst = clicon_log_opt(optarg[0])) < 0)
+ usage(h, argv[0]);
+ if (logdst == CLICON_LOG_FILE &&
+ strlen(optarg)>1 &&
+ clicon_log_file(optarg+1) < 0)
+ goto done;
+ break;
+ }
/*
* Logs, error and debug to stderr or syslog, set debug level
*/
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
-
+ /* This is netsnmplib debugging which is quite extensive + only if compiled w debug */
+ if (dbg > 1)
+ snmp_set_do_debugging(1);
/*
* Register error category and error/log callbacks for netsnmp special error handling
*/
if (clixon_err_cat_reg(OE_SNMP, /* category */
- h, /* handle (can be NULL) */
- clixon_snmp_err_cb /* log fn */
- ) < 0)
- goto done;
+ h, /* handle (can be NULL) */
+ clixon_snmp_err_cb /* log fn */
+ ) < 0)
+ goto done;
yang_init(h);
/* Find, read and parse configfile */
if (clicon_options_main(h) < 0)
- goto done;
+ goto done;
/* Now rest of options */
optind = 1;
opterr = 0;
while ((c = getopt(argc, argv, SNMP_OPTS)) != -1)
- switch (c) {
- case 'h' : /* help */
- case 'D' : /* debug */
- case 'f': /* config file */
- case 'l': /* log */
- break; /* see above */
- case 'o':{ /* Configuration option */
- char *val;
- if ((val = index(optarg, '=')) == NULL)
- usage(h, argv0);
- *val++ = '\0';
- if (clicon_option_add(h, optarg, val) < 0)
- goto done;
- break;
- }
- case 'z': /* Zap other process */
- zap++;
- break;
- default:
- usage(h, argv[0]);
- break;
- }
+ switch (c) {
+ case 'h' : /* help */
+ case 'D' : /* debug */
+ case 'f': /* config file */
+ case 'l': /* log */
+ break; /* see above */
+ case 'o':{ /* Configuration option */
+ char *val;
+ if ((val = index(optarg, '=')) == NULL)
+ usage(h, argv0);
+ *val++ = '\0';
+ if (clicon_option_add(h, optarg, val) < 0)
+ goto done;
+ break;
+ }
+ case 'z': /* Zap other process */
+ zap++;
+ break;
+ default:
+ usage(h, argv[0]);
+ break;
+ }
argc -= optind;
argv += optind;
@@ -434,27 +436,27 @@ main(int argc,
/* Check pid-file, if zap kill the old daemon, else return here */
if ((pidfile = clicon_snmp_pidfile(h)) == NULL){
- clicon_err(OE_FATAL, 0, "pidfile not set");
- goto done;
+ clicon_err(OE_FATAL, 0, "pidfile not set");
+ goto done;
}
if (pidfile_get(pidfile, &pid) < 0)
- goto done;
+ goto done;
if (zap){
- if (pid && pidfile_zapold(pid) < 0)
- return -1;
- if (lstat(pidfile, &st) == 0)
- unlink(pidfile);
- snmp_terminate(h);
- exit(0); /* OK */
+ if (pid && pidfile_zapold(pid) < 0)
+ return -1;
+ if (lstat(pidfile, &st) == 0)
+ unlink(pidfile);
+ snmp_terminate(h);
+ exit(0); /* OK */
}
else if (pid){
- clicon_err(OE_DAEMON, 0, "Clixon_snmp daemon already running with pid %d\n(Try killing it with %s -z)",
- pid, argv0);
- return -1; /* goto done deletes pidfile */
+ clicon_err(OE_DAEMON, 0, "Clixon_snmp daemon already running with pid %d\n(Try killing it with %s -z)",
+ pid, argv0);
+ return -1; /* goto done deletes pidfile */
}
/* Here there is either no old process or we have killed it,.. */
if (lstat(pidfile, &st) == 0)
- unlink(pidfile);
+ unlink(pidfile);
/* Init cligen buffers */
cligen_buflen = clicon_option_int(h, "CLICON_CLI_BUF_START");
@@ -462,7 +464,7 @@ main(int argc,
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
- clicon_log_string_limit_set(sz);
+ clicon_log_string_limit_set(sz);
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
xml_nsctx_namespace_netconf_default(h);
@@ -471,49 +473,49 @@ main(int argc,
* Otherwise it is loaded in netconf_module_load below
*/
if (netconf_module_features(h) < 0)
- goto done;
+ goto done;
/* Create top-level yang spec and store as option */
if ((yspec = yspec_new()) == NULL)
- goto done;
- clicon_dbspec_yang_set(h, yspec);
+ goto done;
+ clicon_dbspec_yang_set(h, yspec);
/* Load Yang modules
* 1. Load a yang module as a specific absolute filename */
if ((str = clicon_yang_main_file(h)) != NULL){
- if (yang_spec_parse_file(h, str, yspec) < 0)
- goto done;
+ if (yang_spec_parse_file(h, str, yspec) < 0)
+ goto done;
}
/* 2. Load a (single) main module */
if ((str = clicon_yang_module_main(h)) != NULL){
- if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
- yspec) < 0)
- goto done;
+ if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
+ yspec) < 0)
+ goto done;
}
/* 3. Load all modules in a directory */
if ((str = clicon_yang_main_dir(h)) != NULL){
- if (yang_spec_load_dir(h, str, yspec) < 0)
- goto done;
+ if (yang_spec_load_dir(h, str, yspec) < 0)
+ goto done;
}
/* Load clixon lib yang module */
if (yang_spec_parse_module(h, "clixon-lib", NULL, yspec) < 0)
- goto done;
+ goto done;
/* Load yang module library, RFC7895 */
if (yang_modules_init(h) < 0)
- goto done;
+ goto done;
/* Add netconf yang spec, used by netconf client and as internal protocol */
if (netconf_module_load(h) < 0)
- goto done;
+ goto done;
/* Here all modules are loaded
* Compute and set canonical namespace context
*/
if (xml_nsctx_yangspec(yspec, &nsctx_global) < 0)
- goto done;
+ goto done;
if (clicon_nsctx_global_set(h, nsctx_global) < 0)
- goto done;
+ goto done;
if (dbg)
- clicon_option_dump(h, dbg);
+ clicon_option_dump(h, dbg);
/* Get session id from backend hello */
clicon_session_id_set(h, getpid());
@@ -524,23 +526,23 @@ main(int argc,
* each message sent to the backend.
*/
if (clicon_hello_req(h, &id) < 0)
- goto done;
+ goto done;
clicon_session_id_set(h, id);
/* Init snmp as subagent */
if (clixon_snmp_init_subagent(h, logdst) < 0)
- goto done;
+ goto done;
/* Init and traverse mib-translated yangs and register callbacks */
if (clixon_snmp_traverse_mibyangs(h) < 0)
- goto done;
+ goto done;
/* Write pid-file */
if (pidfile_write(pidfile) < 0)
- goto done;
+ goto done;
/* main event loop */
if (clixon_event_loop(h) < 0)
- goto done;
+ goto done;
retval = 0;
done:
snmp_terminate(h);
diff --git a/apps/snmp/snmp_register.c b/apps/snmp/snmp_register.c
index 340cfa56..0868eb25 100644
--- a/apps/snmp/snmp_register.c
+++ b/apps/snmp/snmp_register.c
@@ -38,7 +38,7 @@
* smiv2:oid "1.3.6.1.4.1.8072.2.1.1";
* smiv2:defval "42"; (not always)
* 2. container, list
- * smiv2:oid "1.3.6.1.4.1.8072.2.1";
+ * smiv2:oid "1.3.6.1.4.1.8072.2.1";
* 3. module level
* smiv2:alias "netSnmpExamples" {
* smiv2:oid "1.3.6.1.4.1.8072.2";
@@ -96,10 +96,10 @@
*/
static int
mibyang_leaf_register(clicon_handle h,
- yang_stmt *ys,
- cvec *cvk_val,
- oid *oidk,
- size_t oidklen)
+ yang_stmt *ys,
+ cvec *cvk_val,
+ oid *oidk,
+ size_t oidklen)
{
int retval = -1;
netsnmp_handler_registration *nhreg = NULL;
@@ -115,40 +115,40 @@ mibyang_leaf_register(clicon_handle h,
cbuf *cboid = NULL;
if ((cboid = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
if ((ret = yangext_oid_get(ys, oid1, &oid1len, NULL)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto ok;
+ goto ok;
if (oid_append(oid1, &oid1len, oidk, oidklen) < 0)
- goto done;
+ goto done;
/* Check if already registered */
if (clixon_snmp_api_oid_find(oid1, oid1len) == 1)
- goto ok;
+ goto ok;
if (yang_extension_value(ys, "max-access", IETF_YANG_SMIV2_NS, NULL, &modes_str) < 0)
- goto done;
+ goto done;
/* Only for sanity check of types initially to fail early */
if (type_yang2asn1(ys, NULL, 0) < 0)
- goto done;
+ goto done;
/* Get modes (access) read-only, read-write, not-accessible, accessible-for-notify
*/
if (modes_str == NULL)
- goto ok;
+ goto ok;
modes = snmp_access_str2int(modes_str);
/* SMI default value, How is this different from yang defaults?
*/
if (yang_extension_value(ys, "defval", IETF_YANG_SMIV2_NS, NULL, &default_str) < 0)
- goto done;
+ goto done;
name = yang_argument_get(ys);
/* Stateless function, just returns ptr */
if ((handler = netsnmp_create_handler(name, clixon_snmp_scalar_handler)) == NULL){
- clicon_err(OE_XML, errno, "netsnmp_create_handler");
- goto done;
+ clicon_err(OE_XML, errno, "netsnmp_create_handler");
+ goto done;
}
/* Userdata to pass around in netsmp callbacks
@@ -165,17 +165,17 @@ mibyang_leaf_register(clicon_handle h,
sh->sh_oidlen = oid1len;
sh->sh_default = default_str;
if (cvk_val &&
- (sh->sh_cvk_orig = cvec_dup(cvk_val)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_dup");
- goto done;
+ (sh->sh_cvk_orig = cvec_dup(cvk_val)) == NULL){
+ clicon_err(OE_UNIX, errno, "cvec_dup");
+ goto done;
}
/* Stateless function, just returns ptr */
if ((nhreg = netsnmp_handler_registration_create(name, handler,
- oid1, oid1len,
- modes)) == NULL){
- clicon_err(OE_XML, errno, "netsnmp_handler_registration_create");
- netsnmp_handler_free(handler);
- goto done;
+ oid1, oid1len,
+ modes)) == NULL){
+ clicon_err(OE_XML, errno, "netsnmp_handler_registration_create");
+ netsnmp_handler_free(handler);
+ goto done;
}
/* Register our application data and how to free it */
handler->myvoid = (void*)sh;
@@ -186,9 +186,9 @@ mibyang_leaf_register(clicon_handle h,
* XXX: nhreg->agent_data
*/
if ((ret = netsnmp_register_instance(nhreg)) != SNMPERR_SUCCESS){
- /* Note MIB_ errors, not regular SNMPERR_ */
- clicon_err(OE_SNMP, ret-CLIXON_ERR_SNMP_MIB, "netsnmp_register_instance");
- goto done;
+ /* Note MIB_ errors, not regular SNMPERR_ */
+ clicon_err(OE_SNMP, ret-CLIXON_ERR_SNMP_MIB, "netsnmp_register_instance");
+ goto done;
}
oid_cbuf(cboid, oid1, oid1len);
clicon_debug(1, "%s register: %s %s", __FUNCTION__, name, cbuf_get(cboid));
@@ -196,7 +196,7 @@ mibyang_leaf_register(clicon_handle h,
retval = 0;
done:
if (cboid)
- cbuf_free(cboid);
+ cbuf_free(cboid);
return retval;
}
@@ -218,12 +218,12 @@ mibyang_leaf_register(clicon_handle h,
*/
static int
mibyang_table_register(clicon_handle h,
- yang_stmt *ylist,
- oid *oid1,
- size_t oid1len,
- oid *oid2,
- size_t oid2len,
- char *oidstr)
+ yang_stmt *ylist,
+ oid *oid1,
+ size_t oid1len,
+ oid *oid2,
+ size_t oid2len,
+ char *oidstr)
{
int retval = -1;
netsnmp_handler_registration *nhreg;
@@ -240,9 +240,9 @@ mibyang_table_register(clicon_handle h,
char *name;
if ((ys = yang_parent_get(ylist)) == NULL ||
- yang_keyword_get(ys) != Y_CONTAINER){
- clicon_err(OE_YANG, EINVAL, "ylist parent is not list");
- goto done;
+ yang_keyword_get(ys) != Y_CONTAINER){
+ clicon_err(OE_YANG, EINVAL, "ylist parent is not list");
+ goto done;
}
/* Note: This is wrong for augmented nodes where name is the original list, not the
* augmented. For example, for IFMIB you get ifTable twice where you should get ifTable for
@@ -266,15 +266,15 @@ mibyang_table_register(clicon_handle h,
sh->sh_oid2len = oid2len;
if ((handler = netsnmp_create_handler(name, clixon_snmp_table_handler)) == NULL){
- clicon_err(OE_XML, errno, "netsnmp_create_handler");
- goto done;
+ clicon_err(OE_XML, errno, "netsnmp_create_handler");
+ goto done;
}
if ((nhreg = netsnmp_handler_registration_create(name, handler,
- oid1, oid1len,
- HANDLER_CAN_RWRITE)) == NULL){
- clicon_err(OE_XML, errno, "netsnmp_handler_registration_create");
- netsnmp_handler_free(handler);
- goto done;
+ oid1, oid1len,
+ HANDLER_CAN_RWRITE)) == NULL){
+ clicon_err(OE_XML, errno, "netsnmp_handler_registration_create");
+ netsnmp_handler_free(handler);
+ goto done;
}
/* Register our application data and how to free it */
handler->myvoid =(void*)sh;
@@ -283,35 +283,35 @@ mibyang_table_register(clicon_handle h,
/* See netsnmp_register_table_data_set */
if ((table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info)) == NULL){
- clicon_err(OE_UNIX, errno, "SNMP_MALLOC_TYPEDEF");
- goto done;
+ clicon_err(OE_UNIX, errno, "SNMP_MALLOC_TYPEDEF");
+ goto done;
}
/* Keys, go through keys */
if ((cvk = yang_cvec_get(ylist)) == NULL){
- clicon_err(OE_YANG, 0, "No keys");
- goto done;
+ clicon_err(OE_YANG, 0, "No keys");
+ goto done;
}
cvi = NULL;
/* Iterate over individual keys */
while ((cvi = cvec_each(cvk, cvi)) != NULL) {
- keyname = cv_string_get(cvi);
- if ((yleaf = yang_find(ylist, Y_LEAF, keyname)) == NULL){
- clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"",
- yang_argument_get(ylist), keyname);
- goto done;
- }
- if (type_yang2asn1(yleaf, &asn1type, 0) < 0)
- // goto done;
- goto ok; // XXX skip
- if (snmp_varlist_add_variable(&table_info->indexes,
- NULL, // oid name
- 0, // oid len
- asn1type,
- NULL, // value
- 0) == NULL){
- clicon_err(OE_XML, errno, "snmp_varlist_add_variable");
- goto done;
- }
+ keyname = cv_string_get(cvi);
+ if ((yleaf = yang_find(ylist, Y_LEAF, keyname)) == NULL){
+ clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"",
+ yang_argument_get(ylist), keyname);
+ goto done;
+ }
+ if (type_yang2asn1(yleaf, &asn1type, 0) < 0)
+ // goto done;
+ goto ok; // XXX skip
+ if (snmp_varlist_add_variable(&table_info->indexes,
+ NULL, // oid name
+ 0, // oid len
+ asn1type,
+ NULL, // value
+ 0) == NULL){
+ clicon_err(OE_XML, errno, "snmp_varlist_add_variable");
+ goto done;
+ }
}
table_info->min_column = 1;
@@ -319,12 +319,12 @@ mibyang_table_register(clicon_handle h,
yleaf = NULL;
table_info->max_column = 0;
while ((yleaf = yn_each(ylist, yleaf)) != NULL) {
- if (yang_keyword_get(yleaf) == Y_LEAF)
- table_info->max_column++;
+ if (yang_keyword_get(yleaf) == Y_LEAF)
+ table_info->max_column++;
}
if ((ret = netsnmp_register_table(nhreg, table_info)) != SNMPERR_SUCCESS){
- clicon_err(OE_SNMP, ret, "netsnmp_register_table");
- goto done;
+ clicon_err(OE_SNMP, ret, "netsnmp_register_table");
+ goto done;
}
sh->sh_table_info = table_info; /* Keep to free at exit */
clicon_debug(1, "%s register: %s %s", __FUNCTION__, name, oidstr);
@@ -351,7 +351,7 @@ mibyang_table_register(clicon_handle h,
*/
static int
mibyang_list_register(clicon_handle h,
- yang_stmt *ylist)
+ yang_stmt *ylist)
{
int retval = -1;
yang_stmt *yc;
@@ -363,23 +363,23 @@ mibyang_list_register(clicon_handle h,
int ret;
if ((yc = yang_parent_get(ylist)) == NULL ||
- yang_keyword_get(yc) != Y_CONTAINER){
- clicon_err(OE_YANG, EINVAL, "ylist parent is not container");
- goto done;
+ yang_keyword_get(yc) != Y_CONTAINER){
+ clicon_err(OE_YANG, EINVAL, "ylist parent is not container");
+ goto done;
}
if ((ret = yangext_oid_get(ylist, oid2, &oid2len, NULL)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto ok;
+ goto ok;
if ((ret = yangext_oid_get(yc, oid1, &oid1len, &oidstr)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto ok;
+ goto ok;
if (mibyang_table_register(h, ylist,
- oid1, oid1len,
- oid2, oid2len,
- oidstr) < 0)
- goto done;
+ oid1, oid1len,
+ oid2, oid2len,
+ oidstr) < 0)
+ goto done;
ok:
retval = 0;
done:
@@ -406,7 +406,7 @@ mibyang_list_register(clicon_handle h,
*/
static int
mibyang_augment_register(clicon_handle h,
- yang_stmt *yaug)
+ yang_stmt *yaug)
{
int retval = -1;
char *schema_nodeid;
@@ -420,25 +420,25 @@ mibyang_augment_register(clicon_handle h,
char *ri;
if ((ret = yangext_oid_get(yaug, oid2, &oid2len, &oidstr)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto ok;
+ goto ok;
/* Decrement oid of list object (oid2) to container object (oid1) */
memcpy(oid1, oid2, sizeof(oid2));
oid1len = oid2len - 1;
oid1[oid1len] = 0;
if ((ri = rindex(oidstr, '.')) != NULL)
- *ri = '\0';
+ *ri = '\0';
schema_nodeid = yang_argument_get(yaug);
if (yang_abs_schema_nodeid(yaug, schema_nodeid, &ylist) < 0)
- goto done;
+ goto done;
if (yang_keyword_get(ylist) != Y_LIST)
- goto ok; /* skip */
+ goto ok; /* skip */
if (mibyang_table_register(h, ylist,
- oid1, oid1len,
- oid2, oid2len,
- oidstr) < 0)
- goto done;
+ oid1, oid1len,
+ oid2, oid2len,
+ oidstr) < 0)
+ goto done;
ok:
retval = 0;
done:
@@ -459,7 +459,7 @@ mibyang_augment_register(clicon_handle h,
*/
int
mibyang_table_poll(clicon_handle h,
- yang_stmt *ylist)
+ yang_stmt *ylist)
{
int retval = -1;
cvec *nsc = NULL;
@@ -479,9 +479,9 @@ mibyang_table_poll(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if ((ys = yang_parent_get(ylist)) == NULL ||
- yang_keyword_get(ys) != Y_CONTAINER){
- clicon_err(OE_YANG, EINVAL, "ylist parent is not list");
- goto done;
+ yang_keyword_get(ys) != Y_CONTAINER){
+ clicon_err(OE_YANG, EINVAL, "ylist parent is not list");
+ goto done;
}
if (xml_nsctx_yang(ys, &nsc) < 0)
goto done;
@@ -494,30 +494,30 @@ mibyang_table_poll(clicon_handle h,
goto done;
}
if ((xtable = xpath_first(xt, nsc, "%s", xpath)) != NULL) {
- /* Make a clone of key-list, but replace names with values */
- if ((cvk_name = yang_cvec_get(ylist)) == NULL){
- clicon_err(OE_YANG, 0, "No keys");
- goto done;
- }
- xrow = NULL;
- while ((xrow = xml_child_each(xtable, xrow, CX_ELMNT)) != NULL) {
- if ((ret = snmp_xmlkey2val_oid(xrow, cvk_name, &cvk_val, oidk, &oidklen)) < 0)
- goto done;
- if (ret == 0)
- continue; /* skip row, not all indexes */
- xcol = NULL;
- while ((xcol = xml_child_each(xrow, xcol, CX_ELMNT)) != NULL) {
- if ((y = xml_spec(xcol)) == NULL)
- continue;
- if (mibyang_leaf_register(h, y, cvk_val, oidk, oidklen) < 0)
- goto done;
- }
- }
+ /* Make a clone of key-list, but replace names with values */
+ if ((cvk_name = yang_cvec_get(ylist)) == NULL){
+ clicon_err(OE_YANG, 0, "No keys");
+ goto done;
+ }
+ xrow = NULL;
+ while ((xrow = xml_child_each(xtable, xrow, CX_ELMNT)) != NULL) {
+ if ((ret = snmp_xmlkey2val_oid(xrow, cvk_name, &cvk_val, oidk, &oidklen)) < 0)
+ goto done;
+ if (ret == 0)
+ continue; /* skip row, not all indexes */
+ xcol = NULL;
+ while ((xcol = xml_child_each(xrow, xcol, CX_ELMNT)) != NULL) {
+ if ((y = xml_spec(xcol)) == NULL)
+ continue;
+ if (mibyang_leaf_register(h, y, cvk_val, oidk, oidklen) < 0)
+ goto done;
+ }
+ }
}
retval = 0;
done:
if (xpath)
- free(xpath);
+ free(xpath);
if (cvk_val)
cvec_free(cvk_val);
if (xt)
@@ -537,7 +537,7 @@ mibyang_table_poll(clicon_handle h,
* smiv2:oid "1.3.6.1.4.1.8072.2.1.1";
* smiv2:defval "42"; (not always)
* 2. container, list
- * smiv2:oid "1.3.6.1.4.1.8072.2.1";
+ * smiv2:oid "1.3.6.1.4.1.8072.2.1";
* 3. module level
* smiv2:alias "netSnmpExamples" {
* smiv2:oid "1.3.6.1.4.1.8072.2";
@@ -550,51 +550,51 @@ mibyang_table_poll(clicon_handle h,
*/
static int
mibyang_traverse(clicon_handle h,
- yang_stmt *yn)
+ yang_stmt *yn)
{
int retval = -1;
yang_stmt *ys = NULL;
yang_stmt *yp;
int ret;
-
+
clicon_debug(1, "%s %s", __FUNCTION__, yang_argument_get(yn));
switch(yang_keyword_get(yn)){
case Y_AUGMENT:
- if (mibyang_augment_register(h, yn) < 0)
- goto done;
- goto ok;
- break;
+ if (mibyang_augment_register(h, yn) < 0)
+ goto done;
+ goto ok;
+ break;
case Y_LEAF:
- if (mibyang_leaf_register(h, yn, NULL, NULL, 0) < 0)
- goto done;
- break;
+ if (mibyang_leaf_register(h, yn, NULL, NULL, 0) < 0)
+ goto done;
+ break;
case Y_CONTAINER: /* See list case */
- break;
+ break;
case Y_LIST: /* If parent is container -> identify as table */
- yp = yang_parent_get(yn);
- if (yang_keyword_get(yp) == Y_CONTAINER){
+ yp = yang_parent_get(yn);
+ if (yang_keyword_get(yp) == Y_CONTAINER){
- /* Register table entry handler itself (not column/row leafs) */
- if (mibyang_list_register(h, yn) < 0)
- goto done;
- goto ok;
- }
- break;
+ /* Register table entry handler itself (not column/row leafs) */
+ if (mibyang_list_register(h, yn) < 0)
+ goto done;
+ goto ok;
+ }
+ break;
default:
- break;
+ break;
}
/* Traverse data nodes in tree (module is special case */
ys = NULL;
while ((ys = yn_each(yn, ys)) != NULL) {
- /* augment special case of table */
- if (!yang_schemanode(ys) && yang_keyword_get(ys) != Y_AUGMENT)
- continue;
- if ((ret = mibyang_traverse(h, ys)) < 0)
- goto done;
- if (ret > 0){
- retval = ret;
- goto done;
- }
+ /* augment special case of table */
+ if (!yang_schemanode(ys) && yang_keyword_get(ys) != Y_AUGMENT)
+ continue;
+ if ((ret = mibyang_traverse(h, ys)) < 0)
+ goto done;
+ if (ret > 0){
+ retval = ret;
+ goto done;
+ }
}
ok:
retval = 0;
@@ -618,32 +618,32 @@ clixon_snmp_traverse_mibyangs(clicon_handle h)
yang_stmt *ymod;
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
}
/* Loop over clixon configuration file to find all CLICON_SNMP_MIB, and
* then loop over all those MIBs to register OIDs with netsnmp
*/
x = NULL;
while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(x), "CLICON_SNMP_MIB") != 0)
- continue;
- if ((modname = xml_body(x)) == NULL)
- continue;
- clicon_debug(1, "%s %s: \"%s\"", __FUNCTION__, xml_name(x), modname);
- /* Note, here we assume the Yang is loaded by some other mechanism and
- * error if it not found.
- * Alternatively, that YANG could be loaded.
- * Problem is, if clixon_snmp has not loaded it, has backend done it?
- * What happens if backend has not loaded it?
- */
- if ((ymod = yang_find(yspec, Y_MODULE, modname)) == NULL){
- clicon_err(OE_YANG, 0, "Mib-translated-yang %s not loaded", modname);
- goto done;
- }
- /* Recursively traverse the mib-yang to find extensions */
- if (mibyang_traverse(h, ymod) < 0)
- goto done;
+ if (strcmp(xml_name(x), "CLICON_SNMP_MIB") != 0)
+ continue;
+ if ((modname = xml_body(x)) == NULL)
+ continue;
+ clicon_debug(1, "%s %s: \"%s\"", __FUNCTION__, xml_name(x), modname);
+ /* Note, here we assume the Yang is loaded by some other mechanism and
+ * error if it not found.
+ * Alternatively, that YANG could be loaded.
+ * Problem is, if clixon_snmp has not loaded it, has backend done it?
+ * What happens if backend has not loaded it?
+ */
+ if ((ymod = yang_find(yspec, Y_MODULE, modname)) == NULL){
+ clicon_err(OE_YANG, 0, "Mib-translated-yang %s not loaded", modname);
+ goto done;
+ }
+ /* Recursively traverse the mib-yang to find extensions */
+ if (mibyang_traverse(h, ymod) < 0)
+ goto done;
}
retval = 0;
done:
diff --git a/configure b/configure
index 1b701d7b..6c0b3f61 100755
--- a/configure
+++ b/configure
@@ -57,8 +57,8 @@ else
arg=$1;
case $arg in #(
*"$as_nl"*)
- expr "X$arg" : "X\\(.*\\)$as_nl";
- arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+ expr "X$arg" : "X\\(.*\\)$as_nl";
+ arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
esac;
expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
'
@@ -84,7 +84,7 @@ fi
# there to prevent editors from complaining about space-tab.
# (If _AS_PATH_WALK were called with IFS unset, it would disable word
# splitting by setting IFS to empty value.)
-IFS=" "" $as_nl"
+IFS=" "" $as_nl"
# Find who we are. Look in the path if we contain no directory separator.
as_myself=
@@ -213,23 +213,23 @@ do
test -z "$as_dir" && as_dir=.
as_found=:
case $as_dir in #(
- /*)
- for as_base in sh bash ksh sh5; do
- # Try only shells that exist, to save several forks.
- as_shell=$as_dir/$as_base
- if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
- { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
+ /*)
+ for as_base in sh bash ksh sh5; do
+ # Try only shells that exist, to save several forks.
+ as_shell=$as_dir/$as_base
+ if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+ { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
CONFIG_SHELL=$as_shell as_have_required=yes
- if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
+ if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
break 2
fi
fi
- done;;
+ done;;
esac
as_found=false
done
$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
- { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
+ { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
CONFIG_SHELL=$SHELL as_have_required=yes
fi; }
IFS=$as_save_IFS
@@ -328,27 +328,27 @@ as_fn_mkdir_p ()
as_dirs="'$as_qdir' $as_dirs"
as_dir=`$as_dirname -- "$as_dir" ||
$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
- X"$as_dir" : 'X\(//\)[^/]' \| \
- X"$as_dir" : 'X\(//\)$' \| \
- X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+ X"$as_dir" : 'X\(//\)[^/]' \| \
+ X"$as_dir" : 'X\(//\)$' \| \
+ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X"$as_dir" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
- s//\1/
- q
- }
- /^X\(\/\/\)[^/].*/{
- s//\1/
- q
- }
- /^X\(\/\/\)$/{
- s//\1/
- q
- }
- /^X\(\/\).*/{
- s//\1/
- q
- }
- s/.*/./; q'`
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
test -d "$as_dir" && break
done
test -z "$as_dirs" || eval "mkdir $as_dirs"
@@ -437,22 +437,22 @@ fi
as_me=`$as_basename -- "$0" ||
$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
- X"$0" : 'X\(//\)$' \| \
- X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+ X"$0" : 'X\(//\)$' \| \
+ X"$0" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X/"$0" |
sed '/^.*\/\([^/][^/]*\)\/*$/{
- s//\1/
- q
- }
- /^X\/\(\/\/\)$/{
- s//\1/
- q
- }
- /^X\/\(\/\).*/{
- s//\1/
- q
- }
- s/.*/./; q'`
+ s//\1/
+ q
+ }
+ /^X\/\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\/\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
# Avoid depending upon Character Ranges.
as_cr_letters='abcdefghijklmnopqrstuvwxyz'
@@ -501,10 +501,10 @@ ECHO_C= ECHO_N= ECHO_T=
case `echo -n x` in #(((((
-n*)
case `echo 'xy\c'` in
- *c*) ECHO_T=' ';; # ECHO_T is single tab character.
+ *c*) ECHO_T=' ';; # ECHO_T is single tab character.
xy) ECHO_C='\c';;
*) echo `echo ksh88 bug on AIX 6.1` > /dev/null
- ECHO_T=' ';;
+ ECHO_T=' ';;
esac;;
*)
ECHO_N='-n';;
@@ -865,7 +865,7 @@ do
"enable_$ac_useropt"
"*) ;;
*) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
- ac_unrecognized_sep=', ';;
+ ac_unrecognized_sep=', ';;
esac
eval enable_$ac_useropt=no ;;
@@ -891,7 +891,7 @@ do
"enable_$ac_useropt"
"*) ;;
*) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
- ac_unrecognized_sep=', ';;
+ ac_unrecognized_sep=', ';;
esac
eval enable_$ac_useropt=\$ac_optarg ;;
@@ -1104,7 +1104,7 @@ do
"with_$ac_useropt"
"*) ;;
*) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
- ac_unrecognized_sep=', ';;
+ ac_unrecognized_sep=', ';;
esac
eval with_$ac_useropt=\$ac_optarg ;;
@@ -1120,7 +1120,7 @@ do
"with_$ac_useropt"
"*) ;;
*) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
- ac_unrecognized_sep=', ';;
+ ac_unrecognized_sep=', ';;
esac
eval with_$ac_useropt=no ;;
@@ -1181,10 +1181,10 @@ if test -n "$ac_unrecognized_opts"; then
fi
# Check all directory arguments for consistency.
-for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
- datadir sysconfdir sharedstatedir localstatedir includedir \
- oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
- libdir localedir mandir runstatedir
+for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
+ datadir sysconfdir sharedstatedir localstatedir includedir \
+ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
+ libdir localedir mandir runstatedir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
@@ -1237,27 +1237,27 @@ if test -z "$srcdir"; then
# Try the directory containing this script, then the parent directory.
ac_confdir=`$as_dirname -- "$as_myself" ||
$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
- X"$as_myself" : 'X\(//\)[^/]' \| \
- X"$as_myself" : 'X\(//\)$' \| \
- X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
+ X"$as_myself" : 'X\(//\)[^/]' \| \
+ X"$as_myself" : 'X\(//\)$' \| \
+ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X"$as_myself" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
- s//\1/
- q
- }
- /^X\(\/\/\)[^/].*/{
- s//\1/
- q
- }
- /^X\(\/\/\)$/{
- s//\1/
- q
- }
- /^X\(\/\).*/{
- s//\1/
- q
- }
- s/.*/./; q'`
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
srcdir=$ac_confdir
if test ! -r "$srcdir/$ac_unique_file"; then
srcdir=..
@@ -1271,8 +1271,8 @@ if test ! -r "$srcdir/$ac_unique_file"; then
fi
ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
ac_abs_confdir=`(
- cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
- pwd)`
+ cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
+ pwd)`
# When building in place, set srcdir=.
if test "$ac_abs_confdir" = "$ac_pwd"; then
srcdir=.
@@ -1523,15 +1523,15 @@ $as_echo "$ac_try_echo"; } >&5
fi
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } && {
- test -z "$ac_c_werror_flag" ||
- test ! -s conftest.err
+ test -z "$ac_c_werror_flag" ||
+ test ! -s conftest.err
} && test -s conftest.$ac_objext; then :
ac_retval=0
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
- ac_retval=1
+ ac_retval=1
fi
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
as_fn_set_status $ac_retval
@@ -1561,18 +1561,18 @@ $as_echo "$ac_try_echo"; } >&5
fi
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } && {
- test -z "$ac_c_werror_flag" ||
- test ! -s conftest.err
+ test -z "$ac_c_werror_flag" ||
+ test ! -s conftest.err
} && test -s conftest$ac_exeext && {
- test "$cross_compiling" = yes ||
- test -x conftest$ac_exeext
+ test "$cross_compiling" = yes ||
+ test -x conftest$ac_exeext
}; then :
ac_retval=0
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
- ac_retval=1
+ ac_retval=1
fi
# Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
# created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
@@ -1606,8 +1606,8 @@ $as_echo "$ac_try_echo"; } >&5
fi
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } > conftest.i && {
- test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
- test ! -s conftest.err
+ test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+ test ! -s conftest.err
}; then :
ac_retval=0
else
@@ -1644,15 +1644,15 @@ $as_echo "$ac_try_echo"; } >&5
fi
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } && {
- test -z "$ac_cxx_werror_flag" ||
- test ! -s conftest.err
+ test -z "$ac_cxx_werror_flag" ||
+ test ! -s conftest.err
} && test -s conftest.$ac_objext; then :
ac_retval=0
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
- ac_retval=1
+ ac_retval=1
fi
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
as_fn_set_status $ac_retval
@@ -1674,7 +1674,7 @@ if eval \${$3+:} false; then :
$as_echo_n "(cached) " >&6
fi
eval ac_res=\$$3
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
else
# Is the header compilable?
@@ -1739,7 +1739,7 @@ else
eval "$3=\$ac_header_compiler"
fi
eval ac_res=\$$3
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
fi
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
@@ -1813,7 +1813,7 @@ fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$3
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
@@ -1880,7 +1880,7 @@ rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
eval ac_res=\$$3
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
@@ -1968,19 +1968,19 @@ do
2)
as_fn_append ac_configure_args1 " '$ac_arg'"
if test $ac_must_keep_next = true; then
- ac_must_keep_next=false # Got value, back to normal.
+ ac_must_keep_next=false # Got value, back to normal.
else
- case $ac_arg in
- *=* | --config-cache | -C | -disable-* | --disable-* \
- | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
- | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
- | -with-* | --with-* | -without-* | --without-* | --x)
- case "$ac_configure_args0 " in
- "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
- esac
- ;;
- -* ) ac_must_keep_next=true ;;
- esac
+ case $ac_arg in
+ *=* | --config-cache | -C | -disable-* | --disable-* \
+ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+ | -with-* | --with-* | -without-* | --without-* | --x)
+ case "$ac_configure_args0 " in
+ "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+ esac
+ ;;
+ -* ) ac_must_keep_next=true ;;
+ esac
fi
as_fn_append ac_configure_args " '$ac_arg'"
;;
@@ -2025,8 +2025,8 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
*${as_nl}ac_space=\ *)
sed -n \
- "s/'\''/'\''\\\\'\'''\''/g;
- s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
+ "s/'\''/'\''\\\\'\'''\''/g;
+ s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
;; #(
*)
sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
@@ -2057,11 +2057,11 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
echo
for ac_var in $ac_subst_files
do
- eval ac_val=\$$ac_var
- case $ac_val in
- *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
- esac
- $as_echo "$ac_var='\''$ac_val'\''"
+ eval ac_val=\$$ac_var
+ case $ac_val in
+ *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+ esac
+ $as_echo "$ac_var='\''$ac_val'\''"
done | sort
echo
fi
@@ -2189,21 +2189,21 @@ $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
,);;
*)
if test "x$ac_old_val" != "x$ac_new_val"; then
- # differences in whitespace do not lead to failure.
- ac_old_val_w=`echo x $ac_old_val`
- ac_new_val_w=`echo x $ac_new_val`
- if test "$ac_old_val_w" != "$ac_new_val_w"; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
+ # differences in whitespace do not lead to failure.
+ ac_old_val_w=`echo x $ac_old_val`
+ ac_new_val_w=`echo x $ac_new_val`
+ if test "$ac_old_val_w" != "$ac_new_val_w"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
- ac_cache_corrupted=:
- else
- { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
+ ac_cache_corrupted=:
+ else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
- eval $ac_var=\$ac_old_val
- fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5
+ eval $ac_var=\$ac_old_val
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5
$as_echo "$as_me: former value: \`$ac_old_val'" >&2;}
- { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5
+ { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5
$as_echo "$as_me: current value: \`$ac_new_val'" >&2;}
fi;;
esac
@@ -2282,10 +2282,10 @@ CLIXON_VERSION="\"${CLIXON_VERSION_MAJOR}.${CLIXON_VERSION_MINOR}.${CLIXON_VERSI
# Check whether --enable-debug was given.
if test "${enable_debug+set}" = set; then :
enableval=$enable_debug;
- if test "$enableval" = no; then
- ac_enable_debug=no
- else
- ac_enable_debug=yes
+ if test "$enableval" = no; then
+ ac_enable_debug=no
+ else
+ ac_enable_debug=yes
fi
else
@@ -2304,9 +2304,9 @@ fi
# Check CLIgen
if test "$prefix" = "NONE"; then
- CLIGEN_PREFIX="$ac_default_prefix"
+ CLIGEN_PREFIX="$ac_default_prefix"
else
- CLIGEN_PREFIX="$prefix"
+ CLIGEN_PREFIX="$prefix"
fi
ac_config_headers="$ac_config_headers include/clixon_config.h lib/clixon/clixon.h"
@@ -2715,24 +2715,24 @@ do
test -f "$ac_file" || continue
case $ac_file in
*.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
- ;;
+ ;;
[ab].out )
- # We found the default executable, but exeext='' is most
- # certainly right.
- break;;
+ # We found the default executable, but exeext='' is most
+ # certainly right.
+ break;;
*.* )
- if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
- then :; else
- ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
- fi
- # We set ac_cv_exeext here because the later test for it is not
- # safe: cross compilers may not add the suffix if given an `-o'
- # argument, so we may need to know it at that point already.
- # Even if this section looks crufty: it has the advantage of
- # actually working.
- break;;
+ if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
+ then :; else
+ ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+ fi
+ # We set ac_cv_exeext here because the later test for it is not
+ # safe: cross compilers may not add the suffix if given an `-o'
+ # argument, so we may need to know it at that point already.
+ # Even if this section looks crufty: it has the advantage of
+ # actually working.
+ break;;
* )
- break;;
+ break;;
esac
done
test "$ac_cv_exeext" = no && ac_cv_exeext=
@@ -2784,7 +2784,7 @@ for ac_file in conftest.exe conftest conftest.*; do
case $ac_file in
*.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
*.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
- break;;
+ break;;
* ) break;;
esac
done
@@ -2845,9 +2845,9 @@ $as_echo "$ac_try_echo"; } >&5
cross_compiling=no
else
if test "$cross_compiling" = maybe; then
- cross_compiling=yes
+ cross_compiling=yes
else
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot run C compiled programs.
If you meant to cross compile, use \`--host'.
@@ -2987,8 +2987,8 @@ if ac_fn_c_try_compile "$LINENO"; then :
else
ac_c_werror_flag=$ac_save_c_werror_flag
- CFLAGS="-g"
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ CFLAGS="-g"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
@@ -3086,7 +3086,7 @@ return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];
}
_ACEOF
for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
- -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
do
CC="$ac_save_CC $ac_arg"
if ac_fn_c_try_compile "$LINENO"; then :
@@ -3328,30 +3328,30 @@ case $as_dir/ in #((
# by default.
for ac_prog in ginstall scoinst install; do
for ac_exec_ext in '' $ac_executable_extensions; do
- if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
- if test $ac_prog = install &&
- grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
- # AIX install. It has an incompatible calling convention.
- :
- elif test $ac_prog = install &&
- grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
- # program-specific install script used by HP pwplus--don't use.
- :
- else
- rm -rf conftest.one conftest.two conftest.dir
- echo one > conftest.one
- echo two > conftest.two
- mkdir conftest.dir
- if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
- test -s conftest.one && test -s conftest.two &&
- test -s conftest.dir/conftest.one &&
- test -s conftest.dir/conftest.two
- then
- ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
- break 3
- fi
- fi
- fi
+ if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
+ if test $ac_prog = install &&
+ grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+ # AIX install. It has an incompatible calling convention.
+ :
+ elif test $ac_prog = install &&
+ grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+ # program-specific install script used by HP pwplus--don't use.
+ :
+ else
+ rm -rf conftest.one conftest.two conftest.dir
+ echo one > conftest.one
+ echo two > conftest.two
+ mkdir conftest.dir
+ if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
+ test -s conftest.one && test -s conftest.two &&
+ test -s conftest.dir/conftest.one &&
+ test -s conftest.dir/conftest.two
+ then
+ ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+ break 3
+ fi
+ fi
+ fi
done
done
;;
@@ -3813,8 +3813,8 @@ if ac_fn_c_try_compile "$LINENO"; then :
else
ac_c_werror_flag=$ac_save_c_werror_flag
- CFLAGS="-g"
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ CFLAGS="-g"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
@@ -3912,7 +3912,7 @@ return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];
}
_ACEOF
for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
- -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
do
CC="$ac_save_CC $ac_arg"
if ac_fn_c_try_compile "$LINENO"; then :
@@ -3982,7 +3982,7 @@ do
#else
# include
#endif
- Syntax error
+ Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
@@ -4041,7 +4041,7 @@ do
#else
# include
#endif
- Syntax error
+ Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
@@ -4297,8 +4297,8 @@ if ac_fn_cxx_try_compile "$LINENO"; then :
else
ac_cxx_werror_flag=$ac_save_cxx_werror_flag
- CXXFLAGS="-g"
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ CXXFLAGS="-g"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
@@ -4600,10 +4600,10 @@ fi
# Check whether --enable-yang-patch was given.
if test "${enable_yang_patch+set}" = set; then :
enableval=$enable_yang_patch;
- if test "$enableval" = no; then
- enable_yang_patch=no
- else
- enable_yang_patch=yes
+ if test "$enableval" = no; then
+ enable_yang_patch=no
+ else
+ enable_yang_patch=yes
fi
else
@@ -4624,10 +4624,10 @@ fi
# Check whether --enable-publish was given.
if test "${enable_publish+set}" = set; then :
enableval=$enable_publish;
- if test "$enableval" = no; then
- ac_enable_publish=no
- else
- ac_enable_publish=yes
+ if test "$enableval" = no; then
+ ac_enable_publish=no
+ else
+ ac_enable_publish=yes
fi
else
@@ -4845,9 +4845,9 @@ else
# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
#else
# define ISLOWER(c) \
- (('a' <= (c) && (c) <= 'i') \
- || ('j' <= (c) && (c) <= 'r') \
- || ('s' <= (c) && (c) <= 'z'))
+ (('a' <= (c) && (c) <= 'i') \
+ || ('j' <= (c) && (c) <= 'r') \
+ || ('s' <= (c) && (c) <= 'z'))
# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
#endif
@@ -4858,7 +4858,7 @@ main ()
int i;
for (i = 0; i < 256; i++)
if (XOR (islower (i), ISLOWER (i))
- || toupper (i) != TOUPPER (i))
+ || toupper (i) != TOUPPER (i))
return 2;
return 0;
}
@@ -4884,7 +4884,7 @@ fi
# On IRIX 5.3, sys/types and inttypes.h are conflicting.
for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
- inttypes.h stdint.h unistd.h
+ inttypes.h stdint.h unistd.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
@@ -5194,10 +5194,10 @@ fi
# Check whether --enable-http1 was given.
if test "${enable_http1+set}" = set; then :
enableval=$enable_http1;
- if test "$enableval" = no; then
- ac_enable_http1=no
- else
- ac_enable_http1=yes
+ if test "$enableval" = no; then
+ ac_enable_http1=no
+ else
+ ac_enable_http1=yes
fi
else
@@ -5218,10 +5218,10 @@ $as_echo "#define HAVE_HTTP1 true" >>confdefs.h
# Check whether --enable-nghttp2 was given.
if test "${enable_nghttp2+set}" = set; then :
enableval=$enable_nghttp2;
- if test "$enableval" = no; then
- ac_enable_nghttp2=no
- else
- ac_enable_nghttp2=yes
+ if test "$enableval" = no; then
+ ac_enable_nghttp2=no
+ else
+ ac_enable_nghttp2=yes
fi
else
@@ -5783,8 +5783,8 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
# `set' does not quote correctly, so add quotes: double-quote
# substitution turns \\\\ into \\, and sed turns \\ into \.
sed -n \
- "s/'/'\\\\''/g;
- s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+ "s/'/'\\\\''/g;
+ s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
;; #(
*)
# `set' quotes correctly as required by POSIX, so do not add quotes.
@@ -5807,15 +5807,15 @@ if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
{ $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
$as_echo "$as_me: updating cache $cache_file" >&6;}
if test ! -f "$cache_file" || test -h "$cache_file"; then
- cat confcache >"$cache_file"
+ cat confcache >"$cache_file"
else
case $cache_file in #(
*/* | ?:*)
- mv -f confcache "$cache_file"$$ &&
- mv -f "$cache_file"$$ "$cache_file" ;; #(
+ mv -f confcache "$cache_file"$$ &&
+ mv -f "$cache_file"$$ "$cache_file" ;; #(
*)
- mv -f confcache "$cache_file" ;;
- esac
+ mv -f confcache "$cache_file" ;;
+ esac
fi
fi
else
@@ -5920,8 +5920,8 @@ else
arg=$1;
case $arg in #(
*"$as_nl"*)
- expr "X$arg" : "X\\(.*\\)$as_nl";
- arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+ expr "X$arg" : "X\\(.*\\)$as_nl";
+ arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
esac;
expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
'
@@ -5947,7 +5947,7 @@ fi
# there to prevent editors from complaining about space-tab.
# (If _AS_PATH_WALK were called with IFS unset, it would disable word
# splitting by setting IFS to empty value.)
-IFS=" "" $as_nl"
+IFS=" "" $as_nl"
# Find who we are. Look in the path if we contain no directory separator.
as_myself=
@@ -6096,22 +6096,22 @@ fi
as_me=`$as_basename -- "$0" ||
$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
- X"$0" : 'X\(//\)$' \| \
- X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+ X"$0" : 'X\(//\)$' \| \
+ X"$0" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X/"$0" |
sed '/^.*\/\([^/][^/]*\)\/*$/{
- s//\1/
- q
- }
- /^X\/\(\/\/\)$/{
- s//\1/
- q
- }
- /^X\/\(\/\).*/{
- s//\1/
- q
- }
- s/.*/./; q'`
+ s//\1/
+ q
+ }
+ /^X\/\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\/\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
# Avoid depending upon Character Ranges.
as_cr_letters='abcdefghijklmnopqrstuvwxyz'
@@ -6124,10 +6124,10 @@ ECHO_C= ECHO_N= ECHO_T=
case `echo -n x` in #(((((
-n*)
case `echo 'xy\c'` in
- *c*) ECHO_T=' ';; # ECHO_T is single tab character.
+ *c*) ECHO_T=' ';; # ECHO_T is single tab character.
xy) ECHO_C='\c';;
*) echo `echo ksh88 bug on AIX 6.1` > /dev/null
- ECHO_T=' ';;
+ ECHO_T=' ';;
esac;;
*)
ECHO_N='-n';;
@@ -6180,27 +6180,27 @@ as_fn_mkdir_p ()
as_dirs="'$as_qdir' $as_dirs"
as_dir=`$as_dirname -- "$as_dir" ||
$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
- X"$as_dir" : 'X\(//\)[^/]' \| \
- X"$as_dir" : 'X\(//\)$' \| \
- X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+ X"$as_dir" : 'X\(//\)[^/]' \| \
+ X"$as_dir" : 'X\(//\)$' \| \
+ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X"$as_dir" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
- s//\1/
- q
- }
- /^X\(\/\/\)[^/].*/{
- s//\1/
- q
- }
- /^X\(\/\/\)$/{
- s//\1/
- q
- }
- /^X\(\/\).*/{
- s//\1/
- q
- }
- s/.*/./; q'`
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
test -d "$as_dir" && break
done
test -z "$as_dirs" || eval "mkdir $as_dirs"
@@ -6640,21 +6640,21 @@ _ACEOF
# trailing colons and then remove the whole line if VPATH becomes empty
# (actually we leave an empty line to preserve line numbers).
if test "x$srcdir" = x.; then
- ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{
+ ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{
h
s///
s/^/:/
-s/[ ]*$/:/
+s/[ ]*$/:/
s/:\$(srcdir):/:/g
s/:\${srcdir}:/:/g
s/:@srcdir@:/:/g
s/^:*//
s/:*$//
x
-s/\(=[ ]*\).*/\1/
+s/\(=[ ]*\).*/\1/
G
s/\n//
-s/^[^=]*=[ ]*$//
+s/^[^=]*=[ ]*$//
}'
fi
@@ -6696,23 +6696,23 @@ sed -n '
s/.\{148\}/&'"$ac_delim"'/g
t rset
:rset
-s/^[ ]*#[ ]*define[ ][ ]*/ /
+s/^[ ]*#[ ]*define[ ][ ]*/ /
t def
d
:def
s/\\$//
t bsnl
s/["\\]/\\&/g
-s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\
D["\1"]=" \3"/p
-s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p
+s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p
d
:bsnl
s/["\\]/\\&/g
-s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\
D["\1"]=" \3\\\\\\n"\\/p
t cont
-s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p
+s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p
t cont
d
:cont
@@ -6800,14 +6800,14 @@ do
case $ac_f in
-) ac_f="$ac_tmp/stdin";;
*) # Look for the file first in the build tree, then in the source tree
- # (if the path is not absolute). The absolute path cannot be DOS-style,
- # because $ac_f cannot contain `:'.
- test -f "$ac_f" ||
- case $ac_f in
- [\\/$]*) false;;
- *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
- esac ||
- as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
+ # (if the path is not absolute). The absolute path cannot be DOS-style,
+ # because $ac_f cannot contain `:'.
+ test -f "$ac_f" ||
+ case $ac_f in
+ [\\/$]*) false;;
+ *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
+ esac ||
+ as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
esac
case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
as_fn_append ac_file_inputs " '$ac_f'"
@@ -6817,8 +6817,8 @@ do
# use $as_me), people would be surprised to read:
# /* config.h. Generated by config.status. */
configure_input='Generated from '`
- $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
- `' by configure.'
+ $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
+ `' by configure.'
if test x"$ac_file" != x-; then
configure_input="$ac_file. $configure_input"
{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
@@ -6841,27 +6841,27 @@ $as_echo "$as_me: creating $ac_file" >&6;}
ac_dir=`$as_dirname -- "$ac_file" ||
$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
- X"$ac_file" : 'X\(//\)[^/]' \| \
- X"$ac_file" : 'X\(//\)$' \| \
- X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
+ X"$ac_file" : 'X\(//\)[^/]' \| \
+ X"$ac_file" : 'X\(//\)$' \| \
+ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X"$ac_file" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
- s//\1/
- q
- }
- /^X\(\/\/\)[^/].*/{
- s//\1/
- q
- }
- /^X\(\/\/\)$/{
- s//\1/
- q
- }
- /^X\(\/\).*/{
- s//\1/
- q
- }
- s/.*/./; q'`
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
as_dir="$ac_dir"; as_fn_mkdir_p
ac_builddir=.
@@ -6969,7 +6969,7 @@ eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
{ ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
- { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \
+ { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \
"$ac_tmp/out"`; test -z "$ac_out"; } &&
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
which seems to be undefined. Please make sure it is defined" >&5
@@ -6999,7 +6999,7 @@ $as_echo "$as_me: $ac_file is unchanged" >&6;}
else
rm -f "$ac_file"
mv "$ac_tmp/config.h" "$ac_file" \
- || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+ || as_fn_error $? "could not create $ac_file" "$LINENO" 5
fi
else
$as_echo "/* $configure_input */" \
diff --git a/doc/CLI.md b/doc/CLI.md
index a831ae16..282727d3 100644
--- a/doc/CLI.md
+++ b/doc/CLI.md
@@ -23,7 +23,7 @@ Clixon adds some features and structure to CLIgen which include:
set @datamodel, cli_set();
merge @datamodel, cli_merge();
create @datamodel, cli_create();
- show @datamodel, cli_show_auto("running", "xml");
+ show @datamodel, cli_show_auto("running", "xml");
```
The commands (eg `cli_set`) will be called with the first argument an api-path to the referenced object.
* The CLIgen `treename` syntax does not work.
diff --git a/doc/DEVELOP.md b/doc/DEVELOP.md
index 9d2c2d25..3823d7cb 100644
--- a/doc/DEVELOP.md
+++ b/doc/DEVELOP.md
@@ -1,7 +1,7 @@
# README for Clixon developers
* [Code documentation](#documentation)
- * [C style](#c-style)
+ * [C style](#c-style)
* [How to work in git (how-to-work-in-git)](#how-to-work-in-git)
* [How the meta-configure stuff works](#meta-configure)
* [How to debug](#debug)
@@ -47,15 +47,14 @@ myfn(int par1,
ms = NULL;
```
Notes:
-1. the return type of the function and all qualifers on first line (`static int`)
-2. function name and first parameter on second line, thereafter each parameter on own line
+1. The return type of the function and all qualifers on first line (`static int`)
+2. Function name and first parameter on second line, thereafter each parameter on own line
3. Each parameter indented to match the "longest" (`my_structure`)
4. Pointer declarations written: `type *p`, not: `type* p`.
5. All local variables in a function declared at top of function, not inline with C-statements.
6. Local variables can be initialized with scalars or constants, not eg malloc or functions with return values that need to be checked for errors
7. There is a single empty line between local variable declarations and the first function statement.
-
Function signatures are declared in include files or in forward declaration using "one-line" syntax, unless very long:
```
static int myfn(int par1, my_structure *par2);
@@ -123,6 +122,28 @@ files, there is only a single level of include file dependencies.
The drawback is that the same include file may need to be repeated in many .c files.
+### Structs
+
+Struct fields should have a prefix to distinguish them from other struct fields. The prefix should use an abbreviation of the struct name.
+
+Example:
+```
+struct my_struct{
+ int ms_foo;
+ char *ms_string[42];
+}
+```
+where `ms_` is the prefix and is an abbreviation of `my_struct`.
+
+### Global variables
+
+Try to avoid global variables.
+
+If you absolutely need one, try to contain it as static within a
+single C-file, ie do not declare it extern and use it elsewhere.
+
+Also, always prepend a global variable with `_`, underscore.
+
## How to work in git
Clixon uses semantic versioning (https://semver.org).
diff --git a/doc/Doxyfile.graphs b/doc/Doxyfile.graphs
index 7eaf3ef0..667604d9 100644
--- a/doc/Doxyfile.graphs
+++ b/doc/Doxyfile.graphs
@@ -743,7 +743,7 @@ WARN_LOGFILE =
# spaces.
# Note: If this tag is empty the current directory is searched.
-INPUT = ../lib/src/ ../lib/clicon/ ../apps/cli/ ../apps/backend/ ../apps/restconf/ ../apps/netconf ../apps/dbctrl ../datastore ../datastore/text
+INPUT = ../lib/src/ ../lib/clicon/ ../apps/cli/ ../apps/backend/ ../apps/restconf/ ../apps/netconf ../apps/snmp
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
diff --git a/doc/FAQ.md b/doc/FAQ.md
index 41a841b0..618e408e 100644
--- a/doc/FAQ.md
+++ b/doc/FAQ.md
@@ -79,16 +79,16 @@ One of the examples is [a hello world example](https://github.com/clicon/clixon-
## How do you build and install Clixon?
Clixon:
```
- ./configure
- make;
- sudo make install;
+ ./configure
+ make;
+ sudo make install;
```
The main example:
```
- cd example;
- make;
- sudo make install
+ cd example;
+ make;
+ sudo make install
```
## How do I run Clixon example commands?
@@ -162,11 +162,11 @@ clixon_netconf -qf /usr/local/etc/example.xml
However, more useful is to run clixon_netconf as an SSH
subsystem. Register the subsystem in /etc/sshd_config:
```
- Subsystem netconf /usr/local/bin/clixon_netconf -f /usr/local/etc/example.xml
+ Subsystem netconf /usr/local/bin/clixon_netconf -f /usr/local/etc/example.xml
```
and then invoke it from a client using
```
- ssh -s netconf
+ ssh -s netconf
```
## How do I use restconf?
@@ -481,10 +481,10 @@ information using access functions as defined in clixon_backend_transaction.h
You use XPATHs on the XML trees in the transaction commit callback.
Suppose you want to print all added interfaces:
```
- cxobj *target = transaction_target(td); # wanted XML tree
- vec = xpath_vec_flag(target, NULL, "//interface", &len, XML_FLAG_ADD); /* Get added i/fs */
- for (i=0; i */
- cbuf *cbret, /* Reply eg ... */
- void *arg, /* Client session */
- void *regarg) /* Argument given at register */
+ cxobj *xe, /* Request: */
+ cbuf *cbret, /* Reply eg ... */
+ void *arg, /* Client session */
+ void *regarg) /* Argument given at register */
{
cprintf(cbret, " ");
return 0;
@@ -582,10 +582,10 @@ the original operation:
```
static int
my_copy(clicon_handle h, /* Clicon handle */
- cxobj *xe, /* Request: */
- cbuf *cbret, /* Reply eg ... */
- void *arg, /* Client session */
- void *regarg) /* Argument given at register */
+ cxobj *xe, /* Request: */
+ cbuf *cbret, /* Reply eg ... */
+ void *arg, /* Client session */
+ void *regarg) /* Argument given at register */
{
/* Do something */
return 0;
@@ -606,7 +606,7 @@ You can specify an authentication callback for restconf as follows:
```
int
plugin_credentials(clicon_handle h,
- void *arg)
+ void *arg)
{
FCGX_Request *r = (FCGX_Request *)arg;
...
diff --git a/doc/INSTALL.md b/doc/INSTALL.md
index f353efa1..b96ff69e 100644
--- a/doc/INSTALL.md
+++ b/doc/INSTALL.md
@@ -31,7 +31,7 @@ Add a user group, using groupadd and usermod:
### Build from source
```
- configure # Configure clixon to platform
+ configure # Configure clixon to platform
make # Compile
sudo make install # Install libs, binaries, and config-files
sudo make install-include # Install include files (for compiling)
diff --git a/doc/Makefile.in b/doc/Makefile.in
index f0af1e9b..8e2ead5a 100644
--- a/doc/Makefile.in
+++ b/doc/Makefile.in
@@ -37,7 +37,6 @@ datarootdir = @datarootdir@
docdir = @docdir@
pdflatex = @PDFLATEX@
-
SUBDIRS =
.PHONY: clean all doc $(SUBDIRS)
diff --git a/doc/README.md b/doc/README.md
index 36470a65..df73fe41 100644
--- a/doc/README.md
+++ b/doc/README.md
@@ -42,7 +42,7 @@ tool. The existing [CLIgen](http://www.cligen.se) tool was for command-lines onl
Users of Clixon currently include:
* [Netgate](https://www.netgate.com) in particular the [Tnsr product](https://www.tnsr.com/product#architecture)
* [CloudMon360](http://cloudmon360.com)
- * [Grideye](http://hagsand.se/grideye)
+ * [Grideye](http://hagsand.se/grideye)
* [Netclean](https://www.netclean.com/solutions/whitebox) # only CLIgen
* [Prosilient's PTAnalyzer](https://prosilient.com) # only CLIgen
diff --git a/docker/main/README.md b/docker/main/README.md
index 2d6613c9..5d3c4aef 100644
--- a/docker/main/README.md
+++ b/docker/main/README.md
@@ -12,7 +12,7 @@ The directory contains the following files:
- Dockerfile.fcgi Docker build instructions with nginx/fcgi restconf (this is default)
- Dockerfile.native Docker build instructions with native restconf
- Makefile.in "make docker" builds the container
- - README.md This file
+ - README.md This file
- start.sh Start containers
- startsystem.sh Internal start script copied to inside the container (dont run from shell).
- startsystem_fcgi.sh Variant for nginx/fcgi (default)
diff --git a/docker/main/startsystem_fcgi.sh b/docker/main/startsystem_fcgi.sh
index e58d6f48..6d8ab519 100755
--- a/docker/main/startsystem_fcgi.sh
+++ b/docker/main/startsystem_fcgi.sh
@@ -62,21 +62,21 @@ server {
listen 80 default_server;
listen localhost:80 default_server;
listen [::]:80 default_server;
- server_name localhost;
- server_name _;
- location / {
- fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
- include fastcgi_params;
+ server_name localhost;
+ server_name _;
+ location / {
+ fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
+ include fastcgi_params;
}
- location /restconf {
- fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
- include fastcgi_params;
+ location /restconf {
+ fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
+ include fastcgi_params;
}
- location /streams {
- fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
- include fastcgi_params;
- proxy_http_version 1.1;
- proxy_set_header Connection "";
+ location /streams {
+ fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
+ include fastcgi_params;
+ proxy_http_version 1.1;
+ proxy_set_header Connection "";
}
}
EOF
diff --git a/example/main/README.md b/example/main/README.md
index 4d7dbc40..6c51d41a 100644
--- a/example/main/README.md
+++ b/example/main/README.md
@@ -129,7 +129,7 @@ sh> clixon_netconf -qf /usr/local/etc/example.xml
eth1
- ianaift:ip
+ ianaift:ip
true
@@ -179,9 +179,9 @@ In the example, a restconf config is included in the [config file](example.xml):
none
default
- 0.0.0.0
- 80
- false
+ 0.0.0.0
+ 80
+ false
```
@@ -221,20 +221,20 @@ For example, using nginx, install, and edit config file: /etc/nginx/sites-availa
```
server {
...
- location / {
- root /usr/share/nginx/html/restconf;
- fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
- include fastcgi_params;
+ location / {
+ root /usr/share/nginx/html/restconf;
+ fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
+ include fastcgi_params;
}
- location /restconf {
- fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
- include fastcgi_params;
+ location /restconf {
+ fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
+ include fastcgi_params;
}
- location /streams {
- fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
- include fastcgi_params;
- proxy_http_version 1.1;
- proxy_set_header Connection "";
+ location /streams {
+ fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
+ include fastcgi_params;
+ proxy_http_version 1.1;
+ proxy_set_header Connection "";
}
}
```
@@ -315,10 +315,10 @@ curl -X POST http://localhost/restconf/operations/clixon-example:example -H "Co
The example works by defining an RPC in clixon-example.yang:
```
rpc example {
- description "Some example input/output for testing RFC7950 7.14.
+ description "Some example input/output for testing RFC7950 7.14.
RPC simply echoes the input for debugging.";
- input {
- leaf x {
+ input {
+ leaf x {
...
```
@@ -328,10 +328,10 @@ The clixon backend plugin [example_backend.c] reveives the netconf call and rep
```
static int
example_rpc(clicon_handle h,
- cxobj *xe, /* Request: */
- cbuf *cbret, /* Reply eg ... */
- void *arg, /* Client session */
- void *regarg) /* Argument given at register */
+ cxobj *xe, /* Request: */
+ cbuf *cbret, /* Reply eg ... */
+ void *arg, /* Client session */
+ void *regarg) /* Argument given at register */
{
/* code that echoes the request */
return 0;
@@ -375,9 +375,9 @@ The example backend implements an "example:e4" Yang extension, as follows:
```
extension e4 {
description
- "The first child of the ex:e4 (unknown) statement is inserted into
- the module as a regular data statement. This means that 'uses bar;'
- in the ex:e4 statement below is a valid data node";
+ "The first child of the ex:e4 (unknown) statement is inserted into
+ the module as a regular data statement. This means that 'uses bar;'
+ in the ex:e4 statement below is a valid data node";
argument arg;
}
ex:e4 arg1{
diff --git a/example/main/clixon-example@2020-12-01.yang b/example/main/clixon-example@2020-12-01.yang
index c107c366..71980e39 100644
--- a/example/main/clixon-example@2020-12-01.yang
+++ b/example/main/clixon-example@2020-12-01.yang
@@ -3,231 +3,231 @@ module clixon-example {
namespace "urn:example:clixon";
prefix ex;
import ietf-interfaces {
- /* is in yang/optional which means clixon must be installed using --opt-yang-installdir */
- prefix if;
+ /* is in yang/optional which means clixon must be installed using --opt-yang-installdir */
+ prefix if;
}
import ietf-ip {
- prefix ip;
+ prefix ip;
}
import iana-if-type {
- prefix ianaift;
+ prefix ianaift;
}
import ietf-datastores {
- prefix ds;
+ prefix ds;
}
import clixon-autocli{
- prefix autocli;
+ prefix autocli;
}
description
- "Clixon example used as a part of the Clixon test suite.
+ "Clixon example used as a part of the Clixon test suite.
It can be used as a basis for making new Clixon applications.
Note, may change without updating revision, just for testing current master.
";
revision 2020-12-01 {
- description "Added table/parameter/value as the primary data example";
+ description "Added table/parameter/value as the primary data example";
}
revision 2020-03-11 {
- description "Added container around translation list. Released in Clixon 4.4.0";
+ description "Added container around translation list. Released in Clixon 4.4.0";
}
revision 2019-11-05 {
- description "Augment interface. Released in Clixon 4.3.0";
+ description "Augment interface. Released in Clixon 4.3.0";
}
revision 2019-07-23 {
- description "Extension e4. Released in Clixon 4.1.0";
+ description "Extension e4. Released in Clixon 4.1.0";
}
revision 2019-01-13 {
- description "Released in Clixon 3.9";
+ description "Released in Clixon 3.9";
}
/* Example interface type for tests, local callbacks, etc */
identity eth {
- base if:interface-type;
+ base if:interface-type;
}
identity loopback {
- base if:interface-type;
+ base if:interface-type;
}
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
- leaf hidden{
- type string;
- autocli:hide;
- }
- leaf stat{
- description "Inline state data for example application";
- config false;
- type int32;
- }
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
+ leaf hidden{
+ type string;
+ autocli:hide;
+ }
+ leaf stat{
+ description "Inline state data for example application";
+ config false;
+ type int32;
+ }
+ }
}
/* State data (not config) for the example application*/
container state {
- config false;
- description "state data for the example application (must be here for example get operation)";
- leaf-list op {
+ config false;
+ description "state data for the example application (must be here for example get operation)";
+ leaf-list op {
type string;
- }
+ }
}
augment "/if:interfaces/if:interface" {
- container my-status {
- config false;
- description "For testing augment+state";
- leaf int {
- type int32;
- }
- leaf str {
- type string;
- }
- }
+ container my-status {
+ config false;
+ description "For testing augment+state";
+ leaf int {
+ type int32;
+ }
+ leaf str {
+ type string;
+ }
+ }
}
/* yang extension implemented by the example backend code. */
extension e4 {
- description
- "The first child of the ex:e4 (unknown) statement is inserted into
- the module as a regular data statement. This means that 'uses bar;'
- in the ex:e4 statement below is a valid data node";
- argument arg;
+ description
+ "The first child of the ex:e4 (unknown) statement is inserted into
+ the module as a regular data statement. This means that 'uses bar;'
+ in the ex:e4 statement below is a valid data node";
+ argument arg;
}
grouping bar {
- leaf bar{
- type string;
- }
+ leaf bar{
+ type string;
+ }
}
ex:e4 arg1{
- uses bar;
+ uses bar;
}
/* Example notification as used in RFC 5277 and RFC 8040 */
notification event {
- description "Example notification event.";
- leaf event-class {
- type string;
- description "Event class identifier.";
- }
- container reportingEntity {
- description "Event specific information.";
- leaf card {
- type string;
- description "Line card identifier.";
- }
- }
- leaf severity {
- type string;
- description "Event severity description.";
- }
+ description "Example notification event.";
+ leaf event-class {
+ type string;
+ description "Event class identifier.";
+ }
+ container reportingEntity {
+ description "Event specific information.";
+ leaf card {
+ type string;
+ description "Line card identifier.";
+ }
+ }
+ leaf severity {
+ type string;
+ description "Event severity description.";
+ }
}
rpc client-rpc {
- description "Example local client-side RPC that is processed by the
+ description "Example local client-side RPC that is processed by the
the netconf/restconf and not sent to the backend.
This is a clixon implementation detail: some rpc:s
are better processed by the client for API or perf reasons";
- input {
- leaf x {
- type string;
- }
- }
- output {
- leaf x {
- type string;
- }
- }
+ input {
+ leaf x {
+ type string;
+ }
+ }
+ output {
+ leaf x {
+ type string;
+ }
+ }
}
rpc empty {
- description "Smallest possible RPC with no input or output sections";
+ description "Smallest possible RPC with no input or output sections";
}
rpc optional {
- description "Small RPC with optional input and output";
- input {
- leaf x {
- type string;
- }
- }
- output {
- leaf x {
- type string;
- }
- }
+ description "Small RPC with optional input and output";
+ input {
+ leaf x {
+ type string;
+ }
+ }
+ output {
+ leaf x {
+ type string;
+ }
+ }
}
rpc example {
- description "Some example input/output for testing RFC7950 7.14.
+ description "Some example input/output for testing RFC7950 7.14.
RPC simply echoes the input for debugging.";
- input {
- leaf x {
- description
- "If a leaf in the input tree has a 'mandatory' statement with
+ input {
+ leaf x {
+ description
+ "If a leaf in the input tree has a 'mandatory' statement with
the value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- mandatory true;
- }
- leaf y {
- description
- "If a leaf in the input tree has a 'mandatory' statement with the
+ type string;
+ mandatory true;
+ }
+ leaf y {
+ description
+ "If a leaf in the input tree has a 'mandatory' statement with the
value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- default "42";
- }
- leaf-list z {
- description
- "If a leaf-list in the input tree has one or more default
+ type string;
+ default "42";
+ }
+ leaf-list z {
+ description
+ "If a leaf-list in the input tree has one or more default
values, the server MUST use these values (XXX not supported)";
- type string;
- }
- leaf w {
- description
- "If any node has a 'when' statement that would evaluate to
+ type string;
+ }
+ leaf w {
+ description
+ "If any node has a 'when' statement that would evaluate to
'false',then this node MUST NOT be present in the input tree.
(XXX not supported)";
- type string;
- }
- list u0 {
- description "list without key";
- leaf uk{
- type string;
- }
- }
- list u1 {
- description "list with key";
- key uk;
- leaf uk{
- type string;
- }
- leaf val{
- type string;
- }
- }
- }
- output {
- leaf x {
- type string;
- }
- leaf y {
- type string;
- }
- leaf z {
- type string;
- }
- leaf w {
- type string;
- }
- list u0 {
- leaf uk{
- type string;
- }
- }
- list u1 {
- key uk;
- leaf uk{
- type string;
- }
- leaf val{
- type string;
- }
- }
- }
+ type string;
+ }
+ list u0 {
+ description "list without key";
+ leaf uk{
+ type string;
+ }
+ }
+ list u1 {
+ description "list with key";
+ key uk;
+ leaf uk{
+ type string;
+ }
+ leaf val{
+ type string;
+ }
+ }
+ }
+ output {
+ leaf x {
+ type string;
+ }
+ leaf y {
+ type string;
+ }
+ leaf z {
+ type string;
+ }
+ leaf w {
+ type string;
+ }
+ list u0 {
+ leaf uk{
+ type string;
+ }
+ }
+ list u1 {
+ key uk;
+ leaf uk{
+ type string;
+ }
+ leaf val{
+ type string;
+ }
+ }
+ }
}
}
diff --git a/example/main/example.xml.in b/example/main/example.xml.in
index e03d82f1..4cb2a3e4 100644
--- a/example/main/example.xml.in
+++ b/example/main/example.xml.in
@@ -1,6 +1,7 @@
/usr/local/etc/example.xml
ietf-netconf:startup
+ ietf-netconf:confirmed-commit
clixon-restconf:allow-auth-none
clixon-restconf:fcgi
/usr/local/share/clixon
diff --git a/example/main/example_backend.c b/example/main/example_backend.c
index 57515c43..62ca4d1d 100644
--- a/example/main/example_backend.c
+++ b/example/main/example_backend.c
@@ -157,37 +157,37 @@ static int example_stream_timer_setup(clicon_handle h);
int
main_begin(clicon_handle h,
- transaction_data td)
+ transaction_data td)
{
if (_transaction_log)
- transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
+ transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
return 0;
}
/*! This is called on validate (and commit). Check validity of candidate
*/
int
main_validate(clicon_handle h,
- transaction_data td)
+ transaction_data td)
{
if (_transaction_log)
- transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
+ transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
if (_validate_fail_xpath){
- if (_validate_fail_toggle==0 &&
- xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
- _validate_fail_toggle = 1; /* toggle if triggered */
- clicon_err(OE_XML, 0, "User error");
- return -1; /* induce fail */
- }
+ if (_validate_fail_toggle==0 &&
+ xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
+ _validate_fail_toggle = 1; /* toggle if triggered */
+ clicon_err(OE_XML, 0, "User error");
+ return -1; /* induce fail */
+ }
}
return 0;
}
int
main_complete(clicon_handle h,
- transaction_data td)
+ transaction_data td)
{
if (_transaction_log)
- transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
+ transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
return 0;
}
@@ -195,7 +195,7 @@ main_complete(clicon_handle h,
*/
int
main_commit(clicon_handle h,
- transaction_data td)
+ transaction_data td)
{
cxobj *target = transaction_target(td); /* wanted XML tree */
cxobj **vec = NULL;
@@ -204,67 +204,67 @@ main_commit(clicon_handle h,
cvec *nsc = NULL;
if (_transaction_log)
- transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
+ transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
if (_validate_fail_xpath){
- if (_validate_fail_toggle==1 &&
- xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
- _validate_fail_toggle = 0; /* toggle if triggered */
- clicon_err(OE_XML, 0, "User error");
- return -1; /* induce fail */
- }
+ if (_validate_fail_toggle==1 &&
+ xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
+ _validate_fail_toggle = 0; /* toggle if triggered */
+ clicon_err(OE_XML, 0, "User error");
+ return -1; /* induce fail */
+ }
}
/* Create namespace context for xpath */
if ((nsc = xml_nsctx_init(NULL, "urn:ietf:params:xml:ns:yang:ietf-interfaces")) == NULL)
- goto done;
+ goto done;
/* Get all added i/fs */
if (xpath_vec_flag(target, nsc, "//interface", XML_FLAG_ADD, &vec, &len) < 0)
- return -1;
+ return -1;
if (clicon_debug_get())
- for (i=0; ifault Ethernet0 major ") < 0)
- goto done;
+ goto done;
if (example_stream_timer_setup(h) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -308,10 +308,10 @@ example_stream_timer_setup(clicon_handle h)
*/
static int
empty_rpc(clicon_handle h, /* Clicon handle */
- cxobj *xe, /* Request: */
- cbuf *cbret, /* Reply eg ... */
- void *arg, /* client_entry */
- void *regarg) /* Argument given at register */
+ cxobj *xe, /* Request: */
+ cbuf *cbret, /* Reply eg ... */
+ void *arg, /* client_entry */
+ void *regarg) /* Argument given at register */
{
cprintf(cbret, " ", NETCONF_BASE_NAMESPACE);
return 0;
@@ -322,10 +322,10 @@ empty_rpc(clicon_handle h, /* Clicon handle */
*/
static int
example_rpc(clicon_handle h, /* Clicon handle */
- cxobj *xe, /* Request: */
- cbuf *cbret, /* Reply eg ... */
- void *arg, /* client_entry */
- void *regarg) /* Argument given at register */
+ cxobj *xe, /* Request: */
+ cbuf *cbret, /* Reply eg ... */
+ void *arg, /* client_entry */
+ void *regarg) /* Argument given at register */
{
int retval = -1;
cxobj *x = NULL;
@@ -335,24 +335,24 @@ example_rpc(clicon_handle h, /* Clicon handle */
/* get namespace from rpc name, return back in each output parameter */
if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){
- clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
- goto done;
+ clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
+ goto done;
}
cprintf(cbret, "");
if (!xml_child_nr_type(xe, CX_ELMNT))
- cprintf(cbret, " ");
+ cprintf(cbret, " ");
else {
- while ((x = xml_child_each(xe, x, CX_ELMNT)) != NULL) {
- if (xmlns_set(x, NULL, namespace) < 0)
- goto done;
- }
- if (clixon_xml2cbuf(cbret, xe, 0, 0, -1, 1) < 0)
- goto done;
+ while ((x = xml_child_each(xe, x, CX_ELMNT)) != NULL) {
+ if (xmlns_set(x, NULL, namespace) < 0)
+ goto done;
+ }
+ if (clixon_xml2cbuf(cbret, xe, 0, 0, -1, 1) < 0)
+ goto done;
}
cprintf(cbret, " ");
retval = 0;
@@ -364,10 +364,10 @@ example_rpc(clicon_handle h, /* Clicon handle */
*/
static int
example_copy_extra(clicon_handle h, /* Clicon handle */
- cxobj *xe, /* Request: */
- cbuf *cbret, /* Reply eg ... */
- void *arg, /* client_entry */
- void *regarg) /* Argument given at register */
+ cxobj *xe, /* Request: */
+ cbuf *cbret, /* Reply eg ... */
+ void *arg, /* client_entry */
+ void *regarg) /* Argument given at register */
{
int retval = -1;
@@ -382,18 +382,18 @@ example_copy_extra(clicon_handle h, /* Clicon handle */
*/
static int
example_action_reset(clicon_handle h, /* Clicon handle */
- cxobj *xe, /* Request: */
- cbuf *cbret, /* Reply eg ... */
- void *arg, /* client_entry */
- void *regarg) /* Argument given at register */
+ cxobj *xe, /* Request: */
+ cbuf *cbret, /* Reply eg ... */
+ void *arg, /* client_entry */
+ void *regarg) /* Argument given at register */
{
int retval = -1;
char *reset_at;
if ((reset_at = xml_find_body(xe, "reset-at")) != NULL)
- /* Just copy input to output */
- cprintf(cbret, "%s ",
- NETCONF_BASE_NAMESPACE, reset_at);
+ /* Just copy input to output */
+ cprintf(cbret, "%s ",
+ NETCONF_BASE_NAMESPACE, reset_at);
retval = 0;
// done:
return retval;
@@ -421,9 +421,9 @@ example_action_reset(clicon_handle h, /* Clicon handle */
*/
int
example_statedata(clicon_handle h,
- cvec *nsc,
- char *xpath,
- cxobj *xstate)
+ cvec *nsc,
+ char *xpath,
+ cxobj *xstate)
{
int retval = -1;
cxobj **xvec = NULL;
@@ -436,65 +436,65 @@ example_statedata(clicon_handle h,
yang_stmt *yspec = NULL;
if (!_state)
- goto ok;
+ goto ok;
yspec = clicon_dbspec_yang(h);
/* Example of statedata, in this case merging state data with
* state information. In this case adding dummy interface operation state
* to configured interfaces.
* Get config according to xpath */
if ((nsc1 = xml_nsctx_init(NULL, "urn:ietf:params:xml:ns:yang:ietf-interfaces")) == NULL)
- goto done;
+ goto done;
if (xmldb_get0(h, "running", YB_MODULE, nsc1, "/interfaces/interface/name", 1, &xt, NULL, NULL) < 0)
- goto done;
+ goto done;
if (xpath_vec(xt, nsc1, "/interfaces/interface/name", &xvec, &xlen) < 0)
- goto done;
+ goto done;
if (xlen){
- cprintf(cb, "");
- for (i=0; i%s ex:eth up ", name);
- cprintf(cb, "42 foo ");
- cprintf(cb, " ");
- }
- cprintf(cb, " ");
- if (clixon_xml_parse_string(cbuf_get(cb), YB_NONE, NULL, &xstate, NULL) < 0)
- goto done;
+ cprintf(cb, "");
+ for (i=0; i%s ex:eth up ", name);
+ cprintf(cb, "42 foo ");
+ cprintf(cb, "");
+ }
+ cprintf(cb, " ");
+ if (clixon_xml_parse_string(cbuf_get(cb), YB_NONE, NULL, &xstate, NULL) < 0)
+ goto done;
}
/* State in test_yang.sh , test_restconf.sh and test_order.sh */
if (yang_find_module_by_namespace(yspec, "urn:example:clixon") != NULL){
- if (clixon_xml_parse_string(""
- "42 "
- "41 "
- "43 " /* should not be ordered */
- " ",
- YB_NONE,
- NULL, &xstate, NULL) < 0)
- goto done; /* For the case when urn:example:clixon is not loaded */
+ if (clixon_xml_parse_string(""
+ "42 "
+ "41 "
+ "43 " /* should not be ordered */
+ " ",
+ YB_NONE,
+ NULL, &xstate, NULL) < 0)
+ goto done; /* For the case when urn:example:clixon is not loaded */
}
/* Event state from RFC8040 Appendix B.3.1
* Note: (1) order is by-system so is different,
* (2) event-count is XOR on name, so is not 42 and 4
*/
if (yang_find_module_by_namespace(yspec, "urn:example:events") != NULL){
- cbuf_reset(cb);
- cprintf(cb, "");
- cprintf(cb, "interface-down 90 ");
- cprintf(cb, "interface-up 77 ");
- cprintf(cb, " ");
- if (clixon_xml_parse_string(cbuf_get(cb), YB_NONE, NULL, &xstate, NULL) < 0)
- goto done;
+ cbuf_reset(cb);
+ cprintf(cb, "");
+ cprintf(cb, "interface-down 90 ");
+ cprintf(cb, "interface-up 77 ");
+ cprintf(cb, " ");
+ if (clixon_xml_parse_string(cbuf_get(cb), YB_NONE, NULL, &xstate, NULL) < 0)
+ goto done;
}
ok:
retval = 0;
done:
if (nsc1)
- xml_nsctx_free(nsc1);
+ xml_nsctx_free(nsc1);
if (xt)
- xml_free(xt);
+ xml_free(xt);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (xvec)
- free(xvec);
+ free(xvec);
return retval;
}
@@ -513,9 +513,9 @@ example_statedata(clicon_handle h,
*/
int
example_statefile(clicon_handle h,
- cvec *nsc,
- char *xpath,
- cxobj *xstate)
+ cvec *nsc,
+ char *xpath,
+ cxobj *xstate)
{
int retval = -1;
cxobj **xvec = NULL;
@@ -529,57 +529,57 @@ example_statefile(clicon_handle h,
/* If -S is set, then read state data from file */
if (!_state || !_state_file)
- goto ok;
+ goto ok;
yspec = clicon_dbspec_yang(h);
/* Read state file if either not cached, or the cache is NULL */
if (_state_file_cached == 0 ||
- _state_xml_cache == NULL){
- if ((fp = fopen(_state_file, "r")) == NULL){
- clicon_err(OE_UNIX, errno, "open(%s)", _state_file);
- goto done;
- }
- if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL)
- goto done;
- if ((ret = clixon_xml_parse_file(fp, YB_MODULE, yspec, &xt, NULL)) < 0)
- goto done;
- if (_state_file_cached)
- _state_xml_cache = xt;
+ _state_xml_cache == NULL){
+ if ((fp = fopen(_state_file, "r")) == NULL){
+ clicon_err(OE_UNIX, errno, "open(%s)", _state_file);
+ goto done;
+ }
+ if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL)
+ goto done;
+ if ((ret = clixon_xml_parse_file(fp, YB_MODULE, yspec, &xt, NULL)) < 0)
+ goto done;
+ if (_state_file_cached)
+ _state_xml_cache = xt;
}
if (_state_file_cached)
- xt = _state_xml_cache;
+ xt = _state_xml_cache;
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, xpath) < 0)
- goto done;
+ goto done;
/* Mark elements to copy:
* For every node found in x0, mark the tree as changed
*/
for (i=0; i xlen)
- upper = xlen;
+ if ((upper = offset+limit) > xlen)
+ upper = xlen;
}
/* Mark elements to copy:
* For every node found in x0, mark the tree as changed
*/
for (i=lower; imd_status) /* skip if there is proper module-state in datastore */
- goto ok;
+ goto ok;
yspec = clicon_dbspec_yang(h); /* Get all yangs */
/* Get canonical namespaces for using "normalized" prefixes */
if (xml_nsctx_yangspec(yspec, &nsc) < 0)
- goto done;
+ goto done;
/* 1. Remove paths */
for (pp = remove_map; *pp; ++pp){
- /* Find all nodes matching n */
- if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, *pp) < 0)
- goto done;
- /* Remove them */
- /* Loop through all nodes matching mypath and change theoir namespace */
- for (i=0; ims_s0; ms++){
- char *mypath;
- char *mynamespace;
- char *myprefix = NULL;
+ char *mypath;
+ char *mynamespace;
+ char *myprefix = NULL;
- mypath = ms->ms_s0;
- mynamespace = ms->ms_s1;
- if (xml_nsctx_get_prefix(nsc, mynamespace, &myprefix) == 0){
- clicon_err(OE_XML, ENOENT, "Namespace %s not found in canonical namespace map",
- mynamespace);
- goto done;
- }
- /* Find all nodes matching mypath */
- if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, mypath) < 0)
- goto done;
- /* Loop through all nodes matching mypath and change theoir namespace */
- for (i=0; ims_s0;
+ mynamespace = ms->ms_s1;
+ if (xml_nsctx_get_prefix(nsc, mynamespace, &myprefix) == 0){
+ clicon_err(OE_XML, ENOENT, "Namespace %s not found in canonical namespace map",
+ mynamespace);
+ goto done;
+ }
+ /* Find all nodes matching mypath */
+ if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, mypath) < 0)
+ goto done;
+ /* Loop through all nodes matching mypath and change theoir namespace */
+ for (i=0; i"
- "lo ex:loopback "
- " ", YB_MODULE, yspec, &xt, NULL) < 0)
- goto done;
+ "lo ex:loopback "
+ " ", YB_MODULE, yspec, &xt, NULL) < 0)
+ goto done;
/* Replace parent w first child */
if (xml_rootchild(xt, 0, &xt) < 0)
- goto done;
+ goto done;
if ((cbret = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
/* Merge user reset state */
if ((ret = xmldb_put(h, (char*)db, OP_MERGE, xt, clicon_username_get(h), cbret)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- clicon_err(OE_XML, 0, "Error when writing to XML database: %s",
- cbuf_get(cbret));
- goto done;
+ clicon_err(OE_XML, 0, "Error when writing to XML database: %s",
+ cbuf_get(cbret));
+ goto done;
}
ok:
retval = 0;
done:
if (cbret)
- cbuf_free(cbret);
+ cbuf_free(cbret);
if (xt != NULL)
- xml_free(xt);
+ xml_free(xt);
return retval;
}
@@ -1208,14 +1208,14 @@ example_start(clicon_handle h)
* such as "/sfarm:server/sfarm:reset"
*/
if (_action_instanceid){
- if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_FATAL, 0, "No DB_SPEC");
- goto done;
- }
- if (yang_abs_schema_nodeid(yspec, _action_instanceid, &ya) == 0){
- if (ya && action_callback_register(h, ya, example_action_reset, NULL) < 0)
- goto done;
- }
+ if ((yspec = clicon_dbspec_yang(h)) == NULL){
+ clicon_err(OE_FATAL, 0, "No DB_SPEC");
+ goto done;
+ }
+ if (yang_abs_schema_nodeid(yspec, _action_instanceid, &ya) == 0){
+ if (ya && action_callback_register(h, ya, example_action_reset, NULL) < 0)
+ goto done;
+ }
}
retval = 0;
done:
@@ -1239,24 +1239,24 @@ example_daemon(clicon_handle h)
/* Read state file (or should this be in init/start?) */
if (_state && _state_file && _state_file_cached){
- yspec = clicon_dbspec_yang(h);
- if ((fp = fopen(_state_file, "r")) == NULL){
- clicon_err(OE_UNIX, errno, "open(%s)", _state_file);
- goto done;
- }
- /* Need to be yang bound for eg xml_copy_marked() in example_pagination
- */
- if ((ret = clixon_xml_parse_file(fp, YB_MODULE, yspec, &_state_xml_cache, &xerr)) < 0)
- goto done;
- if (ret == 0){
- xml_print(stderr, xerr);
- goto done;
- }
+ yspec = clicon_dbspec_yang(h);
+ if ((fp = fopen(_state_file, "r")) == NULL){
+ clicon_err(OE_UNIX, errno, "open(%s)", _state_file);
+ goto done;
+ }
+ /* Need to be yang bound for eg xml_copy_marked() in example_pagination
+ */
+ if ((ret = clixon_xml_parse_file(fp, YB_MODULE, yspec, &_state_xml_cache, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ xml_print(stderr, xerr);
+ goto done;
+ }
}
retval = 0;
done:
if (fp)
- fclose(fp);
+ fclose(fp);
return retval;
}
@@ -1264,8 +1264,8 @@ int
example_exit(clicon_handle h)
{
if (_state_xml_cache){
- xml_free(_state_xml_cache);
- _state_xml_cache = NULL;
+ xml_free(_state_xml_cache);
+ _state_xml_cache = NULL;
}
return 0;
}
@@ -1313,121 +1313,121 @@ clixon_plugin_init(clicon_handle h)
/* Get user command-line options (after --) */
if (clicon_argv_get(h, &argc, &argv) < 0)
- goto done;
+ goto done;
opterr = 0;
optind = 1;
while ((c = getopt(argc, argv, BACKEND_EXAMPLE_OPTS)) != -1)
- switch (c) {
- case 'a':
- _action_instanceid = optarg;
- break;
- case 'n':
- _notification_stream = 1;
- break;
- case 'r':
- _reset = 1;
- break;
- case 's': /* state callback */
- _state = 1;
- break;
- case 'S': /* state file (requires -s) */
- _state_file = optarg;
- break;
- case 'x': /* state xpath (requires -sS) */
- _state_xpath = optarg;
- break;
- case 'i': /* read state file on init not by request (requires -sS */
- _state_file_cached = 1;
- break;
+ switch (c) {
+ case 'a':
+ _action_instanceid = optarg;
+ break;
+ case 'n':
+ _notification_stream = 1;
+ break;
+ case 'r':
+ _reset = 1;
+ break;
+ case 's': /* state callback */
+ _state = 1;
+ break;
+ case 'S': /* state file (requires -s) */
+ _state_file = optarg;
+ break;
+ case 'x': /* state xpath (requires -sS) */
+ _state_xpath = optarg;
+ break;
+ case 'i': /* read state file on init not by request (requires -sS */
+ _state_file_cached = 1;
+ break;
case 'u': /* module-specific upgrade */
_module_upgrade = 1;
break;
case 'U': /* general-purpose upgrade */
_general_upgrade = 1;
- break;
- case 't': /* transaction log */
- _transaction_log = 1;
- break;
- case 'V': /* validate fail */
- _validate_fail_xpath = optarg;
- break;
- }
+ break;
+ case 't': /* transaction log */
+ _transaction_log = 1;
+ break;
+ case 'V': /* validate fail */
+ _validate_fail_xpath = optarg;
+ break;
+ }
if (_state_file){
- api.ca_statedata = example_statefile; /* Switch state data callback */
- if (_state_xpath){
- /* State pagination callbacks */
- if (clixon_pagination_cb_register(h,
- example_pagination,
- _state_xpath,
- NULL) < 0)
- goto done;
- }
+ api.ca_statedata = example_statefile; /* Switch state data callback */
+ if (_state_xpath){
+ /* State pagination callbacks */
+ if (clixon_pagination_cb_register(h,
+ example_pagination,
+ _state_xpath,
+ NULL) < 0)
+ goto done;
+ }
}
-
+
if (_notification_stream){
- /* Example stream initialization:
- * 1) Register EXAMPLE stream
- * 2) setup timer for notifications, so something happens on stream
- * 3) setup stream callbacks for notification to push channel
- */
- if (clicon_option_exists(h, "CLICON_STREAM_RETENTION"))
- retention.tv_sec = clicon_option_int(h, "CLICON_STREAM_RETENTION");
- if (stream_add(h, "EXAMPLE", "Example event stream", 1, &retention) < 0)
- goto done;
- /* Enable nchan pub/sub streams
- * assumes: CLIXON_PUBLISH_STREAMS, eg configure --enable-publish
- */
- if (clicon_option_exists(h, "CLICON_STREAM_PUB") &&
- stream_publish(h, "EXAMPLE") < 0)
- goto done;
- if (example_stream_timer_setup(h) < 0)
- goto done;
+ /* Example stream initialization:
+ * 1) Register EXAMPLE stream
+ * 2) setup timer for notifications, so something happens on stream
+ * 3) setup stream callbacks for notification to push channel
+ */
+ if (clicon_option_exists(h, "CLICON_STREAM_RETENTION"))
+ retention.tv_sec = clicon_option_int(h, "CLICON_STREAM_RETENTION");
+ if (stream_add(h, "EXAMPLE", "Example event stream", 1, &retention) < 0)
+ goto done;
+ /* Enable nchan pub/sub streams
+ * assumes: CLIXON_PUBLISH_STREAMS, eg configure --enable-publish
+ */
+ if (clicon_option_exists(h, "CLICON_STREAM_PUB") &&
+ stream_publish(h, "EXAMPLE") < 0)
+ goto done;
+ if (example_stream_timer_setup(h) < 0)
+ goto done;
}
/* Register callback for routing rpc calls
*/
/* From example.yang (clicon) */
if (rpc_callback_register(h, empty_rpc,
- NULL,
- "urn:example:clixon",
- "empty"/* Xml tag when callback is made */
- ) < 0)
- goto done;
+ NULL,
+ "urn:example:clixon",
+ "empty"/* Xml tag when callback is made */
+ ) < 0)
+ goto done;
/* Same as example but with optional input/output */
if (rpc_callback_register(h, example_rpc,
- NULL,
- "urn:example:clixon",
- "optional"/* Xml tag when callback is made */
- ) < 0)
- goto done;
+ NULL,
+ "urn:example:clixon",
+ "optional"/* Xml tag when callback is made */
+ ) < 0)
+ goto done;
/* Same as example but with optional input/output */
if (rpc_callback_register(h, example_rpc,
- NULL,
- "urn:example:clixon",
- "example"/* Xml tag when callback is made */
- ) < 0)
- goto done;
+ NULL,
+ "urn:example:clixon",
+ "example"/* Xml tag when callback is made */
+ ) < 0)
+ goto done;
/* Called before the regular system copy_config callback
* If you want to have it called _after_ the system callback, place this call in
* the _start function.
*/
if (rpc_callback_register(h, example_copy_extra,
- NULL,
- NETCONF_BASE_NAMESPACE,
- "copy-config"
- ) < 0)
- goto done;
+ NULL,
+ NETCONF_BASE_NAMESPACE,
+ "copy-config"
+ ) < 0)
+ goto done;
/* Upgrade callback: if you start the backend with -- -u you will get the
* test interface example. Otherwise the auto-upgrade feature is enabled.
*/
if (_module_upgrade){
- if (upgrade_callback_register(h, upgrade_interfaces, "urn:example:interfaces", NULL) < 0)
- goto done;
+ if (upgrade_callback_register(h, upgrade_interfaces, "urn:example:interfaces", NULL) < 0)
+ goto done;
}
else
- if (upgrade_callback_register(h, xml_changelog_upgrade, NULL, NULL) < 0)
- goto done;
+ if (upgrade_callback_register(h, xml_changelog_upgrade, NULL, NULL) < 0)
+ goto done;
/* Return plugin API */
return &api;
done:
diff --git a/example/main/example_backend_nacm.c b/example/main/example_backend_nacm.c
index 9ee872c2..d44c8d76 100644
--- a/example/main/example_backend_nacm.c
+++ b/example/main/example_backend_nacm.c
@@ -82,37 +82,37 @@ static int _validate_fail_toggle = 0; /* fail at validate and commit */
int
nacm_begin(clicon_handle h,
- transaction_data td)
+ transaction_data td)
{
if (_transaction_log)
- transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
+ transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
return 0;
}
/*! This is called on validate (and commit). Check validity of candidate
*/
int
nacm_validate(clicon_handle h,
- transaction_data td)
+ transaction_data td)
{
if (_transaction_log)
- transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
+ transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
if (_validate_fail_xpath){
- if (_validate_fail_toggle==0 &&
- xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
- _validate_fail_toggle = 1; /* toggle if triggered */
- clicon_err(OE_XML, 0, "User error");
- return -1; /* induce fail */
- }
+ if (_validate_fail_toggle==0 &&
+ xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
+ _validate_fail_toggle = 1; /* toggle if triggered */
+ clicon_err(OE_XML, 0, "User error");
+ return -1; /* induce fail */
+ }
}
return 0;
}
int
nacm_complete(clicon_handle h,
- transaction_data td)
+ transaction_data td)
{
if (_transaction_log)
- transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
+ transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
return 0;
}
@@ -120,54 +120,54 @@ nacm_complete(clicon_handle h,
*/
int
nacm_commit(clicon_handle h,
- transaction_data td)
+ transaction_data td)
{
if (_transaction_log)
- transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
+ transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
if (_validate_fail_xpath){
- if (_validate_fail_toggle==1 &&
- xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
- _validate_fail_toggle = 0; /* toggle if triggered */
- clicon_err(OE_XML, 0, "User error");
- return -1; /* induce fail */
- }
+ if (_validate_fail_toggle==1 &&
+ xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
+ _validate_fail_toggle = 0; /* toggle if triggered */
+ clicon_err(OE_XML, 0, "User error");
+ return -1; /* induce fail */
+ }
}
return 0;
}
int
nacm_commit_done(clicon_handle h,
- transaction_data td)
+ transaction_data td)
{
if (_transaction_log)
- transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
+ transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
return 0;
}
int
nacm_revert(clicon_handle h,
- transaction_data td)
+ transaction_data td)
{
if (_transaction_log)
- transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
+ transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
return 0;
}
int
nacm_end(clicon_handle h,
- transaction_data td)
+ transaction_data td)
{
if (_transaction_log)
- transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
+ transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
return 0;
}
int
nacm_abort(clicon_handle h,
- transaction_data td)
+ transaction_data td)
{
if (_transaction_log)
- transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
+ transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
return 0;
}
@@ -184,24 +184,24 @@ nacm_abort(clicon_handle h,
*/
int
nacm_statedata(clicon_handle h,
- cvec *nsc,
- char *xpath,
- cxobj *xstate)
+ cvec *nsc,
+ char *xpath,
+ cxobj *xstate)
{
int retval = -1;
cxobj **xvec = NULL;
/* Example of (static) statedata, real code would poll state */
if (clixon_xml_parse_string(""
- "0 "
- "0 "
- "0 "
- " ", YB_NONE, NULL, &xstate, NULL) < 0)
- goto done;
+ "0 "
+ "0 "
+ "0 "
+ "", YB_NONE, NULL, &xstate, NULL) < 0)
+ goto done;
retval = 0;
done:
if (xvec)
- free(xvec);
+ free(xvec);
return retval;
}
@@ -239,25 +239,25 @@ clixon_plugin_init(clicon_handle h)
clicon_debug(1, "%s backend nacm", __FUNCTION__);
/* Get user command-line options (after --) */
if (clicon_argv_get(h, &argc, &argv) < 0)
- goto done;
+ goto done;
opterr = 0;
optind = 1;
while ((c = getopt(argc, argv, BACKEND_NACM_OPTS)) != -1)
- switch (c) {
- case 't': /* transaction log */
- _transaction_log = 1;
- break;
- case 'v': /* validate fail */
- _validate_fail_xpath = optarg;
- break;
- }
+ switch (c) {
+ case 't': /* transaction log */
+ _transaction_log = 1;
+ break;
+ case 'v': /* validate fail */
+ _validate_fail_xpath = optarg;
+ break;
+ }
nacm_mode = clicon_option_str(h, "CLICON_NACM_MODE");
if (nacm_mode==NULL || strcmp(nacm_mode, "disabled") == 0){
- clicon_log(LOG_DEBUG, "%s CLICON_NACM_MODE not enabled: example nacm module disabled", __FUNCTION__);
- /* Skip nacm module if not enabled _unless_ we use transaction tests */
- if (_transaction_log == 0)
- return NULL;
+ clicon_log(LOG_DEBUG, "%s CLICON_NACM_MODE not enabled: example nacm module disabled", __FUNCTION__);
+ /* Skip nacm module if not enabled _unless_ we use transaction tests */
+ if (_transaction_log == 0)
+ return NULL;
}
/* Return plugin API */
return &api;
diff --git a/example/main/example_cli.c b/example/main/example_cli.c
index 7cafb23d..b0082fb4 100644
--- a/example/main/example_cli.c
+++ b/example/main/example_cli.c
@@ -67,29 +67,29 @@ mycallback(clicon_handle h, cvec *cvv, cvec *argv)
fprintf(stderr, "arg = %s\n", cv_string_get(cvec_i(argv,0))); /* get string value */
if ((nsc = xml_nsctx_init(NULL, "urn:example:clixon")) == NULL)
- goto done;
+ goto done;
/* Show eth0 interfaces config using XPATH */
if (clicon_rpc_get_config(h, NULL, "running",
- "/interfaces/interface[name='eth0']",
- nsc, NULL,
- &xret) < 0)
- goto done;
+ "/interfaces/interface[name='eth0']",
+ nsc, NULL,
+ &xret) < 0)
+ goto done;
if (clixon_xml2file(stdout, xret, 0, 1, cligen_output, 0, 1) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
/*! Example "downcall", ie initiate an RPC to the backend */
int
example_client_rpc(clicon_handle h,
- cvec *cvv,
- cvec *argv)
+ cvec *cvv,
+ cvec *argv)
{
int retval = -1;
cg_var *cva;
@@ -102,25 +102,25 @@ example_client_rpc(clicon_handle h,
cva = cvec_find(cvv, "a"); /* get a cligen variable from vector */
/* Create XML for example netconf RPC */
if (clixon_xml_parse_va(YB_NONE, NULL, &xtop, NULL,
- ""
- "%s ",
- NETCONF_BASE_NAMESPACE,
- clicon_username_get(h),
- NETCONF_MESSAGE_ID_ATTR,
- cv_string_get(cva)) < 0)
- goto done;
+ ""
+ "%s ",
+ NETCONF_BASE_NAMESPACE,
+ clicon_username_get(h),
+ NETCONF_MESSAGE_ID_ATTR,
+ cv_string_get(cva)) < 0)
+ goto done;
/* Skip top-level */
xrpc = xml_child_i(xtop, 0);
/* Send to backend */
if (clicon_rpc_netconf_xml(h, xrpc, &xret, NULL) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Get configuration", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Get configuration", NULL);
+ goto done;
}
/* Print result */
if (clixon_xml2file(stdout, xml_child_i(xret, 0), 0, 0, cligen_output, 0, 1) < 0)
- goto done;
+ goto done;
fprintf(stdout,"\n");
/* pretty-print:
@@ -129,9 +129,9 @@ example_client_rpc(clicon_handle h,
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (xtop)
- xml_free(xtop);
+ xml_free(xtop);
return retval;
}
@@ -168,7 +168,7 @@ clixon_plugin_init(clicon_handle h)
*/
int
cli_incstr(cligen_handle h,
- cg_var *cv)
+ cg_var *cv)
{
char *str;
int i;
@@ -176,12 +176,12 @@ cli_incstr(cligen_handle h,
/* Filter out other than strings
* this is specific to this example, one can do translation */
if (cv == NULL || cv_type_get(cv) != CGV_STRING)
- return 0;
+ return 0;
if ((str = cv_string_get(cv)) == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "cv string is NULL");
- return -1;
+ clicon_err(OE_PLUGIN, EINVAL, "cv string is NULL");
+ return -1;
}
for (i=0; i("The 'persist' value of the persistent confirmed-commit")], cli_commit(); {
+ ("Cancel an ongoing confirmed-commit"), cli_commit();
+ ("Require a confirming commit") {
+ [persist("Make this confirmed-commit persistent") ("The value that must be provided as 'persist-id' in the confirming-commit or cancel-commit")]
+ [("The rollback timeout in seconds")], cli_commit();
+ }
+ }
+}
quit("Quit"), cli_quit();
debug("Debugging parts of the system"){
diff --git a/example/main/example_netconf.c b/example/main/example_netconf.c
index 31b5f83b..c59a8255 100644
--- a/example/main/example_netconf.c
+++ b/example/main/example_netconf.c
@@ -68,10 +68,10 @@ plugin_exit(clicon_handle h)
*/
int
netconf_client_rpc(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
cxobj *x = NULL;
@@ -79,19 +79,19 @@ netconf_client_rpc(clicon_handle h,
/* get namespace from rpc name, return back in each output parameter */
if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){
- clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
- goto done;
+ clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
+ goto done;
}
cprintf(cbret, "", NETCONF_BASE_NAMESPACE);
if (!xml_child_nr_type(xe, CX_ELMNT))
- cprintf(cbret, " ");
+ cprintf(cbret, " ");
else{
- while ((x = xml_child_each(xe, x, CX_ELMNT)) != NULL) {
- if (xmlns_set(x, NULL, namespace) < 0)
- goto done;
- }
- if (clixon_xml2cbuf(cbret, xe, 0, 0, -1, 1) < 0)
- goto done;
+ while ((x = xml_child_each(xe, x, CX_ELMNT)) != NULL) {
+ if (xmlns_set(x, NULL, namespace) < 0)
+ goto done;
+ }
+ if (clixon_xml2cbuf(cbret, xe, 0, 0, -1, 1) < 0)
+ goto done;
}
cprintf(cbret, " ");
retval = 0;
@@ -121,8 +121,8 @@ clixon_plugin_init(clicon_handle h)
clicon_debug(1, "%s restconf", __FUNCTION__);
/* Register local netconf rpc client (note not backend rpc client) */
if (rpc_callback_register(h, netconf_client_rpc, NULL,
- "urn:example:clixon", "client-rpc") < 0)
- return NULL;
+ "urn:example:clixon", "client-rpc") < 0)
+ return NULL;
return &api;
}
diff --git a/example/main/example_restconf.c b/example/main/example_restconf.c
index 90b1aaa1..5ca4a4dc 100644
--- a/example/main/example_restconf.c
+++ b/example/main/example_restconf.c
@@ -54,7 +54,7 @@
#define RESTCONF_EXAMPLE_OPTS ""
static const char Base64[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char Pad64 = '=';
/* skips all whitespace anywhere.
@@ -65,8 +65,8 @@ static const char Pad64 = '=';
*/
int
b64_decode(const char *src,
- char *target,
- size_t targsize)
+ char *target,
+ size_t targsize)
{
int tarindex, state, ch;
char *pos;
@@ -75,59 +75,59 @@ b64_decode(const char *src,
tarindex = 0;
while ((ch = *src++) != '\0') {
- if (isspace(ch)) /* Skip whitespace anywhere. */
- continue;
+ if (isspace(ch)) /* Skip whitespace anywhere. */
+ continue;
- if (ch == Pad64)
- break;
+ if (ch == Pad64)
+ break;
- pos = strchr(Base64, ch);
- if (pos == 0) /* A non-base64 character. */
- return (-1);
+ pos = strchr(Base64, ch);
+ if (pos == 0) /* A non-base64 character. */
+ return (-1);
- switch (state) {
- case 0:
- if (target) {
- if ((size_t)tarindex >= targsize)
- return (-1);
- target[tarindex] = (pos - Base64) << 2;
- }
- state = 1;
- break;
- case 1:
- if (target) {
- if ((size_t)tarindex + 1 >= targsize)
- return (-1);
- target[tarindex] |= (pos - Base64) >> 4;
- target[tarindex+1] = ((pos - Base64) & 0x0f)
- << 4 ;
- }
- tarindex++;
- state = 2;
- break;
- case 2:
- if (target) {
- if ((size_t)tarindex + 1 >= targsize)
- return (-1);
- target[tarindex] |= (pos - Base64) >> 2;
- target[tarindex+1] = ((pos - Base64) & 0x03)
- << 6;
- }
- tarindex++;
- state = 3;
- break;
- case 3:
- if (target) {
- if ((size_t)tarindex >= targsize)
- return (-1);
- target[tarindex] |= (pos - Base64);
- }
- tarindex++;
- state = 0;
- break;
- default:
- return -1;
- }
+ switch (state) {
+ case 0:
+ if (target) {
+ if ((size_t)tarindex >= targsize)
+ return (-1);
+ target[tarindex] = (pos - Base64) << 2;
+ }
+ state = 1;
+ break;
+ case 1:
+ if (target) {
+ if ((size_t)tarindex + 1 >= targsize)
+ return (-1);
+ target[tarindex] |= (pos - Base64) >> 4;
+ target[tarindex+1] = ((pos - Base64) & 0x0f)
+ << 4 ;
+ }
+ tarindex++;
+ state = 2;
+ break;
+ case 2:
+ if (target) {
+ if ((size_t)tarindex + 1 >= targsize)
+ return (-1);
+ target[tarindex] |= (pos - Base64) >> 2;
+ target[tarindex+1] = ((pos - Base64) & 0x03)
+ << 6;
+ }
+ tarindex++;
+ state = 3;
+ break;
+ case 3:
+ if (target) {
+ if ((size_t)tarindex >= targsize)
+ return (-1);
+ target[tarindex] |= (pos - Base64);
+ }
+ tarindex++;
+ state = 0;
+ break;
+ default:
+ return -1;
+ }
}
/*
@@ -135,50 +135,50 @@ b64_decode(const char *src,
* on a byte boundary, and/or with erroneous trailing characters.
*/
- if (ch == Pad64) { /* We got a pad char. */
- ch = *src++; /* Skip it, get next. */
- switch (state) {
- case 0: /* Invalid = in first position */
- case 1: /* Invalid = in second position */
- return (-1);
+ if (ch == Pad64) { /* We got a pad char. */
+ ch = *src++; /* Skip it, get next. */
+ switch (state) {
+ case 0: /* Invalid = in first position */
+ case 1: /* Invalid = in second position */
+ return (-1);
- case 2: /* Valid, means one byte of info */
- /* Skip any number of spaces. */
- for ((void)NULL; ch != '\0'; ch = *src++)
- if (!isspace(ch))
- break;
- /* Make sure there is another trailing = sign. */
- if (ch != Pad64)
- return (-1);
- ch = *src++; /* Skip the = */
- /* Fall through to "single trailing =" case. */
- /* FALLTHROUGH */
+ case 2: /* Valid, means one byte of info */
+ /* Skip any number of spaces. */
+ for ((void)NULL; ch != '\0'; ch = *src++)
+ if (!isspace(ch))
+ break;
+ /* Make sure there is another trailing = sign. */
+ if (ch != Pad64)
+ return (-1);
+ ch = *src++; /* Skip the = */
+ /* Fall through to "single trailing =" case. */
+ /* FALLTHROUGH */
- case 3: /* Valid, means two bytes of info */
- /*
- * We know this char is an =. Is there anything but
- * whitespace after it?
- */
- for ((void)NULL; ch != '\0'; ch = *src++)
- if (!isspace(ch))
- return (-1);
+ case 3: /* Valid, means two bytes of info */
+ /*
+ * We know this char is an =. Is there anything but
+ * whitespace after it?
+ */
+ for ((void)NULL; ch != '\0'; ch = *src++)
+ if (!isspace(ch))
+ return (-1);
- /*
- * Now make sure for cases 2 and 3 that the "extra"
- * bits that slopped past the last full byte were
- * zeros. If we don't check them, they become a
- * subliminal channel.
- */
- if (target && target[tarindex] != 0)
- return (-1);
- }
+ /*
+ * Now make sure for cases 2 and 3 that the "extra"
+ * bits that slopped past the last full byte were
+ * zeros. If we don't check them, they become a
+ * subliminal channel.
+ */
+ if (target && target[tarindex] != 0)
+ return (-1);
+ }
} else {
- /*
- * We ended by seeing the end of the string. Make sure we
- * have no partial bytes lying around.
- */
- if (state != 0)
- return (-1);
+ /*
+ * We ended by seeing the end of the string. Make sure we
+ * have no partial bytes lying around.
+ */
+ if (state != 0)
+ return (-1);
}
return (tarindex);
@@ -198,8 +198,8 @@ b64_decode(const char *src,
*/
static int
example_basic_auth(clicon_handle h,
- void *req,
- char **authp)
+ void *req,
+ char **authp)
{
int retval = -1;
cxobj *xt = NULL;
@@ -213,41 +213,41 @@ example_basic_auth(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (authp == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL");
+ goto done;
}
/* At this point in the code we must use HTTP basic authentication */
if ((auth = restconf_param_get(h, "HTTP_AUTHORIZATION")) == NULL)
- goto fail;
+ goto fail;
if (strlen(auth) < strlen("Basic "))
- goto fail;
+ goto fail;
if (strncmp("Basic ", auth, strlen("Basic ")))
- goto fail;
+ goto fail;
auth += strlen("Basic ");
authlen = strlen(auth)*2;
if ((user = malloc(authlen)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(user, 0, authlen);
if ((ret = b64_decode(auth, user, authlen)) < 0)
- goto done;
+ goto done;
/* auth string is on the format user:passwd */
if ((passwd = index(user,':')) == NULL)
- goto fail;
+ goto fail;
*passwd = '\0';
passwd++;
clicon_debug(1, "%s http user:%s passwd:%s", __FUNCTION__, user, passwd);
/* Here get auth sub-tree where all the users are */
if ((cb = cbuf_new()) == NULL)
- goto done;
+ goto done;
/* XXX Three hardcoded user/passwd (from RFC8341 A.1)*/
if (strcmp(user, "wilma")==0 || strcmp(user, "andy")==0 ||
- strcmp(user, "guest")==0){
- passwd2 = "bar";
+ strcmp(user, "guest")==0){
+ passwd2 = "bar";
}
if (strcmp(passwd, passwd2))
- goto fail;
+ goto fail;
*authp = user; /* authenticated */
user=NULL; /* to avoid free below */
retval = 1;
@@ -256,7 +256,7 @@ example_basic_auth(clicon_handle h,
if (user)
free(user);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (xt)
xml_free(xt);
return retval;
@@ -280,24 +280,24 @@ example_basic_auth(clicon_handle h,
*/
int
example_restconf_credentials(clicon_handle h,
- void *req,
- clixon_auth_type_t auth_type,
- char **authp)
+ void *req,
+ clixon_auth_type_t auth_type,
+ char **authp)
{
int retval = -1;
clicon_debug(1, "%s auth:%s", __FUNCTION__, clixon_auth_type_int2str(auth_type));
switch (auth_type){
case CLIXON_AUTH_NONE: /* FEATURE clixon-restconf:allow-auth-none must be enabled */
- retval = 0;
- break;
+ retval = 0;
+ break;
case CLIXON_AUTH_CLIENT_CERTIFICATE:
- retval = 0; /* Ignore, use default */
- break;
+ retval = 0; /* Ignore, use default */
+ break;
case CLIXON_AUTH_USER:
- if ((retval = example_basic_auth(h, req, authp)) < 0)
- goto done;
- break;
+ if ((retval = example_basic_auth(h, req, authp)) < 0)
+ goto done;
+ break;
}
done:
clicon_debug(1, "%s retval:%d authp:%s", __FUNCTION__, retval, *authp);
@@ -308,10 +308,10 @@ example_restconf_credentials(clicon_handle h,
*/
int
restconf_client_rpc(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
cxobj *x = NULL;
@@ -319,19 +319,19 @@ restconf_client_rpc(clicon_handle h,
/* get namespace from rpc name, return back in each output parameter */
if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){
- clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
- goto done;
+ clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
+ goto done;
}
cprintf(cbret, "", NETCONF_BASE_NAMESPACE);
if (!xml_child_nr_type(xe, CX_ELMNT))
- cprintf(cbret, " ");
+ cprintf(cbret, " ");
else {
- while ((x = xml_child_each(xe, x, CX_ELMNT)) != NULL) {
- if (xmlns_set(x, NULL, namespace) < 0)
- goto done;
- }
- if (clixon_xml2cbuf(cbret, xe, 0, 0, -1, 1) < 0)
- goto done;
+ while ((x = xml_child_each(xe, x, CX_ELMNT)) != NULL) {
+ if (xmlns_set(x, NULL, namespace) < 0)
+ goto done;
+ }
+ if (clixon_xml2cbuf(cbret, xe, 0, 0, -1, 1) < 0)
+ goto done;
}
cprintf(cbret, " ");
retval = 0;
@@ -374,16 +374,16 @@ clixon_plugin_init(clicon_handle h)
clicon_debug(1, "%s restconf", __FUNCTION__);
/* Get user command-line options (after --) */
if (clicon_argv_get(h, &argc, &argv) < 0)
- return NULL;
+ return NULL;
opterr = 0;
optind = 1;
while ((c = getopt(argc, argv, RESTCONF_EXAMPLE_OPTS)) != -1)
- switch (c) {
- default:
- break;
- }
+ switch (c) {
+ default:
+ break;
+ }
/* Register local netconf rpc client (note not backend rpc client) */
if (rpc_callback_register(h, restconf_client_rpc, NULL, "urn:example:clixon", "client-rpc") < 0)
- return NULL;
+ return NULL;
return &api;
}
diff --git a/include/clixon_config.h.in b/include/clixon_config.h.in
index ddb18d98..02f01bdf 100644
--- a/include/clixon_config.h.in
+++ b/include/clixon_config.h.in
@@ -27,6 +27,9 @@
/* Define to 1 if you have the header file. */
#undef HAVE_CLIGEN_CLIGEN_H
+/* Define to 1 if you have the header file. */
+#undef HAVE_CURL_H
+
/* Define to 1 if you have the `getpeereid' function. */
#undef HAVE_GETPEEREID
diff --git a/lib/clixon/clixon_data.h b/lib/clixon/clixon_data.h
index 376d8d0b..d0ae7dcb 100644
--- a/lib/clixon/clixon_data.h
+++ b/lib/clixon/clixon_data.h
@@ -66,6 +66,7 @@ int clicon_data_get(clicon_handle h, const char *name, char **val);
int clicon_data_set(clicon_handle h, const char *name, char *val);
int clicon_data_del(clicon_handle h, const char *name);
+/* Get generic clixon data on the form = where is void* */
int clicon_ptr_get(clicon_handle h, const char *name, void **ptr);
int clicon_ptr_set(clicon_handle h, const char *name, void *ptr);
int clicon_ptr_del(clicon_handle h, const char *name);
diff --git a/lib/clixon/clixon_datastore.h b/lib/clixon/clixon_datastore.h
index 680dfc12..535e2a5f 100644
--- a/lib/clixon/clixon_datastore.h
+++ b/lib/clixon/clixon_datastore.h
@@ -52,8 +52,8 @@ int xmldb_disconnect(clicon_handle h);
/* in clixon_datastore_read.[ch] */
int xmldb_get(clicon_handle h, const char *db, cvec *nsc, char *xpath, cxobj **xtop);
int xmldb_get0(clicon_handle h, const char *db, yang_bind yb,
- cvec *nsc, const char *xpath,
- int copy, cxobj **xtop, modstate_diff_t *msd, cxobj **xerr);
+ cvec *nsc, const char *xpath,
+ int copy, cxobj **xtop, modstate_diff_t *msd, cxobj **xerr);
int xmldb_get0_clear(clicon_handle h, cxobj *x);
int xmldb_get0_free(clicon_handle h, cxobj **xp);
int xmldb_put(clicon_handle h, const char *db, enum operation_type op, cxobj *xt, char *username, cbuf *cbret); /* in clixon_datastore_write.[ch] */
@@ -76,5 +76,6 @@ int xmldb_modified_set(clicon_handle h, const char *db, int value);
int xmldb_empty_get(clicon_handle h, const char *db);
int xmldb_dump(clicon_handle h, FILE *f, cxobj *xt);
int xmldb_print(clicon_handle h, FILE *f);
+int xmldb_rename(clicon_handle h, const char *db, const char *newdb, const char *suffix);
#endif /* _CLIXON_DATASTORE_H */
diff --git a/lib/clixon/clixon_event.h b/lib/clixon/clixon_event.h
index fbd26345..27c8fd7f 100644
--- a/lib/clixon/clixon_event.h
+++ b/lib/clixon/clixon_event.h
@@ -60,7 +60,7 @@ int clixon_event_reg_fd(int fd, int (*fn)(int, void*), void *arg, char *str);
int clixon_event_unreg_fd(int s, int (*fn)(int, void*));
int clixon_event_reg_timeout(struct timeval t, int (*fn)(int, void*),
- void *arg, char *str);
+ void *arg, char *str);
int clixon_event_unreg_timeout(int (*fn)(int, void*), void *arg);
diff --git a/lib/clixon/clixon_file.h b/lib/clixon/clixon_file.h
index 008ab3f9..195522ac 100644
--- a/lib/clixon/clixon_file.h
+++ b/lib/clixon/clixon_file.h
@@ -41,7 +41,7 @@
int clicon_file_dirent(const char *dir, struct dirent **ent,
- const char *regexp, mode_t type);
+ const char *regexp, mode_t type);
int clicon_files_recursive(const char *dir, const char *regexp, cvec *cvv);
diff --git a/lib/clixon/clixon_hash.h b/lib/clixon/clixon_hash.h
index 0bf64827..c1a73d34 100644
--- a/lib/clixon/clixon_hash.h
+++ b/lib/clixon/clixon_hash.h
@@ -39,9 +39,9 @@
#define _CLIXON_HASH_H_
struct clicon_hash {
- qelem_t h_qelem;
+ qelem_t h_qelem;
char *h_key;
- size_t h_vlen;
+ size_t h_vlen;
void *h_val;
};
typedef struct clicon_hash *clicon_hash_t;
@@ -71,13 +71,13 @@ int clicon_hash_keys(clicon_hash_t *hash, char ***vector, size_t *nke
* printf ("%s = %s\n", k, (char *)clicon_hash_value(h, k, NULL));
* } hash_each_end();
*/
-#define clicon_hash_each(__hash__, __key__) \
-{ \
- int __i__; \
- size_t __n__; \
- char **__k__ = hash_keys((__hash__),&__n__); \
- if (__k__) { \
+#define clicon_hash_each(__hash__, __key__) \
+{ \
+ int __i__; \
+ size_t __n__; \
+ char **__k__ = hash_keys((__hash__),&__n__); \
+ if (__k__) { \
for(__i__ = 0; __i__ < __n__ && ((__key__) = __k__[__i__]); __i__++)
-#define clicon_hash_each_end(__hash__) if (__k__) free(__k__); } }
+#define clicon_hash_each_end(__hash__) if (__k__) free(__k__); } }
#endif /* _CLIXON_HASH_H_ */
diff --git a/lib/clixon/clixon_log.h b/lib/clixon/clixon_log.h
index a8494810..9b587b55 100644
--- a/lib/clixon/clixon_log.h
+++ b/lib/clixon/clixon_log.h
@@ -58,6 +58,7 @@ int clicon_log_file(char *filename);
int clicon_log_string_limit_set(size_t sz);
size_t clicon_log_string_limit_get(void);
int clicon_get_logflags(void);
+int clicon_log_str(int level, char *msg);
int clicon_log(int level, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
int clicon_debug(int dbglevel, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
int clicon_debug_init(int dbglevel, FILE *f);
diff --git a/lib/clixon/clixon_nacm.h b/lib/clixon/clixon_nacm.h
index 77526389..8e00d135 100644
--- a/lib/clixon/clixon_nacm.h
+++ b/lib/clixon/clixon_nacm.h
@@ -58,10 +58,10 @@ enum nacm_access{
*/
int nacm_rpc(char *rpc, char *module, char *username, cxobj *xnacm, cbuf *cbret);
int nacm_datanode_read(clicon_handle h, cxobj *xt, cxobj **xvec, size_t xlen, char *username,
- cxobj *nacm_xtree);
+ cxobj *nacm_xtree);
int nacm_datanode_write(clicon_handle h, cxobj *xr, cxobj *xt,
- enum nacm_access access,
- char *username, cxobj *xnacm, cbuf *cbret);
+ enum nacm_access access,
+ char *username, cxobj *xnacm, cbuf *cbret);
int nacm_access_pre(clicon_handle h, char *peername, char *username, cxobj **xnacmp);
int verify_nacm_user(clicon_handle h, enum nacm_credentials_t cred, char *peername, char *nacmname, cbuf *cbret);
diff --git a/lib/clixon/clixon_netconf_lib.h b/lib/clixon/clixon_netconf_lib.h
index 6b0b0935..0b1f571e 100644
--- a/lib/clixon/clixon_netconf_lib.h
+++ b/lib/clixon/clixon_netconf_lib.h
@@ -124,11 +124,11 @@ int netconf_in_use(cbuf *cb, char *type, char *message);
int netconf_invalid_value(cbuf *cb, char *type, char *message);
int netconf_invalid_value_xml(cxobj **xret, char *type, char *message);
int netconf_too_big(cbuf *cb, char *type, char *message);
-int netconf_missing_attribute(cbuf *cb, char *type, char *info, char *message);
+int netconf_missing_attribute(cbuf *cb, char *type, char *info, char *message);
int netconf_missing_attribute_xml(cxobj **xret, char *type, char *info, char *message);
int netconf_bad_attribute(cbuf *cb, char *type, char *info, char *message);
int netconf_bad_attribute_xml(cxobj **xret, char *type, char *info, char *message);
-int netconf_unknown_attribute(cbuf *cb, char *type, char *info, char *message);
+int netconf_unknown_attribute(cbuf *cb, char *type, char *info, char *message);
int netconf_missing_element(cbuf *cb, char *type, char *element, char *message);
int netconf_missing_element_xml(cxobj **xret, char *type, char *element, char *message);
int netconf_bad_element(cbuf *cb, char *type, char *info, char *element);
diff --git a/lib/clixon/clixon_path.h b/lib/clixon/clixon_path.h
index 3f1edfd0..7cffbb57 100644
--- a/lib/clixon/clixon_path.h
+++ b/lib/clixon/clixon_path.h
@@ -66,9 +66,9 @@ typedef struct {
char *cp_prefix; /* Prefix or module name, should be resolved + id to cp_yang */
char *cp_id; /* Identifier */
cvec *cp_cvk; /* Key values: list of (name:value) pairs alt (NULL:value)
- * Can also be single uint32, if so positional eg x/y[42]
- * This seems kludgy but follows RFC 7950 Sec 9.13
- */
+ * Can also be single uint32, if so positional eg x/y[42]
+ * This seems kludgy but follows RFC 7950 Sec 9.13
+ */
yang_stmt *cp_yang; /* Corresponding yang spec (after XML match - ie resolved) */
} clixon_path;
@@ -82,13 +82,13 @@ int api_path_fmt2api_path(const char *api_path_fmt, cvec *cvv, char **api_path,
int api_path_fmt2xpath(char *api_path_fmt, cvec *cvv, char **xpath);
int api_path2xpath(char *api_path, yang_stmt *yspec, char **xpath, cvec **nsc, cxobj **xerr);
int api_path2xml(char *api_path, yang_stmt *yspec, cxobj *xtop,
- yang_class nodeclass, int strict,
- cxobj **xpathp, yang_stmt **ypathp, cxobj **xerr);
+ yang_class nodeclass, int strict,
+ cxobj **xpathp, yang_stmt **ypathp, cxobj **xerr);
int xml2api_path_1(cxobj *x, cbuf *cb);
int clixon_xml_find_api_path(cxobj *xt, yang_stmt *yt, cxobj ***xvec, int *xlen, const char *format,
- ...) __attribute__ ((format (printf, 5, 6)));;
+ ...) __attribute__ ((format (printf, 5, 6)));;
int clixon_xml_find_instance_id(cxobj *xt, yang_stmt *yt, cxobj ***xvec, int *xlen, const char *format,
- ...) __attribute__ ((format (printf, 5, 6)));;
+ ...) __attribute__ ((format (printf, 5, 6)));;
int clixon_instance_id_bind(yang_stmt *yt, cvec *nsctx, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
int clixon_instance_id_parse(yang_stmt *yt, clixon_path **cplistp, cxobj **xerr, const char *format, ...) __attribute__ ((format (printf, 4, 5)));
diff --git a/lib/clixon/clixon_plugin.h b/lib/clixon/clixon_plugin.h
index 43b84345..7037fc34 100644
--- a/lib/clixon/clixon_plugin.h
+++ b/lib/clixon/clixon_plugin.h
@@ -98,11 +98,11 @@ typedef int (*clicon_upgrade_cb)(
*/
enum clixon_auth_type {
CLIXON_AUTH_NONE = 0, /* Message is authenticated automatically to
- anonymous user, maye be changed by ca-auth callback
- FEATURE clixon-restconf:allow-auth-none must be enabled */
+ anonymous user, maye be changed by ca-auth callback
+ FEATURE clixon-restconf:allow-auth-none must be enabled */
CLIXON_AUTH_CLIENT_CERTIFICATE, /* TLS Client certification authentication */
CLIXON_AUTH_USER, /* User-defined authentication according to ca-auth callback.
- Such as "password" authentication */
+ Such as "password" authentication */
};
typedef enum clixon_auth_type clixon_auth_type_t;
@@ -130,7 +130,7 @@ typedef int (plgdaemon_t)(clicon_handle); /* Plugin pre/post daemon
/* Called just before plugin unloaded.
* @param[in] h Clixon handle
*/
-typedef int (plgexit_t)(clicon_handle); /* Plugin exit */
+typedef int (plgexit_t)(clicon_handle); /* Plugin exit */
/* For yang extension handling.
* Called at parsing of yang module containing a statement of an extension.
@@ -293,36 +293,36 @@ struct clixon_plugin_api{
char ca_name[MAXPATHLEN]; /* Name of plugin (given by plugin) */
plginit2_t *ca_init; /* Clixon plugin Init (implicit) */
plgstart_t *ca_start; /* Plugin start */
- plgexit_t *ca_exit; /* Plugin exit */
+ plgexit_t *ca_exit; /* Plugin exit */
plgextension_t *ca_extension; /* Yang extension handler */
union {
- struct { /* cli-specific */
- cli_prompthook_t *ci_prompt; /* Prompt hook */
- cligen_susp_cb_t *ci_suspend; /* Ctrl-Z hook, see cligen getline */
- cligen_interrupt_cb_t *ci_interrupt; /* Ctrl-C, see cligen getline */
- } cau_cli;
- struct { /* restconf-specific */
- plgauth_t *cr_auth; /* Auth credentials */
- } cau_restconf;
- struct { /* netconf-specific */
- } cau_netconf;
- struct { /* backend-specific */
+ struct { /* cli-specific */
+ cli_prompthook_t *ci_prompt; /* Prompt hook */
+ cligen_susp_cb_t *ci_suspend; /* Ctrl-Z hook, see cligen getline */
+ cligen_interrupt_cb_t *ci_interrupt; /* Ctrl-C, see cligen getline */
+ } cau_cli;
+ struct { /* restconf-specific */
+ plgauth_t *cr_auth; /* Auth credentials */
+ } cau_restconf;
+ struct { /* netconf-specific */
+ } cau_netconf;
+ struct { /* backend-specific */
plgdaemon_t *cb_pre_daemon; /* Plugin just before daemonization (only daemon) */
plgdaemon_t *cb_daemon; /* Plugin daemonized (always called) */
- plgreset_t *cb_reset; /* Reset system status */
+ plgreset_t *cb_reset; /* Reset system status */
- plgstatedata_t *cb_statedata; /* Provide state data XML from plugin */
- plglockdb_t *cb_lockdb; /* Database lock changed state */
- trans_cb_t *cb_trans_begin; /* Transaction start */
- trans_cb_t *cb_trans_validate; /* Transaction validation */
- trans_cb_t *cb_trans_complete; /* Transaction validation complete */
- trans_cb_t *cb_trans_commit; /* Transaction commit */
- trans_cb_t *cb_trans_commit_done; /* Transaction when commit done */
- trans_cb_t *cb_trans_revert; /* Transaction revert */
- trans_cb_t *cb_trans_end; /* Transaction completed */
- trans_cb_t *cb_trans_abort; /* Transaction aborted */
- datastore_upgrade_t *cb_datastore_upgrade; /* General-purpose datastore upgrade */
- } cau_backend;
+ plgstatedata_t *cb_statedata; /* Provide state data XML from plugin */
+ plglockdb_t *cb_lockdb; /* Database lock changed state */
+ trans_cb_t *cb_trans_begin; /* Transaction start */
+ trans_cb_t *cb_trans_validate; /* Transaction validation */
+ trans_cb_t *cb_trans_complete; /* Transaction validation complete */
+ trans_cb_t *cb_trans_commit; /* Transaction commit */
+ trans_cb_t *cb_trans_commit_done; /* Transaction when commit done */
+ trans_cb_t *cb_trans_revert; /* Transaction revert */
+ trans_cb_t *cb_trans_end; /* Transaction completed */
+ trans_cb_t *cb_trans_abort; /* Transaction aborted */
+ datastore_upgrade_t *cb_datastore_upgrade; /* General-purpose datastore upgrade */
+ } cau_backend;
} u;
};
/* Access fields */
@@ -373,11 +373,11 @@ typedef struct plugin_context plugin_context_t;
* When namespace and name match, the callback is made
*/
typedef struct {
- qelem_t rc_qelem; /* List header */
+ qelem_t rc_qelem; /* List header */
clicon_rpc_cb rc_callback; /* RPC Callback */
- void *rc_arg; /* Application specific argument to cb */
+ void *rc_arg; /* Application specific argument to cb */
char *rc_namespace;/* Namespace to combine with name tag */
- char *rc_name; /* Xml/json tag/name */
+ char *rc_name; /* Xml/json tag/name */
} rpc_callback_t;
/*
diff --git a/lib/clixon/clixon_proto.h b/lib/clixon/clixon_proto.h
index b56b879b..3304d345 100644
--- a/lib/clixon/clixon_proto.h
+++ b/lib/clixon/clixon_proto.h
@@ -71,13 +71,13 @@ int clicon_connect_unix(clicon_handle h, char *sockpath);
int clicon_rpc_connect_unix(clicon_handle h,
- char *sockpath,
- int *sock0);
+ char *sockpath,
+ int *sock0);
int clicon_rpc_connect_inet(clicon_handle h,
- char *dst,
- uint16_t port,
- int *sock0);
+ char *dst,
+ uint16_t port,
+ int *sock0);
int clicon_rpc(int sock, struct clicon_msg *msg, char **xret, int *eof);
diff --git a/lib/clixon/clixon_proto_client.h b/lib/clixon/clixon_proto_client.h
index 76ff0fb9..d2fd7f93 100644
--- a/lib/clixon/clixon_proto_client.h
+++ b/lib/clixon/clixon_proto_client.h
@@ -49,21 +49,21 @@ int clicon_rpc_netconf(clicon_handle h, char *xmlst, cxobj **xret, int *sp);
int clicon_rpc_netconf_xml(clicon_handle h, cxobj *xml, cxobj **xret, int *sp);
int clicon_rpc_get_config(clicon_handle h, char *username, char *db, char *xpath, cvec *nsc, char *defaults, cxobj **xret);
int clicon_rpc_edit_config(clicon_handle h, char *db, enum operation_type op,
- char *xml);
+ char *xml);
int clicon_rpc_copy_config(clicon_handle h, char *db1, char *db2);
int clicon_rpc_delete_config(clicon_handle h, char *db);
int clicon_rpc_lock(clicon_handle h, char *db);
int clicon_rpc_unlock(clicon_handle h, char *db);
int clicon_rpc_get(clicon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, char *defaults, cxobj **xret);
int clicon_rpc_get_pageable_list(clicon_handle h, char *datastore, char *xpath,
- cvec *nsc, netconf_content content, int32_t depth, char *defaults,
- uint32_t offset, uint32_t limit,
- char *direction, char *sort, char *where,
- cxobj **xt);
+ cvec *nsc, netconf_content content, int32_t depth, char *defaults,
+ uint32_t offset, uint32_t limit,
+ char *direction, char *sort, char *where,
+ cxobj **xt);
int clicon_rpc_close_session(clicon_handle h);
int clicon_rpc_kill_session(clicon_handle h, uint32_t session_id);
int clicon_rpc_validate(clicon_handle h, char *db);
-int clicon_rpc_commit(clicon_handle h);
+int clicon_rpc_commit(clicon_handle h, int confirmed, int cancel, uint32_t timeout, char *persist, char *persist_id);
int clicon_rpc_discard_changes(clicon_handle h);
int clicon_rpc_create_subscription(clicon_handle h, char *stream, char *filter, int *s);
int clicon_rpc_debug(clicon_handle h, int level);
diff --git a/lib/clixon/clixon_queue.h b/lib/clixon/clixon_queue.h
index 6ddb4375..3927333a 100644
--- a/lib/clixon/clixon_queue.h
+++ b/lib/clixon/clixon_queue.h
@@ -50,8 +50,8 @@
* @endcode
*/
typedef struct _qelem_t {
- struct _qelem_t *q_next;
- struct _qelem_t *q_prev;
+ struct _qelem_t *q_next;
+ struct _qelem_t *q_prev;
} qelem_t;
/*! Append element 'elem' to queue.
@@ -64,17 +64,17 @@ typedef struct _qelem_t {
* @endcode
*/
#define ADDQ(elem, pred) { \
- register qelem_t *Xe = (qelem_t *) (elem); \
- register qelem_t *Xp = (qelem_t *) (pred); \
- if (pred) { \
- Xe->q_next = Xp; \
- Xe->q_prev = Xp->q_prev; \
- Xp->q_prev->q_next = Xe; \
- Xp->q_prev = Xe; \
- } else { \
- Xe->q_next = Xe->q_prev = Xe; \
- pred = elem; \
- } \
+ register qelem_t *Xe = (qelem_t *) (elem); \
+ register qelem_t *Xp = (qelem_t *) (pred); \
+ if (pred) { \
+ Xe->q_next = Xp; \
+ Xe->q_prev = Xp->q_prev; \
+ Xp->q_prev->q_next = Xe; \
+ Xp->q_prev = Xe; \
+ } else { \
+ Xe->q_next = Xe->q_prev = Xe; \
+ pred = elem; \
+ } \
}
/*! Insert element 'elem' in queue after 'pred'
@@ -87,17 +87,17 @@ typedef struct _qelem_t {
* @endcode
*/
#define INSQ(elem, pred) { \
- register qelem_t *Xe = (qelem_t *) (elem); \
- register qelem_t *Xp = (qelem_t *) (pred); \
- if (pred) { \
- Xe->q_next = Xp; \
- Xe->q_prev = Xp->q_prev; \
- Xp->q_prev->q_next = Xe; \
- Xp->q_prev = Xe; \
- } else { \
- Xe->q_next = Xe->q_prev = Xe; \
- } \
- pred = elem; \
+ register qelem_t *Xe = (qelem_t *) (elem); \
+ register qelem_t *Xp = (qelem_t *) (pred); \
+ if (pred) { \
+ Xe->q_next = Xp; \
+ Xe->q_prev = Xp->q_prev; \
+ Xp->q_prev->q_next = Xe; \
+ Xp->q_prev = Xe; \
+ } else { \
+ Xe->q_next = Xe->q_prev = Xe; \
+ } \
+ pred = elem; \
}
/*! Remove element 'elem' from queue. 'head' is the pointer to the queue and
@@ -111,15 +111,15 @@ typedef struct _qelem_t {
* DELQ(el, list, struct a*);
* @endcode
*/
-#define DELQ(elem, head, type) { \
- register qelem_t *Xe = (qelem_t *) elem; \
- if (Xe->q_next == Xe) \
- head = NULL; \
- (Xe->q_prev->q_next = Xe->q_next)->q_prev = Xe->q_prev; \
- if (elem == head) \
- head = (type)Xe->q_next; \
- }
-
+#define DELQ(elem, head, type) { \
+ register qelem_t *Xe = (qelem_t *) elem; \
+ if (Xe->q_next == Xe) \
+ head = NULL; \
+ (Xe->q_prev->q_next = Xe->q_next)->q_prev = Xe->q_prev; \
+ if (elem == head) \
+ head = (type)Xe->q_next; \
+ }
+
/*! Get next entry in list
* @param[in] type Type of element
* @param[in] el Return next element after elem.
@@ -127,7 +127,7 @@ typedef struct _qelem_t {
* struct a *list; # existing element (or list)
* NEXTQ(struct a*, el);
*/
-#define NEXTQ(type, elem) ((type)((elem)?((qelem_t *)(elem))->q_next:NULL))
-#define PREVQ(type, elem) ((type)((elem)?((qelem_t *)(elem))->q_prev:NULL))
+#define NEXTQ(type, elem) ((type)((elem)?((qelem_t *)(elem))->q_next:NULL))
+#define PREVQ(type, elem) ((type)((elem)?((qelem_t *)(elem))->q_prev:NULL))
-#endif /* _CLIXON_QUEUE_H_ */
+#endif /* _CLIXON_QUEUE_H_ */
diff --git a/lib/clixon/clixon_stream.h b/lib/clixon/clixon_stream.h
index 2338793d..796664b6 100644
--- a/lib/clixon/clixon_stream.h
+++ b/lib/clixon/clixon_stream.h
@@ -68,7 +68,7 @@
* @param[in] arg Extra argument provided in stream_ss_add
* @see stream_ss_add
*/
-typedef int (*stream_fn_t)(clicon_handle h, int op, cxobj *event, void *arg);
+typedef int (*stream_fn_t)(clicon_handle h, int op, cxobj *event, void *arg);
struct stream_subscription{
qelem_t ss_q; /* queue header */
@@ -111,11 +111,11 @@ int stream_get_xml(clicon_handle h, int access, cbuf *cb);
int stream_timer_setup(int fd, void *arg);
/* Subscriptions */
struct stream_subscription *stream_ss_add(clicon_handle h, char *stream,
- char *xpath, struct timeval *start, struct timeval *stop,
- stream_fn_t fn, void *arg);
+ char *xpath, struct timeval *start, struct timeval *stop,
+ stream_fn_t fn, void *arg);
int stream_ss_rm(clicon_handle h, event_stream_t *es, struct stream_subscription *ss, int force);
struct stream_subscription *stream_ss_find(event_stream_t *es,
- stream_fn_t fn, void *arg);
+ stream_fn_t fn, void *arg);
int stream_ss_delete_all(clicon_handle h, stream_fn_t fn, void *arg);
int stream_ss_delete(clicon_handle h, char *name, stream_fn_t fn, void *arg);
diff --git a/lib/clixon/clixon_string.h b/lib/clixon/clixon_string.h
index 1a6242a9..c28ed8fe 100644
--- a/lib/clixon/clixon_string.h
+++ b/lib/clixon/clixon_string.h
@@ -79,7 +79,7 @@ static inline char * strdup4(char *str)
int len;
len = align4(strlen(str)+1);
if ((dup = (char*) malloc(len)) == NULL)
- return NULL;
+ return NULL;
memcpy(dup, str, strlen(str)+1);
return dup;
}
diff --git a/lib/clixon/clixon_xml.h b/lib/clixon/clixon_xml.h
index 1413fcea..78d90ca9 100644
--- a/lib/clixon/clixon_xml.h
+++ b/lib/clixon/clixon_xml.h
@@ -109,9 +109,9 @@ enum insert_type{ /* edit-config insert */
/* XML object types */
enum cxobj_type {CX_ERROR=-1,
- CX_ELMNT,
- CX_ATTR,
- CX_BODY};
+ CX_ELMNT,
+ CX_ATTR,
+ CX_BODY};
/* How to bind yang to XML top-level when parsing
* Assume an XML tree x with parent xp (or NULL) and a set of children c1,c2:
@@ -147,13 +147,13 @@ enum cxobj_type {CX_ERROR=-1,
enum yang_bind{
YB_NONE=0, /* Dont do Yang binding */
YB_MODULE, /* Search for matching yang binding among top-level symbols of Yang modules of direct
- * children
- * Ie, xml looks like: ... where "x" is a top-level symbol in a module
- */
+ * children
+ * Ie, xml looks like: ... where "x" is a top-level symbol in a module
+ */
YB_MODULE_NEXT, /* Search for matching yang binding among top-level symbols of Yang modules of
- * next-level children
- * Ie, xml looks like: ... where "x" is a top-level symbol in a module
- */
+ * next-level children
+ * Ie, xml looks like: ... where "x" is a top-level symbol in a module
+ */
YB_PARENT, /* Assume yang binding of existing parent and match its children by name */
YB_RPC, /* Assume top-level xml is an incoming netconf RPC message (or hello) */
@@ -178,7 +178,7 @@ typedef struct clixon_xml_vec clixon_xvec; /* struct defined in clicon_xml_vec.c
* xml_flag() flags:
*/
#define XML_FLAG_MARK 0x01 /* General-purpose eg expand and xpath_vec selection and
- * diffs between candidate and running */
+ * diffs between candidate and running */
#define XML_FLAG_TRANSIENT 0x02 /* Marker for dynamic algorithms, unmark asap */
#define XML_FLAG_ADD 0x04 /* Node is added (commits) or parent added rec*/
#define XML_FLAG_DEL 0x08 /* Node is deleted (commits) or parent deleted rec */
@@ -201,7 +201,7 @@ int xml_prefix_set(cxobj *xn, char *name);
char *nscache_get(cxobj *x, char *prefix);
int nscache_get_prefix(cxobj *x, char *ns, char **prefix);
cvec *nscache_get_all(cxobj *x);
-int nscache_set(cxobj *x, char *prefix, char *ns);
+int nscache_set(cxobj *x, char *prefix, char *ns);
int nscache_clear(cxobj *x);
int nscache_replace(cxobj *x, cvec *ns);
cxobj *xml_parent(cxobj *xn);
@@ -255,7 +255,7 @@ int xml_enumerate_get(cxobj *x);
char *xml_body(cxobj *xn);
cxobj *xml_body_get(cxobj *xn);
char *xml_find_type_value(cxobj *xn_parent, const char *prefix,
- const char *name, enum cxobj_type type);
+ const char *name, enum cxobj_type type);
cxobj *xml_find_type(cxobj *xn_parent, const char *prefix, const char *name, enum cxobj_type type);
char *xml_find_value(cxobj *xn_parent, const char *name);
char *xml_find_body(cxobj *xn, const char *name);
diff --git a/lib/clixon/clixon_xml_io.h b/lib/clixon/clixon_xml_io.h
index ce465895..1c2421db 100644
--- a/lib/clixon/clixon_xml_io.h
+++ b/lib/clixon/clixon_xml_io.h
@@ -51,7 +51,7 @@ int xmltree2cbuf(cbuf *cb, cxobj *x, int level);
int clixon_xml_parse_file(FILE *f, yang_bind yb, yang_stmt *yspec, cxobj **xt, cxobj **xerr);
int clixon_xml_parse_string(const char *str, yang_bind yb, yang_stmt *yspec, cxobj **xt, cxobj **xerr);
int clixon_xml_parse_va(yang_bind yb, yang_stmt *yspec, cxobj **xt, cxobj **xerr,
- const char *format, ...) __attribute__ ((format (printf, 5, 6)));
+ const char *format, ...) __attribute__ ((format (printf, 5, 6)));
int clixon_xml_attr_copy(cxobj *xin, cxobj *xout, char *name);
-#endif /* _CLIXON_XML_IO_H_ */
+#endif /* _CLIXON_XML_IO_H_ */
diff --git a/lib/clixon/clixon_xml_map.h b/lib/clixon/clixon_xml_map.h
index 400481bf..137b8cf7 100644
--- a/lib/clixon/clixon_xml_map.h
+++ b/lib/clixon/clixon_xml_map.h
@@ -53,10 +53,10 @@ int isxmlns(cxobj *x);
int xmlns_assign(cxobj *x);
int xml2cvec(cxobj *xt, yang_stmt *ys, cvec **cvv0);
int cvec2xml_1(cvec *cvv, char *toptag, cxobj *xp, cxobj **xt0);
-int xml_diff(yang_stmt *yspec, cxobj *x0, cxobj *x1,
- cxobj ***first, int *firstlen,
- cxobj ***second, int *secondlen,
- cxobj ***changed_x0, cxobj ***changed_x1, int *changedlen);
+int xml_diff(yang_stmt *yspec, cxobj *x0, cxobj *x1,
+ cxobj ***first, int *firstlen,
+ cxobj ***second, int *secondlen,
+ cxobj ***changed_x0, cxobj ***changed_x1, int *changedlen);
int xml_tree_prune_flagged_sub(cxobj *xt, int flag, int test, int *upmark);
int xml_tree_prune_flagged(cxobj *xt, int flag, int test);
int xml_tree_prune_flags(cxobj *xt, int flags, int mask);
@@ -75,6 +75,7 @@ int yang_enum2valstr(yang_stmt *ytype, char *enumstr, char **valstr);
int yang_enum_int_value(cxobj *node, int32_t *val);
int xml_copy_marked(cxobj *x0, cxobj *x1);
int yang_check_when_xpath(cxobj *xn, cxobj *xp, yang_stmt *yn, int *hit, int *nrp, char **xpathp);
+int yang_xml_mandatory(cxobj *xt, yang_stmt *ys);
int xml_rpc_isaction(cxobj *xn);
int xml_find_action(cxobj *xn, int top, cxobj **xap);
int purge_tagged_nodes(cxobj *xn, char *ns, char *name, char *value, int keepnode);
diff --git a/lib/clixon/clixon_xml_nsctx.h b/lib/clixon/clixon_xml_nsctx.h
index 60d9920e..81da6176 100644
--- a/lib/clixon/clixon_xml_nsctx.h
+++ b/lib/clixon/clixon_xml_nsctx.h
@@ -54,7 +54,7 @@ int xml_nsctx_namespace_netconf_default(clicon_handle h);
cvec *xml_nsctx_init(char *prefix, char *ns);
int xml_nsctx_free(cvec *nsc);
char *xml_nsctx_get(cvec *nsc, char *prefix);
-int xml_nsctx_get_prefix(cvec *cvv, char *ns, char **prefix);
+int xml_nsctx_get_prefix(cvec *cvv, char *ns, char **prefix);
int xml_nsctx_add(cvec *nsc, char *prefix, char *ns);
int xml_nsctx_node(cxobj *x, cvec **ncp);
int xml_nsctx_yang(yang_stmt *yn, cvec **ncp);
diff --git a/lib/clixon/clixon_xml_sort.h b/lib/clixon/clixon_xml_sort.h
index f2ea6b4c..fe8ae4f7 100644
--- a/lib/clixon/clixon_xml_sort.h
+++ b/lib/clixon/clixon_xml_sort.h
@@ -48,11 +48,11 @@ int xml_insert(cxobj *xp, cxobj *xc, enum insert_type ins, char *key_val, cvec *
int xml_sort_verify(cxobj *x, void *arg);
#ifdef XML_EXPLICIT_INDEX
int xml_search_indexvar_binary_pos(cxobj *xp, char *indexvar, clixon_xvec *xvec,
- int low, int upper, int max, int *eq);
+ int low, int upper, int max, int *eq);
#endif
int match_base_child(cxobj *x0, cxobj *x1c, yang_stmt *yc, cxobj **x0cp);
int clixon_xml_find_index(cxobj *xp, yang_stmt *yp, char *ns, char *name,
- cvec *cvk, clixon_xvec *xvec);
+ cvec *cvk, clixon_xvec *xvec);
int clixon_xml_find_pos(cxobj *xp, yang_stmt *yc, uint32_t pos, clixon_xvec *xvec);
#endif /* _CLIXON_XML_SORT_H */
diff --git a/lib/clixon/clixon_xpath.h b/lib/clixon/clixon_xpath.h
index 01e4a68d..59eb98be 100644
--- a/lib/clixon/clixon_xpath.h
+++ b/lib/clixon/clixon_xpath.h
@@ -137,7 +137,7 @@ int xpath_vec_ctx(cxobj *xcur, cvec *nsc, const char *xpath, int localonly, xp
int xpath_vec_bool(cxobj *xcur, cvec *nsc, const char *xpformat, ...) __attribute__ ((format (printf, 3, 4)));
int xpath_vec_flag(cxobj *xcur, cvec *nsc, const char *xpformat, uint16_t flags,
- cxobj ***vec, int *veclen, ...) __attribute__ ((format (printf, 3, 7)));
+ cxobj ***vec, int *veclen, ...) __attribute__ ((format (printf, 3, 7)));
/* Functions with explicit namespace context (nsc) set. If you do not need
* explicit namespace contexts (most do not) consider using the API functions
diff --git a/lib/clixon/clixon_yang.h b/lib/clixon/clixon_yang.h
index ce72361f..428180af 100644
--- a/lib/clixon/clixon_yang.h
+++ b/lib/clixon/clixon_yang.h
@@ -46,7 +46,7 @@
* An application can use any flags above that
* @see cv_flag
*/
-#define V_UNSET 0x10 /* Used by XML code to denote a value is not default */
+#define V_UNSET 0x10 /* Used by XML code to denote a value is not default */
/*
* Yang flags used in
@@ -54,12 +54,12 @@
#define YANG_FLAG_MARK 0x01 /* (Dynamic) marker for dynamic algorithms, eg expand and DAG */
#define YANG_FLAG_TMP 0x02 /* (Dynamic) marker for dynamic algorithms, eg DAG detection */
#define YANG_FLAG_NOKEY 0x04 /* Key not mandatory in this list, see eg yang-data extension in
- * RFC 8040 / ietf-restconf.yang
- * see restconf_main_extension_cb
- */
+ * RFC 8040 / ietf-restconf.yang
+ * see restconf_main_extension_cb
+ */
#ifdef XML_EXPLICIT_INDEX
#define YANG_FLAG_INDEX 0x08 /* This yang node under list is (extra) index. --> you can access
- * list elements using this index with binary search */
+ * list elements using this index with binary search */
#endif
#ifdef USE_CONFIG_FLAG_CACHE
#define YANG_FLAG_CONFIG_CACHE 0x10 /* Ancestor config cache is active */
@@ -67,9 +67,9 @@
#endif
#define YANG_FLAG_DISABLED 0x40 /* Disabled due to if-feature evaluate to false
- * Transformed to ANYDATA but some code may need to check
- * why it is an ANYDATA
- */
+ * Transformed to ANYDATA but some code may need to check
+ * why it is an ANYDATA
+ */
/*
* Types
@@ -272,7 +272,6 @@ int yang_apply(yang_stmt *yn, enum rfc_6020 key, yang_applyfn_t fn, int f
int yang_datanode(yang_stmt *ys);
int yang_abs_schema_nodeid(yang_stmt *ys, char *schema_nodeid, yang_stmt **yres);
int yang_desc_schema_nodeid(yang_stmt *yn, char *schema_nodeid, yang_stmt **yres);
-int yang_mandatory(yang_stmt *ys);
int yang_config(yang_stmt *ys);
int yang_config_ancestor(yang_stmt *ys);
int yang_features(clicon_handle h, yang_stmt *yt);
@@ -280,9 +279,9 @@ cvec *yang_arg2cvec(yang_stmt *ys, char *delimi);
int yang_key_match(yang_stmt *yn, char *name, int *lastkey);
int yang_type_cache_regexp_set(yang_stmt *ytype, int rxmode, cvec *regexps);
int yang_type_cache_get(yang_stmt *ytype, yang_stmt **resolved, int *options,
- cvec **cvv, cvec *patterns, int *rxmode, cvec *regexps, uint8_t *fraction);
+ cvec **cvv, cvec *patterns, int *rxmode, cvec *regexps, uint8_t *fraction);
int yang_type_cache_set(yang_stmt *ys, yang_stmt *resolved, int options, cvec *cvv,
- cvec *patterns, uint8_t fraction);
+ cvec *patterns, uint8_t fraction);
yang_stmt *yang_anydata_add(yang_stmt *yp, char *name);
int yang_extension_value(yang_stmt *ys, char *name, char *ns, int *exist, char **value);
int yang_sort_subelements(yang_stmt *ys);
diff --git a/lib/clixon/clixon_yang_module.h b/lib/clixon/clixon_yang_module.h
index 95276fc6..3ea50f3a 100644
--- a/lib/clixon/clixon_yang_module.h
+++ b/lib/clixon/clixon_yang_module.h
@@ -68,7 +68,7 @@ int yang_modules_init(clicon_handle h);
char *yang_modules_revision(clicon_handle h);
int yang_modules_state_get(clicon_handle h, yang_stmt *yspec, char *xpath,
- cvec *nsc, int brief, cxobj **xret);
+ cvec *nsc, int brief, cxobj **xret);
int clixon_module_upgrade(clicon_handle h, cxobj *xt, modstate_diff_t *msd, cbuf *cb);
yang_stmt *yang_find_module_by_prefix(yang_stmt *ys, char *prefix);
yang_stmt *yang_find_module_by_prefix_yspec(yang_stmt *yspec, char *prefix);
diff --git a/lib/clixon/clixon_yang_parse_lib.h b/lib/clixon/clixon_yang_parse_lib.h
index a2cc6a4c..32dc2784 100644
--- a/lib/clixon/clixon_yang_parse_lib.h
+++ b/lib/clixon/clixon_yang_parse_lib.h
@@ -54,7 +54,7 @@
yang_stmt *yang_parse_file(FILE *fp, const char *name, yang_stmt *ysp);
yang_stmt *yang_parse_filename(const char *filename, yang_stmt *ysp);
int yang_spec_parse_module(clicon_handle h, const char *module,
- const char *revision, yang_stmt *yspec);
+ const char *revision, yang_stmt *yspec);
int yang_spec_parse_file(clicon_handle h, char *filename, yang_stmt *yspec);
int yang_spec_load_dir(clicon_handle h, char *dir, yang_stmt *yspec);
int ys_parse_date_arg(char *datearg, uint32_t *dateint);
diff --git a/lib/clixon/clixon_yang_type.h b/lib/clixon/clixon_yang_type.h
index fb2be9f1..f017e5a1 100644
--- a/lib/clixon/clixon_yang_type.h
+++ b/lib/clixon/clixon_yang_type.h
@@ -63,14 +63,14 @@ yang_stmt *yang_find_identity_nsc(yang_stmt *yspec, char *identity, cvec *nsc);
int ys_cv_validate(clicon_handle h, cg_var *cv, yang_stmt *ys, yang_stmt **ysub, char **reason);
int clicon_type2cv(char *type, char *rtype, yang_stmt *ys, enum cv_type *cvtype);
int yang_type_get(yang_stmt *ys, char **otype, yang_stmt **restype,
- int *options, cvec **cvv,
- cvec *patterns, cvec *regexps,
+ int *options, cvec **cvv,
+ cvec *patterns, cvec *regexps,
uint8_t *fraction_digits);
int yang_type_resolve(yang_stmt *yorig, yang_stmt *ys,
- yang_stmt *ytype,
- yang_stmt **restype, int *options,
- cvec **cvv, cvec *patterns, cvec *regexps,
- uint8_t *fraction);
+ yang_stmt *ytype,
+ yang_stmt **restype, int *options,
+ cvec **cvv, cvec *patterns, cvec *regexps,
+ uint8_t *fraction);
enum cv_type yang_type2cv(yang_stmt *ys);
diff --git a/lib/src/clixon_api_path_parse.h b/lib/src/clixon_api_path_parse.h
index c7f7d8a7..54b665fb 100644
--- a/lib/src/clixon_api_path_parse.h
+++ b/lib/src/clixon_api_path_parse.h
@@ -67,4 +67,4 @@ int clixon_api_path_parselex(void *);
int clixon_api_path_parseparse(void *);
void clixon_api_path_parseerror(void *, char*);
-#endif /* _CLIXON_API_PATH_PARSE_H_ */
+#endif /* _CLIXON_API_PATH_PARSE_H_ */
diff --git a/lib/src/clixon_api_path_parse.l b/lib/src/clixon_api_path_parse.l
index b3eebab5..de78e57b 100644
--- a/lib/src/clixon_api_path_parse.l
+++ b/lib/src/clixon_api_path_parse.l
@@ -112,12 +112,12 @@ identifier {namestart}{namechar}*
return IDENTIFIER; }
. { clixon_api_path_parseerror(_AY, "LEXICAL ERROR\n"); return -1; }
-\, { return COMMA; }
+\, { return COMMA; }
\/ { BEGIN(INIT); return SLASH; }
[^:/?#\[\]@,]+ { clixon_api_path_parselval.string = strdup(yytext);
return STRING;}
. { clixon_api_path_parseerror(_AY, "LEXICAL ERROR\n"); return -1; }
-
+
%%
/*! Initialize scanner.
diff --git a/lib/src/clixon_api_path_parse.y b/lib/src/clixon_api_path_parse.y
index 64df2a10..0855f913 100644
--- a/lib/src/clixon_api_path_parse.y
+++ b/lib/src/clixon_api_path_parse.y
@@ -120,13 +120,13 @@
void
clixon_api_path_parseerror(void *_ay,
- char *s)
+ char *s)
{
clicon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'",
- _AY->ay_name,
- _AY->ay_linenum ,
- s,
- clixon_api_path_parsetext);
+ _AY->ay_name,
+ _AY->ay_linenum ,
+ s,
+ clixon_api_path_parsetext);
return;
}
@@ -146,11 +146,11 @@ api_path_parse_exit(clixon_api_path_yacc *ay)
*/
static clixon_path *
path_append(clixon_path *list,
- clixon_path *new)
+ clixon_path *new)
{
clicon_debug(3, "%s()", __FUNCTION__);
if (new == NULL)
- return NULL;
+ return NULL;
ADDQ(new, list);
return list;
}
@@ -159,34 +159,34 @@ path_append(clixon_path *list,
*/
static clixon_path *
path_add_keyvalue(clixon_path *cp,
- cvec *cvk)
+ cvec *cvk)
{
clicon_debug(3, "%s()", __FUNCTION__);
if (cp)
- cp->cp_cvk = cvk;
+ cp->cp_cvk = cvk;
return cp;
}
static clixon_path *
path_new(char *module_name,
- char *id)
+ char *id)
{
clixon_path *cp = NULL;
clicon_debug(3, "%s(%s,%s)", __FUNCTION__, module_name, id);
if ((cp = malloc(sizeof(*cp))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(cp, 0, sizeof(*cp));
if (module_name)
- if ((cp->cp_prefix = strdup(module_name)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
+ if ((cp->cp_prefix = strdup(module_name)) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
if ((cp->cp_id = strdup(id)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
return cp;
done:
@@ -201,20 +201,20 @@ path_new(char *module_name,
*/
static cvec *
keyval_add(cvec *cvv,
- cg_var *cv)
+ cg_var *cv)
{
clicon_debug(3, "%s()", __FUNCTION__);
if (cv == NULL)
- goto done;
+ goto done;
if (cvv == NULL &&
- (cvv = cvec_new(0)) == NULL) {
- clicon_err(OE_UNIX, errno, "cvec_new");
- goto done;
+ (cvv = cvec_new(0)) == NULL) {
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ goto done;
}
if (cvec_append_var(cvv, cv) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_append_var");
- cvv = NULL;
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_append_var");
+ cvv = NULL;
+ goto done;
}
cv_free(cv);
done:
@@ -231,18 +231,18 @@ keyval_set(char *name,
clicon_debug(3, "%s(%s=%s)", __FUNCTION__, name?name:"NULL", val);
if ((cv = cv_new(CGV_STRING)) == NULL){
- clicon_err(OE_UNIX, errno, "cv_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cv_new");
+ goto done;
}
if (name && cv_name_set(cv, name) == NULL){
- clicon_err(OE_UNIX, errno, "cv_string_set");
- cv = NULL;
- goto done;
+ clicon_err(OE_UNIX, errno, "cv_string_set");
+ cv = NULL;
+ goto done;
}
if (cv_string_set(cv, val) == NULL){
- clicon_err(OE_UNIX, errno, "cv_string_set");
- cv = NULL;
- goto done;
+ clicon_err(OE_UNIX, errno, "cv_string_set");
+ cv = NULL;
+ goto done;
}
done:
return cv;
diff --git a/lib/src/clixon_client.c b/lib/src/clixon_client.c
index a5588a85..e66848eb 100644
--- a/lib/src/clixon_client.c
+++ b/lib/src/clixon_client.c
@@ -117,13 +117,13 @@ clixon_client_init(const char *config_file)
clicon_debug(1, "%s", __FUNCTION__);
/* Initiate CLICON handle. CLIgen is also initialized */
if ((h = clicon_handle_init()) == NULL)
- return NULL;
+ return NULL;
/* Set clixon config file - reuse the one in the main installation */
clicon_option_str_set(h, "CLICON_CONFIGFILE",
- config_file?(char*)config_file:CLIXON_DEFAULT_CONFIG);
+ config_file?(char*)config_file:CLIXON_DEFAULT_CONFIG);
/* Find, read and parse configfile */
if (clicon_options_main(h) < 0)
- return NULL;
+ return NULL;
return h;
}
@@ -148,8 +148,8 @@ clixon_client_terminate(clicon_handle h)
*/
static int
clixon_client_lock(int sock,
- const int lock,
- const char *db)
+ const int lock,
+ const char *db)
{
int retval = -1;
cxobj *xret = NULL;
@@ -160,45 +160,45 @@ clixon_client_lock(int sock,
clicon_debug(1, "%s", __FUNCTION__);
if (db == NULL){
- clicon_err(OE_XML, EINVAL, "Expected db");
- goto done;
+ clicon_err(OE_XML, EINVAL, "Expected db");
+ goto done;
}
if ((msg = cbuf_new()) == NULL){
- clicon_err(OE_PLUGIN, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_PLUGIN, errno, "cbuf_new");
+ goto done;
}
if ((msgret = cbuf_new()) == NULL){
- clicon_err(OE_PLUGIN, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_PLUGIN, errno, "cbuf_new");
+ goto done;
}
cprintf(msg, ""
- "<%slock><%s/> %slock> ",
- NETCONF_BASE_NAMESPACE,
- NETCONF_MESSAGE_ID_ATTR,
- lock?"":"un", db, lock?"":"un");
+ "<%slock><%s/> %slock>",
+ NETCONF_BASE_NAMESPACE,
+ NETCONF_MESSAGE_ID_ATTR,
+ lock?"":"un", db, lock?"":"un");
if (clicon_rpc1(sock, msg, msgret, &eof) < 0)
- goto done;
+ goto done;
if (eof){
- close(sock);
- clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
- goto done;
+ close(sock);
+ clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
+ goto done;
}
if (clixon_xml_parse_string(cbuf_get(msgret), YB_NONE, NULL, &xret, NULL) < 0)
- goto done;
+ goto done;
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL){
- xd = xml_parent(xd); /* point to rpc-reply */
- clixon_netconf_error(xd, "Get config", NULL);
- goto done; /* Not fatal */
+ xd = xml_parent(xd); /* point to rpc-reply */
+ clixon_netconf_error(xd, "Get config", NULL);
+ goto done; /* Not fatal */
}
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- cbuf_free(msg);
+ cbuf_free(msg);
if (msgret)
- cbuf_free(msgret);
+ cbuf_free(msgret);
return retval;
}
@@ -219,8 +219,8 @@ clixon_client_hello(int sock)
clicon_debug(1, "%s", __FUNCTION__);
if ((msg = cbuf_new()) == NULL){
- clicon_err(OE_PLUGIN, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_PLUGIN, errno, "cbuf_new");
+ goto done;
}
cprintf(msg, "");
cprintf(msg, "", NETCONF_BASE_NAMESPACE);
@@ -228,12 +228,12 @@ clixon_client_hello(int sock)
cprintf(msg, " ");
cprintf(msg, "]]>]]>");
if (clicon_msg_send1(sock, msg) < 0)
- goto done;
+ goto done;
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (msg)
- cbuf_free(msg);
+ cbuf_free(msg);
return retval;
}
@@ -246,7 +246,7 @@ clixon_client_hello(int sock)
*/
clixon_client_handle
clixon_client_connect(clicon_handle h,
- clixon_client_type socktype)
+ clixon_client_type socktype)
{
struct clixon_client_handle *cch = NULL;
char **argv = NULL;
@@ -259,66 +259,66 @@ clixon_client_connect(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if ((cch = malloc(sz)) == NULL){
- clicon_err(OE_NETCONF, errno, "malloc");
- goto done;
+ clicon_err(OE_NETCONF, errno, "malloc");
+ goto done;
}
memset(cch, 0, sz);
cch->cch_magic = CLIXON_CLIENT_MAGIC;
cch->cch_type = socktype;
switch (socktype){
case CLIXON_CLIENT_IPC:
- if (clicon_rpc_connect(h, &cch->cch_socket) < 0)
- goto err;
- break;
+ if (clicon_rpc_connect(h, &cch->cch_socket) < 0)
+ goto err;
+ break;
case CLIXON_CLIENT_NETCONF:
- nr = 7;
- if (clicon_debug_get() != 0)
- nr += 2;
- if ((argv = calloc(nr, sizeof(char *))) == NULL){
- clicon_err(OE_UNIX, errno, "calloc");
- goto err;
- }
- i = 0;
- if ((netconf_bin = getenv("CLIXON_NETCONF_BIN")) == NULL)
- netconf_bin = CLIXON_NETCONF_BIN;
- if (stat(netconf_bin, &st) < 0){
- clicon_err(OE_NETCONF, errno, "netconf binary %s. Set with CLIXON_NETCONF_BIN=",
- netconf_bin);
- goto err;
- }
- argv[i++] = netconf_bin;
- argv[i++] = "-q";
- argv[i++] = "-f";
- argv[i++] = clicon_option_str(h, "CLICON_CONFIGFILE");
- argv[i++] = "-l"; /* log to syslog */
- argv[i++] = "s";
- if (clicon_debug_get() != 0){
- argv[i++] = "-D";
- snprintf(dbgstr, sizeof(dbgstr)-1, "%d", clicon_debug_get());
- argv[i++] = dbgstr;
- }
- argv[i++] = NULL;
- assert(i==nr);
- if (clixon_proc_socket(argv, &cch->cch_pid, &cch->cch_socket) < 0){
- goto err;
- }
- /* Start with encoding and hello message */
- if (clixon_client_hello(cch->cch_socket) < 0)
- goto err;
- break;
+ nr = 7;
+ if (clicon_debug_get() != 0)
+ nr += 2;
+ if ((argv = calloc(nr, sizeof(char *))) == NULL){
+ clicon_err(OE_UNIX, errno, "calloc");
+ goto err;
+ }
+ i = 0;
+ if ((netconf_bin = getenv("CLIXON_NETCONF_BIN")) == NULL)
+ netconf_bin = CLIXON_NETCONF_BIN;
+ if (stat(netconf_bin, &st) < 0){
+ clicon_err(OE_NETCONF, errno, "netconf binary %s. Set with CLIXON_NETCONF_BIN=",
+ netconf_bin);
+ goto err;
+ }
+ argv[i++] = netconf_bin;
+ argv[i++] = "-q";
+ argv[i++] = "-f";
+ argv[i++] = clicon_option_str(h, "CLICON_CONFIGFILE");
+ argv[i++] = "-l"; /* log to syslog */
+ argv[i++] = "s";
+ if (clicon_debug_get() != 0){
+ argv[i++] = "-D";
+ snprintf(dbgstr, sizeof(dbgstr)-1, "%d", clicon_debug_get());
+ argv[i++] = dbgstr;
+ }
+ argv[i++] = NULL;
+ assert(i==nr);
+ if (clixon_proc_socket(argv, &cch->cch_pid, &cch->cch_socket) < 0){
+ goto err;
+ }
+ /* Start with encoding and hello message */
+ if (clixon_client_hello(cch->cch_socket) < 0)
+ goto err;
+ break;
case CLIXON_CLIENT_SSH:
- break;
+ break;
} /* switch */
/* lock */
if (clixon_client_lock(cch->cch_socket, 1, "running") < 0)
- goto err;
+ goto err;
cch->cch_locked = 1;
done:
clicon_debug(1, "%s retval:%p", __FUNCTION__, cch);
return cch;
err:
if (cch)
- clixon_client_disconnect(cch);
+ clixon_client_disconnect(cch);
cch = NULL;
goto done;
}
@@ -336,24 +336,24 @@ clixon_client_disconnect(clixon_client_handle ch)
clicon_debug(1, "%s", __FUNCTION__);
if (cch == NULL){
- clicon_err(OE_XML, EINVAL, "Expected cch handle");
- goto done;
+ clicon_err(OE_XML, EINVAL, "Expected cch handle");
+ goto done;
}
/* unlock (if locked) */
if (cch->cch_locked)
- ;// (void)clixon_client_lock(cch->cch_socket, 0, "running");
+ ;// (void)clixon_client_lock(cch->cch_socket, 0, "running");
switch(cch->cch_type){
case CLIXON_CLIENT_IPC:
- close(cch->cch_socket);
- break;
+ close(cch->cch_socket);
+ break;
case CLIXON_CLIENT_NETCONF:
- if (clixon_proc_socket_close(cch->cch_pid,
- cch->cch_socket) < 0)
- goto done;
- break;
+ if (clixon_proc_socket_close(cch->cch_pid,
+ cch->cch_socket) < 0)
+ goto done;
+ break;
case CLIXON_CLIENT_SSH:
- break;
+ break;
}
free(cch);
retval = 0;
@@ -368,7 +368,7 @@ clixon_client_disconnect(clixon_client_handle ch)
*/
static int
clixon_xml_bottom(cxobj *xtop,
- cxobj **xbotp)
+ cxobj **xbotp)
{
int retval = -1;
cxobj *x;
@@ -377,15 +377,15 @@ clixon_xml_bottom(cxobj *xtop,
xp = xtop;
while (xp != NULL){
- /* Find child, if many, one which is not a key, if any */
- xc = NULL;
- x = NULL;
- while ((x = xml_child_each(xp, x, CX_ELMNT)) != NULL)
- xc = x;
- /* xc is last XXX */
- if (xc == NULL)
- break;
- xp = xc;
+ /* Find child, if many, one which is not a key, if any */
+ xc = NULL;
+ x = NULL;
+ while ((x = xml_child_each(xp, x, CX_ELMNT)) != NULL)
+ xc = x;
+ /* xc is last XXX */
+ if (xc == NULL)
+ break;
+ xp = xc;
}
retval = 0;
*xbotp = xp;
@@ -406,9 +406,9 @@ clixon_xml_bottom(cxobj *xtop,
*/
static int
clixon_client_get_xdata(int sock,
- const char *namespace,
- const char *xpath,
- cxobj **xdata)
+ const char *namespace,
+ const char *xpath,
+ cxobj **xdata)
{
int retval = -1;
cxobj *xret = NULL;
@@ -421,64 +421,64 @@ clixon_client_get_xdata(int sock,
clicon_debug(1, "%s", __FUNCTION__);
if ((msg = cbuf_new()) == NULL){
- clicon_err(OE_PLUGIN, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_PLUGIN, errno, "cbuf_new");
+ goto done;
}
if ((msgret = cbuf_new()) == NULL){
- clicon_err(OE_PLUGIN, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_PLUGIN, errno, "cbuf_new");
+ goto done;
}
cprintf(msg, "<%s/> ", db);
if (xpath && strlen(xpath)){
- cprintf(msg, "<%s:filter %s:type=\"xpath\" xmlns=\"%s\" %s:select=\"%s\"",
- NETCONF_BASE_PREFIX,
- NETCONF_BASE_PREFIX,
- namespace,
- NETCONF_BASE_PREFIX,
- xpath);
- if (xml_nsctx_cbuf(msg, nsc) < 0)
- goto done;
- cprintf(msg, "/>");
+ cprintf(msg, "<%s:filter %s:type=\"xpath\" xmlns=\"%s\" %s:select=\"%s\"",
+ NETCONF_BASE_PREFIX,
+ NETCONF_BASE_PREFIX,
+ namespace,
+ NETCONF_BASE_PREFIX,
+ xpath);
+ if (xml_nsctx_cbuf(msg, nsc) < 0)
+ goto done;
+ cprintf(msg, "/>");
}
cprintf(msg, " ");
if (netconf_output_encap(NETCONF_SSH_CHUNKED, msg) < 0)
- goto done;
+ goto done;
if (clicon_rpc1(sock, msg, msgret, &eof) < 0)
- goto done;
+ goto done;
if (eof){
- close(sock);
- clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
- goto done;
+ close(sock);
+ clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
+ goto done;
}
if (clixon_xml_parse_string(cbuf_get(msgret), YB_NONE, NULL, &xret, NULL) < 0)
- goto done;
+ goto done;
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL){
- xd = xml_parent(xd); /* point to rpc-reply */
- clixon_netconf_error(xd, "Get config", NULL);
- goto done; /* Not fatal */
+ xd = xml_parent(xd); /* point to rpc-reply */
+ clixon_netconf_error(xd, "Get config", NULL);
+ goto done; /* Not fatal */
}
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL){
- if ((xd = xml_new(NETCONF_OUTPUT_DATA, NULL, CX_ELMNT)) == NULL)
- goto done;
+ if ((xd = xml_new(NETCONF_OUTPUT_DATA, NULL, CX_ELMNT)) == NULL)
+ goto done;
}
else{
- if (xml_rm(xd) < 0)
- goto done;
+ if (xml_rm(xd) < 0)
+ goto done;
}
*xdata = xd;
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- cbuf_free(msg);
+ cbuf_free(msg);
if (msgret)
- cbuf_free(msgret);
+ cbuf_free(msgret);
return retval;
}
@@ -492,9 +492,9 @@ clixon_client_get_xdata(int sock,
*/
static int
clixon_client_get_body_val(int sock,
- const char *namespace,
- const char *xpath,
- char **val)
+ const char *namespace,
+ const char *xpath,
+ char **val)
{
int retval = -1;
cxobj *xdata = NULL;
@@ -502,25 +502,25 @@ clixon_client_get_body_val(int sock,
clicon_debug(1, "%s", __FUNCTION__);
if (val == NULL){
- clicon_err(OE_XML, EINVAL, "Expected val");
- goto done;
+ clicon_err(OE_XML, EINVAL, "Expected val");
+ goto done;
}
if (clixon_client_get_xdata(sock, namespace, xpath, &xdata) < 0)
- goto done;
+ goto done;
if (xdata == NULL){
- clicon_err(OE_XML, EINVAL, "No xml obj found");
- goto done;
+ clicon_err(OE_XML, EINVAL, "No xml obj found");
+ goto done;
}
/* Is this an error, maybe an "unset" retval ? */
if (xml_child_nr_type(xdata, CX_ELMNT) == 0){
- clicon_err(OE_XML, EINVAL, "Value not found");
- goto done;
+ clicon_err(OE_XML, EINVAL, "Value not found");
+ goto done;
}
if (clixon_xml_bottom(xdata, &xobj) < 0)
- goto done;
+ goto done;
if (xobj == NULL){
- clicon_err(OE_XML, EINVAL, "No xml value found");
- goto done;
+ clicon_err(OE_XML, EINVAL, "No xml value found");
+ goto done;
}
*val = xml_body(xobj);
retval = 0;
@@ -539,9 +539,9 @@ clixon_client_get_body_val(int sock,
*/
int
clixon_client_get_bool(clixon_client_handle ch,
- int *rval,
- const char *namespace,
- const char *xpath)
+ int *rval,
+ const char *namespace,
+ const char *xpath)
{
int retval = -1;
struct clixon_client_handle *cch = chandle(ch);
@@ -552,21 +552,21 @@ clixon_client_get_bool(clixon_client_handle ch,
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket,
- namespace, xpath, &val) < 0)
- goto done;
+ namespace, xpath, &val) < 0)
+ goto done;
if ((ret = parse_bool(val, &val0, &reason)) < 0){
- clicon_err(OE_XML, errno, "parse_bool");
- goto done;
+ clicon_err(OE_XML, errno, "parse_bool");
+ goto done;
}
if (ret == 0){
- clicon_err(OE_XML, EINVAL, "%s", reason);
- goto done;
+ clicon_err(OE_XML, EINVAL, "%s", reason);
+ goto done;
}
*rval = (int)val0;
retval = 0;
done:
if (reason)
- free(reason);
+ free(reason);
return retval;
}
@@ -581,10 +581,10 @@ clixon_client_get_bool(clixon_client_handle ch,
*/
int
clixon_client_get_str(clixon_client_handle ch,
- char *rval,
- int n,
- const char *namespace,
- const char *xpath)
+ char *rval,
+ int n,
+ const char *namespace,
+ const char *xpath)
{
int retval = -1;
struct clixon_client_handle *cch = chandle(ch);
@@ -592,8 +592,8 @@ clixon_client_get_str(clixon_client_handle ch,
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket,
- namespace, xpath, &val) < 0)
- goto done;
+ namespace, xpath, &val) < 0)
+ goto done;
strncpy(rval, val, n-1);
rval[n-1]= '\0';
retval = 0;
@@ -611,9 +611,9 @@ clixon_client_get_str(clixon_client_handle ch,
*/
int
clixon_client_get_uint8(clixon_client_handle ch,
- uint8_t *rval,
- const char *namespace,
- const char *xpath)
+ uint8_t *rval,
+ const char *namespace,
+ const char *xpath)
{
int retval = -1;
struct clixon_client_handle *cch = chandle(ch);
@@ -623,20 +623,20 @@ clixon_client_get_uint8(clixon_client_handle ch,
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket,
- namespace, xpath, &val) < 0)
- goto done;
+ namespace, xpath, &val) < 0)
+ goto done;
if ((ret = parse_uint8(val, rval, &reason)) < 0){
- clicon_err(OE_XML, errno, "parse_bool");
- goto done;
+ clicon_err(OE_XML, errno, "parse_bool");
+ goto done;
}
if (ret == 0){
- clicon_err(OE_XML, EINVAL, "%s", reason);
- goto done;
+ clicon_err(OE_XML, EINVAL, "%s", reason);
+ goto done;
}
retval = 0;
done:
if (reason)
- free(reason);
+ free(reason);
return retval;
}
@@ -650,9 +650,9 @@ clixon_client_get_uint8(clixon_client_handle ch,
*/
int
clixon_client_get_uint16(clixon_client_handle ch,
- uint16_t *rval,
- const char *namespace,
- const char *xpath)
+ uint16_t *rval,
+ const char *namespace,
+ const char *xpath)
{
int retval = -1;
struct clixon_client_handle *cch = chandle(ch);
@@ -662,20 +662,20 @@ clixon_client_get_uint16(clixon_client_handle ch,
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket,
- namespace, xpath, &val) < 0)
- goto done;
+ namespace, xpath, &val) < 0)
+ goto done;
if ((ret = parse_uint16(val, rval, &reason)) < 0){
- clicon_err(OE_XML, errno, "parse_bool");
- goto done;
+ clicon_err(OE_XML, errno, "parse_bool");
+ goto done;
}
if (ret == 0){
- clicon_err(OE_XML, EINVAL, "%s", reason);
- goto done;
+ clicon_err(OE_XML, EINVAL, "%s", reason);
+ goto done;
}
retval = 0;
done:
if (reason)
- free(reason);
+ free(reason);
return retval;
}
@@ -689,9 +689,9 @@ clixon_client_get_uint16(clixon_client_handle ch,
*/
int
clixon_client_get_uint32(clixon_client_handle ch,
- uint32_t *rval,
- const char *namespace,
- const char *xpath)
+ uint32_t *rval,
+ const char *namespace,
+ const char *xpath)
{
int retval = -1;
struct clixon_client_handle *cch = chandle(ch);
@@ -701,25 +701,25 @@ clixon_client_get_uint32(clixon_client_handle ch,
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket,
- namespace, xpath, &val) < 0)
- goto done;
+ namespace, xpath, &val) < 0)
+ goto done;
if (val == NULL){
- clicon_err(OE_XML, EFAULT, "val is NULL");
- goto done;
+ clicon_err(OE_XML, EFAULT, "val is NULL");
+ goto done;
}
if ((ret = parse_uint32(val, rval, &reason)) < 0){
- clicon_err(OE_XML, errno, "parse_bool");
- goto done;
+ clicon_err(OE_XML, errno, "parse_bool");
+ goto done;
}
if (ret == 0){
- clicon_err(OE_XML, EINVAL, "%s", reason);
- goto done;
+ clicon_err(OE_XML, EINVAL, "%s", reason);
+ goto done;
}
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (reason)
- free(reason);
+ free(reason);
return retval;
}
@@ -733,9 +733,9 @@ clixon_client_get_uint32(clixon_client_handle ch,
*/
int
clixon_client_get_uint64(clixon_client_handle ch,
- uint64_t *rval,
- const char *namespace,
- const char *xpath)
+ uint64_t *rval,
+ const char *namespace,
+ const char *xpath)
{
int retval = -1;
struct clixon_client_handle *cch = chandle(ch);
@@ -745,20 +745,20 @@ clixon_client_get_uint64(clixon_client_handle ch,
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket,
- namespace, xpath, &val) < 0)
- goto done;
+ namespace, xpath, &val) < 0)
+ goto done;
if ((ret = parse_uint64(val, rval, &reason)) < 0){
- clicon_err(OE_XML, errno, "parse_bool");
- goto done;
+ clicon_err(OE_XML, errno, "parse_bool");
+ goto done;
}
if (ret == 0){
- clicon_err(OE_XML, EINVAL, "%s", reason);
- goto done;
+ clicon_err(OE_XML, EINVAL, "%s", reason);
+ goto done;
}
retval = 0;
done:
if (reason)
- free(reason);
+ free(reason);
return retval;
}
diff --git a/lib/src/clixon_data.c b/lib/src/clixon_data.c
index 2b530549..437507e7 100644
--- a/lib/src/clixon_data.c
+++ b/lib/src/clixon_data.c
@@ -87,15 +87,15 @@
*/
int
clicon_data_get(clicon_handle h,
- const char *name,
- char **val)
+ const char *name,
+ char **val)
{
clicon_hash_t *cdat = clicon_data(h);
if (clicon_hash_lookup(cdat, (char*)name) == NULL)
- return -1;
+ return -1;
if (val)
- *val = clicon_hash_value(cdat, (char*)name, NULL);
+ *val = clicon_hash_value(cdat, (char*)name, NULL);
return 0;
}
@@ -109,8 +109,8 @@ clicon_data_get(clicon_handle h,
*/
int
clicon_data_set(clicon_handle h,
- const char *name,
- char *val)
+ const char *name,
+ char *val)
{
clicon_hash_t *cdat = clicon_data(h);
@@ -126,7 +126,7 @@ clicon_data_set(clicon_handle h,
*/
int
clicon_data_del(clicon_handle h,
- const char *name)
+ const char *name)
{
clicon_hash_t *cdat = clicon_data(h);
@@ -143,18 +143,18 @@ clicon_data_del(clicon_handle h,
*/
int
clicon_ptr_get(clicon_handle h,
- const char *name,
- void **ptr)
+ const char *name,
+ void **ptr)
{
clicon_hash_t *cdat = clicon_data(h);
void *p;
size_t vlen;
if (clicon_hash_lookup(cdat, (char*)name) == NULL)
- return -1;
+ return -1;
if (ptr){
- p = clicon_hash_value(cdat, (char*)name, &vlen);
- memcpy(ptr, p, vlen);
+ p = clicon_hash_value(cdat, (char*)name, &vlen);
+ memcpy(ptr, p, vlen);
}
return 0;
}
@@ -169,8 +169,8 @@ clicon_ptr_get(clicon_handle h,
*/
int
clicon_ptr_set(clicon_handle h,
- const char *name,
- void *ptr)
+ const char *name,
+ void *ptr)
{
clicon_hash_t *cdat = clicon_data(h);
@@ -186,7 +186,7 @@ clicon_ptr_set(clicon_handle h,
*/
int
clicon_ptr_del(clicon_handle h,
- const char *name)
+ const char *name)
{
clicon_hash_t *cdat = clicon_data(h);
@@ -207,12 +207,12 @@ clicon_ptr_del(clicon_handle h,
*/
cvec *
clicon_data_cvec_get(clicon_handle h,
- const char *name)
+ const char *name)
{
cvec *cvv = NULL;
if (clicon_ptr_get(h, name, (void**)&cvv) < 0)
- return NULL;
+ return NULL;
return cvv;
}
@@ -223,14 +223,14 @@ clicon_data_cvec_get(clicon_handle h,
*/
int
clicon_data_cvec_set(clicon_handle h,
- const char *name,
- cvec *cvv)
+ const char *name,
+ cvec *cvv)
{
cvec *cvv0 = NULL;
clicon_ptr_get(h, name, (void**)&cvv0);
if (cvv0)
- cvec_free(cvv0);
+ cvec_free(cvv0);
return clicon_ptr_set(h, name, cvv);
}
@@ -240,13 +240,13 @@ clicon_data_cvec_set(clicon_handle h,
*/
int
clicon_data_cvec_del(clicon_handle h,
- const char *name)
+ const char *name)
{
cvec *cvv = NULL;
clicon_ptr_get(h, name, (void**)&cvv);
if (cvv)
- cvec_free(cvv);
+ cvec_free(cvv);
return clicon_ptr_del(h, name);
}
@@ -261,7 +261,7 @@ clicon_dbspec_yang(clicon_handle h)
yang_stmt *ys = NULL;
if (clicon_ptr_get(h, "dbspec_yang", (void**)&ys) < 0)
- return NULL;
+ return NULL;
return ys;
}
@@ -272,7 +272,7 @@ clicon_dbspec_yang(clicon_handle h)
*/
int
clicon_dbspec_yang_set(clicon_handle h,
- yang_stmt *ys)
+ yang_stmt *ys)
{
return clicon_ptr_set(h, "dbspec_yang", ys);
}
@@ -288,7 +288,7 @@ clicon_config_yang(clicon_handle h)
yang_stmt *ys = NULL;
if (clicon_ptr_get(h, "control_yang", (void**)&ys) < 0)
- return NULL;
+ return NULL;
return ys;
}
@@ -299,7 +299,7 @@ clicon_config_yang(clicon_handle h)
*/
int
clicon_config_yang_set(clicon_handle h,
- yang_stmt *ys)
+ yang_stmt *ys)
{
return clicon_ptr_set(h, "control_yang", ys);
}
@@ -315,7 +315,7 @@ clicon_nacm_ext_yang(clicon_handle h)
yang_stmt *ys = NULL;
if (clicon_ptr_get(h, "nacm_ext_yang", (void**)&ys) < 0)
- return NULL;
+ return NULL;
return ys;
}
@@ -326,7 +326,7 @@ clicon_nacm_ext_yang(clicon_handle h)
*/
int
clicon_nacm_ext_yang_set(clicon_handle h,
- yang_stmt *ys)
+ yang_stmt *ys)
{
return clicon_ptr_set(h, "nacm_ext_yang", ys);
}
@@ -346,7 +346,7 @@ clicon_nsctx_global_get(clicon_handle h)
cvec *cvv = NULL;
if (clicon_ptr_get(h, "nsctx_global", (void**)&cvv) < 0)
- return NULL;
+ return NULL;
return cvv;
}
@@ -357,7 +357,7 @@ clicon_nsctx_global_get(clicon_handle h)
*/
int
clicon_nsctx_global_set(clicon_handle h,
- cvec *nsctx)
+ cvec *nsctx)
{
return clicon_ptr_set(h, "nsctx_global", nsctx);
}
@@ -374,7 +374,7 @@ clicon_nacm_ext(clicon_handle h)
cxobj *x = NULL;
if (clicon_ptr_get(h, "nacm_xml", (void**)&x) < 0)
- return NULL;
+ return NULL;
return x;
}
@@ -386,12 +386,12 @@ clicon_nacm_ext(clicon_handle h)
*/
int
clicon_nacm_ext_set(clicon_handle h,
- cxobj *x)
+ cxobj *x)
{
cxobj *x0 = NULL;
if ((x0 = clicon_nacm_ext(h)) != NULL)
- xml_free(x0);
+ xml_free(x0);
return clicon_ptr_set(h, "nacm_xml", x);
}
@@ -407,7 +407,7 @@ clicon_nacm_cache(clicon_handle h)
cxobj *x = NULL;
if (clicon_ptr_get(h, "nacm_cache", (void**)&x) < 0)
- return NULL;
+ return NULL;
return x;
}
@@ -419,7 +419,7 @@ clicon_nacm_cache(clicon_handle h)
*/
int
clicon_nacm_cache_set(clicon_handle h,
- cxobj *xn)
+ cxobj *xn)
{
return clicon_ptr_set(h, "nacm_cache", xn);
}
@@ -441,7 +441,7 @@ clicon_conf_xml(clicon_handle h)
cxobj *x = NULL;
if (clicon_ptr_get(h, "clixon_conf", (void**)&x) < 0)
- return NULL;
+ return NULL;
return x;
}
@@ -450,7 +450,7 @@ clicon_conf_xml(clicon_handle h)
*/
int
clicon_conf_xml_set(clicon_handle h,
- cxobj *x)
+ cxobj *x)
{
return clicon_ptr_set(h, "clixon_conf", x);
}
@@ -471,8 +471,8 @@ clicon_conf_restconf(clicon_handle h)
{
cxobj *xconfig = NULL;
- if ((xconfig = clicon_conf_xml(h)) != NULL) /* Get local config */
- return xpath_first(xconfig, NULL, "restconf");
+ if ((xconfig = clicon_conf_xml(h)) != NULL) /* Get local config */
+ return xpath_first(xconfig, NULL, "restconf");
return NULL;
}
@@ -490,8 +490,8 @@ clicon_conf_autocli(clicon_handle h)
{
cxobj *xconfig = NULL;
- if ((xconfig = clicon_conf_xml(h)) != NULL) /* Get local config */
- return xpath_first(xconfig, NULL, "autocli");
+ if ((xconfig = clicon_conf_xml(h)) != NULL) /* Get local config */
+ return xpath_first(xconfig, NULL, "autocli");
return NULL;
}
@@ -514,12 +514,12 @@ clicon_username_get(clicon_handle h)
*/
int
clicon_username_set(clicon_handle h,
- void *username)
+ void *username)
{
clicon_hash_t *cdat = clicon_data(h);
if (username == NULL)
- return clicon_hash_del(cdat, "username");
+ return clicon_hash_del(cdat, "username");
return clicon_hash_add(cdat, "username", username, strlen(username)+1)==NULL?-1:0;
}
@@ -546,7 +546,7 @@ clicon_startup_status_get(clicon_handle h)
*/
int
clicon_startup_status_set(clicon_handle h,
- enum startup_status status)
+ enum startup_status status)
{
clicon_hash_t *cdat = clicon_data(h);
if (clicon_hash_add(cdat, "startup_status", &status, sizeof(status))==NULL)
@@ -566,7 +566,7 @@ clicon_socket_get(clicon_handle h)
void *p;
if ((p = clicon_hash_value(cdat, "socket", NULL)) == NULL)
- return -1;
+ return -1;
return *(int*)p;
}
@@ -578,12 +578,12 @@ clicon_socket_get(clicon_handle h)
*/
int
clicon_socket_set(clicon_handle h,
- int s)
+ int s)
{
clicon_hash_t *cdat = clicon_data(h);
if (s == -1)
- return clicon_hash_del(cdat, "socket");
+ return clicon_hash_del(cdat, "socket");
return clicon_hash_add(cdat, "socket", &s, sizeof(int))==NULL?-1:0;
}
@@ -599,7 +599,7 @@ clicon_client_socket_get(clicon_handle h)
void *p;
if ((p = clicon_hash_value(cdat, "client-socket", NULL)) == NULL)
- return -1;
+ return -1;
return *(int*)p;
}
@@ -611,12 +611,12 @@ clicon_client_socket_get(clicon_handle h)
*/
int
clicon_client_socket_set(clicon_handle h,
- int s)
+ int s)
{
clicon_hash_t *cdat = clicon_data(h);
if (s == -1)
- return clicon_hash_del(cdat, "client-socket");
+ return clicon_hash_del(cdat, "client-socket");
return clicon_hash_add(cdat, "client-socket", &s, sizeof(int))==NULL?-1:0;
}
@@ -628,13 +628,13 @@ clicon_client_socket_set(clicon_handle h,
*/
cxobj *
clicon_modst_cache_get(clicon_handle h,
- int brief)
+ int brief)
{
clicon_hash_t *cdat = clicon_data(h);
void *p;
if ((p = clicon_hash_value(cdat, brief?"modst_brief":"modst_full", NULL)) != NULL)
- return *(cxobj **)p;
+ return *(cxobj **)p;
return NULL;
}
@@ -647,20 +647,20 @@ clicon_modst_cache_get(clicon_handle h,
*/
int
clicon_modst_cache_set(clicon_handle h,
- int brief,
- cxobj *xms)
+ int brief,
+ cxobj *xms)
{
clicon_hash_t *cdat = clicon_data(h);
cxobj *x;
if ((x = clicon_modst_cache_get(h, brief)) != NULL)
- xml_free(x);
+ xml_free(x);
if (xms == NULL)
- goto ok;
+ goto ok;
if ((x = xml_dup(xms)) == NULL)
- return -1;
+ return -1;
if (clicon_hash_add(cdat, brief?"modst_brief":"modst_full", &x, sizeof(x))==NULL)
- return -1;
+ return -1;
ok:
return 0;
}
@@ -677,7 +677,7 @@ clicon_xml_changelog_get(clicon_handle h)
void *p;
if ((p = clicon_hash_value(cdat, "xml-changelog", NULL)) != NULL)
- return *(cxobj **)p;
+ return *(cxobj **)p;
return NULL;
}
@@ -690,12 +690,12 @@ clicon_xml_changelog_get(clicon_handle h)
*/
int
clicon_xml_changelog_set(clicon_handle h,
- cxobj *xchlog)
+ cxobj *xchlog)
{
clicon_hash_t *cdat = clicon_data(h);
if (clicon_hash_add(cdat, "xml-changelog", &xchlog, sizeof(xchlog))==NULL)
- return -1;
+ return -1;
return 0;
}
@@ -708,22 +708,22 @@ clicon_xml_changelog_set(clicon_handle h,
*/
int
clicon_argv_get(clicon_handle h,
- int *argc,
- char ***argv)
-
+ int *argc,
+ char ***argv)
+
{
clicon_hash_t *cdat = clicon_data(h);
void *p;
if (argc){
- if ((p = clicon_hash_value(cdat, "argc", NULL)) == NULL)
- return -1;
- *argc = *(int*)p;
+ if ((p = clicon_hash_value(cdat, "argc", NULL)) == NULL)
+ return -1;
+ *argc = *(int*)p;
}
if (argv){
- if ((p = clicon_hash_value(cdat, "argv", NULL)) == NULL)
- return -1;
- *argv = (char**)p;
+ if ((p = clicon_hash_value(cdat, "argv", NULL)) == NULL)
+ return -1;
+ *argv = (char**)p;
}
return 0;
}
@@ -739,9 +739,9 @@ clicon_argv_get(clicon_handle h,
*/
int
clicon_argv_set(clicon_handle h,
- char *prgm,
- int argc,
- char **argv)
+ char *prgm,
+ int argc,
+ char **argv)
{
int retval = -1;
clicon_hash_t *cdat = clicon_data(h);
@@ -751,21 +751,21 @@ clicon_argv_set(clicon_handle h,
/* add space for null-termination and argv[0] program name */
len = argc+2;
if ((argvv = calloc(len, sizeof(char*))) == NULL){
- clicon_err(OE_UNIX, errno, "calloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "calloc");
+ goto done;
}
memcpy(argvv+1, argv, argc*sizeof(char*));
argvv[0] = prgm;
/* Note the value is the argv vector (which is copied) */
if (clicon_hash_add(cdat, "argv", argvv, len*sizeof(char*))==NULL)
- goto done;
+ goto done;
argc += 1;
if (clicon_hash_add(cdat, "argc", &argc, sizeof(argc))==NULL)
- goto done;
+ goto done;
retval = 0;
done:
if (argvv)
- free(argvv);
+ free(argvv);
return retval;
}
@@ -777,13 +777,13 @@ clicon_argv_set(clicon_handle h,
*/
db_elmnt *
clicon_db_elmnt_get(clicon_handle h,
- const char *db)
+ const char *db)
{
clicon_hash_t *cdat = clicon_db_elmnt(h);
void *p;
if ((p = clicon_hash_value(cdat, db, NULL)) != NULL)
- return (db_elmnt *)p;
+ return (db_elmnt *)p;
return NULL;
}
@@ -797,13 +797,13 @@ clicon_db_elmnt_get(clicon_handle h,
*/
int
clicon_db_elmnt_set(clicon_handle h,
- const char *db,
- db_elmnt *de)
+ const char *db,
+ db_elmnt *de)
{
clicon_hash_t *cdat = clicon_db_elmnt(h);
if (clicon_hash_add(cdat, db, de, sizeof(*de))==NULL)
- return -1;
+ return -1;
return 0;
}
@@ -817,13 +817,13 @@ clicon_db_elmnt_set(clicon_handle h,
*/
int
clicon_session_id_get(clicon_handle h,
- uint32_t *id)
+ uint32_t *id)
{
clicon_hash_t *cdat = clicon_data(h);
void *p;
if ((p = clicon_hash_value(cdat, "session-id", NULL)) == NULL)
- return -1;
+ return -1;
*id = *(uint32_t*)p;
return 0;
}
@@ -837,7 +837,7 @@ clicon_session_id_get(clicon_handle h,
*/
int
clicon_session_id_set(clicon_handle h,
- uint32_t id)
+ uint32_t id)
{
clicon_hash_t *cdat = clicon_data(h);
@@ -858,7 +858,7 @@ clicon_quit_upgrade_get(clicon_handle h)
void *p;
if ((p = clicon_hash_value(cdat, "quit-after-upgrade", NULL)) == NULL)
- return 0;
+ return 0;
return *(int*)p;
}
@@ -871,7 +871,7 @@ clicon_quit_upgrade_get(clicon_handle h)
*/
int
clicon_quit_upgrade_set(clicon_handle h,
- int val)
+ int val)
{
clicon_hash_t *cdat = clicon_data(h);
diff --git a/lib/src/clixon_datastore.c b/lib/src/clixon_datastore.c
index bad333b0..dff98121 100644
--- a/lib/src/clixon_datastore.c
+++ b/lib/src/clixon_datastore.c
@@ -93,30 +93,30 @@
*/
int
xmldb_db2file(clicon_handle h,
- const char *db,
- char **filename)
+ const char *db,
+ char **filename)
{
int retval = -1;
cbuf *cb = NULL;
char *dir;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
if ((dir = clicon_xmldb_dir(h)) == NULL){
- clicon_err(OE_XML, errno, "dbdir not set");
- goto done;
+ clicon_err(OE_XML, errno, "dbdir not set");
+ goto done;
}
cprintf(cb, "%s/%s_db", dir, db);
if ((*filename = strdup4(cbuf_get(cb))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -130,10 +130,10 @@ int
xmldb_validate_db(const char *db)
{
if (strcmp(db, "running") != 0 &&
- strcmp(db, "candidate") != 0 &&
- strcmp(db, "startup") != 0 &&
- strcmp(db, "tmp") != 0)
- return -1;
+ strcmp(db, "candidate") != 0 &&
+ strcmp(db, "startup") != 0 &&
+ strcmp(db, "tmp") != 0)
+ return -1;
return 0;
}
@@ -163,18 +163,18 @@ xmldb_disconnect(clicon_handle h)
db_elmnt *de;
if (clicon_hash_keys(clicon_db_elmnt(h), &keys, &klen) < 0)
- goto done;
+ goto done;
for(i = 0; i < klen; i++)
- if ((de = clicon_hash_value(clicon_db_elmnt(h), keys[i], NULL)) != NULL){
- if (de->de_xml){
- xml_free(de->de_xml);
- de->de_xml = NULL;
- }
- }
+ if ((de = clicon_hash_value(clicon_db_elmnt(h), keys[i], NULL)) != NULL){
+ if (de->de_xml){
+ xml_free(de->de_xml);
+ de->de_xml = NULL;
+ }
+ }
retval = 0;
done:
if (keys)
- free(keys);
+ free(keys);
return retval;
}
@@ -187,8 +187,8 @@ xmldb_disconnect(clicon_handle h)
*/
int
xmldb_copy(clicon_handle h,
- const char *from,
- const char *to)
+ const char *from,
+ const char *to)
{
int retval = -1;
char *fromfile = NULL;
@@ -199,60 +199,60 @@ xmldb_copy(clicon_handle h,
cxobj *x1 = NULL; /* from */
cxobj *x2 = NULL; /* to */
+ clicon_debug(1, "%s %s %s", __FUNCTION__, from, to);
/* XXX lock */
if (clicon_datastore_cache(h) != DATASTORE_NOCACHE){
- /* Copy in-memory cache */
- /* 1. "to" xml tree in x1 */
- if ((de1 = clicon_db_elmnt_get(h, from)) != NULL)
- x1 = de1->de_xml;
- if ((de2 = clicon_db_elmnt_get(h, to)) != NULL)
- x2 = de2->de_xml;
- if (x1 == NULL && x2 == NULL){
- /* do nothing */
- }
- else if (x1 == NULL){ /* free x2 and set to NULL */
- xml_free(x2);
- x2 = NULL;
- }
- else if (x2 == NULL){ /* create x2 and copy from x1 */
- if ((x2 = xml_new(xml_name(x1), NULL, CX_ELMNT)) == NULL)
- goto done;
- xml_flag_set(x2, XML_FLAG_TOP);
- if (xml_copy(x1, x2) < 0)
- goto done;
- }
- else{ /* copy x1 to x2 */
- xml_free(x2);
- if ((x2 = xml_new(xml_name(x1), NULL, CX_ELMNT)) == NULL)
- goto done;
- xml_flag_set(x2, XML_FLAG_TOP);
- if (xml_copy(x1, x2) < 0)
- goto done;
- }
- /* always set cache although not strictly necessary in case 1
- * above, but logic gets complicated due to differences with
- * de and de->de_xml */
- if (de2)
- de0 = *de2;
- de0.de_xml = x2; /* The new tree */
+ /* Copy in-memory cache */
+ /* 1. "to" xml tree in x1 */
+ if ((de1 = clicon_db_elmnt_get(h, from)) != NULL)
+ x1 = de1->de_xml;
+ if ((de2 = clicon_db_elmnt_get(h, to)) != NULL)
+ x2 = de2->de_xml;
+ if (x1 == NULL && x2 == NULL){
+ /* do nothing */
+ }
+ else if (x1 == NULL){ /* free x2 and set to NULL */
+ xml_free(x2);
+ x2 = NULL;
+ }
+ else if (x2 == NULL){ /* create x2 and copy from x1 */
+ if ((x2 = xml_new(xml_name(x1), NULL, CX_ELMNT)) == NULL)
+ goto done;
+ xml_flag_set(x2, XML_FLAG_TOP);
+ if (xml_copy(x1, x2) < 0)
+ goto done;
+ }
+ else{ /* copy x1 to x2 */
+ xml_free(x2);
+ if ((x2 = xml_new(xml_name(x1), NULL, CX_ELMNT)) == NULL)
+ goto done;
+ xml_flag_set(x2, XML_FLAG_TOP);
+ if (xml_copy(x1, x2) < 0)
+ goto done;
+ }
+ /* always set cache although not strictly necessary in case 1
+ * above, but logic gets complicated due to differences with
+ * de and de->de_xml */
+ if (de2)
+ de0 = *de2;
+ de0.de_xml = x2; /* The new tree */
}
clicon_db_elmnt_set(h, to, &de0);
/* Copy the files themselves (above only in-memory cache) */
if (xmldb_db2file(h, from, &fromfile) < 0)
- goto done;
+ goto done;
if (xmldb_db2file(h, to, &tofile) < 0)
- goto done;
+ goto done;
if (clicon_file_copy(fromfile, tofile) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (fromfile)
- free(fromfile);
+ free(fromfile);
if (tofile)
- free(tofile);
+ free(tofile);
return retval;
-
}
/*! Lock database
@@ -264,14 +264,14 @@ xmldb_copy(clicon_handle h,
*/
int
xmldb_lock(clicon_handle h,
- const char *db,
- uint32_t id)
+ const char *db,
+ uint32_t id)
{
db_elmnt *de = NULL;
db_elmnt de0 = {0,};
if ((de = clicon_db_elmnt_get(h, db)) != NULL)
- de0 = *de;
+ de0 = *de;
de0.de_id = id;
clicon_db_elmnt_set(h, db, &de0);
clicon_debug(1, "%s: locked by %u", db, id);
@@ -287,13 +287,13 @@ xmldb_lock(clicon_handle h,
*/
int
xmldb_unlock(clicon_handle h,
- const char *db)
+ const char *db)
{
db_elmnt *de = NULL;
if ((de = clicon_db_elmnt_get(h, db)) != NULL){
- de->de_id = 0;
- clicon_db_elmnt_set(h, db, de);
+ de->de_id = 0;
+ clicon_db_elmnt_set(h, db, de);
}
return 0;
}
@@ -306,7 +306,7 @@ xmldb_unlock(clicon_handle h,
*/
int
xmldb_unlock_all(clicon_handle h,
- uint32_t id)
+ uint32_t id)
{
int retval = -1;
char **keys = NULL;
@@ -316,19 +316,19 @@ xmldb_unlock_all(clicon_handle h,
/* get all db:s */
if (clicon_hash_keys(clicon_db_elmnt(h), &keys, &klen) < 0)
- goto done;
+ goto done;
/* Identify the ones locked by client id */
for (i = 0; i < klen; i++) {
- if ((de = clicon_db_elmnt_get(h, keys[i])) != NULL &&
- de->de_id == id){
- de->de_id = 0;
- clicon_db_elmnt_set(h, keys[i], de);
- }
+ if ((de = clicon_db_elmnt_get(h, keys[i])) != NULL &&
+ de->de_id == id){
+ de->de_id = 0;
+ clicon_db_elmnt_set(h, keys[i], de);
+ }
}
retval = 0;
done:
if (keys)
- free(keys);
+ free(keys);
return retval;
}
@@ -341,39 +341,46 @@ xmldb_unlock_all(clicon_handle h,
*/
uint32_t
xmldb_islocked(clicon_handle h,
- const char *db)
+ const char *db)
{
db_elmnt *de;
if ((de = clicon_db_elmnt_get(h, db)) == NULL)
- return 0;
+ return 0;
return de->de_id;
}
-/*! Check if db exists
+/*! Check if db exists or is empty
* @param[in] h Clicon handle
* @param[in] db Database
* @retval -1 Error
* @retval 0 No it does not exist
* @retval 1 Yes it exists
+ * @note An empty datastore is treated as not existent so that a backend after dropping priviliges can re-create it
*/
int
xmldb_exists(clicon_handle h,
- const char *db)
+ const char *db)
{
int retval = -1;
char *filename = NULL;
struct stat sb;
+ clicon_debug(2, "%s %s", __FUNCTION__, db);
if (xmldb_db2file(h, db, &filename) < 0)
- goto done;
+ goto done;
if (lstat(filename, &sb) < 0)
- retval = 0;
- else
- retval = 1;
+ retval = 0;
+
+ else{
+ if (sb.st_size == 0)
+ retval = 0;
+ else
+ retval = 1;
+ }
done:
if (filename)
- free(filename);
+ free(filename);
return retval;
}
@@ -385,16 +392,16 @@ xmldb_exists(clicon_handle h,
*/
int
xmldb_clear(clicon_handle h,
- const char *db)
+ const char *db)
{
cxobj *xt = NULL;
db_elmnt *de = NULL;
if ((de = clicon_db_elmnt_get(h, db)) != NULL){
- if ((xt = de->de_xml) != NULL){
- xml_free(xt);
- de->de_xml = NULL;
- }
+ if ((xt = de->de_xml) != NULL){
+ xml_free(xt);
+ de->de_xml = NULL;
+ }
}
return 0;
}
@@ -404,28 +411,30 @@ xmldb_clear(clicon_handle h,
* @param[in] db Database
* @retval -1 Error
* @retval 0 OK
+ * @note Datastore is not actually deleted so that a backend after dropping priviliges can re-create it
*/
int
xmldb_delete(clicon_handle h,
- const char *db)
+ const char *db)
{
int retval = -1;
char *filename = NULL;
struct stat sb;
+ clicon_debug(2, "%s %s", __FUNCTION__, db);
if (xmldb_clear(h, db) < 0)
- goto done;
+ goto done;
if (xmldb_db2file(h, db, &filename) < 0)
- goto done;
+ goto done;
if (lstat(filename, &sb) == 0)
- if (truncate(filename, 0) < 0){
- clicon_err(OE_DB, errno, "truncate %s", filename);
- goto done;
- }
+ if (truncate(filename, 0) < 0){
+ clicon_err(OE_DB, errno, "truncate %s", filename);
+ goto done;
+ }
retval = 0;
done:
if (filename)
- free(filename);
+ free(filename);
return retval;
}
@@ -437,7 +446,7 @@ xmldb_delete(clicon_handle h,
*/
int
xmldb_create(clicon_handle h,
- const char *db)
+ const char *db)
{
int retval = -1;
char *filename = NULL;
@@ -445,24 +454,25 @@ xmldb_create(clicon_handle h,
db_elmnt *de = NULL;
cxobj *xt = NULL;
+ clicon_debug(2, "%s %s", __FUNCTION__, db);
if ((de = clicon_db_elmnt_get(h, db)) != NULL){
- if ((xt = de->de_xml) != NULL){
- xml_free(xt);
- de->de_xml = NULL;
- }
+ if ((xt = de->de_xml) != NULL){
+ xml_free(xt);
+ de->de_xml = NULL;
+ }
}
if (xmldb_db2file(h, db, &filename) < 0)
- goto done;
+ goto done;
if ((fd = open(filename, O_CREAT|O_WRONLY, S_IRWXU)) == -1) {
- clicon_err(OE_UNIX, errno, "open(%s)", filename);
- goto done;
+ clicon_err(OE_UNIX, errno, "open(%s)", filename);
+ goto done;
}
retval = 0;
done:
if (filename)
- free(filename);
+ free(filename);
if (fd != -1)
- close(fd);
+ close(fd);
return retval;
}
@@ -473,14 +483,14 @@ xmldb_create(clicon_handle h,
*/
int
xmldb_db_reset(clicon_handle h,
- const char *db)
+ const char *db)
{
if (xmldb_exists(h, db) == 1){
- if (xmldb_delete(h, db) != 0 && errno != ENOENT)
- return -1;
+ if (xmldb_delete(h, db) != 0 && errno != ENOENT)
+ return -1;
}
if (xmldb_create(h, db) < 0)
- return -1;
+ return -1;
return 0;
}
@@ -491,12 +501,12 @@ xmldb_db_reset(clicon_handle h,
*/
cxobj *
xmldb_cache_get(clicon_handle h,
- const char *db)
+ const char *db)
{
db_elmnt *de;
if ((de = clicon_db_elmnt_get(h, db)) == NULL)
- return NULL;
+ return NULL;
return de->de_xml;
}
@@ -511,13 +521,13 @@ xmldb_cache_get(clicon_handle h,
*/
int
xmldb_modified_get(clicon_handle h,
- const char *db)
+ const char *db)
{
db_elmnt *de;
if ((de = clicon_db_elmnt_get(h, db)) == NULL){
- clicon_err(OE_CFG, EFAULT, "datastore %s does not exist", db);
- return -1;
+ clicon_err(OE_CFG, EFAULT, "datastore %s does not exist", db);
+ return -1;
}
return de->de_modified;
}
@@ -531,13 +541,13 @@ xmldb_modified_get(clicon_handle h,
*/
int
xmldb_empty_get(clicon_handle h,
- const char *db)
+ const char *db)
{
db_elmnt *de;
if ((de = clicon_db_elmnt_get(h, db)) == NULL){
- clicon_err(OE_CFG, EFAULT, "datastore %s does not exist", db);
- return -1;
+ clicon_err(OE_CFG, EFAULT, "datastore %s does not exist", db);
+ return -1;
}
return de->de_empty;
}
@@ -553,14 +563,14 @@ xmldb_empty_get(clicon_handle h,
*/
int
xmldb_modified_set(clicon_handle h,
- const char *db,
- int value)
+ const char *db,
+ int value)
{
db_elmnt *de;
if ((de = clicon_db_elmnt_get(h, db)) == NULL){
- clicon_err(OE_CFG, EFAULT, "datastore %s does not exist", db);
- return -1;
+ clicon_err(OE_CFG, EFAULT, "datastore %s does not exist", db);
+ return -1;
}
de->de_modified = value;
return 0;
@@ -570,7 +580,7 @@ xmldb_modified_set(clicon_handle h,
*/
int
xmldb_print(clicon_handle h,
- FILE *f)
+ FILE *f)
{
int retval = -1;
db_elmnt *de = NULL;
@@ -579,18 +589,63 @@ xmldb_print(clicon_handle h,
int i;
if (clicon_hash_keys(clicon_db_elmnt(h), &keys, &klen) < 0)
- goto done;
+ goto done;
for (i = 0; i < klen; i++){
- /* XXX name */
- if ((de = clicon_db_elmnt_get(h, keys[i])) == NULL)
- continue;
- fprintf(f, "Datastore: %s\n", keys[i]);
- fprintf(f, " Session: %u\n", de->de_id);
- fprintf(f, " XML: %p\n", de->de_xml);
- fprintf(f, " Modified: %d\n", de->de_modified);
- fprintf(f, " Empty: %d\n", de->de_empty);
+ /* XXX name */
+ if ((de = clicon_db_elmnt_get(h, keys[i])) == NULL)
+ continue;
+ fprintf(f, "Datastore: %s\n", keys[i]);
+ fprintf(f, " Session: %u\n", de->de_id);
+ fprintf(f, " XML: %p\n", de->de_xml);
+ fprintf(f, " Modified: %d\n", de->de_modified);
+ fprintf(f, " Empty: %d\n", de->de_empty);
}
retval = 0;
done:
return retval;
}
+
+/*! Rename an XML database
+ * @param[in] h Clicon handle
+ * @param[in] db Database name
+ * @param[in] newdb New Database name; if NULL, then same as old
+ * @param[in] suffix Suffix to append to new database name
+ * @retval -1 Error
+ * @retval 0 OK
+ * @note if newdb and suffix are null, OK is returned as it is a no-op
+ */
+int
+xmldb_rename(clicon_handle h,
+ const char *db,
+ const char *newdb,
+ const char *suffix)
+{
+ int retval = -1;
+ char *old;
+ char *fname = NULL;
+ cbuf *cb = NULL;
+
+ if ((xmldb_db2file(h, db, &old)) < 0)
+ goto done;
+ if (newdb == NULL && suffix == NULL) // no-op
+ goto done;
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "%s", newdb == NULL ? old : newdb);
+ if (suffix)
+ cprintf(cb, "%s", suffix);
+ fname = cbuf_get(cb);
+ if ((rename(old, fname)) < 0) {
+ clicon_err(OE_UNIX, errno, "rename: %s", strerror(errno));
+ goto done;
+ };
+ retval = 0;
+ done:
+ if (cb)
+ cbuf_free(cb);
+ if (old)
+ free(old);
+ return retval;
+}
diff --git a/lib/src/clixon_datastore_read.c b/lib/src/clixon_datastore_read.c
index 2b65e51c..13bac99e 100644
--- a/lib/src/clixon_datastore_read.c
+++ b/lib/src/clixon_datastore_read.c
@@ -92,7 +92,7 @@
*/
static int
singleconfigroot(cxobj *xt,
- cxobj **xp)
+ cxobj **xp)
{
int retval = -1;
cxobj *x = NULL;
@@ -101,25 +101,25 @@ singleconfigroot(cxobj *xt,
/* There should only be one element and called config */
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL){
- i++;
- if (strcmp(xml_name(x), DATASTORE_TOP_SYMBOL)){
- clicon_err(OE_DB, ENOENT, "Wrong top-element %s expected %s",
- xml_name(x), DATASTORE_TOP_SYMBOL);
- goto done;
- }
+ i++;
+ if (strcmp(xml_name(x), DATASTORE_TOP_SYMBOL)){
+ clicon_err(OE_DB, ENOENT, "Wrong top-element %s expected %s",
+ xml_name(x), DATASTORE_TOP_SYMBOL);
+ goto done;
+ }
}
if (i != 1){
- clicon_err(OE_DB, ENOENT, "Top-element is not unique, expecting single config");
- goto done;
+ clicon_err(OE_DB, ENOENT, "Top-element is not unique, expecting single config");
+ goto done;
}
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL){
- if (xml_rm(x) < 0)
- goto done;
- if (xml_free(xt) < 0)
- goto done;
- *xp = x;
- break;
+ if (xml_rm(x) < 0)
+ goto done;
+ if (xml_free(xt) < 0)
+ goto done;
+ *xp = x;
+ break;
}
retval = 0;
done:
@@ -132,9 +132,9 @@ singleconfigroot(cxobj *xt,
*/
static int
xml_copy_bottom_recurse(cxobj *x0t,
- cxobj *x0,
- cxobj *x1t,
- cxobj **x1pp)
+ cxobj *x0,
+ cxobj *x1t,
+ cxobj **x1pp)
{
int retval = -1;
cxobj *x0p = NULL;
@@ -150,52 +150,52 @@ xml_copy_bottom_recurse(cxobj *x0t,
char *keyname;
if (x0 == x0t){
- *x1pp = x1t;
- goto ok;
+ *x1pp = x1t;
+ goto ok;
}
if ((x0p = xml_parent(x0)) == NULL){
- clicon_err(OE_XML, EFAULT, "Reached top of tree");
- goto done;
+ clicon_err(OE_XML, EFAULT, "Reached top of tree");
+ goto done;
}
if (xml_copy_bottom_recurse(x0t, x0p, x1t, &x1p) < 0)
- goto done;
+ goto done;
y = xml_spec(x0);
/* Look if it exists */
if (match_base_child(x1p, x0, y, &x1) < 0)
- goto done;
+ goto done;
if (x1 == NULL){ /* If not, create it and copy it one level only */
- if ((x1 = xml_new(xml_name(x0), x1p, CX_ELMNT)) == NULL)
- goto done;
- if (xml_copy_one(x0, x1) < 0)
- goto done;
- /* Copy all attributes */
- x0a = NULL;
- while ((x0a = xml_child_each(x0, x0a, -1)) != NULL) {
- /* Assume ordered, skip after attributes */
- if (xml_type(x0a) != CX_ATTR)
- break;
- if ((x1a = xml_new(xml_name(x0a), x1, CX_ATTR)) == NULL)
- goto done;
- if (xml_copy_one(x0a, x1a) < 0)
- goto done;
- }
- /* Key nodes in lists are copied */
- if (y && yang_keyword_get(y) == Y_LIST){
- /* Loop over all key variables */
- cvk = yang_cvec_get(y); /* Use Y_LIST cache, see ys_populate_list() */
- cvi = NULL;
- /* Iterate over individual keys */
- while ((cvi = cvec_each(cvk, cvi)) != NULL) {
- keyname = cv_string_get(cvi);
- if ((x0k = xml_find_type(x0, NULL, keyname, CX_ELMNT)) != NULL){
- if ((x1k = xml_new(keyname, x1, CX_ELMNT)) == NULL)
- goto done;
- if (xml_copy(x0k, x1k) < 0)
- goto done;
- }
+ if ((x1 = xml_new(xml_name(x0), x1p, CX_ELMNT)) == NULL)
+ goto done;
+ if (xml_copy_one(x0, x1) < 0)
+ goto done;
+ /* Copy all attributes */
+ x0a = NULL;
+ while ((x0a = xml_child_each(x0, x0a, -1)) != NULL) {
+ /* Assume ordered, skip after attributes */
+ if (xml_type(x0a) != CX_ATTR)
+ break;
+ if ((x1a = xml_new(xml_name(x0a), x1, CX_ATTR)) == NULL)
+ goto done;
+ if (xml_copy_one(x0a, x1a) < 0)
+ goto done;
+ }
+ /* Key nodes in lists are copied */
+ if (y && yang_keyword_get(y) == Y_LIST){
+ /* Loop over all key variables */
+ cvk = yang_cvec_get(y); /* Use Y_LIST cache, see ys_populate_list() */
+ cvi = NULL;
+ /* Iterate over individual keys */
+ while ((cvi = cvec_each(cvk, cvi)) != NULL) {
+ keyname = cv_string_get(cvi);
+ if ((x0k = xml_find_type(x0, NULL, keyname, CX_ELMNT)) != NULL){
+ if ((x1k = xml_new(keyname, x1, CX_ELMNT)) == NULL)
+ goto done;
+ if (xml_copy(x0k, x1k) < 0)
+ goto done;
+ }
- }
- }
+ }
+ }
}
*x1pp = x1;
ok:
@@ -210,8 +210,8 @@ xml_copy_bottom_recurse(cxobj *x0t,
*/
static int
xml_copy_from_bottom(cxobj *x0t,
- cxobj *x0,
- cxobj *x1t)
+ cxobj *x0,
+ cxobj *x1t)
{
int retval = -1;
cxobj *x1p = NULL;
@@ -220,20 +220,20 @@ xml_copy_from_bottom(cxobj *x0t,
yang_stmt *y = NULL;
if (x0 == x0t)
- goto ok;
+ goto ok;
x0p = xml_parent(x0);
if (xml_copy_bottom_recurse(x0t, x0p, x1t, &x1p) < 0)
- goto done;
+ goto done;
if ((y = xml_spec(x0)) != NULL){
- /* Look if it exists */
- if (match_base_child(x1p, x0, y, &x1) < 0)
- goto done;
+ /* Look if it exists */
+ if (match_base_child(x1p, x0, y, &x1) < 0)
+ goto done;
}
if (x1 == NULL){ /* If not, create it and copy complete tree */
- if ((x1 = xml_new(xml_name(x0), x1p, CX_ELMNT)) == NULL)
- goto done;
- if (xml_copy(x0, x1) < 0)
- goto done;
+ if ((x1 = xml_new(xml_name(x0), x1p, CX_ELMNT)) == NULL)
+ goto done;
+ if (xml_copy(x0, x1) < 0)
+ goto done;
}
ok:
retval = 0;
@@ -270,9 +270,9 @@ xml_copy_from_bottom(cxobj *x0t,
*/
static int
text_read_modstate(clicon_handle h,
- yang_stmt *yspec,
- cxobj *xt,
- modstate_diff_t *msdiff)
+ yang_stmt *yspec,
+ cxobj *xt,
+ modstate_diff_t *msdiff)
{
int retval = -1;
cxobj *xmodfile = NULL; /* modstate of system (loaded yang modules in runtime) */
@@ -290,102 +290,102 @@ text_read_modstate(clicon_handle h,
/* Read module-state as computed at startup, see startup_module_state() */
if ((xmodcache = clicon_modst_cache_get(h, 1)) != NULL)
- xmodsystem = xml_find_type(xmodcache, NULL, "module-set", CX_ELMNT);
+ xmodsystem = xml_find_type(xmodcache, NULL, "module-set", CX_ELMNT);
xyanglib = xml_find_type(xt, NULL, "yang-library", CX_ELMNT);
if ((xmodfile = xpath_first(xt, NULL, "yang-library/module-set")) != NULL)
- ;
+ ;
else if ((xmodfile = xml_find_type(xt, NULL, "modules-state", CX_ELMNT)) != NULL)
- rfc7895++;
+ rfc7895++;
if (xmodfile && xmodsystem && msdiff){
- msdiff->md_status = 1; /* There is module state in the file */
- /* Create modstate tree for this file
- * Note, module-set is not a top-level symbol, so cannot bind using module-set
- */
- if (clixon_xml_parse_string("",
- YB_NONE, yspec, &msdiff->md_diff, NULL) < 0)
- goto done;
- if (xml_rootchild(msdiff->md_diff, 0, &msdiff->md_diff) < 0)
- goto done;
+ msdiff->md_status = 1; /* There is module state in the file */
+ /* Create modstate tree for this file
+ * Note, module-set is not a top-level symbol, so cannot bind using module-set
+ */
+ if (clixon_xml_parse_string("",
+ YB_NONE, yspec, &msdiff->md_diff, NULL) < 0)
+ goto done;
+ if (xml_rootchild(msdiff->md_diff, 0, &msdiff->md_diff) < 0)
+ goto done;
- if (!rfc7895){
- if ((xf = xpath_first(xt, NULL, "yang-library/content-id")) != NULL){
- if (xml_body(xf) && (msdiff->md_content_id = strdup(xml_body(xf))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- }
- }
- /* 3) For each module state m in the file */
- xf = NULL;
- while ((xf = xml_child_each(xmodfile, xf, CX_ELMNT)) != NULL) {
- if (rfc7895){
- if (strcmp(xml_name(xf), "module-set-id") == 0){
- if (xml_body(xf) && (msdiff->md_content_id = strdup(xml_body(xf))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- continue;
- }
- }
- if (strcmp(xml_name(xf), "module"))
- continue; /* ignore other tags, such as module-set-id */
- if ((name = xml_find_body(xf, "name")) == NULL)
- continue;
- /* 3a) There is no such module in the system */
- if ((xs = xpath_first(xmodsystem, NULL, "module[name=\"%s\"]", name)) == NULL){
- if ((xf2 = xml_dup(xf)) == NULL) /* Make a copy of this modstate */
- goto done;
- if (xml_addsub(msdiff->md_diff, xf2) < 0) /* Add it to modstatediff */
- goto done;
- xml_flag_set(xf2, XML_FLAG_DEL);
- continue;
- }
- /* These two shouldnt happen since revision is key, just ignore */
- if ((frev = xml_find_body(xf, "revision")) == NULL)
- continue;
- if ((srev = xml_find_body(xs, "revision")) == NULL)
- continue;
- if (strcmp(frev, srev) != 0){
- /* 3c) File module-state does not match system */
- if ((xf2 = xml_dup(xf)) == NULL)
- goto done;
- if (xml_addsub(msdiff->md_diff, xf2) < 0)
- goto done;
- xml_flag_set(xf2, XML_FLAG_CHANGE);
- }
- }
- /* 4) For each module state s in the system (xmodsystem) */
- xs = NULL;
- while ((xs = xml_child_each(xmodsystem, xs, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(xs), "module"))
- continue; /* ignore other tags, such as module-set-id */
- if ((name = xml_find_body(xs, "name")) == NULL)
- continue;
- /* 4a) If there is no such module in the file -> add to list mark as ADD */
- if ((xf = xpath_first(xmodfile, NULL, "module[name=\"%s\"]", name)) == NULL){
- if ((xs2 = xml_dup(xs)) == NULL) /* Make a copy of this modstate */
- goto done;
- if (xml_addsub(msdiff->md_diff, xs2) < 0) /* Add it to modstatediff */
- goto done;
- xml_flag_set(xs2, XML_FLAG_ADD);
- continue;
- }
- }
+ if (!rfc7895){
+ if ((xf = xpath_first(xt, NULL, "yang-library/content-id")) != NULL){
+ if (xml_body(xf) && (msdiff->md_content_id = strdup(xml_body(xf))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ }
+ }
+ /* 3) For each module state m in the file */
+ xf = NULL;
+ while ((xf = xml_child_each(xmodfile, xf, CX_ELMNT)) != NULL) {
+ if (rfc7895){
+ if (strcmp(xml_name(xf), "module-set-id") == 0){
+ if (xml_body(xf) && (msdiff->md_content_id = strdup(xml_body(xf))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ continue;
+ }
+ }
+ if (strcmp(xml_name(xf), "module"))
+ continue; /* ignore other tags, such as module-set-id */
+ if ((name = xml_find_body(xf, "name")) == NULL)
+ continue;
+ /* 3a) There is no such module in the system */
+ if ((xs = xpath_first(xmodsystem, NULL, "module[name=\"%s\"]", name)) == NULL){
+ if ((xf2 = xml_dup(xf)) == NULL) /* Make a copy of this modstate */
+ goto done;
+ if (xml_addsub(msdiff->md_diff, xf2) < 0) /* Add it to modstatediff */
+ goto done;
+ xml_flag_set(xf2, XML_FLAG_DEL);
+ continue;
+ }
+ /* These two shouldnt happen since revision is key, just ignore */
+ if ((frev = xml_find_body(xf, "revision")) == NULL)
+ continue;
+ if ((srev = xml_find_body(xs, "revision")) == NULL)
+ continue;
+ if (strcmp(frev, srev) != 0){
+ /* 3c) File module-state does not match system */
+ if ((xf2 = xml_dup(xf)) == NULL)
+ goto done;
+ if (xml_addsub(msdiff->md_diff, xf2) < 0)
+ goto done;
+ xml_flag_set(xf2, XML_FLAG_CHANGE);
+ }
+ }
+ /* 4) For each module state s in the system (xmodsystem) */
+ xs = NULL;
+ while ((xs = xml_child_each(xmodsystem, xs, CX_ELMNT)) != NULL) {
+ if (strcmp(xml_name(xs), "module"))
+ continue; /* ignore other tags, such as module-set-id */
+ if ((name = xml_find_body(xs, "name")) == NULL)
+ continue;
+ /* 4a) If there is no such module in the file -> add to list mark as ADD */
+ if ((xf = xpath_first(xmodfile, NULL, "module[name=\"%s\"]", name)) == NULL){
+ if ((xs2 = xml_dup(xs)) == NULL) /* Make a copy of this modstate */
+ goto done;
+ if (xml_addsub(msdiff->md_diff, xs2) < 0) /* Add it to modstatediff */
+ goto done;
+ xml_flag_set(xs2, XML_FLAG_ADD);
+ continue;
+ }
+ }
}
/* The module-state is removed from the input XML tree. This is done
* in all cases, whether CLICON_XMLDB_MODSTATE is on or not.
* Clixon systems with CLICON_XMLDB_MODSTATE disabled ignores it
*/
if (rfc7895){
- if (xmodfile){
- if (xml_purge(xmodfile) < 0)
- goto done;
- }
+ if (xmodfile){
+ if (xml_purge(xmodfile) < 0)
+ goto done;
+ }
}
else if (xyanglib)
- if (xml_purge(xyanglib) < 0)
- goto done;
+ if (xml_purge(xyanglib) < 0)
+ goto done;
retval = 0;
done:
return retval;
@@ -399,7 +399,7 @@ text_read_modstate(clicon_handle h,
*/
static int
disable_nacm_on_empty(cxobj *xt,
- yang_stmt *yspec)
+ yang_stmt *yspec)
{
int retval = -1;
yang_stmt *ymod;
@@ -410,27 +410,27 @@ disable_nacm_on_empty(cxobj *xt,
cxobj *xb;
if ((ymod = yang_find(yspec, Y_MODULE, "ietf-netconf-acm")) == NULL)
- goto ok;
+ goto ok;
if ((xnacm = xpath_first(xt, NULL, "nacm")) == NULL)
- goto ok;
+ goto ok;
/* Go through all children and check all are defaults, otherwise quit */
x = NULL;
while ((x = xml_child_each(xnacm, x, CX_ELMNT)) != NULL) {
- if (!xml_flag(x, XML_FLAG_DEFAULT))
- break;
+ if (!xml_flag(x, XML_FLAG_DEFAULT))
+ break;
}
if (x != NULL)
- goto ok; /* not empty, at least one non-default child of nacm */
+ goto ok; /* not empty, at least one non-default child of nacm */
if (clixon_xml_find_instance_id(xt, yspec, &vec, &len, "/nacm:nacm/nacm:enable-nacm") < 1)
- goto done;
+ goto done;
if (len){
- if ((xb = xml_body_get(vec[0])) == NULL)
- goto done;
- if (xml_value_set(xb, "false") < 0)
- goto done;
+ if ((xb = xml_body_get(vec[0])) == NULL)
+ goto done;
+ if (xml_value_set(xb, "false") < 0)
+ goto done;
}
if (vec)
- free(vec);
+ free(vec);
ok:
retval = 0;
done:
@@ -455,13 +455,13 @@ disable_nacm_on_empty(cxobj *xt,
*/
int
xmldb_readfile(clicon_handle h,
- const char *db,
- yang_bind yb,
- yang_stmt *yspec,
- cxobj **xp,
- db_elmnt *de,
- modstate_diff_t *msdiff0,
- cxobj **xerr)
+ const char *db,
+ yang_bind yb,
+ yang_stmt *yspec,
+ cxobj **xp,
+ db_elmnt *de,
+ modstate_diff_t *msdiff0,
+ cxobj **xerr)
{
int retval = -1;
cxobj *x0 = NULL;
@@ -481,23 +481,23 @@ xmldb_readfile(clicon_handle h,
yang_stmt *yspec1 = NULL;
if (yb != YB_MODULE && yb != YB_NONE){
- clicon_err(OE_XML, EINVAL, "yb is %d but should be module or none", yb);
- goto done;
+ clicon_err(OE_XML, EINVAL, "yb is %d but should be module or none", yb);
+ goto done;
}
if (xmldb_db2file(h, db, &dbfile) < 0)
- goto done;
+ goto done;
if (dbfile==NULL){
- clicon_err(OE_XML, 0, "dbfile NULL");
- goto done;
+ clicon_err(OE_XML, 0, "dbfile NULL");
+ goto done;
}
if ((format = clicon_option_str(h, "CLICON_XMLDB_FORMAT")) == NULL){
- clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
- goto done;
+ clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
+ goto done;
}
/* Parse file into internal XML tree from different formats */
if ((fp = fopen(dbfile, "r")) == NULL) {
- clicon_err(OE_UNIX, errno, "open(%s)", dbfile);
- goto done;
+ clicon_err(OE_UNIX, errno, "open(%s)", dbfile);
+ goto done;
}
/* Read whole datastore file on the form:
*
@@ -506,147 +506,147 @@ xmldb_readfile(clicon_handle h,
*
* ret == 0 should not happen with YB_NONE. Binding is done later */
if (strcmp(format, "json")==0){
- if (clixon_json_parse_file(fp, 1, YB_NONE, yspec, &x0, xerr) < 0)
- goto done;
+ if (clixon_json_parse_file(fp, 1, YB_NONE, yspec, &x0, xerr) < 0)
+ goto done;
}
else {
- if (clixon_xml_parse_file(fp, YB_NONE, yspec, &x0, xerr) < 0){
- goto done;
- }
+ if (clixon_xml_parse_file(fp, YB_NONE, yspec, &x0, xerr) < 0){
+ goto done;
+ }
}
/* Always assert a top-level called "config".
* To ensure that, deal with two cases:
* 1. File is empty -> rename top-level to "config"
*/
if (xml_child_nr(x0) == 0){
- if (xml_name_set(x0, DATASTORE_TOP_SYMBOL) < 0)
- goto done;
+ if (xml_name_set(x0, DATASTORE_TOP_SYMBOL) < 0)
+ goto done;
}
/* 2. File is not empty ... -> replace root */
else{
- /* There should only be one element and called config */
- if (singleconfigroot(x0, &x0) < 0)
- goto done;
+ /* There should only be one element and called config */
+ if (singleconfigroot(x0, &x0) < 0)
+ goto done;
}
/* Purge all top-level body objects */
x = NULL;
while ((x = xml_find_type(x0, NULL, "body", CX_BODY)) != NULL)
- xml_purge(x);
+ xml_purge(x);
xml_flag_set(x0, XML_FLAG_TOP);
if (xml_child_nr(x0) == 0 && de)
- de->de_empty = 1;
+ de->de_empty = 1;
/* Check if we support modstate */
if (clicon_option_bool(h, "CLICON_XMLDB_MODSTATE"))
- if ((msdiff = modstate_diff_new()) == NULL)
- goto done;
+ if ((msdiff = modstate_diff_new()) == NULL)
+ goto done;
/* First try RFC8525, but also backward compatible RFC7895 */
if ((x = xpath_first(x0, NULL, "yang-library/module-set")) != NULL ||
- (x = xml_find_type(x0, NULL, "modules-state", CX_ELMNT)) != NULL){
- if ((xmodfile = xml_dup(x)) == NULL)
- goto done;
+ (x = xml_find_type(x0, NULL, "modules-state", CX_ELMNT)) != NULL){
+ if ((xmodfile = xml_dup(x)) == NULL)
+ goto done;
}
/* Datastore files may contain module-state defining
* which modules are used in the file.
* Strip module-state, analyze it with CHANGE/ADD/RM and return msdiff
*/
if (text_read_modstate(h, yspec, x0, msdiff) < 0)
- goto done;
+ goto done;
if (yb == YB_MODULE){
- if (msdiff){
- /* Check if old/deleted yangs not present in the loaded/running yangspec.
- * If so, append them to the global yspec
- */
- needclone = 0;
- xmsd = NULL;
- while ((xmsd = xml_child_each(msdiff->md_diff, xmsd, CX_ELMNT)) != NULL) {
- if (xml_flag(xmsd, XML_FLAG_CHANGE|XML_FLAG_DEL) == 0)
- continue;
- needclone++;
- /* Extract name, namespace, and revision */
- if ((name = xml_find_body(xmsd, "name")) == NULL)
- continue;
- if ((ns = xml_find_body(xmsd, "namespace")) == NULL)
- continue;
- /* Extract revision */
- if ((rev = xml_find_body(xmsd, "revision")) == NULL)
- continue;
- /* Add old/deleted yangs not present in the loaded/running yangspec. */
- if ((ymod = yang_find_module_by_namespace_revision(yspec, ns, rev)) == NULL){
- /* YANG Module not found, look for it and append if found */
- if (yang_spec_parse_module(h, name, rev, yspec) < 0){
- /* Special case: file-not-found errors */
- if (clicon_suberrno == ENOENT){
- cbuf *cberr = NULL;
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- cprintf(cberr, "Internal error: %s", clicon_err_reason);
- clicon_err_reset();
- if (xerr && netconf_operation_failed_xml(xerr, "application", cbuf_get(cberr))< 0)
- goto done;
- cbuf_free(cberr);
- goto fail;
- }
- goto done;
- }
- }
- }
- /* If we found an obsolete yang module, we need to make a clone yspec with the
- * exactly the yang modules found
- * Same ymodules are inserted into yspec1, ie pointers only
- */
- if (needclone && xmodfile){
- if ((yspec1 = yspec_new()) == NULL)
- goto done;
- xmsd = NULL;
- while ((xmsd = xml_child_each(xmodfile, xmsd, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(xmsd), "module"))
- continue;
- if ((ns = xml_find_body(xmsd, "namespace")) == NULL)
- continue;
- if ((rev = xml_find_body(xmsd, "revision")) == NULL)
- continue;
- if ((ymod = yang_find_module_by_namespace_revision(yspec, ns, rev)) == NULL)
- continue; // XXX error?
- if (yn_insert1(yspec1, ymod) < 0)
- goto done;
- }
- }
- } /* if msdiff */
- /* xml looks like: ... actually YB_MODULE_NEXT
- */
- if ((ret = xml_bind_yang(x0, YB_MODULE, yspec1?yspec1:yspec, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- if (xml_sort_recurse(x0) < 0)
- goto done;
+ if (msdiff){
+ /* Check if old/deleted yangs not present in the loaded/running yangspec.
+ * If so, append them to the global yspec
+ */
+ needclone = 0;
+ xmsd = NULL;
+ while ((xmsd = xml_child_each(msdiff->md_diff, xmsd, CX_ELMNT)) != NULL) {
+ if (xml_flag(xmsd, XML_FLAG_CHANGE|XML_FLAG_DEL) == 0)
+ continue;
+ needclone++;
+ /* Extract name, namespace, and revision */
+ if ((name = xml_find_body(xmsd, "name")) == NULL)
+ continue;
+ if ((ns = xml_find_body(xmsd, "namespace")) == NULL)
+ continue;
+ /* Extract revision */
+ if ((rev = xml_find_body(xmsd, "revision")) == NULL)
+ continue;
+ /* Add old/deleted yangs not present in the loaded/running yangspec. */
+ if ((ymod = yang_find_module_by_namespace_revision(yspec, ns, rev)) == NULL){
+ /* YANG Module not found, look for it and append if found */
+ if (yang_spec_parse_module(h, name, rev, yspec) < 0){
+ /* Special case: file-not-found errors */
+ if (clicon_suberrno == ENOENT){
+ cbuf *cberr = NULL;
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cberr, "Internal error: %s", clicon_err_reason);
+ clicon_err_reset();
+ if (xerr && netconf_operation_failed_xml(xerr, "application", cbuf_get(cberr))< 0)
+ goto done;
+ cbuf_free(cberr);
+ goto fail;
+ }
+ goto done;
+ }
+ }
+ }
+ /* If we found an obsolete yang module, we need to make a clone yspec with the
+ * exactly the yang modules found
+ * Same ymodules are inserted into yspec1, ie pointers only
+ */
+ if (needclone && xmodfile){
+ if ((yspec1 = yspec_new()) == NULL)
+ goto done;
+ xmsd = NULL;
+ while ((xmsd = xml_child_each(xmodfile, xmsd, CX_ELMNT)) != NULL) {
+ if (strcmp(xml_name(xmsd), "module"))
+ continue;
+ if ((ns = xml_find_body(xmsd, "namespace")) == NULL)
+ continue;
+ if ((rev = xml_find_body(xmsd, "revision")) == NULL)
+ continue;
+ if ((ymod = yang_find_module_by_namespace_revision(yspec, ns, rev)) == NULL)
+ continue; // XXX error?
+ if (yn_insert1(yspec1, ymod) < 0)
+ goto done;
+ }
+ }
+ } /* if msdiff */
+ /* xml looks like: ... actually YB_MODULE_NEXT
+ */
+ if ((ret = xml_bind_yang(x0, YB_MODULE, yspec1?yspec1:yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ if (xml_sort_recurse(x0) < 0)
+ goto done;
}
if (xp){
- *xp = x0;
- x0 = NULL;
+ *xp = x0;
+ x0 = NULL;
}
if (msdiff0){
- *msdiff0 = *msdiff;
- free(msdiff); /* Just body */
- msdiff = NULL;
+ *msdiff0 = *msdiff;
+ free(msdiff); /* Just body */
+ msdiff = NULL;
}
retval = 1;
done:
if (yspec1)
- ys_free1(yspec1, 1);
+ ys_free1(yspec1, 1);
if (xmodfile)
- xml_free(xmodfile);
+ xml_free(xmodfile);
if (msdiff)
- modstate_diff_free(msdiff);
+ modstate_diff_free(msdiff);
if (fp)
- fclose(fp);
+ fclose(fp);
if (dbfile)
- free(dbfile);
+ free(dbfile);
if (x0)
- xml_free(x0);
+ xml_free(x0);
return retval;
fail:
retval = 0;
@@ -673,13 +673,13 @@ xmldb_readfile(clicon_handle h,
*/
static int
xmldb_get_nocache(clicon_handle h,
- const char *db,
- yang_bind yb,
- cvec *nsc,
- const char *xpath,
- cxobj **xtop,
- modstate_diff_t *msdiff,
- cxobj **xerr)
+ const char *db,
+ yang_bind yb,
+ cvec *nsc,
+ const char *xpath,
+ cxobj **xtop,
+ modstate_diff_t *msdiff,
+ cxobj **xerr)
{
int retval = -1;
char *dbfile = NULL;
@@ -694,71 +694,71 @@ xmldb_get_nocache(clicon_handle h,
db_elmnt de0 = {0,};
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No yang spec");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "No yang spec");
+ goto done;
}
/* xml looks like: ... where "x" is a top-level symbol in a module */
if ((ret = xmldb_readfile(h, db, yb, yspec, &xt, &de0, msdiff, xerr)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
clicon_db_elmnt_set(h, db, &de0); /* Content is copied */
/* Here xt looks like: ... */
/* Given the xpath, return a vector of matches in xvec */
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, xpath?xpath:"/") < 0)
- goto done;
+ goto done;
/* If vectors are specified then mark the nodes found with all ancestors
* and filter out everything else,
* otherwise return complete tree.
*/
if (xvec != NULL)
- for (i=0; i1)
- if (clixon_xml2file(stderr, xt, 0, 1, fprintf, 0, 0) < 0)
- goto done;
+ if (clixon_xml2file(stderr, xt, 0, 1, fprintf, 0, 0) < 0)
+ goto done;
*xtop = xt;
xt = NULL;
retval = 1;
done:
if (xt)
- xml_free(xt);
+ xml_free(xt);
if (dbfile)
- free(dbfile);
+ free(dbfile);
if (xvec)
- free(xvec);
+ free(xvec);
if (fd != -1)
- close(fd);
+ close(fd);
return retval;
fail:
retval = 0;
@@ -785,13 +785,13 @@ xmldb_get_nocache(clicon_handle h,
*/
static int
xmldb_get_cache(clicon_handle h,
- const char *db,
- yang_bind yb,
- cvec *nsc,
- const char *xpath,
- cxobj **xtop,
- modstate_diff_t *msdiff,
- cxobj **xerr)
+ const char *db,
+ yang_bind yb,
+ cvec *nsc,
+ const char *xpath,
+ cxobj **xtop,
+ modstate_diff_t *msdiff,
+ cxobj **xerr)
{
int retval = -1;
@@ -807,41 +807,41 @@ xmldb_get_cache(clicon_handle h,
int ret;
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No yang spec");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "No yang spec");
+ goto done;
}
de = clicon_db_elmnt_get(h, db);
if (de == NULL || de->de_xml == NULL){ /* Cache miss, read XML from file */
- /* If there is no xml x0 tree (in cache), then read it from file */
- /* xml looks like: ... where "x" is a top-level symbol in a module */
- if ((ret = xmldb_readfile(h, db, yb, yspec, &x0t, &de0, msdiff, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- /* Should we validate file if read from disk?
- * No, argument against: we may want to have a semantically wrong file and wish to edit?
- */
- de0.de_xml = x0t;
- if (de)
- de0.de_id = de->de_id;
- clicon_db_elmnt_set(h, db, &de0); /* Content is copied */
+ /* If there is no xml x0 tree (in cache), then read it from file */
+ /* xml looks like: ... where "x" is a top-level symbol in a module */
+ if ((ret = xmldb_readfile(h, db, yb, yspec, &x0t, &de0, msdiff, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ /* Should we validate file if read from disk?
+ * No, argument against: we may want to have a semantically wrong file and wish to edit?
+ */
+ de0.de_xml = x0t;
+ if (de)
+ de0.de_id = de->de_id;
+ clicon_db_elmnt_set(h, db, &de0); /* Content is copied */
} /* x0t == NULL */
else
- x0t = de->de_xml;
+ x0t = de->de_xml;
if (yb == YB_MODULE && !xml_spec(x0t)){
- if ((ret = xml_bind_yang(x0t, YB_MODULE, yspec, xerr)) < 0)
- goto done;
- if (ret == 0)
- ; /* XXX */
- else {
- /* Add default global values (to make xpath below include defaults) */
- if (xml_global_defaults(h, x0t, nsc, xpath, yspec, 0) < 0)
- goto done;
- /* Add default recursive values */
- if (xml_default_recurse(x0t, 0) < 0)
- goto done;
- }
+ if ((ret = xml_bind_yang(x0t, YB_MODULE, yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ ; /* XXX */
+ else {
+ /* Add default global values (to make xpath below include defaults) */
+ if (xml_global_defaults(h, x0t, nsc, xpath, yspec, 0) < 0)
+ goto done;
+ /* Add default recursive values */
+ if (xml_default_recurse(x0t, 0) < 0)
+ goto done;
+ }
}
/* Here x0t looks like: ... */
/* Given the xpath, return a vector of matches in xvec
@@ -853,71 +853,71 @@ xmldb_get_cache(clicon_handle h,
* b) if config dont dont state data
*/
if (xpath_vec(x0t, nsc, "%s", &xvec, &xlen, xpath?xpath:"/") < 0)
- goto done;
+ goto done;
/* Make new tree by copying top-of-tree from x0t to x1t */
if ((x1t = xml_new(xml_name(x0t), NULL, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
xml_flag_set(x1t, XML_FLAG_TOP);
xml_spec_set(x1t, xml_spec(x0t));
if (xlen < 1000){
- /* This is optimized for the case when the tree is large and xlen is small
- * If the tree is large and xlen too, then the other is better.
- * This only works if yang bind
- */
- for (i=0; i1)
- if (clixon_xml2file(stderr, x1t, 0, 1, fprintf, 0, 0) < 0)
- goto done;
+ if (clixon_xml2file(stderr, x1t, 0, 1, fprintf, 0, 0) < 0)
+ goto done;
*xtop = x1t;
retval = 1;
done:
clicon_debug(2, "%s retval:%d", __FUNCTION__, retval);
if (xvec)
- free(xvec);
+ free(xvec);
return retval;
fail:
retval = 0;
@@ -943,13 +943,13 @@ xmldb_get_cache(clicon_handle h,
*/
static int
xmldb_get_zerocopy(clicon_handle h,
- const char *db,
- yang_bind yb,
- cvec *nsc,
- const char *xpath,
- cxobj **xtop,
- modstate_diff_t *msdiff,
- cxobj **xerr)
+ const char *db,
+ yang_bind yb,
+ cvec *nsc,
+ const char *xpath,
+ cxobj **xtop,
+ modstate_diff_t *msdiff,
+ cxobj **xerr)
{
int retval = -1;
@@ -964,62 +964,62 @@ xmldb_get_zerocopy(clicon_handle h,
int ret;
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No yang spec");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "No yang spec");
+ goto done;
}
de = clicon_db_elmnt_get(h, db);
if (de == NULL || de->de_xml == NULL){ /* Cache miss, read XML from file */
- /* If there is no xml x0 tree (in cache), then read it from file */
- /* xml looks like: ... where "x" is a top-level symbol in a module */
- if ((ret = xmldb_readfile(h, db, yb, yspec, &x0t, &de0, msdiff, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- /* Should we validate file if read from disk?
- * No, argument against: we may want to have a semantically wrong file and wish to edit?
- */
- de0.de_xml = x0t;
- if (de)
- de0.de_id = de->de_id;
- clicon_db_elmnt_set(h, db, &de0);
+ /* If there is no xml x0 tree (in cache), then read it from file */
+ /* xml looks like: ... where "x" is a top-level symbol in a module */
+ if ((ret = xmldb_readfile(h, db, yb, yspec, &x0t, &de0, msdiff, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ /* Should we validate file if read from disk?
+ * No, argument against: we may want to have a semantically wrong file and wish to edit?
+ */
+ de0.de_xml = x0t;
+ if (de)
+ de0.de_id = de->de_id;
+ clicon_db_elmnt_set(h, db, &de0);
} /* x0t == NULL */
else
- x0t = de->de_xml;
+ x0t = de->de_xml;
/* Here xt looks like: ... */
if (xpath_vec(x0t, nsc, "%s", &xvec, &xlen, xpath?xpath:"/") < 0)
- goto done;
+ goto done;
/* Iterate through the match vector
* For every node found in x0, mark the tree up to t1
*/
for (i=0; i 1)
- if (clixon_xml2file(stderr, x0t, 0, 1, fprintf, 0, 0) < 0)
- goto done;
+ if (clixon_xml2file(stderr, x0t, 0, 1, fprintf, 0, 0) < 0)
+ goto done;
*xtop = x0t;
retval = 1;
done:
clicon_debug(2, "%s retval:%d", __FUNCTION__, retval);
if (xvec)
- free(xvec);
+ free(xvec);
return retval;
fail:
retval = 0;
@@ -1045,10 +1045,10 @@ xmldb_get_zerocopy(clicon_handle h,
*/
int
xmldb_get(clicon_handle h,
- const char *db,
- cvec *nsc,
- char *xpath,
- cxobj **xret)
+ const char *db,
+ cvec *nsc,
+ char *xpath,
+ cxobj **xret)
{
return xmldb_get0(h, db, YB_MODULE, nsc, xpath, 1, xret, NULL, NULL);
}
@@ -1105,42 +1105,42 @@ xmldb_get(clicon_handle h,
*/
int
xmldb_get0(clicon_handle h,
- const char *db,
- yang_bind yb,
- cvec *nsc,
- const char *xpath,
- int copy,
- cxobj **xret,
- modstate_diff_t *msdiff,
- cxobj **xerr)
+ const char *db,
+ yang_bind yb,
+ cvec *nsc,
+ const char *xpath,
+ int copy,
+ cxobj **xret,
+ modstate_diff_t *msdiff,
+ cxobj **xerr)
{
int retval = -1;
switch (clicon_datastore_cache(h)){
case DATASTORE_NOCACHE:
- /* Read from file into created/copy tree, prune non-matching xpath
- * Add default values in copy
- * Copy deleted by xmldb_free
- */
- retval = xmldb_get_nocache(h, db, yb, nsc, xpath, xret, msdiff, xerr);
- break;
+ /* Read from file into created/copy tree, prune non-matching xpath
+ * Add default values in copy
+ * Copy deleted by xmldb_free
+ */
+ retval = xmldb_get_nocache(h, db, yb, nsc, xpath, xret, msdiff, xerr);
+ break;
case DATASTORE_CACHE_ZEROCOPY:
- /* Get cache (file if empty) mark xpath match in original tree
- * add default values in original tree and return that.
- * Default values and markings removed in xmldb_clear
- */
- if (!copy){
- retval = xmldb_get_zerocopy(h, db, yb, nsc, xpath, xret, msdiff, xerr);
- break;
- }
- /* fall through */
+ /* Get cache (file if empty) mark xpath match in original tree
+ * add default values in original tree and return that.
+ * Default values and markings removed in xmldb_clear
+ */
+ if (!copy){
+ retval = xmldb_get_zerocopy(h, db, yb, nsc, xpath, xret, msdiff, xerr);
+ break;
+ }
+ /* fall through */
case DATASTORE_CACHE:
- /* Get cache (file if empty) mark xpath match and copy marked into copy
- * Add default values in copy, return copy
- * Copy deleted by xmldb_free
- */
- retval = xmldb_get_cache(h, db, yb, nsc, xpath, xret, msdiff, xerr);
- break;
+ /* Get cache (file if empty) mark xpath match and copy marked into copy
+ * Add default values in copy, return copy
+ * Copy deleted by xmldb_free
+ */
+ retval = xmldb_get_cache(h, db, yb, nsc, xpath, xret, msdiff, xerr);
+ break;
}
return retval;
}
@@ -1156,21 +1156,21 @@ xmldb_get0(clicon_handle h,
*/
int
xmldb_get0_clear(clicon_handle h,
- cxobj *x)
+ cxobj *x)
{
int retval = -1;
if (x == NULL)
- goto ok;
+ goto ok;
/* Remove global defaults and empty non-presence containers */
if (xml_defaults_nopresence(x, 2) < 0)
- goto done;
+ goto done;
/* Clear XML tree of defaults */
if (xml_tree_prune_flagged(x, XML_FLAG_TRANSIENT, 1) < 0)
- goto done;
+ goto done;
/* clear mark and change */
xml_apply0(x, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset,
- (void*)(XML_FLAG_MARK|XML_FLAG_ADD|XML_FLAG_CHANGE));
+ (void*)(XML_FLAG_MARK|XML_FLAG_ADD|XML_FLAG_CHANGE));
ok:
retval = 0;
done:
@@ -1185,14 +1185,14 @@ xmldb_get0_clear(clicon_handle h,
*/
int
xmldb_get0_free(clicon_handle h,
- cxobj **xp)
+ cxobj **xp)
{
if (*xp == NULL)
- return 0;
+ return 0;
/* Note that if clicon_datastore_cache(h) fails (returns -1), the following
* xml_free can fail (if **xp not obtained using xmldb_get0) */
if (clicon_datastore_cache(h) != DATASTORE_CACHE_ZEROCOPY)
- xml_free(*xp);
+ xml_free(*xp);
*xp = NULL;
return 0;
}
diff --git a/lib/src/clixon_datastore_read.h b/lib/src/clixon_datastore_read.h
index 1c962dd9..ea3c948a 100644
--- a/lib/src/clixon_datastore_read.h
+++ b/lib/src/clixon_datastore_read.h
@@ -42,6 +42,6 @@
* Prototypes
*/
int xmldb_readfile(clicon_handle h, const char *db, yang_bind yb, yang_stmt *yspec,
- cxobj **xp, db_elmnt *de, modstate_diff_t *msd, cxobj **xerr);
+ cxobj **xp, db_elmnt *de, modstate_diff_t *msd, cxobj **xerr);
#endif /* _CLIXON_DATASTORE_READ_H */
diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c
index 760bab19..d4b9d40b 100644
--- a/lib/src/clixon_datastore_write.c
+++ b/lib/src/clixon_datastore_write.c
@@ -90,7 +90,7 @@
* If such an attribute its found, its string value is returned.
* @param[in] x XML node (where to look for attribute)
* @param[in] name Attribute name
- * @param[in] ns (Expected)Namespace of attribute
+ * @param[in] ns (Expected)Namespace of attribute
* @param[out] cbret Error message (if retval=0)
* @param[out] valp Pointer to value (if retval=1)
* @retval -1 Error
@@ -99,10 +99,10 @@
*/
static int
attr_ns_value(cxobj *x,
- char *name,
- char *ns,
- cbuf *cbret,
- char **valp)
+ char *name,
+ char *ns,
+ cbuf *cbret,
+ char **valp)
{
int retval = -1;
cxobj *xa;
@@ -111,17 +111,17 @@ attr_ns_value(cxobj *x,
/* prefix=NULL since we do not know the prefix */
if ((xa = xml_find_type(x, NULL, name, CX_ATTR)) != NULL){
- if (xml2ns(xa, xml_prefix(xa), &ans) < 0)
- goto done;
- if (ans == NULL){ /* the attribute exists, but no namespace */
- if (netconf_bad_attribute(cbret, "application", name, "Unresolved attribute prefix (no namespace?)") < 0)
- goto done;
- goto fail;
- }
- /* the attribute exists, but not w expected namespace */
- if (ns == NULL ||
- strcmp(ans, ns) == 0)
- val = xml_value(xa);
+ if (xml2ns(xa, xml_prefix(xa), &ans) < 0)
+ goto done;
+ if (ans == NULL){ /* the attribute exists, but no namespace */
+ if (netconf_bad_attribute(cbret, "application", name, "Unresolved attribute prefix (no namespace?)") < 0)
+ goto done;
+ goto fail;
+ }
+ /* the attribute exists, but not w expected namespace */
+ if (ns == NULL ||
+ strcmp(ans, ns) == 0)
+ val = xml_value(xa);
}
*valp = val;
retval = 1;
@@ -149,11 +149,11 @@ attr_ns_value(cxobj *x,
*/
static int
check_body_namespace(cxobj *x0,
- cxobj *x0p,
- cxobj *x1,
- char *x1bstr,
- yang_stmt *y,
- cbuf *cbret)
+ cxobj *x0p,
+ cxobj *x1,
+ char *x1bstr,
+ yang_stmt *y,
+ cbuf *cbret)
{
int retval = -1;
char *prefix = NULL;
@@ -167,53 +167,53 @@ check_body_namespace(cxobj *x0,
/* XXX: need to identify root better than hiereustics and strcmp,... */
isroot = xml_parent(x0p)==NULL &&
- strcmp(xml_name(x0p), DATASTORE_TOP_SYMBOL) == 0 &&
- xml_prefix(x0p)==NULL;
+ strcmp(xml_name(x0p), DATASTORE_TOP_SYMBOL) == 0 &&
+ xml_prefix(x0p)==NULL;
if (nodeid_split(x1bstr, &prefix, NULL) < 0)
- goto done;
+ goto done;
if (prefix == NULL)
- goto ok; /* skip */
+ goto ok; /* skip */
if (xml2ns(x1, prefix, &ns0) < 0)
- goto done;
+ goto done;
if (xml2ns(x0, prefix, &ns1) < 0)
- goto done;
+ goto done;
if (ns0 != NULL && ns1 != NULL){ /* namespace exists in both x1 and x0 */
- if (strcmp(ns0, ns1)){
- /* prefixes in x1 and x0 refers to different namespaces
- * XXX return netconf error instead
+ if (strcmp(ns0, ns1)){
+ /* prefixes in x1 and x0 refers to different namespaces
+ * XXX return netconf error instead
bad-attribue?
- */
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cberr, "identityref: \"%s\": namespace collision %s vs %s", x1bstr, ns0, ns1);
- if (netconf_invalid_value(cbret, "application", cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
- }
+ */
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cberr, "identityref: \"%s\": namespace collision %s vs %s", x1bstr, ns0, ns1);
+ if (netconf_invalid_value(cbret, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
}
else if (ns0 != NULL && ns1 == NULL){ /* namespace exists in x0 but not in x1: add it to x1*/
- if (isroot)
- x = x0;
- else
- x = x0p;
- if (nscache_set(x, prefix, ns0) < 0)
- goto done;
- /* Create xmlns attribute to x0 XXX same code ^*/
- if (prefix){
- if ((xa = xml_new(prefix, x, CX_ATTR)) == NULL)
- goto done;
- if (xml_prefix_set(xa, "xmlns") < 0)
- goto done;
- }
- else{
- if ((xa = xml_new("xmlns", x, CX_ATTR)) == NULL)
- goto done;
- }
- if (xml_value_set(xa, ns0) < 0)
- goto done;
- xml_sort(x); /* Ensure attr is first / XXX xml_insert? */
+ if (isroot)
+ x = x0;
+ else
+ x = x0p;
+ if (nscache_set(x, prefix, ns0) < 0)
+ goto done;
+ /* Create xmlns attribute to x0 XXX same code ^*/
+ if (prefix){
+ if ((xa = xml_new(prefix, x, CX_ATTR)) == NULL)
+ goto done;
+ if (xml_prefix_set(xa, "xmlns") < 0)
+ goto done;
+ }
+ else{
+ if ((xa = xml_new("xmlns", x, CX_ATTR)) == NULL)
+ goto done;
+ }
+ if (xml_value_set(xa, ns0) < 0)
+ goto done;
+ xml_sort(x); /* Ensure attr is first / XXX xml_insert? */
}
#if 0
else if (ns0 == NULL && ns1 != NULL){ /* namespace exists in x1 but not in x0: OK (but request is realy invalid */
@@ -221,39 +221,39 @@ bad-attribue?
#endif
else{ /* Namespace does not exist in x0: error */
#ifdef IDENTITYREF_KLUDGE
- if (ns1 == NULL){
- if ((ret = yang_find_namespace_by_prefix(y, prefix, &ns0)) < 0)
- goto done;
- if (ret == 0){ /* no such namespace in yang */
- ;
- }
- else{ /* Add it according to the kludge,... */
- if ((xa = xml_new(prefix, x0, CX_ATTR)) == NULL)
- goto done;
- if (xml_prefix_set(xa, "xmlns") < 0)
- goto done;
- if (xml_value_set(xa, ns0) < 0)
- goto done;
- }
- }
+ if (ns1 == NULL){
+ if ((ret = yang_find_namespace_by_prefix(y, prefix, &ns0)) < 0)
+ goto done;
+ if (ret == 0){ /* no such namespace in yang */
+ ;
+ }
+ else{ /* Add it according to the kludge,... */
+ if ((xa = xml_new(prefix, x0, CX_ATTR)) == NULL)
+ goto done;
+ if (xml_prefix_set(xa, "xmlns") < 0)
+ goto done;
+ if (xml_value_set(xa, ns0) < 0)
+ goto done;
+ }
+ }
#else
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cberr, "identityref: \"%s\": prefix \"%s\" has no associated namespace", x1bstr, prefix);
- if (netconf_invalid_value(cbret, "application", cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cberr, "identityref: \"%s\": prefix \"%s\" has no associated namespace", x1bstr, prefix);
+ if (netconf_invalid_value(cbret, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
#endif
}
ok:
retval = 1;
done:
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
if (prefix)
- free(prefix);
+ free(prefix);
return retval;
fail:
retval = 0;
@@ -281,9 +281,9 @@ bad-attribue?
*/
static int
check_when_condition(cxobj *x0p,
- cxobj *x1,
- yang_stmt *y0,
- cbuf *cbret)
+ cxobj *x1,
+ yang_stmt *y0,
+ cbuf *cbret)
{
int retval = -1;
char *xpath = NULL;
@@ -294,37 +294,37 @@ check_when_condition(cxobj *x0p,
cxobj *x1p;
if ((y = y0) != NULL ||
- (y = (yang_stmt*)xml_spec(x1)) != NULL){
- if ((xpath = yang_when_xpath_get(y)) != NULL){
- nsc = yang_when_nsc_get(y);
- x1p = xml_parent(x1);
- if ((nr = xpath_vec_bool(x1p, nsc, "%s", xpath)) < 0) /* Try request */
- goto done;
- if (nr == 0){
- /* Try existing tree */
- if ((nr = xpath_vec_bool(x0p, nsc, "%s", xpath)) < 0)
- goto done;
- if (nr == 0){
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cberr, "Node '%s' tagged with 'when' condition '%s' in module '%s' evaluates to false in edit-config operation (see RFC 7950 Sec 8.3.2)",
- yang_argument_get(y),
- xpath,
- yang_argument_get(ys_module(y)));
- if (netconf_unknown_element(cbret, "application", yang_argument_get(y),
- cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
- }
- }
- }
+ (y = (yang_stmt*)xml_spec(x1)) != NULL){
+ if ((xpath = yang_when_xpath_get(y)) != NULL){
+ nsc = yang_when_nsc_get(y);
+ x1p = xml_parent(x1);
+ if ((nr = xpath_vec_bool(x1p, nsc, "%s", xpath)) < 0) /* Try request */
+ goto done;
+ if (nr == 0){
+ /* Try existing tree */
+ if ((nr = xpath_vec_bool(x0p, nsc, "%s", xpath)) < 0)
+ goto done;
+ if (nr == 0){
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cberr, "Node '%s' tagged with 'when' condition '%s' in module '%s' evaluates to false in edit-config operation (see RFC 7950 Sec 8.3.2)",
+ yang_argument_get(y),
+ xpath,
+ yang_argument_get(ys_module(y)));
+ if (netconf_unknown_element(cbret, "application", yang_argument_get(y),
+ cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ }
}
retval = 1;
done:
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
return retval;
fail:
retval = 0;
@@ -335,22 +335,22 @@ check_when_condition(cxobj *x0p,
*/
static int
choice_case_get(yang_stmt *yc,
- yang_stmt **ycase,
- yang_stmt **ychoice)
+ yang_stmt **ycase,
+ yang_stmt **ychoice)
{
yang_stmt *yp;
if ((yp = yang_parent_get(yc)) == NULL)
- return 0;
+ return 0;
if (yang_keyword_get(yp) == Y_CASE){
- *ycase = yp;
- *ychoice = yang_parent_get(yp);
- return 1;
+ *ycase = yp;
+ *ychoice = yang_parent_get(yp);
+ return 1;
}
else if (yang_keyword_get(yp) == Y_CHOICE){
- *ycase = NULL;
- *ychoice = yp;
- return 1;
+ *ycase = NULL;
+ *ychoice = yp;
+ return 1;
}
return 0;
}
@@ -361,34 +361,34 @@ choice_case_get(yang_stmt *yc,
*/
static int
choice_is_other(yang_stmt *y0c,
- yang_stmt *y0case,
- yang_stmt *y0choice,
- yang_stmt *y1c,
- yang_stmt *y1case,
- yang_stmt *y1choice)
+ yang_stmt *y0case,
+ yang_stmt *y0choice,
+ yang_stmt *y1c,
+ yang_stmt *y1case,
+ yang_stmt *y1choice)
{
yang_stmt *ycase;
yang_stmt *ychoice;
if (y0choice == y1choice){
- if ((y0case == NULL && y0c != y1c) ||
- y0case != y1case){
- return 1;
- }
+ if ((y0case == NULL && y0c != y1c) ||
+ y0case != y1case){
+ return 1;
+ }
}
else {
- /* First recurse y0 */
- if (choice_case_get(y0choice, &ycase, &ychoice)){
- if (choice_is_other(y0choice, ycase, ychoice,
- y1c, y1case, y1choice) == 1)
- return 1;
- }
- /* Second recurse y1 */
- if (choice_case_get(y1choice, &ycase, &ychoice)){
- if (choice_is_other(y0choice, y0case, y0choice,
- y1choice, ycase, ychoice) == 1)
- return 1;
- }
+ /* First recurse y0 */
+ if (choice_case_get(y0choice, &ycase, &ychoice)){
+ if (choice_is_other(y0choice, ycase, ychoice,
+ y1c, y1case, y1choice) == 1)
+ return 1;
+ }
+ /* Second recurse y1 */
+ if (choice_case_get(y1choice, &ycase, &ychoice)){
+ if (choice_is_other(y0choice, y0case, y0choice,
+ y1choice, ycase, ychoice) == 1)
+ return 1;
+ }
}
return 0;
}
@@ -412,7 +412,7 @@ choice_is_other(yang_stmt *y0c,
*/
static int
choice_delete_other(cxobj *x0,
- yang_stmt *y1c)
+ yang_stmt *y1c)
{
int retval = -1;
cxobj *x0c;
@@ -424,27 +424,27 @@ choice_delete_other(cxobj *x0,
yang_stmt *y1choice = NULL;
if (choice_case_get(y1c, &y1case, &y1choice) == 0)
- goto ok;
+ goto ok;
x0prev = NULL;
x0c = NULL;
while ((x0c = xml_child_each(x0, x0c, CX_ELMNT)) != NULL) {
- if ((y0c = xml_spec(x0c)) == NULL ||
- yang_parent_get(y0c) == NULL){
- x0prev = x0c;
- continue;
- }
- if (choice_case_get(y0c, &y0case, &y0choice) == 0){
- x0prev = x0c;
- continue;
- }
- /* Check if x0/y0 is part of other choice/case than y1 recursively , if so purge */
- if (choice_is_other(y0c, y0case, y0choice, y1c, y1case, y1choice) == 1){
- if (xml_purge(x0c) < 0)
- goto done;
- x0c = x0prev;
- continue;
- }
- x0prev = x0c;
+ if ((y0c = xml_spec(x0c)) == NULL ||
+ yang_parent_get(y0c) == NULL){
+ x0prev = x0c;
+ continue;
+ }
+ if (choice_case_get(y0c, &y0case, &y0choice) == 0){
+ x0prev = x0c;
+ continue;
+ }
+ /* Check if x0/y0 is part of other choice/case than y1 recursively , if so purge */
+ if (choice_is_other(y0c, y0case, y0choice, y1c, y1case, y1choice) == 1){
+ if (xml_purge(x0c) < 0)
+ goto done;
+ x0c = x0prev;
+ continue;
+ }
+ x0prev = x0c;
}
ok:
retval = 0;
@@ -477,17 +477,17 @@ choice_delete_other(cxobj *x0,
*/
static int
text_modify(clicon_handle h,
- cxobj *x0,
- cxobj *x0p,
- cxobj *x0t,
- cxobj *x1,
- cxobj *x1t,
- yang_stmt *y0,
- enum operation_type op,
- char *username,
- cxobj *xnacm,
- int permit,
- cbuf *cbret)
+ cxobj *x0,
+ cxobj *x0p,
+ cxobj *x0t,
+ cxobj *x1,
+ cxobj *x1t,
+ yang_stmt *y0,
+ enum operation_type op,
+ char *username,
+ cxobj *xnacm,
+ int permit,
+ cbuf *cbret)
{
int retval = -1;
char *opstr = NULL;
@@ -508,468 +508,468 @@ text_modify(clicon_handle h,
enum insert_type insert = INS_LAST;
int changed = 0; /* Only if x0p's children have changed-> sort necessary */
cvec *nscx1 = NULL;
- char *createstr = NULL;
+ char *createstr = NULL;
yang_stmt *yrestype = NULL;
char *restype;
if (x1 == NULL){
- clicon_err(OE_XML, EINVAL, "x1 is missing");
- goto done;
+ clicon_err(OE_XML, EINVAL, "x1 is missing");
+ goto done;
}
if ((ret = check_when_condition(x0p, x1, y0, cbret)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* Check for operations embedded in tree according to netconf */
if ((ret = attr_ns_value(x1, "operation", NETCONF_BASE_NAMESPACE,
- cbret, &opstr)) < 0)
- goto done;
+ cbret, &opstr)) < 0)
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
if (opstr != NULL)
- if (xml_operation(opstr, &op) < 0)
- goto done;
+ if (xml_operation(opstr, &op) < 0)
+ goto done;
if ((ret = attr_ns_value(x1, "objectcreate", NULL, cbret, &createstr)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
if (createstr != NULL &&
- (op == OP_REPLACE || op == OP_MERGE || op == OP_CREATE)){
- if (x0 == NULL || xml_defaults_nopresence(x0, 0)){ /* does not exist or is default */
- if (strcmp(createstr, "false")==0){
- /* RFC 8040 4.6 PATCH:
- * If the target resource instance does not exist, the server MUST NOT create it.
- */
- if (netconf_data_missing(cbret,
- "RFC 8040 4.6. PATCH: If the target resource instance does not exist, the server MUST NOT create it") < 0)
- goto done;
- goto fail;
- }
- clicon_data_set(h, "objectexisted", "false");
- }
- else{ /* exists */
- clicon_data_set(h, "objectexisted", "true");
- }
+ (op == OP_REPLACE || op == OP_MERGE || op == OP_CREATE)){
+ if (x0 == NULL || xml_defaults_nopresence(x0, 0)){ /* does not exist or is default */
+ if (strcmp(createstr, "false")==0){
+ /* RFC 8040 4.6 PATCH:
+ * If the target resource instance does not exist, the server MUST NOT create it.
+ */
+ if (netconf_data_missing(cbret,
+ "RFC 8040 4.6. PATCH: If the target resource instance does not exist, the server MUST NOT create it") < 0)
+ goto done;
+ goto fail;
+ }
+ clicon_data_set(h, "objectexisted", "false");
+ }
+ else{ /* exists */
+ clicon_data_set(h, "objectexisted", "true");
+ }
}
x1name = xml_name(x1);
if (yang_keyword_get(y0) == Y_LEAF_LIST ||
- yang_keyword_get(y0) == Y_LEAF){
- /* This is a check that a leaf does not have sub-elements
- * such as: a b
- */
- if (xml_child_nr_type(x1, CX_ELMNT)){
- if (netconf_unknown_element(cbret, "application", x1name, "Leaf contains sub-element") < 0)
- goto done;
- goto fail;
- }
- /* If leaf-list and ordered-by user, then get yang:insert attribute
- * See RFC 7950 Sec 7.7.9
- */
- if (yang_keyword_get(y0) == Y_LEAF_LIST &&
- yang_find(y0, Y_ORDERED_BY, "user") != NULL){
- if ((ret = attr_ns_value(x1,
- "insert", YANG_XML_NAMESPACE,
- cbret, &instr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- if (instr != NULL &&
- xml_attr_insert2val(instr, &insert) < 0)
- goto done;
- if ((ret = attr_ns_value(x1,
- "value", YANG_XML_NAMESPACE,
- cbret, &valstr)) < 0)
- goto done;
- /* if insert/before, value attribute must be there */
- if ((insert == INS_AFTER || insert == INS_BEFORE) &&
- valstr == NULL){
- if (netconf_missing_attribute(cbret, "application", "value ", "Missing value attribute when insert is before or after") < 0)
- goto done;
- goto fail;
- }
- }
- x1bstr = xml_body(x1);
- switch(op){
- case OP_CREATE:
- if (x0){
- if (netconf_data_exists(cbret, "Data already exists; cannot create new resource") < 0)
- goto done;
- goto fail;
- }
- case OP_REPLACE: /* fall thru */
- case OP_MERGE:
- if (!(op == OP_MERGE && instr==NULL)){
- /* Remove existing, also applies to merge in the special case
- * of ordered-by user and (changed) insert attribute.
- */
- if (!permit && xnacm){
- if ((ret = nacm_datanode_write(h, x1, x1t, x0?NACM_UPDATE:NACM_CREATE, username, xnacm, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- permit = 1;
- }
- /* XXX: Note, if there is an error in adding the object later, the
- * original object is not reverted.
- */
- if (x0){
- xml_purge(x0);
- x0 = NULL;
- }
- } /* OP_MERGE & insert */
- case OP_NONE: /* fall thru */
- if (x0==NULL){
- if ((op != OP_NONE) && !permit && xnacm){
- if ((ret = nacm_datanode_write(h, x1, x1t, NACM_CREATE, username, xnacm, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- permit = 1;
- }
- /* Add new xml node but without parent - insert when node fully
- copied (see changed conditional below) */
- if ((x0 = xml_new(x1name, NULL, CX_ELMNT)) == NULL)
- goto done;
- xml_spec_set(x0, y0);
+ yang_keyword_get(y0) == Y_LEAF){
+ /* This is a check that a leaf does not have sub-elements
+ * such as: a b
+ */
+ if (xml_child_nr_type(x1, CX_ELMNT)){
+ if (netconf_unknown_element(cbret, "application", x1name, "Leaf contains sub-element") < 0)
+ goto done;
+ goto fail;
+ }
+ /* If leaf-list and ordered-by user, then get yang:insert attribute
+ * See RFC 7950 Sec 7.7.9
+ */
+ if (yang_keyword_get(y0) == Y_LEAF_LIST &&
+ yang_find(y0, Y_ORDERED_BY, "user") != NULL){
+ if ((ret = attr_ns_value(x1,
+ "insert", YANG_XML_NAMESPACE,
+ cbret, &instr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ if (instr != NULL &&
+ xml_attr_insert2val(instr, &insert) < 0)
+ goto done;
+ if ((ret = attr_ns_value(x1,
+ "value", YANG_XML_NAMESPACE,
+ cbret, &valstr)) < 0)
+ goto done;
+ /* if insert/before, value attribute must be there */
+ if ((insert == INS_AFTER || insert == INS_BEFORE) &&
+ valstr == NULL){
+ if (netconf_missing_attribute(cbret, "application", "value ", "Missing value attribute when insert is before or after") < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ x1bstr = xml_body(x1);
+ switch(op){
+ case OP_CREATE:
+ if (x0){
+ if (netconf_data_exists(cbret, "Data already exists; cannot create new resource") < 0)
+ goto done;
+ goto fail;
+ }
+ case OP_REPLACE: /* fall thru */
+ case OP_MERGE:
+ if (!(op == OP_MERGE && instr==NULL)){
+ /* Remove existing, also applies to merge in the special case
+ * of ordered-by user and (changed) insert attribute.
+ */
+ if (!permit && xnacm){
+ if ((ret = nacm_datanode_write(h, x1, x1t, x0?NACM_UPDATE:NACM_CREATE, username, xnacm, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ permit = 1;
+ }
+ /* XXX: Note, if there is an error in adding the object later, the
+ * original object is not reverted.
+ */
+ if (x0){
+ xml_purge(x0);
+ x0 = NULL;
+ }
+ } /* OP_MERGE & insert */
+ case OP_NONE: /* fall thru */
+ if (x0==NULL){
+ if ((op != OP_NONE) && !permit && xnacm){
+ if ((ret = nacm_datanode_write(h, x1, x1t, NACM_CREATE, username, xnacm, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ permit = 1;
+ }
+ /* Add new xml node but without parent - insert when node fully
+ copied (see changed conditional below) */
+ if ((x0 = xml_new(x1name, NULL, CX_ELMNT)) == NULL)
+ goto done;
+ xml_spec_set(x0, y0);
- /* Get namespace from x1
- * Check if namespace exists in x0 parent
- * if not add new binding and replace in x0.
- * See also xmlns copying of attributes in the body section below
- * Note that this may add "unnecessary" namespace declarations
- */
- if (assign_namespace_element(x1, x0, x0p) < 0)
- goto done;
- changed++;
- if (op==OP_NONE)
- xml_flag_set(x0, XML_FLAG_NONE); /* Mark for potential deletion */
- if (x1bstr){ /* empty type does not have body */ /* XXX Here x0 = */
- if ((x0b = xml_new("body", x0, CX_BODY)) == NULL)
- goto done;
- }
- }
- /* Some bodies (eg identityref) requires proper namespace setup, so a type lookup is
- * necessary.
- */
- if (yang_type_get(y0, NULL, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0)
- goto done;
- if (yrestype == NULL){
- clicon_err(OE_CFG, EFAULT, "No restype (internal error)");
- goto done;
- }
- restype = yang_argument_get(yrestype);
- /* Differentiate between an empty type (NULL) and an empty string "" */
- if (x1bstr==NULL && strcmp(restype, "string")==0)
- x1bstr="";
- if (x1bstr){
- if (strcmp(restype, "identityref") == 0){
- x1bstr = clixon_trim2(x1bstr, " \t\n");
- if ((ret = check_body_namespace(x0, x0p, x1, x1bstr, y0, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- else{
- /* Some bodies strip pretty-printed here, unsure where to do this,.. */
- if (strcmp(restype, "enumeration") == 0 ||
- strcmp(restype, "bits") == 0)
- x1bstr = clixon_trim2(x1bstr, " \t\n");
- /* If origin body has namespace definitions, copy them. The reason is that
- * some bodies rely on namespace prefixes, such as NACM path, but there is
- * no way we can know this here.
- * However, this may lead to namespace collisions if these prefixes are not
- * canonical, and may collide with the assign_namespace_element() above (but that
- * is for element symbols)
- * Oh well.
- */
- if (assign_namespace_body(x1, x0) < 0)
- goto done;
- }
- /* XXX here x1bstr is checked for null, while adding an empty string above */
- if ((x0b = xml_body_get(x0)) == NULL && x1bstr && strlen(x1bstr)){
- if ((x0b = xml_new("body", x0, CX_BODY)) == NULL)
- goto done;
- }
- x0bstr = xml_value(x0b);
- if (x0bstr==NULL || strcmp(x0bstr, x1bstr)){
- if ((op != OP_NONE) && !permit && xnacm){
- if ((ret = nacm_datanode_write(h, x1, x1t,
- x0bstr==NULL?NACM_CREATE:NACM_UPDATE,
- username, xnacm, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- if (xml_value_set(x0b, x1bstr) < 0)
- goto done;
- /* If a default value ies replaced, then reset default flag */
- if (xml_flag(x0, XML_FLAG_DEFAULT))
- xml_flag_reset(x0, XML_FLAG_DEFAULT);
- }
- } /* x1bstr */
- if (changed){
- if (xml_insert(x0p, x0, insert, valstr, NULL) < 0)
- goto done;
- }
- break;
- case OP_DELETE:
- if (x0==NULL){
- if (netconf_data_missing(cbret, "Data does not exist; cannot delete resource") < 0)
- goto done;
- goto fail;
- }
- case OP_REMOVE: /* fall thru */
- if (x0){
- if ((op != OP_NONE) && !permit && xnacm){
- if ((ret = nacm_datanode_write(h, x0, x0t, NACM_DELETE, username, xnacm, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- x0bstr = xml_body(x0);
- /* Purge if x1 value is NULL(match-all) or both values are equal */
- if ((x1bstr == NULL) ||
- ((x0bstr=xml_body(x0)) != NULL && strcmp(x0bstr, x1bstr)==0)){
- if (xml_purge(x0) < 0)
- goto done;
- }
- else {
- if (op == OP_DELETE){
- if (netconf_data_missing(cbret, "Data does not exist; cannot delete resource") < 0)
- goto done;
- goto fail;
- }
- }
- }
- break;
- default:
- break;
- } /* switch op */
+ /* Get namespace from x1
+ * Check if namespace exists in x0 parent
+ * if not add new binding and replace in x0.
+ * See also xmlns copying of attributes in the body section below
+ * Note that this may add "unnecessary" namespace declarations
+ */
+ if (assign_namespace_element(x1, x0, x0p) < 0)
+ goto done;
+ changed++;
+ if (op==OP_NONE)
+ xml_flag_set(x0, XML_FLAG_NONE); /* Mark for potential deletion */
+ if (x1bstr){ /* empty type does not have body */ /* XXX Here x0 = */
+ if ((x0b = xml_new("body", x0, CX_BODY)) == NULL)
+ goto done;
+ }
+ }
+ /* Some bodies (eg identityref) requires proper namespace setup, so a type lookup is
+ * necessary.
+ */
+ if (yang_type_get(y0, NULL, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0)
+ goto done;
+ if (yrestype == NULL){
+ clicon_err(OE_CFG, EFAULT, "No restype (internal error)");
+ goto done;
+ }
+ restype = yang_argument_get(yrestype);
+ /* Differentiate between an empty type (NULL) and an empty string "" */
+ if (x1bstr==NULL && strcmp(restype, "string")==0)
+ x1bstr="";
+ if (x1bstr){
+ if (strcmp(restype, "identityref") == 0){
+ x1bstr = clixon_trim2(x1bstr, " \t\n");
+ if ((ret = check_body_namespace(x0, x0p, x1, x1bstr, y0, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ else{
+ /* Some bodies strip pretty-printed here, unsure where to do this,.. */
+ if (strcmp(restype, "enumeration") == 0 ||
+ strcmp(restype, "bits") == 0)
+ x1bstr = clixon_trim2(x1bstr, " \t\n");
+ /* If origin body has namespace definitions, copy them. The reason is that
+ * some bodies rely on namespace prefixes, such as NACM path, but there is
+ * no way we can know this here.
+ * However, this may lead to namespace collisions if these prefixes are not
+ * canonical, and may collide with the assign_namespace_element() above (but that
+ * is for element symbols)
+ * Oh well.
+ */
+ if (assign_namespace_body(x1, x0) < 0)
+ goto done;
+ }
+ /* XXX here x1bstr is checked for null, while adding an empty string above */
+ if ((x0b = xml_body_get(x0)) == NULL && x1bstr && strlen(x1bstr)){
+ if ((x0b = xml_new("body", x0, CX_BODY)) == NULL)
+ goto done;
+ }
+ x0bstr = xml_value(x0b);
+ if (x0bstr==NULL || strcmp(x0bstr, x1bstr)){
+ if ((op != OP_NONE) && !permit && xnacm){
+ if ((ret = nacm_datanode_write(h, x1, x1t,
+ x0bstr==NULL?NACM_CREATE:NACM_UPDATE,
+ username, xnacm, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ if (xml_value_set(x0b, x1bstr) < 0)
+ goto done;
+ /* If a default value ies replaced, then reset default flag */
+ if (xml_flag(x0, XML_FLAG_DEFAULT))
+ xml_flag_reset(x0, XML_FLAG_DEFAULT);
+ }
+ } /* x1bstr */
+ if (changed){
+ if (xml_insert(x0p, x0, insert, valstr, NULL) < 0)
+ goto done;
+ }
+ break;
+ case OP_DELETE:
+ if (x0==NULL){
+ if (netconf_data_missing(cbret, "Data does not exist; cannot delete resource") < 0)
+ goto done;
+ goto fail;
+ }
+ case OP_REMOVE: /* fall thru */
+ if (x0){
+ if ((op != OP_NONE) && !permit && xnacm){
+ if ((ret = nacm_datanode_write(h, x0, x0t, NACM_DELETE, username, xnacm, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ x0bstr = xml_body(x0);
+ /* Purge if x1 value is NULL(match-all) or both values are equal */
+ if ((x1bstr == NULL) ||
+ ((x0bstr=xml_body(x0)) != NULL && strcmp(x0bstr, x1bstr)==0)){
+ if (xml_purge(x0) < 0)
+ goto done;
+ }
+ else {
+ if (op == OP_DELETE){
+ if (netconf_data_missing(cbret, "Data does not exist; cannot delete resource") < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ } /* switch op */
} /* if LEAF|LEAF_LIST */
else { /* eg Y_CONTAINER, Y_LIST, Y_ANYXML */
- /* If list and ordered-by user, then get insert attribute
+ /* If list and ordered-by user, then get insert attribute
- * See RFC 7950 Sec 7.8.6
- */
- if (yang_keyword_get(y0) == Y_LIST &&
- yang_find(y0, Y_ORDERED_BY, "user") != NULL){
- if ((ret = attr_ns_value(x1,
- "insert", YANG_XML_NAMESPACE,
- cbret, &instr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- if (instr != NULL &&
- xml_attr_insert2val(instr, &insert) < 0)
- goto done;
- if ((ret = attr_ns_value(x1,
- "key", YANG_XML_NAMESPACE,
- cbret, &keystr)) < 0)
- goto done;
+ * See RFC 7950 Sec 7.8.6
+ */
+ if (yang_keyword_get(y0) == Y_LIST &&
+ yang_find(y0, Y_ORDERED_BY, "user") != NULL){
+ if ((ret = attr_ns_value(x1,
+ "insert", YANG_XML_NAMESPACE,
+ cbret, &instr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ if (instr != NULL &&
+ xml_attr_insert2val(instr, &insert) < 0)
+ goto done;
+ if ((ret = attr_ns_value(x1,
+ "key", YANG_XML_NAMESPACE,
+ cbret, &keystr)) < 0)
+ goto done;
- /* if insert/before, key attribute must be there */
- if ((insert == INS_AFTER || insert == INS_BEFORE) &&
- keystr == NULL){
- if (netconf_missing_attribute(cbret, "application", "key ", "Missing key attribute when insert is before or after") < 0)
- goto done;
- goto fail;
- }
- /* If keystr is set, need a full namespace context */
- if (keystr && xml_nsctx_node(x1, &nscx1) < 0)
- goto done;
- }
- switch(op){
- case OP_CREATE:
- if (x0){
- if (xml_defaults_nopresence(x0, 0) == 0){
- if (netconf_data_exists(cbret, "Data already exists; cannot create new resource") < 0)
- goto done;
- goto fail;
- }
- }
- case OP_REPLACE: /* fall thru */
- case OP_MERGE:
- if (!(op == OP_MERGE && instr==NULL)){
- /* Remove existing, also applies to merge in the special case
- * of ordered-by user and (changed) insert attribute.
- */
- if (!permit && xnacm){
- if ((ret = nacm_datanode_write(h, x1, x1t, x0?NACM_UPDATE:NACM_CREATE, username, xnacm, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- permit = 1;
- }
- /* XXX: Note, if there is an error in adding the object later, the
- * original object is not reverted.
- */
- if (x0){
- xml_purge(x0);
- x0 = NULL;
- }
- } /* OP_MERGE & insert */
- case OP_NONE: /* fall thru */
- /* Special case: anyxml, just replace tree,
- See rfc6020 7.10.3
- An anyxml node is treated as an opaque chunk of data. This data
- can be modified in its entirety only.
- Any "operation" attributes present on subelements of an anyxml
- node are ignored by the NETCONF server.*/
- if (yang_keyword_get(y0) == Y_ANYXML ||
- yang_keyword_get(y0) == Y_ANYDATA){
- if (op == OP_NONE)
- break;
- if (op==OP_MERGE && !permit && xnacm){
- if ((ret = nacm_datanode_write(h, x1, x1t, x0?NACM_UPDATE:NACM_CREATE, username, xnacm, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- permit = 1;
- }
- if (x0){
- xml_purge(x0);
- }
- if ((x0 = xml_new(x1name, x0p, CX_ELMNT)) == NULL)
- goto done;
- if (xml_copy(x1, x0) < 0)
- goto done;
- break;
- } /* anyxml, anydata */
- if (x0==NULL){
- if (op==OP_MERGE && !permit && xnacm){
- if ((ret = nacm_datanode_write(h, x1, x1t, NACM_CREATE, username, xnacm, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- permit = 1;
- }
- /* Add new xml node but without parent - insert when node fully
- * copied (see changed conditional below)
- * Note x0 may dangle cases if exit before changed conditional
- */
- if ((x0 = xml_new(x1name, NULL, CX_ELMNT)) == NULL)
- goto done;
- xml_spec_set(x0, y0);
+ /* if insert/before, key attribute must be there */
+ if ((insert == INS_AFTER || insert == INS_BEFORE) &&
+ keystr == NULL){
+ if (netconf_missing_attribute(cbret, "application", "key ", "Missing key attribute when insert is before or after") < 0)
+ goto done;
+ goto fail;
+ }
+ /* If keystr is set, need a full namespace context */
+ if (keystr && xml_nsctx_node(x1, &nscx1) < 0)
+ goto done;
+ }
+ switch(op){
+ case OP_CREATE:
+ if (x0){
+ if (xml_defaults_nopresence(x0, 0) == 0){
+ if (netconf_data_exists(cbret, "Data already exists; cannot create new resource") < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ case OP_REPLACE: /* fall thru */
+ case OP_MERGE:
+ if (!(op == OP_MERGE && instr==NULL)){
+ /* Remove existing, also applies to merge in the special case
+ * of ordered-by user and (changed) insert attribute.
+ */
+ if (!permit && xnacm){
+ if ((ret = nacm_datanode_write(h, x1, x1t, x0?NACM_UPDATE:NACM_CREATE, username, xnacm, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ permit = 1;
+ }
+ /* XXX: Note, if there is an error in adding the object later, the
+ * original object is not reverted.
+ */
+ if (x0){
+ xml_purge(x0);
+ x0 = NULL;
+ }
+ } /* OP_MERGE & insert */
+ case OP_NONE: /* fall thru */
+ /* Special case: anyxml, just replace tree,
+ See rfc6020 7.10.3
+ An anyxml node is treated as an opaque chunk of data. This data
+ can be modified in its entirety only.
+ Any "operation" attributes present on subelements of an anyxml
+ node are ignored by the NETCONF server.*/
+ if (yang_keyword_get(y0) == Y_ANYXML ||
+ yang_keyword_get(y0) == Y_ANYDATA){
+ if (op == OP_NONE)
+ break;
+ if (op==OP_MERGE && !permit && xnacm){
+ if ((ret = nacm_datanode_write(h, x1, x1t, x0?NACM_UPDATE:NACM_CREATE, username, xnacm, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ permit = 1;
+ }
+ if (x0){
+ xml_purge(x0);
+ }
+ if ((x0 = xml_new(x1name, x0p, CX_ELMNT)) == NULL)
+ goto done;
+ if (xml_copy(x1, x0) < 0)
+ goto done;
+ break;
+ } /* anyxml, anydata */
+ if (x0==NULL){
+ if (op==OP_MERGE && !permit && xnacm){
+ if ((ret = nacm_datanode_write(h, x1, x1t, NACM_CREATE, username, xnacm, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ permit = 1;
+ }
+ /* Add new xml node but without parent - insert when node fully
+ * copied (see changed conditional below)
+ * Note x0 may dangle cases if exit before changed conditional
+ */
+ if ((x0 = xml_new(x1name, NULL, CX_ELMNT)) == NULL)
+ goto done;
+ xml_spec_set(x0, y0);
#ifdef XML_PARENT_CANDIDATE
- xml_parent_candidate_set(x0, x0p);
+ xml_parent_candidate_set(x0, x0p);
#endif
- changed++;
- /* Get namespace from x1
- * Check if namespace exists in x0 parent
- * if not add new binding and replace in x0.
- */
- if (assign_namespace_element(x1, x0, x0p) < 0)
- goto done;
- if (op==OP_NONE)
- xml_flag_set(x0, XML_FLAG_NONE); /* Mark for potential deletion */
- }
- /* First pass: Loop through children of the x1 modification tree
- * collect matching nodes from x0 in x0vec (no changes to x0 children)
- */
- if ((x0vec = calloc(xml_child_nr_type(x1, CX_ELMNT), sizeof(x1))) == NULL){
- clicon_err(OE_UNIX, errno, "calloc");
- goto done;
- }
- x1c = NULL;
- i = 0;
- while ((x1c = xml_child_each(x1, x1c, CX_ELMNT)) != NULL) {
- x1cname = xml_name(x1c);
- /* Get yang spec of the child by child matching */
- yc = yang_find_datanode(y0, x1cname);
- if (yc == NULL){
- if (clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1){
- /* Add dummy Y_ANYDATA yang stmt, see ysp_add */
- if ((yc = yang_anydata_add(y0, x1cname)) < 0)
- goto done;
- xml_spec_set(x1c, yc);
- clicon_log(LOG_WARNING,
- "%s: %d: No YANG spec for %s, anydata used",
- __FUNCTION__, __LINE__, x1cname);
- }
- else{
- if (netconf_unknown_element(cbret, "application", x1cname, "Unassigned yang spec") < 0)
- goto done;
- goto fail;
- }
- }
- /* There is a cornercase (eg augment) of multi-namespace trees where
- * the yang child has a different namespace.
- * As an alternative, return in populate where this is detected first time.
- */
- if (yc != xml_spec(x1c)){
- clicon_err(OE_YANG, errno, "XML node %s not in namespace %s",
- x1cname, yang_find_mynamespace(y0));
- goto done;
- }
- /* Check if existing choice/case should be deleted */
- if (choice_delete_other(x0, yc) < 0)
- goto done;
- /* See if there is a corresponding node in the base tree */
- x0c = NULL;
- if (match_base_child(x0, x1c, yc, &x0c) < 0)
- goto done;
- x0vec[i++] = x0c; /* != NULL if x0c is matching x1c */
- }
- /* Second pass: Loop through children of the x1 modification tree again
- * Now potentially modify x0:s children
- * Here x0vec contains one-to-one matching nodes of x1:s children.
- */
- x1c = NULL;
- i = 0;
- while ((x1c = xml_child_each(x1, x1c, CX_ELMNT)) != NULL) {
- x0c = x0vec[i++];
- x1cname = xml_name(x1c);
- yc = yang_find_datanode(y0, x1cname);
- if ((ret = text_modify(h, x0c, x0, x0t, x1c, x1t,
- yc, op,
- username, xnacm, permit, cbret)) < 0)
- goto done;
- /* If xml return - ie netconf error xml tree, then stop and return OK */
- if (ret == 0)
- goto fail;
- }
- if (changed){
+ changed++;
+ /* Get namespace from x1
+ * Check if namespace exists in x0 parent
+ * if not add new binding and replace in x0.
+ */
+ if (assign_namespace_element(x1, x0, x0p) < 0)
+ goto done;
+ if (op==OP_NONE)
+ xml_flag_set(x0, XML_FLAG_NONE); /* Mark for potential deletion */
+ }
+ /* First pass: Loop through children of the x1 modification tree
+ * collect matching nodes from x0 in x0vec (no changes to x0 children)
+ */
+ if ((x0vec = calloc(xml_child_nr_type(x1, CX_ELMNT), sizeof(x1))) == NULL){
+ clicon_err(OE_UNIX, errno, "calloc");
+ goto done;
+ }
+ x1c = NULL;
+ i = 0;
+ while ((x1c = xml_child_each(x1, x1c, CX_ELMNT)) != NULL) {
+ x1cname = xml_name(x1c);
+ /* Get yang spec of the child by child matching */
+ yc = yang_find_datanode(y0, x1cname);
+ if (yc == NULL){
+ if (clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1){
+ /* Add dummy Y_ANYDATA yang stmt, see ysp_add */
+ if ((yc = yang_anydata_add(y0, x1cname)) < 0)
+ goto done;
+ xml_spec_set(x1c, yc);
+ clicon_log(LOG_WARNING,
+ "%s: %d: No YANG spec for %s, anydata used",
+ __FUNCTION__, __LINE__, x1cname);
+ }
+ else{
+ if (netconf_unknown_element(cbret, "application", x1cname, "Unassigned yang spec") < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ /* There is a cornercase (eg augment) of multi-namespace trees where
+ * the yang child has a different namespace.
+ * As an alternative, return in populate where this is detected first time.
+ */
+ if (yc != xml_spec(x1c)){
+ clicon_err(OE_YANG, errno, "XML node %s not in namespace %s",
+ x1cname, yang_find_mynamespace(y0));
+ goto done;
+ }
+ /* Check if existing choice/case should be deleted */
+ if (choice_delete_other(x0, yc) < 0)
+ goto done;
+ /* See if there is a corresponding node in the base tree */
+ x0c = NULL;
+ if (match_base_child(x0, x1c, yc, &x0c) < 0)
+ goto done;
+ x0vec[i++] = x0c; /* != NULL if x0c is matching x1c */
+ }
+ /* Second pass: Loop through children of the x1 modification tree again
+ * Now potentially modify x0:s children
+ * Here x0vec contains one-to-one matching nodes of x1:s children.
+ */
+ x1c = NULL;
+ i = 0;
+ while ((x1c = xml_child_each(x1, x1c, CX_ELMNT)) != NULL) {
+ x0c = x0vec[i++];
+ x1cname = xml_name(x1c);
+ yc = yang_find_datanode(y0, x1cname);
+ if ((ret = text_modify(h, x0c, x0, x0t, x1c, x1t,
+ yc, op,
+ username, xnacm, permit, cbret)) < 0)
+ goto done;
+ /* If xml return - ie netconf error xml tree, then stop and return OK */
+ if (ret == 0)
+ goto fail;
+ }
+ if (changed){
#ifdef XML_PARENT_CANDIDATE
- xml_parent_candidate_set(x0, NULL);
+ xml_parent_candidate_set(x0, NULL);
#endif
- if (xml_insert(x0p, x0, insert, keystr, nscx1) < 0)
- goto done;
- }
- break;
- case OP_DELETE:
- if (x0==NULL){
- if (netconf_data_missing(cbret, "Data does not exist; cannot delete resource") < 0)
- goto done;
- goto fail;
- }
- case OP_REMOVE: /* fall thru */
- if (x0){
- if (!permit && xnacm){
- if ((ret = nacm_datanode_write(h, x0, x0t, NACM_DELETE, username, xnacm, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- if (xml_purge(x0) < 0)
- goto done;
- }
- break;
- default:
- break;
- } /* CONTAINER switch op */
+ if (xml_insert(x0p, x0, insert, keystr, nscx1) < 0)
+ goto done;
+ }
+ break;
+ case OP_DELETE:
+ if (x0==NULL){
+ if (netconf_data_missing(cbret, "Data does not exist; cannot delete resource") < 0)
+ goto done;
+ goto fail;
+ }
+ case OP_REMOVE: /* fall thru */
+ if (x0){
+ if (!permit && xnacm){
+ if ((ret = nacm_datanode_write(h, x0, x0t, NACM_DELETE, username, xnacm, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ if (xml_purge(x0) < 0)
+ goto done;
+ }
+ break;
+ default:
+ break;
+ } /* CONTAINER switch op */
} /* else Y_CONTAINER */
retval = 1;
done:
if (nscx1)
- xml_nsctx_free(nscx1);
+ xml_nsctx_free(nscx1);
/* Remove dangling added objects */
if (changed && x0 && xml_parent(x0)==NULL)
- xml_purge(x0);
+ xml_purge(x0);
if (x0vec)
- free(x0vec);
+ free(x0vec);
return retval;
fail: /* cbret set */
retval = 0;
@@ -995,16 +995,16 @@ text_modify(clicon_handle h,
*/
static int
text_modify_top(clicon_handle h,
- cxobj *x0,
- cxobj *x0t,
- cxobj *x1,
- cxobj *x1t,
- yang_stmt *yspec,
- enum operation_type op,
- char *username,
- cxobj *xnacm,
- int permit,
- cbuf *cbret)
+ cxobj *x0,
+ cxobj *x0t,
+ cxobj *x1,
+ cxobj *x1t,
+ yang_stmt *yspec,
+ enum operation_type op,
+ char *username,
+ cxobj *xnacm,
+ int permit,
+ cbuf *cbret)
{
int retval = -1;
char *x1cname; /* child name */
@@ -1018,119 +1018,119 @@ text_modify_top(clicon_handle h,
/* Check for operations embedded in tree according to netconf */
if ((ret = attr_ns_value(x1,
- "operation", NETCONF_BASE_NAMESPACE,
- cbret, &opstr)) < 0)
- goto done;
+ "operation", NETCONF_BASE_NAMESPACE,
+ cbret, &opstr)) < 0)
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
if (opstr != NULL)
- if (xml_operation(opstr, &op) < 0)
- goto done;
+ if (xml_operation(opstr, &op) < 0)
+ goto done;
if ((ret = attr_ns_value(x1, "objectcreate", NULL, cbret, &createstr)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* Special case if incoming x1 is empty, top-level only */
if (xml_child_nr_type(x1, CX_ELMNT) == 0){
- if (xml_child_nr_type(x0, CX_ELMNT)){ /* base tree not empty */
- switch(op){
- case OP_DELETE:
- case OP_REMOVE:
- case OP_REPLACE:
- if (!permit && xnacm){
- if ((ret = nacm_datanode_write(h, x0, x0t, NACM_DELETE, username, xnacm, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- permit = 1;
- }
- while ((x0c = xml_child_i(x0, 0)) != 0)
- if (xml_purge(x0c) < 0)
- goto done;
- break;
- default:
- break;
- }
- }
- else /* base tree empty */
- switch(op){
+ if (xml_child_nr_type(x0, CX_ELMNT)){ /* base tree not empty */
+ switch(op){
+ case OP_DELETE:
+ case OP_REMOVE:
+ case OP_REPLACE:
+ if (!permit && xnacm){
+ if ((ret = nacm_datanode_write(h, x0, x0t, NACM_DELETE, username, xnacm, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ permit = 1;
+ }
+ while ((x0c = xml_child_i(x0, 0)) != 0)
+ if (xml_purge(x0c) < 0)
+ goto done;
+ break;
+ default:
+ break;
+ }
+ }
+ else /* base tree empty */
+ switch(op){
#if 0 /* According to RFC6020 7.5.8 you cant delete a non-existing object.
- On the other hand, the top-level cannot be removed anyway.
- Additionally, I think this is irritating so I disable it.
- I.e., curl -u andy:bar -sS -X DELETE http://localhost/restconf/data
+ On the other hand, the top-level cannot be removed anyway.
+ Additionally, I think this is irritating so I disable it.
+ I.e., curl -u andy:bar -sS -X DELETE http://localhost/restconf/data
*/
- case OP_DELETE:
- if (netconf_data_missing(cbret, "Data does not exist; cannot delete resource") < 0)
- goto done;
- goto fail;
- break;
+ case OP_DELETE:
+ if (netconf_data_missing(cbret, "Data does not exist; cannot delete resource") < 0)
+ goto done;
+ goto fail;
+ break;
#endif
- default:
- break;
- }
+ default:
+ break;
+ }
}
/* Special case top-level replace */
else if (op == OP_REPLACE || op == OP_DELETE){
- if (createstr != NULL){
- if (xml_child_nr_type(x0, CX_ELMNT)) /* base tree not empty */
- clicon_data_set(h, "objectexisted", "true");
- else
- clicon_data_set(h, "objectexisted", "false");
- }
- if (!permit && xnacm){
- if ((ret = nacm_datanode_write(h, x1, x1t, NACM_UPDATE, username, xnacm, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- permit = 1;
- }
- while ((x0c = xml_child_i(x0, 0)) != 0)
- if (xml_purge(x0c) < 0)
- goto done;
+ if (createstr != NULL){
+ if (xml_child_nr_type(x0, CX_ELMNT)) /* base tree not empty */
+ clicon_data_set(h, "objectexisted", "true");
+ else
+ clicon_data_set(h, "objectexisted", "false");
+ }
+ if (!permit && xnacm){
+ if ((ret = nacm_datanode_write(h, x1, x1t, NACM_UPDATE, username, xnacm, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ permit = 1;
+ }
+ while ((x0c = xml_child_i(x0, 0)) != 0)
+ if (xml_purge(x0c) < 0)
+ goto done;
}
/* Loop through children of the modification tree */
x1c = NULL;
while ((x1c = xml_child_each(x1, x1c, CX_ELMNT)) != NULL) {
- x1cname = xml_name(x1c);
- /* Get yang spec of the child */
- yc = NULL;
- if (ys_module_by_xml(yspec, x1c, &ymod) <0)
- goto done;
- if (ymod != NULL)
- yc = yang_find_datanode(ymod, x1cname);
- if (yc == NULL){
- if (ymod != NULL &&
- clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1){
- /* Add dummy Y_ANYDATA yang stmt, see ysp_add */
- if ((yc = yang_anydata_add(ymod, x1cname)) < 0)
- goto done;
- xml_spec_set(x1c, yc);
- clicon_log(LOG_WARNING,
- "%s: %d: No YANG spec for %s, anydata used",
- __FUNCTION__, __LINE__, x1cname);
- }
- else{
- if (netconf_unknown_element(cbret, "application", x1cname, "Unassigned yang spec") < 0)
- goto done;
- goto fail;
- }
- }
- /* See if there is a corresponding node in the base tree */
- if (match_base_child(x0, x1c, yc, &x0c) < 0)
- goto done;
- if (x0c && (yc != xml_spec(x0c))){
- /* There is a match but is should be replaced (choice)*/
- if (xml_purge(x0c) < 0)
- goto done;
- x0c = NULL;
- }
- if ((ret = text_modify(h, x0c, x0, x0t, x1c, x1t,
- yc, op,
- username, xnacm, permit, cbret)) < 0)
- goto done;
- /* If xml return - ie netconf error xml tree, then stop and return OK */
- if (ret == 0)
- goto fail;
+ x1cname = xml_name(x1c);
+ /* Get yang spec of the child */
+ yc = NULL;
+ if (ys_module_by_xml(yspec, x1c, &ymod) <0)
+ goto done;
+ if (ymod != NULL)
+ yc = yang_find_datanode(ymod, x1cname);
+ if (yc == NULL){
+ if (ymod != NULL &&
+ clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1){
+ /* Add dummy Y_ANYDATA yang stmt, see ysp_add */
+ if ((yc = yang_anydata_add(ymod, x1cname)) < 0)
+ goto done;
+ xml_spec_set(x1c, yc);
+ clicon_log(LOG_WARNING,
+ "%s: %d: No YANG spec for %s, anydata used",
+ __FUNCTION__, __LINE__, x1cname);
+ }
+ else{
+ if (netconf_unknown_element(cbret, "application", x1cname, "Unassigned yang spec") < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ /* See if there is a corresponding node in the base tree */
+ if (match_base_child(x0, x1c, yc, &x0c) < 0)
+ goto done;
+ if (x0c && (yc != xml_spec(x0c))){
+ /* There is a match but is should be replaced (choice)*/
+ if (xml_purge(x0c) < 0)
+ goto done;
+ x0c = NULL;
+ }
+ if ((ret = text_modify(h, x0c, x0, x0t, x1c, x1t,
+ yc, op,
+ username, xnacm, permit, cbret)) < 0)
+ goto done;
+ /* If xml return - ie netconf error xml tree, then stop and return OK */
+ if (ret == 0)
+ goto fail;
}
// ok:
retval = 1;
@@ -1167,11 +1167,11 @@ text_modify_top(clicon_handle h,
*/
int
xmldb_put(clicon_handle h,
- const char *db,
- enum operation_type op,
- cxobj *x1,
- char *username,
- cbuf *cbret)
+ const char *db,
+ enum operation_type op,
+ cxobj *x1,
+ char *username,
+ cbuf *cbret)
{
int retval = -1;
char *dbfile = NULL;
@@ -1192,42 +1192,42 @@ xmldb_put(clicon_handle h,
cxobj *xerr = NULL;
if (cbret == NULL){
- clicon_err(OE_XML, EINVAL, "cbret is NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "cbret is NULL");
+ goto done;
}
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No yang spec");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "No yang spec");
+ goto done;
}
if (x1 && strcmp(xml_name(x1), NETCONF_INPUT_CONFIG) != 0){
- clicon_err(OE_XML, 0, "Top-level symbol of modification tree is %s, expected \"%s\"",
- xml_name(x1), NETCONF_INPUT_CONFIG);
- goto done;
+ clicon_err(OE_XML, 0, "Top-level symbol of modification tree is %s, expected \"%s\"",
+ xml_name(x1), NETCONF_INPUT_CONFIG);
+ goto done;
}
if ((de = clicon_db_elmnt_get(h, db)) != NULL){
- if (clicon_datastore_cache(h) != DATASTORE_NOCACHE)
- x0 = de->de_xml; /* XXX flag is not XML_FLAG_TOP */
+ if (clicon_datastore_cache(h) != DATASTORE_NOCACHE)
+ x0 = de->de_xml; /* XXX flag is not XML_FLAG_TOP */
}
/* If there is no xml x0 tree (in cache), then read it from file */
if (x0 == NULL){
- firsttime++; /* to avoid leakage on error, see fail from text_modify */
- /* xml looks like: ... where "x" is a top-level symbol in a module */
- if ((ret = xmldb_readfile(h, db, YB_MODULE, yspec, &x0, de, NULL, &xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ firsttime++; /* to avoid leakage on error, see fail from text_modify */
+ /* xml looks like: ... where "x" is a top-level symbol in a module */
+ if ((ret = xmldb_readfile(h, db, YB_MODULE, yspec, &x0, de, NULL, &xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
if (strcmp(xml_name(x0), DATASTORE_TOP_SYMBOL) !=0 ||
- xml_flag(x0, XML_FLAG_TOP) == 0){
- clicon_err(OE_XML, 0, "Top-level symbol is %s, expected \"%s\"",
- xml_name(x0), DATASTORE_TOP_SYMBOL);
- goto done;
+ xml_flag(x0, XML_FLAG_TOP) == 0){
+ clicon_err(OE_XML, 0, "Top-level symbol is %s, expected \"%s\"",
+ xml_name(x0), DATASTORE_TOP_SYMBOL);
+ goto done;
}
/* Here x0 looks like: ... */
#if 0 /* debug */
if (xml_apply0(x1, -1, xml_sort_verify, NULL) < 0)
- clicon_log(LOG_NOTICE, "%s: verify failed #1", __FUNCTION__);
+ clicon_log(LOG_NOTICE, "%s: verify failed #1", __FUNCTION__);
#endif
xnacm = clicon_nacm_cache(h);
@@ -1240,89 +1240,89 @@ xmldb_put(clicon_handle h,
* new tree is made.
*/
if ((ret = text_modify_top(h, x0, x0, x1, x1, yspec, op, username, xnacm, permit, cbret)) < 0)
- goto done;
+ goto done;
/* If xml return - ie netconf error xml tree, then stop and return OK */
if (ret == 0){
- /* If first time and quit here, x0 is not written back into cache and leaks */
- if (firsttime && x0){
- xml_free(x0);
- x0 = NULL;
- }
- goto fail;
+ /* If first time and quit here, x0 is not written back into cache and leaks */
+ if (firsttime && x0){
+ xml_free(x0);
+ x0 = NULL;
+ }
+ goto fail;
}
/* Remove NONE nodes if all subs recursively are also NONE */
if (xml_tree_prune_flagged_sub(x0, XML_FLAG_NONE, 0, NULL) <0)
- goto done;
+ goto done;
if (xml_apply(x0, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset,
- (void*)(XML_FLAG_NONE|XML_FLAG_MARK)) < 0)
- goto done;
+ (void*)(XML_FLAG_NONE|XML_FLAG_MARK)) < 0)
+ goto done;
/* Remove global defaults and empty non-presence containers */
if (xml_defaults_nopresence(x0, 2) < 0)
- goto done;
+ goto done;
#if 0 /* debug */
if (xml_apply0(x0, -1, xml_sort_verify, NULL) < 0)
- clicon_log(LOG_NOTICE, "%s: verify failed #3", __FUNCTION__);
+ clicon_log(LOG_NOTICE, "%s: verify failed #3", __FUNCTION__);
#endif
/* Write back to datastore cache if first time */
if (clicon_datastore_cache(h) != DATASTORE_NOCACHE){
- db_elmnt de0 = {0,};
- if (de != NULL)
- de0 = *de;
- if (de0.de_xml == NULL)
- de0.de_xml = x0;
- de0.de_empty = (xml_child_nr(de0.de_xml) == 0);
- clicon_db_elmnt_set(h, db, &de0);
+ db_elmnt de0 = {0,};
+ if (de != NULL)
+ de0 = *de;
+ if (de0.de_xml == NULL)
+ de0.de_xml = x0;
+ de0.de_empty = (xml_child_nr(de0.de_xml) == 0);
+ clicon_db_elmnt_set(h, db, &de0);
}
if (xmldb_db2file(h, db, &dbfile) < 0)
- goto done;
+ goto done;
if (dbfile==NULL){
- clicon_err(OE_XML, 0, "dbfile NULL");
- goto done;
+ clicon_err(OE_XML, 0, "dbfile NULL");
+ goto done;
}
/* Add module revision info before writing to file)
* Only if CLICON_XMLDB_MODSTATE is set
*/
if ((x = clicon_modst_cache_get(h, 1)) != NULL){
- if ((xmodst = xml_dup(x)) == NULL)
- goto done;
- if (xml_addsub(x0, xmodst) < 0)
- goto done;
+ if ((xmodst = xml_dup(x)) == NULL)
+ goto done;
+ if (xml_addsub(x0, xmodst) < 0)
+ goto done;
}
if ((format = clicon_option_str(h, "CLICON_XMLDB_FORMAT")) == NULL){
- clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
- goto done;
+ clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
+ goto done;
}
if ((f = fopen(dbfile, "w")) == NULL){
- clicon_err(OE_CFG, errno, "Creating file %s", dbfile);
- goto done;
+ clicon_err(OE_CFG, errno, "Creating file %s", dbfile);
+ goto done;
}
pretty = clicon_option_bool(h, "CLICON_XMLDB_PRETTY");
if (strcmp(format,"json")==0){
- if (clixon_json2file(f, x0, pretty, fprintf, 0, 0) < 0)
- goto done;
+ if (clixon_json2file(f, x0, pretty, fprintf, 0, 0) < 0)
+ goto done;
}
else if (clixon_xml2file(f, x0, 0, pretty, fprintf, 0, 0) < 0)
- goto done;
+ goto done;
/* Remove modules state after writing to file
*/
if (xmodst && xml_purge(xmodst) < 0)
- goto done;
+ goto done;
retval = 1;
done:
if (f != NULL)
- fclose(f);
+ fclose(f);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (dbfile)
- free(dbfile);
+ free(dbfile);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (x0 && clicon_datastore_cache(h) == DATASTORE_NOCACHE)
- xml_free(x0);
+ xml_free(x0);
return retval;
fail:
retval = 0;
@@ -1333,8 +1333,8 @@ xmldb_put(clicon_handle h,
*/
int
xmldb_dump(clicon_handle h,
- FILE *f,
- cxobj *xt)
+ FILE *f,
+ cxobj *xt)
{
int retval = -1;
cxobj *x;
@@ -1344,25 +1344,25 @@ xmldb_dump(clicon_handle h,
/* clear XML tree of defaults */
if (xml_tree_prune_flagged(xt, XML_FLAG_DEFAULT, 1) < 0)
- goto done;
+ goto done;
/* Add modstate first */
if ((x = clicon_modst_cache_get(h, 1)) != NULL){
- if ((xmodst = xml_dup(x)) == NULL)
- goto done;
- if (xml_child_insert_pos(xt, xmodst, 0) < 0)
- goto done;
+ if ((xmodst = xml_dup(x)) == NULL)
+ goto done;
+ if (xml_child_insert_pos(xt, xmodst, 0) < 0)
+ goto done;
}
if ((format = clicon_option_str(h, "CLICON_XMLDB_FORMAT")) == NULL){
- clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
- goto done;
+ clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
+ goto done;
}
pretty = clicon_option_bool(h, "CLICON_XMLDB_PRETTY");
if (strcmp(format,"json")==0){
- if (clixon_json2file(f, xt, pretty, fprintf, 0, 0) < 0)
- goto done;
+ if (clixon_json2file(f, xt, pretty, fprintf, 0, 0) < 0)
+ goto done;
}
else if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
diff --git a/lib/src/clixon_dispatcher.c b/lib/src/clixon_dispatcher.c
index b3793fb5..4728febb 100644
--- a/lib/src/clixon_dispatcher.c
+++ b/lib/src/clixon_dispatcher.c
@@ -113,8 +113,8 @@
*/
static int
split_path(char *path,
- char ***plist,
- size_t *plist_len)
+ char ***plist,
+ size_t *plist_len)
{
int retval = -1;
size_t allocated = PATH_CHUNKS;
@@ -125,14 +125,14 @@ split_path(char *path,
char *new_element;
if ((work = strdup(path)) == NULL)
- goto done;
+ goto done;
if ((list = malloc(allocated * sizeof(char *))) == NULL)
- goto done;
+ goto done;
memset(list, 0, allocated * sizeof(char *));
ptr = work;
if (*ptr == '/') {
- if ((new_element = strdup("/")) == NULL)
- goto done;
+ if ((new_element = strdup("/")) == NULL)
+ goto done;
list[len++] = new_element;
ptr++;
}
@@ -144,11 +144,11 @@ split_path(char *path,
/* we've run out of space, allocate a bigger list */
allocated += PATH_CHUNKS;
if ((list = realloc(list, allocated * sizeof(char *))) == NULL)
- goto done;
+ goto done;
}
if ((new_element = strdup(ptr)) == NULL)
- goto done;
+ goto done;
list[len++] = new_element;
ptr = strtok(NULL, "/");
@@ -170,7 +170,7 @@ split_path(char *path,
*/
static void
split_path_free(char **list,
- size_t len)
+ size_t len)
{
size_t i;
@@ -219,14 +219,14 @@ find_peer(dispatcher_entry_t *node, char *node_name)
*/
static dispatcher_entry_t *
add_peer_node(dispatcher_entry_t *node,
- char *name)
+ char *name)
{
dispatcher_entry_t *new_node = NULL;
dispatcher_entry_t *eptr;
if ((new_node = malloc(sizeof(dispatcher_entry_t))) == NULL)
- return NULL;
-
+ return NULL;
+
memset(new_node, 0, sizeof(dispatcher_entry_t));
if (node == NULL) {
/* this is a new node */
@@ -279,12 +279,12 @@ add_peer_node(dispatcher_entry_t *node,
static dispatcher_entry_t *
add_child_node(dispatcher_entry_t *node,
- char *name)
+ char *name)
{
dispatcher_entry_t *child_ptr;
if ((child_ptr = add_peer_node(node->children, name)) == NULL)
- return NULL;
+ return NULL;
node->children = child_ptr->peer_head;
return child_ptr;
@@ -299,7 +299,7 @@ add_child_node(dispatcher_entry_t *node,
*/
static dispatcher_entry_t *
get_entry(dispatcher_entry_t *root,
- char *path)
+ char *path)
{
char **split_path_list = NULL;
size_t split_path_len = 0;
@@ -308,12 +308,12 @@ get_entry(dispatcher_entry_t *root,
/* cut the path up into individual elements */
if (split_path(path, &split_path_list, &split_path_len) < 0)
- return NULL;
+ return NULL;
/* some elements may have keys defined, strip them off */
for (int i = 0; i < split_path_len; i++) {
- char *kptr = split_path_list[i];
- strsep(&kptr, "=[]");
+ char *kptr = split_path_list[i];
+ strsep(&kptr, "=[]");
}
/* search down the tree */
@@ -321,7 +321,7 @@ get_entry(dispatcher_entry_t *root,
char *query = split_path_list[i];
if ((ptr = find_peer(ptr, query)) == NULL) {
- split_path_free(split_path_list, split_path_len);
+ split_path_free(split_path_list, split_path_len);
/* we ran out of matches, use last found handler */
return best;
}
@@ -350,9 +350,9 @@ get_entry(dispatcher_entry_t *root,
*/
static int
call_handler_helper(dispatcher_entry_t *entry,
- void *handle,
- char *path,
- void *user_args)
+ void *handle,
+ char *path,
+ void *user_args)
{
if (entry->children != NULL) {
call_handler_helper(entry->children, handle, path, user_args);
@@ -382,14 +382,14 @@ call_handler_helper(dispatcher_entry_t *entry,
*/
int
dispatcher_register_handler(dispatcher_entry_t **root,
- dispatcher_definition *x)
+ dispatcher_definition *x)
{
char **split_path_list = NULL;
size_t split_path_len = 0;
dispatcher_entry_t *ptr;
if (*x->dd_path != '/') {
- errno = EINVAL;
+ errno = EINVAL;
return -1;
}
@@ -398,7 +398,7 @@ dispatcher_register_handler(dispatcher_entry_t **root,
* up to create the elements of the dispatcher table
*/
if (split_path(x->dd_path, &split_path_list, &split_path_len) < 0)
- return -1;
+ return -1;
/*
* the first element is always a peer to the top level
@@ -406,14 +406,14 @@ dispatcher_register_handler(dispatcher_entry_t **root,
ptr = *root;
if ((ptr = add_peer_node(ptr, split_path_list[0])) == NULL)
- return -1;
+ return -1;
if (*root == NULL) {
*root = ptr;
}
for (size_t i = 1; i < split_path_len; i++) {
if ((ptr = add_child_node(ptr, split_path_list[i])) == NULL)
- return -1;
+ return -1;
}
/* when we get here, ptr points at last entry added */
@@ -442,16 +442,16 @@ dispatcher_register_handler(dispatcher_entry_t **root,
*/
int
dispatcher_call_handlers(dispatcher_entry_t *root,
- void *handle,
- char *path,
- void *user_args)
+ void *handle,
+ char *path,
+ void *user_args)
{
int ret = 0;
dispatcher_entry_t *best;
if ((best = get_entry(root, path)) == NULL){
- errno = ENOENT;
- return -1;
+ errno = ENOENT;
+ return -1;
}
if (best->children != NULL) {
call_handler_helper(best->children, handle, path, user_args);
@@ -468,13 +468,13 @@ int
dispatcher_free(dispatcher_entry_t *root)
{
if (root == NULL)
- return 0;
+ return 0;
if (root->children)
- dispatcher_free(root->children);
+ dispatcher_free(root->children);
if (root->peer)
- dispatcher_free(root->peer);
+ dispatcher_free(root->peer);
if (root->node_name)
- free(root->node_name);
+ free(root->node_name);
free(root);
return 0;
}
@@ -484,18 +484,18 @@ dispatcher_free(dispatcher_entry_t *root)
#define INDENT 3
int
dispatcher_print(FILE *f,
- int level,
- dispatcher_entry_t *de)
+ int level,
+ dispatcher_entry_t *de)
{
fprintf(f, "%*s%s", level*INDENT, "", de->node_name);
if (de->handler)
- fprintf(f, " %p", de->handler);
+ fprintf(f, " %p", de->handler);
if (de->arg)
- fprintf(f, " (%p)", de->arg);
+ fprintf(f, " (%p)", de->arg);
fprintf(f, "\n");
if (de->children)
- dispatcher_print(f, level+1, de->children);
+ dispatcher_print(f, level+1, de->children);
if (de->peer)
- dispatcher_print(f, level, de->peer);
+ dispatcher_print(f, level, de->peer);
return 0;
}
diff --git a/lib/src/clixon_err.c b/lib/src/clixon_err.c
index be8ab50e..b319b1c6 100644
--- a/lib/src/clixon_err.c
+++ b/lib/src/clixon_err.c
@@ -131,13 +131,13 @@ static struct errvec EV[] = {
static char *
clicon_strerror1(int err,
- struct errvec vec[])
+ struct errvec vec[])
{
struct errvec *ev;
for (ev=vec; ev->ev_err != -1; ev++)
- if (ev->ev_err == err)
- break;
+ if (ev->ev_err == err)
+ break;
return ev?(ev->ev_str?ev->ev_str:"unknown"):"CLICON unknown error";
}
@@ -163,13 +163,13 @@ find_category(int category)
int found = 0;
if ((cec = _err_cat_list) != NULL){
- do {
- if (cec->cec_category == category){
- found++;
- break;
- }
- cec = NEXTQ(clixon_err_cats *, cec);
- } while (cec && cec != _err_cat_list);
+ do {
+ if (cec->cec_category == category){
+ found++;
+ break;
+ }
+ cec = NEXTQ(clixon_err_cats *, cec);
+ } while (cec && cec != _err_cat_list);
}
return found?cec:NULL;
}
@@ -192,10 +192,10 @@ find_category(int category)
*/
int
clicon_err_fn(const char *fn,
- const int line,
- int category,
- int suberr,
- const char *format, ...)
+ const int line,
+ int category,
+ int suberr,
+ const char *format, ...)
{
va_list args;
int len;
@@ -214,77 +214,77 @@ clicon_err_fn(const char *fn,
/* allocate a message string exactly fitting the message length */
if ((msg = malloc(len+1)) == NULL){
- fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
- goto done;
+ fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
+ goto done;
}
/* second round: compute write message from format and args */
va_start(args, format);
if (vsnprintf(msg, len+1, format, args) < 0){
- va_end(args);
- fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
- goto done;
+ va_end(args);
+ fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
+ goto done;
}
va_end(args);
strncpy(clicon_err_reason, msg, ERR_STRLEN-1);
/* Check category callbacks as defined in clixon_err_cat_reg */
if ((cec = find_category(category)) != NULL &&
- cec->cec_logfn){
- cbuf *cb = NULL;
- if ((cb = cbuf_new()) == NULL){
- fprintf(stderr, "cbuf_new: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
- goto done;
- }
- if (cec->cec_logfn(cec->cec_handle, suberr, cb) < 0)
- goto done;
- /* Here we could take care of specific errno, like application-defined errors */
- if (fn)
- clicon_log(LOG_ERR, "%s: %d: %s: %s: %s",
- fn,
- line,
- clicon_strerror(category),
- cbuf_get(cb),
- msg);
- else
- clicon_log(LOG_ERR, "%s: %s: %s",
- clicon_strerror(category),
- cbuf_get(cb),
- msg);
- if (cb)
- cbuf_free(cb);
+ cec->cec_logfn){
+ cbuf *cb = NULL;
+ if ((cb = cbuf_new()) == NULL){
+ fprintf(stderr, "cbuf_new: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
+ goto done;
+ }
+ if (cec->cec_logfn(cec->cec_handle, suberr, cb) < 0)
+ goto done;
+ /* Here we could take care of specific errno, like application-defined errors */
+ if (fn)
+ clicon_log(LOG_ERR, "%s: %d: %s: %s: %s",
+ fn,
+ line,
+ clicon_strerror(category),
+ cbuf_get(cb),
+ msg);
+ else
+ clicon_log(LOG_ERR, "%s: %s: %s",
+ clicon_strerror(category),
+ cbuf_get(cb),
+ msg);
+ if (cb)
+ cbuf_free(cb);
}
else if (suberr){ /* Actually log it */
- /* Here we could take care of specific errno, like application-defined errors */
- if (fn)
- clicon_log(LOG_ERR, "%s: %d: %s: %s: %s",
- fn,
- line,
- clicon_strerror(category),
- msg,
- suberr==XMLPARSE_ERRNO?"XML parse error":strerror(suberr));
- else
- clicon_log(LOG_ERR, "%s: %s: %s",
- clicon_strerror(category),
- msg,
- suberr==XMLPARSE_ERRNO?"XML parse error":strerror(suberr));
+ /* Here we could take care of specific errno, like application-defined errors */
+ if (fn)
+ clicon_log(LOG_ERR, "%s: %d: %s: %s: %s",
+ fn,
+ line,
+ clicon_strerror(category),
+ msg,
+ suberr==XMLPARSE_ERRNO?"XML parse error":strerror(suberr));
+ else
+ clicon_log(LOG_ERR, "%s: %s: %s",
+ clicon_strerror(category),
+ msg,
+ suberr==XMLPARSE_ERRNO?"XML parse error":strerror(suberr));
}
else{
- if (fn)
- clicon_log(LOG_ERR, "%s: %d: %s: %s",
- fn,
- line,
- clicon_strerror(category),
- msg);
- else
- clicon_log(LOG_ERR, "%s: %s",
- clicon_strerror(category),
- msg);
+ if (fn)
+ clicon_log(LOG_ERR, "%s: %d: %s: %s",
+ fn,
+ line,
+ clicon_strerror(category),
+ msg);
+ else
+ clicon_log(LOG_ERR, "%s: %s",
+ clicon_strerror(category),
+ msg);
}
retval = 0;
done:
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -304,7 +304,7 @@ clicon_err_save(void)
struct err_state *es;
if ((es = malloc(sizeof(*es))) == NULL)
- return NULL;
+ return NULL;
es->es_errno = clicon_errno;
es->es_suberrno = clicon_suberrno;
strncpy(es->es_reason, clicon_err_reason, ERR_STRLEN);
@@ -319,10 +319,10 @@ clicon_err_restore(void* handle)
struct err_state *es;
if ((es = (struct err_state *)handle) != NULL){
- clicon_errno = es->es_errno;
- clicon_suberrno = es->es_suberrno;
- strncpy(clicon_err_reason, es->es_reason, ERR_STRLEN);
- free(es);
+ clicon_errno = es->es_errno;
+ clicon_suberrno = es->es_suberrno;
+ strncpy(clicon_err_reason, es->es_reason, ERR_STRLEN);
+ free(es);
}
return 0;
}
@@ -334,14 +334,14 @@ clicon_err_restore(void* handle)
*/
int
clixon_err_cat_reg(enum clicon_err category,
- void *handle,
- clixon_cat_log_cb logfn)
+ void *handle,
+ clixon_cat_log_cb logfn)
{
clixon_err_cats *cec;
if ((cec = malloc(sizeof *cec)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- return -1;
+ clicon_err(OE_UNIX, errno, "malloc");
+ return -1;
}
memset(cec, 0, sizeof *cec);
cec->cec_category = category;
@@ -357,8 +357,8 @@ clixon_err_exit(void)
clixon_err_cats *cec = NULL;
while ((cec = _err_cat_list) != NULL){
- DELQ(cec, _err_cat_list, clixon_err_cats *);
- free(cec);
+ DELQ(cec, _err_cat_list, clixon_err_cats *);
+ free(cec);
}
return 0;
}
diff --git a/lib/src/clixon_event.c b/lib/src/clixon_event.c
index 746e3287..4bad456c 100644
--- a/lib/src/clixon_event.c
+++ b/lib/src/clixon_event.c
@@ -131,7 +131,7 @@ static int
clixon_exit_decr(void)
{
if (_clicon_exit > 1)
- _clicon_exit--;
+ _clicon_exit--;
return 0;
}
@@ -176,15 +176,15 @@ clicon_sig_ignore_get(void)
*/
int
clixon_event_reg_fd(int fd,
- int (*fn)(int, void*),
- void *arg,
- char *str)
+ int (*fn)(int, void*),
+ void *arg,
+ char *str)
{
struct event_data *e;
if ((e = (struct event_data *)malloc(sizeof(struct event_data))) == NULL){
- clicon_err(OE_EVENTS, errno, "malloc");
- return -1;
+ clicon_err(OE_EVENTS, errno, "malloc");
+ return -1;
}
memset(e, 0, sizeof(struct event_data));
strncpy(e->e_string, str, EVENT_STRLEN-1);
@@ -207,21 +207,21 @@ clixon_event_reg_fd(int fd,
*/
int
clixon_event_unreg_fd(int s,
- int (*fn)(int, void*))
+ int (*fn)(int, void*))
{
struct event_data *e, **e_prev;
int found = 0;
e_prev = ⅇ
for (e = ee; e; e = e->e_next){
- if (fn == e->e_fn && s == e->e_fd) {
- found++;
- *e_prev = e->e_next;
- _ee_unreg++;
- free(e);
- break;
- }
- e_prev = &e->e_next;
+ if (fn == e->e_fn && s == e->e_fd) {
+ found++;
+ *e_prev = e->e_next;
+ _ee_unreg++;
+ free(e);
+ break;
+ }
+ e_prev = &e->e_next;
}
return found?0:-1;
}
@@ -251,15 +251,15 @@ clixon_event_unreg_fd(int s,
*/
int
clixon_event_reg_timeout(struct timeval t,
- int (*fn)(int, void*),
- void *arg,
- char *str)
+ int (*fn)(int, void*),
+ void *arg,
+ char *str)
{
struct event_data *e, *e1, **e_prev;
if ((e = (struct event_data *)malloc(sizeof(struct event_data))) == NULL){
- clicon_err(OE_EVENTS, errno, "malloc");
- return -1;
+ clicon_err(OE_EVENTS, errno, "malloc");
+ return -1;
}
memset(e, 0, sizeof(struct event_data));
strncpy(e->e_string, str, EVENT_STRLEN-1);
@@ -270,9 +270,9 @@ clixon_event_reg_timeout(struct timeval t,
/* Sort into right place */
e_prev = &ee_timers;
for (e1=ee_timers; e1; e1=e1->e_next){
- if (timercmp(&e->e_time, &e1->e_time, <))
- break;
- e_prev = &e1->e_next;
+ if (timercmp(&e->e_time, &e1->e_time, <))
+ break;
+ e_prev = &e1->e_next;
}
e->e_next = e1;
*e_prev = e;
@@ -293,20 +293,20 @@ clixon_event_reg_timeout(struct timeval t,
*/
int
clixon_event_unreg_timeout(int (*fn)(int, void*),
- void *arg)
+ void *arg)
{
struct event_data *e, **e_prev;
int found = 0;
e_prev = &ee_timers;
for (e = ee_timers; e; e = e->e_next){
- if (fn == e->e_fn && arg == e->e_arg) {
- found++;
- *e_prev = e->e_next;
- free(e);
- break;
- }
- e_prev = &e->e_next;
+ if (fn == e->e_fn && arg == e->e_arg) {
+ found++;
+ *e_prev = e->e_next;
+ free(e);
+ break;
+ }
+ e_prev = &e->e_next;
}
return found?0:-1;
}
@@ -327,7 +327,7 @@ clixon_event_poll(int fd)
FD_ZERO(&fdset);
FD_SET(fd, &fdset);
if ((retval = select(FD_SETSIZE, &fdset, NULL, NULL, &tnull)) < 0)
- clicon_err(OE_EVENTS, errno, "select");
+ clicon_err(OE_EVENTS, errno, "select");
return retval;
}
@@ -350,100 +350,100 @@ clixon_event_loop(clicon_handle h)
int retval = -1;
while (clixon_exit_get() != 1){
- FD_ZERO(&fdset);
- if (clicon_sig_child_get()){
- /* Go through processes and wait for child processes */
- if (clixon_process_waitpid(h) < 0)
- goto err;
- clicon_sig_child_set(0);
- }
- for (e=ee; e; e=e->e_next)
- if (e->e_type == EVENT_FD)
- FD_SET(e->e_fd, &fdset);
- if (ee_timers != NULL){
- gettimeofday(&t0, NULL);
- timersub(&ee_timers->e_time, &t0, &t);
- if (t.tv_sec < 0)
- n = select(FD_SETSIZE, &fdset, NULL, NULL, &tnull);
- else
- n = select(FD_SETSIZE, &fdset, NULL, NULL, &t);
- }
- else
- n = select(FD_SETSIZE, &fdset, NULL, NULL, NULL);
- if (clixon_exit_get() == 1){
- break;
- }
- if (n == -1) {
- if (errno == EINTR){
- /* Signals are checked and are in three classes:
- * (1) Signals that exit gracefully, the function returns 0
- * Must be registered such as by set_signal() of SIGTERM,SIGINT, etc with a handler that calls
- * clicon_exit_set().
- * (2) SIGCHILD Childs that exit(), go through clixon_proc list and cal waitpid
- * New select loop is called
- * (2) Signals are ignored, and the select is rerun, ie handler calls clicon_sig_ignore_get
- * New select loop is called
- * (3) Other signals result in an error and return -1.
- */
- clicon_debug(1, "%s select: %s", __FUNCTION__, strerror(errno));
- if (clixon_exit_get() == 1){
- clicon_err(OE_EVENTS, errno, "select");
- retval = 0;
- }
- else if (clicon_sig_child_get()){
- /* Go through processes and wait for child processes */
- if (clixon_process_waitpid(h) < 0)
- goto err;
- clicon_sig_child_set(0);
- continue;
- }
- else if (clicon_sig_ignore_get()){
- clicon_sig_ignore_set(0);
- continue;
- }
- else
- clicon_err(OE_EVENTS, errno, "select");
- }
- else
- clicon_err(OE_EVENTS, errno, "select");
- goto err;
- }
- if (n==0){ /* Timeout */
- e = ee_timers;
- ee_timers = ee_timers->e_next;
- clicon_debug(2, "%s timeout: %s", __FUNCTION__, e->e_string);
- if ((*e->e_fn)(0, e->e_arg) < 0){
- free(e);
- goto err;
- }
- free(e);
- }
- _ee_unreg = 0;
- for (e=ee; e; e=e_next){
- if (clixon_exit_get() == 1){
- break;
- }
- e_next = e->e_next;
- if(e->e_type == EVENT_FD && FD_ISSET(e->e_fd, &fdset)){
- clicon_debug(2, "%s: FD_ISSET: %s", __FUNCTION__, e->e_string);
- if ((*e->e_fn)(e->e_fd, e->e_arg) < 0){
- clicon_debug(1, "%s Error in: %s", __FUNCTION__, e->e_string);
- goto err;
- }
- if (_ee_unreg){
- _ee_unreg = 0;
- break;
- }
- }
- }
- clixon_exit_decr(); /* If exit is set and > 1, decrement it (and exit when 1) */
- continue;
+ FD_ZERO(&fdset);
+ if (clicon_sig_child_get()){
+ /* Go through processes and wait for child processes */
+ if (clixon_process_waitpid(h) < 0)
+ goto err;
+ clicon_sig_child_set(0);
+ }
+ for (e=ee; e; e=e->e_next)
+ if (e->e_type == EVENT_FD)
+ FD_SET(e->e_fd, &fdset);
+ if (ee_timers != NULL){
+ gettimeofday(&t0, NULL);
+ timersub(&ee_timers->e_time, &t0, &t);
+ if (t.tv_sec < 0)
+ n = select(FD_SETSIZE, &fdset, NULL, NULL, &tnull);
+ else
+ n = select(FD_SETSIZE, &fdset, NULL, NULL, &t);
+ }
+ else
+ n = select(FD_SETSIZE, &fdset, NULL, NULL, NULL);
+ if (clixon_exit_get() == 1){
+ break;
+ }
+ if (n == -1) {
+ if (errno == EINTR){
+ /* Signals are checked and are in three classes:
+ * (1) Signals that exit gracefully, the function returns 0
+ * Must be registered such as by set_signal() of SIGTERM,SIGINT, etc with a handler that calls
+ * clicon_exit_set().
+ * (2) SIGCHILD Childs that exit(), go through clixon_proc list and cal waitpid
+ * New select loop is called
+ * (2) Signals are ignored, and the select is rerun, ie handler calls clicon_sig_ignore_get
+ * New select loop is called
+ * (3) Other signals result in an error and return -1.
+ */
+ clicon_debug(1, "%s select: %s", __FUNCTION__, strerror(errno));
+ if (clixon_exit_get() == 1){
+ clicon_err(OE_EVENTS, errno, "select");
+ retval = 0;
+ }
+ else if (clicon_sig_child_get()){
+ /* Go through processes and wait for child processes */
+ if (clixon_process_waitpid(h) < 0)
+ goto err;
+ clicon_sig_child_set(0);
+ continue;
+ }
+ else if (clicon_sig_ignore_get()){
+ clicon_sig_ignore_set(0);
+ continue;
+ }
+ else
+ clicon_err(OE_EVENTS, errno, "select");
+ }
+ else
+ clicon_err(OE_EVENTS, errno, "select");
+ goto err;
+ }
+ if (n==0){ /* Timeout */
+ e = ee_timers;
+ ee_timers = ee_timers->e_next;
+ clicon_debug(2, "%s timeout: %s", __FUNCTION__, e->e_string);
+ if ((*e->e_fn)(0, e->e_arg) < 0){
+ free(e);
+ goto err;
+ }
+ free(e);
+ }
+ _ee_unreg = 0;
+ for (e=ee; e; e=e_next){
+ if (clixon_exit_get() == 1){
+ break;
+ }
+ e_next = e->e_next;
+ if(e->e_type == EVENT_FD && FD_ISSET(e->e_fd, &fdset)){
+ clicon_debug(2, "%s: FD_ISSET: %s", __FUNCTION__, e->e_string);
+ if ((*e->e_fn)(e->e_fd, e->e_arg) < 0){
+ clicon_debug(1, "%s Error in: %s", __FUNCTION__, e->e_string);
+ goto err;
+ }
+ if (_ee_unreg){
+ _ee_unreg = 0;
+ break;
+ }
+ }
+ }
+ clixon_exit_decr(); /* If exit is set and > 1, decrement it (and exit when 1) */
+ continue;
err:
- clicon_debug(1, "%s err", __FUNCTION__);
- break;
+ clicon_debug(1, "%s err", __FUNCTION__);
+ break;
}
if (clixon_exit_get() == 1)
- retval = 0;
+ retval = 0;
clicon_debug(1, "%s done:%d", __FUNCTION__, retval);
return retval;
}
@@ -455,14 +455,14 @@ clixon_event_exit(void)
e_next = ee;
while ((e = e_next) != NULL){
- e_next = e->e_next;
- free(e);
+ e_next = e->e_next;
+ free(e);
}
ee = NULL;
e_next = ee_timers;
while ((e = e_next) != NULL){
- e_next = e->e_next;
- free(e);
+ e_next = e->e_next;
+ free(e);
}
ee_timers = NULL;
return 0;
diff --git a/lib/src/clixon_file.c b/lib/src/clixon_file.c
index 9391e74d..83731c11 100644
--- a/lib/src/clixon_file.c
+++ b/lib/src/clixon_file.c
@@ -66,7 +66,7 @@
*/
static int
clicon_file_dirent_sort(const void* arg1,
- const void* arg2)
+ const void* arg2)
{
struct dirent *d1 = (struct dirent *)arg1;
struct dirent *d2 = (struct dirent *)arg2;
@@ -79,8 +79,8 @@ clicon_file_dirent_sort(const void* arg1,
*/
static int
clicon_files_recursive1(const char *dir,
- regex_t *re,
- cvec *cvv)
+ regex_t *re,
+ cvec *cvv)
{
int retval = -1;
struct dirent *dent = NULL;
@@ -90,41 +90,41 @@ clicon_files_recursive1(const char *dir,
struct stat st;
if (dir == NULL){
- clicon_err(OE_UNIX, EINVAL, "Requires dir != NULL");
- goto done;
+ clicon_err(OE_UNIX, EINVAL, "Requires dir != NULL");
+ goto done;
}
if ((dirp = opendir(dir)) != NULL)
- while ((dent = readdir(dirp)) != NULL) {
- if (dent->d_type == DT_DIR) {
- /* If we find a directory we might want to enter it, unless it
- is the current directory (.) or parent (..) */
- if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0)
- continue;
+ while ((dent = readdir(dirp)) != NULL) {
+ if (dent->d_type == DT_DIR) {
+ /* If we find a directory we might want to enter it, unless it
+ is the current directory (.) or parent (..) */
+ if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0)
+ continue;
- /* Build the new directory and enter it. */
- sprintf(path, "%s/%s", dir, dent->d_name);
- if (clicon_files_recursive1(path, re, cvv) < 0)
- goto done;
- }
- else if (dent->d_type == DT_REG) {
- /* If we encounter a file, match it against the regexp and
- add it to the list of found files.*/
- if (re != NULL &&
- regexec(re, dent->d_name, (size_t)0, NULL, 0) != 0)
- continue;
- snprintf(path, MAXPATHLEN-1, "%s/%s", dir, dent->d_name);
- if ((res = lstat(path, &st)) != 0){
- clicon_err(OE_UNIX, errno, "lstat");
- goto done;
- }
- if ((st.st_mode & S_IFREG) == 0)
- continue;
- if (cvec_add_string(cvv, dent->d_name, path) < 0){
- clicon_err(OE_UNIX, errno, "cvec_add_string");
- goto done;
- }
- }
- }
+ /* Build the new directory and enter it. */
+ sprintf(path, "%s/%s", dir, dent->d_name);
+ if (clicon_files_recursive1(path, re, cvv) < 0)
+ goto done;
+ }
+ else if (dent->d_type == DT_REG) {
+ /* If we encounter a file, match it against the regexp and
+ add it to the list of found files.*/
+ if (re != NULL &&
+ regexec(re, dent->d_name, (size_t)0, NULL, 0) != 0)
+ continue;
+ snprintf(path, MAXPATHLEN-1, "%s/%s", dir, dent->d_name);
+ if ((res = lstat(path, &st)) != 0){
+ clicon_err(OE_UNIX, errno, "lstat");
+ goto done;
+ }
+ if ((st.st_mode & S_IFREG) == 0)
+ continue;
+ if (cvec_add_string(cvv, dent->d_name, path) < 0){
+ clicon_err(OE_UNIX, errno, "cvec_add_string");
+ goto done;
+ }
+ }
+ }
retval = 0;
done:
if (dirp)
@@ -137,7 +137,7 @@ clicon_files_recursive1(const char *dir,
int
clicon_files_recursive(const char *dir,
const char *regexp,
- cvec *cvv)
+ cvec *cvv)
{
int retval = -1;
regex_t re = {0,};
@@ -148,10 +148,10 @@ clicon_files_recursive(const char *dir,
if (regexp && (res = regcomp(&re, regexp, REG_EXTENDED)) != 0) {
regerror(res, &re, errbuf, sizeof(errbuf));
clicon_err(OE_DB, 0, "regcomp: %s", errbuf);
- goto done;
+ goto done;
}
if (clicon_files_recursive1(dir, &re, cvv) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (regexp)
@@ -186,9 +186,9 @@ clicon_files_recursive(const char *dir,
*/
int
clicon_file_dirent(const char *dir,
- struct dirent **ent,
- const char *regexp,
- mode_t type)
+ struct dirent **ent,
+ const char *regexp,
+ mode_t type)
{
int retval = -1;
DIR *dirp = NULL;
@@ -219,29 +219,29 @@ clicon_file_dirent(const char *dir,
while((dent = readdir(dirp)) != NULL) {
/* Filename matching */
if (regexp) {
- if (regexec(&re, dent->d_name, (size_t) 0, NULL, 0) != 0)
- continue;
+ if (regexec(&re, dent->d_name, (size_t) 0, NULL, 0) != 0)
+ continue;
}
/* File type matching */
if (type) {
- snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dent->d_name);
- res = lstat(filename, &st);
- if (res != 0) {
- clicon_err(OE_UNIX, errno, "lstat");
- goto quit;
- }
- if ((type & st.st_mode) == 0)
- continue;
+ snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dent->d_name);
+ res = lstat(filename, &st);
+ if (res != 0) {
+ clicon_err(OE_UNIX, errno, "lstat");
+ goto quit;
+ }
+ if ((type & st.st_mode) == 0)
+ continue;
}
direntStructSize = offsetof(struct dirent, d_name) + strlen(dent->d_name) + 1;
if ((new = realloc(new, (nent+1)*sizeof(struct dirent))) == NULL) {
- clicon_err(OE_UNIX, errno, "realloc");
- goto quit;
+ clicon_err(OE_UNIX, errno, "realloc");
+ goto quit;
} /* realloc */
clicon_debug(2, "%s memcpy(%p %p %u", __FUNCTION__, &new[nent], dent, direntStructSize);
/* man (3) readdir:
- * By implication, the use sizeof(struct dirent) to capture the size of the record including
- * the size of d_name is also incorrect. */
+ * By implication, the use sizeof(struct dirent) to capture the size of the record including
+ * the size of d_name is also incorrect. */
memset(&new[nent], 0, sizeof(struct dirent));
memcpy(&new[nent], dent, direntStructSize);
nent++;
@@ -267,7 +267,7 @@ quit:
*/
int
clicon_file_copy(char *src,
- char *target)
+ char *target)
{
int retval = -1;
int inF = 0, ouF = 0;
@@ -277,30 +277,30 @@ clicon_file_copy(char *src,
struct stat st;
if (stat(src, &st) != 0){
- clicon_err(OE_UNIX, errno, "stat");
- return -1;
+ clicon_err(OE_UNIX, errno, "stat");
+ return -1;
}
if((inF = open(src, O_RDONLY)) == -1) {
- clicon_err(OE_UNIX, errno, "open(%s) for read", src);
- return -1;
+ clicon_err(OE_UNIX, errno, "open(%s) for read", src);
+ return -1;
}
if((ouF = open(target, O_WRONLY | O_CREAT | O_TRUNC, st.st_mode)) == -1) {
- clicon_err(OE_UNIX, errno, "open(%s) for write", target);
- err = errno;
- goto error;
+ clicon_err(OE_UNIX, errno, "open(%s) for write", target);
+ err = errno;
+ goto error;
}
while((bytes = read(inF, line, sizeof(line))) > 0)
- if (write(ouF, line, bytes) < 0){
- clicon_err(OE_UNIX, errno, "write(%s)", src);
- err = errno;
- goto error;
- }
+ if (write(ouF, line, bytes) < 0){
+ clicon_err(OE_UNIX, errno, "write(%s)", src);
+ err = errno;
+ goto error;
+ }
retval = 0;
error:
close(inF);
if (ouF)
- close(ouF);
+ close(ouF);
if (retval < 0)
- errno = err;
+ errno = err;
return retval;
}
diff --git a/lib/src/clixon_handle.c b/lib/src/clixon_handle.c
index 16bee390..7960bf10 100644
--- a/lib/src/clixon_handle.c
+++ b/lib/src/clixon_handle.c
@@ -109,22 +109,22 @@ clicon_handle_init0(int size)
clicon_handle h = NULL;
if ((ch = malloc(size)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(ch, 0, size);
ch->ch_magic = CLICON_MAGIC;
if ((ch->ch_copt = clicon_hash_init()) == NULL){
- clicon_handle_exit((clicon_handle)ch);
- goto done;
+ clicon_handle_exit((clicon_handle)ch);
+ goto done;
}
if ((ch->ch_data = clicon_hash_init()) == NULL){
- clicon_handle_exit((clicon_handle)ch);
- goto done;
+ clicon_handle_exit((clicon_handle)ch);
+ goto done;
}
if ((ch->ch_db_elmnt = clicon_hash_init()) == NULL){
- clicon_handle_exit((clicon_handle)ch);
- goto done;
+ clicon_handle_exit((clicon_handle)ch);
+ goto done;
}
h = (clicon_handle)ch;
done:
@@ -157,11 +157,11 @@ clicon_handle_exit(clicon_handle h)
clicon_hash_t *ha;
if ((ha = clicon_options(h)) != NULL)
- clicon_hash_free(ha);
+ clicon_hash_free(ha);
if ((ha = clicon_data(h)) != NULL)
- clicon_hash_free(ha);
+ clicon_hash_free(ha);
if ((ha = clicon_db_elmnt(h)) != NULL)
- clicon_hash_free(ha);
+ clicon_hash_free(ha);
stream_delete_all(h, 1);
free(ch);
retval = 0;
@@ -228,7 +228,7 @@ clicon_stream(clicon_handle h)
int
clicon_stream_set(clicon_handle h,
- event_stream_t *es)
+ event_stream_t *es)
{
struct clicon_handle *ch = handle(h);
@@ -238,7 +238,7 @@ clicon_stream_set(clicon_handle h,
int
clicon_stream_append(clicon_handle h,
- event_stream_t *es)
+ event_stream_t *es)
{
struct clicon_handle *ch = handle(h);
diff --git a/lib/src/clixon_hash.c b/lib/src/clixon_hash.c
index e7a28abf..7d887af5 100644
--- a/lib/src/clixon_hash.c
+++ b/lib/src/clixon_hash.c
@@ -98,7 +98,7 @@
#include "clixon_err.h"
#include "clixon_hash.h"
-#define HASH_SIZE 1031 /* Number of hash buckets. Should be a prime */
+#define HASH_SIZE 1031 /* Number of hash buckets. Should be a prime */
#define align4(s) (((s)/4)*4 + 4)
/*! A very simplistic algorithm to calculate a hash bucket index
@@ -109,7 +109,7 @@ hash_bucket(const char *str)
uint32_t n = 0;
while(*str)
- n += (uint32_t)*str++;
+ n += (uint32_t)*str++;
return n % HASH_SIZE;
}
@@ -144,13 +144,13 @@ clicon_hash_free(clicon_hash_t *hash)
int i;
clicon_hash_t tmp;
for (i = 0; i < HASH_SIZE; i++) {
- while (hash[i]) {
- tmp = hash[i];
- DELQ(tmp, hash[i], clicon_hash_t);
- free(tmp->h_key);
- free(tmp->h_val);
- free(tmp);
- }
+ while (hash[i]) {
+ tmp = hash[i];
+ DELQ(tmp, hash[i], clicon_hash_t);
+ free(tmp->h_key);
+ free(tmp->h_val);
+ free(tmp);
+ }
}
free(hash);
return 0;
@@ -165,7 +165,7 @@ clicon_hash_free(clicon_hash_t *hash)
*/
clicon_hash_t
clicon_hash_lookup(clicon_hash_t *hash,
- const char *key)
+ const char *key)
{
uint32_t bkt;
clicon_hash_t h;
@@ -173,11 +173,11 @@ clicon_hash_lookup(clicon_hash_t *hash,
bkt = hash_bucket(key);
h = hash[bkt];
if (h) {
- do {
- if (!strcmp(h->h_key, key))
- return h;
- h = NEXTQ(clicon_hash_t, h);
- } while (h != hash[bkt]);
+ do {
+ if (!strcmp(h->h_key, key))
+ return h;
+ h = NEXTQ(clicon_hash_t, h);
+ } while (h != hash[bkt]);
}
return NULL;
}
@@ -191,21 +191,21 @@ clicon_hash_lookup(clicon_hash_t *hash,
*/
void *
clicon_hash_value(clicon_hash_t *hash,
- const char *key,
- size_t *vlen)
+ const char *key,
+ size_t *vlen)
{
clicon_hash_t h;
if (hash == NULL){
- clicon_err(OE_UNIX, EINVAL, "hash is NULL");
- return NULL;
+ clicon_err(OE_UNIX, EINVAL, "hash is NULL");
+ return NULL;
}
h = clicon_hash_lookup(hash, key);
if (h == NULL)
- return NULL; /* OK, key not found */
+ return NULL; /* OK, key not found */
if (vlen)
- *vlen = h->h_vlen;
+ *vlen = h->h_vlen;
return h->h_val;
}
@@ -221,69 +221,69 @@ clicon_hash_value(clicon_hash_t *hash,
*/
clicon_hash_t
clicon_hash_add(clicon_hash_t *hash,
- const char *key,
- void *val,
- size_t vlen)
+ const char *key,
+ void *val,
+ size_t vlen)
{
void *newval = NULL;
clicon_hash_t h;
clicon_hash_t new = NULL;
if (hash == NULL){
- clicon_err(OE_UNIX, EINVAL, "hash is NULL");
- return NULL;
+ clicon_err(OE_UNIX, EINVAL, "hash is NULL");
+ return NULL;
}
/* Check NULL case */
if ((val == NULL && vlen != 0) ||
- (val != NULL && vlen == 0)){
- clicon_err(OE_UNIX, EINVAL, "Mismatch in value and length, only one is zero");
- goto catch;
+ (val != NULL && vlen == 0)){
+ clicon_err(OE_UNIX, EINVAL, "Mismatch in value and length, only one is zero");
+ goto catch;
}
/* If variable exist, don't allocate a new. just replace value */
h = clicon_hash_lookup(hash, key);
if (h == NULL) {
- if ((new = (clicon_hash_t)malloc(sizeof(*new))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto catch;
- }
- memset(new, 0, sizeof(*new));
-
- new->h_key = strdup(key);
- if (new->h_key == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto catch;
- }
-
- h = new;
+ if ((new = (clicon_hash_t)malloc(sizeof(*new))) == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto catch;
+ }
+ memset(new, 0, sizeof(*new));
+
+ new->h_key = strdup(key);
+ if (new->h_key == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto catch;
+ }
+
+ h = new;
}
if (vlen){
- /* Make copy of value. aligned */
- newval = malloc(align4(vlen+3));
- if (newval == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto catch;
- }
- memcpy(newval, val, vlen);
+ /* Make copy of value. aligned */
+ newval = malloc(align4(vlen+3));
+ if (newval == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto catch;
+ }
+ memcpy(newval, val, vlen);
}
/* Free old value if existing variable */
if (h->h_val)
- free(h->h_val);
+ free(h->h_val);
h->h_val = newval;
h->h_vlen = vlen;
/* Add to list only if new variable */
if (new)
- INSQ(h, hash[hash_bucket(key)]);
+ INSQ(h, hash[hash_bucket(key)]);
return h;
catch:
if (new) {
- if (new->h_key)
- free(new->h_key);
- free(new);
+ if (new->h_key)
+ free(new->h_key);
+ free(new);
}
return NULL;
@@ -299,17 +299,17 @@ catch:
*/
int
clicon_hash_del(clicon_hash_t *hash,
- const char *key)
+ const char *key)
{
clicon_hash_t h;
if (hash == NULL){
- clicon_err(OE_UNIX, EINVAL, "hash is NULL");
- return -1;
+ clicon_err(OE_UNIX, EINVAL, "hash is NULL");
+ return -1;
}
h = clicon_hash_lookup(hash, key);
if (h == NULL)
- return -1;
+ return -1;
DELQ(h, hash[hash_bucket(key)], clicon_hash_t);
@@ -322,17 +322,17 @@ clicon_hash_del(clicon_hash_t *hash,
/*! Return vector of keys in hash table
*
- * @param[in] hash Hash table
+ * @param[in] hash Hash table
* @param[out] vector Vector of keys, NULL if not found
- * @param[out] nkeys Size of key vector
+ * @param[out] nkeys Size of key vector
* @retval 0 OK
* @retval -1 Error
* @note: vector needs to be deallocated with free
*/
int
clicon_hash_keys(clicon_hash_t *hash,
- char ***vector,
- size_t *nkeys)
+ char ***vector,
+ size_t *nkeys)
{
int retval = -1;
int bkt;
@@ -341,47 +341,47 @@ clicon_hash_keys(clicon_hash_t *hash,
char **keys = NULL;
if (hash == NULL){
- clicon_err(OE_UNIX, EINVAL, "hash is NULL");
- return -1;
+ clicon_err(OE_UNIX, EINVAL, "hash is NULL");
+ return -1;
}
*nkeys = 0;
for (bkt = 0; bkt < HASH_SIZE; bkt++) {
- h = hash[bkt];
- do {
- if (h == NULL)
- break;
- tmp = realloc(keys, ((*nkeys)+1) * sizeof(char *));
- if (tmp == NULL){
- clicon_err(OE_UNIX, errno, "realloc");
- goto catch;
- }
- keys = tmp;
- keys[*nkeys] = h->h_key;
- (*nkeys)++;
- h = NEXTQ(clicon_hash_t, h);
- } while (h != hash[bkt]);
+ h = hash[bkt];
+ do {
+ if (h == NULL)
+ break;
+ tmp = realloc(keys, ((*nkeys)+1) * sizeof(char *));
+ if (tmp == NULL){
+ clicon_err(OE_UNIX, errno, "realloc");
+ goto catch;
+ }
+ keys = tmp;
+ keys[*nkeys] = h->h_key;
+ (*nkeys)++;
+ h = NEXTQ(clicon_hash_t, h);
+ } while (h != hash[bkt]);
}
if (vector){
- *vector = keys;
- keys = NULL;
+ *vector = keys;
+ keys = NULL;
}
retval = 0;
catch:
if (keys)
- free(keys);
+ free(keys);
return retval;
}
/*! Dump contents of hash to FILE pointer.
*
- * @param[in] hash Hash structure
- * @param[in] f FILE pointer for print output
+ * @param[in] hash Hash structure
+ * @param[in] f FILE pointer for print output
* @retval 0 OK
* @retval -1 Error
*/
int
clicon_hash_dump(clicon_hash_t *hash,
- FILE *f)
+ FILE *f)
{
int retval = -1;
int i;
@@ -391,18 +391,18 @@ clicon_hash_dump(clicon_hash_t *hash,
size_t vlen;
if (hash == NULL)
- goto ok;
+ goto ok;
if (clicon_hash_keys(hash, &keys, &klen) < 0)
- goto done;
+ goto done;
for(i = 0; i < klen; i++) {
- val = clicon_hash_value(hash, keys[i], &vlen);
- printf("%s =\t 0x%p , length %zu\n", keys[i], val, vlen);
+ val = clicon_hash_value(hash, keys[i], &vlen);
+ printf("%s =\t 0x%p , length %zu\n", keys[i], val, vlen);
}
ok:
retval = 0;
done:
if (keys)
- free(keys);
+ free(keys);
return retval;
}
diff --git a/lib/src/clixon_instance_id_parse.h b/lib/src/clixon_instance_id_parse.h
index df127f9f..3dafad19 100644
--- a/lib/src/clixon_instance_id_parse.h
+++ b/lib/src/clixon_instance_id_parse.h
@@ -68,4 +68,4 @@ int clixon_instance_id_parselex(void *);
int clixon_instance_id_parseparse(void *);
void clixon_instance_id_parseerror(void *, char*);
-#endif /* _CLIXON_INSTANCE_ID_PARSE_H_ */
+#endif /* _CLIXON_INSTANCE_ID_PARSE_H_ */
diff --git a/lib/src/clixon_instance_id_parse.l b/lib/src/clixon_instance_id_parse.l
index 2eb004a6..11b3729f 100644
--- a/lib/src/clixon_instance_id_parse.l
+++ b/lib/src/clixon_instance_id_parse.l
@@ -124,7 +124,7 @@ uint [1-9][0-9]*
[^\']+ { clixon_instance_id_parselval.string = strdup(yytext); return STRING; }
\' { BEGIN(_IY->iy_lex_state); return SQUOTE; }
-
+
%%
/*! Initialize scanner.
diff --git a/lib/src/clixon_instance_id_parse.y b/lib/src/clixon_instance_id_parse.y
index c81671e8..a150a44b 100644
--- a/lib/src/clixon_instance_id_parse.y
+++ b/lib/src/clixon_instance_id_parse.y
@@ -132,13 +132,13 @@
void
clixon_instance_id_parseerror(void *_iy,
- char *s)
+ char *s)
{
clicon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'",
- _IY->iy_name,
- _IY->iy_linenum ,
- s,
- clixon_instance_id_parsetext);
+ _IY->iy_name,
+ _IY->iy_linenum ,
+ s,
+ clixon_instance_id_parsetext);
return;
}
@@ -158,11 +158,11 @@ instance_id_parse_exit(clixon_instance_id_yacc *iy)
*/
static clixon_path *
path_append(clixon_path *list,
- clixon_path *new)
+ clixon_path *new)
{
clicon_debug(2, "%s()", __FUNCTION__);
if (new == NULL)
- return NULL;
+ return NULL;
ADDQ(new, list);
return list;
}
@@ -173,11 +173,11 @@ path_append(clixon_path *list,
*/
static clixon_path *
path_add_keyvalue(clixon_path *cp,
- cvec *cvk)
+ cvec *cvk)
{
clicon_debug(2, "%s()", __FUNCTION__);
if (cp == NULL)
- goto done;
+ goto done;
cp->cp_cvk = cvk;
done:
return cp;
@@ -185,24 +185,24 @@ path_add_keyvalue(clixon_path *cp,
static clixon_path *
path_new(char *prefix,
- char *id)
+ char *id)
{
clixon_path *cp = NULL;
clicon_debug(2, "%s(%s,%s)", __FUNCTION__, prefix, id);
if ((cp = malloc(sizeof(*cp))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(cp, 0, sizeof(*cp));
if (prefix)
- if ((cp->cp_prefix = strdup(prefix)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
+ if ((cp->cp_prefix = strdup(prefix)) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
if ((cp->cp_id = strdup(id)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
return cp;
done:
@@ -221,24 +221,24 @@ keyval_pos(char *uint)
clicon_debug(2, "%s(%s)", __FUNCTION__, uint);
if ((cvv = cvec_new(1)) == NULL) {
- clicon_err(OE_UNIX, errno, "cvec_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ goto done;
}
cv = cvec_i(cvv, 0);
cv_type_set(cv, CGV_UINT32);
if ((ret = cv_parse1(uint, cv, &reason)) < 0){
- clicon_err(OE_UNIX, errno, "cv_parse1");
- cvv = NULL;
- goto done;
+ clicon_err(OE_UNIX, errno, "cv_parse1");
+ cvv = NULL;
+ goto done;
}
if (ret == 0){
- clicon_err(OE_UNIX, errno, "cv_parse1: %s", reason);
- cvv = NULL;
- goto done;
+ clicon_err(OE_UNIX, errno, "cv_parse1: %s", reason);
+ cvv = NULL;
+ goto done;
}
done:
if (reason)
- free(reason);
+ free(reason);
return cvv;
}
@@ -250,20 +250,20 @@ keyval_pos(char *uint)
*/
static cvec *
keyval_add(cvec *cvv,
- cg_var *cv)
+ cg_var *cv)
{
clicon_debug(2, "%s()", __FUNCTION__);
if (cv == NULL)
- goto done;
+ goto done;
if (cvv == NULL &&
- (cvv = cvec_new(0)) == NULL) {
- clicon_err(OE_UNIX, errno, "cvec_new");
- goto done;
+ (cvv = cvec_new(0)) == NULL) {
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ goto done;
}
if (cvec_append_var(cvv, cv) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_append_var");
- cvv = NULL;
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_append_var");
+ cvv = NULL;
+ goto done;
}
cv_free(cv);
done:
@@ -280,18 +280,18 @@ keyval_set(char *name,
clicon_debug(2, "%s(%s=%s)", __FUNCTION__, name, val);
if ((cv = cv_new(CGV_STRING)) == NULL){
- clicon_err(OE_UNIX, errno, "cv_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cv_new");
+ goto done;
}
if (name && cv_name_set(cv, name) == NULL){
- clicon_err(OE_UNIX, errno, "cv_string_set");
- cv = NULL;
- goto done;
+ clicon_err(OE_UNIX, errno, "cv_string_set");
+ cv = NULL;
+ goto done;
}
if (cv_string_set(cv, val) == NULL){
- clicon_err(OE_UNIX, errno, "cv_string_set");
- cv = NULL;
- goto done;
+ clicon_err(OE_UNIX, errno, "cv_string_set");
+ cv = NULL;
+ goto done;
}
done:
return cv;
@@ -323,7 +323,7 @@ element : node_id element2 { $$ = path_add_keyvalue($1, $2);
node_id : IDENTIFIER { $$ = path_new(NULL, $1); free($1);
clicon_debug(3,"node_id = IDENTIFIER");}
| prefix COLON IDENTIFIER { $$ = path_new($1, $3); free($1); free($3);
- clicon_debug(3,"node_id = prefix : IDENTIFIER");}
+ clicon_debug(3,"node_id = prefix : IDENTIFIER");}
;
prefix : IDENTIFIER { $$=$1; clicon_debug(3,"prefix = IDENTIFIER");}
@@ -336,11 +336,11 @@ element2 : key_preds { $$=$1; clicon_debug(3,"element2 = key_preds");
leaf_list_pred : LSQBR leaf_list_pred_expr RSQBR
{ if (($$ = keyval_add(NULL, $2)) == NULL) YYABORT;
- clicon_debug(3,"leaf_list_pred = [ leaf_list_pred_expr ]"); }
+ clicon_debug(3,"leaf_list_pred = [ leaf_list_pred_expr ]"); }
;
leaf_list_pred_expr : DOT EQUAL qstring { $$ = keyval_set(".", $3); free($3);
- clicon_debug(3,"leaf_list_pred_expr = '.=' qstring"); }
+ clicon_debug(3,"leaf_list_pred_expr = '.=' qstring"); }
;
pos : LSQBR UINT RSQBR { $$ = keyval_pos($2); free($2);
diff --git a/lib/src/clixon_json.c b/lib/src/clixon_json.c
index 010ab2b3..7525f630 100644
--- a/lib/src/clixon_json.c
+++ b/lib/src/clixon_json.c
@@ -101,9 +101,9 @@ enum array_element_type{
enum childtype{
NULL_CHILD=0, /* eg no children. Translated to null if in
- * array or leaf terminal, and to {} if proper object, ie container.
- * anyxml/anydata?
- */
+ * array or leaf terminal, and to {} if proper object, ie container.
+ * anyxml/anydata?
+ */
BODY_CHILD, /* eg one child which is a body, eg 1 */
ANY_CHILD, /* eg or */
};
@@ -120,22 +120,22 @@ child_type(cxobj *x)
clen = xml_child_nr_notype(x, CX_ATTR);
if (xml_type(x) != CX_ELMNT)
- return -1; /* n/a */
+ return -1; /* n/a */
if (clen == 0)
- return NULL_CHILD;
+ return NULL_CHILD;
if (clen > 1)
- return ANY_CHILD;
+ return ANY_CHILD;
/* From here exactly one noattr child, get it */
xc = NULL;
while ((xc = xml_child_each(x, xc, -1)) != NULL)
- if (xml_type(xc) != CX_ATTR)
- break;
+ if (xml_type(xc) != CX_ATTR)
+ break;
if (xc == NULL)
- return -2; /* n/a */
+ return -2; /* n/a */
if (xml_child_nr_notype(xc, CX_ATTR) == 0 && xml_type(xc)==CX_BODY)
- return BODY_CHILD;
+ return BODY_CHILD;
else
- return ANY_CHILD;
+ return ANY_CHILD;
}
static char*
@@ -143,14 +143,14 @@ childtype2str(enum childtype lt)
{
switch(lt){
case NULL_CHILD:
- return "null";
- break;
+ return "null";
+ break;
case BODY_CHILD:
- return "body";
- break;
+ return "body";
+ break;
case ANY_CHILD:
- return "any";
- break;
+ return "any";
+ break;
}
return "";
}
@@ -160,23 +160,23 @@ arraytype2str(enum array_element_type lt)
{
switch(lt){
case NO_ARRAY:
- return "no";
- break;
+ return "no";
+ break;
case FIRST_ARRAY:
- return "first";
- break;
+ return "first";
+ break;
case MIDDLE_ARRAY:
- return "middle";
- break;
+ return "middle";
+ break;
case LAST_ARRAY:
- return "last";
- break;
+ return "last";
+ break;
case SINGLE_ARRAY:
- return "single";
- break;
+ return "single";
+ break;
case BODY_ARRAY:
- return "body";
- break;
+ return "body";
+ break;
}
return "";
}
@@ -193,8 +193,8 @@ arraytype2str(enum array_element_type lt)
*/
static enum array_element_type
array_eval(cxobj *xprev,
- cxobj *x,
- cxobj *xnext)
+ cxobj *x,
+ cxobj *xnext)
{
enum array_element_type arraytype = NO_ARRAY;
int eqprev=0;
@@ -205,39 +205,39 @@ array_eval(cxobj *xprev,
nsx = xml_find_type_value(x, NULL, "xmlns", CX_ATTR);
if (xml_type(x) != CX_ELMNT){
- arraytype = BODY_ARRAY;
- goto done;
+ arraytype = BODY_ARRAY;
+ goto done;
}
if (xnext &&
- xml_type(xnext)==CX_ELMNT &&
- strcmp(xml_name(x), xml_name(xnext))==0){
+ xml_type(xnext)==CX_ELMNT &&
+ strcmp(xml_name(x), xml_name(xnext))==0){
ns2 = xml_find_type_value(xnext, NULL, "xmlns", CX_ATTR);
- if ((!nsx && !ns2)
- || (nsx && ns2 && strcmp(nsx,ns2)==0))
- eqnext++;
+ if ((!nsx && !ns2)
+ || (nsx && ns2 && strcmp(nsx,ns2)==0))
+ eqnext++;
}
if (xprev &&
- xml_type(xprev)==CX_ELMNT &&
- strcmp(xml_name(x),xml_name(xprev))==0){
- ns2 = xml_find_type_value(xprev, NULL, "xmlns", CX_ATTR);
- if ((!nsx && !ns2)
- || (nsx && ns2 && strcmp(nsx,ns2)==0))
- eqprev++;
+ xml_type(xprev)==CX_ELMNT &&
+ strcmp(xml_name(x),xml_name(xprev))==0){
+ ns2 = xml_find_type_value(xprev, NULL, "xmlns", CX_ATTR);
+ if ((!nsx && !ns2)
+ || (nsx && ns2 && strcmp(nsx,ns2)==0))
+ eqprev++;
}
if (eqprev && eqnext)
- arraytype = MIDDLE_ARRAY;
+ arraytype = MIDDLE_ARRAY;
else if (eqprev)
- arraytype = LAST_ARRAY;
+ arraytype = LAST_ARRAY;
else if (eqnext)
- arraytype = FIRST_ARRAY;
+ arraytype = FIRST_ARRAY;
else if ((ys = xml_spec(x)) != NULL) {
- if (yang_keyword_get(ys) == Y_LIST || yang_keyword_get(ys) == Y_LEAF_LIST)
- arraytype = SINGLE_ARRAY;
- else
- arraytype = NO_ARRAY;
+ if (yang_keyword_get(ys) == Y_LIST || yang_keyword_get(ys) == Y_LEAF_LIST)
+ arraytype = SINGLE_ARRAY;
+ else
+ arraytype = NO_ARRAY;
}
else
- arraytype = NO_ARRAY;
+ arraytype = NO_ARRAY;
done:
return arraytype;
}
@@ -248,7 +248,7 @@ array_eval(cxobj *xprev,
*/
static int
json_str_escape_cdata(cbuf *cb,
- char *str)
+ char *str)
{
int retval = -1;
int i;
@@ -259,40 +259,40 @@ json_str_escape_cdata(cbuf *cb,
len = strlen(str);
for (i=0; i", strlen("]]>")) == 0){
- esc=0;
- i += strlen("]]>")-1;
- }
- else
- cprintf(cb, "%c", str[i]);
- break;
+ case '<':
+ if (!esc &&
+ strncmp(&str[i], "", strlen("]]>")) == 0){
+ esc=0;
+ i += strlen("]]>")-1;
+ }
+ else
+ cprintf(cb, "%c", str[i]);
+ break;
#endif /* JSON_CDATA_STRIP */
- default: /* fall thru */
- cprintf(cb, "%c", str[i]);
- break;
- }
+ default: /* fall thru */
+ cprintf(cb, "%c", str[i]);
+ break;
+ }
retval = 0;
// done:
return retval;
@@ -311,8 +311,8 @@ json_str_escape_cdata(cbuf *cb,
*/
static int
json2xml_decode_identityref(cxobj *x,
- yang_stmt *y,
- cxobj **xerr)
+ yang_stmt *y,
+ cxobj **xerr)
{
int retval = -1;
char *ns;
@@ -330,80 +330,80 @@ json2xml_decode_identityref(cxobj *x,
clicon_debug(1, "%s", __FUNCTION__);
yspec = ys_spec(y);
if ((xb = xml_body_get(x)) == NULL)
- goto ok;
+ goto ok;
body = xml_value(xb);
if (nodeid_split(body, &prefix, &id) < 0)
- goto done;
+ goto done;
/* prefix is a module name -> find module */
if (prefix){
- if ((ymod = yang_find_module_by_name(yspec, prefix)) != NULL){
- ns = yang_find_mynamespace(ymod);
- /* Is this namespace in the xml context?
- * (yes) use its prefix (unless it is NULL)
- * (no) insert a xmlns: statement
- * Get the whole namespace context from x
- */
- if (xml_nsctx_node(x, &nsc) < 0)
- goto done;
- clicon_debug(1, "%s prefix:%s body:%s namespace:%s",
- __FUNCTION__, prefix, body, ns);
- if (!xml_nsctx_get_prefix(nsc, ns, &prefix2)){
- /* (no) insert a xmlns: statement
- * Get yang prefix from import statement of my mod */
- if (yang_find_prefix_by_namespace(y, ns, &prefix2) == 0){
+ if ((ymod = yang_find_module_by_name(yspec, prefix)) != NULL){
+ ns = yang_find_mynamespace(ymod);
+ /* Is this namespace in the xml context?
+ * (yes) use its prefix (unless it is NULL)
+ * (no) insert a xmlns: statement
+ * Get the whole namespace context from x
+ */
+ if (xml_nsctx_node(x, &nsc) < 0)
+ goto done;
+ clicon_debug(1, "%s prefix:%s body:%s namespace:%s",
+ __FUNCTION__, prefix, body, ns);
+ if (!xml_nsctx_get_prefix(nsc, ns, &prefix2)){
+ /* (no) insert a xmlns: statement
+ * Get yang prefix from import statement of my mod */
+ if (yang_find_prefix_by_namespace(y, ns, &prefix2) == 0){
#ifndef IDENTITYREF_KLUDGE
- /* Just get the prefix from the module's own namespace */
- if (xerr && netconf_unknown_namespace_xml(xerr, "application",
- ns,
- "No local prefix corresponding to namespace") < 0)
- goto done;
- goto fail;
+ /* Just get the prefix from the module's own namespace */
+ if (xerr && netconf_unknown_namespace_xml(xerr, "application",
+ ns,
+ "No local prefix corresponding to namespace") < 0)
+ goto done;
+ goto fail;
#endif
- }
- /* if prefix2 is NULL here, we get the canonical prefix */
- if (prefix2 == NULL)
- prefix2 = yang_find_myprefix(ymod);
- /* Add "xmlns:prefix2=namespace" */
- if ((xa = xml_new(prefix2, x, CX_ATTR)) == NULL)
- goto done;
- if (xml_prefix_set(xa, "xmlns") < 0)
- goto done;
- if (xml_value_set(xa, ns) < 0)
- goto done;
- }
- /* Here prefix2 is valid and can be NULL
- Change body prefix to prefix2:id */
- if ((cbv = cbuf_new()) == NULL){
- clicon_err(OE_JSON, errno, "cbuf_new");
- goto done;
- }
- if (prefix2)
- cprintf(cbv, "%s:%s", prefix2, id);
- else
- cprintf(cbv, "%s", id);
+ }
+ /* if prefix2 is NULL here, we get the canonical prefix */
+ if (prefix2 == NULL)
+ prefix2 = yang_find_myprefix(ymod);
+ /* Add "xmlns:prefix2=namespace" */
+ if ((xa = xml_new(prefix2, x, CX_ATTR)) == NULL)
+ goto done;
+ if (xml_prefix_set(xa, "xmlns") < 0)
+ goto done;
+ if (xml_value_set(xa, ns) < 0)
+ goto done;
+ }
+ /* Here prefix2 is valid and can be NULL
+ Change body prefix to prefix2:id */
+ if ((cbv = cbuf_new()) == NULL){
+ clicon_err(OE_JSON, errno, "cbuf_new");
+ goto done;
+ }
+ if (prefix2)
+ cprintf(cbv, "%s:%s", prefix2, id);
+ else
+ cprintf(cbv, "%s", id);
- if (xml_value_set(xb, cbuf_get(cbv)) < 0)
- goto done;
- }
- else{
- if (xerr && netconf_unknown_namespace_xml(xerr, "application",
- prefix,
- "No module corresponding to prefix") < 0)
- goto done;
- goto fail;
- }
+ if (xml_value_set(xb, cbuf_get(cbv)) < 0)
+ goto done;
+ }
+ else{
+ if (xerr && netconf_unknown_namespace_xml(xerr, "application",
+ prefix,
+ "No module corresponding to prefix") < 0)
+ goto done;
+ goto fail;
+ }
} /* prefix */
ok:
retval = 1;
done:
if (prefix)
- free(prefix);
+ free(prefix);
if (id)
- free(id);
+ free(id);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (cbv)
- cbuf_free(cbv);
+ cbuf_free(cbv);
return retval;
fail:
retval = 0;
@@ -425,7 +425,7 @@ json2xml_decode_identityref(cxobj *x,
*/
int
json2xml_decode(cxobj *x,
- cxobj **xerr)
+ cxobj **xerr)
{
int retval = -1;
yang_stmt *y;
@@ -435,29 +435,29 @@ json2xml_decode(cxobj *x,
yang_stmt *ytype = NULL;
if ((y = xml_spec(x)) != NULL){
- keyword = yang_keyword_get(y);
- if (keyword == Y_LEAF || keyword == Y_LEAF_LIST){
- if (yang_type_get(y, NULL, &ytype, NULL, NULL, NULL, NULL, NULL) < 0)
- goto done;
+ keyword = yang_keyword_get(y);
+ if (keyword == Y_LEAF || keyword == Y_LEAF_LIST){
+ if (yang_type_get(y, NULL, &ytype, NULL, NULL, NULL, NULL, NULL) < 0)
+ goto done;
- if (ytype){
- if (strcmp(yang_argument_get(ytype), "identityref")==0){
- if ((ret = json2xml_decode_identityref(x, y, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- else if (strcmp(yang_argument_get(ytype), "empty")==0)
- ; /* dont need to do anything */
- }
- }
+ if (ytype){
+ if (strcmp(yang_argument_get(ytype), "identityref")==0){
+ if ((ret = json2xml_decode_identityref(x, y, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ else if (strcmp(yang_argument_get(ytype), "empty")==0)
+ ; /* dont need to do anything */
+ }
+ }
}
xc = NULL;
while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL){
- if ((ret = json2xml_decode(xc, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = json2xml_decode(xc, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
retval = 1;
done:
@@ -475,9 +475,9 @@ json2xml_decode(cxobj *x,
*/
static int
xml2json_encode_identityref(cxobj *xb,
- char *body,
- yang_stmt *yp,
- cbuf *cb)
+ char *body,
+ yang_stmt *yp,
+ cbuf *cb)
{
int retval = -1;
char *prefix = NULL;
@@ -491,10 +491,10 @@ xml2json_encode_identityref(cxobj *xb,
my_ymod = ys_module(yp);
yspec = ys_spec(yp);
if (nodeid_split(body, &prefix, &id) < 0)
- goto done;
+ goto done;
/* prefix is xml local -> get namespace */
if (xml2ns(xb, prefix, &namespace) < 0)
- goto done;
+ goto done;
/* We got the namespace, now get the module */
// clicon_debug(1, "%s body:%s prefix:%s namespace:%s", __FUNCTION__, body, prefix, namespace);
#ifdef IDENTITYREF_KLUDGE
@@ -503,31 +503,31 @@ xml2json_encode_identityref(cxobj *xb,
* xmlns that should be there, as a kludge we search for its (own)
* prefix in mymodule.
*/
- if ((ymod = yang_find_module_by_prefix_yspec(yspec, prefix)) != NULL)
- cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
- else
- cprintf(cb, "%s", id);
+ if ((ymod = yang_find_module_by_prefix_yspec(yspec, prefix)) != NULL)
+ cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
+ else
+ cprintf(cb, "%s", id);
}
else
#endif
- {
+ {
if ((ymod = yang_find_module_by_namespace(yspec, namespace)) != NULL){
-
- if (ymod == my_ymod)
- cprintf(cb, "%s", id);
- else{
- cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
- }
+
+ if (ymod == my_ymod)
+ cprintf(cb, "%s", id);
+ else{
+ cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
+ }
}
else
- cprintf(cb, "%s", id);
- }
+ cprintf(cb, "%s", id);
+ }
retval = 0;
done:
if (prefix)
- free(prefix);
+ free(prefix);
if (id)
- free(id);
+ free(id);
return retval;
}
@@ -539,9 +539,9 @@ xml2json_encode_identityref(cxobj *xb,
*/
static int
xml2json_encode_leafs(cxobj *xb,
- cxobj *xp,
- yang_stmt *yp,
- cbuf *cb0)
+ cxobj *xp,
+ yang_stmt *yp,
+ cbuf *cb0)
{
int retval = -1;
enum rfc_6020 keyword;
@@ -554,103 +554,103 @@ xml2json_encode_leafs(cxobj *xb,
cbuf *cb = NULL; /* the variable itself */
if ((cb = cbuf_new()) ==NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
body = xb?xml_value(xb):NULL;
if (yp == NULL){
- cprintf(cb, "%s", body?body:"null");
- goto ok; /* unknown */
+ cprintf(cb, "%s", body?body:"null");
+ goto ok; /* unknown */
}
keyword = yang_keyword_get(yp);
switch (keyword){
case Y_LEAF:
case Y_LEAF_LIST:
- if (yang_type_get(yp, &origtype, &ytype, NULL, NULL, NULL, NULL, NULL) < 0)
- goto done;
- restype = ytype?yang_argument_get(ytype):NULL;
- cvtype = yang_type2cv(yp);
- switch (cvtype){
- case CGV_STRING:
- case CGV_REST:
- if (body==NULL)
- ; /* empty: "" */
- else if (ytype){
- if (strcmp(restype, "identityref")==0){
- if (xml2json_encode_identityref(xb, body, yp, cb) < 0)
- goto done;
- }
- else{
- cprintf(cb, "%s", body);
- }
- }
- else
- cprintf(cb, "%s", body);
- break;
- case CGV_INT64:
- case CGV_UINT64:
- case CGV_DEC64:
- // [RFC7951] JSON Encoding of YANG Data
- // 6.1 Numeric Types - A value of the "int64", "uint64", or "decimal64" type is represented as a JSON string
- if (yang_keyword_get(yp) == Y_LEAF_LIST && xml_child_nr_type(xml_parent(xp), CX_ELMNT) == 1) {
- cprintf(cb, "[%s]", body);
- }
- else {
- cprintf(cb, "%s", body);
- }
- quote = 1;
- break;
- case CGV_INT8:
- case CGV_INT16:
- case CGV_INT32:
- case CGV_UINT8:
- case CGV_UINT16:
- case CGV_UINT32:
- case CGV_BOOL:
- cprintf(cb, "%s", body);
- quote = 0;
- break;
- case CGV_VOID:
- /* special case YANG empty type */
- if (body == NULL && strcmp(restype, "empty")==0){
- quote = 0;
- if (keyword == Y_LEAF)
- cprintf(cb, "[null]");
- else if (keyword == Y_LEAF_LIST && strcmp(restype, "empty") == 0)
- cprintf(cb, "[null]");
- else
- cprintf(cb, "null");
- }
- break;
- default:
- if (body)
- cprintf(cb, "%s", body);
- else
- cprintf(cb, "{}"); /* dont know */
- }
- break;
+ if (yang_type_get(yp, &origtype, &ytype, NULL, NULL, NULL, NULL, NULL) < 0)
+ goto done;
+ restype = ytype?yang_argument_get(ytype):NULL;
+ cvtype = yang_type2cv(yp);
+ switch (cvtype){
+ case CGV_STRING:
+ case CGV_REST:
+ if (body==NULL)
+ ; /* empty: "" */
+ else if (ytype){
+ if (strcmp(restype, "identityref")==0){
+ if (xml2json_encode_identityref(xb, body, yp, cb) < 0)
+ goto done;
+ }
+ else{
+ cprintf(cb, "%s", body);
+ }
+ }
+ else
+ cprintf(cb, "%s", body);
+ break;
+ case CGV_INT64:
+ case CGV_UINT64:
+ case CGV_DEC64:
+ // [RFC7951] JSON Encoding of YANG Data
+ // 6.1 Numeric Types - A value of the "int64", "uint64", or "decimal64" type is represented as a JSON string
+ if (yang_keyword_get(yp) == Y_LEAF_LIST && xml_child_nr_type(xml_parent(xp), CX_ELMNT) == 1) {
+ cprintf(cb, "[%s]", body);
+ }
+ else {
+ cprintf(cb, "%s", body);
+ }
+ quote = 1;
+ break;
+ case CGV_INT8:
+ case CGV_INT16:
+ case CGV_INT32:
+ case CGV_UINT8:
+ case CGV_UINT16:
+ case CGV_UINT32:
+ case CGV_BOOL:
+ cprintf(cb, "%s", body);
+ quote = 0;
+ break;
+ case CGV_VOID:
+ /* special case YANG empty type */
+ if (body == NULL && strcmp(restype, "empty")==0){
+ quote = 0;
+ if (keyword == Y_LEAF)
+ cprintf(cb, "[null]");
+ else if (keyword == Y_LEAF_LIST && strcmp(restype, "empty") == 0)
+ cprintf(cb, "[null]");
+ else
+ cprintf(cb, "null");
+ }
+ break;
+ default:
+ if (body)
+ cprintf(cb, "%s", body);
+ else
+ cprintf(cb, "{}"); /* dont know */
+ }
+ break;
default:
- cprintf(cb, "%s", body);
- break;
+ cprintf(cb, "%s", body);
+ break;
}
ok:
/* write into original cb0
* includign quoting and encoding
*/
if (quote){
- cprintf(cb0, "\"");
- json_str_escape_cdata(cb0, cbuf_get(cb));
+ cprintf(cb0, "\"");
+ json_str_escape_cdata(cb0, cbuf_get(cb));
}
else
- cprintf(cb0, "%s", cbuf_get(cb));
+ cprintf(cb0, "%s", cbuf_get(cb));
if (quote)
- cprintf(cb0, "\"");
+ cprintf(cb0, "\"");
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (origtype)
- free(origtype);
+ free(origtype);
return retval;
}
@@ -661,36 +661,36 @@ xml2json_encode_leafs(cxobj *xb,
*/
static int
nullchild(cbuf *cb,
- cxobj *x,
- yang_stmt *y)
+ cxobj *x,
+ yang_stmt *y)
{
int retval = -1;
if (y == NULL){
- /* This is very problematic.
- * RFC 7951 explicitly forbids "null" to be used unless for empty types in [null]
- */
- cprintf(cb, "{}");
+ /* This is very problematic.
+ * RFC 7951 explicitly forbids "null" to be used unless for empty types in [null]
+ */
+ cprintf(cb, "{}");
}
else{
- switch (yang_keyword_get(y)){
- case Y_ANYXML:
- case Y_ANYDATA:
- case Y_CONTAINER:
- cprintf(cb, "{}");
- break;
- case Y_LEAF:
- case Y_LEAF_LIST:
- if (xml2json_encode_leafs(NULL, x, y, cb) < 0)
- goto done;
- break;
- default:
- /* This is very problematic.
- * RFC 7951 explicitly forbids "null" to be used unless for empty types in [null]
- */
- cprintf(cb, "{}");
- break;
- }
+ switch (yang_keyword_get(y)){
+ case Y_ANYXML:
+ case Y_ANYDATA:
+ case Y_CONTAINER:
+ cprintf(cb, "{}");
+ break;
+ case Y_LEAF:
+ case Y_LEAF_LIST:
+ if (xml2json_encode_leafs(NULL, x, y, cb) < 0)
+ goto done;
+ break;
+ default:
+ /* This is very problematic.
+ * RFC 7951 explicitly forbids "null" to be used unless for empty types in [null]
+ */
+ cprintf(cb, "{}");
+ break;
+ }
}
retval = 0;
done:
@@ -715,27 +715,27 @@ nullchild(cbuf *cb,
*/
static int
json_metadata_encoding(cbuf *cb,
- cxobj *x,
- int level,
- int pretty,
- char *prefix,
- char *name,
- char *modname2,
- char *name2,
- char *val,
- int list)
+ cxobj *x,
+ int level,
+ int pretty,
+ char *prefix,
+ char *name,
+ char *modname2,
+ char *name2,
+ char *val,
+ int list)
{
cprintf(cb, ",\"@");
if (prefix)
- cprintf(cb, "%s:", prefix);
+ cprintf(cb, "%s:", prefix);
cprintf(cb, "%s\":", name);
if (list)
- cprintf(cb, "[");
+ cprintf(cb, "[");
cprintf(cb, "%*s", pretty?((level+1)*JSON_INDENT):0, "{");
cprintf(cb, "\"%s:%s\":%s", modname2, name2, val);
cprintf(cb, "%*s", pretty?((level+1)*JSON_INDENT):0, "}");
if (list)
- cprintf(cb, "%*s", pretty?(level*JSON_INDENT):0, "]");
+ cprintf(cb, "%*s", pretty?(level*JSON_INDENT):0, "]");
return 0;
}
@@ -760,12 +760,12 @@ json_metadata_encoding(cbuf *cb,
*/
static int
xml2json_encode_attr(cxobj *xa,
- cxobj *xp,
- yang_stmt *yp,
- int level,
- int pretty,
- char *modname,
- cbuf *metacb)
+ cxobj *xp,
+ yang_stmt *yp,
+ int level,
+ int pretty,
+ char *modname,
+ cbuf *metacb)
{
int retval = -1;
int ismeta = 0;
@@ -774,34 +774,34 @@ xml2json_encode_attr(cxobj *xa,
enum rfc_6020 ykeyw;
if (xml2ns(xa, xml_prefix(xa), &namespace) < 0)
- goto done;
+ goto done;
/* Check for (1) registered meta-data */
if (namespace != NULL && yp){
- ykeyw = yang_keyword_get(yp);
- if ((ymod = yang_find_module_by_namespace(ys_spec(yp), namespace)) != NULL){
- if (yang_metadata_annotation_check(xa, ymod, &ismeta) < 0)
- goto done;
- if (ismeta)
- if (json_metadata_encoding(metacb, xp, level, pretty,
- modname, xml_name(xp),
- yang_argument_get(ymod),
- xml_name(xa),
- xml_value(xa),
- ykeyw == Y_LEAF_LIST || ykeyw == Y_LIST) < 0)
- goto done;
- }
- /* Check for (2) assigned - hardcoded for now */
- else if (strcmp(namespace, "urn:ietf:params:xml:ns:netconf:default:1.0") == 0 &&
- strcmp(xml_name(xa), "default") == 0){
- /* RFC 7952 / RFC 8040 defaults attribute */
- if (json_metadata_encoding(metacb, xp, level, pretty,
- modname, xml_name(xp),
- "ietf-netconf-with-defaults",
- xml_name(xa),
- xml_value(xa),
- ykeyw == Y_LEAF_LIST || ykeyw == Y_LIST) < 0)
- goto done;
- }
+ ykeyw = yang_keyword_get(yp);
+ if ((ymod = yang_find_module_by_namespace(ys_spec(yp), namespace)) != NULL){
+ if (yang_metadata_annotation_check(xa, ymod, &ismeta) < 0)
+ goto done;
+ if (ismeta)
+ if (json_metadata_encoding(metacb, xp, level, pretty,
+ modname, xml_name(xp),
+ yang_argument_get(ymod),
+ xml_name(xa),
+ xml_value(xa),
+ ykeyw == Y_LEAF_LIST || ykeyw == Y_LIST) < 0)
+ goto done;
+ }
+ /* Check for (2) assigned - hardcoded for now */
+ else if (strcmp(namespace, "urn:ietf:params:xml:ns:netconf:default:1.0") == 0 &&
+ strcmp(xml_name(xa), "default") == 0){
+ /* RFC 7952 / RFC 8040 defaults attribute */
+ if (json_metadata_encoding(metacb, xp, level, pretty,
+ modname, xml_name(xp),
+ "ietf-netconf-with-defaults",
+ xml_name(xa),
+ xml_value(xa),
+ ykeyw == Y_LEAF_LIST || ykeyw == Y_LIST) < 0)
+ goto done;
+ }
}
retval = 0;
done:
@@ -848,13 +848,13 @@ xml2json_encode_attr(cxobj *xa,
*/
static int
xml2json1_cbuf(cbuf *cb,
- cxobj *x,
- enum array_element_type arraytype,
- int level,
- int pretty,
- int flat,
- char *modname0,
- cbuf *metacbp)
+ cxobj *x,
+ enum array_element_type arraytype,
+ int level,
+ int pretty,
+ int flat,
+ char *modname0,
+ cbuf *metacbp)
{
int retval = -1;
int i;
@@ -869,101 +869,101 @@ xml2json1_cbuf(cbuf *cb,
cbuf *metacbc = NULL;
if ((ys = xml_spec(x)) != NULL){
- if (ys_real_module(ys, &ymod) < 0)
- goto done;
- modname = yang_argument_get(ymod);
- /* Special case for ietf-netconf -> ietf-restconf translation
- * A special case is for return data on the form {"data":...}
- * See also json_xmlns_translate()
- */
- if (strcmp(modname, "ietf-netconf") == 0)
- modname = "ietf-restconf";
- if (modname0 && strcmp(modname, modname0) == 0)
- modname=NULL;
- else
- modname0 = modname; /* modname0 is ancestor ns passed to child */
+ if (ys_real_module(ys, &ymod) < 0)
+ goto done;
+ modname = yang_argument_get(ymod);
+ /* Special case for ietf-netconf -> ietf-restconf translation
+ * A special case is for return data on the form {"data":...}
+ * See also json_xmlns_translate()
+ */
+ if (strcmp(modname, "ietf-netconf") == 0)
+ modname = "ietf-restconf";
+ if (modname0 && strcmp(modname, modname0) == 0)
+ modname=NULL;
+ else
+ modname0 = modname; /* modname0 is ancestor ns passed to child */
}
childt = child_type(x);
if (pretty==2)
- cprintf(cb, "#%s_array, %s_child ",
- arraytype2str(arraytype),
- childtype2str(childt));
+ cprintf(cb, "#%s_array, %s_child ",
+ arraytype2str(arraytype),
+ childtype2str(childt));
switch(arraytype){
case BODY_ARRAY: /* Only place in fn where body is printed (except nullchild) */
- xp = xml_parent(x);
- if (xml2json_encode_leafs(x, xp, xml_spec(xp), cb) < 0)
- goto done;
- break;
+ xp = xml_parent(x);
+ if (xml2json_encode_leafs(x, xp, xml_spec(xp), cb) < 0)
+ goto done;
+ break;
case NO_ARRAY:
- if (!flat){
- cprintf(cb, "%*s\"", pretty?(level*JSON_INDENT):0, "");
- if (modname)
- cprintf(cb, "%s:", modname);
- cprintf(cb, "%s\":%s", xml_name(x), pretty?" ":"");
- }
- switch (childt){
- case NULL_CHILD:
- if (nullchild(cb, x, ys) < 0)
- goto done;
- break;
- case BODY_CHILD:
- break;
- case ANY_CHILD:
- cprintf(cb, "{%s", pretty?"\n":"");
- break;
- default:
- break;
- }
- break;
+ if (!flat){
+ cprintf(cb, "%*s\"", pretty?(level*JSON_INDENT):0, "");
+ if (modname)
+ cprintf(cb, "%s:", modname);
+ cprintf(cb, "%s\":%s", xml_name(x), pretty?" ":"");
+ }
+ switch (childt){
+ case NULL_CHILD:
+ if (nullchild(cb, x, ys) < 0)
+ goto done;
+ break;
+ case BODY_CHILD:
+ break;
+ case ANY_CHILD:
+ cprintf(cb, "{%s", pretty?"\n":"");
+ break;
+ default:
+ break;
+ }
+ break;
case FIRST_ARRAY:
case SINGLE_ARRAY:
- cprintf(cb, "%*s\"", pretty?(level*JSON_INDENT):0, "");
- if (modname)
- cprintf(cb, "%s:", modname);
- cprintf(cb, "%s\":%s", xml_name(x), pretty?" ":"");
- level++;
- cprintf(cb, "[%s%*s",
- pretty?"\n":"",
- pretty?(level*JSON_INDENT):0, "");
- switch (childt){
- case NULL_CHILD:
- if (nullchild(cb, x, ys) < 0)
- goto done;
- break;
- case BODY_CHILD:
- break;
- case ANY_CHILD:
- cprintf(cb, "{%s", pretty?"\n":"");
- break;
- default:
- break;
- }
- break;
+ cprintf(cb, "%*s\"", pretty?(level*JSON_INDENT):0, "");
+ if (modname)
+ cprintf(cb, "%s:", modname);
+ cprintf(cb, "%s\":%s", xml_name(x), pretty?" ":"");
+ level++;
+ cprintf(cb, "[%s%*s",
+ pretty?"\n":"",
+ pretty?(level*JSON_INDENT):0, "");
+ switch (childt){
+ case NULL_CHILD:
+ if (nullchild(cb, x, ys) < 0)
+ goto done;
+ break;
+ case BODY_CHILD:
+ break;
+ case ANY_CHILD:
+ cprintf(cb, "{%s", pretty?"\n":"");
+ break;
+ default:
+ break;
+ }
+ break;
case MIDDLE_ARRAY:
case LAST_ARRAY:
- level++;
- cprintf(cb, "%*s",
- pretty?(level*JSON_INDENT):0, "");
- switch (childt){
- case NULL_CHILD:
- if (nullchild(cb, x, ys) < 0)
- goto done;
- break;
- case BODY_CHILD:
- break;
- case ANY_CHILD:
- cprintf(cb, "{%s", pretty?"\n":"");
- break;
- default:
- break;
- }
- break;
+ level++;
+ cprintf(cb, "%*s",
+ pretty?(level*JSON_INDENT):0, "");
+ switch (childt){
+ case NULL_CHILD:
+ if (nullchild(cb, x, ys) < 0)
+ goto done;
+ break;
+ case BODY_CHILD:
+ break;
+ case ANY_CHILD:
+ cprintf(cb, "{%s", pretty?"\n":"");
+ break;
+ default:
+ break;
+ }
+ break;
default:
- break;
+ break;
}
if ((metacbc = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
/* Check for typed sub-body if:
* arraytype=* but child-type is BODY_CHILD
@@ -971,92 +971,92 @@ xml2json1_cbuf(cbuf *cb,
*/
commas = xml_child_nr_notype(x, CX_ATTR) - 1;
for (i=0; i 0) {
- cprintf(cb, ",%s", pretty?"\n":"");
- --commas;
- }
+ xc = xml_child_i(x, i);
+ if (xml_type(xc) == CX_ATTR){
+ if (metacbp &&
+ xml2json_encode_attr(xc, x, ys, level, pretty, modname, metacbp) < 0)
+ goto done;
+ continue;
+ }
+ xc_arraytype = array_eval(i?xml_child_i(x,i-1):NULL,
+ xc,
+ xml_child_i(x, i+1));
+ if (xml2json1_cbuf(cb,
+ xc,
+ xc_arraytype,
+ level+1, pretty, 0, modname0,
+ metacbc) < 0)
+ goto done;
+ if (commas > 0) {
+ cprintf(cb, ",%s", pretty?"\n":"");
+ --commas;
+ }
}
if (cbuf_len(metacbc)){
- cprintf(cb, "%s", cbuf_get(metacbc));
+ cprintf(cb, "%s", cbuf_get(metacbc));
}
switch (arraytype){
case BODY_ARRAY:
- break;
+ break;
case NO_ARRAY:
- switch (childt){
- case NULL_CHILD:
- case BODY_CHILD:
- break;
- case ANY_CHILD:
- cprintf(cb, "%s%*s}",
- pretty?"\n":"",
- pretty?(level*JSON_INDENT):0, "");
- break;
- default:
- break;
- }
- level--;
- break;
+ switch (childt){
+ case NULL_CHILD:
+ case BODY_CHILD:
+ break;
+ case ANY_CHILD:
+ cprintf(cb, "%s%*s}",
+ pretty?"\n":"",
+ pretty?(level*JSON_INDENT):0, "");
+ break;
+ default:
+ break;
+ }
+ level--;
+ break;
case FIRST_ARRAY:
case MIDDLE_ARRAY:
- switch (childt){
- case NULL_CHILD:
- case BODY_CHILD:
- break;
- case ANY_CHILD:
- cprintf(cb, "%s%*s}",
- pretty?"\n":"",
- pretty?(level*JSON_INDENT):0, "");
- level--;
- break;
- default:
- break;
- }
- break;
+ switch (childt){
+ case NULL_CHILD:
+ case BODY_CHILD:
+ break;
+ case ANY_CHILD:
+ cprintf(cb, "%s%*s}",
+ pretty?"\n":"",
+ pretty?(level*JSON_INDENT):0, "");
+ level--;
+ break;
+ default:
+ break;
+ }
+ break;
case SINGLE_ARRAY:
case LAST_ARRAY:
- switch (childt){
- case NULL_CHILD:
- case BODY_CHILD:
- cprintf(cb, "%s",pretty?"\n":"");
- break;
- case ANY_CHILD:
- cprintf(cb, "%s%*s}",
- pretty?"\n":"",
- pretty?(level*JSON_INDENT):0, "");
- cprintf(cb, "%s",pretty?"\n":"");
- level--;
- break;
- default:
- break;
- }
- cprintf(cb, "%*s]",
- pretty?(level*JSON_INDENT):0,"");
- break;
+ switch (childt){
+ case NULL_CHILD:
+ case BODY_CHILD:
+ cprintf(cb, "%s",pretty?"\n":"");
+ break;
+ case ANY_CHILD:
+ cprintf(cb, "%s%*s}",
+ pretty?"\n":"",
+ pretty?(level*JSON_INDENT):0, "");
+ cprintf(cb, "%s",pretty?"\n":"");
+ level--;
+ break;
+ default:
+ break;
+ }
+ cprintf(cb, "%*s]",
+ pretty?(level*JSON_INDENT):0,"");
+ break;
default:
- break;
+ break;
}
retval = 0;
done:
if (metacbc)
- cbuf_free(metacbc);
+ cbuf_free(metacbc);
return retval;
}
@@ -1077,51 +1077,51 @@ xml2json1_cbuf(cbuf *cb,
*/
static int
xml2json_cbuf1(cbuf *cb,
- cxobj *x,
- int pretty,
- int autocliext)
+ cxobj *x,
+ int pretty,
+ int autocliext)
{
int retval = 1;
int level = 0;
yang_stmt *y;
enum array_element_type arraytype = NO_ARRAY;
int exist = 0;
-
+
y = xml_spec(x);
if (autocliext && y != NULL) {
- if (yang_extension_value(y, "hide-show", CLIXON_AUTOCLI_NS, &exist, NULL) < 0)
- goto done;
- if (exist)
- goto ok;
+ if (yang_extension_value(y, "hide-show", CLIXON_AUTOCLI_NS, &exist, NULL) < 0)
+ goto done;
+ if (exist)
+ goto ok;
}
cprintf(cb, "%*s{%s",
- pretty?level*JSON_INDENT:0,"",
- pretty?"\n":"");
+ pretty?level*JSON_INDENT:0,"",
+ pretty?"\n":"");
if (y != NULL){
- switch (yang_keyword_get(y)){
- case Y_LEAF_LIST:
- case Y_LIST:
- arraytype = SINGLE_ARRAY;
- break;
- default:
- arraytype = NO_ARRAY;
- break;
- }
+ switch (yang_keyword_get(y)){
+ case Y_LEAF_LIST:
+ case Y_LIST:
+ arraytype = SINGLE_ARRAY;
+ break;
+ default:
+ arraytype = NO_ARRAY;
+ break;
+ }
}
if (xml2json1_cbuf(cb,
- x,
- arraytype,
- level+1,
- pretty,
- 0,
- NULL, /* ancestor modname / namespace */
- NULL) < 0)
- goto done;
+ x,
+ arraytype,
+ level+1,
+ pretty,
+ 0,
+ NULL, /* ancestor modname / namespace */
+ NULL) < 0)
+ goto done;
cprintf(cb, "%s%*s}%s",
- pretty?"\n":"",
- pretty?level*JSON_INDENT:0,"",
- pretty?"\n":"");
+ pretty?"\n":"",
+ pretty?level*JSON_INDENT:0,"",
+ pretty?"\n":"");
ok:
retval = 0;
done:
@@ -1150,23 +1150,23 @@ xml2json_cbuf1(cbuf *cb,
*/
int
clixon_json2cbuf(cbuf *cb,
- cxobj *xt,
- int pretty,
- int skiptop,
- int autocliext)
+ cxobj *xt,
+ int pretty,
+ int skiptop,
+ int autocliext)
{
int retval = -1;
cxobj *xc;
if (skiptop){
- xc = NULL;
- while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL)
- if (xml2json_cbuf1(cb, xc, pretty, autocliext) < 0)
- goto done;
+ xc = NULL;
+ while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL)
+ if (xml2json_cbuf1(cb, xc, pretty, autocliext) < 0)
+ goto done;
}
else {
- if (xml2json_cbuf1(cb, xt, pretty, autocliext) < 0)
- goto done;
+ if (xml2json_cbuf1(cb, xt, pretty, autocliext) < 0)
+ goto done;
}
retval = 0;
done:
@@ -1188,9 +1188,9 @@ clixon_json2cbuf(cbuf *cb,
*/
int
xml2json_cbuf_vec(cbuf *cb,
- cxobj **vec,
- size_t veclen,
- int pretty)
+ cxobj **vec,
+ size_t veclen,
+ int pretty)
{
int retval = -1;
int level = 0;
@@ -1200,41 +1200,41 @@ xml2json_cbuf_vec(cbuf *cb,
cvec *nsc = NULL;
if ((xp = xml_new("xml2json", NULL, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
/* Make a copy of old and graft it into new top-object
* Also copy namespace context */
for (i=0; i ietf-restconf translation
- * A special case is for return data on the form {"data":...}
- * See also xml2json1_cbuf
- */
- if (strcmp(modname, "ietf-restconf") == 0)
- modname = "ietf-netconf";
- if ((ymod = yang_find_module_by_name(yspec, modname)) == NULL){
- if (xerr &&
- netconf_unknown_namespace_xml(xerr, "application",
- modname,
- "No yang module found corresponding to prefix") < 0)
- goto done;
- goto fail;
- }
- namespace = yang_find_mynamespace(ymod);
- /* It would be possible to use canonical prefixes here, but probably not
- * necessary or even right. Therefore, the namespace given by the JSON prefix / module
- * is always the default namespace with prefix NULL.
- * If not, this would be the prefix to pass instead of NULL
- * prefix = yang_find_myprefix(ymod);
- */
- if (xml_namespace_change(x, namespace, NULL) < 0)
- goto done;
+ /* Special case for ietf-netconf -> ietf-restconf translation
+ * A special case is for return data on the form {"data":...}
+ * See also xml2json1_cbuf
+ */
+ if (strcmp(modname, "ietf-restconf") == 0)
+ modname = "ietf-netconf";
+ if ((ymod = yang_find_module_by_name(yspec, modname)) == NULL){
+ if (xerr &&
+ netconf_unknown_namespace_xml(xerr, "application",
+ modname,
+ "No yang module found corresponding to prefix") < 0)
+ goto done;
+ goto fail;
+ }
+ namespace = yang_find_mynamespace(ymod);
+ /* It would be possible to use canonical prefixes here, but probably not
+ * necessary or even right. Therefore, the namespace given by the JSON prefix / module
+ * is always the default namespace with prefix NULL.
+ * If not, this would be the prefix to pass instead of NULL
+ * prefix = yang_find_myprefix(ymod);
+ */
+ if (xml_namespace_change(x, namespace, NULL) < 0)
+ goto done;
}
xc = NULL;
while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL){
- if ((ret = json_xmlns_translate(yspec, xc, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = json_xmlns_translate(yspec, xc, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
retval = 1;
done:
@@ -1417,11 +1417,11 @@ json_xmlns_translate(yang_stmt *yspec,
*/
static int
_json_parse(char *str,
- int rfc7951,
- yang_bind yb,
- yang_stmt *yspec,
- cxobj *xt,
- cxobj **xerr)
+ int rfc7951,
+ yang_bind yb,
+ yang_stmt *yspec,
+ cxobj *xt,
+ cxobj **xerr)
{
int retval = -1;
clixon_json_yacc jy = {0,};
@@ -1437,93 +1437,93 @@ _json_parse(char *str,
jy.jy_current = xt;
jy.jy_xtop = xt;
if (json_scan_init(&jy) < 0)
- goto done;
+ goto done;
if (json_parse_init(&jy) < 0)
- goto done;
+ goto done;
if (clixon_json_parseparse(&jy) != 0) { /* yacc returns 1 on error */
- clicon_log(LOG_NOTICE, "JSON error: line %d", jy.jy_linenum);
- if (clicon_errno == 0)
- clicon_err(OE_JSON, 0, "JSON parser error with no error code (should not happen)");
- goto done;
+ clicon_log(LOG_NOTICE, "JSON error: line %d", jy.jy_linenum);
+ if (clicon_errno == 0)
+ clicon_err(OE_JSON, 0, "JSON parser error with no error code (should not happen)");
+ goto done;
}
/* Traverse new objects */
for (i = 0; i < jy.jy_xlen; i++) {
- x = jy.jy_xvec[i];
- /* RFC 7951 Section 4: A namespace-qualified member name MUST be used for all
- * members of a top-level JSON object
- */
- if (rfc7951 && xml_prefix(x) == NULL){
- /* XXX: For top-level config file: */
- if (yb != YB_NONE || strcmp(xml_name(x),DATASTORE_TOP_SYMBOL)!=0){
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cberr, "Top-level JSON object %s is not qualified with namespace which is a MUST according to RFC 7951", xml_name(x));
- if (xerr && netconf_malformed_message_xml(xerr, cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
- }
- }
- /* Names are split into name/prefix, but now add namespace info */
- if ((ret = json_xmlns_translate(yspec, x, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- /* Now assign yang stmts to each XML node
- * XXX should be xml_bind_yang0_parent() sometimes.
- */
- switch (yb){
- case YB_PARENT:
- if ((ret = xml_bind_yang0(x, yb, yspec, xerr)) < 0)
- goto done;
- if (ret == 0)
- failed++;
- break;
- case YB_MODULE_NEXT:
- if ((ret = xml_bind_yang(x, YB_MODULE, yspec, xerr)) < 0)
- goto done;
- if (ret == 0)
- failed++;
- break;
- case YB_MODULE:
- if ((ret = xml_bind_yang0(x, yb, yspec, xerr)) < 0)
- goto done;
- if (ret == 0)
- failed++;
- break;
- case YB_NONE:
- break;
- case YB_RPC:
- if ((ret = xml_bind_yang_rpc(x, yspec, xerr)) < 0)
- goto done;
- if (ret == 0)
- failed++;
- break;
- }
- /* Now find leafs with identityrefs (+transitive) and translate
- * prefixes in values to XML namespaces */
- if ((ret = json2xml_decode(x, xerr)) < 0)
- goto done;
- if (ret == 0) /* XXX necessary? */
- goto fail;
+ x = jy.jy_xvec[i];
+ /* RFC 7951 Section 4: A namespace-qualified member name MUST be used for all
+ * members of a top-level JSON object
+ */
+ if (rfc7951 && xml_prefix(x) == NULL){
+ /* XXX: For top-level config file: */
+ if (yb != YB_NONE || strcmp(xml_name(x),DATASTORE_TOP_SYMBOL)!=0){
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cberr, "Top-level JSON object %s is not qualified with namespace which is a MUST according to RFC 7951", xml_name(x));
+ if (xerr && netconf_malformed_message_xml(xerr, cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ /* Names are split into name/prefix, but now add namespace info */
+ if ((ret = json_xmlns_translate(yspec, x, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ /* Now assign yang stmts to each XML node
+ * XXX should be xml_bind_yang0_parent() sometimes.
+ */
+ switch (yb){
+ case YB_PARENT:
+ if ((ret = xml_bind_yang0(x, yb, yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ failed++;
+ break;
+ case YB_MODULE_NEXT:
+ if ((ret = xml_bind_yang(x, YB_MODULE, yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ failed++;
+ break;
+ case YB_MODULE:
+ if ((ret = xml_bind_yang0(x, yb, yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ failed++;
+ break;
+ case YB_NONE:
+ break;
+ case YB_RPC:
+ if ((ret = xml_bind_yang_rpc(x, yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ failed++;
+ break;
+ }
+ /* Now find leafs with identityrefs (+transitive) and translate
+ * prefixes in values to XML namespaces */
+ if ((ret = json2xml_decode(x, xerr)) < 0)
+ goto done;
+ if (ret == 0) /* XXX necessary? */
+ goto fail;
}
if (failed)
- goto fail;
+ goto fail;
/* Sort the complete tree after parsing. Sorting is not really meaningful if Yang
not bound */
if (yb != YB_NONE)
- if (xml_sort_recurse(xt) < 0)
- goto done;
+ if (xml_sort_recurse(xt) < 0)
+ goto done;
retval = 1;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
json_parse_exit(&jy);
json_scan_exit(&jy);
if (jy.jy_xvec)
- free(jy.jy_xvec);
+ free(jy.jy_xvec);
return retval;
fail: /* invalid */
retval = 0;
@@ -1554,20 +1554,20 @@ _json_parse(char *str,
*/
int
clixon_json_parse_string(char *str,
- int rfc7951,
- yang_bind yb,
- yang_stmt *yspec,
- cxobj **xt,
- cxobj **xerr)
+ int rfc7951,
+ yang_bind yb,
+ yang_stmt *yspec,
+ cxobj **xt,
+ cxobj **xerr)
{
clicon_debug(1, "%s", __FUNCTION__);
if (xt==NULL){
- clicon_err(OE_JSON, EINVAL, "xt is NULL");
- return -1;
+ clicon_err(OE_JSON, EINVAL, "xt is NULL");
+ return -1;
}
if (*xt == NULL){
- if ((*xt = xml_new("top", NULL, CX_ELMNT)) == NULL)
- return -1;
+ if ((*xt = xml_new("top", NULL, CX_ELMNT)) == NULL)
+ return -1;
}
return _json_parse(str, rfc7951, yb, yspec, *xt, xerr);
}
@@ -1610,11 +1610,11 @@ clixon_json_parse_string(char *str,
*/
int
clixon_json_parse_file(FILE *fp,
- int rfc7951,
- yang_bind yb,
- yang_stmt *yspec,
- cxobj **xt,
- cxobj **xerr)
+ int rfc7951,
+ yang_bind yb,
+ yang_stmt *yspec,
+ cxobj **xt,
+ cxobj **xerr)
{
int retval = -1;
int ret;
@@ -1626,53 +1626,53 @@ clixon_json_parse_file(FILE *fp,
int len = 0;
if (xt==NULL){
- clicon_err(OE_JSON, EINVAL, "xt is NULL");
- return -1;
+ clicon_err(OE_JSON, EINVAL, "xt is NULL");
+ return -1;
}
if ((jsonbuf = malloc(jsonbuflen)) == NULL){
- clicon_err(OE_JSON, errno, "malloc");
- goto done;
+ clicon_err(OE_JSON, errno, "malloc");
+ goto done;
}
memset(jsonbuf, 0, jsonbuflen);
ptr = jsonbuf;
while (1){
- if ((ret = fread(&ch, 1, 1, fp)) < 0){
- clicon_err(OE_JSON, errno, "read");
- break;
- }
- if (ret != 0)
- jsonbuf[len++] = ch;
- if (ret == 0){
- if (*xt == NULL)
- if ((*xt = xml_new(JSON_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
- goto done;
- if (len){
- if ((ret = _json_parse(ptr, rfc7951, yb, yspec, *xt, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- break;
- }
- if (len >= jsonbuflen-1){ /* Space: one for the null character */
- oldjsonbuflen = jsonbuflen;
- jsonbuflen *= 2;
- if ((jsonbuf = realloc(jsonbuf, jsonbuflen)) == NULL){
- clicon_err(OE_JSON, errno, "realloc");
- goto done;
- }
- memset(jsonbuf+oldjsonbuflen, 0, jsonbuflen-oldjsonbuflen);
- ptr = jsonbuf;
- }
+ if ((ret = fread(&ch, 1, 1, fp)) < 0){
+ clicon_err(OE_JSON, errno, "read");
+ break;
+ }
+ if (ret != 0)
+ jsonbuf[len++] = ch;
+ if (ret == 0){
+ if (*xt == NULL)
+ if ((*xt = xml_new(JSON_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
+ goto done;
+ if (len){
+ if ((ret = _json_parse(ptr, rfc7951, yb, yspec, *xt, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ break;
+ }
+ if (len >= jsonbuflen-1){ /* Space: one for the null character */
+ oldjsonbuflen = jsonbuflen;
+ jsonbuflen *= 2;
+ if ((jsonbuf = realloc(jsonbuf, jsonbuflen)) == NULL){
+ clicon_err(OE_JSON, errno, "realloc");
+ goto done;
+ }
+ memset(jsonbuf+oldjsonbuflen, 0, jsonbuflen-oldjsonbuflen);
+ ptr = jsonbuf;
+ }
}
retval = 1;
done:
if (retval < 0 && *xt){
- free(*xt);
- *xt = NULL;
+ free(*xt);
+ *xt = NULL;
}
if (jsonbuf)
- free(jsonbuf);
+ free(jsonbuf);
return retval;
fail:
retval = 0;
diff --git a/lib/src/clixon_json_parse.h b/lib/src/clixon_json_parse.h
index fcb4bacc..47199b86 100644
--- a/lib/src/clixon_json_parse.h
+++ b/lib/src/clixon_json_parse.h
@@ -69,4 +69,4 @@ int clixon_json_parselex(void *);
int clixon_json_parseparse(void *);
void clixon_json_parseerror(void *, char*);
-#endif /* _CLIXON_JSON_PARSE_H_ */
+#endif /* _CLIXON_JSON_PARSE_H_ */
diff --git a/lib/src/clixon_json_parse.y b/lib/src/clixon_json_parse.y
index 76fc75b2..f5331d3f 100644
--- a/lib/src/clixon_json_parse.y
+++ b/lib/src/clixon_json_parse.y
@@ -53,11 +53,11 @@ A JSON value is an object, array, number, string, true, false, or null
value ::= object |
array |
- number |
- string |
- 'true' |
- 'false' |
- 'null' ;
+ number |
+ string |
+ 'true' |
+ 'false' |
+ 'null' ;
object ::= '{' [objlist] '}';
objlist ::= pair [',' objlist];
@@ -149,12 +149,12 @@ extern int clixon_json_parseget_lineno (void);
void
clixon_json_parseerror(void *_jy,
- char *s)
+ char *s)
{
clicon_err(OE_JSON, XMLPARSE_ERRNO, "json_parse: line %d: %s at or before: '%s'",
- _JY->jy_linenum ,
- s,
- clixon_json_parsetext);
+ _JY->jy_linenum ,
+ s,
+ clixon_json_parsetext);
return;
}
@@ -176,7 +176,7 @@ json_parse_exit(clixon_json_yacc *jy)
*/
static int
json_current_new(clixon_json_yacc *jy,
- char *name)
+ char *name)
{
int retval = -1;
cxobj *x;
@@ -186,24 +186,24 @@ json_current_new(clixon_json_yacc *jy,
clicon_debug(2, "%s", __FUNCTION__);
/* Find colon separator and if found split into prefix:name */
if (nodeid_split(name, &prefix, &id) < 0)
- goto done;
+ goto done;
if ((x = xml_new(id, jy->jy_current, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (xml_prefix_set(x, prefix) < 0)
- goto done;
+ goto done;
/* If topmost, add to top-list created list */
if (jy->jy_current == jy->jy_xtop){
- if (cxvec_append(x, &jy->jy_xvec, &jy->jy_xlen) < 0)
- goto done;
+ if (cxvec_append(x, &jy->jy_xvec, &jy->jy_xlen) < 0)
+ goto done;
}
jy->jy_current = x;
retval = 0;
done:
if (prefix)
- free(prefix);
+ free(prefix);
if (id)
- free(id);
+ free(id);
return retval;
}
@@ -212,7 +212,7 @@ json_current_pop(clixon_json_yacc *jy)
{
clicon_debug(2, "%s", __FUNCTION__);
if (jy->jy_current)
- jy->jy_current = xml_parent(jy->jy_current);
+ jy->jy_current = xml_parent(jy->jy_current);
return 0;
}
@@ -249,16 +249,16 @@ json_current_clone(clixon_json_yacc *jy)
static int
json_current_body(clixon_json_yacc *jy,
- char *value)
+ char *value)
{
int retval = -1;
cxobj *xn;
clicon_debug(2, "%s", __FUNCTION__);
if ((xn = xml_new("body", jy->jy_current, CX_BODY)) == NULL)
- goto done;
+ goto done;
if (value && xml_value_append(xn, value) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -279,7 +279,7 @@ value : J_TRUE { json_current_body(_JY, "true"); _PARSE_DEBUG("va
| J_FALSE { json_current_body(_JY, "false"); _PARSE_DEBUG("value->FALSE");}
| J_NULL { json_current_body(_JY, NULL); _PARSE_DEBUG("value->NULL");}
| object { _PARSE_DEBUG("value->object"); }
- | array { _PARSE_DEBUG("value->array"); }
+ | array { _PARSE_DEBUG("value->array"); }
| number { json_current_body(_JY, $1); free($1); _PARSE_DEBUG("value->number");}
| string { json_current_body(_JY, cbuf_get($1)); cbuf_free($1); _PARSE_DEBUG("value->string");}
@@ -314,10 +314,10 @@ string : J_DQ ustring J_DQ { _PARSE_DEBUG("string->\" ustring \"");$$=$2;
/* unquoted string: can be optimized by reading whole string in lex */
ustring : ustring J_CHAR
{
- cbuf_append_str($1,$2); $$=$1; free($2);
- }
+ cbuf_append_str($1,$2); $$=$1; free($2);
+ }
| J_CHAR
- { cbuf *cb = cbuf_new(); cbuf_append_str(cb,$1); $$=cb; free($1);}
+ { cbuf *cb = cbuf_new(); cbuf_append_str(cb,$1); $$=cb; free($1);}
;
number : J_NUMBER { $$ = $1; }
diff --git a/lib/src/clixon_log.c b/lib/src/clixon_log.c
index 19444b33..f54520cc 100644
--- a/lib/src/clixon_log.c
+++ b/lib/src/clixon_log.c
@@ -86,22 +86,22 @@ static int _clixon_log_trunc = 0;
* @param[in] upto log priority, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG (see syslog(3)).
* @param[in] flags bitmask: if CLICON_LOG_STDERR, then print logs to stderr
* if CLICON_LOG_SYSLOG, then print logs to syslog
- * You can do a combination of both
+ * You can do a combination of both
* @code
* clicon_log_init(__PROGRAM__, LOG_INFO, CLICON_LOG_STDERR);
* @endcode
*/
int
clicon_log_init(char *ident,
- int upto,
- int flags)
+ int upto,
+ int flags)
{
_logflags = flags;
if (flags & CLICON_LOG_SYSLOG){
- if (setlogmask(LOG_UPTO(upto)) < 0)
- /* Cant syslog here */
- fprintf(stderr, "%s: setlogmask: %s\n", __FUNCTION__, strerror(errno));
- openlog(ident, LOG_PID, LOG_USER); /* LOG_PUSER is achieved by direct stderr logs in clicon_log */
+ if (setlogmask(LOG_UPTO(upto)) < 0)
+ /* Cant syslog here */
+ fprintf(stderr, "%s: setlogmask: %s\n", __FUNCTION__, strerror(errno));
+ openlog(ident, LOG_PID, LOG_USER); /* LOG_PUSER is achieved by direct stderr logs in clicon_log */
}
return 0;
}
@@ -110,7 +110,7 @@ int
clicon_log_exit(void)
{
if (_logfile)
- fclose(_logfile);
+ fclose(_logfile);
closelog(); /* optional */
return 0;
}
@@ -127,22 +127,22 @@ clicon_log_opt(char c)
switch (c){
case 's':
- logdst = CLICON_LOG_SYSLOG;
- break;
+ logdst = CLICON_LOG_SYSLOG;
+ break;
case 'e':
- logdst = CLICON_LOG_STDERR;
- break;
+ logdst = CLICON_LOG_STDERR;
+ break;
case 'o':
- logdst = CLICON_LOG_STDOUT;
- break;
+ logdst = CLICON_LOG_STDOUT;
+ break;
case 'f':
- logdst = CLICON_LOG_FILE;
- break;
+ logdst = CLICON_LOG_FILE;
+ break;
case 'n':
- logdst = 0;
- break;
+ logdst = 0;
+ break;
default:
- break;
+ break;
}
return logdst;
}
@@ -157,10 +157,10 @@ int
clicon_log_file(char *filename)
{
if (_logfile)
- fclose(_logfile);
+ fclose(_logfile);
if ((_logfile = fopen(filename, "a")) == NULL){
- fprintf(stderr, "fopen: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
- return -1;
+ fprintf(stderr, "fopen: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
+ return -1;
}
return 0;
}
@@ -199,8 +199,8 @@ flogtime(FILE *f)
gettimeofday(&tv, NULL);
localtime_r((time_t*)&tv.tv_sec, &tm);
fprintf(f, "%s %2d %02d:%02d:%02d: ",
- mon2name(tm.tm_mon), tm.tm_mday,
- tm.tm_hour, tm.tm_min, tm.tm_sec);
+ mon2name(tm.tm_mon), tm.tm_mday,
+ tm.tm_hour, tm.tm_min, tm.tm_sec);
return 0;
}
@@ -218,14 +218,14 @@ slogtime(void)
/* Example: "Apr 14 11:30:52: " len=17+1 */
if ((str = malloc(18)) == NULL){
- fprintf(stderr, "%s: malloc: %s\n", __FUNCTION__, strerror(errno));
- return NULL;
+ fprintf(stderr, "%s: malloc: %s\n", __FUNCTION__, strerror(errno));
+ return NULL;
}
gettimeofday(&tv, NULL);
tm = localtime((time_t*)&tv.tv_sec);
snprintf(str, 18, "%s %2d %02d:%02d:%02d: ",
- mon2name(tm->tm_mon), tm->tm_mday,
- tm->tm_hour, tm->tm_min, tm->tm_sec);
+ mon2name(tm->tm_mon), tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
return str;
}
#endif
@@ -238,29 +238,29 @@ slogtime(void)
* @note syslog makes its own filtering, but if log to stderr we do it here
* @see clicon_debug
*/
-static int
+int
clicon_log_str(int level,
- char *msg)
+ char *msg)
{
if (_logflags & CLICON_LOG_SYSLOG)
- syslog(LOG_MAKEPRI(LOG_USER, level), "%s", msg);
+ syslog(LOG_MAKEPRI(LOG_USER, level), "%s", msg);
/* syslog makes own filtering, we do it here:
* if normal (not debug) then filter loglevels >= debug
*/
if (_clixon_debug == 0 && level >= LOG_DEBUG)
- goto done;
+ goto done;
if (_logflags & CLICON_LOG_STDERR){
- flogtime(stderr);
- fprintf(stderr, "%s\n", msg);
+ flogtime(stderr);
+ fprintf(stderr, "%s\n", msg);
}
if (_logflags & CLICON_LOG_STDOUT){
- flogtime(stdout);
- fprintf(stdout, "%s\n", msg);
+ flogtime(stdout);
+ fprintf(stdout, "%s\n", msg);
}
if ((_logflags & CLICON_LOG_FILE) && _logfile){
- flogtime(_logfile);
- fprintf(_logfile, "%s\n", msg);
- fflush(_logfile);
+ flogtime(_logfile);
+ fprintf(_logfile, "%s\n", msg);
+ fflush(_logfile);
}
/* Enable this if you want syslog in a stream. But there are problems with
* recursion
@@ -275,14 +275,14 @@ clicon_log_str(int level,
* is OR:d with facility == LOG_USER
* @param[in] format Message to print as argv.
* @code
- clicon_log(LOG_NOTICE, "%s: dump to dtd not supported", __PROGRAM__);
+ clicon_log(LOG_NOTICE, "%s: dump to dtd not supported", __PROGRAM__);
* @endcode
* @see clicon_log_init clicon_log_str
* @see clicon_log_xml
*/
int
clicon_log(int level,
- const char *format, ...)
+ const char *format, ...)
{
va_list args;
size_t len;
@@ -297,20 +297,20 @@ clicon_log(int level,
/* Truncate long debug strings */
if ((trunc = clicon_log_string_limit_get()) && trunc < len)
- len = trunc;
+ len = trunc;
/* allocate a message string exactly fitting the message length */
if ((msg = malloc(len+1)) == NULL){
- fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
- goto done;
+ fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
+ goto done;
}
/* second round: compute write message from format and args */
va_start(args, format);
if (vsnprintf(msg, len+1, format, args) < 0){
- va_end(args);
- fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
- goto done;
+ va_end(args);
+ fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
+ goto done;
}
va_end(args);
/* Actually log it */
@@ -319,7 +319,7 @@ clicon_log(int level,
retval = 0;
done:
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -337,19 +337,19 @@ clicon_log(int level,
* Note this is _not_ level from syslog(3)
* @param[in] f Debug-file. Open file where debug messages are directed.
* If not NULL, it overrides the clicon_log settings which is otherwise
- * where debug messages are directed.
+ * where debug messages are directed.
* @see clicon_log_file where a filename can be given
*/
int
clicon_debug_init(int dbglevel,
- FILE *f)
+ FILE *f)
{
_clixon_debug = dbglevel; /* Global variable */
if (f != NULL){
- if (_logfile)
- fclose(_logfile);
- _logfile = f;
+ if (_logfile)
+ fclose(_logfile);
+ _logfile = f;
}
return 0;
}
@@ -375,7 +375,7 @@ clicon_debug_get(void)
*/
int
clicon_debug(int dbglevel,
- const char *format, ...)
+ const char *format, ...)
{
va_list args;
size_t len;
@@ -384,7 +384,7 @@ clicon_debug(int dbglevel,
size_t trunc;
if (dbglevel > _clixon_debug) /* compare debug mask with global variable */
- return 0;
+ return 0;
/* first round: compute length of debug message */
va_start(args, format);
len = vsnprintf(NULL, 0, format, args);
@@ -392,26 +392,26 @@ clicon_debug(int dbglevel,
/* Truncate long debug strings */
if ((trunc = clicon_log_string_limit_get()) && trunc < len)
- len = trunc;
-
+ len = trunc;
+
/* allocate a message string exactly fitting the message length */
if ((msg = malloc(len+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* second round: compute write message from format and args */
va_start(args, format);
if (vsnprintf(msg, len+1, format, args) < 0){
- va_end(args);
- clicon_err(OE_UNIX, errno, "vsnprintf");
- goto done;
+ va_end(args);
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ goto done;
}
va_end(args);
clicon_log_str(LOG_DEBUG, msg);
retval = 0;
done:
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -435,7 +435,7 @@ mon2name(int md)
case 10: return "Nov";
case 11: return "Dec";
default:
- break;
+ break;
}
return NULL;
}
diff --git a/lib/src/clixon_nacm.c b/lib/src/clixon_nacm.c
index 5f499f13..b57df23d 100644
--- a/lib/src/clixon_nacm.c
+++ b/lib/src/clixon_nacm.c
@@ -89,17 +89,17 @@
*/
static int
match_access(char *access_operations,
- char *mode,
- char *mode2)
+ char *mode,
+ char *mode2)
{
if (access_operations==NULL)
- return 0;
+ return 0;
if (strcmp(access_operations,"*")==0)
- return 1;
+ return 1;
if (strstr(access_operations, mode)!=NULL)
- return 1;
+ return 1;
if (mode2 && strstr(access_operations, mode2)!=NULL)
- return 1;
+ return 1;
return 0;
}
@@ -127,8 +127,8 @@ match_access(char *access_operations,
*/
static int
nacm_rule_rpc(char *rpc,
- char *module,
- cxobj *xrule)
+ char *module,
+ cxobj *xrule)
{
int retval = -1;
char *module_rule; /* rule module name */
@@ -136,26 +136,26 @@ nacm_rule_rpc(char *rpc,
char *access_operations;
/* 7a) The rule's "module-name" leaf is "*" or equals the name of
- the YANG module where the protocol operation is defined. */
+ the YANG module where the protocol operation is defined. */
if ((module_rule = xml_find_body(xrule, "module-name")) == NULL)
- goto nomatch;
+ goto nomatch;
if (strcmp(module_rule,"*") && strcmp(module_rule,module))
- goto nomatch;
+ goto nomatch;
/* 7b) Either (1) the rule does not have a "rule-type" defined or
- (2) the "rule-type" is "protocol-operation" and the
- "rpc-name" is "*" or equals the name of the requested
- protocol operation. */
+ (2) the "rule-type" is "protocol-operation" and the
+ "rpc-name" is "*" or equals the name of the requested
+ protocol operation. */
if ((rpc_rule = xml_find_body(xrule, "rpc-name")) == NULL){
- if (xml_find_body(xrule, "path") || xml_find_body(xrule, "notification-name"))
- goto nomatch;
+ if (xml_find_body(xrule, "path") || xml_find_body(xrule, "notification-name"))
+ goto nomatch;
}
if (rpc_rule && (strcmp(rpc_rule, "*") && strcmp(rpc_rule, rpc)))
- goto nomatch;
+ goto nomatch;
/* 7c) The rule's "access-operations" leaf has the "exec" bit set or
- has the special value "*". */
+ has the special value "*". */
access_operations = xml_find_body(xrule, "access-operations");
if (!match_access(access_operations, "exec", NULL))
- goto nomatch;
+ goto nomatch;
retval = 1;
done:
return retval;
@@ -179,10 +179,10 @@ nacm_rule_rpc(char *rpc,
*/
int
nacm_rpc(char *rpc,
- char *module,
- char *username,
- cxobj *xnacm,
- cbuf *cbret)
+ char *module,
+ char *username,
+ cxobj *xnacm,
+ cbuf *cbret)
{
int retval = -1;
cxobj *xrule;
@@ -202,72 +202,72 @@ nacm_rpc(char *rpc,
/* Create namespace context for with nacm namespace as default */
if ((nsc = xml_nsctx_init(NULL, NACM_NS)) == NULL)
- goto done;
+ goto done;
/* 3. If the requested operation is the NETCONF
protocol operation, then the protocol operation is permitted.
*/
if (strcmp(rpc, "close-session") == 0)
- goto permit;
+ goto permit;
/* 4. Check all the "group" entries to see if any of them contain a
"user-name" entry that equals the username for the session
making the request. (If the "enable-external-groups" leaf is
"true", add to these groups the set of groups provided by the
- transport layer.) */
+ transport layer.) */
if (username == NULL)
- goto step10;
+ goto step10;
/* User's group */
if (xpath_vec(xnacm, nsc, "groups/group[user-name='%s']", &gvec, &glen, username) < 0)
- goto done;
+ goto done;
/* 5. If no groups are found, continue with step 10. */
if (glen == 0)
- goto step10;
+ goto step10;
/* 6. Process all rule-list entries, in the order they appear in the
configuration. If a rule-list's "group" leaf-list does not
match any of the user's groups, proceed to the next rule-list
entry. */
if (xpath_vec(xnacm, nsc, "rule-list", &rlistvec, &rlistlen) < 0)
- goto done;
+ goto done;
for (i=0; i or , then the protocol operation
is denied. */
if (strcmp(rpc, "kill-session")==0 || strcmp(rpc, "delete-config")==0){
- if (netconf_access_denied(cbret, "application", "default deny") < 0)
- goto done;
- goto deny;
+ if (netconf_access_denied(cbret, "application", "default deny") < 0)
+ goto done;
+ goto deny;
}
/* 12. If the "exec-default" leaf is set to "permit", then permit the
- protocol operation; otherwise, deny the request. */
+ protocol operation; otherwise, deny the request. */
exec_default = xml_find_body(xnacm, "exec-default");
if (exec_default ==NULL || strcmp(exec_default, "permit")==0)
- goto permit;
+ goto permit;
if (netconf_access_denied(cbret, "application", "default deny") < 0)
- goto done;
+ goto done;
goto deny;
permit:
retval = 1;
done:
clicon_debug(1, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (gvec)
- free(gvec);
+ free(gvec);
if (rlistvec)
- free(rlistvec);
+ free(rlistvec);
if (rvec)
- free(rvec);
+ free(rvec);
return retval;
deny: /* Here, cbret must contain a netconf error msg */
assert(cbuf_len(cbret));
@@ -326,29 +326,29 @@ prepvec_free(prepvec *pv_list)
prepvec *pv;
while((pv = pv_list) != NULL) {
- DELQ(pv, pv_list, prepvec *);
- if (pv->pv_xpathvec)
- clixon_xvec_free(pv->pv_xpathvec);
- free(pv);
+ DELQ(pv, pv_list, prepvec *);
+ if (pv->pv_xpathvec)
+ clixon_xvec_free(pv->pv_xpathvec);
+ free(pv);
}
return 0;
}
prepvec *
prepvec_add(prepvec **pv_listp,
- cxobj *xrule)
+ cxobj *xrule)
{
prepvec *pv;
if ((pv = malloc(sizeof(*pv))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- return NULL;
+ clicon_err(OE_UNIX, errno, "malloc");
+ return NULL;
}
memset(pv, 0, sizeof(*pv));
ADDQ(pv, *pv_listp);
pv->pv_xrule = xrule;
if ((pv->pv_xpathvec = clixon_xvec_new()) == NULL)
- return NULL;
+ return NULL;
return pv;
}
@@ -361,14 +361,14 @@ prepvec_add(prepvec **pv_listp,
*/
static int
nacm_datanode_prepare(clicon_handle h,
- cxobj *xt,
- enum nacm_access access,
- cxobj **gvec,
- size_t glen,
- cxobj **rlistvec,
- size_t rlistlen,
- cvec *nsc,
- prepvec **pv_listp)
+ cxobj *xt,
+ enum nacm_access access,
+ cxobj **gvec,
+ size_t glen,
+ cxobj **rlistvec,
+ size_t rlistlen,
+ cvec *nsc,
+ prepvec **pv_listp)
{
int retval = -1;
cxobj *rlist;
@@ -377,7 +377,7 @@ nacm_datanode_prepare(clicon_handle h,
int k;
char *gname;
cxobj **rvec = NULL; /* rules */
- size_t rlen;
+ size_t rlen;
cxobj *xrule;
cxobj *pathobj;
char *access_operations;
@@ -391,123 +391,123 @@ nacm_datanode_prepare(clicon_handle h,
prepvec *pv;
yspec = clicon_dbspec_yang(h);
- for (i=0; ipv_xpathvec, xvec[k]) < 0)
- goto done;
- }
- if (xvec){
- free(xvec);
- xvec = NULL;
- }
- if (nsc0){
- cvec_free(nsc0);
- nsc0 = NULL;
- }
- if (path){
- free(path);
- path = NULL;
- }
- }
- }
- if (rvec){
- free(rvec);
- rvec=NULL;
- }
+ if ((ret = clixon_xml_find_instance_id(xt, yspec, &xvec, &xlen, "%s", path)) < 0)
+ goto done;
+ if (ret == 0)
+ continue;
+ /* Here a new xrule is found, add it */
+ if ((pv = prepvec_add(pv_listp, xrule)) == NULL)
+ goto done;
+ for (k=0; kpv_xpathvec, xvec[k]) < 0)
+ goto done;
+ }
+ if (xvec){
+ free(xvec);
+ xvec = NULL;
+ }
+ if (nsc0){
+ cvec_free(nsc0);
+ nsc0 = NULL;
+ }
+ if (path){
+ free(path);
+ path = NULL;
+ }
+ }
+ }
+ if (rvec){
+ free(rvec);
+ rvec=NULL;
+ }
}
retval = 0;
done:
if (xvec)
- free(xvec);
+ free(xvec);
if (path)
- free(path);
+ free(path);
if (nsc0)
- cvec_free(nsc0);
+ cvec_free(nsc0);
return retval;
}
@@ -527,9 +527,9 @@ nacm_datanode_prepare(clicon_handle h,
*/
static int
nacm_data_write_xrule_xml(cxobj *xn,
- cxobj *xrule,
- clixon_xvec *xpathvec,
- yang_stmt *yspec)
+ cxobj *xrule,
+ clixon_xvec *xpathvec,
+ yang_stmt *yspec)
{
int retval = -1;
yang_stmt *ymod;
@@ -539,34 +539,34 @@ nacm_data_write_xrule_xml(cxobj *xn,
int i;
if ((module_pattern = xml_find_body(xrule, "module-name")) == NULL)
- goto nomatch;
+ goto nomatch;
/* 6a) The rule's "module-name" leaf is "*" or equals the name of
* the YANG module where the requested data node is defined.
*/
if (strcmp(module_pattern, "*") != 0){
- if (ys_module_by_xml(yspec, xn, &ymod) < 0)
- goto done;
- /* ymod is NULL (xn is "config") Can this breach the NACM rule? */
- if (ymod && strcmp(yang_argument_get(ymod), module_pattern) != 0)
- goto nomatch;
+ if (ys_module_by_xml(yspec, xn, &ymod) < 0)
+ goto done;
+ /* ymod is NULL (xn is "config") Can this breach the NACM rule? */
+ if (ymod && strcmp(yang_argument_get(ymod), module_pattern) != 0)
+ goto nomatch;
}
action = xml_find_body(xrule, "action"); /* mandatory */
/* 6b) Either (1) the rule does not have a "rule-type" defined or
- (2) the "rule-type" is "data-node" and the "path" matches the
- Requested data node, action node, or notification node. */
+ (2) the "rule-type" is "data-node" and the "path" matches the
+ Requested data node, action node, or notification node. */
if (xml_find_type(xrule, NULL, "path", CX_ELMNT) == NULL){
- if (strcmp(action, "deny")==0)
- goto deny;
- goto permit;
+ if (strcmp(action, "deny")==0)
+ goto deny;
+ goto permit;
}
for (i=0; ipv_xrule, pv->pv_xpathvec, yspec)) < 0)
- goto done;
- switch(ret){
- case 0: /* No match, continue with next rule */
- break;
- case 1: /* Match and deny: break all traversal and send error back to client */
- if (netconf_access_denied(cbret, "application", "access denied") < 0)
- goto done;
- goto deny;
- break;
- case 2: /* Match and permit: break rule processing but continue recursion */
- break;
- }
- if (ret == 2)
- break;
- pv = NEXTQ(prepvec *, pv);
- } while (pv && pv != pv_list);
+ do {
+ /* return values: -1:Error /0:no match /1: deny /2: permit
+ */
+ if ((ret = nacm_data_write_xrule_xml(xn, pv->pv_xrule, pv->pv_xpathvec, yspec)) < 0)
+ goto done;
+ switch(ret){
+ case 0: /* No match, continue with next rule */
+ break;
+ case 1: /* Match and deny: break all traversal and send error back to client */
+ if (netconf_access_denied(cbret, "application", "access denied") < 0)
+ goto done;
+ goto deny;
+ break;
+ case 2: /* Match and permit: break rule processing but continue recursion */
+ break;
+ }
+ if (ret == 2)
+ break;
+ pv = NEXTQ(prepvec *, pv);
+ } while (pv && pv != pv_list);
}
/* If no rule match, check default rule: if deny then break traversal and send error */
if (ret == 0 && !defpermit){
- if (netconf_access_denied(cbret, "application", "default deny") < 0)
- goto done;
- goto deny;
+ if (netconf_access_denied(cbret, "application", "default deny") < 0)
+ goto done;
+ goto deny;
}
/* If node should be purged, dont recurse and defer removal to caller */
- x = NULL; /* Recursively check XML */
+ x = NULL; /* Recursively check XML */
while ((x = xml_child_each(xn, x, CX_ELMNT)) != NULL) {
- if ((ret = nacm_datanode_write_recurse(h, x, pv_list,
- defpermit, yspec, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto deny;
+ if ((ret = nacm_datanode_write_recurse(h, x, pv_list,
+ defpermit, yspec, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto deny;
}
retval = 1; /* accept */
done:
@@ -675,12 +675,12 @@ nacm_datanode_write_recurse(clicon_handle h,
*/
int
nacm_datanode_write(clicon_handle h,
- cxobj *xreq,
- cxobj *xt,
- enum nacm_access access,
- char *username,
- cxobj *xnacm,
- cbuf *cbret)
+ cxobj *xreq,
+ cxobj *xt,
+ enum nacm_access access,
+ char *username,
+ cxobj *xnacm,
+ cbuf *cbret)
{
int retval = -1;
cxobj **gvec = NULL; /* groups */
@@ -695,48 +695,48 @@ nacm_datanode_write(clicon_handle h,
/* Create namespace context for with nacm namespace as default */
if ((nsc = xml_nsctx_init(NULL, NACM_NS)) == NULL)
- goto done;
+ goto done;
if (xnacm == NULL)
- goto permit;
+ goto permit;
/* write-default (create, update, or delete) has default deny so should never be NULL */
if ((write_default = xml_find_body(xnacm, "write-default")) == NULL){
- clicon_err(OE_XML, EINVAL, "No nacm write-default rule");
- goto done;
+ clicon_err(OE_XML, EINVAL, "No nacm write-default rule");
+ goto done;
}
/* 3. Check all the "group" entries to see if any of them contain a
"user-name" entry that equals the username for the session
making the request. (If the "enable-external-groups" leaf is
"true", add to these groups the set of groups provided by the
- transport layer.) */
+ transport layer.) */
if (username == NULL)
- goto step9;
+ goto step9;
/* User's group */
if (xpath_vec(xnacm, nsc, "groups/group[user-name='%s']", &gvec, &glen, username) < 0)
- goto done;
+ goto done;
/* 4. If no groups are found, continue with step 9. */
if (glen == 0)
- goto step9;
+ goto step9;
/* 5. Process all rule-list entries, in the order they appear in the
configuration. If a rule-list's "group" leaf-list does not
match any of the user's groups, proceed to the next rule-list
entry. */
if (xpath_vec(xnacm, nsc, "rule-list", &rlistvec, &rlistlen) < 0)
- goto done;
+ goto done;
/* First run through rules and cache rules as well as lookup objects in xt.
*/
if (nacm_datanode_prepare(h, xt, access, gvec, glen, rlistvec, rlistlen, nsc, &pv_list) < 0)
- goto done;
+ goto done;
/* Then recursivelyy traverse all requested nodes */
if ((ret = nacm_datanode_write_recurse(h, xreq, pv_list,
- strcmp(write_default, "deny"),
- clicon_dbspec_yang(h),
- cbret)) < 0)
- goto done;
+ strcmp(write_default, "deny"),
+ clicon_dbspec_yang(h),
+ cbret)) < 0)
+ goto done;
if (ret == 0) /* deny */
- goto deny;
+ goto deny;
goto permit;
/* 8. At this point, no matching rule was found in any rule-list
- entry. */
+ entry. */
step9:
/* 10. For a "write" access operation, if the requested data node is
defined in a YANG module advertised in the server capabilities
@@ -744,31 +744,31 @@ nacm_datanode_write(clicon_handle h,
"nacm:default-deny-write" or a "nacm:default-deny-all"
statement, then the access request is denied for the data node
and all its descendants.
- XXX
+ XXX
*/
/*12. For a "write" access operation, if the "write-default" leaf is
set to "permit", then permit the data node access request;
otherwise, deny the request.*/
/* write-default has default permit so should never be NULL */
if (strcmp(write_default, "deny") == 0){
- if (netconf_access_denied(cbret, "application", "default deny") < 0)
- goto done;
- goto deny;
+ if (netconf_access_denied(cbret, "application", "default deny") < 0)
+ goto done;
+ goto deny;
}
permit:
retval = 1;
done:
clicon_debug(1, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval);
if (pv_list)
- prepvec_free(pv_list);
+ prepvec_free(pv_list);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (gvec)
- free(gvec);
+ free(gvec);
if (rlistvec)
- free(rlistvec);
+ free(rlistvec);
if (rvec)
- free(rvec);
+ free(rvec);
return retval;
deny: /* Here, cbret must contain a netconf error msg */
assert(cbuf_len(cbret));
@@ -788,16 +788,16 @@ nacm_datanode_write(clicon_handle h,
*/
static int
nacm_data_read_action(cxobj *xrule,
- cxobj *xn)
+ cxobj *xn)
{
int retval = -1;
char *action;
if ((action = xml_find_body(xrule, "action")) != NULL){
- if (strcmp(action, "deny")==0)
- xml_flag_set(xn, XML_FLAG_DEL);
- else if (strcmp(action, "permit")==0)
- xml_flag_set(xn, XML_FLAG_MARK);
+ if (strcmp(action, "deny")==0)
+ xml_flag_set(xn, XML_FLAG_DEL);
+ else if (strcmp(action, "permit")==0)
+ xml_flag_set(xn, XML_FLAG_MARK);
}
retval = 0;
//done:
@@ -819,9 +819,9 @@ nacm_data_read_action(cxobj *xrule,
*/
static int
nacm_data_read_xrule_xml(cxobj *xn,
- cxobj *xrule,
- clixon_xvec *xpathvec,
- yang_stmt *yspec)
+ cxobj *xrule,
+ clixon_xvec *xpathvec,
+ yang_stmt *yspec)
{
int retval = -1;
yang_stmt *ymod;
@@ -830,32 +830,32 @@ nacm_data_read_xrule_xml(cxobj *xn,
int i;
if ((module_pattern = xml_find_body(xrule, "module-name")) == NULL)
- goto nomatch;
+ goto nomatch;
/* 6a) The rule's "module-name" leaf is "*" or equals the name of
* the YANG module where the requested data node is defined.
*/
if (strcmp(module_pattern, "*") != 0){
- if (ys_module_by_xml(yspec, xn, &ymod) < 0)
- goto done;
- if (strcmp(yang_argument_get(ymod), module_pattern) != 0)
- goto nomatch;
+ if (ys_module_by_xml(yspec, xn, &ymod) < 0)
+ goto done;
+ if (strcmp(yang_argument_get(ymod), module_pattern) != 0)
+ goto nomatch;
}
/* 6b) Either (1) the rule does not have a "rule-type" defined or
- (2) the "rule-type" is "data-node" and the "path" matches the
- requested data node, action node, or notification node. */
+ (2) the "rule-type" is "data-node" and the "path" matches the
+ requested data node, action node, or notification node. */
if (xml_find_type(xrule, NULL, "path", CX_ELMNT) == NULL){
- if (nacm_data_read_action(xrule, xn) < 0)
- goto done;
- goto match;
+ if (nacm_data_read_action(xrule, xn) < 0)
+ goto done;
+ goto match;
}
for (i=0; ipv_xrule,
- pv->pv_xpathvec,
- yspec)) < 0)
- goto done;
- if (ret == 1)
- break; /* stop at first match */
- pv = NEXTQ(prepvec *, pv);
- } while (pv && pv != pv_list);
- }
+ pv = pv_list;
+ if (pv){
+ do {
+ if ((ret = nacm_data_read_xrule_xml(xn,
+ pv->pv_xrule,
+ pv->pv_xpathvec,
+ yspec)) < 0)
+ goto done;
+ if (ret == 1)
+ break; /* stop at first match */
+ pv = NEXTQ(prepvec *, pv);
+ } while (pv && pv != pv_list);
+ }
#if 0 /* 6(A) in algorithm
* If N did not match any rule R, and default rule is deny, remove that subtree */
- if (strcmp(read_default, "deny") == 0)
- if (xml_tree_prune_flagged_sub(xt, XML_FLAG_MARK, 1, NULL) < 0)
- goto done;
+ if (strcmp(read_default, "deny") == 0)
+ if (xml_tree_prune_flagged_sub(xt, XML_FLAG_MARK, 1, NULL) < 0)
+ goto done;
#endif
}
/* If node should be purged, dont recurse and defer removal to caller */
if (xml_flag(xn, XML_FLAG_DEL) == 0){
- x = NULL; /* Recursively check XML */
- xprev = NULL;
- while ((x = xml_child_each(xn, x, CX_ELMNT)) != NULL) {
- if (nacm_datanode_read_recurse(h, x, pv_list, yspec) < 0)
- goto done;
- /* check for delayed remove */
- if (xml_flag(x, XML_FLAG_DEL)){
- if (xml_purge(x) < 0)
- goto done;
- x = xprev;
- }
- }
+ x = NULL; /* Recursively check XML */
+ xprev = NULL;
+ while ((x = xml_child_each(xn, x, CX_ELMNT)) != NULL) {
+ if (nacm_datanode_read_recurse(h, x, pv_list, yspec) < 0)
+ goto done;
+ /* check for delayed remove */
+ if (xml_flag(x, XML_FLAG_DEL)){
+ if (xml_purge(x) < 0)
+ goto done;
+ x = xprev;
+ }
+ }
}
retval = 0;
done:
@@ -980,11 +980,11 @@ nacm_datanode_read_recurse(clicon_handle h,
*/
int
nacm_datanode_read(clicon_handle h,
- cxobj *xt,
- cxobj **xrvec,
- size_t xrlen,
- char *username,
- cxobj *xnacm)
+ cxobj *xt,
+ cxobj **xrvec,
+ size_t xrlen,
+ char *username,
+ cxobj *xnacm)
{
int retval = -1;
cxobj **gvec = NULL; /* groups */
@@ -998,17 +998,17 @@ nacm_datanode_read(clicon_handle h,
/* Create namespace context for with nacm namespace as default */
if ((nsc = xml_nsctx_init(NULL, NACM_NS)) == NULL)
- goto done;
+ goto done;
/* 3. Check all the "group" entries to see if any of them contain a
"user-name" entry that equals the username for the session
making the request. (If the "enable-external-groups" leaf is
"true", add to these groups the set of groups provided by the
- transport layer.) */
+ transport layer.) */
if (username == NULL)
- goto step9;
+ goto step9;
/* User's group */
if (xpath_vec(xnacm, nsc, "groups/group[user-name='%s']", &gvec, &glen, username) < 0)
- goto done;
+ goto done;
/* 4. If no groups are found (glen=0), continue and check read-default
in step 11. */
/* 5. Process all rule-list entries, in the order they appear in the
@@ -1016,31 +1016,31 @@ nacm_datanode_read(clicon_handle h,
match any of the user's groups, proceed to the next rule-list
entry. */
if (xpath_vec(xnacm, nsc, "rule-list", &rlistvec, &rlistlen) < 0)
- goto done;
+ goto done;
/* read-default has default permit so should never be NULL */
if ((read_default = xml_find_body(xnacm, "read-default")) == NULL){
- clicon_err(OE_XML, EINVAL, "No nacm read-default rule");
- goto done;
+ clicon_err(OE_XML, EINVAL, "No nacm read-default rule");
+ goto done;
}
/* First run through rules and cache rules as well as lookup objects in xt.
* DANGER: objects could be stale if they are removed?
*/
if (nacm_datanode_prepare(h, xt, NACM_READ, gvec, glen, rlistvec, rlistlen, nsc, &pv_list) < 0)
- goto done;
+ goto done;
/* Then recursivelyy traverse all nodes */
if (nacm_datanode_read_recurse(h, xt, pv_list, clicon_dbspec_yang(h)) < 0)
- goto done;
+ goto done;
#if 1
/* Step 8(B) above:
* If default rule is deny, recursively remove all subtrees that are not marked
*/
if (strcmp(read_default, "deny") == 0)
- if (xml_tree_prune_flagged_sub(xt, XML_FLAG_MARK, 1, NULL) < 0)
- goto done;
+ if (xml_tree_prune_flagged_sub(xt, XML_FLAG_MARK, 1, NULL) < 0)
+ goto done;
#endif
/* reset flag */
if (xml_apply(xt, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)XML_FLAG_MARK) < 0)
- goto done;
+ goto done;
goto ok;
/* 8. At this point, no matching rule was found in any rule-list
@@ -1053,20 +1053,20 @@ nacm_datanode_read(clicon_handle h,
and all its descendants are not included in the reply.
*/
for (i=0; i"
- "%s "
- "in-use "
- "error ",
- NETCONF_BASE_NAMESPACE,
- type) <0)
- goto err;
+ "%s "
+ "in-use "
+ "error ",
+ NETCONF_BASE_NAMESPACE,
+ type) <0)
+ goto err;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (cprintf(cb, "%s ", encstr) < 0)
- goto err;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (cprintf(cb, "%s ", encstr) < 0)
+ goto err;
}
if (cprintf(cb, " ") <0)
- goto err;
+ goto err;
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
err:
clicon_err(OE_XML, errno, "cprintf");
@@ -126,8 +126,8 @@ netconf_in_use(cbuf *cb,
*/
int
netconf_invalid_value_xml(cxobj **xret,
- char *type,
- char *message)
+ char *type,
+ char *message)
{
int retval =-1;
cxobj *xerr = NULL;
@@ -135,37 +135,37 @@ netconf_invalid_value_xml(cxobj **xret,
cxobj *xa;
if (xret == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
- goto done;
+ if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
+ goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
- goto done;
+ goto done;
if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL,
- "%s "
- "invalid-value "
- "error ", type) < 0)
- goto done;
+ "%s "
+ "invalid-value "
+ "error ", type) < 0)
+ goto done;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL,
- "%s ", encstr) < 0)
- goto done;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL,
+ "%s ", encstr) < 0)
+ goto done;
}
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
}
@@ -178,20 +178,20 @@ netconf_invalid_value_xml(cxobj **xret,
*/
int
netconf_invalid_value(cbuf *cb,
- char *type,
- char *message)
+ char *type,
+ char *message)
{
int retval = -1;
cxobj *xret = NULL;
if (netconf_invalid_value_xml(&xret, type, message) < 0)
- goto done;
+ goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -205,31 +205,31 @@ netconf_invalid_value(cbuf *cb,
*/
int
netconf_too_big(cbuf *cb,
- char *type,
- char *message)
+ char *type,
+ char *message)
{
int retval = -1;
char *encstr = NULL;
if (cprintf(cb, ""
- "%s "
- "too-big "
- "error ",
- NETCONF_BASE_NAMESPACE,
- type) <0)
- goto err;
+ "%s "
+ "too-big "
+ "error ",
+ NETCONF_BASE_NAMESPACE,
+ type) <0)
+ goto err;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (cprintf(cb, "%s ", encstr) < 0)
- goto err;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (cprintf(cb, "%s ", encstr) < 0)
+ goto err;
}
if (cprintf(cb, " ") <0)
- goto err;
+ goto err;
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
err:
clicon_err(OE_XML, errno, "cprintf");
@@ -246,9 +246,9 @@ netconf_too_big(cbuf *cb,
*/
int
netconf_missing_attribute_xml(cxobj **xret,
- char *type,
- char *attr,
- char *message)
+ char *type,
+ char *attr,
+ char *message)
{
int retval = -1;
cxobj *xerr = NULL;
@@ -256,37 +256,37 @@ netconf_missing_attribute_xml(cxobj **xret,
cxobj *xa;
if (xret == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
- goto done;
+ if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
+ goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
- goto done;
+ goto done;
if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s "
- "missing-attribute "
- "%s "
- "error ", type, attr) < 0)
- goto done;
+ "missing-attribute "
+ "%s "
+ "error ", type, attr) < 0)
+ goto done;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
- encstr) < 0)
- goto done;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
+ encstr) < 0)
+ goto done;
}
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
}
@@ -300,21 +300,21 @@ netconf_missing_attribute_xml(cxobj **xret,
*/
int
netconf_missing_attribute(cbuf *cb,
- char *type,
- char *attr,
- char *message)
+ char *type,
+ char *attr,
+ char *message)
{
int retval = -1;
cxobj *xret = NULL;
if (netconf_missing_attribute_xml(&xret, type, attr, message) < 0)
- goto done;
+ goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -329,21 +329,21 @@ netconf_missing_attribute(cbuf *cb,
*/
int
netconf_bad_attribute(cbuf *cb,
- char *type,
- char *info,
- char *message)
+ char *type,
+ char *info,
+ char *message)
{
int retval = -1;
cxobj *xret = NULL;
if (netconf_bad_attribute_xml(&xret, type, info, message) < 0)
- goto done;
+ goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -358,9 +358,9 @@ netconf_bad_attribute(cbuf *cb,
*/
int
netconf_bad_attribute_xml(cxobj **xret,
- char *type,
- char *info,
- char *message)
+ char *type,
+ char *info,
+ char *message)
{
int retval = -1;
cxobj *xerr = NULL;
@@ -368,37 +368,37 @@ netconf_bad_attribute_xml(cxobj **xret,
cxobj *xa;
if (xret == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
- goto done;
+ if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
+ goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
- goto done;
+ goto done;
if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s "
- "bad-attribute "
- "%s "
- "error ", type, info) < 0)
- goto done;
+ "bad-attribute "
+ "%s "
+ "error ", type, info) < 0)
+ goto done;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
- encstr) < 0)
- goto done;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
+ encstr) < 0)
+ goto done;
}
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
}
@@ -412,32 +412,32 @@ netconf_bad_attribute_xml(cxobj **xret,
*/
int
netconf_unknown_attribute(cbuf *cb,
- char *type,
- char *info,
- char *message)
+ char *type,
+ char *info,
+ char *message)
{
int retval = -1;
char *encstr = NULL;
if (cprintf(cb, ""
- "%s "
- "unknown-attribute "
- "%s "
- "error ",
- NETCONF_BASE_NAMESPACE, type, info) <0)
- goto err;
+ "%s "
+ "unknown-attribute "
+ "%s "
+ "error ",
+ NETCONF_BASE_NAMESPACE, type, info) <0)
+ goto err;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (cprintf(cb, "%s ", encstr) < 0)
- goto err;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (cprintf(cb, "%s ", encstr) < 0)
+ goto err;
}
if (cprintf(cb, " ") <0)
- goto err;
+ goto err;
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
err:
clicon_err(OE_XML, errno, "cprintf");
@@ -453,11 +453,11 @@ netconf_unknown_attribute(cbuf *cb,
*/
static int
netconf_common_xml(cxobj **xret,
- char *type,
- char *tag,
- char *infotag,
- char *element,
- char *message)
+ char *type,
+ char *tag,
+ char *infotag,
+ char *element,
+ char *message)
{
int retval =-1;
cxobj *xerr;
@@ -465,39 +465,39 @@ netconf_common_xml(cxobj **xret,
cxobj *xa;
if (xret == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
- goto done;
- if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
- goto done;
- if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
+ goto done;
+ if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
+ goto done;
+ if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
+ goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
- goto done;
+ goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s "
- "%s "
- "<%s>%s%s> "
- "error ",
- type, tag, infotag, element, infotag) < 0)
- goto done;
+ "%s "
+ "<%s>%s%s> "
+ "error ",
+ type, tag, infotag, element, infotag) < 0)
+ goto done;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
- encstr) < 0)
- goto done;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
+ encstr) < 0)
+ goto done;
}
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
}
@@ -511,22 +511,22 @@ netconf_common_xml(cxobj **xret,
*/
int
netconf_missing_element(cbuf *cb,
- char *type,
- char *element,
- char *message)
+ char *type,
+ char *element,
+ char *message)
{
int retval = -1;
cxobj *xret = NULL;
if (netconf_common_xml(&xret, type, "missing-element",
- "bad-element", element, message) < 0)
- goto done;
+ "bad-element", element, message) < 0)
+ goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -538,12 +538,12 @@ netconf_missing_element(cbuf *cb,
*/
int
netconf_missing_element_xml(cxobj **xret,
- char *type,
- char *element,
- char *message)
+ char *type,
+ char *element,
+ char *message)
{
return netconf_common_xml(xret, type, "missing-element",
- "bad-element", element, message);
+ "bad-element", element, message);
}
/*! Create Netconf bad-element error XML tree according to RFC 6241 App A
@@ -557,30 +557,30 @@ netconf_missing_element_xml(cxobj **xret,
*/
int
netconf_bad_element(cbuf *cb,
- char *type,
- char *element,
- char *message)
+ char *type,
+ char *element,
+ char *message)
{
int retval = -1;
cxobj *xret = NULL;
if (netconf_common_xml(&xret, type, "bad-element",
- "bad-element",element, message) < 0)
- goto done;
+ "bad-element",element, message) < 0)
+ goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
int
netconf_bad_element_xml(cxobj **xret,
- char *type,
- char *element,
- char *message)
+ char *type,
+ char *element,
+ char *message)
{
return netconf_common_xml(xret, type, "bad-element", "bad-element", element, message);
}
@@ -595,22 +595,22 @@ netconf_bad_element_xml(cxobj **xret,
*/
int
netconf_unknown_element(cbuf *cb,
- char *type,
- char *element,
- char *message)
+ char *type,
+ char *element,
+ char *message)
{
int retval = -1;
cxobj *xret = NULL;
if (netconf_common_xml(&xret, type, "unknown-element",
- "bad-element", element, message) < 0)
- goto done;
+ "bad-element", element, message) < 0)
+ goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -624,12 +624,12 @@ netconf_unknown_element(cbuf *cb,
*/
int
netconf_unknown_element_xml(cxobj **xret,
- char *type,
- char *element,
- char *message)
+ char *type,
+ char *element,
+ char *message)
{
return netconf_common_xml(xret, type, "unknown-element",
- "bad-element", element, message);
+ "bad-element", element, message);
}
/*! Create Netconf unknown-namespace error XML tree according to RFC 6241 App A
@@ -642,33 +642,33 @@ netconf_unknown_element_xml(cxobj **xret,
*/
int
netconf_unknown_namespace(cbuf *cb,
- char *type,
- char *ns,
- char *message)
+ char *type,
+ char *ns,
+ char *message)
{
int retval = -1;
cxobj *xret = NULL;
if (netconf_common_xml(&xret, type, "unknown-namespace",
- "bad-namespace", ns, message) < 0)
- goto done;
+ "bad-namespace", ns, message) < 0)
+ goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
int
netconf_unknown_namespace_xml(cxobj **xret,
- char *type,
- char *ns,
- char *message)
+ char *type,
+ char *ns,
+ char *message)
{
return netconf_common_xml(xret, type, "unknown-namespace",
- "bad-namespace", ns, message);
+ "bad-namespace", ns, message);
}
/*! Create Netconf access-denied error cbuf according to RFC 6241 App A
@@ -682,20 +682,20 @@ netconf_unknown_namespace_xml(cxobj **xret,
*/
int
netconf_access_denied(cbuf *cb,
- char *type,
- char *message)
+ char *type,
+ char *message)
{
int retval = -1;
cxobj *xret = NULL;
if (netconf_access_denied_xml(&xret, type, message) < 0)
- goto done;
+ goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -716,8 +716,8 @@ netconf_access_denied(cbuf *cb,
*/
int
netconf_access_denied_xml(cxobj **xret,
- char *type,
- char *message)
+ char *type,
+ char *message)
{
int retval =-1;
cxobj *xerr;
@@ -725,36 +725,36 @@ netconf_access_denied_xml(cxobj **xret,
cxobj *xa;
if (xret == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
- goto done;
+ if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
+ goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
- goto done;
+ goto done;
if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s "
- "access-denied "
- "error ", type) < 0)
- goto done;
+ "access-denied "
+ "error ", type) < 0)
+ goto done;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
- encstr) < 0)
- goto done;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
+ encstr) < 0)
+ goto done;
}
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
}
@@ -768,31 +768,31 @@ netconf_access_denied_xml(cxobj **xret,
*/
int
netconf_lock_denied(cbuf *cb,
- char *info,
- char *message)
+ char *info,
+ char *message)
{
int retval = -1;
char *encstr = NULL;
if (cprintf(cb, ""
- "protocol "
- "lock-denied "
- "%s "
- "error ",
- NETCONF_BASE_NAMESPACE, info) <0)
- goto err;
+ "protocol "
+ "lock-denied "
+ "%s "
+ "error ",
+ NETCONF_BASE_NAMESPACE, info) <0)
+ goto err;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (cprintf(cb, "%s ", encstr) < 0)
- goto err;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (cprintf(cb, "%s ", encstr) < 0)
+ goto err;
}
if (cprintf(cb, " ") <0)
- goto err;
+ goto err;
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
err:
clicon_err(OE_XML, errno, "cprintf");
@@ -808,30 +808,30 @@ netconf_lock_denied(cbuf *cb,
*/
int
netconf_resource_denied(cbuf *cb,
- char *type,
- char *message)
+ char *type,
+ char *message)
{
int retval = -1;
char *encstr = NULL;
if (cprintf(cb, ""
- "%s "
- "resource-denied "
- "error ",
- NETCONF_BASE_NAMESPACE, type) <0)
- goto err;
+ "%s "
+ "resource-denied "
+ "error ",
+ NETCONF_BASE_NAMESPACE, type) <0)
+ goto err;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (cprintf(cb, "%s ", encstr) < 0)
- goto err;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (cprintf(cb, "%s ", encstr) < 0)
+ goto err;
}
if (cprintf(cb, " ") <0)
- goto err;
+ goto err;
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
err:
clicon_err(OE_XML, errno, "cprintf");
@@ -848,30 +848,30 @@ netconf_resource_denied(cbuf *cb,
*/
int
netconf_rollback_failed(cbuf *cb,
- char *type,
- char *message)
+ char *type,
+ char *message)
{
int retval = -1;
char *encstr = NULL;
if (cprintf(cb, ""
- "%s "
- "rollback-failed "
- "error ",
- NETCONF_BASE_NAMESPACE, type) <0)
- goto err;
+ "%s "
+ "rollback-failed "
+ "error ",
+ NETCONF_BASE_NAMESPACE, type) <0)
+ goto err;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (cprintf(cb, "%s ", encstr) < 0)
- goto err;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (cprintf(cb, "%s ", encstr) < 0)
+ goto err;
}
if (cprintf(cb, " ") <0)
- goto err;
+ goto err;
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
err:
clicon_err(OE_XML, errno, "cprintf");
@@ -888,29 +888,29 @@ netconf_rollback_failed(cbuf *cb,
*/
int
netconf_data_exists(cbuf *cb,
- char *message)
+ char *message)
{
int retval = -1;
char *encstr = NULL;
if (cprintf(cb, ""
- "application "
- "data-exists "
- "error ",
- NETCONF_BASE_NAMESPACE) <0)
- goto err;
+ "application "
+ "data-exists "
+ "error ",
+ NETCONF_BASE_NAMESPACE) <0)
+ goto err;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (cprintf(cb, "%s ", encstr) < 0)
- goto err;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (cprintf(cb, "%s ", encstr) < 0)
+ goto err;
}
if (cprintf(cb, " ") <0)
- goto err;
+ goto err;
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
err:
clicon_err(OE_XML, errno, "cprintf");
@@ -927,19 +927,19 @@ netconf_data_exists(cbuf *cb,
*/
int
netconf_data_missing(cbuf *cb,
- char *message)
+ char *message)
{
int retval = -1;
cxobj *xret = NULL;
if (netconf_data_missing_xml(&xret, message) < 0)
- goto done;
+ goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -953,7 +953,7 @@ netconf_data_missing(cbuf *cb,
*/
int
netconf_data_missing_xml(cxobj **xret,
- char *message)
+ char *message)
{
int retval = -1;
char *encstr = NULL;
@@ -961,39 +961,39 @@ netconf_data_missing_xml(cxobj **xret,
cxobj *xa;
if (xret == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
- goto done;
+ if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
+ goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
- goto done;
+ goto done;
if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL,
- "application "
- "data-missing ") < 0)
- goto done;
+ "application "
+ "data-missing ") < 0)
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL,
- "error ") < 0)
- goto done;
+ "error ") < 0)
+ goto done;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL,
- "%s ", encstr) < 0)
- goto done;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL,
+ "%s ", encstr) < 0)
+ goto done;
}
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
}
@@ -1009,9 +1009,9 @@ netconf_data_missing_xml(cxobj **xret,
*/
int
netconf_missing_choice_xml(cxobj **xret,
- cxobj *x,
- char *name,
- char *message)
+ cxobj *x,
+ char *name,
+ char *message)
{
int retval = -1;
char *encstr = NULL;
@@ -1021,52 +1021,52 @@ netconf_missing_choice_xml(cxobj **xret,
char *encpath = NULL;
if (xret == NULL || name == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret or name is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret or name is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
- goto done;
+ if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
+ goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
- goto done;
+ goto done;
if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
/* error-path: Path to the element with the missing choice. */
if (xml2xpath(x, NULL, &path) < 0)
- goto done;
+ goto done;
if (xml_chardata_encode(&encpath, "%s", path) < 0)
- goto done;
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL,
- "application "
- "data-missing "
+ "application "
+ "data-missing "
"missing-choice "
- "%s "
- "%s "
- "error ",
- encpath,
- YANG_XML_NAMESPACE,
- name) < 0)
- goto done;
+ "%s "
+ "%s "
+ "error ",
+ encpath,
+ YANG_XML_NAMESPACE,
+ name) < 0)
+ goto done;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL,
- "%s ", encstr) < 0)
- goto done;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL,
+ "%s ", encstr) < 0)
+ goto done;
}
retval = 0;
done:
if (path)
- free(path);
+ free(path);
if (encstr)
- free(encstr);
+ free(encstr);
if (encpath)
- free(encpath);
+ free(encpath);
return retval;
}
@@ -1087,8 +1087,8 @@ netconf_missing_choice_xml(cxobj **xret,
*/
int
netconf_operation_not_supported_xml(cxobj **xret,
- char *type,
- char *message)
+ char *type,
+ char *message)
{
int retval =-1;
cxobj *xerr;
@@ -1096,37 +1096,37 @@ netconf_operation_not_supported_xml(cxobj **xret,
cxobj *xa;
if (xret == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
- goto done;
+ if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
+ goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
- goto done;
+ goto done;
if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s "
- "operation-not-supported "
- "error ",
- type) < 0)
- goto done;
+ "operation-not-supported "
+ "error ",
+ type) < 0)
+ goto done;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
- encstr) < 0)
- goto done;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
+ encstr) < 0)
+ goto done;
}
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
}
@@ -1140,20 +1140,20 @@ netconf_operation_not_supported_xml(cxobj **xret,
*/
int
netconf_operation_not_supported(cbuf *cb,
- char *type,
- char *message)
+ char *type,
+ char *message)
{
int retval = -1;
cxobj *xret = NULL;
if (netconf_operation_not_supported_xml(&xret, type, message) < 0)
- goto done;
+ goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -1168,20 +1168,20 @@ netconf_operation_not_supported(cbuf *cb,
*/
int
netconf_operation_failed(cbuf *cb,
- char *type,
- char *message)
+ char *type,
+ char *message)
{
int retval = -1;
cxobj *xret = NULL;
if (netconf_operation_failed_xml(&xret, type, message) < 0)
- goto done;
+ goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -1202,8 +1202,8 @@ netconf_operation_failed(cbuf *cb,
*/
int
netconf_operation_failed_xml(cxobj **xret,
- char *type,
- char *message)
+ char *type,
+ char *message)
{
int retval =-1;
cxobj *xerr;
@@ -1211,37 +1211,37 @@ netconf_operation_failed_xml(cxobj **xret,
cxobj *xa;
if (xret == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
- goto done;
+ if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
+ goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
- goto done;
+ goto done;
if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s "
- "operation-failed "
- "error ",
- type) < 0)
- goto done;
+ "operation-failed "
+ "error ",
+ type) < 0)
+ goto done;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
- encstr) < 0)
- goto done;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
+ encstr) < 0)
+ goto done;
}
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
}
@@ -1257,19 +1257,19 @@ netconf_operation_failed_xml(cxobj **xret,
*/
int
netconf_malformed_message(cbuf *cb,
- char *message)
+ char *message)
{
int retval = -1;
cxobj *xret = NULL;
if (netconf_malformed_message_xml(&xret, message) < 0)
- goto done;
+ goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -1291,7 +1291,7 @@ netconf_malformed_message(cbuf *cb,
*/
int
netconf_malformed_message_xml(cxobj **xret,
- char *message)
+ char *message)
{
int retval =-1;
cxobj *xerr;
@@ -1299,36 +1299,36 @@ netconf_malformed_message_xml(cxobj **xret,
cxobj *xa;
if (xret == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
- goto done;
+ if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
+ goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
- goto done;
+ goto done;
if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "rpc "
- "malformed-message "
- "error ") < 0)
- goto done;
+ "malformed-message "
+ "error ") < 0)
+ goto done;
if (message){
- if (xml_chardata_encode(&encstr, "%s", message) < 0)
- goto done;
- if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
- encstr) < 0)
- goto done;
+ if (xml_chardata_encode(&encstr, "%s", message) < 0)
+ goto done;
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "%s ",
+ encstr) < 0)
+ goto done;
}
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
}
@@ -1343,8 +1343,8 @@ netconf_malformed_message_xml(cxobj **xret,
*/
int
netconf_data_not_unique_xml(cxobj **xret,
- cxobj *x,
- cvec *cvk)
+ cxobj *x,
+ cvec *cvk)
{
int retval = -1;
cg_var *cvi = NULL;
@@ -1355,52 +1355,52 @@ netconf_data_not_unique_xml(cxobj **xret,
char *encpath = NULL;
if (xret == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
- goto done;
+ if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
+ goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
- goto done;
+ goto done;
if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL,
- "application "
- "operation-failed "
- "data-not-unique "
- "error ") < 0)
- goto done;
+ "application "
+ "operation-failed "
+ "data-not-unique "
+ "error ") < 0)
+ goto done;
/* error-info: Contains an instance identifier that points to a leaf
* that invalidates the "unique" constraint. This element is present once for each
* non-unique leaf. */
if (cvec_len(cvk)){
- if ((xinfo = xml_new("error-info", xerr, CX_ELMNT)) == NULL)
- goto done;
- if (xml2xpath(x, NULL, &path) < 0)
- goto done;
- if (xml_chardata_encode(&encpath, "%s", path) < 0)
- goto done;
- while ((cvi = cvec_each(cvk, cvi)) != NULL){
- if (clixon_xml_parse_va(YB_NONE, NULL, &xinfo, NULL,
- "%s/%s ",
- YANG_XML_NAMESPACE,
- encpath,
- cv_string_get(cvi)) < 0)
- goto done;
- }
+ if ((xinfo = xml_new("error-info", xerr, CX_ELMNT)) == NULL)
+ goto done;
+ if (xml2xpath(x, NULL, &path) < 0)
+ goto done;
+ if (xml_chardata_encode(&encpath, "%s", path) < 0)
+ goto done;
+ while ((cvi = cvec_each(cvk, cvi)) != NULL){
+ if (clixon_xml_parse_va(YB_NONE, NULL, &xinfo, NULL,
+ "%s/%s ",
+ YANG_XML_NAMESPACE,
+ encpath,
+ cv_string_get(cvi)) < 0)
+ goto done;
+ }
}
retval = 0;
done:
if (path)
- free(path);
+ free(path);
if (encpath)
- free(encpath);
+ free(encpath);
return retval;
}
@@ -1416,9 +1416,9 @@ netconf_data_not_unique_xml(cxobj **xret,
*/
int
netconf_minmax_elements_xml(cxobj **xret,
- cxobj *xp,
- char *name,
- int max)
+ cxobj *xp,
+ char *name,
+ int max)
{
int retval = -1;
cxobj *xerr;
@@ -1427,42 +1427,42 @@ netconf_minmax_elements_xml(cxobj **xret,
cxobj *xa;
if (xret == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
- goto done;
+ if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
+ goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
- goto done;
+ goto done;
if ((xa = xml_new("xmlns", *xret, CX_ATTR)) == NULL)
- goto done;
+ goto done;
if (xml_value_set(xa, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (xml_parent(xp)){ /* Dont include root, eg */
if (xml2xpath(xp, NULL, &path) < 0)
goto done;
- if (xml_chardata_encode(&encpath, "%s", path) < 0)
- goto done;
+ if (xml_chardata_encode(&encpath, "%s", path) < 0)
+ goto done;
}
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "protocol "
- "operation-failed "
- "too-%s-elements "
- "error "
- "%s/%s ",
- max?"many":"few",
- encpath?encpath:"",
- name) < 0)
- goto done;
+ "operation-failed "
+ "too-%s-elements "
+ "error "
+ "%s/%s ",
+ max?"many":"few",
+ encpath?encpath:"",
+ name) < 0)
+ goto done;
retval = 0;
done:
if (path)
- free(path);
+ free(path);
if (encpath)
- free(encpath);
+ free(encpath);
return retval;
}
@@ -1476,36 +1476,36 @@ netconf_minmax_elements_xml(cxobj **xret,
*/
int
netconf_trymerge(cxobj *x,
- yang_stmt *yspec,
- cxobj **xret)
+ yang_stmt *yspec,
+ cxobj **xret)
{
int retval = -1;
char *reason = NULL;
cxobj *xc;
if (xret == NULL){
- clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
+ goto done;
}
if (*xret == NULL){
- if ((*xret = xml_dup(x)) == NULL)
- goto done;
- goto ok;
+ if ((*xret = xml_dup(x)) == NULL)
+ goto done;
+ goto ok;
}
if (xml_merge(*xret, x, yspec, &reason) < 0)
- goto done;
+ goto done;
if (reason){
- while ((xc = xml_child_i(*xret, 0)) != NULL)
- xml_purge(xc);
- if (netconf_operation_failed_xml(xret, "rpc", reason)< 0)
- goto done;
- goto fail;
+ while ((xc = xml_child_i(*xret, 0)) != NULL)
+ xml_purge(xc);
+ if (netconf_operation_failed_xml(xret, "rpc", reason)< 0)
+ goto done;
+ goto fail;
}
ok:
retval = 1;
done:
if (reason)
- free(reason);
+ free(reason);
return retval;
fail:
retval = 0;
@@ -1533,19 +1533,19 @@ netconf_module_features(clicon_handle h)
cxobj *xc;
if ((xc = clicon_conf_xml(h)) == NULL){
- clicon_err(OE_CFG, ENOENT, "Clicon configuration not loaded");
- goto done;
+ clicon_err(OE_CFG, ENOENT, "Clicon configuration not loaded");
+ goto done;
}
/* Enable features (hardcoded here) */
if (clixon_xml_parse_string("ietf-netconf:candidate ",
- YB_PARENT, NULL, &xc, NULL) < 0)
- goto done;
+ YB_PARENT, NULL, &xc, NULL) < 0)
+ goto done;
if (clixon_xml_parse_string("ietf-netconf:validate ",
- YB_PARENT, NULL, &xc, NULL) < 0)
- goto done;
+ YB_PARENT, NULL, &xc, NULL) < 0)
+ goto done;
if (clixon_xml_parse_string("ietf-netconf:xpath ",
- YB_PARENT, NULL, &xc, NULL) < 0)
- goto done;
+ YB_PARENT, NULL, &xc, NULL) < 0)
+ goto done;
retval = 0;
done:
return retval;
@@ -1566,48 +1566,48 @@ netconf_module_load(clicon_handle h)
yspec = clicon_dbspec_yang(h);
/* Load yang spec */
if (yang_spec_parse_module(h, "ietf-netconf", NULL, yspec)< 0)
- goto done;
+ goto done;
/* Load yang Netconf stream discovery */
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC5277"))
- if (yang_spec_parse_module(h, "clixon-rfc5277", NULL, yspec)< 0)
- goto done;
+ if (yang_spec_parse_module(h, "clixon-rfc5277", NULL, yspec)< 0)
+ goto done;
/* Load yang Restconf stream discovery */
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040") &&
- yang_spec_parse_module(h, "ietf-restconf-monitoring", NULL, yspec)< 0)
- goto done;
+ yang_spec_parse_module(h, "ietf-restconf-monitoring", NULL, yspec)< 0)
+ goto done;
/* YANG module revision change management */
if (clicon_option_bool(h, "CLICON_XML_CHANGELOG"))
- if (yang_spec_parse_module(h, "clixon-xml-changelog", NULL, yspec)< 0)
- goto done;
+ if (yang_spec_parse_module(h, "clixon-xml-changelog", NULL, yspec)< 0)
+ goto done;
/* Load restconf yang to data. Note clixon-restconf.yang is always part of clixon-config */
if (clicon_option_bool(h, "CLICON_BACKEND_RESTCONF_PROCESS"))
- if (yang_spec_parse_module(h, "clixon-restconf", NULL, yspec)< 0)
- goto done;
+ if (yang_spec_parse_module(h, "clixon-restconf", NULL, yspec)< 0)
+ goto done;
/* XXX: Both the following settings are because clicon-handle is not part of all API
* functions
* Treat unknown XML as anydata */
if (clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1)
- xml_bind_yang_unknown_anydata(1);
+ xml_bind_yang_unknown_anydata(1);
/* Make message-id attribute optional */
if (clicon_option_bool(h, "CLICON_NETCONF_MESSAGE_ID_OPTIONAL") == 1)
- xml_bind_netconf_message_id_optional(1);
+ xml_bind_netconf_message_id_optional(1);
/* Load ietf list pagination */
if (yang_spec_parse_module(h, "ietf-list-pagination", NULL, yspec)< 0)
- goto done;
+ goto done;
/* Load ietf list pagination netconf */
if (yang_spec_parse_module(h, "ietf-list-pagination-nc", NULL, yspec)< 0)
- goto done;
+ goto done;
/* Load rfc6243 with-defaults module explicit (imported by ietf-list-pagination-nc) */
if (yang_spec_parse_module(h, "ietf-netconf-with-defaults", NULL, yspec)< 0)
- goto done;
+ goto done;
/* Framing: If hello protocol skipped, set framing direct, ie fix chunked framing if NETCONF-1.1
* But start with default: RFC 4741 EOM ]]>]]>
* For now this only applies to external protocol
*/
clicon_option_int_set(h, "netconf-framing", NETCONF_SSH_EOM);
if (clicon_option_bool(h, "CLICON_NETCONF_HELLO_OPTIONAL")){
- if (clicon_option_int(h, "CLICON_NETCONF_BASE_CAPABILITY") > 0) /* RFC 6241 */
- clicon_option_int_set(h, "netconf-framing", NETCONF_SSH_CHUNKED);
+ if (clicon_option_int(h, "CLICON_NETCONF_BASE_CAPABILITY") > 0) /* RFC 6241 */
+ clicon_option_int_set(h, "netconf-framing", NETCONF_SSH_CHUNKED);
}
retval = 0;
done:
@@ -1630,7 +1630,7 @@ netconf_module_load(clicon_handle h)
*/
char*
netconf_db_find(cxobj *xn,
- char *name)
+ char *name)
{
cxobj *xs; /* source */
cxobj *xi;
@@ -1638,9 +1638,9 @@ netconf_db_find(cxobj *xn,
/* XXX should use prefix cf edit_config */
if ((xs = xml_find(xn, name)) == NULL)
- goto done;
+ goto done;
if ((xi = xml_child_i(xs, 0)) == NULL)
- goto done;
+ goto done;
db = xml_name(xi);
done:
return db;
@@ -1654,7 +1654,7 @@ netconf_db_find(cxobj *xn,
* @code
* cbuf *cb = NULL;
* if ((cb = cbuf_new()) ==NULL){
- * err;
+ * err;
* if (netconf_err2cb(xerr, cb) < 0)
* err;
* printf("%s", cbuf_get(cb));
@@ -1664,26 +1664,26 @@ netconf_db_find(cxobj *xn,
*/
int
netconf_err2cb(cxobj *xerr,
- cbuf *cberr)
+ cbuf *cberr)
{
int retval = -1;
cxobj *x;
if ((x=xpath_first(xerr, NULL, "//error-type"))!=NULL)
- cprintf(cberr, "%s ", xml_body(x));
+ cprintf(cberr, "%s ", xml_body(x));
if ((x=xpath_first(xerr, NULL, "//error-tag"))!=NULL)
- cprintf(cberr, "%s ", xml_body(x));
+ cprintf(cberr, "%s ", xml_body(x));
if ((x=xpath_first(xerr, NULL, "//error-message"))!=NULL)
- cprintf(cberr, "%s ", xml_body(x));
+ cprintf(cberr, "%s ", xml_body(x));
if ((x=xpath_first(xerr, NULL, "//error-info")) != NULL &&
- xml_child_nr(x) > 0){
- if (clixon_xml2cbuf(cberr, xml_child_i(x, 0), 0, 0, -1, 0) < 0)
- goto done;
+ xml_child_nr(x) > 0){
+ if (clixon_xml2cbuf(cberr, xml_child_i(x, 0), 0, 0, -1, 0) < 0)
+ goto done;
}
if ((x=xpath_first(xerr, NULL, "//error-app-tag"))!=NULL)
- cprintf(cberr, ": %s ", xml_body(x));
+ cprintf(cberr, ": %s ", xml_body(x));
if ((x=xpath_first(xerr, NULL, "//error-path"))!=NULL)
- cprintf(cberr, ": %s ", xml_body(x));
+ cprintf(cberr, ": %s ", xml_body(x));
retval = 0;
done:
return retval;
@@ -1752,61 +1752,75 @@ netconf_content_int2str(netconf_content nr)
* backend, and backend may implement more modules - please consider if using
* library routines for detecting capabilities here. In contrast, yang module
* list (RFC7895) is processed by the backend.
- * @note encode bodies, see xml_chardata_encode()
+ * @note If you add new, remember to encode bodies if needed, see xml_chardata_encode()
+ * @note
* @see yang_modules_state_get
* @see netconf_module_load
*/
int
netconf_hello_server(clicon_handle h,
- cbuf *cb,
- uint32_t session_id)
+ cbuf *cb,
+ uint32_t session_id)
{
int retval = -1;
char *module_set_id;
char *ietf_yang_library_revision;
char *encstr = NULL;
+ yang_stmt *yspec = clicon_dbspec_yang(h);
module_set_id = clicon_option_str(h, "CLICON_MODULE_SET_ID");
cprintf(cb, "", NETCONF_BASE_NAMESPACE);
cprintf(cb, "");
if (clicon_option_int(h, "CLICON_NETCONF_BASE_CAPABILITY") > 0){
- /* Each peer MUST send at least the base NETCONF capability, "urn:ietf:params:netconf:base:1.1"
- * RFC 6241 Sec 8.1
- */
- cprintf(cb, "%s ", NETCONF_BASE_CAPABILITY_1_1);
+ /* Each peer MUST send at least the base NETCONF capability, "urn:ietf:params:netconf:base:1.1"
+ * RFC 6241 Sec 8.1
+ */
+ cprintf(cb, "%s ", NETCONF_BASE_CAPABILITY_1_1);
}
/* A peer MAY include capabilities for previous NETCONF versions, to indicate
that it supports multiple protocol versions. */
cprintf(cb, "%s ", NETCONF_BASE_CAPABILITY_1_0);
+
/* Check if RFC7895 loaded and revision found */
if ((ietf_yang_library_revision = yang_modules_revision(h)) != NULL){
- if (xml_chardata_encode(&encstr, "urn:ietf:params:netconf:capability:yang-library:1.0?revision=%s&module-set-id=%s",
- ietf_yang_library_revision,
- module_set_id) < 0)
- goto done;
- cprintf(cb, "%s ", encstr);
- if (encstr){
- free(encstr);
- encstr = NULL;
- }
+ if (xml_chardata_encode(&encstr, "urn:ietf:params:netconf:capability:yang-library:1.0?revision=%s&module-set-id=%s",
+ ietf_yang_library_revision,
+ module_set_id) < 0)
+ goto done;
+ cprintf(cb, "%s ", encstr);
+ if (encstr){
+ free(encstr);
+ encstr = NULL;
+ }
}
+ /* RFC6241 Sec 8.3. Candidate Configuration Capability */
cprintf(cb, "urn:ietf:params:netconf:capability:candidate:1.0 ");
+ /* RFC6241 Sec 8.6. Validate Capability */
cprintf(cb, "urn:ietf:params:netconf:capability:validate:1.1 ");
- cprintf(cb, "urn:ietf:params:netconf:capability:startup:1.0 ");
+ /* rfc 6241 Sec 8.7 Distinct Startup Capability */
+ if (if_feature(yspec, "ietf-netconf", "startup"))
+ cprintf(cb, "urn:ietf:params:netconf:capability:startup:1.0 ");
+ /* RFC6241 Sec 8.9. XPath Capability */
cprintf(cb, "urn:ietf:params:netconf:capability:xpath:1.0 ");
- cprintf(cb, "urn:ietf:params:netconf:capability:notification:1.0 ");
/* rfc6243 with-defaults capability modes */
cprintf(cb, "");
xml_chardata_cbuf_append(cb, "urn:ietf:params:netconf:capability:with-defaults:1.0?basic-mode=explicit&also-supported=report-all,trim,report-all-tagged");
cprintf(cb, " ");
+ /* RFC5277 Notification Capability */
+ cprintf(cb, "urn:ietf:params:netconf:capability:notification:1.0 ");
+ /* It is somewhat arbitrary why some features/capabilities are hardocded and why some are not
+ * rfc 6241 Sec 8.4 confirmed-commit capabilities */
+ if (if_feature(yspec, "ietf-netconf", "confirmed-commit"))
+ cprintf(cb, "urn:ietf:params:netconf:capability:confirmed-commit:1.1 ");
+
cprintf(cb, " ");
if (session_id)
- cprintf(cb, "%lu ", (long unsigned int)session_id);
+ cprintf(cb, "%lu ", (long unsigned int)session_id);
cprintf(cb, " ");
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
}
@@ -1822,27 +1836,27 @@ netconf_hello_server(clicon_handle h,
*/
int
clixon_netconf_error_fn(const char *fn,
- const int line,
- cxobj *xerr,
- const char *msg,
- const char *arg)
+ const int line,
+ cxobj *xerr,
+ const char *msg,
+ const char *arg)
{
int retval = -1;
cbuf *cb = NULL;
if ((cb = cbuf_new()) ==NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
if (msg){
- cprintf(cb, "%s", msg);
- if (arg)
- cprintf(cb, " \"%s\" ", arg);
-
- cprintf(cb, ": ");
+ cprintf(cb, "%s", msg);
+ if (arg)
+ cprintf(cb, " \"%s\" ", arg);
+
+ cprintf(cb, ": ");
}
if (netconf_err2cb(xerr, cb) < 0)
- goto done;
+ goto done;
#if 0 /* More verbose output for debugging */
clicon_log(LOG_ERR, "%s: %d: %s", fn, line, cbuf_get(cb));
#else
@@ -1851,7 +1865,7 @@ clixon_netconf_error_fn(const char *fn,
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -1870,24 +1884,24 @@ clixon_netconf_error_fn(const char *fn,
*/
int
clixon_netconf_internal_error(cxobj *xerr,
- char *msg,
- char *arg)
+ char *msg,
+ char *arg)
{
int retval = -1;
cxobj *xr;
cxobj *xb;
if ((xr = xpath_first(xerr, NULL, "//error-tag")) != NULL &&
- (xb = xml_body_get(xr))){
- if (xml_value_set(xb, "operation-failed") < 0)
- goto done;
+ (xb = xml_body_get(xr))){
+ if (xml_value_set(xb, "operation-failed") < 0)
+ goto done;
}
if ((xr = xpath_first(xerr, NULL, "//error-message")) != NULL &&
- (xb = xml_body_get(xr))){
- if (xml_value_append(xb, msg) < 0)
- goto done;
- if (arg &&xml_value_append(xb, arg) < 0)
- goto done;
+ (xb = xml_body_get(xr))){
+ if (xml_value_append(xb, msg) < 0)
+ goto done;
+ if (arg &&xml_value_append(xb, arg) < 0)
+ goto done;
}
retval = 0;
done:
@@ -1921,38 +1935,38 @@ clixon_netconf_internal_error(cxobj *xerr,
*/
int
netconf_parse_uint32(char *name,
- char *valstr,
- char *defaultstr,
- uint32_t defaultvalue,
- cbuf *cbret,
- uint32_t *value)
+ char *valstr,
+ char *defaultstr,
+ uint32_t defaultvalue,
+ cbuf *cbret,
+ uint32_t *value)
{
int retval = -1;
int ret;
char *reason = NULL;
if (valstr == NULL){
- clicon_err(OE_NETCONF, EINVAL, "valstr is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "valstr is NULL");
+ goto done;
}
if (defaultstr && strcmp(valstr, defaultstr) == 0)
- *value = defaultvalue;
+ *value = defaultvalue;
else {
- if ((ret = parse_uint32(valstr, value, &reason)) < 0){
- clicon_err(OE_XML, errno, "parse_uint32");
- goto done;
- }
- if (ret == 0){
- if (netconf_bad_element(cbret, "application",
- name, "Unrecognized value") < 0)
- goto done;
- goto fail;
- }
+ if ((ret = parse_uint32(valstr, value, &reason)) < 0){
+ clicon_err(OE_XML, errno, "parse_uint32");
+ goto done;
+ }
+ if (ret == 0){
+ if (netconf_bad_element(cbret, "application",
+ name, "Unrecognized value") < 0)
+ goto done;
+ goto fail;
+ }
}
retval = 1;
done:
if (reason)
- free(reason);
+ free(reason);
return retval;
fail:
retval = 0;
@@ -1964,38 +1978,38 @@ netconf_parse_uint32(char *name,
*/
int
netconf_parse_uint32_xml(char *name,
- char *valstr,
- char *defaultstr,
- uint32_t defaultvalue,
- cxobj **xerr,
- uint32_t *value)
+ char *valstr,
+ char *defaultstr,
+ uint32_t defaultvalue,
+ cxobj **xerr,
+ uint32_t *value)
{
int retval = -1;
int ret;
char *reason = NULL;
if (valstr == NULL){
- clicon_err(OE_NETCONF, EINVAL, "valstr is NULL");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "valstr is NULL");
+ goto done;
}
if (defaultstr && strcmp(valstr, defaultstr) == 0)
- *value = defaultvalue;
+ *value = defaultvalue;
else {
- if ((ret = parse_uint32(valstr, value, &reason)) < 0){
- clicon_err(OE_XML, errno, "parse_uint32");
- goto done;
- }
- if (ret == 0){
- if (netconf_bad_element_xml(xerr, "application",
- name, "Unrecognized value") < 0)
- goto done;
- goto fail;
- }
+ if ((ret = parse_uint32(valstr, value, &reason)) < 0){
+ clicon_err(OE_XML, errno, "parse_uint32");
+ goto done;
+ }
+ if (ret == 0){
+ if (netconf_bad_element_xml(xerr, "application",
+ name, "Unrecognized value") < 0)
+ goto done;
+ goto fail;
+ }
}
retval = 1;
done:
if (reason)
- free(reason);
+ free(reason);
return retval;
fail:
retval = 0;
@@ -2010,28 +2024,28 @@ netconf_parse_uint32_xml(char *name,
*/
int
netconf_framing_preamble(netconf_framing_type framing,
- cbuf *cb)
+ cbuf *cb)
{
int retval = -1;
char *body = NULL;
switch (framing){
case NETCONF_SSH_EOM:
- break;
+ break;
case NETCONF_SSH_CHUNKED:
- if ((body = strdup(cbuf_get(cb))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- cbuf_reset(cb);
- cprintf(cb, "\n#%zu\n", strlen(body)); /* Add RFC6242 chunked-end */
- cbuf_append_str(cb, body);
- break;
+ if ((body = strdup(cbuf_get(cb))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ cbuf_reset(cb);
+ cprintf(cb, "\n#%zu\n", strlen(body)); /* Add RFC6242 chunked-end */
+ cbuf_append_str(cb, body);
+ break;
}
retval = 0;
done:
if (body)
- free(body);
+ free(body);
return retval;
}
@@ -2042,15 +2056,15 @@ netconf_framing_preamble(netconf_framing_type framing,
*/
int
netconf_framing_postamble(netconf_framing_type framing,
- cbuf *cb)
+ cbuf *cb)
{
switch (framing){
case NETCONF_SSH_EOM:
- cprintf(cb, "]]>]]>"); /* Add RFC4742 end-of-message marker */
- break;
+ cprintf(cb, "]]>]]>"); /* Add RFC4742 end-of-message marker */
+ break;
case NETCONF_SSH_CHUNKED:
- cprintf(cb, "\n##\n"); /* Add RFC6242 chunked-end */
- break;
+ cprintf(cb, "\n##\n"); /* Add RFC6242 chunked-end */
+ break;
}
return 0;
}
@@ -2065,8 +2079,8 @@ netconf_framing_postamble(netconf_framing_type framing,
*/
int
netconf_output(int s,
- cbuf *cb,
- char *msg)
+ cbuf *cb,
+ char *msg)
{
int retval = -1;
char *buf = cbuf_get(cb);
@@ -2074,26 +2088,26 @@ netconf_output(int s,
clicon_debug(1, "SEND %s", msg);
if (clicon_debug_get() > 1){ /* XXX: below only works to stderr, clicon_debug may log to syslog */
- cxobj *xt = NULL;
- if (clixon_xml_parse_string(buf, YB_NONE, NULL, &xt, NULL) == 0){
- if (clixon_xml2file(stderr, xml_child_i(xt, 0), 0, 0, fprintf, 0, 0) < 0)
- goto done;
- fprintf(stderr, "\n");
- xml_free(xt);
- }
+ cxobj *xt = NULL;
+ if (clixon_xml_parse_string(buf, YB_NONE, NULL, &xt, NULL) == 0){
+ if (clixon_xml2file(stderr, xml_child_i(xt, 0), 0, 0, fprintf, 0, 0) < 0)
+ goto done;
+ fprintf(stderr, "\n");
+ xml_free(xt);
+ }
}
if (write(s, buf, len) < 0){
- if (errno == EPIPE)
- clicon_debug(1, "%s write err SIGPIPE", __FUNCTION__);
- else
- clicon_log(LOG_ERR, "%s: write: %s", __FUNCTION__, strerror(errno));
- goto done;
+ if (errno == EPIPE)
+ clicon_debug(1, "%s write err SIGPIPE", __FUNCTION__);
+ else
+ clicon_log(LOG_ERR, "%s: write: %s", __FUNCTION__, strerror(errno));
+ goto done;
}
retval = 0;
done:
return retval;
}
-
+
/*! Encapsulate and send outgoing netconf packet as cbuf on socket
*
* @param[in] framing Framing type, ie EOM(1.0) or chunked (1.1)
@@ -2106,14 +2120,14 @@ netconf_output(int s,
*/
int
netconf_output_encap(netconf_framing_type framing,
- cbuf *cb)
+ cbuf *cb)
{
int retval = -1;
if (netconf_framing_preamble(framing, cb) < 0)
- goto done;
+ goto done;
if (netconf_framing_postamble(framing, cb) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -2161,95 +2175,95 @@ netconf_output_encap(netconf_framing_type framing,
*/
int
netconf_input_chunked_framing(char ch,
- int *state,
- size_t *size)
+ int *state,
+ size_t *size)
{
int retval = 0;
clicon_debug(2, "%s ch:%c(%d) state:%d size:%zu", __FUNCTION__, ch, ch, *state, *size);
switch (*state){
case 0:
- if (ch == '\n'){
- (*state)++;
- break;
- }
- clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-start: expected \\n but received %c (state:%d)", ch, *state);
- goto err;
- break;
+ if (ch == '\n'){
+ (*state)++;
+ break;
+ }
+ clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-start: expected \\n but received %c (state:%d)", ch, *state);
+ goto err;
+ break;
case 1:
case 5:
- if (ch == '#'){
- (*state)++;
- break;
- }
- clicon_err(OE_NETCONF, 0, "NETCONF framing error: expected # but received %c (state:%d)", ch, *state);
- goto err;
- break;
+ if (ch == '#'){
+ (*state)++;
+ break;
+ }
+ clicon_err(OE_NETCONF, 0, "NETCONF framing error: expected # but received %c (state:%d)", ch, *state);
+ goto err;
+ break;
case 2:
- if (ch == '#'){
- (*state) = 0;
- retval = 2; /* end of frame (empty data) */
- break;
- }
- else if (ch >= '1' && ch <= '9'){ /* first num */
- (*state)++;
- *size = ch-'0';
- break;
- }
- clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-start: expected 1-9 or # but received %c (state:%d)", ch, *state);
- goto err;
- break;
+ if (ch == '#'){
+ (*state) = 0;
+ retval = 2; /* end of frame (empty data) */
+ break;
+ }
+ else if (ch >= '1' && ch <= '9'){ /* first num */
+ (*state)++;
+ *size = ch-'0';
+ break;
+ }
+ clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-start: expected 1-9 or # but received %c (state:%d)", ch, *state);
+ goto err;
+ break;
case 3:
- if (ch >= '0' && ch <= '9'){ /* other nums */
- *size = (*size)*10 + ch-'0';
- break;
- }
- else if (ch == '\n'){
- (*state)++;
- break;
- }
- clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-size: expected 0-9 or \\n but received %c (state:%d)", ch, *state);
- goto err;
- break;
+ if (ch >= '0' && ch <= '9'){ /* other nums */
+ *size = (*size)*10 + ch-'0';
+ break;
+ }
+ else if (ch == '\n'){
+ (*state)++;
+ break;
+ }
+ clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-size: expected 0-9 or \\n but received %c (state:%d)", ch, *state);
+ goto err;
+ break;
case 4:
- if (*size > 0){ /* chunk-data */
- (*size)--;
- retval = 1; /* chunk-data */
- break;
- }
- else if (*size == 0 && ch == '\n'){
- (*state)++;
- break;
- }
- clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-end: expected \\n but received %c (state:%d)", ch, *state);
- goto err;
- break;
+ if (*size > 0){ /* chunk-data */
+ (*size)--;
+ retval = 1; /* chunk-data */
+ break;
+ }
+ else if (*size == 0 && ch == '\n'){
+ (*state)++;
+ break;
+ }
+ clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-end: expected \\n but received %c (state:%d)", ch, *state);
+ goto err;
+ break;
case 6:
- if (ch == '#'){
- (*state)++;
- break;
- }
- else if (ch >= '1' && ch <= '9'){ /* first num */
- *state=3;
- *size = ch-'0';
- break;
- }
- clicon_err(OE_NETCONF, 0, "NETCONF framing error: expected # but received %c (state:%d)", ch, *state);
- goto err;
- break;
+ if (ch == '#'){
+ (*state)++;
+ break;
+ }
+ else if (ch >= '1' && ch <= '9'){ /* first num */
+ *state=3;
+ *size = ch-'0';
+ break;
+ }
+ clicon_err(OE_NETCONF, 0, "NETCONF framing error: expected # but received %c (state:%d)", ch, *state);
+ goto err;
+ break;
case 7:
- if (ch == '\n'){
- (*state) = 0;
- retval = 2; /* end of frame */
- break;
- }
- clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-end: expected \\n but received %c (state:%d)", ch, *state);
- goto err;
- break;
+ if (ch == '\n'){
+ (*state) = 0;
+ retval = 2; /* end of frame */
+ break;
+ }
+ clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-end: expected \\n but received %c (state:%d)", ch, *state);
+ goto err;
+ break;
default:
- clicon_err(OE_NETCONF, 0, "NETCONF framing error %c , invalid state:%d", ch, *state);
- goto err;
- break;
+ clicon_err(OE_NETCONF, 0, "NETCONF framing error %c , invalid state:%d", ch, *state);
+ goto err;
+ break;
}
done:
return retval;
diff --git a/lib/src/clixon_netns.c b/lib/src/clixon_netns.c
index a1d54b19..7329e5f9 100644
--- a/lib/src/clixon_netns.c
+++ b/lib/src/clixon_netns.c
@@ -51,7 +51,7 @@
*/
static int
send_sock(int usock,
- int fd)
+ int fd)
{
int retval = -1;
int *fdptr;
@@ -70,8 +70,8 @@ send_sock(int usock,
memcpy(fdptr,&fd,sizeof(fd));
msg.msg_controllen=CMSG_SPACE(sizeof(fd));
if (sendmsg(usock, &msg, 0) < 0){
- clicon_err(OE_UNIX, errno, "sendmsg");
- goto done;
+ clicon_err(OE_UNIX, errno, "sendmsg");
+ goto done;
}
retval = 0;
done:
@@ -83,7 +83,7 @@ send_sock(int usock,
*/
static int
get_sock(int usock,
- int *fd)
+ int *fd)
{
int retval = -1;
struct msghdr msg={0};
@@ -96,8 +96,8 @@ get_sock(int usock,
msg.msg_controllen=sizeof(buf);
/* Block here */
if (recvmsg(usock, &msg, 0) < 0){
- clicon_err(OE_UNIX, errno, "recvmsg");
- goto done;
+ clicon_err(OE_UNIX, errno, "recvmsg");
+ goto done;
}
cmsg=CMSG_FIRSTHDR(&msg);
memcpy(fd, CMSG_DATA(cmsg), sizeof(*fd));
@@ -118,11 +118,11 @@ get_sock(int usock,
*/
static int
create_socket(struct sockaddr *sa,
- size_t sin_len,
- int backlog,
- int flags,
- const char *addrstr,
- int *sock)
+ size_t sin_len,
+ int backlog,
+ int flags,
+ const char *addrstr,
+ int *sock)
{
int retval = -1;
int s = -1;
@@ -130,8 +130,8 @@ create_socket(struct sockaddr *sa,
clicon_debug(1, "%s", __FUNCTION__);
if (sock == NULL){
- clicon_err(OE_PROTO, EINVAL, "Requires socket output parameter");
- goto done;
+ clicon_err(OE_PROTO, EINVAL, "Requires socket output parameter");
+ goto done;
}
/* create inet socket */
@@ -142,49 +142,49 @@ create_socket(struct sockaddr *sa,
#endif
if ((s = socket(sa->sa_family, flags,
- 0)) < 0) {
- clicon_err(OE_UNIX, errno, "socket");
- goto done;
+ 0)) < 0) {
+ clicon_err(OE_UNIX, errno, "socket");
+ goto done;
}
#ifdef __APPLE__
if (fcntl(s, O_CLOEXEC)) {
- clicon_err(OE_UNIX, errno, "fcntl");
- goto done;
+ clicon_err(OE_UNIX, errno, "fcntl");
+ goto done;
}
#endif
if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)) == -1) {
- clicon_err(OE_UNIX, errno, "setsockopt SO_KEEPALIVE");
- goto done;
+ clicon_err(OE_UNIX, errno, "setsockopt SO_KEEPALIVE");
+ goto done;
}
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) == -1) {
- clicon_err(OE_UNIX, errno, "setsockopt SO_REUSEADDR");
- goto done;
+ clicon_err(OE_UNIX, errno, "setsockopt SO_REUSEADDR");
+ goto done;
}
/* only bind ipv6, otherwise it may bind to ipv4 as well which is strange but seems default */
if (sa->sa_family == AF_INET6 &&
- setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) {
- clicon_err(OE_UNIX, errno, "setsockopt IPPROTO_IPV6");
- goto done;
+ setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) {
+ clicon_err(OE_UNIX, errno, "setsockopt IPPROTO_IPV6");
+ goto done;
}
if (bind(s, sa, sin_len) == -1) {
- /* Note may be ignored in upper layer by checking for EADDRNOTAVAIL, see eg restconf_openssl_init */
- clicon_err(OE_UNIX, errno, "bind(%s)", addrstr);
- goto done;
+ /* Note may be ignored in upper layer by checking for EADDRNOTAVAIL, see eg restconf_openssl_init */
+ clicon_err(OE_UNIX, errno, "bind(%s)", addrstr);
+ goto done;
}
if (listen(s, backlog ) < 0){
- clicon_err(OE_UNIX, errno, "listen");
- goto done;
+ clicon_err(OE_UNIX, errno, "listen");
+ goto done;
}
if (sock)
- *sock = s;
+ *sock = s;
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
if (retval != 0 && s != -1)
- close(s);
+ close(s);
return retval;
}
@@ -201,12 +201,12 @@ create_socket(struct sockaddr *sa,
*/
static int
fork_netns_socket(const char *netns,
- struct sockaddr *sa,
- size_t sin_len,
- int backlog,
- int flags,
- const char *addrstr,
- int *sock)
+ struct sockaddr *sa,
+ size_t sin_len,
+ int backlog,
+ int flags,
+ const char *addrstr,
+ int *sock)
{
int retval = -1;
int sp[2] = {-1, -1};
@@ -223,75 +223,75 @@ fork_netns_socket(const char *netns,
clicon_debug(1, "%s %s", __FUNCTION__, netns);
if (socketpair(AF_UNIX, sock_flags, 0, sp) < 0){
- clicon_err(OE_UNIX, errno, "socketpair");
- goto done;
+ clicon_err(OE_UNIX, errno, "socketpair");
+ goto done;
}
#ifdef __APPLE__
if (fcntl(sp[0], O_CLOEXEC)) {
- clicon_err(OE_UNIX, errno, "fcntl, sp[0]");
- goto done;
+ clicon_err(OE_UNIX, errno, "fcntl, sp[0]");
+ goto done;
}
if (fcntl(sp[1], O_CLOEXEC)) {
- clicon_err(OE_UNIX, errno, "fcntl, sp[1]");
- goto done;
+ clicon_err(OE_UNIX, errno, "fcntl, sp[1]");
+ goto done;
}
#endif
/* Check namespace exists */
- sprintf(nspath,"/var/run/netns/%s", netns);
+ sprintf(nspath,"/var/run/netns/%s", netns);
if (stat(nspath, &st) < 0){
- clicon_err(OE_UNIX, errno, ": stat(%s)", nspath);
- goto done;
+ clicon_err(OE_UNIX, errno, ": stat(%s)", nspath);
+ goto done;
}
if ((child = fork()) < 0) {
- clicon_err(OE_UNIX, errno, "fork");
- goto done;
+ clicon_err(OE_UNIX, errno, "fork");
+ goto done;
}
- if (child == 0) { /* Child */
- int fd;
- int s = -1;
+ if (child == 0) { /* Child */
+ int fd;
+ int s = -1;
- close(sp[0]);
- /* Switch to namespace */
- if ((fd=open(nspath, O_RDONLY)) < 0) {
- clicon_err(OE_UNIX, errno, "open(%s)", nspath);
- send_sock(sp[1], sp[1]); /* Dummy to wake parent */
- exit(1); /* Dont do return here, need to exit child */
- }
+ close(sp[0]);
+ /* Switch to namespace */
+ if ((fd=open(nspath, O_RDONLY)) < 0) {
+ clicon_err(OE_UNIX, errno, "open(%s)", nspath);
+ send_sock(sp[1], sp[1]); /* Dummy to wake parent */
+ exit(1); /* Dont do return here, need to exit child */
+ }
#ifdef HAVE_SETNS
- if (setns(fd, CLONE_NEWNET) < 0){
- clicon_err(OE_UNIX, errno, "setns(%s)", netns);
- send_sock(sp[1], sp[1]); /* Dummy to wake parent */
- exit(1); /* Dont do return here, need to exit child */
- }
+ if (setns(fd, CLONE_NEWNET) < 0){
+ clicon_err(OE_UNIX, errno, "setns(%s)", netns);
+ send_sock(sp[1], sp[1]); /* Dummy to wake parent */
+ exit(1); /* Dont do return here, need to exit child */
+ }
#endif
- close(fd);
- /* Create socket in this namespace */
- if (create_socket(sa, sin_len, backlog, flags, addrstr, &s) < 0){
- send_sock(sp[1], sp[1]); /* Dummy to wake parent */
- exit(1); /* Dont do return here, need to exit child */
- }
- /* Send socket to parent */
- if (send_sock(sp[1], s) < 0)
- exit(1); /* Dont do return here, need to exit child */
- close(s);
- close(sp[1]);
- exit(0);
+ close(fd);
+ /* Create socket in this namespace */
+ if (create_socket(sa, sin_len, backlog, flags, addrstr, &s) < 0){
+ send_sock(sp[1], sp[1]); /* Dummy to wake parent */
+ exit(1); /* Dont do return here, need to exit child */
+ }
+ /* Send socket to parent */
+ if (send_sock(sp[1], s) < 0)
+ exit(1); /* Dont do return here, need to exit child */
+ close(s);
+ close(sp[1]);
+ exit(0);
}
/* Parent */
close(sp[1]);
if (get_sock(sp[0], sock) < 0)
- goto done;
+ goto done;
close(sp[0]);
if(waitpid(child, &wstatus, 0) == child)
- ; // retval = WEXITSTATUS(status); /* Dont know what to do with status */
+ ; // retval = WEXITSTATUS(status); /* Dont know what to do with status */
if (WEXITSTATUS(wstatus)){
- clicon_debug(1, "%s wstatus:%d", __FUNCTION__, WEXITSTATUS(wstatus));
- *sock = -1;
- clicon_err(OE_UNIX, EADDRNOTAVAIL, "bind(%s)", addrstr);
- goto done;
+ clicon_debug(1, "%s wstatus:%d", __FUNCTION__, WEXITSTATUS(wstatus));
+ *sock = -1;
+ clicon_err(OE_UNIX, EADDRNOTAVAIL, "bind(%s)", addrstr);
+ goto done;
}
retval = 0;
done:
@@ -311,28 +311,28 @@ fork_netns_socket(const char *netns,
*/
int
clixon_netns_socket(const char *netns,
- struct sockaddr *sa,
- size_t sin_len,
- int backlog,
- int flags,
- const char *addrstr,
- int *sock)
+ struct sockaddr *sa,
+ size_t sin_len,
+ int backlog,
+ int flags,
+ const char *addrstr,
+ int *sock)
{
int retval = -1;
clicon_debug(1, "%s", __FUNCTION__);
if (netns == NULL){
- if (create_socket(sa, sin_len, backlog, flags, addrstr, sock) < 0)
- goto done;
- goto ok;
+ if (create_socket(sa, sin_len, backlog, flags, addrstr, sock) < 0)
+ goto done;
+ goto ok;
}
else {
#ifdef HAVE_SETNS
- if (fork_netns_socket(netns, sa, sin_len, backlog, flags, addrstr, sock) < 0)
- goto done;
+ if (fork_netns_socket(netns, sa, sin_len, backlog, flags, addrstr, sock) < 0)
+ goto done;
#else
- clicon_err(OE_UNIX, errno, "No namespace support on platform: %s", netns);
- return -1;
+ clicon_err(OE_UNIX, errno, "No namespace support on platform: %s", netns);
+ return -1;
#endif
}
ok:
diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c
index 7276599f..41dbb266 100644
--- a/lib/src/clixon_options.c
+++ b/lib/src/clixon_options.c
@@ -137,7 +137,7 @@ static const map_str2int yang_regexp_map[] = {
*/
int
clicon_option_dump(clicon_handle h,
- int dbglevel)
+ int dbglevel)
{
int retval = -1;
clicon_hash_t *hash = clicon_options(h);
@@ -149,43 +149,43 @@ clicon_option_dump(clicon_handle h,
cxobj *x = NULL;
if (clicon_hash_keys(hash, &keys, &klen) < 0)
- goto done;
+ goto done;
for(i = 0; i < klen; i++) {
- val = clicon_hash_value(hash, keys[i], &vlen);
- if (vlen){
- if (((char*)val)[vlen-1]=='\0') /* assume string */
- clicon_debug(dbglevel, "%s =\t \"%s\"", keys[i], (char*)val);
- else
- clicon_debug(dbglevel, "%s =\t 0x%p , length %zu", keys[i], val, vlen);
- }
- else
- clicon_debug(dbglevel, "%s = NULL", keys[i]);
+ val = clicon_hash_value(hash, keys[i], &vlen);
+ if (vlen){
+ if (((char*)val)[vlen-1]=='\0') /* assume string */
+ clicon_debug(dbglevel, "%s =\t \"%s\"", keys[i], (char*)val);
+ else
+ clicon_debug(dbglevel, "%s =\t 0x%p , length %zu", keys[i], val, vlen);
+ }
+ else
+ clicon_debug(dbglevel, "%s = NULL", keys[i]);
}
/* Next print CLICON_FEATURE, CLICON_YANG_DIR and CLICON_SNMP_DIR from config tree
* Since they are lists they are placed in the config tree.
*/
x = NULL;
while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(x), "CLICON_YANG_DIR") != 0)
- continue;
- clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
+ if (strcmp(xml_name(x), "CLICON_YANG_DIR") != 0)
+ continue;
+ clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
}
x = NULL;
while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(x), "CLICON_FEATURE") != 0)
- continue;
- clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
+ if (strcmp(xml_name(x), "CLICON_FEATURE") != 0)
+ continue;
+ clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
}
x = NULL;
while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(x), "CLICON_SNMP_MIB") != 0)
- continue;
- clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
+ if (strcmp(xml_name(x), "CLICON_SNMP_MIB") != 0)
+ continue;
+ clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
}
retval = 0;
done:
if (keys)
- free(keys);
+ free(keys);
return retval;
}
@@ -196,8 +196,8 @@ clicon_option_dump(clicon_handle h,
*/
static int
parse_configfile_one(const char *filename,
- yang_stmt *yspec,
- cxobj **xconfig)
+ yang_stmt *yspec,
+ cxobj **xconfig)
{
int retval = -1;
FILE *fp = NULL;
@@ -208,49 +208,49 @@ parse_configfile_one(const char *filename,
int ret;
if ((fp = fopen(filename, "r")) == NULL){
- clicon_err(OE_UNIX, errno, "open configure file: %s", filename);
- return -1;
+ clicon_err(OE_UNIX, errno, "open configure file: %s", filename);
+ return -1;
}
clicon_debug(2, "%s: Reading config file %s", __FUNCTION__, filename);
if ((ret = clixon_xml_parse_file(fp, yspec?YB_MODULE:YB_NONE, yspec, &xt, &xerr)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if ((cbret = cbuf_new()) ==NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- if (netconf_err2cb(xerr, cbret) < 0)
- goto done;
- /* Here one could make it more relaxing to not quit on unrecognized option? */
- clixon_netconf_error(xerr, NULL, NULL);
- goto done;
+ if ((cbret = cbuf_new()) ==NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ if (netconf_err2cb(xerr, cbret) < 0)
+ goto done;
+ /* Here one could make it more relaxing to not quit on unrecognized option? */
+ clixon_netconf_error(xerr, NULL, NULL);
+ goto done;
}
/* Ensure a single root */
if (xt == NULL || xml_child_nr(xt) != 1){
- clicon_err(OE_CFG, 0, "Config file %s: Lacks single top element", filename);
- goto done;
+ clicon_err(OE_CFG, 0, "Config file %s: Lacks single top element", filename);
+ goto done;
}
if (xml_rootchild(xt, 0, &xt) < 0)
- goto done;
+ goto done;
/* Check well-formedness */
if (strcmp(xml_name(xt), "clixon-config") != 0 ||
- (xa = xml_find_type(xt, NULL, "xmlns", CX_ATTR)) == NULL ||
- strcmp(xml_value(xa), CLIXON_CONF_NS) != 0){
- clicon_err(OE_CFG, 0, "Config file %s: Lacks top-level \"clixon-config\" element\nClixon config files should begin with: ", filename, CLIXON_CONF_NS);
- goto done;
+ (xa = xml_find_type(xt, NULL, "xmlns", CX_ATTR)) == NULL ||
+ strcmp(xml_value(xa), CLIXON_CONF_NS) != 0){
+ clicon_err(OE_CFG, 0, "Config file %s: Lacks top-level \"clixon-config\" element\nClixon config files should begin with: ", filename, CLIXON_CONF_NS);
+ goto done;
}
*xconfig = xt;
xt = NULL;
retval = 0;
done:
if (xt)
- xml_free(xt);
+ xml_free(xt);
if (fp)
- fclose(fp);
+ fclose(fp);
if (cbret)
- cbuf_free(cbret);
+ cbuf_free(cbret);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
return retval;
}
@@ -266,10 +266,10 @@ parse_configfile_one(const char *filename,
*/
static int
parse_configfile(clicon_handle h,
- const char *filename,
- char *extraconfdir0,
- yang_stmt *yspec,
- cxobj **xconfig)
+ const char *filename,
+ char *extraconfdir0,
+ yang_stmt *yspec,
+ cxobj **xconfig)
{
int retval = -1;
struct stat st;
@@ -293,123 +293,123 @@ parse_configfile(clicon_handle h,
DIR *dirp;
if (filename == NULL || !strlen(filename)){
- clicon_err(OE_UNIX, 0, "Not specified");
- goto done;
+ clicon_err(OE_UNIX, 0, "Not specified");
+ goto done;
}
if (stat(filename, &st) < 0){
- clicon_err(OE_UNIX, errno, "%s", filename);
- goto done;
+ clicon_err(OE_UNIX, errno, "%s", filename);
+ goto done;
}
if (!S_ISREG(st.st_mode)){
- clicon_err(OE_UNIX, 0, "%s is not a regular file", filename);
- goto done;
+ clicon_err(OE_UNIX, 0, "%s is not a regular file", filename);
+ goto done;
}
/* Parse main config file */
if (parse_configfile_one(filename, yspec, &xt) < 0)
- goto done;
+ goto done;
/* xt is a single-rooted: ...
* If no override (eg from command-line)
* Bootstrap: Shortcut to read extra confdir inline */
if ((extraconfdir = extraconfdir0) == NULL)
- if ((xc = xpath_first(xt, 0, "CLICON_CONFIGDIR")) != NULL)
- extraconfdir = xml_body(xc);
+ if ((xc = xpath_first(xt, 0, "CLICON_CONFIGDIR")) != NULL)
+ extraconfdir = xml_body(xc);
if (extraconfdir){ /* If extra dir, parse extra config files */
- /* A check it exists (also done in clicon_file_dirent) */
- if ((dirp = opendir(extraconfdir)) == NULL) {
- clicon_err(OE_UNIX, errno, "CLICON_CONFIGDIR: %s opendir", extraconfdir);
- goto done;
- }
- closedir(dirp);
- if((ndp = clicon_file_dirent(extraconfdir, &dp, NULL, S_IFREG)) < 0) /* Read dir */
- goto done;
- /* Loop through files */
- for (i = 0; i < ndp; i++){
- snprintf(filename1, sizeof(filename1), "%s/%s", extraconfdir, dp[i].d_name);
- if (parse_configfile_one(filename1, yspec, &xe) < 0)
- goto done;
- /* Drain objects from extrafile and replace/append to main */
- while ((xec = xml_child_i_type(xe, 0, CX_ELMNT)) != NULL) {
- name = xml_name(xec);
- body = xml_body(xec);
- /* Ignore non-leafs */
- if (name == NULL || body == NULL)
- continue;
- /* Ignored from file due to bootstrapping */
- if (strcmp(name,"CLICON_CONFIGFILE")==0)
- continue;
- /* List options for configure options that are lists or leaf-lists: append to main */
- if (strcmp(name,"CLICON_FEATURE")==0 ||
- strcmp(name,"CLICON_YANG_DIR")==0 ||
- strcmp(name,"CLICON_SNMP_MIB")==0){
- if (xml_addsub(xt, xec) < 0)
- goto done;
- continue;
- }
- /* Remove existing in master if any */
- if ((x = xml_find_type(xt, NULL, name, CX_ELMNT)) != NULL)
- xml_purge(x);
- /* Append to master (removed from xe) */
- if (xml_addsub(xt, xec) < 0)
- goto done;
- }
- if (xe)
- xml_free(xe);
- xe = NULL;
- }
+ /* A check it exists (also done in clicon_file_dirent) */
+ if ((dirp = opendir(extraconfdir)) == NULL) {
+ clicon_err(OE_UNIX, errno, "CLICON_CONFIGDIR: %s opendir", extraconfdir);
+ goto done;
+ }
+ closedir(dirp);
+ if((ndp = clicon_file_dirent(extraconfdir, &dp, NULL, S_IFREG)) < 0) /* Read dir */
+ goto done;
+ /* Loop through files */
+ for (i = 0; i < ndp; i++){
+ snprintf(filename1, sizeof(filename1), "%s/%s", extraconfdir, dp[i].d_name);
+ if (parse_configfile_one(filename1, yspec, &xe) < 0)
+ goto done;
+ /* Drain objects from extrafile and replace/append to main */
+ while ((xec = xml_child_i_type(xe, 0, CX_ELMNT)) != NULL) {
+ name = xml_name(xec);
+ body = xml_body(xec);
+ /* Ignore non-leafs */
+ if (name == NULL || body == NULL)
+ continue;
+ /* Ignored from file due to bootstrapping */
+ if (strcmp(name,"CLICON_CONFIGFILE")==0)
+ continue;
+ /* List options for configure options that are lists or leaf-lists: append to main */
+ if (strcmp(name,"CLICON_FEATURE")==0 ||
+ strcmp(name,"CLICON_YANG_DIR")==0 ||
+ strcmp(name,"CLICON_SNMP_MIB")==0){
+ if (xml_addsub(xt, xec) < 0)
+ goto done;
+ continue;
+ }
+ /* Remove existing in master if any */
+ if ((x = xml_find_type(xt, NULL, name, CX_ELMNT)) != NULL)
+ xml_purge(x);
+ /* Append to master (removed from xe) */
+ if (xml_addsub(xt, xec) < 0)
+ goto done;
+ }
+ if (xe)
+ xml_free(xe);
+ xe = NULL;
+ }
}
if (xml_default_recurse(xt, 0) < 0)
- goto done;
+ goto done;
if ((ret = xml_yang_validate_add(h, xt, &xerr)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if ((cbret = cbuf_new()) ==NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- if (netconf_err2cb(xerr, cbret) < 0)
- goto done;
- clicon_err(OE_CFG, 0, "Config file validation: %s", cbuf_get(cbret));
- goto done;
+ if ((cbret = cbuf_new()) ==NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ if (netconf_err2cb(xerr, cbret) < 0)
+ goto done;
+ clicon_err(OE_CFG, 0, "Config file validation: %s", cbuf_get(cbret));
+ goto done;
}
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- name = xml_name(x);
- body = xml_body(x);
- /* Ignore non-leafs */
- if (name == NULL || body == NULL)
- continue;
- /* Ignored from file due to bootstrapping */
- if (strcmp(name,"CLICON_CONFIGFILE")==0)
- continue;
- /* List options for configure options that are leaf-lists (not leaf)
- * They must be accessed directly by looping over clicon_conf_xml(h)
- */
- if (strcmp(name,"CLICON_FEATURE")==0)
- continue;
- if (strcmp(name,"CLICON_YANG_DIR")==0)
- continue;
- if (strcmp(name,"CLICON_SNMP_MIB")==0)
- continue;
- if (clicon_hash_add(copt,
- name,
- body,
- strlen(body)+1) == NULL)
- goto done;
+ name = xml_name(x);
+ body = xml_body(x);
+ /* Ignore non-leafs */
+ if (name == NULL || body == NULL)
+ continue;
+ /* Ignored from file due to bootstrapping */
+ if (strcmp(name,"CLICON_CONFIGFILE")==0)
+ continue;
+ /* List options for configure options that are leaf-lists (not leaf)
+ * They must be accessed directly by looping over clicon_conf_xml(h)
+ */
+ if (strcmp(name,"CLICON_FEATURE")==0)
+ continue;
+ if (strcmp(name,"CLICON_YANG_DIR")==0)
+ continue;
+ if (strcmp(name,"CLICON_SNMP_MIB")==0)
+ continue;
+ if (clicon_hash_add(copt,
+ name,
+ body,
+ strlen(body)+1) == NULL)
+ goto done;
}
retval = 0;
*xconfig = xt;
xt = NULL;
done:
if (dp)
- free(dp);
+ free(dp);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (cbret)
- cbuf_free(cbret);
+ cbuf_free(cbret);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (xt)
- xml_free(xt);
+ xml_free(xt);
return retval;
}
@@ -425,29 +425,29 @@ parse_configfile(clicon_handle h,
*/
int
clicon_option_add(clicon_handle h,
- const char *name,
- char *value)
+ const char *name,
+ char *value)
{
int retval = -1;
clicon_hash_t *copt = clicon_options(h);
cxobj *x;
if (strcmp(name, "CLICON_FEATURE")==0 ||
- strcmp(name, "CLICON_YANG_DIR")==0 ||
- strcmp(name, "CLICON_SNMP_MIB")==0){
- if ((x = clicon_conf_xml(h)) == NULL){
- clicon_err(OE_UNIX, ENOENT, "option %s not found (clicon_conf_xml_set has not been called?)", name);
- goto done;
- }
- if (clixon_xml_parse_va(YB_NONE, NULL, &x, NULL, "<%s>%s%s>",
- name, value, name) < 0)
- goto done;
+ strcmp(name, "CLICON_YANG_DIR")==0 ||
+ strcmp(name, "CLICON_SNMP_MIB")==0){
+ if ((x = clicon_conf_xml(h)) == NULL){
+ clicon_err(OE_UNIX, ENOENT, "option %s not found (clicon_conf_xml_set has not been called?)", name);
+ goto done;
+ }
+ if (clixon_xml_parse_va(YB_NONE, NULL, &x, NULL, "<%s>%s%s>",
+ name, value, name) < 0)
+ goto done;
}
if (clicon_hash_add(copt,
- name,
- value,
- strlen(value)+1) == NULL)
- goto done;
+ name,
+ value,
+ strlen(value)+1) == NULL)
+ goto done;
retval = 0;
done:
return retval;
@@ -478,32 +478,32 @@ clicon_options_main(clicon_handle h)
/* Create configure yang-spec */
if ((yspec = yspec_new()) == NULL)
- goto done;
+ goto done;
/*
* Set configure file if not set by command-line above
*/
if (!clicon_hash_lookup(copt, "CLICON_CONFIGFILE")){
- clicon_option_str_set(h, "CLICON_CONFIGFILE", CLIXON_DEFAULT_CONFIG);
+ clicon_option_str_set(h, "CLICON_CONFIGFILE", CLIXON_DEFAULT_CONFIG);
}
configfile = clicon_hash_value(copt, "CLICON_CONFIGFILE", NULL);
if (strlen(configfile) == 0)
- configfile = clicon_hash_value(copt, "CLICON_CONFIGFILE", NULL);
+ configfile = clicon_hash_value(copt, "CLICON_CONFIGFILE", NULL);
clicon_debug(1, "CLICON_CONFIGFILE=%s", configfile);
/* File must end with .xml */
if ((suffix = rindex(configfile, '.')) != NULL){
- suffix++;
- xml = strcmp(suffix, "xml") == 0;
+ suffix++;
+ xml = strcmp(suffix, "xml") == 0;
}
if (xml == 0){
- clicon_err(OE_CFG, 0, "%s: suffix %s not recognized", configfile, suffix);
- goto done;
+ clicon_err(OE_CFG, 0, "%s: suffix %s not recognized", configfile, suffix);
+ goto done;
}
/* Override extraconfdir */
if (clicon_option_str(h, "CLICON_CONFIGDIR") &&
- (extraconfdir = strdup(clicon_option_str(h, "CLICON_CONFIGDIR"))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ (extraconfdir = strdup(clicon_option_str(h, "CLICON_CONFIGDIR"))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
/* Read configfile first without yangspec, and without extra config dir for bootstrapping,
@@ -515,7 +515,7 @@ clicon_options_main(clicon_handle h)
* - no extra config dir
*/
if (parse_configfile(h, configfile, extraconfdir, NULL, &xconfig) < 0)
- goto done;
+ goto done;
clicon_conf_xml_set(h, xconfig);
@@ -528,26 +528,26 @@ clicon_options_main(clicon_handle h)
* If fcgi option gets secondary this should probably be changed
*/
if (clixon_xml_parse_string("clixon-restconf:fcgi ",
- YB_PARENT, NULL, &xconfig, NULL) < 0)
- goto done;
+ YB_PARENT, NULL, &xconfig, NULL) < 0)
+ goto done;
#endif
/* Parse clixon yang spec */
if (yang_spec_parse_module(h, "clixon-config", NULL, yspec) < 0)
- goto done;
+ goto done;
/* Load restconf yang. Note this is also a part of clixon-config */
if (yang_spec_parse_module(h, "clixon-restconf", NULL, yspec)< 0)
- goto done;
+ goto done;
clicon_conf_xml_set(h, NULL);
if (xconfig){
- xml_free(xconfig);
- xconfig = NULL;
+ xml_free(xconfig);
+ xconfig = NULL;
}
/* Read configfile second time now with check yang spec */
if (parse_configfile(h, configfile, extraconfdir, yspec, &xconfig) < 0)
- goto done;
+ goto done;
if (xml_spec(xconfig) == NULL){
- clicon_err(OE_CFG, 0, "Config file %s: did not find corresponding Yang specification\nHint: File does not begin with: or clixon-config.yang not found?", configfile, CLIXON_CONF_NS);
- goto done;
+ clicon_err(OE_CFG, 0, "Config file %s: did not find corresponding Yang specification\nHint: File does not begin with: or clixon-config.yang not found?", configfile, CLIXON_CONF_NS);
+ goto done;
}
/* Set yang config spec (must store to free at exit, since conf_xml below uses it) */
if (clicon_config_yang_set(h, yspec) < 0)
@@ -555,14 +555,14 @@ clicon_options_main(clicon_handle h)
yspec = NULL;
/* Set clixon_conf pointer to handle */
if (clicon_conf_xml_set(h, xconfig) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (yspec)
- ys_free(yspec);
+ ys_free(yspec);
if (extraconfdir)
- free(extraconfdir);
+ free(extraconfdir);
return retval;
}
@@ -574,7 +574,7 @@ clicon_options_main(clicon_handle h)
*/
int
clicon_option_exists(clicon_handle h,
- const char *name)
+ const char *name)
{
clicon_hash_t *copt = clicon_options(h);
@@ -593,12 +593,12 @@ clicon_option_exists(clicon_handle h,
*/
char *
clicon_option_str(clicon_handle h,
- const char *name)
+ const char *name)
{
clicon_hash_t *copt = clicon_options(h);
if (clicon_hash_lookup(copt, (char*)name) == NULL)
- return NULL;
+ return NULL;
return clicon_hash_value(copt, (char*)name, NULL);
}
@@ -611,8 +611,8 @@ clicon_option_str(clicon_handle h,
*/
int
clicon_option_str_set(clicon_handle h,
- const char *name,
- char *val)
+ const char *name,
+ char *val)
{
clicon_hash_t *copt = clicon_options(h);
@@ -627,7 +627,7 @@ clicon_option_str_set(clicon_handle h,
* @retval -1 If option does not exist
* @code
* if (clicon_option_exists(h, "X"))
- * return clicon_option_int(h, "X");
+ * return clicon_option_int(h, "X");
* else
* return 0;
* @endcode
@@ -637,12 +637,12 @@ clicon_option_str_set(clicon_handle h,
*/
int
clicon_option_int(clicon_handle h,
- const char *name)
+ const char *name)
{
char *s;
if ((s = clicon_option_str(h, name)) == NULL)
- return -1;
+ return -1;
return atoi(s);
}
@@ -653,13 +653,13 @@ clicon_option_int(clicon_handle h,
*/
int
clicon_option_int_set(clicon_handle h,
- const char *name,
- int val)
+ const char *name,
+ int val)
{
char s[64];
if (snprintf(s, sizeof(s)-1, "%u", val) < 0)
- return -1;
+ return -1;
return clicon_option_str_set(h, name, s);
}
@@ -671,7 +671,7 @@ clicon_option_int_set(clicon_handle h,
* @retval 1 true
* @code
* if (clicon_option_exists(h, "X")
- * return clicon_option_bool(h, "X");
+ * return clicon_option_bool(h, "X");
* else
* return 0; # default false?
* @endcode
@@ -681,16 +681,16 @@ clicon_option_int_set(clicon_handle h,
*/
int
clicon_option_bool(clicon_handle h,
- const char *name)
+ const char *name)
{
char *s;
if ((s = clicon_option_str(h, name)) == NULL)
- return 0;
+ return 0;
if (strcmp(s,"true")==0)
- return 1;
+ return 1;
if (strcmp(s,"1")==0)
- return 1;
+ return 1;
return 0; /* Hopefully false, but anything else than "true" or "one" */
}
@@ -701,18 +701,18 @@ clicon_option_bool(clicon_handle h,
*/
int
clicon_option_bool_set(clicon_handle h,
- const char *name,
- int val)
+ const char *name,
+ int val)
{
char s[64];
if (val != 0 && val != 1){
- clicon_err(OE_CFG, EINVAL, "val is %d, 0 or 1 expected", val);
- return -1;
+ clicon_err(OE_CFG, EINVAL, "val is %d, 0 or 1 expected", val);
+ return -1;
}
if (snprintf(s, sizeof(s)-1, "%s", val?"true":"false") < 0){
- clicon_err(OE_CFG, errno, "snprintf");
- return -1;
+ clicon_err(OE_CFG, errno, "snprintf");
+ return -1;
}
return clicon_option_str_set(h, name, s);
}
@@ -723,7 +723,7 @@ clicon_option_bool_set(clicon_handle h,
*/
int
clicon_option_del(clicon_handle h,
- const char *name)
+ const char *name)
{
clicon_hash_t *copt = clicon_options(h);
@@ -752,9 +752,9 @@ clicon_cli_varonly(clicon_handle h)
char const *opt = "CLICON_CLI_VARONLY";
if (clicon_option_exists(h, opt))
- return clicon_option_int(h, opt);
+ return clicon_option_int(h, opt);
else
- return 0;
+ return 0;
}
/*! Get family of backend socket: AF_UNIX, AF_INET or AF_INET6
@@ -768,15 +768,15 @@ clicon_sock_family(clicon_handle h)
char *s;
if ((s = clicon_option_str(h, "CLICON_SOCK_FAMILY")) == NULL)
- return AF_UNIX;
+ return AF_UNIX;
else if (strcmp(s, "IPv4")==0)
- return AF_INET;
+ return AF_INET;
else if (strcmp(s, "IPv6")==0)
- return AF_INET6;
+ return AF_INET6;
else if (strcmp(s, "UNIX")==0)
- return AF_UNIX;
+ return AF_UNIX;
else
- return -1;
+ return -1;
}
/*! Get port for backend socket in case of AF_INET or AF_INET6
@@ -790,7 +790,7 @@ clicon_sock_port(clicon_handle h)
char *s;
if ((s = clicon_option_str(h, "CLICON_SOCK_PORT")) == NULL)
- return -1;
+ return -1;
return atoi(s);
}
@@ -804,9 +804,9 @@ clicon_autocommit(clicon_handle h)
char const *opt = "CLICON_AUTOCOMMIT";
if (clicon_option_exists(h, opt))
- return clicon_option_int(h, opt);
+ return clicon_option_int(h, opt);
else
- return 0;
+ return 0;
}
/*! Which method to boot/start clicon backend
@@ -819,7 +819,7 @@ clicon_startup_mode(clicon_handle h)
char *mode;
if ((mode = clicon_option_str(h, "CLICON_STARTUP_MODE")) == NULL)
- return -1;
+ return -1;
return clicon_str2int(startup_mode_map, mode);
}
@@ -833,7 +833,7 @@ clicon_backend_privileges_mode(clicon_handle h)
char *mode;
if ((mode = clicon_option_str(h, "CLICON_BACKEND_PRIVILEGES")) == NULL)
- return -1;
+ return -1;
return clicon_str2int(priv_mode_map, mode);
}
@@ -847,7 +847,7 @@ clicon_restconf_privileges_mode(clicon_handle h)
char *mode;
if ((mode = clicon_option_str(h, "CLICON_RESTCONF_PRIVILEGES")) == NULL)
- return -1;
+ return -1;
return clicon_str2int(priv_mode_map, mode);
}
@@ -861,7 +861,7 @@ clicon_nacm_credentials(clicon_handle h)
char *mode;
if ((mode = clicon_option_str(h, "CLICON_NACM_CREDENTIALS")) == NULL)
- return -1;
+ return -1;
return clicon_str2int(nacm_credentials_map, mode);
}
@@ -876,9 +876,9 @@ clicon_datastore_cache(clicon_handle h)
char *str;
if ((str = clicon_option_str(h, "CLICON_DATASTORE_CACHE")) == NULL)
- return DATASTORE_CACHE;
+ return DATASTORE_CACHE;
else
- return clicon_str2int(datastore_cache_map, str);
+ return clicon_str2int(datastore_cache_map, str);
}
/*! Which Yang regexp/pattern engine to use
@@ -892,9 +892,9 @@ clicon_yang_regexp(clicon_handle h)
char *str;
if ((str = clicon_option_str(h, "CLICON_YANG_REGEXP")) == NULL)
- return REGEXP_POSIX;
+ return REGEXP_POSIX;
else
- return clicon_str2int(yang_regexp_map, str);
+ return clicon_str2int(yang_regexp_map, str);
}
/*---------------------------------------------------------------------
@@ -912,7 +912,7 @@ clicon_quiet_mode(clicon_handle h)
{
char *s;
if ((s = clicon_option_str(h, "CLICON_QUIET")) == NULL)
- return 0; /* default */
+ return 0; /* default */
return atoi(s);
}
@@ -922,7 +922,7 @@ clicon_quiet_mode(clicon_handle h)
*/
int
clicon_quiet_mode_set(clicon_handle h,
- int val)
+ int val)
{
return clicon_option_int_set(h, "CLICON_QUIET", val);
}
diff --git a/lib/src/clixon_path.c b/lib/src/clixon_path.c
index 09fd5b59..22ecbe6a 100644
--- a/lib/src/clixon_path.c
+++ b/lib/src/clixon_path.c
@@ -118,13 +118,13 @@
* err;
* ...
* if (cplist)
- * clixon_path_free(cplist);
+ * clixon_path_free(cplist);
* @endcode
* @see clixon_path_free
*/
static int
api_path_parse(char *api_path,
- clixon_path **cplist)
+ clixon_path **cplist)
{
int retval = -1;
clixon_api_path_yacc ay = {0,};
@@ -134,14 +134,14 @@ api_path_parse(char *api_path,
ay.ay_name = "api-path parser";
ay.ay_linenum = 1;
if (api_path_scan_init(&ay) < 0)
- goto done;
+ goto done;
if (api_path_parse_init(&ay) < 0)
- goto done;
+ goto done;
if (clixon_api_path_parseparse(&ay) != 0) { /* yacc returns 1 on error */
- clicon_log(LOG_NOTICE, "API-PATH error: on line %d", ay.ay_linenum);
- if (clicon_errno == 0)
- clicon_err(OE_XML, 0, "API-PATH parser error with no error code (should not happen)");
- goto done;
+ clicon_log(LOG_NOTICE, "API-PATH error: on line %d", ay.ay_linenum);
+ if (clicon_errno == 0)
+ clicon_err(OE_XML, 0, "API-PATH parser error with no error code (should not happen)");
+ goto done;
}
api_path_parse_exit(&ay);
api_path_scan_exit(&ay);
@@ -163,13 +163,13 @@ api_path_parse(char *api_path,
* err;
* ...
* if (cplist)
- * clixon_path_free(cplist);
+ * clixon_path_free(cplist);
* @endcode
* @see clixon_path_free
*/
static int
instance_id_parse(char *path,
- clixon_path **cplist)
+ clixon_path **cplist)
{
int retval = -1;
clixon_instance_id_yacc iy = {0,};
@@ -179,14 +179,14 @@ instance_id_parse(char *path,
iy.iy_name = "instance-id parser";
iy.iy_linenum = 1;
if (instance_id_scan_init(&iy) < 0)
- goto done;
+ goto done;
if (instance_id_parse_init(&iy) < 0)
- goto done;
+ goto done;
if (clixon_instance_id_parseparse(&iy) != 0) { /* yacc returns 1 on error */
- clicon_log(LOG_NOTICE, "Instance-id error: on line %d", iy.iy_linenum);
- if (clicon_errno == 0)
- clicon_err(OE_XML, 0, "Instance-id parser error with no error code (should not happen)");
- goto done;
+ clicon_log(LOG_NOTICE, "Instance-id error: on line %d", iy.iy_linenum);
+ if (clicon_errno == 0)
+ clicon_err(OE_XML, 0, "Instance-id parser error with no error code (should not happen)");
+ goto done;
}
instance_id_parse_exit(&iy);
instance_id_scan_exit(&iy);
@@ -202,14 +202,14 @@ clixon_path_free(clixon_path *cplist)
clixon_path *cp;
while ((cp = cplist) != NULL){
- DELQ(cp, cplist, clixon_path *);
- if (cp->cp_prefix)
- free(cp->cp_prefix);
- if (cp->cp_id)
- free(cp->cp_id);
- if (cp->cp_cvk)
- cvec_free(cp->cp_cvk);
- free(cp);
+ DELQ(cp, cplist, clixon_path *);
+ if (cp->cp_prefix)
+ free(cp->cp_prefix);
+ if (cp->cp_id)
+ free(cp->cp_id);
+ if (cp->cp_cvk)
+ cvec_free(cp->cp_cvk);
+ free(cp);
}
return 0;
}
@@ -218,32 +218,32 @@ clixon_path_free(clixon_path *cplist)
*/
static int
clixon_path_print(FILE *f,
- clixon_path *cplist)
+ clixon_path *cplist)
{
clixon_path *cp;
cg_var *cv;
if ((cp = cplist) != NULL){
- do {
- fprintf(f, "/");
- if (cp->cp_prefix)
- fprintf(f, "%s:", cp->cp_prefix);
- fprintf(f, "%s", cp->cp_id);
- if (cp->cp_cvk){
- fprintf(f, "=");
- cv = NULL;
- while ((cv = cvec_each(cp->cp_cvk, cv)) != NULL){
- fprintf(f, "[");
- /* If cvk has one integer argument, interpret as position, eg x/y[42] */
- if (cvec_len(cp->cp_cvk) == 1 && (cv_type_get(cv) == CGV_UINT32))
- fprintf(f, "%u", cv_uint32_get(cv));
- else
- fprintf(f, "%s=\"%s\"", cv_name_get(cv), cv_string_get(cv));
- fprintf(f, "]");
- }
- }
- cp = NEXTQ(clixon_path *, cp);
- } while (cp && cp != cplist);
+ do {
+ fprintf(f, "/");
+ if (cp->cp_prefix)
+ fprintf(f, "%s:", cp->cp_prefix);
+ fprintf(f, "%s", cp->cp_id);
+ if (cp->cp_cvk){
+ fprintf(f, "=");
+ cv = NULL;
+ while ((cv = cvec_each(cp->cp_cvk, cv)) != NULL){
+ fprintf(f, "[");
+ /* If cvk has one integer argument, interpret as position, eg x/y[42] */
+ if (cvec_len(cp->cp_cvk) == 1 && (cv_type_get(cv) == CGV_UINT32))
+ fprintf(f, "%u", cv_uint32_get(cv));
+ else
+ fprintf(f, "%s=\"%s\"", cv_name_get(cv), cv_string_get(cv));
+ fprintf(f, "]");
+ }
+ }
+ cp = NEXTQ(clixon_path *, cp);
+ } while (cp && cp != cplist);
}
fprintf(f, "\n");
return 0;
@@ -258,7 +258,7 @@ clixon_path_print(FILE *f,
*/
int
xml_yang_root(cxobj *x,
- cxobj **xr)
+ cxobj **xr)
{
int retval = -1;
cxobj *xp;
@@ -266,14 +266,14 @@ xml_yang_root(cxobj *x,
yang_stmt *yp;
while ((xp = xml_parent(x)) != NULL){
- if ((y = xml_spec(x)) != NULL &&
- (yp = yang_parent_get(y)) != NULL)
- /* Actually, maybe only the Y_MODULE clause is relevant */
- if (yp==NULL ||
- yang_keyword_get(yp) == Y_MODULE ||
- yang_keyword_get(yp) == Y_SUBMODULE)
- break; /* x is the root */
- x = xp;
+ if ((y = xml_spec(x)) != NULL &&
+ (yp = yang_parent_get(y)) != NULL)
+ /* Actually, maybe only the Y_MODULE clause is relevant */
+ if (yp==NULL ||
+ yang_keyword_get(yp) == Y_MODULE ||
+ yang_keyword_get(yp) == Y_SUBMODULE)
+ break; /* x is the root */
+ x = xp;
}
*xr = x;
retval = 0;
@@ -294,8 +294,8 @@ xml_yang_root(cxobj *x,
*/
static int
yang2api_path_fmt_1(yang_stmt *ys,
- int inclkey,
- cbuf *cb)
+ int inclkey,
+ cbuf *cb)
{
yang_stmt *yp; /* parent */
yang_stmt *ymod = NULL;
@@ -305,73 +305,73 @@ yang2api_path_fmt_1(yang_stmt *ys,
int retval = -1;
if ((yp = yang_parent_get(ys)) == NULL){
- clicon_err(OE_YANG, EINVAL, "yang expected parent %s", yang_argument_get(ys));
- goto done;
+ clicon_err(OE_YANG, EINVAL, "yang expected parent %s", yang_argument_get(ys));
+ goto done;
}
if (yp != NULL && /* XXX rm */
- yang_keyword_get(yp) != Y_MODULE &&
- yang_keyword_get(yp) != Y_SUBMODULE){
+ yang_keyword_get(yp) != Y_MODULE &&
+ yang_keyword_get(yp) != Y_SUBMODULE){
- if (yang2api_path_fmt_1((yang_stmt *)yp, 1, cb) < 0) /* recursive call */
- goto done;
- if (yang_keyword_get(yp) != Y_CHOICE && yang_keyword_get(yp) != Y_CASE){
+ if (yang2api_path_fmt_1((yang_stmt *)yp, 1, cb) < 0) /* recursive call */
+ goto done;
+ if (yang_keyword_get(yp) != Y_CHOICE && yang_keyword_get(yp) != Y_CASE){
#if 0
- /* In some cases, such as cli_show_auto, a trailing '/' should
- * NOT be present if ys is a key in a list.
- * But in other cases (I think most), the / should be there,
- * so a patch is added in cli_show_auto instead.
- */
- if (yang_keyword_get(ys) == Y_LEAF && yp &&
- yang_keyword_get(yp) == Y_LIST &&
- yang_key_match(yp, ys->ys_argument, NULL) == 1)
- ;
- else
+ /* In some cases, such as cli_show_auto, a trailing '/' should
+ * NOT be present if ys is a key in a list.
+ * But in other cases (I think most), the / should be there,
+ * so a patch is added in cli_show_auto instead.
+ */
+ if (yang_keyword_get(ys) == Y_LEAF && yp &&
+ yang_keyword_get(yp) == Y_LIST &&
+ yang_key_match(yp, ys->ys_argument, NULL) == 1)
+ ;
+ else
#endif
- cprintf(cb, "/");
- }
- /* If parent namespace/module is different from child -> add child prefix */
- if (ys_real_module(yp, &ypmod) < 0)
- goto done;
- if (ys_real_module(ys, &ymod) < 0)
- goto done;
- if (ypmod != ymod)
- cprintf(cb, "%s:", yang_argument_get(ymod));
+ cprintf(cb, "/");
+ }
+ /* If parent namespace/module is different from child -> add child prefix */
+ if (ys_real_module(yp, &ypmod) < 0)
+ goto done;
+ if (ys_real_module(ys, &ymod) < 0)
+ goto done;
+ if (ypmod != ymod)
+ cprintf(cb, "%s:", yang_argument_get(ymod));
}
else /* top symbol - mark with name prefix */
- cprintf(cb, "/%s:", yang_argument_get(yp));
+ cprintf(cb, "/%s:", yang_argument_get(yp));
if (inclkey){
- if (yang_keyword_get(ys) != Y_CHOICE && yang_keyword_get(ys) != Y_CASE)
- cprintf(cb, "%s", yang_argument_get(ys));
+ if (yang_keyword_get(ys) != Y_CHOICE && yang_keyword_get(ys) != Y_CASE)
+ cprintf(cb, "%s", yang_argument_get(ys));
}
else{
- if (yang_keyword_get(ys) == Y_LEAF && yp &&
- yang_keyword_get(yp) == Y_LIST){
- if (yang_key_match(yp, yang_argument_get(ys), NULL) == 0)
- cprintf(cb, "%s", yang_argument_get(ys)); /* Not if leaf and key */
- }
- else
- if (yang_keyword_get(ys) != Y_CHOICE && yang_keyword_get(ys) != Y_CASE)
- cprintf(cb, "%s", yang_argument_get(ys));
+ if (yang_keyword_get(ys) == Y_LEAF && yp &&
+ yang_keyword_get(yp) == Y_LIST){
+ if (yang_key_match(yp, yang_argument_get(ys), NULL) == 0)
+ cprintf(cb, "%s", yang_argument_get(ys)); /* Not if leaf and key */
+ }
+ else
+ if (yang_keyword_get(ys) != Y_CHOICE && yang_keyword_get(ys) != Y_CASE)
+ cprintf(cb, "%s", yang_argument_get(ys));
}
switch (yang_keyword_get(ys)){
case Y_LIST:
- cvk = yang_cvec_get(ys); /* Use Y_LIST cache, see ys_populate_list() */
- if (cvec_len(cvk))
- cprintf(cb, "=");
- /* Iterate over individual keys */
- for (i=0; i get module + change namespace */
- if ((ymod = yang_find_module_by_name(yspec, prefix)) == NULL){
- cprintf(cberr, "No such yang module: %s", prefix);
- if (xerr && netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
- }
- namespace = yang_find_mynamespace(ymod); /* change namespace */
- }
- if (i == offset && ymod) /* root */
- y = yang_find_datanode(ymod, name);
- else
- y = yang_find_datanode(y, name);
- if (y == NULL){
- if (xerr && netconf_unknown_element_xml(xerr, "application", name, "Unknown element") < 0)
- goto done;
- goto fail;
- }
+ nodeid = cv_name_get(cv);
+ /* api-path: prefix points to module */
+ if (nodeid_split(nodeid, &prefix, &name) < 0)
+ goto done;
+ clicon_debug(1, "%s [%d] cvname: %s:%s",
+ __FUNCTION__, i, prefix?prefix:"", name);
+ /* top-node must have prefix */
+ if (i == offset && prefix == NULL){
+ cprintf(cberr, "'%s': Expected prefix:name", nodeid);
+ if (xerr && netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
+ ymod = NULL;
+ if (prefix){ /* if prefix -> get module + change namespace */
+ if ((ymod = yang_find_module_by_name(yspec, prefix)) == NULL){
+ cprintf(cberr, "No such yang module: %s", prefix);
+ if (xerr && netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
+ namespace = yang_find_mynamespace(ymod); /* change namespace */
+ }
+ if (i == offset && ymod) /* root */
+ y = yang_find_datanode(ymod, name);
+ else
+ y = yang_find_datanode(y, name);
+ if (y == NULL){
+ if (xerr && netconf_unknown_element_xml(xerr, "application", name, "Unknown element") < 0)
+ goto done;
+ goto fail;
+ }
- /* Get XML/xpath prefix given namespace.
- * note different from api-path prefix
- */
- if (xml_nsctx_get_prefix(nsc, namespace, &xprefix) == 0){
- xprefix = yang_find_myprefix(y);
- clicon_debug(1, "%s prefix not found add it %s", __FUNCTION__, xprefix);
- /* not found, add it to nsc
- * XXX: do we always have to add it? It could be default?
- */
- // if (xml2prefix(x1, namespace, &pexisting));
- if (xml_nsctx_add(nsc, xprefix, namespace) < 0)
- goto done;
- }
- /* Check if has value, means '=' */
- if (cv_type_get(cv) == CGV_STRING){
- /* val is uri percent encoded, eg x%2Cy,z */
+ /* Get XML/xpath prefix given namespace.
+ * note different from api-path prefix
+ */
+ if (xml_nsctx_get_prefix(nsc, namespace, &xprefix) == 0){
+ xprefix = yang_find_myprefix(y);
+ clicon_debug(1, "%s prefix not found add it %s", __FUNCTION__, xprefix);
+ /* not found, add it to nsc
+ * XXX: do we always have to add it? It could be default?
+ */
+ // if (xml2prefix(x1, namespace, &pexisting));
+ if (xml_nsctx_add(nsc, xprefix, namespace) < 0)
+ goto done;
+ }
+ /* Check if has value, means '=' */
+ if (cv_type_get(cv) == CGV_STRING){
+ /* val is uri percent encoded, eg x%2Cy,z */
if ((val = cv2str_dup(cv)) == NULL)
goto done;
- switch (yang_keyword_get(y)){
- case Y_LIST:
- /* Transform value "a,b,c" to "a" "b" "c" (nvalvec=3)
- * Note that vnr can be < length of cvk, due to empty or unset values
- */
- if (valvec){ /* loop, valvec may have been used before */
- free(valvec);
- valvec = NULL;
- }
- if ((valvec = clicon_strsep(val, ",", &nvalvec)) == NULL)
- goto done;
- cvk = yang_cvec_get(y); /* Use Y_LIST cache, see ys_populate_list() */
- cvi = NULL;
- /* Iterate over individual yang keys */
- if (i != offset)
- cprintf(xpath, "/");
- if (xprefix)
- cprintf(xpath, "%s:", xprefix);
- cprintf(xpath, "%s", name);
- vi = 0;
- while ((cvi = cvec_each(cvk, cvi)) != NULL && vi1 && api_path[0] == '/' && api_path[1] == '/'){
- if (xerr && netconf_invalid_value_xml(xerr, "application", "Invalid api-path beginning with //") < 0)
- goto done;
- goto fail;
+ if (xerr && netconf_invalid_value_xml(xerr, "application", "Invalid api-path beginning with //") < 0)
+ goto done;
+ goto fail;
}
/* Split api-path into cligen variable vector,
* dont decode since api_path2xpath_cvv takes uri encode as input */
if (uri_str2cvec(api_path, '/', '=', 0, &cvv) < 0)
- goto done;
+ goto done;
if ((xpath = cbuf_new()) == NULL)
goto done;
if ((ret = api_path2xpath_cvv(cvv, 0, yspec, xpath, nsc, xerr)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* prepare output xpath parameter */
if (xpathp)
- if ((*xpathp = strdup(cbuf_get(xpath))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
+ if ((*xpathp = strdup(cbuf_get(xpath))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
retval = 1;
done:
if (cvv)
- cvec_free(cvv);
+ cvec_free(cvv);
if (xpath)
- cbuf_free(xpath);
+ cbuf_free(xpath);
return retval;
fail:
retval = 0; /* Validation failed */
@@ -916,14 +916,14 @@ api_path2xpath(char *api_path,
*/
static int
api_path2xml_vec(char **vec,
- int nvec,
- cxobj *x0,
- yang_stmt *y0,
- yang_class nodeclass,
- int strict,
- cxobj **xbotp,
- yang_stmt **ybotp,
- cxobj **xerr)
+ int nvec,
+ cxobj *x0,
+ yang_stmt *y0,
+ yang_class nodeclass,
+ int strict,
+ cxobj **xbotp,
+ yang_stmt **ybotp,
+ cxobj **xerr)
{
int retval = -1;
char *nodeid;
@@ -947,190 +947,190 @@ api_path2xml_vec(char **vec,
char *val = NULL;
if ((nodeid = vec[0]) == NULL || strlen(nodeid)==0){
- if (xbotp)
- *xbotp = x0;
- if (ybotp)
- *ybotp = y0;
- goto ok;
+ if (xbotp)
+ *xbotp = x0;
+ if (ybotp)
+ *ybotp = y0;
+ goto ok;
} /* E.g "x=1,2" -> nodeid:x restval=1,2 */
if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
/* restval is RFC 3896 encoded */
if ((restval = index(nodeid, '=')) != NULL){
- *restval = '\0';
- restval++;
+ *restval = '\0';
+ restval++;
}
/* Split into prefix and localname */
if (nodeid_split(nodeid, &prefix, &name) < 0)
- goto done;
+ goto done;
if (yang_keyword_get(y0) == Y_SPEC){ /* top-node */
- if (prefix == NULL){
- cprintf(cberr, "api-path element '%s', expected prefix:name", nodeid);
- if (xerr &&
- netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
- }
- if ((ymod = yang_find_module_by_name(y0, prefix)) == NULL){
- cprintf(cberr, "No such yang module prefix");
- if (xerr &&
- netconf_unknown_element_xml(xerr, "application", prefix, cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
- }
- namespace = yang_find_mynamespace(ymod);
- y0 = ymod;
+ if (prefix == NULL){
+ cprintf(cberr, "api-path element '%s', expected prefix:name", nodeid);
+ if (xerr &&
+ netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
+ if ((ymod = yang_find_module_by_name(y0, prefix)) == NULL){
+ cprintf(cberr, "No such yang module prefix");
+ if (xerr &&
+ netconf_unknown_element_xml(xerr, "application", prefix, cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
+ namespace = yang_find_mynamespace(ymod);
+ y0 = ymod;
}
y = (nodeclass==YC_SCHEMANODE)?
- yang_find_schemanode(y0, name):
- yang_find_datanode(y0, name);
+ yang_find_schemanode(y0, name):
+ yang_find_datanode(y0, name);
if (y == NULL){
- if (xerr &&
- netconf_unknown_element_xml(xerr, "application", name, "Unknown element") < 0)
- goto done;
- goto fail;
+ if (xerr &&
+ netconf_unknown_element_xml(xerr, "application", name, "Unknown element") < 0)
+ goto done;
+ goto fail;
}
if (prefix && namespace == NULL){
- if ((ymod = yang_find_module_by_name(ys_spec(y0), prefix)) == NULL){
- cprintf(cberr, "api-path element prefix: '%s', no such yang module", prefix);
- if (xerr &&
- netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
- }
- namespace = yang_find_mynamespace(ymod);
+ if ((ymod = yang_find_module_by_name(ys_spec(y0), prefix)) == NULL){
+ cprintf(cberr, "api-path element prefix: '%s', no such yang module", prefix);
+ if (xerr &&
+ netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
+ namespace = yang_find_mynamespace(ymod);
}
switch (yang_keyword_get(y)){
case Y_LEAF_LIST:
#if 0
- if (restval==NULL){
- clicon_err(OE_XML, 0, "malformed key, expected '=restval'");
- goto done;
- }
+ if (restval==NULL){
+ clicon_err(OE_XML, 0, "malformed key, expected '=restval'");
+ goto done;
+ }
#endif
- if (x0 == NULL)
- break;
- if ((x = xml_new(yang_argument_get(y), x0, CX_ELMNT)) == NULL)
- goto done;
- xml_spec_set(x, y);
- if ((xb = xml_new("body", x, CX_BODY)) == NULL)
- goto done;
- if (restval){
- if (uri_percent_decode(restval, &val) < 0)
- goto done;
- }
- if (val && xml_value_set(xb, val) < 0)
- goto done;
- break;
+ if (x0 == NULL)
+ break;
+ if ((x = xml_new(yang_argument_get(y), x0, CX_ELMNT)) == NULL)
+ goto done;
+ xml_spec_set(x, y);
+ if ((xb = xml_new("body", x, CX_BODY)) == NULL)
+ goto done;
+ if (restval){
+ if (uri_percent_decode(restval, &val) < 0)
+ goto done;
+ }
+ if (val && xml_value_set(xb, val) < 0)
+ goto done;
+ break;
case Y_LIST:
- cvk = yang_cvec_get(y); /* Use Y_LIST cache, see ys_populate_list() */
- if (restval==NULL){
- if (strict){
- cprintf(cberr, "malformed key =%s, expected '=restval'", nodeid);
- if (xerr &&
- netconf_malformed_message_xml(xerr, cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
- }
- }
- else{
- /* Transform restval "a,b,c" to "a" "b" "c" (nvalvec=3)
- * Note that vnr can be < length of cvk, due to empty or unset values
- * Note also that valvec entries are encoded
- */
- if ((valvec = clicon_strsep(restval, ",", &nvalvec)) == NULL)
- goto done;
- if ((nvalvec != cvec_len(cvk)) && strict){
- cprintf(cberr, "List key %s length mismatch", name);
- if (xerr &&
- netconf_malformed_message_xml(xerr, cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
- }
- }
- cvi = NULL;
- /* create list object */
- if (x0){
- if ((x = xml_new(name, x0, CX_ELMNT)) == NULL)
- goto done;
- xml_spec_set(x, y);
- }
- vi = 0;
- /* Create keys */
- while ((cvi = cvec_each(cvk, cvi)) != NULL){
- keyname = cv_string_get(cvi);
- if ((ykey = yang_find(y, Y_LEAF, keyname)) == NULL){
- cprintf(cberr, "List statement \"%s\" has no key leaf \"%s\"",
- yang_argument_get(y), keyname);
- if (xerr &&
- netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
- }
- if (x != NULL){
- if ((xn = xml_new(keyname, x, CX_ELMNT)) == NULL)
- goto done;
- xml_spec_set(xn, ykey);
- if ((xb = xml_new("body", xn, CX_BODY)) == NULL)
- goto done;
- if (vi++ < nvalvec){
- /* Here assign and decode key values */
- val = NULL;
- if (uri_percent_decode(valvec[vi-1], &val) < 0)
- goto done;
- if (xml_value_set(xb, val) < 0)
- goto done;
- if (val){
- free(val);
- val = NULL;
- }
- }
- }
- }
- break;
+ cvk = yang_cvec_get(y); /* Use Y_LIST cache, see ys_populate_list() */
+ if (restval==NULL){
+ if (strict){
+ cprintf(cberr, "malformed key =%s, expected '=restval'", nodeid);
+ if (xerr &&
+ netconf_malformed_message_xml(xerr, cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ else{
+ /* Transform restval "a,b,c" to "a" "b" "c" (nvalvec=3)
+ * Note that vnr can be < length of cvk, due to empty or unset values
+ * Note also that valvec entries are encoded
+ */
+ if ((valvec = clicon_strsep(restval, ",", &nvalvec)) == NULL)
+ goto done;
+ if ((nvalvec != cvec_len(cvk)) && strict){
+ cprintf(cberr, "List key %s length mismatch", name);
+ if (xerr &&
+ netconf_malformed_message_xml(xerr, cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ cvi = NULL;
+ /* create list object */
+ if (x0){
+ if ((x = xml_new(name, x0, CX_ELMNT)) == NULL)
+ goto done;
+ xml_spec_set(x, y);
+ }
+ vi = 0;
+ /* Create keys */
+ while ((cvi = cvec_each(cvk, cvi)) != NULL){
+ keyname = cv_string_get(cvi);
+ if ((ykey = yang_find(y, Y_LEAF, keyname)) == NULL){
+ cprintf(cberr, "List statement \"%s\" has no key leaf \"%s\"",
+ yang_argument_get(y), keyname);
+ if (xerr &&
+ netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
+ if (x != NULL){
+ if ((xn = xml_new(keyname, x, CX_ELMNT)) == NULL)
+ goto done;
+ xml_spec_set(xn, ykey);
+ if ((xb = xml_new("body", xn, CX_BODY)) == NULL)
+ goto done;
+ if (vi++ < nvalvec){
+ /* Here assign and decode key values */
+ val = NULL;
+ if (uri_percent_decode(valvec[vi-1], &val) < 0)
+ goto done;
+ if (xml_value_set(xb, val) < 0)
+ goto done;
+ if (val){
+ free(val);
+ val = NULL;
+ }
+ }
+ }
+ }
+ break;
default: /* eg Y_CONTAINER, Y_LEAF */
- if (restval != NULL){
- if (strict){
- cprintf(cberr, "malformed api-path, =%s not expected", restval);
- if (xerr &&
- netconf_malformed_message_xml(xerr, cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
- }
- }
- if (x0 &&
- (x = xml_find_type(x0, NULL, name, CX_ELMNT)) == NULL){ /* eg key of list */
- if ((x = xml_new(name, x0, CX_ELMNT)) == NULL)
- goto done;
- xml_spec_set(x, y);
- }
- break;
+ if (restval != NULL){
+ if (strict){
+ cprintf(cberr, "malformed api-path, =%s not expected", restval);
+ if (xerr &&
+ netconf_malformed_message_xml(xerr, cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ if (x0 &&
+ (x = xml_find_type(x0, NULL, name, CX_ELMNT)) == NULL){ /* eg key of list */
+ if ((x = xml_new(name, x0, CX_ELMNT)) == NULL)
+ goto done;
+ xml_spec_set(x, y);
+ }
+ break;
}
if (x && namespace){
- if (xmlns_set(x, NULL, namespace) < 0)
- goto done;
+ if (xmlns_set(x, NULL, namespace) < 0)
+ goto done;
}
if ((retval = api_path2xml_vec(vec+1, nvec-1,
- x, y,
- nodeclass, strict,
- xbotp, ybotp, xerr)) < 1)
- goto done;
+ x, y,
+ nodeclass, strict,
+ xbotp, ybotp, xerr)) < 1)
+ goto done;
ok:
retval = 1; /* OK */
done:
clicon_debug(2, "%s retval:%d", __FUNCTION__, retval);
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
if (prefix)
- free(prefix);
+ free(prefix);
if (name)
- free(name);
+ free(name);
if (valvec)
- free(valvec);
+ free(valvec);
if (val)
- free(val);
+ free(val);
return retval;
fail:
retval = 0; /* invalid api-path or XML */
@@ -1171,13 +1171,13 @@ api_path2xml_vec(char **vec,
*/
int
api_path2xml(char *api_path,
- yang_stmt *yspec,
- cxobj *xtop,
- yang_class nodeclass,
- int strict,
- cxobj **xbotp,
- yang_stmt **ybotp,
- cxobj **xerr)
+ yang_stmt *yspec,
+ cxobj *xtop,
+ yang_class nodeclass,
+ int strict,
+ cxobj **xbotp,
+ yang_stmt **ybotp,
+ cxobj **xerr)
{
int retval = -1;
char **vec = NULL;
@@ -1187,44 +1187,44 @@ api_path2xml(char *api_path,
clicon_debug(2, "%s api_path:%s", __FUNCTION__, api_path);
if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
if (*api_path != '/'){
- cprintf(cberr, "Invalid api-path: %s (must start with '/')", api_path);
- if (xerr && netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
+ cprintf(cberr, "Invalid api-path: %s (must start with '/')", api_path);
+ if (xerr && netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
}
if ((vec = clicon_strsep(api_path, "/", &nvec)) == NULL)
- goto done;
+ goto done;
/* Remove trailing '/'. Like in /a/ -> /a */
if (nvec > 1 && !strlen(vec[nvec-1]))
- nvec--;
+ nvec--;
if (nvec < 1){
- cprintf(cberr, "Malformed api-path: %s: too short)", api_path);
- if (xerr && netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
+ cprintf(cberr, "Malformed api-path: %s: too short)", api_path);
+ if (xerr && netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
}
nvec--; /* NULL-terminated */
if ((retval = api_path2xml_vec(vec+1, nvec,
- xtop, yspec, nodeclass, strict,
- xbotp, ybotp, xerr)) < 1)
- goto done;
+ xtop, yspec, nodeclass, strict,
+ xbotp, ybotp, xerr)) < 1)
+ goto done;
/* Fix namespace */
if (xbotp){
- xml_yang_root(*xbotp, &xroot);
- if (xmlns_assign(xroot) < 0)
- goto done;
+ xml_yang_root(*xbotp, &xroot);
+ if (xmlns_assign(xroot) < 0)
+ goto done;
}
// ok:
retval = 1;
done:
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
if (vec)
- free(vec);
+ free(vec);
return retval;
fail:
retval = 0;
@@ -1242,7 +1242,7 @@ api_path2xml(char *api_path,
int
xml2api_path_1(cxobj *x,
- cbuf *cb)
+ cbuf *cb)
{
int retval = -1;
yang_stmt *y = NULL;
@@ -1259,59 +1259,59 @@ xml2api_path_1(cxobj *x,
cxobj *xp;
if ((y = xml_spec(x)) == NULL){
- cprintf(cb, "/%s", xml_name(x));
- goto ok;
+ cprintf(cb, "/%s", xml_name(x));
+ goto ok;
}
ymod = ys_module(y);
xp = xml_parent(x);
if (ymod && xp && xml_spec(xp)==NULL) /* Add prefix only if root */
- cprintf(cb, "/%s:%s", yang_argument_get(ymod), xml_name(x));
+ cprintf(cb, "/%s:%s", yang_argument_get(ymod), xml_name(x));
else
- cprintf(cb, "/%s", xml_name(x));
+ cprintf(cb, "/%s", xml_name(x));
keyword = yang_keyword_get(y);
switch (keyword){
case Y_LEAF_LIST:
- b = xml_body(x);
- enc = NULL;
- if (uri_percent_encode(&enc, "%s", b) < 0)
- goto done;
- cprintf(cb, "=%s", enc?enc:"");
- if (enc)
- free(enc);
- break;
+ b = xml_body(x);
+ enc = NULL;
+ if (uri_percent_encode(&enc, "%s", b) < 0)
+ goto done;
+ cprintf(cb, "=%s", enc?enc:"");
+ if (enc)
+ free(enc);
+ break;
case Y_LIST:
- cvk = yang_cvec_get(y); /* Use Y_LIST cache, see ys_populate_list() */
- if (cvec_len(cvk))
- cprintf(cb, "=");
- /* Iterate over individual keys */
- cvi = NULL;
- i = 0;
- while ((cvi = cvec_each(cvk, cvi)) != NULL) {
- keyname = cv_string_get(cvi);
- if ((xkey = xml_find(x, keyname)) == NULL)
- goto done; /* No key in xml */
- if ((xb = xml_find(x, keyname)) == NULL)
- goto done;
- if (i++)
- cprintf(cb, ",");
- b = xml_body(xb);
- enc = NULL;
- if (uri_percent_encode(&enc, "%s", b) < 0)
- goto done;
- cprintf(cb, "%s", enc?enc:"");
- if (enc)
- free(enc);
- }
- break;
+ cvk = yang_cvec_get(y); /* Use Y_LIST cache, see ys_populate_list() */
+ if (cvec_len(cvk))
+ cprintf(cb, "=");
+ /* Iterate over individual keys */
+ cvi = NULL;
+ i = 0;
+ while ((cvi = cvec_each(cvk, cvi)) != NULL) {
+ keyname = cv_string_get(cvi);
+ if ((xkey = xml_find(x, keyname)) == NULL)
+ goto done; /* No key in xml */
+ if ((xb = xml_find(x, keyname)) == NULL)
+ goto done;
+ if (i++)
+ cprintf(cb, ",");
+ b = xml_body(xb);
+ enc = NULL;
+ if (uri_percent_encode(&enc, "%s", b) < 0)
+ goto done;
+ cprintf(cb, "%s", enc?enc:"");
+ if (enc)
+ free(enc);
+ }
+ break;
default:
- break;
+ break;
}
#if 0
{ /* Just for testing */
- cxobj *xc;
- if ((xc = xml_child_i_type(x, 0, CX_ELMNT)) != NULL)
- if (xml2api_path_1(xc, cb) < 0)
- goto done;
+ cxobj *xc;
+ if ((xc = xml_child_i_type(x, 0, CX_ELMNT)) != NULL)
+ if (xml2api_path_1(xc, cb) < 0)
+ goto done;
}
#endif
ok:
@@ -1336,7 +1336,7 @@ xml2api_path_1(cxobj *x,
*/
static int
api_path_resolve(clixon_path *cplist,
- yang_stmt *yt)
+ yang_stmt *yt)
{
int retval = -1;
clixon_path *cp;
@@ -1346,56 +1346,56 @@ api_path_resolve(clixon_path *cplist,
cg_var *cvy;
if ((cp = cplist) != NULL){
- do {
- if (yang_keyword_get(yt) == Y_SPEC){
- if (cp->cp_prefix == NULL){
- clicon_err(OE_YANG, ENOENT, "Modulename not defined for top-level id.");
- goto fail;
- }
- if ((yt = yang_find_module_by_name(yt, cp->cp_prefix)) == NULL){
- clicon_err(OE_YANG, ENOENT, "Modulename in api-path does not correspond to existing module");
- goto fail;
- }
- }
- if ((yc = yang_find_datanode(yt, cp->cp_id)) == NULL){
- clicon_err(OE_YANG, ENOENT, "Corresponding yang node for id not found");
- goto fail;
- }
- cp->cp_yang = yc;
- if (cp->cp_cvk){
- /* Iterate over yang list keys and assign as names (or "." for leaf-list) in cvk */
- if (yang_keyword_get(yc) == Y_LEAF_LIST){
- cva = NULL;
- while ((cva = cvec_each(cp->cp_cvk, cva)) != NULL) {
- if (cv_name_get(cva) == NULL)
- cv_name_set(cva, ".");
- }
- }
- else if (yang_keyword_get(yc) == Y_LIST){
- if (cvec_len(cp->cp_cvk) > cvec_len(yang_cvec_get(yc))){
- clicon_err(OE_YANG, ENOENT, "Number of keys in key-value list does not match Yang list");
- goto fail;
- }
- i = 0;
- cva = NULL;
- while ((cva = cvec_each(cp->cp_cvk, cva)) != NULL) {
- if (cv_name_get(cva) != NULL){
- clicon_err(OE_YANG, ENOENT, "Unexpected named key %s (shouldnt happen)",
- cv_name_get(cva));
- goto fail;
- }
- cvy = cvec_i(yang_cvec_get(yc), i++);
- cv_name_set(cva, cv_string_get(cvy));
- }
- }
- else{
- clicon_err(OE_YANG, ENOENT, "key-values only defined for list or leaf-list");
- goto fail;
- }
- }
- yt = yc;
- cp = NEXTQ(clixon_path *, cp);
- } while (cp && cp != cplist);
+ do {
+ if (yang_keyword_get(yt) == Y_SPEC){
+ if (cp->cp_prefix == NULL){
+ clicon_err(OE_YANG, ENOENT, "Modulename not defined for top-level id.");
+ goto fail;
+ }
+ if ((yt = yang_find_module_by_name(yt, cp->cp_prefix)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "Modulename in api-path does not correspond to existing module");
+ goto fail;
+ }
+ }
+ if ((yc = yang_find_datanode(yt, cp->cp_id)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "Corresponding yang node for id not found");
+ goto fail;
+ }
+ cp->cp_yang = yc;
+ if (cp->cp_cvk){
+ /* Iterate over yang list keys and assign as names (or "." for leaf-list) in cvk */
+ if (yang_keyword_get(yc) == Y_LEAF_LIST){
+ cva = NULL;
+ while ((cva = cvec_each(cp->cp_cvk, cva)) != NULL) {
+ if (cv_name_get(cva) == NULL)
+ cv_name_set(cva, ".");
+ }
+ }
+ else if (yang_keyword_get(yc) == Y_LIST){
+ if (cvec_len(cp->cp_cvk) > cvec_len(yang_cvec_get(yc))){
+ clicon_err(OE_YANG, ENOENT, "Number of keys in key-value list does not match Yang list");
+ goto fail;
+ }
+ i = 0;
+ cva = NULL;
+ while ((cva = cvec_each(cp->cp_cvk, cva)) != NULL) {
+ if (cv_name_get(cva) != NULL){
+ clicon_err(OE_YANG, ENOENT, "Unexpected named key %s (shouldnt happen)",
+ cv_name_get(cva));
+ goto fail;
+ }
+ cvy = cvec_i(yang_cvec_get(yc), i++);
+ cv_name_set(cva, cv_string_get(cvy));
+ }
+ }
+ else{
+ clicon_err(OE_YANG, ENOENT, "key-values only defined for list or leaf-list");
+ goto fail;
+ }
+ }
+ yt = yc;
+ cp = NEXTQ(clixon_path *, cp);
+ } while (cp && cp != cplist);
}
retval = 1;
done:
@@ -1426,7 +1426,7 @@ api_path_resolve(clixon_path *cplist,
*/
static int
instance_id_resolve(clixon_path *cplist,
- yang_stmt *yt)
+ yang_stmt *yt)
{
int retval = -1;
clixon_path *cp;
@@ -1437,64 +1437,64 @@ instance_id_resolve(clixon_path *cplist,
yspec = ys_spec(yt);
if ((cp = cplist) != NULL){
- do {
- if (cp->cp_prefix == NULL){
- clicon_err(OE_YANG, ENOENT, "No prefix of identifier (keynames may omit prefix)");
- goto fail;
- }
- if (yang_keyword_get(yt) == Y_SPEC){
- if ((yt = yang_find_module_by_prefix_yspec(yspec, cp->cp_prefix)) == NULL){
- clicon_err(OE_YANG, ENOENT, "Prefix \"%s\" does not correspond to any existing module", cp->cp_prefix);
- goto fail;
- }
- }
- if ((yc = yang_find_datanode(yt, cp->cp_id)) == NULL){
- clicon_err(OE_YANG, ENOENT, "Node %s used in path has no corresponding yang node",
- cp->cp_id);
- goto fail;
- }
- cp->cp_yang = yc;
- switch (yang_keyword_get(yc)){
- case Y_LIST:
- if (cp->cp_cvk == NULL){
+ do {
+ if (cp->cp_prefix == NULL){
+ clicon_err(OE_YANG, ENOENT, "No prefix of identifier (keynames may omit prefix)");
+ goto fail;
+ }
+ if (yang_keyword_get(yt) == Y_SPEC){
+ if ((yt = yang_find_module_by_prefix_yspec(yspec, cp->cp_prefix)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "Prefix \"%s\" does not correspond to any existing module", cp->cp_prefix);
+ goto fail;
+ }
+ }
+ if ((yc = yang_find_datanode(yt, cp->cp_id)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "Node %s used in path has no corresponding yang node",
+ cp->cp_id);
+ goto fail;
+ }
+ cp->cp_yang = yc;
+ switch (yang_keyword_get(yc)){
+ case Y_LIST:
+ if (cp->cp_cvk == NULL){
#if 0 /* see key-value presence in lists note above */
- clicon_err(OE_YANG, ENOENT, "key-values mandatory for lists");
- goto fail;
+ clicon_err(OE_YANG, ENOENT, "key-values mandatory for lists");
+ goto fail;
#endif
- break;
- }
+ break;
+ }
#if 0 /* see key-value presence in lists note above */
- if (cvec_len(cp->cp_cvk) > cvec_len(yang_cvec_get(yc))){
- clicon_err(OE_YANG, ENOENT, "Number of keys in key-value list does not match Yang list ");
- goto fail;
- }
+ if (cvec_len(cp->cp_cvk) > cvec_len(yang_cvec_get(yc))){
+ clicon_err(OE_YANG, ENOENT, "Number of keys in key-value list does not match Yang list ");
+ goto fail;
+ }
#endif
- cva = NULL;
- while ((cva = cvec_each(cp->cp_cvk, cva)) != NULL) {
- if ((kname = cv_name_get(cva)) != NULL){ /* Check var exists */
- if (yang_find(yc, 0, kname) == NULL){
- clicon_err(OE_YANG, ENOENT, "Index variable %s used in path is not child of Yang node %s",
- kname, yang_argument_get(yc));
- goto fail;
- }
- }
- else{ /* Assume index */
-
- }
- }
- break;
- case Y_LEAF_LIST:
- break;
- default:
- if (cp->cp_cvk != NULL){
- clicon_err(OE_YANG, ENOENT, "key-values only defined for list or leaf-list");
- goto fail;
- }
- break;
- }
- yt = yc;
- cp = NEXTQ(clixon_path *, cp);
- } while (cp && cp != cplist);
+ cva = NULL;
+ while ((cva = cvec_each(cp->cp_cvk, cva)) != NULL) {
+ if ((kname = cv_name_get(cva)) != NULL){ /* Check var exists */
+ if (yang_find(yc, 0, kname) == NULL){
+ clicon_err(OE_YANG, ENOENT, "Index variable %s used in path is not child of Yang node %s",
+ kname, yang_argument_get(yc));
+ goto fail;
+ }
+ }
+ else{ /* Assume index */
+
+ }
+ }
+ break;
+ case Y_LEAF_LIST:
+ break;
+ default:
+ if (cp->cp_cvk != NULL){
+ clicon_err(OE_YANG, ENOENT, "key-values only defined for list or leaf-list");
+ goto fail;
+ }
+ break;
+ }
+ yt = yc;
+ cp = NEXTQ(clixon_path *, cp);
+ } while (cp && cp != cplist);
}
retval = 1;
done:
@@ -1516,9 +1516,9 @@ instance_id_resolve(clixon_path *cplist,
*/
static int
clixon_path_search(cxobj *xt,
- yang_stmt *yt,
- clixon_path *cplist,
- clixon_xvec **xvec0)
+ yang_stmt *yt,
+ clixon_path *cplist,
+ clixon_xvec **xvec0)
{
int retval = -1;
char *modns; /* Module namespace of api-path */
@@ -1526,54 +1526,54 @@ clixon_path_search(cxobj *xt,
clixon_xvec *xvecp = NULL;
clixon_xvec *xvecc = NULL;
yang_stmt *yc;
- cxobj *xp;
+ cxobj *xp;
int i;
cg_var *cv;
if ((xvecp = clixon_xvec_new()) == NULL)
- goto done;
+ goto done;
modns = NULL;
if ((cp = cplist) != NULL){
- if (clixon_xvec_append(xvecp, xt) < 0)
- goto done;
- do {
- yc = cp->cp_yang;
- if ((modns = yang_find_mynamespace(yc)) == NULL)
- goto fail;
- if (xvecp){
- if ((xvecc = clixon_xvec_new()) == NULL)
- goto done;
- for (i=0; icp_cvk && /* cornercase for instance-id [] special case */
- (yang_keyword_get(yc) == Y_LIST || yang_keyword_get(yc) == Y_LEAF_LIST) &&
- cvec_len(cp->cp_cvk) == 1 && (cv = cvec_i(cp->cp_cvk,0)) &&
- (cv_type_get(cv) == CGV_UINT32)){
- if (clixon_xml_find_pos(xp, yc, cv_uint32_get(cv), xvecc) < 0)
- goto done;
- }
- else if (clixon_xml_find_index(xp, yang_parent_get(yc),
- modns, yang_argument_get(yc),
- cp->cp_cvk, xvecc) < 0)
- goto done;
- /* XXX: xvecc append! either here or in the functions */
- } /* for */
- }
- if (xvecp)
- clixon_xvec_free(xvecp);
- xvecp = xvecc;
- xvecc = NULL;
- cp = NEXTQ(clixon_path *, cp);
- } while (cp && cp != cplist);
- *xvec0 = xvecp;
- xvecp = NULL;
+ if (clixon_xvec_append(xvecp, xt) < 0)
+ goto done;
+ do {
+ yc = cp->cp_yang;
+ if ((modns = yang_find_mynamespace(yc)) == NULL)
+ goto fail;
+ if (xvecp){
+ if ((xvecc = clixon_xvec_new()) == NULL)
+ goto done;
+ for (i=0; icp_cvk && /* cornercase for instance-id [] special case */
+ (yang_keyword_get(yc) == Y_LIST || yang_keyword_get(yc) == Y_LEAF_LIST) &&
+ cvec_len(cp->cp_cvk) == 1 && (cv = cvec_i(cp->cp_cvk,0)) &&
+ (cv_type_get(cv) == CGV_UINT32)){
+ if (clixon_xml_find_pos(xp, yc, cv_uint32_get(cv), xvecc) < 0)
+ goto done;
+ }
+ else if (clixon_xml_find_index(xp, yang_parent_get(yc),
+ modns, yang_argument_get(yc),
+ cp->cp_cvk, xvecc) < 0)
+ goto done;
+ /* XXX: xvecc append! either here or in the functions */
+ } /* for */
+ }
+ if (xvecp)
+ clixon_xvec_free(xvecp);
+ xvecp = xvecc;
+ xvecc = NULL;
+ cp = NEXTQ(clixon_path *, cp);
+ } while (cp && cp != cplist);
+ *xvec0 = xvecp;
+ xvecp = NULL;
} /* if */
retval = 1;
done:
if (xvecp)
- clixon_xvec_free(xvecp);
+ clixon_xvec_free(xvecp);
if (xvecc)
- clixon_xvec_free(xvecc);
+ clixon_xvec_free(xvecc);
return retval;
fail: /* eg no yang for api-path, no match */
*xvec0 = NULL;
@@ -1609,11 +1609,11 @@ clixon_path_search(cxobj *xt,
*/
int
clixon_xml_find_api_path(cxobj *xt,
- yang_stmt *yt,
- cxobj ***xvec,
- int *xlen,
- const char *format,
- ...)
+ yang_stmt *yt,
+ cxobj ***xvec,
+ int *xlen,
+ const char *format,
+ ...)
{
int retval = -1;
va_list ap;
@@ -1628,42 +1628,42 @@ clixon_xml_find_api_path(cxobj *xt,
va_end(ap);
/* allocate an api-path string exactly fitting the length */
if ((api_path = malloc(len+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* second round: actually compute api-path string content */
va_start(ap, format);
if (vsnprintf(api_path, len+1, format, ap) < 0){
- clicon_err(OE_UNIX, errno, "vsnprintf");
- va_end(ap);
- goto done;
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ va_end(ap);
+ goto done;
}
va_end(ap);
/* Parse api-path string to structured clixon-path data */
if (api_path_parse(api_path, &cplist) < 0)
- goto done;
+ goto done;
if (clicon_debug_get())
- clixon_path_print(stderr, cplist);
+ clixon_path_print(stderr, cplist);
/* Resolve module:name to yang-stmt, fail if not successful */
if ((ret = api_path_resolve(cplist, yt)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
if ((ret = clixon_path_search(xt, yt, cplist, &xv)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* Convert to api xvec format */
if (clixon_xvec_extract(xv, xvec, xlen, NULL) < 0)
- goto done;
+ goto done;
retval = 1;
done:
if (xv)
- clixon_xvec_free(xv);
+ clixon_xvec_free(xv);
if (cplist)
- clixon_path_free(cplist);
+ clixon_path_free(cplist);
if (api_path)
- free(api_path);
+ free(api_path);
return retval;
fail:
retval = 0;
@@ -1703,11 +1703,11 @@ clixon_xml_find_api_path(cxobj *xt,
*/
int
clixon_xml_find_instance_id(cxobj *xt,
- yang_stmt *yt,
- cxobj ***xvec,
- int *xlen,
- const char *format,
- ...)
+ yang_stmt *yt,
+ cxobj ***xvec,
+ int *xlen,
+ const char *format,
+ ...)
{
int retval = -1;
va_list ap;
@@ -1722,41 +1722,41 @@ clixon_xml_find_instance_id(cxobj *xt,
va_end(ap);
/* allocate a path string exactly fitting the length */
if ((path = malloc(len+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* second round: actually compute api-path string content */
va_start(ap, format);
if (vsnprintf(path, len+1, format, ap) < 0){
- clicon_err(OE_UNIX, errno, "vsnprintf");
- va_end(ap);
- goto done;
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ va_end(ap);
+ goto done;
}
va_end(ap);
if (instance_id_parse(path, &cplist) < 0)
- goto done;
+ goto done;
if (clicon_debug_get())
- clixon_path_print(stderr, cplist);
+ clixon_path_print(stderr, cplist);
/* Resolve module:name to pointer to yang-stmt, fail if not successful */
if ((ret = instance_id_resolve(cplist, yt)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
if ((ret = clixon_path_search(xt, yt, cplist, &xv)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* Convert to api xvec format */
if (xv && clixon_xvec_extract(xv, xvec, xlen, NULL) < 0)
- goto done;
+ goto done;
retval = 1;
done:
if (xv)
- clixon_xvec_free(xv);
+ clixon_xvec_free(xv);
if (cplist)
- clixon_path_free(cplist);
+ clixon_path_free(cplist);
if (path)
- free(path);
+ free(path);
return retval;
fail:
retval = 0;
@@ -1792,9 +1792,9 @@ clixon_xml_find_instance_id(cxobj *xt,
*/
int
clixon_instance_id_bind(yang_stmt *yt,
- cvec *nsctx,
- const char *format,
- ...)
+ cvec *nsctx,
+ const char *format,
+ ...)
{
int retval = -1;
va_list ap;
@@ -1810,45 +1810,45 @@ clixon_instance_id_bind(yang_stmt *yt,
va_end(ap);
/* allocate a path string exactly fitting the length */
if ((path = malloc(len+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* second round: actually compute api-path string content */
va_start(ap, format);
if (vsnprintf(path, len+1, format, ap) < 0){
- clicon_err(OE_UNIX, errno, "vsnprintf");
- va_end(ap);
- goto done;
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ va_end(ap);
+ goto done;
}
va_end(ap);
if (instance_id_parse(path, &cplist) < 0)
- goto done;
+ goto done;
if (clicon_debug_get())
- clixon_path_print(stderr, cplist);
+ clixon_path_print(stderr, cplist);
/* Resolve module:name to pointer to yang-stmt, fail if not successful */
if ((ret = instance_id_resolve(cplist, yt)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* Loop through prefixes used */
if ((cp = cplist) != NULL){
- do {
- if (cp->cp_prefix &&
- cp->cp_yang &&
- (namespace = yang_find_mynamespace(cp->cp_yang)) != NULL){
- if (xml_nsctx_get(nsctx, cp->cp_prefix) == NULL)
- if (xml_nsctx_add(nsctx, cp->cp_prefix, namespace) < 0)
- goto done;
- }
- cp = NEXTQ(clixon_path *, cp);
- } while (cp && cp != cplist);
+ do {
+ if (cp->cp_prefix &&
+ cp->cp_yang &&
+ (namespace = yang_find_mynamespace(cp->cp_yang)) != NULL){
+ if (xml_nsctx_get(nsctx, cp->cp_prefix) == NULL)
+ if (xml_nsctx_add(nsctx, cp->cp_prefix, namespace) < 0)
+ goto done;
+ }
+ cp = NEXTQ(clixon_path *, cp);
+ } while (cp && cp != cplist);
}
retval = 1;
done:
if (cplist)
- clixon_path_free(cplist);
+ clixon_path_free(cplist);
if (path)
- free(path);
+ free(path);
return retval;
fail:
retval = 0;
@@ -1869,10 +1869,10 @@ clixon_instance_id_bind(yang_stmt *yt,
*/
int
clixon_instance_id_parse(yang_stmt *yt,
- clixon_path **cplistp,
- cxobj **xerr,
- const char *format,
- ...)
+ clixon_path **cplistp,
+ cxobj **xerr,
+ const char *format,
+ ...)
{
int retval = -1;
va_list ap;
@@ -1886,39 +1886,39 @@ clixon_instance_id_parse(yang_stmt *yt,
va_end(ap);
/* allocate a path string exactly fitting the length */
if ((path = malloc(len+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* second round: actually compute api-path string content */
va_start(ap, format);
if (vsnprintf(path, len+1, format, ap) < 0){
- clicon_err(OE_UNIX, errno, "vsnprintf");
- va_end(ap);
- goto done;
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ va_end(ap);
+ goto done;
}
va_end(ap);
if (instance_id_parse(path, &cplist) < 0)
- goto done;
+ goto done;
if (clicon_debug_get())
- clixon_path_print(stderr, cplist);
+ clixon_path_print(stderr, cplist);
/* Resolve module:name to pointer to yang-stmt, fail if not successful */
if ((ret = instance_id_resolve(cplist, yt)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- if (xerr && netconf_invalid_value_xml(xerr, "application", clicon_err_reason) < 0)
- goto done;
- goto fail;
+ if (xerr && netconf_invalid_value_xml(xerr, "application", clicon_err_reason) < 0)
+ goto done;
+ goto fail;
}
if (cplistp){
- *cplistp = cplist;
- cplist = NULL;
+ *cplistp = cplist;
+ cplist = NULL;
}
retval = 1;
done:
if (cplist)
- clixon_path_free(cplist);
+ clixon_path_free(cplist);
if (path)
- free(path);
+ free(path);
return retval;
fail:
retval = 0;
diff --git a/lib/src/clixon_plugin.c b/lib/src/clixon_plugin.c
index aadacbb6..0d9d3daa 100644
--- a/lib/src/clixon_plugin.c
+++ b/lib/src/clixon_plugin.c
@@ -102,10 +102,10 @@ struct clixon_plugin{
* revision.
*/
typedef struct {
- qelem_t uc_qelem; /* List header */
+ qelem_t uc_qelem; /* List header */
clicon_upgrade_cb uc_callback; /* RPC Callback */
const char *uc_fnstr; /* Stringified fn name for debug */
- void *uc_arg; /* Application specific argument to cb */
+ void *uc_arg; /* Application specific argument to cb */
char *uc_namespace; /* Module namespace */
} upgrade_callback_t;
@@ -131,7 +131,7 @@ plugin_module_struct_get(clicon_handle h)
void *p;
if ((p = clicon_hash_value(cdat, "plugin-module-struct", &len)) != NULL)
- return *(plugin_module_struct **)p;
+ return *(plugin_module_struct **)p;
return NULL;
}
@@ -141,7 +141,7 @@ plugin_module_struct_get(clicon_handle h)
*/
static int
plugin_module_struct_set(clicon_handle h,
- plugin_module_struct *ms)
+ plugin_module_struct *ms)
{
clicon_hash_t *cdat = clicon_data(h);
@@ -149,7 +149,7 @@ plugin_module_struct_set(clicon_handle h,
so we send a ptr to the ptr to indicate what to copy.
*/
if (clicon_hash_add(cdat, "plugin-module-struct", &ms, sizeof(ms)) == NULL)
- return -1;
+ return -1;
return 0;
}
@@ -199,20 +199,20 @@ clixon_plugin_handle_get(clixon_plugin_t *cp)
*/
clixon_plugin_t *
clixon_plugin_each(clicon_handle h,
- clixon_plugin_t *cpprev)
+ clixon_plugin_t *cpprev)
{
clixon_plugin_t *cpnext = NULL;
plugin_module_struct *ms = plugin_module_struct_get(h);
/* ms == NULL means plugins are not yet initialized */
if (ms == NULL || ms->ms_plugin_list == NULL)
- cpnext = NULL;
+ cpnext = NULL;
else if (cpprev == NULL)
- cpnext = ms->ms_plugin_list;
+ cpnext = ms->ms_plugin_list;
else{
- cpnext = NEXTQ(clixon_plugin_t *, cpprev);
- if (cpnext == ms->ms_plugin_list)
- cpnext = NULL;
+ cpnext = NEXTQ(clixon_plugin_t *, cpprev);
+ if (cpnext == ms->ms_plugin_list)
+ cpnext = NULL;
}
return cpnext;
}
@@ -235,34 +235,34 @@ clixon_plugin_each(clicon_handle h,
*/
clixon_plugin_t *
clixon_plugin_each_revert(clicon_handle h,
- clixon_plugin_t *cpprev,
- int nr)
+ clixon_plugin_t *cpprev,
+ int nr)
{
int i;
clixon_plugin_t *cpnext = NULL;
plugin_module_struct *ms = plugin_module_struct_get(h);
if (ms == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
- return NULL;
+ clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
+ return NULL;
}
if (ms->ms_plugin_list == NULL)
- cpnext = NULL;
+ cpnext = NULL;
else if (cpprev == NULL){
- cpnext = ms->ms_plugin_list;
- for (i = nr-1; i > 0; i--) {
- cpnext = NEXTQ(clixon_plugin_t *, cpnext);
- if (cpnext == ms->ms_plugin_list){
- cpnext = NULL;
- break;
- }
- }
+ cpnext = ms->ms_plugin_list;
+ for (i = nr-1; i > 0; i--) {
+ cpnext = NEXTQ(clixon_plugin_t *, cpnext);
+ if (cpnext == ms->ms_plugin_list){
+ cpnext = NULL;
+ break;
+ }
+ }
}
else{
- if (cpprev == ms->ms_plugin_list)
- cpnext = NULL;
- else
- cpnext = PREVQ(clixon_plugin_t *, cpprev);
+ if (cpprev == ms->ms_plugin_list)
+ cpnext = NULL;
+ else
+ cpnext = PREVQ(clixon_plugin_t *, cpprev);
}
return cpnext;
}
@@ -279,21 +279,21 @@ clixon_plugin_each_revert(clicon_handle h,
*/
clixon_plugin_t *
clixon_plugin_find(clicon_handle h,
- const char *name)
+ const char *name)
{
clixon_plugin_t *cp = NULL;
plugin_module_struct *ms = plugin_module_struct_get(h);
if (ms == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
- return NULL;
+ clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
+ return NULL;
}
if ((cp = ms->ms_plugin_list) != NULL){
- do {
- if (strcmp(cp->cp_name, name) == 0)
- return cp;
- cp = NEXTQ(clixon_plugin_t *, cp);
- } while (cp && cp != ms->ms_plugin_list);
+ do {
+ if (strcmp(cp->cp_name, name) == 0)
+ return cp;
+ cp = NEXTQ(clixon_plugin_t *, cp);
+ } while (cp && cp != ms->ms_plugin_list);
}
return NULL;
}
@@ -311,10 +311,10 @@ clixon_plugin_find(clicon_handle h,
*/
static int
plugin_load_one(clicon_handle h,
- char *file, /* note modified */
- const char *function,
- int dlflags,
- clixon_plugin_t **cpp)
+ char *file, /* note modified */
+ const char *function,
+ int dlflags,
+ clixon_plugin_t **cpp)
{
int retval = -1;
char *error;
@@ -330,40 +330,40 @@ plugin_load_one(clicon_handle h,
dlerror(); /* Clear any existing error */
if ((handle = dlopen(file, dlflags)) == NULL) {
error = (char*)dlerror();
- clicon_err(OE_PLUGIN, errno, "dlopen(%s): %s", file, error ? error : "Unknown error");
- goto done;
+ clicon_err(OE_PLUGIN, errno, "dlopen(%s): %s", file, error ? error : "Unknown error");
+ goto done;
}
/* call plugin_init() if defined, eg CLIXON_PLUGIN_INIT or CLIXON_BACKEND_INIT */
if ((initfn = dlsym(handle, function)) == NULL){
- clicon_err(OE_PLUGIN, errno, "Failed to find %s when loading clixon plugin %s", CLIXON_PLUGIN_INIT, file);
- goto done;
+ clicon_err(OE_PLUGIN, errno, "Failed to find %s when loading clixon plugin %s", CLIXON_PLUGIN_INIT, file);
+ goto done;
}
if ((error = (char*)dlerror()) != NULL) {
- clicon_err(OE_UNIX, 0, "dlsym: %s: %s", file, error);
- goto done;
+ clicon_err(OE_UNIX, 0, "dlsym: %s: %s", file, error);
+ goto done;
}
clicon_err_reset();
wh = NULL;
if (plugin_context_check(h, &wh, file, __FUNCTION__) < 0)
- goto done;
+ goto done;
if ((api = initfn(h)) == NULL) {
- if (!clicon_errno){ /* if clicon_err() is not called then log and continue */
- clicon_log(LOG_DEBUG, "Warning: failed to initiate %s", strrchr(file,'/')?strchr(file, '/'):file);
- retval = 0;
- goto done;
- }
- else{
- clicon_err(OE_PLUGIN, errno, "Failed to initiate %s", strrchr(file,'/')?strchr(file, '/'):file);
- goto done;
- }
+ if (!clicon_errno){ /* if clicon_err() is not called then log and continue */
+ clicon_log(LOG_DEBUG, "Warning: failed to initiate %s", strrchr(file,'/')?strchr(file, '/'):file);
+ retval = 0;
+ goto done;
+ }
+ else{
+ clicon_err(OE_PLUGIN, errno, "Failed to initiate %s", strrchr(file,'/')?strchr(file, '/'):file);
+ goto done;
+ }
}
if (plugin_context_check(h, &wh, file, __FUNCTION__) < 0)
- goto done;
+ goto done;
/* Note: sizeof clixon_plugin_api which is largest of clixon_plugin_api:s */
if ((cp = (clixon_plugin_t *)malloc(sizeof(struct clixon_plugin))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(cp, 0, sizeof(struct clixon_plugin));
cp->cp_handle = handle;
@@ -371,24 +371,24 @@ plugin_load_one(clicon_handle h,
name = strrchr(file, '/') ? strrchr(file, '/')+1 : file;
/* strip extension, eg .so from name */
if ((p=strrchr(name, '.')) != NULL)
- *p = '\0';
+ *p = '\0';
/* Copy name to struct */
snprintf(cp->cp_name, sizeof(cp->cp_name), "%*s",
- (int)strlen(name), name);
+ (int)strlen(name), name);
cp->cp_api = *api;
if (cp){
- *cpp = cp;
- cp = NULL;
+ *cpp = cp;
+ cp = NULL;
}
retval = 1;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (wh != NULL)
- free(wh);
+ free(wh);
if (retval != 1 && handle)
- dlclose(handle);
+ dlclose(handle);
if (cp)
- free(cp);
+ free(cp);
return retval;
}
@@ -402,9 +402,9 @@ plugin_load_one(clicon_handle h,
*/
int
clixon_plugins_load(clicon_handle h,
- const char *function,
- const char *dir,
- const char *regexp)
+ const char *function,
+ const char *dir,
+ const char *regexp)
{
int retval = -1;
int ndp;
@@ -417,27 +417,27 @@ clixon_plugins_load(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (ms == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
+ goto done;
}
/* Get plugin objects names from plugin directory */
if((ndp = clicon_file_dirent(dir, &dp, regexp?regexp:"(.so)$", S_IFREG)) < 0)
- goto done;
+ goto done;
/* Load all plugins */
for (i = 0; i < ndp; i++) {
- snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dp[i].d_name);
- clicon_debug(1, "DEBUG: Loading plugin '%.*s' ...",
- (int)strlen(filename), filename);
- if ((ret = plugin_load_one(h, filename, function, RTLD_NOW, &cp)) < 0)
- goto done;
- if (ret == 0)
- continue;
- ADDQ(cp, ms->ms_plugin_list);
+ snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dp[i].d_name);
+ clicon_debug(1, "DEBUG: Loading plugin '%.*s' ...",
+ (int)strlen(filename), filename);
+ if ((ret = plugin_load_one(h, filename, function, RTLD_NOW, &cp)) < 0)
+ goto done;
+ if (ret == 0)
+ continue;
+ ADDQ(cp, ms->ms_plugin_list);
}
retval = 0;
done:
if (dp)
- free(dp);
+ free(dp);
return retval;
}
@@ -456,8 +456,8 @@ done:
*/
int
clixon_pseudo_plugin(clicon_handle h,
- const char *name,
- clixon_plugin_t **cpp)
+ const char *name,
+ clixon_plugin_t **cpp)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
@@ -465,14 +465,14 @@ clixon_pseudo_plugin(clicon_handle h,
clicon_debug(1, "%s %s", __FUNCTION__, name);
if (ms == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
+ goto done;
}
/* Create a pseudo plugins */
/* Note: sizeof clixon_plugin_api which is largest of clixon_plugin_api:s */
if ((cp = (clixon_plugin_t *)malloc(sizeof(struct clixon_plugin))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(cp, 0, sizeof(struct clixon_plugin));
snprintf(cp->cp_name, sizeof(cp->cp_name), "%*s", (int)strlen(name), name);
@@ -482,7 +482,7 @@ clixon_pseudo_plugin(clicon_handle h,
retval = 0;
done:
if (cp)
- free(cp);
+ free(cp);
return retval;
}
@@ -499,36 +499,36 @@ plugin_context_get(void)
struct plugin_context *pc = NULL;
if ((pc = malloc(sizeof(*pc))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(pc, 0, sizeof(*pc));
if (sigprocmask(0, NULL, &pc->pc_sigset) < 0){
- clicon_err(OE_UNIX, errno, "sigprocmask");
- goto done;
+ clicon_err(OE_UNIX, errno, "sigprocmask");
+ goto done;
}
for (i=1; i<32; i++){
- if (sigaction(i, NULL, &pc->pc_sigaction_vec[i]) < 0){
- clicon_err(OE_UNIX, errno, "sigaction");
- goto done;
- }
- /* Mask SA_RESTORER: Not intended for application use.
- * Note that it may not be included in user space so may be hardcoded below
- */
+ if (sigaction(i, NULL, &pc->pc_sigaction_vec[i]) < 0){
+ clicon_err(OE_UNIX, errno, "sigaction");
+ goto done;
+ }
+ /* Mask SA_RESTORER: Not intended for application use.
+ * Note that it may not be included in user space so may be hardcoded below
+ */
#ifdef SA_RESTORER
- pc->pc_sigaction_vec[i].sa_flags &= ~SA_RESTORER;
+ pc->pc_sigaction_vec[i].sa_flags &= ~SA_RESTORER;
#else
- pc->pc_sigaction_vec[i].sa_flags &= ~0x04000000;
+ pc->pc_sigaction_vec[i].sa_flags &= ~0x04000000;
#endif
}
if (isatty(0) && tcgetattr(0, &pc->pc_termios) < 0){
- clicon_err(OE_UNIX, errno, "tcgetattr %d", errno);
- goto done;
+ clicon_err(OE_UNIX, errno, "tcgetattr %d", errno);
+ goto done;
}
return pc;
done:
if (pc)
- free(pc);
+ free(pc);
return NULL;
}
@@ -557,9 +557,9 @@ plugin_context_get(void)
*/
int
plugin_context_check(clicon_handle h,
- void **wh,
- const char *name,
- const char *fn)
+ void **wh,
+ const char *name,
+ const char *fn)
{
int retval = -1;
int failed = 0;
@@ -569,95 +569,95 @@ plugin_context_check(clicon_handle h,
int option;
if (h == NULL){
- errno = EINVAL;
- return -1;
+ errno = EINVAL;
+ return -1;
}
option = clicon_option_int(h, "CLICON_PLUGIN_CALLBACK_CHECK");
/* Check if plugion checks are enabled */
if (option == 0)
- return 1;
+ return 1;
if (wh == NULL){
- errno = EINVAL;
- return -1;
+ errno = EINVAL;
+ return -1;
}
if (*wh == NULL){
- *wh = plugin_context_get();
- return 1;
+ *wh = plugin_context_get();
+ return 1;
}
oldpc = (struct plugin_context *)*wh;
if ((newpc = plugin_context_get()) == NULL)
- goto done;
+ goto done;
if (oldpc->pc_termios.c_iflag != newpc->pc_termios.c_iflag){
- clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios input modes from 0x%x to 0x%x", __FUNCTION__,
- name, fn,
- oldpc->pc_termios.c_iflag,
- newpc->pc_termios.c_iflag);
- failed++;
+ clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios input modes from 0x%x to 0x%x", __FUNCTION__,
+ name, fn,
+ oldpc->pc_termios.c_iflag,
+ newpc->pc_termios.c_iflag);
+ failed++;
}
if (oldpc->pc_termios.c_oflag != newpc->pc_termios.c_oflag){
- clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios output modes from 0x%x to 0x%x", __FUNCTION__,
- name, fn,
- oldpc->pc_termios.c_oflag,
- newpc->pc_termios.c_oflag);
- failed++;
+ clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios output modes from 0x%x to 0x%x", __FUNCTION__,
+ name, fn,
+ oldpc->pc_termios.c_oflag,
+ newpc->pc_termios.c_oflag);
+ failed++;
}
if (oldpc->pc_termios.c_cflag != newpc->pc_termios.c_cflag){
- clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios control modes from 0x%x to 0x%x", __FUNCTION__,
- name, fn,
- oldpc->pc_termios.c_cflag,
- newpc->pc_termios.c_cflag);
- failed++;
+ clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios control modes from 0x%x to 0x%x", __FUNCTION__,
+ name, fn,
+ oldpc->pc_termios.c_cflag,
+ newpc->pc_termios.c_cflag);
+ failed++;
}
if (oldpc->pc_termios.c_lflag != newpc->pc_termios.c_lflag){
- clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios local modes from 0x%x to 0x%x", __FUNCTION__,
- name, fn,
- oldpc->pc_termios.c_lflag,
- newpc->pc_termios.c_lflag);
- failed++;
+ clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios local modes from 0x%x to 0x%x", __FUNCTION__,
+ name, fn,
+ oldpc->pc_termios.c_lflag,
+ newpc->pc_termios.c_lflag);
+ failed++;
}
/* XXX pc_termios.cc_t c_cc[NCCS] not checked */
/* Abort if option is 2 or above on failure
*/
if (option > 1 && failed)
- abort();
+ abort();
for (i=1; i<32; i++){
- if (sigismember(&oldpc->pc_sigset, i) != sigismember(&newpc->pc_sigset, i)){
- clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed blocking of signal %s(%d) from %d to %d", __FUNCTION__,
- name, fn, strsignal(i), i,
- sigismember(&oldpc->pc_sigset, i),
- sigismember(&newpc->pc_sigset, i)
- );
- failed++;
- }
- if (oldpc->pc_sigaction_vec[i].sa_flags != newpc->pc_sigaction_vec[i].sa_flags){
- clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed flags of signal %s(%d) from 0x%x to 0x%x", __FUNCTION__,
- name, fn, strsignal(i), i,
- oldpc->pc_sigaction_vec[i].sa_flags,
- newpc->pc_sigaction_vec[i].sa_flags);;
- failed++;
- }
- if (oldpc->pc_sigaction_vec[i].sa_sigaction != newpc->pc_sigaction_vec[i].sa_sigaction){
- clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed action of signal %s(%d) from %p to %p", __FUNCTION__,
- name, fn, strsignal(i), i,
- oldpc->pc_sigaction_vec[i].sa_sigaction,
- newpc->pc_sigaction_vec[i].sa_sigaction);
- failed++;
- }
- /* Abort if option is 2 or above on failure
- */
- if (option > 1 && failed)
- abort();
+ if (sigismember(&oldpc->pc_sigset, i) != sigismember(&newpc->pc_sigset, i)){
+ clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed blocking of signal %s(%d) from %d to %d", __FUNCTION__,
+ name, fn, strsignal(i), i,
+ sigismember(&oldpc->pc_sigset, i),
+ sigismember(&newpc->pc_sigset, i)
+ );
+ failed++;
+ }
+ if (oldpc->pc_sigaction_vec[i].sa_flags != newpc->pc_sigaction_vec[i].sa_flags){
+ clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed flags of signal %s(%d) from 0x%x to 0x%x", __FUNCTION__,
+ name, fn, strsignal(i), i,
+ oldpc->pc_sigaction_vec[i].sa_flags,
+ newpc->pc_sigaction_vec[i].sa_flags);;
+ failed++;
+ }
+ if (oldpc->pc_sigaction_vec[i].sa_sigaction != newpc->pc_sigaction_vec[i].sa_sigaction){
+ clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed action of signal %s(%d) from %p to %p", __FUNCTION__,
+ name, fn, strsignal(i), i,
+ oldpc->pc_sigaction_vec[i].sa_sigaction,
+ newpc->pc_sigaction_vec[i].sa_sigaction);
+ failed++;
+ }
+ /* Abort if option is 2 or above on failure
+ */
+ if (option > 1 && failed)
+ abort();
}
if (failed)
- goto fail;
+ goto fail;
retval = 1; /* OK */
done:
if (newpc)
- free(newpc);
+ free(newpc);
if (oldpc)
- free(oldpc);
+ free(oldpc);
if (wh && *wh)
- *wh = NULL;
+ *wh = NULL;
return retval;
fail:
retval = 0;
@@ -672,24 +672,24 @@ plugin_context_check(clicon_handle h,
*/
int
clixon_plugin_start_one(clixon_plugin_t *cp,
- clicon_handle h)
+ clicon_handle h)
{
int retval = -1;
plgstart_t *fn; /* Plugin start */
void *wh = NULL;
if ((fn = cp->cp_api.ca_start) != NULL){
- wh = NULL;
- if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
- goto done;
- if (fn(h) < 0) {
- if (clicon_errno < 0)
- clicon_log(LOG_WARNING, "%s: Internal error: Start callback in plugin: %s returned -1 but did not make a clicon_err call",
- __FUNCTION__, cp->cp_name);
- goto done;
- }
- if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
- goto done;
+ wh = NULL;
+ if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
+ goto done;
+ if (fn(h) < 0) {
+ if (clicon_errno < 0)
+ clicon_log(LOG_WARNING, "%s: Internal error: Start callback in plugin: %s returned -1 but did not make a clicon_err call",
+ __FUNCTION__, cp->cp_name);
+ goto done;
+ }
+ if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
+ goto done;
}
retval = 0;
done:
@@ -708,8 +708,8 @@ clixon_plugin_start_all(clicon_handle h)
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
- if (clixon_plugin_start_one(cp, h) < 0)
- goto done;
+ if (clixon_plugin_start_one(cp, h) < 0)
+ goto done;
}
retval = 0;
done:
@@ -725,29 +725,29 @@ clixon_plugin_start_all(clicon_handle h)
*/
static int
clixon_plugin_exit_one(clixon_plugin_t *cp,
- clicon_handle h)
+ clicon_handle h)
{
int retval = -1;
char *error;
plgexit_t *fn;
void *wh = NULL;
-
+
if ((fn = cp->cp_api.ca_exit) != NULL){
- wh = NULL;
- if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
- goto done;
- if (fn(h) < 0) {
- if (clicon_errno < 0)
- clicon_log(LOG_WARNING, "%s: Internal error: Exit callback in plugin: %s returned -1 but did not make a clicon_err call",
- __FUNCTION__, cp->cp_name);
- goto done;
- }
- if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
- goto done;
- if (dlclose(cp->cp_handle) != 0) {
- error = (char*)dlerror();
- clicon_err(OE_PLUGIN, errno, "dlclose: %s", error ? error : "Unknown error");
- }
+ wh = NULL;
+ if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
+ goto done;
+ if (fn(h) < 0) {
+ if (clicon_errno < 0)
+ clicon_log(LOG_WARNING, "%s: Internal error: Exit callback in plugin: %s returned -1 but did not make a clicon_err call",
+ __FUNCTION__, cp->cp_name);
+ goto done;
+ }
+ if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
+ goto done;
+ if (dlclose(cp->cp_handle) != 0) {
+ error = (char*)dlerror();
+ clicon_err(OE_PLUGIN, errno, "dlclose: %s", error ? error : "Unknown error");
+ }
}
retval = 0;
done:
@@ -767,12 +767,12 @@ clixon_plugin_exit_all(clicon_handle h)
plugin_module_struct *ms = plugin_module_struct_get(h);
if (ms != NULL){
- while ((cp = ms->ms_plugin_list) != NULL){
- DELQ(cp, ms->ms_plugin_list, clixon_plugin_t *);
- if (clixon_plugin_exit_one(cp, h) < 0)
- goto done;
- free(cp);
- }
+ while ((cp = ms->ms_plugin_list) != NULL){
+ DELQ(cp, ms->ms_plugin_list, clixon_plugin_t *);
+ if (clixon_plugin_exit_one(cp, h) < 0)
+ goto done;
+ free(cp);
+ }
}
retval = 0;
done:
@@ -794,10 +794,10 @@ clixon_plugin_exit_all(clicon_handle h)
*/
static int
clixon_plugin_auth_one(clixon_plugin_t *cp,
- clicon_handle h,
- void *req,
- clixon_auth_type_t auth_type,
- char **authp)
+ clicon_handle h,
+ void *req,
+ clixon_auth_type_t auth_type,
+ char **authp)
{
int retval = -1;
plgauth_t *fn; /* Plugin auth */
@@ -805,20 +805,20 @@ clixon_plugin_auth_one(clixon_plugin_t *cp,
clicon_debug(1, "%s", __FUNCTION__);
if ((fn = cp->cp_api.ca_auth) != NULL){
- wh = NULL;
- if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
- goto done;
- if ((retval = fn(h, req, auth_type, authp)) < 0) {
- if (clicon_errno < 0)
- clicon_log(LOG_WARNING, "%s: Internal error: Auth callback in plugin: %s returned -1 but did not make a clicon_err call",
- __FUNCTION__, cp->cp_name);
- goto done;
- }
- if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
- goto done;
+ wh = NULL;
+ if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
+ goto done;
+ if ((retval = fn(h, req, auth_type, authp)) < 0) {
+ if (clicon_errno < 0)
+ clicon_log(LOG_WARNING, "%s: Internal error: Auth callback in plugin: %s returned -1 but did not make a clicon_err call",
+ __FUNCTION__, cp->cp_name);
+ goto done;
+ }
+ if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
+ goto done;
}
else
- retval = 0; /* Ignored / no callback */
+ retval = 0; /* Ignored / no callback */
done:
clicon_debug(1, "%s retval:%d auth:%s", __FUNCTION__, retval, *authp);
return retval;
@@ -840,9 +840,9 @@ clixon_plugin_auth_one(clixon_plugin_t *cp,
*/
int
clixon_plugin_auth_all(clicon_handle h,
- void *req,
- clixon_auth_type_t auth_type,
- char **authp)
+ void *req,
+ clixon_auth_type_t auth_type,
+ char **authp)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
@@ -850,17 +850,17 @@ clixon_plugin_auth_all(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (authp == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL");
+ goto done;
}
*authp = NULL;
ret = 0; /* ignore */
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
- if ((ret = clixon_plugin_auth_one(cp, h, req, auth_type, authp)) < 0)
- goto done;
- if (ret == 1)
- break; /* result, not ignored */
- /* ret == 0, ignore try next */
+ if ((ret = clixon_plugin_auth_one(cp, h, req, auth_type, authp)) < 0)
+ goto done;
+ if (ret == 1)
+ break; /* result, not ignored */
+ /* ret == 0, ignore try next */
}
retval = ret;
done:
@@ -879,26 +879,26 @@ clixon_plugin_auth_all(clicon_handle h,
*/
int
clixon_plugin_extension_one(clixon_plugin_t *cp,
- clicon_handle h,
- yang_stmt *yext,
- yang_stmt *ys)
+ clicon_handle h,
+ yang_stmt *yext,
+ yang_stmt *ys)
{
int retval = 1;
plgextension_t *fn; /* Plugin extension fn */
void *wh = NULL;
if ((fn = cp->cp_api.ca_extension) != NULL){
- wh = NULL;
- if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
- goto done;
- if (fn(h, yext, ys) < 0) {
- if (clicon_errno < 0)
- clicon_log(LOG_WARNING, "%s: Internal error: Extension callback in plugin: %s returned -1 but did not make a clicon_err call",
- __FUNCTION__, cp->cp_name);
- goto done;
- }
- if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
- goto done;
+ wh = NULL;
+ if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
+ goto done;
+ if (fn(h, yext, ys) < 0) {
+ if (clicon_errno < 0)
+ clicon_log(LOG_WARNING, "%s: Internal error: Extension callback in plugin: %s returned -1 but did not make a clicon_err call",
+ __FUNCTION__, cp->cp_name);
+ goto done;
+ }
+ if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
+ goto done;
}
retval = 0;
done:
@@ -919,15 +919,15 @@ clixon_plugin_extension_one(clixon_plugin_t *cp,
*/
int
clixon_plugin_extension_all(clicon_handle h,
- yang_stmt *yext,
- yang_stmt *ys)
+ yang_stmt *yext,
+ yang_stmt *ys)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
- if (clixon_plugin_extension_one(cp, h, yext, ys) < 0)
- goto done;
+ if (clixon_plugin_extension_one(cp, h, yext, ys) < 0)
+ goto done;
}
retval = 0;
done:
@@ -947,10 +947,10 @@ clixon_plugin_extension_all(clicon_handle h,
*/
int
clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp,
- clicon_handle h,
- const char *db,
- cxobj *xt,
- modstate_diff_t *msd)
+ clicon_handle h,
+ const char *db,
+ cxobj *xt,
+ modstate_diff_t *msd)
{
int retval = -1;
@@ -958,17 +958,17 @@ clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp,
void *wh = NULL;
if ((fn = cp->cp_api.ca_datastore_upgrade) != NULL){
- wh = NULL;
- if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
- goto done;
- if (fn(h, db, xt, msd) < 0) {
- if (clicon_errno < 0)
- clicon_log(LOG_WARNING, "%s: Internal error: Datastore upgrade callback in plugin: %s returned -1 but did not make a clicon_err call",
- __FUNCTION__, cp->cp_name);
- goto done;
- }
- if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
- goto done;
+ wh = NULL;
+ if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
+ goto done;
+ if (fn(h, db, xt, msd) < 0) {
+ if (clicon_errno < 0)
+ clicon_log(LOG_WARNING, "%s: Internal error: Datastore upgrade callback in plugin: %s returned -1 but did not make a clicon_err call",
+ __FUNCTION__, cp->cp_name);
+ goto done;
+ }
+ if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
+ goto done;
}
retval = 0;
done:
@@ -987,16 +987,16 @@ clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp,
*/
int
clixon_plugin_datastore_upgrade_all(clicon_handle h,
- const char *db,
- cxobj *xt,
- modstate_diff_t *msd)
+ const char *db,
+ cxobj *xt,
+ modstate_diff_t *msd)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
- if (clixon_plugin_datastore_upgrade_one(cp, h, db, xt, msd) < 0)
- goto done;
+ if (clixon_plugin_datastore_upgrade_one(cp, h, db, xt, msd) < 0)
+ goto done;
}
retval = 0;
done:
@@ -1016,10 +1016,10 @@ rpc_callback_dump(clicon_handle h)
clicon_debug(1, "%s--------------", __FUNCTION__);
if ((rc = ms->ms_rpc_callbacks) != NULL)
- do {
- clicon_debug(1, "%s %s", __FUNCTION__, rc->rc_name);
- rc = NEXTQ(rpc_callback_t *, rc);
- } while (rc != ms->ms_rpc_callbacks);
+ do {
+ clicon_debug(1, "%s %s", __FUNCTION__, rc->rc_name);
+ rc = NEXTQ(rpc_callback_t *, rc);
+ } while (rc != ms->ms_rpc_callbacks);
return 0;
}
#endif
@@ -1037,26 +1037,26 @@ rpc_callback_dump(clicon_handle h)
*/
int
rpc_callback_register(clicon_handle h,
- clicon_rpc_cb cb,
- void *arg,
- const char *ns,
- const char *name)
+ clicon_rpc_cb cb,
+ void *arg,
+ const char *ns,
+ const char *name)
{
rpc_callback_t *rc = NULL;
plugin_module_struct *ms = plugin_module_struct_get(h);
clicon_debug(1, "%s %s", __FUNCTION__, name);
if (ms == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
+ goto done;
}
if (name == NULL || ns == NULL){
- clicon_err(OE_DB, EINVAL, "name or namespace NULL");
- goto done;
+ clicon_err(OE_DB, EINVAL, "name or namespace NULL");
+ goto done;
}
if ((rc = malloc(sizeof(rpc_callback_t))) == NULL) {
- clicon_err(OE_DB, errno, "malloc");
- goto done;
+ clicon_err(OE_DB, errno, "malloc");
+ goto done;
}
memset(rc, 0, sizeof(*rc));
rc->rc_callback = cb;
@@ -1067,11 +1067,11 @@ rpc_callback_register(clicon_handle h,
return 0;
done:
if (rc){
- if (rc->rc_namespace)
- free(rc->rc_namespace);
- if (rc->rc_name)
- free(rc->rc_name);
- free(rc);
+ if (rc->rc_namespace)
+ free(rc->rc_namespace);
+ if (rc->rc_name)
+ free(rc->rc_name);
+ free(rc);
}
return -1;
}
@@ -1085,14 +1085,14 @@ rpc_callback_delete_all(clicon_handle h)
plugin_module_struct *ms = plugin_module_struct_get(h);
if (ms != NULL)
- while((rc = ms->ms_rpc_callbacks) != NULL) {
- DELQ(rc, ms->ms_rpc_callbacks, rpc_callback_t *);
- if (rc->rc_namespace)
- free(rc->rc_namespace);
- if (rc->rc_name)
- free(rc->rc_name);
- free(rc);
- }
+ while((rc = ms->ms_rpc_callbacks) != NULL) {
+ DELQ(rc, ms->ms_rpc_callbacks, rpc_callback_t *);
+ if (rc->rc_namespace)
+ free(rc->rc_namespace);
+ if (rc->rc_name)
+ free(rc->rc_name);
+ free(rc);
+ }
return 0;
}
@@ -1113,10 +1113,10 @@ rpc_callback_delete_all(clicon_handle h)
*/
int
rpc_callback_call(clicon_handle h,
- cxobj *xe,
- void *arg,
- int *nrp,
- cbuf *cbret)
+ cxobj *xe,
+ void *arg,
+ int *nrp,
+ cbuf *cbret)
{
int retval = -1;
rpc_callback_t *rc;
@@ -1129,41 +1129,41 @@ rpc_callback_call(clicon_handle h,
int ret;
if (ms == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
+ goto done;
}
name = xml_name(xe);
prefix = xml_prefix(xe);
xml2ns(xe, prefix, &ns);
if ((rc = ms->ms_rpc_callbacks) != NULL)
- do {
- if (strcmp(rc->rc_name, name) == 0 &&
- ns && rc->rc_namespace &&
- strcmp(rc->rc_namespace, ns) == 0){
- wh = NULL;
- if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0)
- goto done;
- if (rc->rc_callback(h, xe, cbret, arg, rc->rc_arg) < 0){
- clicon_debug(1, "%s Error in: %s", __FUNCTION__, rc->rc_name);
- if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0)
- goto done;
- goto done;
- }
- nr++;
- if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0)
- goto done;
- }
- rc = NEXTQ(rpc_callback_t *, rc);
- } while (rc != ms->ms_rpc_callbacks);
+ do {
+ if (strcmp(rc->rc_name, name) == 0 &&
+ ns && rc->rc_namespace &&
+ strcmp(rc->rc_namespace, ns) == 0){
+ wh = NULL;
+ if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0)
+ goto done;
+ if (rc->rc_callback(h, xe, cbret, arg, rc->rc_arg) < 0){
+ clicon_debug(1, "%s Error in: %s", __FUNCTION__, rc->rc_name);
+ if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0)
+ goto done;
+ goto done;
+ }
+ nr++;
+ if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0)
+ goto done;
+ }
+ rc = NEXTQ(rpc_callback_t *, rc);
+ } while (rc != ms->ms_rpc_callbacks);
/* action reply checked in action_callback_call */
if (nr && !xml_rpc_isaction(xe)){
- if ((ret = rpc_reply_check(h, name, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = rpc_reply_check(h, name, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
if (nrp)
- *nrp = nr;
+ *nrp = nr;
retval = 1; /* 0: none found, >0 nr of handlers called */
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
@@ -1189,9 +1189,9 @@ rpc_callback_call(clicon_handle h,
*/
int
action_callback_register(clicon_handle h,
- yang_stmt *ya,
- clicon_rpc_cb cb,
- void *arg)
+ yang_stmt *ya,
+ clicon_rpc_cb cb,
+ void *arg)
{
int retval = -1;
rpc_callback_t *rc = NULL;
@@ -1199,13 +1199,13 @@ action_callback_register(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (ya == NULL){
- clicon_err(OE_DB, EINVAL, "yang node is NULL");
- goto done;
+ clicon_err(OE_DB, EINVAL, "yang node is NULL");
+ goto done;
}
name = yang_argument_get(ya);
if ((rc = malloc(sizeof(rpc_callback_t))) == NULL) {
- clicon_err(OE_DB, errno, "malloc");
- goto done;
+ clicon_err(OE_DB, errno, "malloc");
+ goto done;
}
memset(rc, 0, sizeof(*rc));
rc->rc_callback = cb;
@@ -1213,7 +1213,7 @@ action_callback_register(clicon_handle h,
rc->rc_namespace = strdup(YANG_XML_NAMESPACE); // XXX
rc->rc_name = strdup(name);
if (yang_action_cb_add(ya, rc) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -1236,10 +1236,10 @@ action_callback_register(clicon_handle h,
*/
int
action_callback_call(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
cxobj *xa = NULL;
@@ -1251,43 +1251,43 @@ action_callback_call(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (xml_find_action(xe, 1, &xa) < 0)
- goto done;
+ goto done;
if (xa == NULL){
- if (netconf_operation_not_supported(cbret, "application", "Action not found") < 0)
- goto done;
- goto ok;
+ if (netconf_operation_not_supported(cbret, "application", "Action not found") < 0)
+ goto done;
+ goto ok;
}
if ((ya = xml_spec(xa)) == NULL){
- if (netconf_operation_not_supported(cbret, "application", "Action spec not found") < 0)
- goto done;
- goto ok;
+ if (netconf_operation_not_supported(cbret, "application", "Action spec not found") < 0)
+ goto done;
+ goto ok;
}
name = xml_name(xa);
/* Action callback */
if ((rc = (rpc_callback_t *)yang_action_cb_get(ya)) != NULL){
- do {
- if (strcmp(rc->rc_name, name) == 0){
- if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0)
- goto done;
- if (rc->rc_callback(h, xa, cbret, arg, rc->rc_arg) < 0){
- clicon_debug(1, "%s Error in: %s", __FUNCTION__, rc->rc_name);
- if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0)
- goto done;
- goto done;
- }
- nr++;
- if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0)
- goto done;
- }
- rc = NEXTQ(rpc_callback_t *, rc);
- } while (rc != yang_action_cb_get(ya));
+ do {
+ if (strcmp(rc->rc_name, name) == 0){
+ if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0)
+ goto done;
+ if (rc->rc_callback(h, xa, cbret, arg, rc->rc_arg) < 0){
+ clicon_debug(1, "%s Error in: %s", __FUNCTION__, rc->rc_name);
+ if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0)
+ goto done;
+ goto done;
+ }
+ nr++;
+ if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0)
+ goto done;
+ }
+ rc = NEXTQ(rpc_callback_t *, rc);
+ } while (rc != yang_action_cb_get(ya));
}
if (nr){
#ifdef NYI
- if ((ret = rpc_action_reply_check(h, xe, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = rpc_action_reply_check(h, xe, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
#endif
}
ok:
@@ -1313,35 +1313,35 @@ action_callback_call(clicon_handle h,
*/
int
upgrade_callback_reg_fn(clicon_handle h,
- clicon_upgrade_cb cb,
- const char *fnstr,
- const char *ns,
- void *arg)
+ clicon_upgrade_cb cb,
+ const char *fnstr,
+ const char *ns,
+ void *arg)
{
upgrade_callback_t *uc = NULL;
plugin_module_struct *ms = plugin_module_struct_get(h);
if (ms == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
+ goto done;
}
if ((uc = malloc(sizeof(upgrade_callback_t))) == NULL) {
- clicon_err(OE_DB, errno, "malloc");
- goto done;
+ clicon_err(OE_DB, errno, "malloc");
+ goto done;
}
memset(uc, 0, sizeof(*uc));
uc->uc_callback = cb;
uc->uc_fnstr = fnstr;
uc->uc_arg = arg;
if (ns)
- uc->uc_namespace = strdup(ns);
+ uc->uc_namespace = strdup(ns);
ADDQ(uc, ms->ms_upgrade_callbacks);
return 0;
done:
if (uc){
- if (uc->uc_namespace)
- free(uc->uc_namespace);
- free(uc);
+ if (uc->uc_namespace)
+ free(uc->uc_namespace);
+ free(uc);
}
return -1;
}
@@ -1355,12 +1355,12 @@ upgrade_callback_delete_all(clicon_handle h)
plugin_module_struct *ms = plugin_module_struct_get(h);
if (ms != NULL)
- while((uc = ms->ms_upgrade_callbacks) != NULL) {
- DELQ(uc, ms->ms_upgrade_callbacks, upgrade_callback_t *);
- if (uc->uc_namespace)
- free(uc->uc_namespace);
- free(uc);
- }
+ while((uc = ms->ms_upgrade_callbacks) != NULL) {
+ DELQ(uc, ms->ms_upgrade_callbacks, upgrade_callback_t *);
+ if (uc->uc_namespace)
+ free(uc->uc_namespace);
+ free(uc);
+ }
return 0;
}
@@ -1380,12 +1380,12 @@ upgrade_callback_delete_all(clicon_handle h)
*/
int
upgrade_callback_call(clicon_handle h,
- cxobj *xt,
- char *ns,
- uint16_t op,
- uint32_t from,
- uint32_t to,
- cbuf *cbret)
+ cxobj *xt,
+ char *ns,
+ uint16_t op,
+ uint32_t from,
+ uint32_t to,
+ cbuf *cbret)
{
int retval = -1;
upgrade_callback_t *uc;
@@ -1394,36 +1394,36 @@ upgrade_callback_call(clicon_handle h,
plugin_module_struct *ms = plugin_module_struct_get(h);
if (ms == NULL){
- clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
- goto done;
+ clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
+ goto done;
}
if ((uc = ms->ms_upgrade_callbacks) != NULL)
- do {
- /* For matching an upgrade callback:
- * - No module name registered (matches all modules) OR
- * - Names match
- * AND
- * - No registered from revision (matches all revisions) OR
- * - Registered from revision >= from AND
- * - Registered to revision <= to (which includes case both 0)
- */
- if (uc->uc_namespace == NULL || strcmp(uc->uc_namespace, ns)==0){
- if ((ret = uc->uc_callback(h, xt, ns, op, from, to, uc->uc_arg, cbret)) < 0){
- clicon_debug(1, "%s Error in: %s", __FUNCTION__, uc->uc_namespace);
- goto done;
- }
- if (ret == 0){
- if (cbuf_len(cbret)==0){
- clicon_err(OE_CFG, 0, "Validation fail %s(%s): cbret not set",
- uc->uc_fnstr, ns);
- goto done;
- }
- goto fail;
- }
- nr++;
- }
- uc = NEXTQ(upgrade_callback_t *, uc);
- } while (uc != ms->ms_upgrade_callbacks);
+ do {
+ /* For matching an upgrade callback:
+ * - No module name registered (matches all modules) OR
+ * - Names match
+ * AND
+ * - No registered from revision (matches all revisions) OR
+ * - Registered from revision >= from AND
+ * - Registered to revision <= to (which includes case both 0)
+ */
+ if (uc->uc_namespace == NULL || strcmp(uc->uc_namespace, ns)==0){
+ if ((ret = uc->uc_callback(h, xt, ns, op, from, to, uc->uc_arg, cbret)) < 0){
+ clicon_debug(1, "%s Error in: %s", __FUNCTION__, uc->uc_namespace);
+ goto done;
+ }
+ if (ret == 0){
+ if (cbuf_len(cbret)==0){
+ clicon_err(OE_CFG, 0, "Validation fail %s(%s): cbret not set",
+ uc->uc_fnstr, ns);
+ goto done;
+ }
+ goto fail;
+ }
+ nr++;
+ }
+ uc = NEXTQ(upgrade_callback_t *, uc);
+ } while (uc != ms->ms_upgrade_callbacks);
retval = 1;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
@@ -1472,16 +1472,16 @@ clixon_plugin_module_init(clicon_handle h)
struct plugin_module_struct *ph;
if (plugin_module_struct_get(h) != NULL){
- clicon_err(OE_PLUGIN, EFAULT, "Already initialized");
- goto done;
+ clicon_err(OE_PLUGIN, EFAULT, "Already initialized");
+ goto done;
}
if ((ph = malloc(sizeof(*ph))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(ph, 0, sizeof(*ph));
if (plugin_module_struct_set(h, ph) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -1504,8 +1504,8 @@ clixon_plugin_module_exit(clicon_handle h)
upgrade_callback_delete_all(h);
/* Delete plugin_module itself */
if ((ph = plugin_module_struct_get(h)) != NULL){
- free(ph);
- plugin_module_struct_set(h, NULL);
+ free(ph);
+ plugin_module_struct_set(h, NULL);
}
return 0;
}
diff --git a/lib/src/clixon_proc.c b/lib/src/clixon_proc.c
index c789fe14..b26ae094 100644
--- a/lib/src/clixon_proc.c
+++ b/lib/src/clixon_proc.c
@@ -59,12 +59,12 @@
2. It is stopped due to a rpc or configuration remove:
The parent kills the process and enters EXITING waiting for a SIGCHLD that triggers a wait,
- therafter it goes to STOPPED
+ therafter it goes to STOPPED
RUNNING --stop--> EXITING --sigchld/wait--> STOPPED
3. It is restarted due to rpc or config change (eg a server is added, a key modified, etc).
The parent kills the process and enters EXITING waiting for a SIGCHLD that triggers a wait,
- therafter a new process is started and it goes to RUNNING with a new pid
+ therafter a new process is started and it goes to RUNNING with a new pid
RUNNING --restart--> EXITING --sigchld/wait + restart --> RUNNING(pid)
@@ -72,7 +72,7 @@
STOPPED --(re)start--> RUNNING(pid)
^ <--1.wait(kill)--- | ^
- | stop/| |
+ | stop/| |
| restart| | restart
| v |
wait(stop) ------- EXITING(dying pid) <----> kill after timeout
@@ -172,8 +172,8 @@ clixon_proc_sigint(int sig)
*/
int
clixon_proc_socket(char **argv,
- pid_t *pid,
- int *sock)
+ pid_t *pid,
+ int *sock)
{
int retval = -1;
int sp[2] = {-1, -1};
@@ -189,23 +189,23 @@ clixon_proc_socket(char **argv,
#endif
if (argv == NULL){
- clicon_err(OE_UNIX, EINVAL, "argv is NULL");
- goto done;
+ clicon_err(OE_UNIX, EINVAL, "argv is NULL");
+ goto done;
}
if (socketpair(AF_UNIX, sock_flags, 0, sp) < 0){
- clicon_err(OE_UNIX, errno, "socketpair");
- goto done;
+ clicon_err(OE_UNIX, errno, "socketpair");
+ goto done;
}
#ifdef __APPLE__
if (fcntl(sp[0], O_CLOEXEC)) {
- clicon_err(OE_UNIX, errno, "fcntl, sp[0]");
- goto done;
+ clicon_err(OE_UNIX, errno, "fcntl, sp[0]");
+ goto done;
}
if (fcntl(sp[1], O_CLOEXEC)) {
- clicon_err(OE_UNIX, errno, "fcntl, sp[1]");
- goto done;
+ clicon_err(OE_UNIX, errno, "fcntl, sp[1]");
+ goto done;
}
#endif
@@ -213,32 +213,32 @@ clixon_proc_socket(char **argv,
set_signal(SIGINT, clixon_proc_sigint, &oldhandler);
sig++;
if ((child = fork()) < 0) {
- clicon_err(OE_UNIX, errno, "fork");
- goto done;
+ clicon_err(OE_UNIX, errno, "fork");
+ goto done;
}
- if (child == 0) { /* Child */
- /* Unblock all signals except TSTP */
- clicon_signal_unblock(0);
- signal(SIGTSTP, SIG_IGN);
+ if (child == 0) { /* Child */
+ /* Unblock all signals except TSTP */
+ clicon_signal_unblock(0);
+ signal(SIGTSTP, SIG_IGN);
- close(sp[0]);
- close(0);
- if (dup2(sp[1], STDIN_FILENO) < 0){
- perror("dup2");
- return -1;
- }
- close(1);
- if (dup2(sp[1], STDOUT_FILENO) < 0){
- perror("dup2");
- return -1;
- }
- close(sp[1]);
-
- if (execvp(argv[0], argv) < 0){
- perror("execvp");
- return -1;
- }
- exit(-1); /* Shouldnt reach here */
+ close(sp[0]);
+ close(0);
+ if (dup2(sp[1], STDIN_FILENO) < 0){
+ perror("dup2");
+ return -1;
+ }
+ close(1);
+ if (dup2(sp[1], STDOUT_FILENO) < 0){
+ perror("dup2");
+ return -1;
+ }
+ close(sp[1]);
+
+ if (execvp(argv[0], argv) < 0){
+ perror("execvp");
+ return -1;
+ }
+ exit(-1); /* Shouldnt reach here */
}
/* Parent */
close(sp[1]);
@@ -246,9 +246,9 @@ clixon_proc_socket(char **argv,
*sock = sp[0];
retval = 0;
done:
- if (sig){ /* Restore sigmask and fn */
- sigprocmask(SIG_SETMASK, &oset, NULL);
- set_signal(SIGINT, oldhandler, NULL);
+ if (sig){ /* Restore sigmask and fn */
+ sigprocmask(SIG_SETMASK, &oset, NULL);
+ set_signal(SIGINT, oldhandler, NULL);
}
return retval;
}
@@ -258,17 +258,17 @@ clixon_proc_socket(char **argv,
*/
int
clixon_proc_socket_close(pid_t pid,
- int sock)
+ int sock)
{
int retval = -1;
int status;
if (sock != -1)
- close(sock); /* usually kills */
+ close(sock); /* usually kills */
kill(pid, SIGTERM);
// usleep(100000); /* Wait for child to finish */
if(waitpid(pid, &status, 0) == pid)
- retval = WEXITSTATUS(status);
+ retval = WEXITSTATUS(status);
return retval;
}
@@ -282,8 +282,8 @@ clixon_proc_socket_close(pid_t pid,
*/
int
clixon_proc_background(char **argv,
- const char *netns,
- pid_t *pid0)
+ const char *netns,
+ pid_t *pid0)
{
int retval = -1;
pid_t child = 0;
@@ -295,74 +295,74 @@ clixon_proc_background(char **argv,
clicon_debug(1, "%s", __FUNCTION__);
if (argv == NULL){
- clicon_err(OE_UNIX, EINVAL, "argv is NULL");
- goto quit;
+ clicon_err(OE_UNIX, EINVAL, "argv is NULL");
+ goto quit;
}
if (clicon_debug_get()){
- i = 0;
- while (argv[i]){
- clicon_debug(1, "%s argv[%d]:%s", __FUNCTION__, i, argv[i]);
- i++;
- }
+ i = 0;
+ while (argv[i]){
+ clicon_debug(1, "%s argv[%d]:%s", __FUNCTION__, i, argv[i]);
+ i++;
+ }
}
/* Sanity check: program exists */
if (stat(argv[0], &fstat) < 0) {
- clicon_err(OE_FATAL, errno, "%s", argv[0]);
- goto quit;
+ clicon_err(OE_FATAL, errno, "%s", argv[0]);
+ goto quit;
}
/* Before here call quit on error */
sigprocmask(0, NULL, &oset);
set_signal(SIGINT, clixon_proc_sigint, &oldhandler);
/* Now call done on error */
if ((child = fork()) < 0) {
- clicon_err(OE_UNIX, errno, "fork");
- goto done;
+ clicon_err(OE_UNIX, errno, "fork");
+ goto done;
}
if (child == 0) { /* Child */
#ifdef HAVE_SETNS
char nsfile[PATH_MAX];
- int nsfd;
+ int nsfd;
#endif
- clicon_debug(1, "%s child", __FUNCTION__);
- clicon_signal_unblock(0);
- signal(SIGTSTP, SIG_IGN);
- if (chdir("/") < 0){
- clicon_err(OE_UNIX, errno, "chdirq");
- exit(1);
- }
- /* Close open descriptors */
- if ( ! getrlimit(RLIMIT_NOFILE, &rlim))
- for (i = 0; i < rlim.rlim_cur; i++)
- close(i);
+ clicon_debug(1, "%s child", __FUNCTION__);
+ clicon_signal_unblock(0);
+ signal(SIGTSTP, SIG_IGN);
+ if (chdir("/") < 0){
+ clicon_err(OE_UNIX, errno, "chdirq");
+ exit(1);
+ }
+ /* Close open descriptors */
+ if ( ! getrlimit(RLIMIT_NOFILE, &rlim))
+ for (i = 0; i < rlim.rlim_cur; i++)
+ close(i);
#ifdef HAVE_SETNS /* linux network namespaces */
- /* If network namespace is defined, let child join it
- * XXX: this is work-in-progress
- */
- if (netns != NULL) {
- snprintf(nsfile, PATH_MAX, "/var/run/netns/%s", netns); /* see man setns / ip netns */
- clicon_debug(1, "%s nsfile:%s", __FUNCTION__, nsfile);
- /* Change network namespace */
- if ((nsfd = open(nsfile, O_RDONLY | O_CLOEXEC)) < 0){
- clicon_err(OE_UNIX, errno, "open");
- exit(1);
- }
- if (setns(nsfd, 0) < 0){ /* Join that namespace */
- clicon_err(OE_UNIX, errno, "setns");
- exit(1);
- }
- close(nsfd);
- if (unshare(CLONE_NEWNS) < 0){
- clicon_err(OE_UNIX, errno, "unshare");
- exit(1);
- }
- }
+ /* If network namespace is defined, let child join it
+ * XXX: this is work-in-progress
+ */
+ if (netns != NULL) {
+ snprintf(nsfile, PATH_MAX, "/var/run/netns/%s", netns); /* see man setns / ip netns */
+ clicon_debug(1, "%s nsfile:%s", __FUNCTION__, nsfile);
+ /* Change network namespace */
+ if ((nsfd = open(nsfile, O_RDONLY | O_CLOEXEC)) < 0){
+ clicon_err(OE_UNIX, errno, "open");
+ exit(1);
+ }
+ if (setns(nsfd, 0) < 0){ /* Join that namespace */
+ clicon_err(OE_UNIX, errno, "setns");
+ exit(1);
+ }
+ close(nsfd);
+ if (unshare(CLONE_NEWNS) < 0){
+ clicon_err(OE_UNIX, errno, "unshare");
+ exit(1);
+ }
+ }
#endif /* HAVE_SETNS */
- if (execvp(argv[0], argv) < 0) {
- clicon_err(OE_UNIX, errno, "execv(%s)", argv[0]);
- exit(1);
- }
- /* Not reached */
+ if (execvp(argv[0], argv) < 0) {
+ clicon_err(OE_UNIX, errno, "execv(%s)", argv[0]);
+ exit(1);
+ }
+ /* Not reached */
}
done:
sigprocmask(SIG_SETMASK, &oset, NULL);
@@ -417,19 +417,19 @@ clixon_process_op_str2int(char *opstr)
*/
int
clixon_process_argv_get(clicon_handle h,
- const char *name,
- char ***argv,
- int *argc)
+ const char *name,
+ char ***argv,
+ int *argc)
{
process_entry_t *pe;
pe = _proc_entry_list;
do {
- if (strcmp(pe->pe_name, name) == 0){
- *argv = pe->pe_argv;
- *argc = pe->pe_argc;
- }
- pe = NEXTQ(process_entry_t *, pe);
+ if (strcmp(pe->pe_name, name) == 0){
+ *argv = pe->pe_argv;
+ *argc = pe->pe_argc;
+ }
+ pe = NEXTQ(process_entry_t *, pe);
} while (pe != _proc_entry_list);
return 0;
}
@@ -449,59 +449,59 @@ clixon_process_argv_get(clicon_handle h,
*/
int
clixon_process_register(clicon_handle h,
- const char *name,
- const char *description,
- const char *netns,
- proc_cb_t *callback,
- char **argv,
- int argc)
+ const char *name,
+ const char *description,
+ const char *netns,
+ proc_cb_t *callback,
+ char **argv,
+ int argc)
{
int retval = -1;
process_entry_t *pe = NULL;
int i;
-
+
if (name == NULL){
- clicon_err(OE_DB, EINVAL, "name is NULL");
- goto done;
+ clicon_err(OE_DB, EINVAL, "name is NULL");
+ goto done;
}
if (argv == NULL){
- clicon_err(OE_DB, EINVAL, "argv is NULL");
- goto done;
+ clicon_err(OE_DB, EINVAL, "argv is NULL");
+ goto done;
}
if ((pe = malloc(sizeof(process_entry_t))) == NULL) {
- clicon_err(OE_DB, errno, "malloc");
- goto done;
+ clicon_err(OE_DB, errno, "malloc");
+ goto done;
}
memset(pe, 0, sizeof(*pe));
if ((pe->pe_name = strdup(name)) == NULL){
- clicon_err(OE_DB, errno, "strdup name");
- goto done;
+ clicon_err(OE_DB, errno, "strdup name");
+ goto done;
}
if (description && (pe->pe_description = strdup(description)) == NULL){
- clicon_err(OE_DB, errno, "strdup description");
- goto done;
+ clicon_err(OE_DB, errno, "strdup description");
+ goto done;
}
if (netns && (pe->pe_netns = strdup(netns)) == NULL){
- clicon_err(OE_DB, errno, "strdup netns");
- goto done;
+ clicon_err(OE_DB, errno, "strdup netns");
+ goto done;
}
pe->pe_argc = argc;
if ((pe->pe_argv = calloc(argc, sizeof(char *))) == NULL){
- clicon_err(OE_UNIX, errno, "calloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "calloc");
+ goto done;
}
for (i=0; ipe_argv[i] = strdup(argv[i])) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
+ if (argv[i] != NULL &&
+ (pe->pe_argv[i] = strdup(argv[i])) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
}
pe->pe_callback = callback;
clicon_debug(1, "%s %s ----> %s", __FUNCTION__,
- pe->pe_name,
- clicon_int2str(proc_state_map, PROC_STATE_STOPPED)
- );
+ pe->pe_name,
+ clicon_int2str(proc_state_map, PROC_STATE_STOPPED)
+ );
pe->pe_state = PROC_STATE_STOPPED;
ADDQ(pe, _proc_entry_list);
retval = 0;
@@ -515,17 +515,17 @@ clixon_process_delete_only(process_entry_t *pe)
char **pa;
if (pe->pe_name)
- free(pe->pe_name);
+ free(pe->pe_name);
if (pe->pe_description)
- free(pe->pe_description);
+ free(pe->pe_description);
if (pe->pe_netns)
- free(pe->pe_netns);
+ free(pe->pe_netns);
if (pe->pe_argv){
- for (pa = pe->pe_argv; *pa != NULL; pa++){
- if (*pa)
- free(*pa);
- }
- free(pe->pe_argv);
+ for (pa = pe->pe_argv; *pa != NULL; pa++){
+ if (*pa)
+ free(*pa);
+ }
+ free(pe->pe_argv);
}
free(pe);
return 0;
@@ -539,8 +539,8 @@ clixon_process_delete_all(clicon_handle h)
process_entry_t *pe;
while((pe = _proc_entry_list) != NULL) {
- DELQ(pe, _proc_entry_list, process_entry_t *);
- clixon_process_delete_only(pe);
+ DELQ(pe, _proc_entry_list, process_entry_t *);
+ clixon_process_delete_only(pe);
}
return 0;
}
@@ -549,7 +549,7 @@ clixon_process_delete_all(clicon_handle h)
*/
static int
proc_op_run(pid_t pid0,
- int *runp)
+ int *runp)
{
int retval = -1;
int run;
@@ -557,20 +557,20 @@ proc_op_run(pid_t pid0,
run = 0;
if ((pid = pid0) != 0){ /* if 0 stopped */
- /* Check if alive */
- run = 1;
- if ((kill(pid, 0)) < 0){
- if (errno == ESRCH){
- run = 0;
- }
- else{
- clicon_err(OE_UNIX, errno, "kill(%d)", pid);
- goto done;
- }
- }
+ /* Check if alive */
+ run = 1;
+ if ((kill(pid, 0)) < 0){
+ if (errno == ESRCH){
+ run = 0;
+ }
+ else{
+ clicon_err(OE_UNIX, errno, "kill(%d)", pid);
+ goto done;
+ }
+ }
}
if (runp)
- *runp = run;
+ *runp = run;
retval = 0;
done:
return retval;
@@ -625,9 +625,9 @@ done:
*/
int
clixon_process_operation(clicon_handle h,
- const char *name,
- proc_operation op0,
- int wrapit)
+ const char *name,
+ proc_operation op0,
+ int wrapit)
{
int retval = -1;
process_entry_t *pe;
@@ -638,50 +638,50 @@ clixon_process_operation(clicon_handle h,
clicon_debug(1, "%s name:%s op:%s", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0));
if (_proc_entry_list == NULL)
- goto ok;
+ goto ok;
if ((pe = _proc_entry_list) != NULL)
- do {
- if (strcmp(pe->pe_name, name) == 0){
- /* Call wrapper function that eg changes op1 based on config */
- op = op0;
- if (wrapit && pe->pe_callback != NULL)
- if (pe->pe_callback(h, pe, &op) < 0)
- goto done;
- if (op == PROC_OP_START || op == PROC_OP_STOP || op == PROC_OP_RESTART){
- pe->pe_operation = op;
- clicon_debug(1, "%s scheduling name: %s pid:%d op: %s", __FUNCTION__,
- name, pe->pe_pid,
- clicon_int2str(proc_operation_map, pe->pe_operation));
- if (pe->pe_state==PROC_STATE_RUNNING &&
- (op == PROC_OP_STOP || op == PROC_OP_RESTART)){
- isrunning = 0;
- if (proc_op_run(pe->pe_pid, &isrunning) < 0)
- goto done;
- if (isrunning) {
- clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d",
- pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */
- kill(pe->pe_pid, SIGTERM);
- delay = 1;
- }
- clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__,
- pe->pe_name, pe->pe_pid,
- clicon_int2str(proc_state_map, pe->pe_state),
- clicon_int2str(proc_operation_map, pe->pe_operation),
- clicon_int2str(proc_state_map, PROC_STATE_EXITING)
- );
- pe->pe_state = PROC_STATE_EXITING; /* Keep operation stop/restart */
- }
- sched++;/* start: immediate stop/restart: not immediate: wait timeout */
- }
- else{
- clicon_debug(1, "%s name:%s op %s cancelled by wrap", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0));
- }
- break; /* hit break here */
- }
- pe = NEXTQ(process_entry_t *, pe);
+ do {
+ if (strcmp(pe->pe_name, name) == 0){
+ /* Call wrapper function that eg changes op1 based on config */
+ op = op0;
+ if (wrapit && pe->pe_callback != NULL)
+ if (pe->pe_callback(h, pe, &op) < 0)
+ goto done;
+ if (op == PROC_OP_START || op == PROC_OP_STOP || op == PROC_OP_RESTART){
+ pe->pe_operation = op;
+ clicon_debug(1, "%s scheduling name: %s pid:%d op: %s", __FUNCTION__,
+ name, pe->pe_pid,
+ clicon_int2str(proc_operation_map, pe->pe_operation));
+ if (pe->pe_state==PROC_STATE_RUNNING &&
+ (op == PROC_OP_STOP || op == PROC_OP_RESTART)){
+ isrunning = 0;
+ if (proc_op_run(pe->pe_pid, &isrunning) < 0)
+ goto done;
+ if (isrunning) {
+ clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d",
+ pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */
+ kill(pe->pe_pid, SIGTERM);
+ delay = 1;
+ }
+ clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__,
+ pe->pe_name, pe->pe_pid,
+ clicon_int2str(proc_state_map, pe->pe_state),
+ clicon_int2str(proc_operation_map, pe->pe_operation),
+ clicon_int2str(proc_state_map, PROC_STATE_EXITING)
+ );
+ pe->pe_state = PROC_STATE_EXITING; /* Keep operation stop/restart */
+ }
+ sched++;/* start: immediate stop/restart: not immediate: wait timeout */
+ }
+ else{
+ clicon_debug(1, "%s name:%s op %s cancelled by wrap", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0));
+ }
+ break; /* hit break here */
+ }
+ pe = NEXTQ(process_entry_t *, pe);
} while (pe != _proc_entry_list);
if (sched && clixon_process_sched_register(h, delay) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
@@ -699,9 +699,9 @@ clixon_process_operation(clicon_handle h,
*/
int
clixon_process_status(clicon_handle h,
- const char *name,
- cbuf *cbret)
-
+ const char *name,
+ cbuf *cbret)
+
{
int retval = -1;
process_entry_t *pe;
@@ -711,50 +711,50 @@ clixon_process_status(clicon_handle h,
int match = 0;
if (_proc_entry_list != NULL){
- pe = _proc_entry_list;
- do {
- if (strcmp(pe->pe_name, name) == 0){
- clicon_debug(1, "%s found %s pid:%d", __FUNCTION__, name, pe->pe_pid);
- /* Check if running */
- run = 0;
- if (pe->pe_pid && proc_op_run(pe->pe_pid, &run) < 0)
- goto done;
- cprintf(cbret, "%s ",
- NETCONF_BASE_NAMESPACE, CLIXON_LIB_NS, run?"true":"false");
- if (pe->pe_description)
- cprintf(cbret, "%s ", CLIXON_LIB_NS, pe->pe_description);
- cprintf(cbret, "", CLIXON_LIB_NS);
- /* The command may include any data, including XML (such as restconf -R
- * command) and therefore needs explicit encoding */
- for (i=0; ipe_argc-1; i++){
- if (i)
- if (xml_chardata_cbuf_append(cbret, " ") < 0)
- goto done;
- if (xml_chardata_cbuf_append(cbret, pe->pe_argv[i]) < 0)
- goto done;
- }
- cprintf(cbret, " ");
- cprintf(cbret, "%s ", CLIXON_LIB_NS,
- clicon_int2str(proc_state_map, pe->pe_state));
- if (timerisset(&pe->pe_starttime)){
- if (time2str(pe->pe_starttime, timestr, sizeof(timestr)) < 0){
- clicon_err(OE_UNIX, errno, "time2str");
- goto done;
- }
- cprintf(cbret, "%s ", CLIXON_LIB_NS, timestr);
- }
- if (pe->pe_pid)
- cprintf(cbret, "%u ", CLIXON_LIB_NS, pe->pe_pid);
- cprintf(cbret, " ");
- match++;
- break; /* hit break here */
- }
- pe = NEXTQ(process_entry_t *, pe);
- } while (pe != _proc_entry_list);
+ pe = _proc_entry_list;
+ do {
+ if (strcmp(pe->pe_name, name) == 0){
+ clicon_debug(1, "%s found %s pid:%d", __FUNCTION__, name, pe->pe_pid);
+ /* Check if running */
+ run = 0;
+ if (pe->pe_pid && proc_op_run(pe->pe_pid, &run) < 0)
+ goto done;
+ cprintf(cbret, "%s ",
+ NETCONF_BASE_NAMESPACE, CLIXON_LIB_NS, run?"true":"false");
+ if (pe->pe_description)
+ cprintf(cbret, "%s ", CLIXON_LIB_NS, pe->pe_description);
+ cprintf(cbret, "", CLIXON_LIB_NS);
+ /* The command may include any data, including XML (such as restconf -R
+ * command) and therefore needs explicit encoding */
+ for (i=0; ipe_argc-1; i++){
+ if (i)
+ if (xml_chardata_cbuf_append(cbret, " ") < 0)
+ goto done;
+ if (xml_chardata_cbuf_append(cbret, pe->pe_argv[i]) < 0)
+ goto done;
+ }
+ cprintf(cbret, " ");
+ cprintf(cbret, "%s ", CLIXON_LIB_NS,
+ clicon_int2str(proc_state_map, pe->pe_state));
+ if (timerisset(&pe->pe_starttime)){
+ if (time2str(pe->pe_starttime, timestr, sizeof(timestr)) < 0){
+ clicon_err(OE_UNIX, errno, "time2str");
+ goto done;
+ }
+ cprintf(cbret, "%s ", CLIXON_LIB_NS, timestr);
+ }
+ if (pe->pe_pid)
+ cprintf(cbret, "%u ", CLIXON_LIB_NS, pe->pe_pid);
+ cprintf(cbret, " ");
+ match++;
+ break; /* hit break here */
+ }
+ pe = NEXTQ(process_entry_t *, pe);
+ } while (pe != _proc_entry_list);
}
if (!match){ /* No match, return error */
- if (netconf_unknown_element(cbret, "application", (char*)name, "Process service is not known") < 0)
- goto done;
+ if (netconf_unknown_element(cbret, "application", (char*)name, "Process service is not known") < 0)
+ goto done;
}
retval = 0;
done:
@@ -777,22 +777,22 @@ clixon_process_start_all(clicon_handle h)
clicon_debug(1, "%s",__FUNCTION__);
if (_proc_entry_list == NULL)
- goto ok;
+ goto ok;
pe = _proc_entry_list;
do {
- op = PROC_OP_START;
- /* Call wrapper function that eg changes op based on config */
- if (pe->pe_callback != NULL)
- if (pe->pe_callback(h, pe, &op) < 0)
- goto done;
- if (op == PROC_OP_START){
- pe->pe_operation = op;
- sched++; /* Immediate dont delay for start */
- }
- pe = NEXTQ(process_entry_t *, pe);
+ op = PROC_OP_START;
+ /* Call wrapper function that eg changes op based on config */
+ if (pe->pe_callback != NULL)
+ if (pe->pe_callback(h, pe, &op) < 0)
+ goto done;
+ if (op == PROC_OP_START){
+ pe->pe_operation = op;
+ sched++; /* Immediate dont delay for start */
+ }
+ pe = NEXTQ(process_entry_t *, pe);
} while (pe != _proc_entry_list);
if (sched && clixon_process_sched_register(h, 0) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
@@ -811,7 +811,7 @@ clixon_process_start_all(clicon_handle h)
*/
static int
clixon_process_sched(int fd,
- clicon_handle h)
+ clicon_handle h)
{
int retval = -1;
process_entry_t *pe;
@@ -820,87 +820,87 @@ clixon_process_sched(int fd,
clicon_debug(1, "%s",__FUNCTION__);
if (_proc_entry_list == NULL)
- goto ok;
+ goto ok;
pe = _proc_entry_list;
do {
- clicon_debug(1, "%s name: %s pid:%d %s --op:%s-->", __FUNCTION__,
- pe->pe_name, pe->pe_pid, clicon_int2str(proc_state_map, pe->pe_state), clicon_int2str(proc_operation_map, pe->pe_operation));
- /* Execute pending operations and not already exiting */
- if (pe->pe_operation != PROC_OP_NONE){
- switch (pe->pe_state){
- case PROC_STATE_EXITING:
- switch (pe->pe_operation){
- case PROC_OP_STOP:
- case PROC_OP_RESTART: /* Kill again */
- isrunning = 0;
- if (proc_op_run(pe->pe_pid, &isrunning) < 0)
- goto done;
- if (isrunning) {
- clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d",
- pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */
- kill(pe->pe_pid, SIGTERM);
- sched++; /* Not immediate: wait timeout */
- }
- default:
- break;
- }
- break; /* only clixon_process_waitpid can change state in exiting */
- case PROC_STATE_STOPPED:
- switch (pe->pe_operation){
- case PROC_OP_RESTART: /* stopped -> restart can happen if its externall stopped */
- case PROC_OP_START:
- /* Check if actual running using kill(0) */
- isrunning = 0;
- if (proc_op_run(pe->pe_pid, &isrunning) < 0)
- goto done;
- if (!isrunning)
- if (clixon_proc_background(pe->pe_argv, pe->pe_netns, &pe->pe_pid) < 0)
- goto done;
- clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__,
- pe->pe_name, pe->pe_pid,
- clicon_int2str(proc_state_map, pe->pe_state),
- clicon_int2str(proc_operation_map, pe->pe_operation),
- clicon_int2str(proc_state_map, PROC_STATE_RUNNING)
- );
- pe->pe_state = PROC_STATE_RUNNING;
- gettimeofday(&pe->pe_starttime, NULL);
- pe->pe_operation = PROC_OP_NONE;
- break;
- default:
- break;
- }
- break;
- case PROC_STATE_RUNNING:
- /* Check if actual running using kill(0) */
- isrunning = 0;
- if (proc_op_run(pe->pe_pid, &isrunning) < 0)
- goto done;
- switch (pe->pe_operation){
- case PROC_OP_START:
- if (isrunning) /* Already runs */
- break;
- if (clixon_proc_background(pe->pe_argv, pe->pe_netns, &pe->pe_pid) < 0)
- goto done;
- clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__,
- pe->pe_name, pe->pe_pid,
- clicon_int2str(proc_state_map, pe->pe_state),
- clicon_int2str(proc_operation_map, pe->pe_operation),
- clicon_int2str(proc_state_map, PROC_STATE_RUNNING)
- );
- gettimeofday(&pe->pe_starttime, NULL);
- pe->pe_operation = PROC_OP_NONE;
- break;
- default:
- break;
- }/* switch pe_state */
- default:
- break;
- } /* switch pe_state */
- }
- pe = NEXTQ(process_entry_t *, pe);
+ clicon_debug(1, "%s name: %s pid:%d %s --op:%s-->", __FUNCTION__,
+ pe->pe_name, pe->pe_pid, clicon_int2str(proc_state_map, pe->pe_state), clicon_int2str(proc_operation_map, pe->pe_operation));
+ /* Execute pending operations and not already exiting */
+ if (pe->pe_operation != PROC_OP_NONE){
+ switch (pe->pe_state){
+ case PROC_STATE_EXITING:
+ switch (pe->pe_operation){
+ case PROC_OP_STOP:
+ case PROC_OP_RESTART: /* Kill again */
+ isrunning = 0;
+ if (proc_op_run(pe->pe_pid, &isrunning) < 0)
+ goto done;
+ if (isrunning) {
+ clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d",
+ pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */
+ kill(pe->pe_pid, SIGTERM);
+ sched++; /* Not immediate: wait timeout */
+ }
+ default:
+ break;
+ }
+ break; /* only clixon_process_waitpid can change state in exiting */
+ case PROC_STATE_STOPPED:
+ switch (pe->pe_operation){
+ case PROC_OP_RESTART: /* stopped -> restart can happen if its externall stopped */
+ case PROC_OP_START:
+ /* Check if actual running using kill(0) */
+ isrunning = 0;
+ if (proc_op_run(pe->pe_pid, &isrunning) < 0)
+ goto done;
+ if (!isrunning)
+ if (clixon_proc_background(pe->pe_argv, pe->pe_netns, &pe->pe_pid) < 0)
+ goto done;
+ clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__,
+ pe->pe_name, pe->pe_pid,
+ clicon_int2str(proc_state_map, pe->pe_state),
+ clicon_int2str(proc_operation_map, pe->pe_operation),
+ clicon_int2str(proc_state_map, PROC_STATE_RUNNING)
+ );
+ pe->pe_state = PROC_STATE_RUNNING;
+ gettimeofday(&pe->pe_starttime, NULL);
+ pe->pe_operation = PROC_OP_NONE;
+ break;
+ default:
+ break;
+ }
+ break;
+ case PROC_STATE_RUNNING:
+ /* Check if actual running using kill(0) */
+ isrunning = 0;
+ if (proc_op_run(pe->pe_pid, &isrunning) < 0)
+ goto done;
+ switch (pe->pe_operation){
+ case PROC_OP_START:
+ if (isrunning) /* Already runs */
+ break;
+ if (clixon_proc_background(pe->pe_argv, pe->pe_netns, &pe->pe_pid) < 0)
+ goto done;
+ clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__,
+ pe->pe_name, pe->pe_pid,
+ clicon_int2str(proc_state_map, pe->pe_state),
+ clicon_int2str(proc_operation_map, pe->pe_operation),
+ clicon_int2str(proc_state_map, PROC_STATE_RUNNING)
+ );
+ gettimeofday(&pe->pe_starttime, NULL);
+ pe->pe_operation = PROC_OP_NONE;
+ break;
+ default:
+ break;
+ }/* switch pe_state */
+ default:
+ break;
+ } /* switch pe_state */
+ }
+ pe = NEXTQ(process_entry_t *, pe);
} while (pe != _proc_entry_list);
if (sched && clixon_process_sched_register(h, 1) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
@@ -918,7 +918,7 @@ clixon_process_sched(int fd,
*/
static int
clixon_process_sched_register(clicon_handle h,
- int delay)
+ int delay)
{
int retval = -1;
struct timeval t;
@@ -927,9 +927,9 @@ clixon_process_sched_register(clicon_handle h,
clicon_debug(2, "%s", __FUNCTION__);
gettimeofday(&t, NULL);
if (delay)
- timeradd(&t, &t1, &t);
+ timeradd(&t, &t1, &t);
if (clixon_event_reg_timeout(t, clixon_process_sched, h, "process") < 0)
- goto done;
+ goto done;
retval = 0;
done:
clicon_debug(2, "%s retval:%d", __FUNCTION__, retval);
@@ -951,59 +951,59 @@ clixon_process_waitpid(clicon_handle h)
clicon_debug(1, "%s", __FUNCTION__);
if (_proc_entry_list == NULL)
- goto ok;
+ goto ok;
if ((pe = _proc_entry_list) != NULL)
- do {
- clicon_debug(1, "%s %s(%d) %s op:%s", __FUNCTION__,
- pe->pe_name, pe->pe_pid,
- clicon_int2str(proc_state_map, pe->pe_state),
- clicon_int2str(proc_operation_map, pe->pe_operation));
- if (pe->pe_pid != 0
- && (pe->pe_state == PROC_STATE_RUNNING || pe->pe_state == PROC_STATE_EXITING)
- // && (pe->pe_operation == PROC_OP_STOP || pe->pe_operation == PROC_OP_RESTART)
- ){
- clicon_debug(1, "%s %s waitpid(%d)", __FUNCTION__, pe->pe_name, pe->pe_pid);
- if ((wpid = waitpid(pe->pe_pid, &status, WNOHANG)) == pe->pe_pid){
- clicon_debug(1, "%s waitpid(%d) waited", __FUNCTION__, pe->pe_pid);
- pe->pe_exit_status = status;
- switch (pe->pe_operation){
- case PROC_OP_NONE: /* Spontaneous / External termination */
- case PROC_OP_STOP:
- clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__,
- pe->pe_name, pe->pe_pid,
- clicon_int2str(proc_state_map, pe->pe_state),
- clicon_int2str(proc_operation_map, pe->pe_operation),
- clicon_int2str(proc_state_map, PROC_STATE_STOPPED)
- );
- pe->pe_state = PROC_STATE_STOPPED;
- pe->pe_pid = 0;
- timerclear(&pe->pe_starttime);
- break;
- case PROC_OP_RESTART:
- /* This is the case where there is an existing process running.
- * it was killed above but still runs and needs to be reaped */
- if (clixon_proc_background(pe->pe_argv, pe->pe_netns, &pe->pe_pid) < 0)
- goto done;
- gettimeofday(&pe->pe_starttime, NULL);
- clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__,
- pe->pe_name, pe->pe_pid,
- clicon_int2str(proc_state_map, pe->pe_state),
- clicon_int2str(proc_operation_map, pe->pe_operation),
- clicon_int2str(proc_state_map, PROC_STATE_RUNNING)
- );
- pe->pe_state = PROC_STATE_RUNNING;
- gettimeofday(&pe->pe_starttime, NULL);
- break;
- default:
- break;
- }
- pe->pe_operation = PROC_OP_NONE;
- break; /* pid is unique */
- }
- else
- clicon_debug(1, "%s waitpid(%d) nomatch:%d", __FUNCTION__, pe->pe_pid, wpid);
- }
- pe = NEXTQ(process_entry_t *, pe);
+ do {
+ clicon_debug(1, "%s %s(%d) %s op:%s", __FUNCTION__,
+ pe->pe_name, pe->pe_pid,
+ clicon_int2str(proc_state_map, pe->pe_state),
+ clicon_int2str(proc_operation_map, pe->pe_operation));
+ if (pe->pe_pid != 0
+ && (pe->pe_state == PROC_STATE_RUNNING || pe->pe_state == PROC_STATE_EXITING)
+ // && (pe->pe_operation == PROC_OP_STOP || pe->pe_operation == PROC_OP_RESTART)
+ ){
+ clicon_debug(1, "%s %s waitpid(%d)", __FUNCTION__, pe->pe_name, pe->pe_pid);
+ if ((wpid = waitpid(pe->pe_pid, &status, WNOHANG)) == pe->pe_pid){
+ clicon_debug(1, "%s waitpid(%d) waited", __FUNCTION__, pe->pe_pid);
+ pe->pe_exit_status = status;
+ switch (pe->pe_operation){
+ case PROC_OP_NONE: /* Spontaneous / External termination */
+ case PROC_OP_STOP:
+ clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__,
+ pe->pe_name, pe->pe_pid,
+ clicon_int2str(proc_state_map, pe->pe_state),
+ clicon_int2str(proc_operation_map, pe->pe_operation),
+ clicon_int2str(proc_state_map, PROC_STATE_STOPPED)
+ );
+ pe->pe_state = PROC_STATE_STOPPED;
+ pe->pe_pid = 0;
+ timerclear(&pe->pe_starttime);
+ break;
+ case PROC_OP_RESTART:
+ /* This is the case where there is an existing process running.
+ * it was killed above but still runs and needs to be reaped */
+ if (clixon_proc_background(pe->pe_argv, pe->pe_netns, &pe->pe_pid) < 0)
+ goto done;
+ gettimeofday(&pe->pe_starttime, NULL);
+ clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__,
+ pe->pe_name, pe->pe_pid,
+ clicon_int2str(proc_state_map, pe->pe_state),
+ clicon_int2str(proc_operation_map, pe->pe_operation),
+ clicon_int2str(proc_state_map, PROC_STATE_RUNNING)
+ );
+ pe->pe_state = PROC_STATE_RUNNING;
+ gettimeofday(&pe->pe_starttime, NULL);
+ break;
+ default:
+ break;
+ }
+ pe->pe_operation = PROC_OP_NONE;
+ break; /* pid is unique */
+ }
+ else
+ clicon_debug(1, "%s waitpid(%d) nomatch:%d", __FUNCTION__, pe->pe_pid, wpid);
+ }
+ pe = NEXTQ(process_entry_t *, pe);
} while (pe && pe != _proc_entry_list);
ok:
retval = 0;
diff --git a/lib/src/clixon_proto.c b/lib/src/clixon_proto.c
index d15fc198..e0f0276b 100644
--- a/lib/src/clixon_proto.c
+++ b/lib/src/clixon_proto.c
@@ -107,8 +107,8 @@ format_int2str(enum format_enum showas)
struct formatvec *fv;
for (fv=_FORMATS; fv->fv_int != -1; fv++)
- if (fv->fv_int == showas)
- break;
+ if (fv->fv_int == showas)
+ break;
return fv?(fv->fv_str?fv->fv_str:"unknown"):"unknown";
}
@@ -122,8 +122,8 @@ format_str2int(char *str)
struct formatvec *fv;
for (fv=_FORMATS; fv->fv_int != -1; fv++)
- if (strcmp(fv->fv_str, str) == 0)
- break;
+ if (strcmp(fv->fv_str, str) == 0)
+ break;
return fv?fv->fv_int:-1;
}
@@ -138,7 +138,7 @@ format_str2int(char *str)
*/
struct clicon_msg *
clicon_msg_encode(uint32_t id,
- const char *format, ...)
+ const char *format, ...)
{
va_list args;
uint32_t xmllen;
@@ -152,8 +152,8 @@ clicon_msg_encode(uint32_t id,
len = hdrlen + xmllen;
if ((msg = (struct clicon_msg *)malloc(len)) == NULL){
- clicon_err(OE_PROTO, errno, "malloc");
- return NULL;
+ clicon_err(OE_PROTO, errno, "malloc");
+ return NULL;
}
memset(msg, 0, len);
/* hdr */
@@ -180,10 +180,10 @@ clicon_msg_encode(uint32_t id,
*/
int
clicon_msg_decode(struct clicon_msg *msg,
- yang_stmt *yspec,
- uint32_t *id,
- cxobj **xml,
- cxobj **xerr)
+ yang_stmt *yspec,
+ uint32_t *id,
+ cxobj **xml,
+ cxobj **xerr)
{
int retval = -1;
char *xmlstr;
@@ -191,14 +191,14 @@ clicon_msg_decode(struct clicon_msg *msg,
/* hdr */
if (id)
- *id = ntohl(msg->op_id);
+ *id = ntohl(msg->op_id);
/* body */
xmlstr = msg->op_body;
clicon_debug(1, "%s %s", __FUNCTION__, xmlstr);
if ((ret = clixon_xml_parse_string(xmlstr, yspec?YB_RPC:YB_NONE, yspec, xml, xerr)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
retval = 1;
done:
return retval;
@@ -215,15 +215,15 @@ clicon_msg_decode(struct clicon_msg *msg,
*/
int
clicon_connect_unix(clicon_handle h,
- char *sockpath)
+ char *sockpath)
{
struct sockaddr_un addr;
int retval = -1;
int s;
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- clicon_err(OE_CFG, errno, "socket");
- return -1;
+ clicon_err(OE_CFG, errno, "socket");
+ return -1;
}
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
@@ -231,14 +231,14 @@ clicon_connect_unix(clicon_handle h,
clicon_debug(2, "%s: connecting to %s", __FUNCTION__, addr.sun_path);
if (connect(s, (struct sockaddr *)&addr, SUN_LEN(&addr)) < 0){
- if (errno == EACCES)
- clicon_err(OE_CFG, errno, "connecting unix socket: %s. "
- "Is user not member of group: \"%s\"?",
- sockpath, clicon_sock_group(h));
- else
- clicon_err(OE_CFG, errno, "connecting unix socket: %s", sockpath);
- close(s);
- goto done;
+ if (errno == EACCES)
+ clicon_err(OE_CFG, errno, "connecting unix socket: %s. "
+ "Is user not member of group: \"%s\"?",
+ sockpath, clicon_sock_group(h));
+ else
+ clicon_err(OE_CFG, errno, "connecting unix socket: %s", sockpath);
+ close(s);
+ goto done;
}
retval = s;
done:
@@ -259,35 +259,35 @@ atomicio_sig_handler(int arg)
*/
static ssize_t
atomicio(ssize_t (*fn) (int, void *, size_t),
- int fd,
- void *s0,
- size_t n)
+ int fd,
+ void *s0,
+ size_t n)
{
char *s = s0;
ssize_t res, pos = 0;
while (n > pos) {
- _atomicio_sig = 0;
- res = (fn)(fd, s + pos, n - pos);
- switch (res) {
- case -1:
- if (errno == EINTR){
- if (!_atomicio_sig)
- continue;
- }
- else if (errno == EAGAIN)
- continue;
- else if (errno == ECONNRESET)/* Connection reset by peer */
- res = 0;
- else if (errno == EPIPE) /* Client shutdown */
- res = 0;
- else if (errno == EBADF) /* client shutdown - freebsd */
- res = 0;
- case 0: /* fall thru */
- return (res);
- default:
- pos += res;
- }
+ _atomicio_sig = 0;
+ res = (fn)(fd, s + pos, n - pos);
+ switch (res) {
+ case -1:
+ if (errno == EINTR){
+ if (!_atomicio_sig)
+ continue;
+ }
+ else if (errno == EAGAIN)
+ continue;
+ else if (errno == ECONNRESET)/* Connection reset by peer */
+ res = 0;
+ else if (errno == EPIPE) /* Client shutdown */
+ res = 0;
+ else if (errno == EBADF) /* client shutdown - freebsd */
+ res = 0;
+ case 0: /* fall thru */
+ return (res);
+ default:
+ pos += res;
+ }
}
return (pos);
}
@@ -303,26 +303,26 @@ msg_dump(struct clicon_msg *msg)
int i;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_CFG, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_CFG, errno, "cbuf_new");
+ goto done;
}
cprintf(cb, "%s:", __FUNCTION__);
for (i=0; iop_len); i++){
- cprintf(cb, "%02x", ((char*)msg)[i]&0xff);
- if ((i+1)%32==0){
- clicon_debug(2, "%s", cbuf_get(cb));
- cbuf_reset(cb);
- cprintf(cb, "%s:", __FUNCTION__);
- }
- else
- if ((i+1)%4==0)
- cprintf(cb, " ");
+ cprintf(cb, "%02x", ((char*)msg)[i]&0xff);
+ if ((i+1)%32==0){
+ clicon_debug(2, "%s", cbuf_get(cb));
+ cbuf_reset(cb);
+ cprintf(cb, "%s:", __FUNCTION__);
+ }
+ else
+ if ((i+1)%4==0)
+ cprintf(cb, " ");
}
clicon_debug(2, "%s", cbuf_get(cb));
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -334,22 +334,22 @@ msg_dump(struct clicon_msg *msg)
*/
int
clicon_msg_send(int s,
- struct clicon_msg *msg)
+ struct clicon_msg *msg)
{
int retval = -1;
int e;
clicon_debug(2, "%s: send msg len=%d",
- __FUNCTION__, ntohl(msg->op_len));
+ __FUNCTION__, ntohl(msg->op_len));
if (clicon_debug_get() > 2)
- msg_dump(msg);
+ msg_dump(msg);
if (atomicio((ssize_t (*)(int, void *, size_t))write,
- s, msg, ntohl(msg->op_len)) < 0){
- e = errno;
- clicon_err(OE_CFG, e, "atomicio");
- clicon_log(LOG_WARNING, "%s: write: %s len:%u msg:%s", __FUNCTION__,
- strerror(e), ntohs(msg->op_len), msg->op_body);
- goto done;
+ s, msg, ntohl(msg->op_len)) < 0){
+ e = errno;
+ clicon_err(OE_CFG, e, "atomicio");
+ clicon_log(LOG_WARNING, "%s: write: %s len:%u msg:%s", __FUNCTION__,
+ strerror(e), ntohs(msg->op_len), msg->op_body);
+ goto done;
}
retval = 0;
done:
@@ -374,8 +374,8 @@ clicon_msg_send(int s,
*/
int
clicon_msg_rcv(int s,
- struct clicon_msg **msg,
- int *eof)
+ struct clicon_msg **msg,
+ int *eof)
{
int retval = -1;
struct clicon_msg hdr;
@@ -386,43 +386,43 @@ clicon_msg_rcv(int s,
*eof = 0;
if (0)
- set_signal(SIGINT, atomicio_sig_handler, &oldhandler);
+ set_signal(SIGINT, atomicio_sig_handler, &oldhandler);
if ((hlen = atomicio(read, s, &hdr, sizeof(hdr))) < 0){
- clicon_err(OE_CFG, errno, "atomicio");
- goto done;
+ clicon_err(OE_CFG, errno, "atomicio");
+ goto done;
}
if (hlen == 0){
- retval = 0;
- *eof = 1;
- goto done;
+ retval = 0;
+ *eof = 1;
+ goto done;
}
if (hlen != sizeof(hdr)){
- clicon_err(OE_CFG, errno, "header too short (%d)", hlen);
- goto done;
+ clicon_err(OE_CFG, errno, "header too short (%d)", hlen);
+ goto done;
}
mlen = ntohl(hdr.op_len);
clicon_debug(2, "%s: rcv msg len=%d",
- __FUNCTION__, mlen);
+ __FUNCTION__, mlen);
if ((*msg = (struct clicon_msg *)malloc(mlen)) == NULL){
- clicon_err(OE_CFG, errno, "malloc");
- goto done;
+ clicon_err(OE_CFG, errno, "malloc");
+ goto done;
}
memcpy(*msg, &hdr, hlen);
if ((len2 = atomicio(read, s, (*msg)->op_body, mlen - sizeof(hdr))) < 0){
- clicon_err(OE_CFG, errno, "read");
- goto done;
+ clicon_err(OE_CFG, errno, "read");
+ goto done;
}
if (len2 != mlen - sizeof(hdr)){
- clicon_err(OE_CFG, errno, "body too short");
- goto done;
+ clicon_err(OE_CFG, errno, "body too short");
+ goto done;
}
if (clicon_debug_get() > 1)
- msg_dump(*msg);
+ msg_dump(*msg);
retval = 0;
done:
if (0)
- set_signal(SIGINT, oldhandler, NULL);
+ set_signal(SIGINT, oldhandler, NULL);
return retval;
}
@@ -436,8 +436,8 @@ clicon_msg_rcv(int s,
*/
int
clicon_msg_rcv1(int s,
- cbuf *cb,
- int *eof)
+ cbuf *cb,
+ int *eof)
{
int retval = -1;
unsigned char buf[BUFSIZ];
@@ -459,7 +459,7 @@ clicon_msg_rcv1(int s,
}
} /* read */
if (len == 0){ /* EOF */
- *eof = 1;
+ *eof = 1;
close(s);
goto ok;
}
@@ -497,15 +497,15 @@ clicon_msg_rcv1(int s,
*/
int
clicon_msg_send1(int s,
- cbuf *cb)
+ cbuf *cb)
{
int retval = -1;
if (atomicio((ssize_t (*)(int, void *, size_t))write,
- s, cbuf_get(cb), cbuf_len(cb)+1) < 0){
- clicon_err(OE_CFG, errno, "atomicio");
- clicon_log(LOG_WARNING, "%s: write: %s", __FUNCTION__, strerror(errno));
- goto done;
+ s, cbuf_get(cb), cbuf_len(cb)+1) < 0){
+ clicon_err(OE_CFG, errno, "atomicio");
+ clicon_log(LOG_WARNING, "%s: write: %s", __FUNCTION__, strerror(errno));
+ goto done;
}
retval = 0;
done:
@@ -525,8 +525,8 @@ clicon_msg_send1(int s,
*/
int
clicon_rpc_connect_unix(clicon_handle h,
- char *sockpath,
- int *sock0)
+ char *sockpath,
+ int *sock0)
{
int retval = -1;
int s = -1;
@@ -534,20 +534,20 @@ clicon_rpc_connect_unix(clicon_handle h,
clicon_debug(1, "Send msg on %s", sockpath);
if (sock0 == NULL){
- clicon_err(OE_NETCONF, EINVAL, "sock0 expected");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "sock0 expected");
+ goto done;
}
/* special error handling to get understandable messages (otherwise ENOENT) */
if (stat(sockpath, &sb) < 0){
- clicon_err(OE_PROTO, errno, "%s: config daemon not running?", sockpath);
- goto done;
+ clicon_err(OE_PROTO, errno, "%s: config daemon not running?", sockpath);
+ goto done;
}
if (!S_ISSOCK(sb.st_mode)){
- clicon_err(OE_PROTO, EIO, "%s: Not unix socket", sockpath);
- goto done;
+ clicon_err(OE_PROTO, EIO, "%s: Not unix socket", sockpath);
+ goto done;
}
if ((s = clicon_connect_unix(h, sockpath)) < 0)
- goto done;
+ goto done;
*sock0 = s;
retval = 0;
done:
@@ -567,9 +567,9 @@ clicon_rpc_connect_unix(clicon_handle h,
*/
int
clicon_rpc_connect_inet(clicon_handle h,
- char *dst,
- uint16_t port,
- int *sock0)
+ char *dst,
+ uint16_t port,
+ int *sock0)
{
int retval = -1;
int s = -1;
@@ -577,24 +577,24 @@ clicon_rpc_connect_inet(clicon_handle h,
clicon_debug(1, "Send msg to %s:%hu", dst, port);
if (sock0 == NULL){
- clicon_err(OE_NETCONF, EINVAL, "sock0 expected");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "sock0 expected");
+ goto done;
}
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)
- goto done; /* Could check getaddrinfo */
+ goto done; /* Could check getaddrinfo */
/* special error handling to get understandable messages (otherwise ENOENT) */
if ((s = socket(addr.sin_family, SOCK_STREAM, 0)) < 0) {
- clicon_err(OE_CFG, errno, "socket");
- return -1;
+ clicon_err(OE_CFG, errno, "socket");
+ return -1;
}
if (connect(s, (struct sockaddr*)&addr, sizeof(addr)) < 0){
- clicon_err(OE_CFG, errno, "connecting socket inet4");
- close(s);
- goto done;
+ clicon_err(OE_CFG, errno, "connecting socket inet4");
+ close(s);
+ goto done;
}
*sock0 = s;
retval = 0;
@@ -619,31 +619,31 @@ clicon_rpc_connect_inet(clicon_handle h,
*/
int
clicon_rpc(int sock,
- struct clicon_msg *msg,
- char **ret,
- int *eof)
+ struct clicon_msg *msg,
+ char **ret,
+ int *eof)
{
int retval = -1;
struct clicon_msg *reply = NULL;
char *data = NULL;
if (clicon_msg_send(sock, msg) < 0)
- goto done;
+ goto done;
if (clicon_msg_rcv(sock, &reply, eof) < 0)
- goto done;
+ goto done;
if (*eof)
- goto ok;
+ goto ok;
data = reply->op_body; /* assume string */
if (ret && data)
- if ((*ret = strdup(data)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
+ if ((*ret = strdup(data)) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
ok:
retval = 0;
done:
if (reply)
- free(reply);
+ free(reply);
return retval;
}
@@ -661,21 +661,21 @@ clicon_rpc(int sock,
*/
int
clicon_rpc1(int sock,
- cbuf *msg,
- cbuf *msgret,
- int *eof)
+ cbuf *msg,
+ cbuf *msgret,
+ int *eof)
{
int retval = -1;
clicon_debug(1, "%s", __FUNCTION__);
if (netconf_framing_preamble(NETCONF_SSH_CHUNKED, msg) < 0)
- goto done;
+ goto done;
if (netconf_framing_postamble(NETCONF_SSH_CHUNKED, msg) < 0)
- goto done;
+ goto done;
if (clicon_msg_send1(sock, msg) < 0)
- goto done;
+ goto done;
if (clicon_msg_rcv1(sock, msgret, eof) < 0)
- goto done;
+ goto done;
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
@@ -692,8 +692,8 @@ clicon_rpc1(int sock,
*/
int
send_msg_reply(int s,
- char *data,
- uint32_t datalen)
+ char *data,
+ uint32_t datalen)
{
int retval = -1;
struct clicon_msg *reply = NULL;
@@ -701,17 +701,17 @@ send_msg_reply(int s,
len = sizeof(*reply) + datalen;
if ((reply = (struct clicon_msg *)malloc(len)) == NULL)
- goto done;
+ goto done;
memset(reply, 0, len);
reply->op_len = htonl(len);
if (datalen > 0)
memcpy(reply->op_body, data, datalen);
if (clicon_msg_send(s, reply) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (reply)
- free(reply);
+ free(reply);
return retval;
}
@@ -726,19 +726,19 @@ send_msg_reply(int s,
*/
static int
send_msg_notify(int s,
- char *event)
+ char *event)
{
int retval = -1;
struct clicon_msg *msg = NULL;
if ((msg=clicon_msg_encode(0, "%s", event)) == NULL)
- goto done;
+ goto done;
if (clicon_msg_send(s, msg) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -753,25 +753,25 @@ send_msg_notify(int s,
*/
int
send_msg_notify_xml(clicon_handle h,
- int s,
- cxobj *xev)
+ int s,
+ cxobj *xev)
{
int retval = -1;
cbuf *cb = NULL;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_PLUGIN, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_PLUGIN, errno, "cbuf_new");
+ goto done;
}
if (clixon_xml2cbuf(cb, xev, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
if (send_msg_notify(s, cbuf_get(cb)) < 0)
- goto done;
+ goto done;
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -794,20 +794,20 @@ send_msg_notify_xml(clicon_handle h,
*/
int
detect_endtag(char *tag,
- char ch,
- int *state)
+ char ch,
+ int *state)
{
int retval = 0;
if (tag[*state] == ch){
- (*state)++;
- if (*state == strlen(tag)){
- *state = 0;
- retval = 1;
- }
+ (*state)++;
+ if (*state == strlen(tag)){
+ *state = 0;
+ retval = 1;
+ }
}
else
- *state = 0;
+ *state = 0;
return retval;
}
@@ -829,31 +829,31 @@ detect_endtag(char *tag,
*/
int
clixon_inet2sin(const char *addrtype,
- const char *addrstr,
- uint16_t port,
- struct sockaddr *sa,
- size_t *sa_len)
+ const char *addrstr,
+ uint16_t port,
+ struct sockaddr *sa,
+ size_t *sa_len)
{
struct sockaddr_in6 *sin6;
struct sockaddr_in *sin;
if (strcmp(addrtype, "inet:ipv6-address") == 0) {
- sin6 = (struct sockaddr_in6 *)sa;
+ sin6 = (struct sockaddr_in6 *)sa;
*sa_len = sizeof(struct sockaddr_in6);
sin6->sin6_port = htons(port);
sin6->sin6_family = AF_INET6;
inet_pton(AF_INET6, addrstr, &sin6->sin6_addr);
}
else if (strcmp(addrtype, "inet:ipv4-address") == 0) {
- sin = (struct sockaddr_in *)sa;
+ sin = (struct sockaddr_in *)sa;
*sa_len = sizeof(struct sockaddr_in);
sin->sin_family = AF_INET;
sin->sin_port = htons(port);
sin->sin_addr.s_addr = inet_addr(addrstr);
}
else{
- clicon_err(OE_XML, EINVAL, "Unexpected addrtype: %s", addrtype);
- return -1;
+ clicon_err(OE_XML, EINVAL, "Unexpected addrtype: %s", addrtype);
+ return -1;
}
return 0;
}
diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c
index 06afc117..623ccb0f 100644
--- a/lib/src/clixon_proto_client.c
+++ b/lib/src/clixon_proto_client.c
@@ -83,45 +83,49 @@
#include "clixon_netconf_lib.h"
#include "clixon_proto_client.h"
+#define PERSIST_ID_XML_FMT "%s "
+#define PERSIST_XML_FMT "%s "
+#define TIMEOUT_XML_FMT "%u "
+
/*! Connect to internal netconf socket
*/
int
clicon_rpc_connect(clicon_handle h,
- int *sockp)
+ int *sockp)
{
int retval = -1;
char *sockstr = NULL;
int port;
if ((sockstr = clicon_sock_str(h)) == NULL){
- clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set");
- goto done;
+ clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set");
+ goto done;
}
/* What to do if inet socket? */
switch (clicon_sock_family(h)){
case AF_UNIX:
- if (clicon_rpc_connect_unix(h, sockstr, sockp) < 0){
+ if (clicon_rpc_connect_unix(h, sockstr, sockp) < 0){
#if 0
- if (errno == ESHUTDOWN)
- /* Maybe could reconnect on a higher layer, but lets fail
- loud and proud */
- cligen_exiting_set(cli_cligen(h), 1);
+ if (errno == ESHUTDOWN)
+ /* Maybe could reconnect on a higher layer, but lets fail
+ loud and proud */
+ cligen_exiting_set(cli_cligen(h), 1);
#endif
- goto done;
- }
- break;
+ goto done;
+ }
+ break;
case AF_INET:
- if ((port = clicon_sock_port(h)) < 0){
- clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set");
- goto done;
- }
- if (port < 0){
- clicon_err(OE_FATAL, 0, "CLICON_SOCK_PORT not set");
- goto done;
- }
- if (clicon_rpc_connect_inet(h, sockstr, port, sockp) < 0)
- goto done;
- break;
+ if ((port = clicon_sock_port(h)) < 0){
+ clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set");
+ goto done;
+ }
+ if (port < 0){
+ clicon_err(OE_FATAL, 0, "CLICON_SOCK_PORT not set");
+ goto done;
+ }
+ if (clicon_rpc_connect_inet(h, sockstr, port, sockp) < 0)
+ goto done;
+ break;
}
retval = 0;
done:
@@ -136,28 +140,28 @@ clicon_rpc_connect(clicon_handle h,
*/
static int
clicon_rpc_msg_once(clicon_handle h,
- struct clicon_msg *msg,
- char **retdata,
- int *eof,
- int *sp)
+ struct clicon_msg *msg,
+ char **retdata,
+ int *eof,
+ int *sp)
{
int retval = -1;
int s;
if ((s = clicon_client_socket_get(h)) < 0){
- if (clicon_rpc_connect(h, &s) < 0)
- goto done;
- clicon_client_socket_set(h, s);
+ if (clicon_rpc_connect(h, &s) < 0)
+ goto done;
+ clicon_client_socket_set(h, s);
}
if (clicon_rpc(s, msg, retdata, eof) < 0){
- /* 2. check socket shutdown AFTER rpc */
- close(s);
- s = -1;
- clicon_client_socket_set(h, -1);
- goto done;
+ /* 2. check socket shutdown AFTER rpc */
+ close(s);
+ s = -1;
+ clicon_client_socket_set(h, -1);
+ goto done;
}
if (sp)
- *sp = s;
+ *sp = s;
retval = 0;
done:
return retval;
@@ -174,8 +178,8 @@ clicon_rpc_msg_once(clicon_handle h,
*/
int
clicon_rpc_msg(clicon_handle h,
- struct clicon_msg *msg,
- cxobj **xret0)
+ struct clicon_msg *msg,
+ cxobj **xret0)
{
int retval = -1;
char *retdata = NULL;
@@ -189,51 +193,51 @@ clicon_rpc_msg(clicon_handle h,
clicon_debug(2, "%s request:%s", __FUNCTION__, msg->op_body);
/* Create a socket and connect to it, either UNIX, IPv4 or IPv6 per config options */
if (clicon_rpc_msg_once(h, msg, &retdata, &eof, &s) < 0)
- goto done;
+ goto done;
if (eof){
- /* 2. check socket shutdown AFTER rpc */
- close(s);
- s = -1;
- clicon_client_socket_set(h, -1);
+ /* 2. check socket shutdown AFTER rpc */
+ close(s);
+ s = -1;
+ clicon_client_socket_set(h, -1);
#ifdef PROTO_RESTART_RECONNECT
- if (!clixon_exit_get()) { /* May be part of termination */
- if (clicon_rpc_msg_once(h, msg, &retdata, &eof, NULL) < 0)
- goto done;
- if (eof){
- close(s);
- s = -1;
- clicon_client_socket_set(h, -1);
-
- clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
- goto done;
- }
- /* To disable this restart, unset PROTO_RESTART_RECONNECT */
- clicon_log(LOG_WARNING, "The backend was probably restarted and the client has reconnected to the backend. Any locks or candidate edits are lost.");
- }
+ if (!clixon_exit_get()) { /* May be part of termination */
+ if (clicon_rpc_msg_once(h, msg, &retdata, &eof, NULL) < 0)
+ goto done;
+ if (eof){
+ close(s);
+ s = -1;
+ clicon_client_socket_set(h, -1);
+
+ clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
+ goto done;
+ }
+ /* To disable this restart, unset PROTO_RESTART_RECONNECT */
+ clicon_log(LOG_WARNING, "The backend was probably restarted and the client has reconnected to the backend. Any locks or candidate edits are lost.");
+ }
#else
- clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
- goto done;
+ clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
+ goto done;
#endif
}
clicon_debug(2, "%s retdata:%s", __FUNCTION__, retdata);
if (retdata){
- /* Cannot populate xret here because need to know RPC name (eg "lock") in order to associate yang
- * to reply.
- */
- if (clixon_xml_parse_string(retdata, YB_NONE, NULL, &xret, NULL) < 0)
- goto done;
+ /* Cannot populate xret here because need to know RPC name (eg "lock") in order to associate yang
+ * to reply.
+ */
+ if (clixon_xml_parse_string(retdata, YB_NONE, NULL, &xret, NULL) < 0)
+ goto done;
}
if (xret0){
- *xret0 = xret;
- xret = NULL;
+ *xret0 = xret;
+ xret = NULL;
}
retval = 0;
done:
if (retdata)
- free(retdata);
+ free(retdata);
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -247,9 +251,9 @@ clicon_rpc_msg(clicon_handle h,
*/
int
clicon_rpc_msg_persistent(clicon_handle h,
- struct clicon_msg *msg,
- cxobj **xret0,
- int *sock0)
+ struct clicon_msg *msg,
+ cxobj **xret0,
+ int *sock0)
{
int retval = -1;
char *retdata = NULL;
@@ -258,8 +262,8 @@ clicon_rpc_msg_persistent(clicon_handle h,
int eof = 0;
if (sock0 == NULL){
- clicon_err(OE_NETCONF, EINVAL, "Missing socket pointer");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "Missing socket pointer");
+ goto done;
}
#ifdef RPC_USERNAME_ASSERT
assert(strstr(msg->op_body, "username")!=NULL); /* XXX */
@@ -267,30 +271,30 @@ clicon_rpc_msg_persistent(clicon_handle h,
clicon_debug(1, "%s request:%s", __FUNCTION__, msg->op_body);
/* Create a socket and connect to it, either UNIX, IPv4 or IPv6 per config options */
if (clicon_rpc_msg_once(h, msg, &retdata, &eof, &s) < 0)
- goto done;
+ goto done;
if (eof){
- /* 2. check socket shutdown AFTER rpc */
- close(s);
- s = -1;
- clicon_client_socket_set(h, -1);
- /* Note here one could try a restart as done in clicon_rpc_msg, but seems not
- * right since if backend is restarted, the notification stream is gone.
- */
- clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
- goto done;
+ /* 2. check socket shutdown AFTER rpc */
+ close(s);
+ s = -1;
+ clicon_client_socket_set(h, -1);
+ /* Note here one could try a restart as done in clicon_rpc_msg, but seems not
+ * right since if backend is restarted, the notification stream is gone.
+ */
+ clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
+ goto done;
}
clicon_debug(1, "%s retdata:%s", __FUNCTION__, retdata);
if (retdata){
- /* Cannot populate xret here because need to know RPC name (eg "lock") in order to associate yang
- * to reply.
- */
- if (clixon_xml_parse_string(retdata, YB_NONE, NULL, &xret, NULL) < 0)
- goto done;
+ /* Cannot populate xret here because need to know RPC name (eg "lock") in order to associate yang
+ * to reply.
+ */
+ if (clixon_xml_parse_string(retdata, YB_NONE, NULL, &xret, NULL) < 0)
+ goto done;
}
if (xret0){
- *xret0 = xret;
- xret = NULL;
+ *xret0 = xret;
+ xret = NULL;
}
/* If returned, keep socket open, otherwise close it below */
*sock0 = s;
@@ -298,11 +302,11 @@ clicon_rpc_msg_persistent(clicon_handle h,
retval = 0;
done:
if (s >= 0)
- close(s);
+ close(s);
if (retdata)
- free(retdata);
+ free(retdata);
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -319,15 +323,15 @@ clicon_rpc_msg_persistent(clicon_handle h,
*/
static int
session_id_check(clicon_handle h,
- uint32_t *session_id)
+ uint32_t *session_id)
{
int retval = -1;
uint32_t id;
if (clicon_session_id_get(h, &id) < 0){ /* Not set yet */
- if (clicon_hello_req(h, &id) < 0)
- goto done;
- clicon_session_id_set(h, id);
+ if (clicon_hello_req(h, &id) < 0)
+ goto done;
+ clicon_session_id_set(h, id);
}
retval = 0;
*session_id = id;
@@ -345,36 +349,36 @@ session_id_check(clicon_handle h,
* cxobj *xret = NULL;
* int s = -1;
* if (clicon_rpc_netconf(h, " ", &xret, &s) < 0)
- * err;
+ * err;
* xml_free(xret);
* @endcode
* @see clicon_rpc_netconf_xml xml as tree instead of string
*/
int
clicon_rpc_netconf(clicon_handle h,
- char *xmlstr,
- cxobj **xret,
- int *sp)
+ char *xmlstr,
+ cxobj **xret,
+ int *sp)
{
int retval = -1;
uint32_t session_id;
struct clicon_msg *msg = NULL;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
if ((msg = clicon_msg_encode(session_id, "%s", xmlstr)) < 0)
- goto done;
+ goto done;
if (sp){
- if (clicon_rpc_msg_persistent(h, msg, xret, sp) < 0)
- goto done;
+ if (clicon_rpc_msg_persistent(h, msg, xret, sp) < 0)
+ goto done;
}
else
- if (clicon_rpc_msg(h, msg, xret) < 0)
- goto done;
+ if (clicon_rpc_msg(h, msg, xret) < 0)
+ goto done;
retval = 0;
done:
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -390,7 +394,7 @@ clicon_rpc_netconf(clicon_handle h,
* cxobj *xret = NULL;
* int s;
* if (clicon_rpc_netconf_xml(h, x, &xret, &s) < 0)
- * err;
+ * err;
* xml_free(xret);
* @endcode
@@ -398,9 +402,9 @@ clicon_rpc_netconf(clicon_handle h,
*/
int
clicon_rpc_netconf_xml(clicon_handle h,
- cxobj *xml,
- cxobj **xret,
- int *sp)
+ cxobj *xml,
+ cxobj **xret,
+ int *sp)
{
int retval = -1;
cbuf *cb = NULL;
@@ -412,42 +416,42 @@ clicon_rpc_netconf_xml(clicon_handle h,
int ret;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
if ((xname = xml_child_i_type(xml, 0, 0)) == NULL){
- clicon_err(OE_NETCONF, EINVAL, "Missing rpc name");
- goto done;
+ clicon_err(OE_NETCONF, EINVAL, "Missing rpc name");
+ goto done;
}
rpcname = xml_name(xname); /* Store rpc name and use in yang binding after reply */
if (clixon_xml2cbuf(cb, xml, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
if (clicon_rpc_netconf(h, cbuf_get(cb), xret, sp) < 0)
- goto done;
+ goto done;
if ((xreply = xml_find_type(*xret, NULL, "rpc-reply", CX_ELMNT)) != NULL &&
- xml_find_type(xreply, NULL, "rpc-error", CX_ELMNT) == NULL){
- yspec = clicon_dbspec_yang(h);
- /* Here use rpc name to bind to yang */
- if ((ret = xml_bind_yang_rpc_reply(xreply, rpcname, yspec, &xerr)) < 0)
- goto done;
- if (ret == 0){
- /* Replace reply with error */
- if (*xret) {
- cxobj *xc;
- if ((xc = xml_child_i(*xret, 0)) != NULL)
- xml_purge(xc);
- if (xml_addsub(*xret, xerr) < 0)
- goto done;
- xerr = NULL;
- }
- }
+ xml_find_type(xreply, NULL, "rpc-error", CX_ELMNT) == NULL){
+ yspec = clicon_dbspec_yang(h);
+ /* Here use rpc name to bind to yang */
+ if ((ret = xml_bind_yang_rpc_reply(xreply, rpcname, yspec, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ /* Replace reply with error */
+ if (*xret) {
+ cxobj *xc;
+ if ((xc = xml_child_i(*xret, 0)) != NULL)
+ xml_purge(xc);
+ if (xml_addsub(*xret, xerr) < 0)
+ goto done;
+ xerr = NULL;
+ }
+ }
}
retval = 0;
done:
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -472,7 +476,7 @@ clicon_rpc_netconf_xml(clicon_handle h,
* if (clicon_rpc_get_config(h, NULL, "running", "/hello/world", nsc, "explicit", &xt) < 0)
* err;
* if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
- * clixon_netconf_error(xerr, "msg", "/hello/world");
+ * clixon_netconf_error(xerr, "msg", "/hello/world");
* err;
* }
* if (xt)
@@ -486,12 +490,12 @@ clicon_rpc_netconf_xml(clicon_handle h,
*/
int
clicon_rpc_get_config(clicon_handle h,
- char *username,
- char *db,
- char *xpath,
- cvec *nsc,
- char *defaults,
- cxobj **xt)
+ char *username,
+ char *db,
+ char *xpath,
+ cvec *nsc,
+ char *defaults,
+ cxobj **xt)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -505,84 +509,84 @@ clicon_rpc_get_config(clicon_handle h,
cvec *nscd = NULL;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
if ((cb = cbuf_new()) == NULL)
- goto done;
+ goto done;
cprintf(cb, "<%s/> ", db);
if (xpath && strlen(xpath)){
- cprintf(cb, "<%s:filter %s:type=\"xpath\" %s:select=\"%s\"",
- NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX,
- xpath);
- if (xml_nsctx_cbuf(cb, nsc) < 0)
- goto done;
- cprintf(cb, "/>");
+ cprintf(cb, "<%s:filter %s:type=\"xpath\" %s:select=\"%s\"",
+ NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX,
+ xpath);
+ if (xml_nsctx_cbuf(cb, nsc) < 0)
+ goto done;
+ cprintf(cb, "/>");
}
if (defaults != NULL)
- cprintf(cb, "%s ",
- IETF_NETCONF_WITH_DEFAULTS_YANG_NAMESPACE,
- defaults);
+ cprintf(cb, "%s ",
+ IETF_NETCONF_WITH_DEFAULTS_YANG_NAMESPACE,
+ defaults);
cprintf(cb, " ");
if ((msg = clicon_msg_encode(session_id, "%s", cbuf_get(cb))) == NULL)
- goto done;
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
yspec = clicon_dbspec_yang(h);
/* Send xml error back: first check error, then ok */
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL)
- xd = xml_parent(xd); /* point to rpc-reply */
+ xd = xml_parent(xd); /* point to rpc-reply */
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL){
- if ((xd = xml_new(NETCONF_OUTPUT_DATA, NULL, CX_ELMNT)) == NULL)
- goto done;
- if (xml_bind_special(xd, yspec, "/nc:get-config/output/data") < 0)
- goto done;
+ if ((xd = xml_new(NETCONF_OUTPUT_DATA, NULL, CX_ELMNT)) == NULL)
+ goto done;
+ if (xml_bind_special(xd, yspec, "/nc:get-config/output/data") < 0)
+ goto done;
}
else{
- if (xml_bind_special(xd, yspec, "/nc:get-config/output/data") < 0)
- goto done;
- if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0)
- goto done;
- if (ret == 0){
- if (clixon_netconf_internal_error(xerr,
- ". Internal error, backend returned invalid XML.",
- NULL) < 0)
- goto done;
- if ((xd = xpath_first(xerr, NULL, "rpc-error")) == NULL){
- clicon_err(OE_XML, ENOENT, "Expected rpc-error tag but none found(internal)");
- goto done;
- }
- }
+ if (xml_bind_special(xd, yspec, "/nc:get-config/output/data") < 0)
+ goto done;
+ if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ if (clixon_netconf_internal_error(xerr,
+ ". Internal error, backend returned invalid XML.",
+ NULL) < 0)
+ goto done;
+ if ((xd = xpath_first(xerr, NULL, "rpc-error")) == NULL){
+ clicon_err(OE_XML, ENOENT, "Expected rpc-error tag but none found(internal)");
+ goto done;
+ }
+ }
}
if (xt && xd){
- /* Sync namespaces, ie explicitly set all xmlns attributes to xd */
- if (xml_nsctx_node(xd, &nscd) < 0)
- goto done;
- if (xml_rm(xd) < 0)
- goto done;
- if (xmlns_set_all(xd, nscd) < 0)
- goto done;
- xml_sort(xd); /* Ensure attr is first */
- *xt = xd;
+ /* Sync namespaces, ie explicitly set all xmlns attributes to xd */
+ if (xml_nsctx_node(xd, &nscd) < 0)
+ goto done;
+ if (xml_rm(xd) < 0)
+ goto done;
+ if (xmlns_set_all(xd, nscd) < 0)
+ goto done;
+ xml_sort(xd); /* Ensure attr is first */
+ *xt = xd;
}
retval = 0;
done:
if (nscd)
- cvec_free(nscd);
+ cvec_free(nscd);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -602,9 +606,9 @@ clicon_rpc_get_config(clicon_handle h,
*/
int
clicon_rpc_edit_config(clicon_handle h,
- char *db,
- enum operation_type op,
- char *xmlstr)
+ char *db,
+ enum operation_type op,
+ char *xmlstr)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -615,36 +619,36 @@ clicon_rpc_edit_config(clicon_handle h,
uint32_t session_id;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
if ((cb = cbuf_new()) == NULL)
- goto done;
+ goto done;
cprintf(cb, "<%s/> ", db);
cprintf(cb, "%s ",
- xml_operation2str(op));
+ xml_operation2str(op));
if (xmlstr)
- cprintf(cb, "%s", xmlstr);
+ cprintf(cb, "%s", xmlstr);
cprintf(cb, " ");
if ((msg = clicon_msg_encode(session_id, "%s", cbuf_get(cb))) == NULL)
- goto done;
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Editing configuration", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Editing configuration", NULL);
+ goto done;
}
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -663,8 +667,8 @@ clicon_rpc_edit_config(clicon_handle h,
*/
int
clicon_rpc_copy_config(clicon_handle h,
- char *db1,
- char *db2)
+ char *db1,
+ char *db2)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -674,28 +678,28 @@ clicon_rpc_copy_config(clicon_handle h,
uint32_t session_id;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(session_id,
- ""
- "<%s/> <%s/> ",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_MESSAGE_ID_ATTR,
- db1, db2)) == NULL)
- goto done;
+ ""
+ "<%s/> <%s/> ",
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_MESSAGE_ID_ATTR,
+ db1, db2)) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Copying configuration", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Copying configuration", NULL);
+ goto done;
}
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -711,7 +715,7 @@ clicon_rpc_copy_config(clicon_handle h,
*/
int
clicon_rpc_delete_config(clicon_handle h,
- char *db)
+ char *db)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -721,28 +725,28 @@ clicon_rpc_delete_config(clicon_handle h,
uint32_t session_id;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(session_id,
- ""
- "<%s/> none ",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_MESSAGE_ID_ATTR,
- db)) == NULL)
- goto done;
+ ""
+ "<%s/> none ",
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_MESSAGE_ID_ATTR,
+ db)) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Deleting configuration", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Deleting configuration", NULL);
+ goto done;
}
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -754,7 +758,7 @@ clicon_rpc_delete_config(clicon_handle h,
*/
int
clicon_rpc_lock(clicon_handle h,
- char *db)
+ char *db)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -764,28 +768,28 @@ clicon_rpc_lock(clicon_handle h,
uint32_t session_id;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(session_id,
- ""
- "<%s/> ",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_MESSAGE_ID_ATTR,
- db)) == NULL)
- goto done;
+ ""
+ "<%s/> ",
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_MESSAGE_ID_ATTR,
+ db)) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Locking configuration", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Locking configuration", NULL);
+ goto done;
}
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -797,7 +801,7 @@ clicon_rpc_lock(clicon_handle h,
*/
int
clicon_rpc_unlock(clicon_handle h,
- char *db)
+ char *db)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -807,28 +811,28 @@ clicon_rpc_unlock(clicon_handle h,
uint32_t session_id;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(session_id,
- ""
- "<%s/> ",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_MESSAGE_ID_ATTR,
- db)) == NULL)
- goto done;
+ ""
+ "<%s/> ",
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_MESSAGE_ID_ATTR,
+ db)) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Configuration unlock", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Configuration unlock", NULL);
+ goto done;
}
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -869,12 +873,12 @@ clicon_rpc_unlock(clicon_handle h,
*/
int
clicon_rpc_get(clicon_handle h,
- char *xpath,
- cvec *nsc, /* namespace context for filter */
- netconf_content content,
- int32_t depth,
- char *defaults,
- cxobj **xt)
+ char *xpath,
+ cvec *nsc, /* namespace context for filter */
+ netconf_content content,
+ int32_t depth,
+ char *defaults,
+ cxobj **xt)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -889,89 +893,89 @@ clicon_rpc_get(clicon_handle h,
cvec *nscd = NULL;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
if ((cb = cbuf_new()) == NULL)
- goto done;
+ goto done;
cprintf(cb, " */
if (depth != -1)
- cprintf(cb, " depth=\"%d\"", depth);
+ cprintf(cb, " depth=\"%d\"", depth);
cprintf(cb, ">"); /* get */
/* If xpath, add a filter */
if (xpath && strlen(xpath)) {
- cprintf(cb, "<%s:filter %s:type=\"xpath\" %s:select=\"%s\"",
- NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX,
- xpath);
- if (xml_nsctx_cbuf(cb, nsc) < 0)
- goto done;
- cprintf(cb, "/>");
+ cprintf(cb, "<%s:filter %s:type=\"xpath\" %s:select=\"%s\"",
+ NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX,
+ xpath);
+ if (xml_nsctx_cbuf(cb, nsc) < 0)
+ goto done;
+ cprintf(cb, "/>");
}
if (defaults != NULL)
- cprintf(cb, "%s ",
- IETF_NETCONF_WITH_DEFAULTS_YANG_NAMESPACE,
- defaults);
+ cprintf(cb, "%s ",
+ IETF_NETCONF_WITH_DEFAULTS_YANG_NAMESPACE,
+ defaults);
cprintf(cb, " ");
if ((msg = clicon_msg_encode(session_id,
- "%s", cbuf_get(cb))) == NULL)
- goto done;
+ "%s", cbuf_get(cb))) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
yspec = clicon_dbspec_yang(h);
/* Send xml error back: first check error, then ok */
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL)
- xd = xml_parent(xd); /* point to rpc-reply */
+ xd = xml_parent(xd); /* point to rpc-reply */
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL){
- if ((xd = xml_new(NETCONF_OUTPUT_DATA, NULL, CX_ELMNT)) == NULL)
- goto done;
- if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0)
- goto done;
+ if ((xd = xml_new(NETCONF_OUTPUT_DATA, NULL, CX_ELMNT)) == NULL)
+ goto done;
+ if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0)
+ goto done;
}
else{
- if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0)
- goto done;
- if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0)
- goto done;
- if (ret == 0){
- if (clixon_netconf_internal_error(xerr,
- ". Internal error, backend returned invalid XML.",
- NULL) < 0)
- goto done;
- xd = xerr;
- xerr = NULL;
- }
+ if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0)
+ goto done;
+ if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ if (clixon_netconf_internal_error(xerr,
+ ". Internal error, backend returned invalid XML.",
+ NULL) < 0)
+ goto done;
+ xd = xerr;
+ xerr = NULL;
+ }
}
if (xt && xd){
- /* Sync namespaces, ie explicitly set all xmlns attributes to xd */
- if (xml_nsctx_node(xd, &nscd) < 0)
- goto done;
- if (xml_rm(xd) < 0)
- goto done;
- if (xmlns_set_all(xd, nscd) < 0)
- goto done;
- xml_sort(xd); /* Ensure attr is first */
- *xt = xd;
+ /* Sync namespaces, ie explicitly set all xmlns attributes to xd */
+ if (xml_nsctx_node(xd, &nscd) < 0)
+ goto done;
+ if (xml_rm(xd) < 0)
+ goto done;
+ if (xmlns_set_all(xd, nscd) < 0)
+ goto done;
+ xml_sort(xd); /* Ensure attr is first */
+ *xt = xd;
}
retval = 0;
done:
if (nscd)
- cvec_free(nscd);
+ cvec_free(nscd);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -998,18 +1002,18 @@ clicon_rpc_get(clicon_handle h,
*/
int
clicon_rpc_get_pageable_list(clicon_handle h,
- char *datastore,
- char *xpath,
- cvec *nsc, /* namespace context for xpath */
- netconf_content content,
- int32_t depth,
- char *defaults,
- uint32_t offset,
- uint32_t limit,
- char *direction,
- char *sort,
- char *where,
- cxobj **xt)
+ char *datastore,
+ char *xpath,
+ cvec *nsc, /* namespace context for xpath */
+ netconf_content content,
+ int32_t depth,
+ char *defaults,
+ uint32_t offset,
+ uint32_t limit,
+ char *direction,
+ char *sort,
+ char *where,
+ cxobj **xt)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -1024,109 +1028,109 @@ clicon_rpc_get_pageable_list(clicon_handle h,
cvec *nscd = NULL;
if (datastore == NULL){
- clicon_err(OE_XML, EINVAL, "datastore not given");
- goto done;
+ clicon_err(OE_XML, EINVAL, "datastore not given");
+ goto done;
}
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
if ((cb = cbuf_new()) == NULL)
- goto done;
+ goto done;
cprintf(cb, " */
if (depth != -1)
- cprintf(cb, " depth=\"%d\"", depth);
+ cprintf(cb, " depth=\"%d\"", depth);
/* declare lp prefix in get, so sub-elements dont need to */
cprintf(cb, ">"); /* get */
/* If xpath, add a filter */
if (xpath && strlen(xpath)) {
- cprintf(cb, "<%s:filter %s:type=\"xpath\" %s:select=\"%s\"",
- NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX,
- xpath);
- if (xml_nsctx_cbuf(cb, nsc) < 0)
- goto done;
- cprintf(cb, "/>");
+ cprintf(cb, "<%s:filter %s:type=\"xpath\" %s:select=\"%s\"",
+ NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX,
+ xpath);
+ if (xml_nsctx_cbuf(cb, nsc) < 0)
+ goto done;
+ cprintf(cb, "/>");
}
if (defaults != NULL)
- cprintf(cb, "%s ",
- IETF_NETCONF_WITH_DEFAULTS_YANG_NAMESPACE,
- defaults);
+ cprintf(cb, "%s ",
+ IETF_NETCONF_WITH_DEFAULTS_YANG_NAMESPACE,
+ defaults);
/* Explicit use of list-pagination */
cprintf(cb, "", IETF_PAGINATON_NC_NAMESPACE);
if (offset != 0)
- cprintf(cb, "%u ", offset);
+ cprintf(cb, "%u ", offset);
if (limit != 0)
- cprintf(cb, "%u ", limit);
+ cprintf(cb, "%u ", limit);
if (direction)
- cprintf(cb, "%s ", direction);
+ cprintf(cb, "%s ", direction);
if (sort)
- cprintf(cb, "%s ", sort);
+ cprintf(cb, "%s ", sort);
if (where)
- cprintf(cb, "%s ", where);
+ cprintf(cb, "%s ", where);
cprintf(cb, " ");
cprintf(cb, " ");
cprintf(cb, " ");
if ((msg = clicon_msg_encode(session_id, "%s", cbuf_get(cb))) == NULL)
- goto done;
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
yspec = clicon_dbspec_yang(h);
/* Send xml error back: first check error, then ok */
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL)
- xd = xml_parent(xd); /* point to rpc-reply */
+ xd = xml_parent(xd); /* point to rpc-reply */
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL){
- if ((xd = xml_new(NETCONF_OUTPUT_DATA, NULL, CX_ELMNT)) == NULL)
- goto done;
- if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0)
- goto done;
+ if ((xd = xml_new(NETCONF_OUTPUT_DATA, NULL, CX_ELMNT)) == NULL)
+ goto done;
+ if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0)
+ goto done;
}
else{
- if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0)
- goto done;
- if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0)
- goto done;
- if (ret == 0){
- if (clixon_netconf_internal_error(xerr,
- ". Internal error, backend returned invalid XML.",
- NULL) < 0)
- goto done;
- if ((xd = xpath_first(xerr, NULL, "rpc-error")) == NULL){
- clicon_err(OE_XML, ENOENT, "Expected rpc-error tag but none found(internal)");
- goto done;
- }
- }
+ if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0)
+ goto done;
+ if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0)
+ goto done;
+ if (ret == 0){
+ if (clixon_netconf_internal_error(xerr,
+ ". Internal error, backend returned invalid XML.",
+ NULL) < 0)
+ goto done;
+ if ((xd = xpath_first(xerr, NULL, "rpc-error")) == NULL){
+ clicon_err(OE_XML, ENOENT, "Expected rpc-error tag but none found(internal)");
+ goto done;
+ }
+ }
}
if (xt && xd){
- /* Sync namespaces, ie explicitly set all xmlns attributes to xd */
- if (xml_nsctx_node(xd, &nscd) < 0)
- goto done;
- if (xml_rm(xd) < 0)
- goto done;
- if (xmlns_set_all(xd, nscd) < 0)
- goto done;
- xml_sort(xd); /* Ensure attr is first */
- *xt = xd;
+ /* Sync namespaces, ie explicitly set all xmlns attributes to xd */
+ if (xml_nsctx_node(xd, &nscd) < 0)
+ goto done;
+ if (xml_rm(xd) < 0)
+ goto done;
+ if (xmlns_set_all(xd, nscd) < 0)
+ goto done;
+ xml_sort(xd); /* Ensure attr is first */
+ *xt = xd;
}
retval = 0;
done:
if (nscd)
- cvec_free(nscd);
+ cvec_free(nscd);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (xerr)
- xml_free(xerr);
+ xml_free(xerr);
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -1150,29 +1154,29 @@ clicon_rpc_close_session(clicon_handle h)
int s;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(session_id,
- " ",
- NETCONF_BASE_NAMESPACE, username?username:"",
- NETCONF_MESSAGE_ID_ATTR)) == NULL)
- goto done;
+ " ",
+ NETCONF_BASE_NAMESPACE, username?username:"",
+ NETCONF_MESSAGE_ID_ATTR)) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((s = clicon_client_socket_get(h)) >= 0){
- close(s);
- clicon_client_socket_set(h, -1);
+ close(s);
+ clicon_client_socket_set(h, -1);
}
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Close session", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Close session", NULL);
+ goto done;
}
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -1184,7 +1188,7 @@ clicon_rpc_close_session(clicon_handle h)
*/
int
clicon_rpc_kill_session(clicon_handle h,
- uint32_t session_id)
+ uint32_t session_id)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -1194,39 +1198,41 @@ clicon_rpc_kill_session(clicon_handle h,
uint32_t my_session_id; /* Not the one to kill */
if (session_id_check(h, &my_session_id) < 0)
- goto done;
+ goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(my_session_id,
- "%u ",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_MESSAGE_ID_ATTR,
- session_id)) == NULL)
- goto done;
+ "%u ",
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_MESSAGE_ID_ATTR,
+ session_id)) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Kill session", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Kill session", NULL);
+ goto done;
}
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
/*! Send validate request to backend daemon
* @param[in] h CLICON handle
* @param[in] db Name of database
- * @retval 0 OK
+ * @retval 1 OK
+ * @retval 0 Invalid, netconf error return, and logged to syslog
* @retval -1 Error and logged to syslog
+ * @note error returns are logged but not returned
*/
int
clicon_rpc_validate(clicon_handle h,
- char *db)
+ char *db)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -1236,37 +1242,51 @@ clicon_rpc_validate(clicon_handle h,
uint32_t session_id;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(session_id,
- "<%s/> ",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_MESSAGE_ID_ATTR,
- db)) == NULL)
- goto done;
+ "<%s/> ",
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_MESSAGE_ID_ATTR,
+ db)) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, CLIXON_ERRSTR_VALIDATE_FAILED, NULL);
- goto done;
+ clixon_netconf_error(xerr, CLIXON_ERRSTR_VALIDATE_FAILED, NULL);
+ retval = 0;
+ goto done;
}
- retval = 0;
+ retval = 1;
done:
if (msg)
- free(msg);
+ free(msg);
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
/*! Commit changes send a commit request to backend daemon
* @param[in] h CLICON handle
- * @retval 0 OK
- * @retval -1 Error and logged to syslog
+ * @param[in] confirmed If set, send commit/confirmed
+ * @param[in] cancel If set, send cancle-commit
+ * @param[in] timeout For confirmed, a timeout in seconds (default 600s)
+ * @param[in] persist A persist identifier to use
+ * @param[in] persist_id If cancel or confirmed, the persist id
+ * @retval 1 OK
+ * @retval 0 Invalid, netconf error return, and logged to syslog
+ * @retval -1 Error
+ * @see rfc6241 Sec 8.4 Confirmed Commit Capability
+ * @note error returns are logged but not returned
*/
int
-clicon_rpc_commit(clicon_handle h)
+clicon_rpc_commit(clicon_handle h,
+ int confirmed,
+ int cancel,
+ uint32_t timeout,
+ char *persist,
+ char *persist_id)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -1274,28 +1294,83 @@ clicon_rpc_commit(clicon_handle h)
cxobj *xerr;
char *username;
uint32_t session_id;
-
- if (session_id_check(h, &session_id) < 0)
- goto done;
- username = clicon_username_get(h);
- if ((msg = clicon_msg_encode(session_id,
- " ",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_MESSAGE_ID_ATTR)) == NULL)
- goto done;
- if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
- if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, CLIXON_ERRSTR_COMMIT_FAILED, NULL);
- goto done;
+ char *persist_id_xml = NULL;
+ char *persist_xml = NULL;
+ char *timeout_xml = NULL;
+
+ if (persist_id) {
+ if ((persist_id_xml = malloc(strlen(persist_id) + strlen(PERSIST_ID_XML_FMT) + 1)) == NULL) {
+ clicon_err(OE_UNIX, 0, "malloc: %s", strerror(errno));
+ }
+ sprintf(persist_id_xml, PERSIST_ID_XML_FMT, persist_id);
}
- retval = 0;
+
+ if (persist) {
+ if ((persist_xml = malloc(strlen(persist) + strlen(PERSIST_XML_FMT) + 1)) == NULL) {
+ clicon_err(OE_UNIX, 0, "malloc: %s", strerror(errno));
+ };
+ sprintf(persist_xml, PERSIST_XML_FMT, persist);
+ }
+
+ if (timeout > 0) {
+
+ /* timeout is a uint32_t, so max value is 2^32, a 10-digit number, we'll just always malloc for a string that
+ * may be that large rather than calculate the string length
+ */
+
+ if ((timeout_xml = malloc(10 + 1 + strlen(TIMEOUT_XML_FMT))) == NULL) {
+ clicon_err(OE_UNIX, 0, "malloc: %s", strerror(errno));
+ };
+ sprintf(timeout_xml, TIMEOUT_XML_FMT, timeout);
+ }
+ if (session_id_check(h, &session_id) < 0)
+ goto done;
+ username = clicon_username_get(h);
+ if (cancel) {
+ msg = clicon_msg_encode(session_id,
+ "%s ",
+ NETCONF_BASE_NAMESPACE,
+ username ? username : "",
+ NETCONF_MESSAGE_ID_ATTR,
+ persist_id ? persist_id_xml : "");
+ } else if (confirmed) {
+ msg = clicon_msg_encode(session_id,
+ " %s%s%s ",
+ NETCONF_BASE_NAMESPACE,
+ username ? username : "",
+ NETCONF_MESSAGE_ID_ATTR,
+ timeout ? timeout_xml : "",
+ persist_id ? persist_id_xml : "",
+ persist ? persist_xml : "");
+ } else {
+ msg = clicon_msg_encode(session_id,
+ "%s ",
+ NETCONF_BASE_NAMESPACE,
+ username ? username : "",
+ NETCONF_MESSAGE_ID_ATTR,
+ persist ? persist_xml : "");
+ }
+ if (msg == NULL)
+ goto done;
+ if (clicon_rpc_msg(h, msg, &xret) < 0)
+ goto done;
+ if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
+ clixon_netconf_error(xerr, CLIXON_ERRSTR_COMMIT_FAILED, NULL);
+ retval = 0;
+ goto done;
+ }
+ retval = 1;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- free(msg);
+ free(msg);
+ if (persist_id_xml)
+ free(persist_id_xml);
+ if (persist_xml)
+ free(persist_xml);
+ if (timeout_xml)
+ free(timeout_xml);
return retval;
}
@@ -1315,26 +1390,26 @@ clicon_rpc_discard_changes(clicon_handle h)
uint32_t session_id;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(session_id,
- " ",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_MESSAGE_ID_ATTR)) == NULL)
- goto done;
+ " ",
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_MESSAGE_ID_ATTR)) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Discard changes", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Discard changes", NULL);
+ goto done;
}
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -1350,9 +1425,9 @@ clicon_rpc_discard_changes(clicon_handle h)
*/
int
clicon_rpc_create_subscription(clicon_handle h,
- char *stream,
- char *filter,
- int *s0)
+ char *stream,
+ char *filter,
+ int *s0)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -1362,31 +1437,31 @@ clicon_rpc_create_subscription(clicon_handle h,
uint32_t session_id;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(session_id,
- ""
- "%s "
- " "
- " ",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_MESSAGE_ID_ATTR,
- EVENT_RFC5277_NAMESPACE,
- stream?stream:"", filter?filter:"")) == NULL)
- goto done;
+ ""
+ "%s "
+ " "
+ " ",
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_MESSAGE_ID_ATTR,
+ EVENT_RFC5277_NAMESPACE,
+ stream?stream:"", filter?filter:"")) == NULL)
+ goto done;
if (clicon_rpc_msg_persistent(h, msg, &xret, s0) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Create subscription", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Create subscription", NULL);
+ goto done;
}
retval = 0;
done:
if (xret)
- xml_free(xret);
+ xml_free(xret);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -1398,7 +1473,7 @@ clicon_rpc_create_subscription(clicon_handle h,
*/
int
clicon_rpc_debug(clicon_handle h,
- int level)
+ int level)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -1408,32 +1483,32 @@ clicon_rpc_debug(clicon_handle h,
uint32_t session_id;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(session_id,
- "%d ",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_MESSAGE_ID_ATTR,
- CLIXON_LIB_NS,
- level)) == NULL)
- goto done;
+ "%d ",
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_MESSAGE_ID_ATTR,
+ CLIXON_LIB_NS,
+ level)) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Debug", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Debug", NULL);
+ goto done;
}
if (xpath_first(xret, NULL, "//rpc-reply/ok") == NULL){
- clicon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
- goto done;
+ clicon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
+ goto done;
}
retval = 0;
done:
if (msg)
- free(msg);
+ free(msg);
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -1449,7 +1524,7 @@ clicon_rpc_debug(clicon_handle h,
*/
int
clicon_rpc_restconf_debug(clicon_handle h,
- int level)
+ int level)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -1459,33 +1534,33 @@ clicon_rpc_restconf_debug(clicon_handle h,
uint32_t session_id;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(session_id,
- "%d ",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_MESSAGE_ID_ATTR,
- CLIXON_RESTCONF_NS,
- level)) == NULL)
- goto done;
+ "%d ",
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_MESSAGE_ID_ATTR,
+ CLIXON_RESTCONF_NS,
+ level)) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Debug", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Debug", NULL);
+ goto done;
}
if (xpath_first(xret, NULL, "//rpc-reply/ok") == NULL){
- clicon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
- goto done;
+ clicon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
+ goto done;
}
- if ((retval = clicon_rpc_commit(h)) < 0)
- goto done;
+ if ((retval = clicon_rpc_commit(h, 0, 0, 0, NULL, NULL)) < 1)
+ goto done;
done:
if (msg)
- free(msg);
+ free(msg);
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -1500,7 +1575,7 @@ clicon_rpc_restconf_debug(clicon_handle h,
*/
int
clicon_hello_req(clicon_handle h,
- uint32_t *id)
+ uint32_t *id)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -1513,31 +1588,31 @@ clicon_hello_req(clicon_handle h,
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(0, "%s ",
- username?username:"",
- NETCONF_BASE_NAMESPACE,
- NETCONF_BASE_CAPABILITY_1_1)) == NULL)
- goto done;
+ username?username:"",
+ NETCONF_BASE_NAMESPACE,
+ NETCONF_BASE_CAPABILITY_1_1)) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Hello", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Hello", NULL);
+ goto done;
}
if ((x = xpath_first(xret, NULL, "hello/session-id")) == NULL){
- clicon_err(OE_XML, 0, "hello session-id");
- goto done;
+ clicon_err(OE_XML, 0, "hello session-id");
+ goto done;
}
b = xml_body(x);
if ((ret = parse_uint32(b, id, NULL)) <= 0){
- clicon_err(OE_XML, errno, "parse_uint32");
- goto done;
+ clicon_err(OE_XML, errno, "parse_uint32");
+ goto done;
}
retval = 0;
done:
if (msg)
- free(msg);
+ free(msg);
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
@@ -1549,7 +1624,7 @@ clicon_hello_req(clicon_handle h,
*/
int
clicon_rpc_restart_plugin(clicon_handle h,
- char *plugin)
+ char *plugin)
{
int retval = -1;
struct clicon_msg *msg = NULL;
@@ -1559,31 +1634,31 @@ clicon_rpc_restart_plugin(clicon_handle h,
uint32_t session_id;
if (session_id_check(h, &session_id) < 0)
- goto done;
+ goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(session_id,
- "%s ",
- NETCONF_BASE_NAMESPACE,
- username?username:"",
- NETCONF_MESSAGE_ID_ATTR,
- CLIXON_LIB_NS,
- plugin)) == NULL)
- goto done;
+ "%s ",
+ NETCONF_BASE_NAMESPACE,
+ username?username:"",
+ NETCONF_MESSAGE_ID_ATTR,
+ CLIXON_LIB_NS,
+ plugin)) == NULL)
+ goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
- goto done;
+ goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
- clixon_netconf_error(xerr, "Debug", NULL);
- goto done;
+ clixon_netconf_error(xerr, "Debug", NULL);
+ goto done;
}
if (xpath_first(xret, NULL, "//rpc-reply/ok") == NULL){
- clicon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
- goto done;
+ clicon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
+ goto done;
}
retval = 0;
done:
if (msg)
- free(msg);
+ free(msg);
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
}
diff --git a/lib/src/clixon_regex.c b/lib/src/clixon_regex.c
index 9e25d56b..a5a57ffa 100644
--- a/lib/src/clixon_regex.c
+++ b/lib/src/clixon_regex.c
@@ -93,7 +93,7 @@
*/
int
regexp_xsd2posix(char *xsd,
- char **posix)
+ char **posix)
{
int retval = -1;
cbuf *cb = NULL;
@@ -105,111 +105,111 @@ regexp_xsd2posix(char *xsd,
size_t len;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
esc=0;
len = strlen(xsd);
for (i=0; i 1) {
- if (kill(pid, 0) == 0 || errno != ESRCH) {
- /* Yes there is a process */
- *pid0 = pid;
- }
+ if (kill(pid, 0) == 0 || errno != ESRCH) {
+ /* Yes there is a process */
+ *pid0 = pid;
+ }
}
return 0;
}
@@ -208,14 +208,14 @@ pidfile_get_fd(FILE *f,
*/
int
pidfile_get(char *pidfile,
- pid_t *pid)
+ pid_t *pid)
{
FILE *f;
*pid = 0;
if ((f = fopen(pidfile, "r")) != NULL){
- pidfile_get_fd(f, pid);
- fclose(f);
+ pidfile_get_fd(f, pid);
+ fclose(f);
}
return 0;
}
@@ -264,20 +264,20 @@ pidfile_write(char *pidfile)
/* Here, there should be no old agent and no pidfile */
if ((f = fopen(pidfile, "w")) == NULL){
- if (errno == EACCES)
- clicon_err(OE_DAEMON, errno, "Creating pid-file %s (Try run as root?)", pidfile);
- else
- clicon_err(OE_DAEMON, errno, "Creating pid-file %s", pidfile);
- goto done;
+ if (errno == EACCES)
+ clicon_err(OE_DAEMON, errno, "Creating pid-file %s (Try run as root?)", pidfile);
+ else
+ clicon_err(OE_DAEMON, errno, "Creating pid-file %s", pidfile);
+ goto done;
}
if ((retval = fprintf(f, "%ld\n", (long) getpid())) < 1){
- clicon_err(OE_DAEMON, errno, "Could not write pid to %s", pidfile);
- goto done;
+ clicon_err(OE_DAEMON, errno, "Could not write pid to %s", pidfile);
+ goto done;
}
clicon_debug(1, "Opened pidfile %s with pid %d", pidfile, getpid());
retval = 0;
done:
if (f != NULL)
- fclose(f);
+ fclose(f);
return retval;
}
diff --git a/lib/src/clixon_stream.c b/lib/src/clixon_stream.c
index 331257a2..b141757c 100644
--- a/lib/src/clixon_stream.c
+++ b/lib/src/clixon_stream.c
@@ -97,18 +97,18 @@
*/
event_stream_t *
stream_find(clicon_handle h,
- const char *name)
+ const char *name)
{
event_stream_t *es0;
event_stream_t *es = NULL;
es0 = clicon_stream(h);
if ((es = es0) != NULL)
- do {
- if (strcmp(name, es->es_name)==0)
- return es;
- es = NEXTQ(struct event_stream *, es);
- } while (es && es != es0);
+ do {
+ if (strcmp(name, es->es_name)==0)
+ return es;
+ es = NEXTQ(struct event_stream *, es);
+ } while (es && es != es0);
return NULL;
}
@@ -121,32 +121,32 @@ stream_find(clicon_handle h,
*/
int
stream_add(clicon_handle h,
- const char *name,
- const char *description,
- const int replay_enabled,
- struct timeval *retention)
+ const char *name,
+ const char *description,
+ const int replay_enabled,
+ struct timeval *retention)
{
int retval = -1;
event_stream_t *es;
if ((es = stream_find(h, name)) != NULL)
- goto ok;
+ goto ok;
if ((es = malloc(sizeof(event_stream_t))) == NULL){
- clicon_err(OE_XML, errno, "malloc");
- goto done;
+ clicon_err(OE_XML, errno, "malloc");
+ goto done;
}
memset(es, 0, sizeof(event_stream_t));
if ((es->es_name = strdup(name)) == NULL){
- clicon_err(OE_XML, errno, "strdup");
- goto done;
+ clicon_err(OE_XML, errno, "strdup");
+ goto done;
}
if ((es->es_description = strdup(description)) == NULL){
- clicon_err(OE_XML, errno, "strdup");
- goto done;
+ clicon_err(OE_XML, errno, "strdup");
+ goto done;
}
es->es_replay_enabled = replay_enabled;
if (retention)
- es->es_retention = *retention;
+ es->es_retention = *retention;
clicon_stream_append(h, es);
ok:
retval = 0;
@@ -160,7 +160,7 @@ stream_add(clicon_handle h,
*/
int
stream_delete_all(clicon_handle h,
- int force)
+ int force)
{
struct stream_replay *r;
struct stream_subscription *ss;
@@ -168,21 +168,21 @@ stream_delete_all(clicon_handle h,
event_stream_t *head = clicon_stream(h);
while ((es = clicon_stream(h)) != NULL){
- DELQ(es, head, event_stream_t *);
- clicon_stream_set(h, head);
- if (es->es_name)
- free(es->es_name);
- if (es->es_description)
- free(es->es_description);
- while ((ss = es->es_subscription) != NULL)
- stream_ss_rm(h, es, ss, force); /* XXX in some cases leaks memory due to DONT clause in stream_ss_rm() */
- while ((r = es->es_replay) != NULL){
- DELQ(r, es->es_replay, struct stream_replay *);
- if (r->r_xml)
- xml_free(r->r_xml);
- free(r);
- }
- free(es);
+ DELQ(es, head, event_stream_t *);
+ clicon_stream_set(h, head);
+ if (es->es_name)
+ free(es->es_name);
+ if (es->es_description)
+ free(es->es_description);
+ while ((ss = es->es_subscription) != NULL)
+ stream_ss_rm(h, es, ss, force); /* XXX in some cases leaks memory due to DONT clause in stream_ss_rm() */
+ while ((r = es->es_replay) != NULL){
+ DELQ(r, es->es_replay, struct stream_replay *);
+ if (r->r_xml)
+ xml_free(r->r_xml);
+ free(r);
+ }
+ free(es);
}
return 0;
}
@@ -196,8 +196,8 @@ stream_delete_all(clicon_handle h,
*/
int
stream_get_xml(clicon_handle h,
- int access,
- cbuf *cb)
+ int access,
+ cbuf *cb)
{
event_stream_t *es = NULL;
char *url_prefix;
@@ -205,25 +205,25 @@ stream_get_xml(clicon_handle h,
cprintf(cb, "");
if ((es = clicon_stream(h)) != NULL){
- do {
- cprintf(cb, "");
- cprintf(cb, "%s ", es->es_name);
- if (es->es_description)
- cprintf(cb, "%s ", es->es_description);
- cprintf(cb, "%s ",
- es->es_replay_enabled?"true":"false");
- if (access){
- cprintf(cb, "");
- cprintf(cb, "xml ");
- url_prefix = clicon_option_str(h, "CLICON_STREAM_URL");
- stream_path = clicon_option_str(h, "CLICON_STREAM_PATH");
- cprintf(cb, "%s/%s/%s ",
- url_prefix, stream_path, es->es_name);
- cprintf(cb, " ");
- }
- cprintf(cb, " ");
- es = NEXTQ(struct event_stream *, es);
- } while (es && es != clicon_stream(h));
+ do {
+ cprintf(cb, "");
+ cprintf(cb, "%s ", es->es_name);
+ if (es->es_description)
+ cprintf(cb, "%s ", es->es_description);
+ cprintf(cb, "%s ",
+ es->es_replay_enabled?"true":"false");
+ if (access){
+ cprintf(cb, "");
+ cprintf(cb, "xml ");
+ url_prefix = clicon_option_str(h, "CLICON_STREAM_URL");
+ stream_path = clicon_option_str(h, "CLICON_STREAM_PATH");
+ cprintf(cb, "%s/%s/%s ",
+ url_prefix, stream_path, es->es_name);
+ cprintf(cb, " ");
+ }
+ cprintf(cb, " ");
+ es = NEXTQ(struct event_stream *, es);
+ } while (es && es != clicon_stream(h));
}
cprintf(cb, " ");
return 0;
@@ -236,7 +236,7 @@ stream_get_xml(clicon_handle h,
*/
int
stream_timer_setup(int fd,
- void *arg)
+ void *arg)
{
int retval = -1;
clicon_handle h = (clicon_handle)arg;
@@ -261,47 +261,47 @@ stream_timer_setup(int fd,
* 2) Go throughreplay buffer and remove entries with passed retention time
*/
if ((es = clicon_stream(h)) != NULL){
- do {
+ do {
/* 1) Go through subscriptions, if stop-time and its past, remove it */
- if ((ss = es->es_subscription) != NULL)
- do {
- if (timerisset(&ss->ss_stoptime) && timercmp(&ss->ss_stoptime, &now, <)){
- ss1 = NEXTQ(struct stream_subscription *, ss);
- /* Signal to remove stream for upper levels */
- if (stream_ss_rm(h, es, ss, 0) < 0)
- goto done;
- ss = ss1;
- }
- else
- ss = NEXTQ(struct stream_subscription *, ss);
- } while (ss && ss != es->es_subscription);
+ if ((ss = es->es_subscription) != NULL)
+ do {
+ if (timerisset(&ss->ss_stoptime) && timercmp(&ss->ss_stoptime, &now, <)){
+ ss1 = NEXTQ(struct stream_subscription *, ss);
+ /* Signal to remove stream for upper levels */
+ if (stream_ss_rm(h, es, ss, 0) < 0)
+ goto done;
+ ss = ss1;
+ }
+ else
+ ss = NEXTQ(struct stream_subscription *, ss);
+ } while (ss && ss != es->es_subscription);
/* 2) Go throughreplay buffer and remove entries with passed retention time */
- if (timerisset(&es->es_retention) &&
- (r = es->es_replay) != NULL){
- timersub(&now, &es->es_retention, &tret);
- do {
- if (timercmp(&r->r_tv, &tret, <)){
- r1 = NEXTQ(struct stream_replay *, r);
- DELQ(r, es->es_replay, struct stream_replay *);
- if (r->r_xml)
- xml_free(r->r_xml);
- free(r);
- r = r1;
- }
- else
- r = NEXTQ(struct stream_replay *, r);
- } while (r && r!=es->es_replay);
- }
- es = NEXTQ(struct event_stream *, es);
- } while (es && es != clicon_stream(h));
+ if (timerisset(&es->es_retention) &&
+ (r = es->es_replay) != NULL){
+ timersub(&now, &es->es_retention, &tret);
+ do {
+ if (timercmp(&r->r_tv, &tret, <)){
+ r1 = NEXTQ(struct stream_replay *, r);
+ DELQ(r, es->es_replay, struct stream_replay *);
+ if (r->r_xml)
+ xml_free(r->r_xml);
+ free(r);
+ r = r1;
+ }
+ else
+ r = NEXTQ(struct stream_replay *, r);
+ } while (r && r!=es->es_replay);
+ }
+ es = NEXTQ(struct event_stream *, es);
+ } while (es && es != clicon_stream(h));
}
/* Initiate new timer */
timeradd(&now, &t1, &t);
if (clixon_event_reg_timeout(t,
- stream_timer_setup, /* this function */
- h, /* clicon handle */
- "stream timer setup") < 0)
- goto done;
+ stream_timer_setup, /* this function */
+ h, /* clicon handle */
+ "stream timer setup") < 0)
+ goto done;
retval = 0;
done:
return retval;
@@ -331,37 +331,37 @@ stream_del()
*/
struct stream_subscription *
stream_ss_add(clicon_handle h,
- char *stream,
- char *xpath,
- struct timeval *starttime,
- struct timeval *stoptime,
- stream_fn_t fn,
- void *arg)
+ char *stream,
+ char *xpath,
+ struct timeval *starttime,
+ struct timeval *stoptime,
+ stream_fn_t fn,
+ void *arg)
{
event_stream_t *es;
struct stream_subscription *ss = NULL;
clicon_debug(1, "%s", __FUNCTION__);
if ((es = stream_find(h, stream)) == NULL){
- clicon_err(OE_CFG, ENOENT, "Stream %s not found", stream);
- goto done;
+ clicon_err(OE_CFG, ENOENT, "Stream %s not found", stream);
+ goto done;
}
if ((ss = malloc(sizeof(*ss))) == NULL){
- clicon_err(OE_CFG, errno, "malloc");
- goto done;
+ clicon_err(OE_CFG, errno, "malloc");
+ goto done;
}
memset(ss, 0, sizeof(*ss));
if ((ss->ss_stream = strdup(stream)) == NULL){
- clicon_err(OE_CFG, errno, "strdup");
- goto done;
+ clicon_err(OE_CFG, errno, "strdup");
+ goto done;
}
if (stoptime)
- ss->ss_stoptime = *stoptime;
+ ss->ss_stoptime = *stoptime;
if (starttime)
- ss->ss_starttime = *starttime;
+ ss->ss_starttime = *starttime;
if (xpath && (ss->ss_xpath = strdup(xpath)) == NULL){
- clicon_err(OE_CFG, errno, "strdup");
- goto done;
+ clicon_err(OE_CFG, errno, "strdup");
+ goto done;
}
ss->ss_fn = fn;
ss->ss_arg = arg;
@@ -369,7 +369,7 @@ stream_ss_add(clicon_handle h,
return ss;
done:
if (ss)
- free(ss);
+ free(ss);
return NULL;
}
@@ -383,20 +383,20 @@ stream_ss_add(clicon_handle h,
*/
int
stream_ss_rm(clicon_handle h,
- event_stream_t *es,
- struct stream_subscription *ss,
- int force)
+ event_stream_t *es,
+ struct stream_subscription *ss,
+ int force)
{
clicon_debug(1, "%s", __FUNCTION__);
DELQ(ss, es->es_subscription, struct stream_subscription *);
/* Remove from upper layers - close socket etc. */
(*ss->ss_fn)(h, 1, NULL, ss->ss_arg);
if (force){
- if (ss->ss_stream)
- free(ss->ss_stream);
- if (ss->ss_xpath)
- free(ss->ss_xpath);
- free(ss);
+ if (ss->ss_stream)
+ free(ss->ss_stream);
+ if (ss->ss_xpath)
+ free(ss->ss_xpath);
+ free(ss);
}
clicon_debug(1, "%s retval: 0", __FUNCTION__);
return 0;
@@ -411,17 +411,17 @@ stream_ss_rm(clicon_handle h,
*/
struct stream_subscription *
stream_ss_find(event_stream_t *es,
- stream_fn_t fn,
- void *arg)
+ stream_fn_t fn,
+ void *arg)
{
struct stream_subscription *ss;
if ((ss = es->es_subscription) != NULL)
- do {
- if (fn == ss->ss_fn && arg == ss->ss_arg)
- return ss;
- ss = NEXTQ(struct stream_subscription *, ss);
- } while (ss && ss != es->es_subscription);
+ do {
+ if (fn == ss->ss_fn && arg == ss->ss_arg)
+ return ss;
+ ss = NEXTQ(struct stream_subscription *, ss);
+ } while (ss && ss != es->es_subscription);
return NULL;
}
@@ -433,22 +433,22 @@ stream_ss_find(event_stream_t *es,
*/
int
stream_ss_delete_all(clicon_handle h,
- stream_fn_t fn,
- void *arg)
+ stream_fn_t fn,
+ void *arg)
{
int retval = -1;
event_stream_t *es;
struct stream_subscription *ss;
if ((es = clicon_stream(h)) != NULL){
- do {
- if ((ss = stream_ss_find(es, fn, arg)) != NULL){
- if (stream_ss_rm(h, es, ss, 1) < 0)
- goto done;
- }
- es = NEXTQ(struct event_stream *, es);
- } while (es && es != clicon_stream(h));
- }
+ do {
+ if ((ss = stream_ss_find(es, fn, arg)) != NULL){
+ if (stream_ss_rm(h, es, ss, 1) < 0)
+ goto done;
+ }
+ es = NEXTQ(struct event_stream *, es);
+ } while (es && es != clicon_stream(h));
+ }
retval = 0;
done:
return retval;
@@ -459,24 +459,24 @@ stream_ss_delete_all(clicon_handle h,
*/
int
stream_ss_delete(clicon_handle h,
- char *name,
- stream_fn_t fn,
- void *arg)
+ char *name,
+ stream_fn_t fn,
+ void *arg)
{
int retval = -1;
event_stream_t *es;
struct stream_subscription *ss;
if ((es = clicon_stream(h)) != NULL){
- do {
- if (strcmp(name, es->es_name)==0)
- if ((ss = stream_ss_find(es, fn, arg)) != NULL){
- if (stream_ss_rm(h, es, ss, 0) < 0)
- goto done;
- }
- es = NEXTQ(struct event_stream *, es);
- } while (es && es != clicon_stream(h));
- }
+ do {
+ if (strcmp(name, es->es_name)==0)
+ if ((ss = stream_ss_find(es, fn, arg)) != NULL){
+ if (stream_ss_rm(h, es, ss, 0) < 0)
+ goto done;
+ }
+ es = NEXTQ(struct event_stream *, es);
+ } while (es && es != clicon_stream(h));
+ }
retval = 0;
done:
return retval;
@@ -494,9 +494,9 @@ stream_ss_delete(clicon_handle h,
*/
static int
stream_notify1(clicon_handle h,
- event_stream_t *es,
- struct timeval *tv,
- cxobj *xevent)
+ event_stream_t *es,
+ struct timeval *tv,
+ cxobj *xevent)
{
int retval = -1;
struct stream_subscription *ss;
@@ -504,25 +504,25 @@ stream_notify1(clicon_handle h,
clicon_debug(2, "%s", __FUNCTION__);
/* Go thru all subscriptions and find matches */
if ((ss = es->es_subscription) != NULL)
- do {
- if (timerisset(&ss->ss_stoptime) && /* stoptime has passed */
- timercmp(&ss->ss_stoptime, tv, <)){
- struct stream_subscription *ss1;
- ss1 = NEXTQ(struct stream_subscription *, ss);
- /* Signal to remove stream for upper levels */
- if (stream_ss_rm(h, es, ss, 1) < 0)
- goto done;
- ss = ss1;
- }
- else{ /* xpath match */
- if (ss->ss_xpath == NULL ||
- strlen(ss->ss_xpath)==0 ||
- xpath_first(xevent, NULL, "%s", ss->ss_xpath) != NULL)
- if ((*ss->ss_fn)(h, 0, xevent, ss->ss_arg) < 0)
- goto done;
- ss = NEXTQ(struct stream_subscription *, ss);
- }
- } while (es->es_subscription && ss != es->es_subscription);
+ do {
+ if (timerisset(&ss->ss_stoptime) && /* stoptime has passed */
+ timercmp(&ss->ss_stoptime, tv, <)){
+ struct stream_subscription *ss1;
+ ss1 = NEXTQ(struct stream_subscription *, ss);
+ /* Signal to remove stream for upper levels */
+ if (stream_ss_rm(h, es, ss, 1) < 0)
+ goto done;
+ ss = ss1;
+ }
+ else{ /* xpath match */
+ if (ss->ss_xpath == NULL ||
+ strlen(ss->ss_xpath)==0 ||
+ xpath_first(xevent, NULL, "%s", ss->ss_xpath) != NULL)
+ if ((*ss->ss_fn)(h, 0, xevent, ss->ss_arg) < 0)
+ goto done;
+ ss = NEXTQ(struct stream_subscription *, ss);
+ }
+ } while (es->es_subscription && ss != es->es_subscription);
retval = 0;
done:
return retval;
@@ -542,8 +542,8 @@ stream_notify1(clicon_handle h,
*/
int
stream_notify(clicon_handle h,
- char *stream,
- const char *event, ...)
+ char *stream,
+ const char *event, ...)
{
int retval = -1;
va_list args;
@@ -558,54 +558,54 @@ stream_notify(clicon_handle h,
clicon_debug(2, "%s", __FUNCTION__);
if ((es = stream_find(h, stream)) == NULL)
- goto ok;
+ goto ok;
va_start(args, event);
len = vsnprintf(NULL, 0, event, args) + 1;
va_end(args);
if ((str = malloc(len)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(str, 0, len);
va_start(args, event);
len = vsnprintf(str, len, event, args) + 1;
va_end(args);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_YANG, 0, "No yang spec");
- goto done;
+ clicon_err(OE_YANG, 0, "No yang spec");
+ goto done;
}
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
gettimeofday(&tv, NULL);
if (time2str(tv, timestr, sizeof(timestr)) < 0){
- clicon_err(OE_UNIX, errno, "time2str");
- goto done;
+ clicon_err(OE_UNIX, errno, "time2str");
+ goto done;
}
/* From RFC5277 */
cprintf(cb, "%s %s ",
- NOTIFICATION_RFC5277_NAMESPACE, timestr, str);
+ NOTIFICATION_RFC5277_NAMESPACE, timestr, str);
if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, &xev, NULL) < 0)
- goto done;
+ goto done;
if (xml_rootchild(xev, 0, &xev) < 0)
- goto done;
+ goto done;
if (stream_notify1(h, es, &tv, xev) < 0)
- goto done;
+ goto done;
if (es->es_replay_enabled){
- if (stream_replay_add(es, &tv, xev) < 0)
- goto done;
- xev = NULL; /* xml stored in replay_add and should not be freed */
+ if (stream_replay_add(es, &tv, xev) < 0)
+ goto done;
+ xev = NULL; /* xml stored in replay_add and should not be freed */
}
ok:
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (xev)
- xml_free(xev);
+ xml_free(xev);
if (str)
- free(str);
+ free(str);
return retval;
}
@@ -619,8 +619,8 @@ stream_notify(clicon_handle h,
*/
int
stream_notify_xml(clicon_handle h,
- char *stream,
- cxobj *xml)
+ char *stream,
+ cxobj *xml)
{
int retval = -1;
cxobj *xev = NULL;
@@ -634,47 +634,47 @@ stream_notify_xml(clicon_handle h,
clicon_debug(2, "%s", __FUNCTION__);
if ((es = stream_find(h, stream)) == NULL)
- goto ok;
+ goto ok;
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_YANG, 0, "No yang spec");
- goto done;
+ clicon_err(OE_YANG, 0, "No yang spec");
+ goto done;
}
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
gettimeofday(&tv, NULL);
if (time2str(tv, timestr, sizeof(timestr)) < 0){
- clicon_err(OE_UNIX, errno, "time2str");
- goto done;
+ clicon_err(OE_UNIX, errno, "time2str");
+ goto done;
}
cprintf(cb, "%s NULL ",
- NOTIFICATION_RFC5277_NAMESPACE,
- timestr); /* XXX str is always NULL */
+ NOTIFICATION_RFC5277_NAMESPACE,
+ timestr); /* XXX str is always NULL */
if (clixon_xml_parse_string(cbuf_get(cb), YB_NONE, yspec, &xev, NULL) < 0)
- goto done;
+ goto done;
if (xml_rootchild(xev, 0, &xev) < 0)
- goto done;
+ goto done;
if ((xml2 = xml_dup(xml)) == NULL)
- goto done;
+ goto done;
if (xml_addsub(xev, xml2) < 0)
- goto done;
+ goto done;
if (stream_notify1(h, es, &tv, xev) < 0)
- goto done;
+ goto done;
if (es->es_replay_enabled){
- if (stream_replay_add(es, &tv, xev) < 0)
- goto done;
- xev = NULL; /* xml stored in replay_add and should not be freed */
+ if (stream_replay_add(es, &tv, xev) < 0)
+ goto done;
+ xev = NULL; /* xml stored in replay_add and should not be freed */
}
ok:
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (xev)
- xml_free(xev);
+ xml_free(xev);
if (str)
- free(str);
+ free(str);
return retval;
}
@@ -701,41 +701,41 @@ stream_notify_xml(clicon_handle h,
the future are valid. This parameter is of type dateTime and
compliant to [RFC3339]. Implementations must support time
zones.
-
+
* Assume no future sample timestamps.
*/
static int
stream_replay_notify(clicon_handle h,
- event_stream_t *es,
- struct stream_subscription *ss)
+ event_stream_t *es,
+ struct stream_subscription *ss)
{
int retval = -1;
struct stream_replay *r;
/* If is not present, this is not a replay */
if (!timerisset(&ss->ss_starttime))
- goto ok;
+ goto ok;
if (!es->es_replay_enabled)
- goto ok;
+ goto ok;
/* Get replay linked list */
if ((r = es->es_replay) == NULL)
- goto ok;
+ goto ok;
/* First loop to skip until start */
do {
- if (timercmp(&r->r_tv, &ss->ss_starttime, >=))
- break;
- r = NEXTQ(struct stream_replay *, r);
+ if (timercmp(&r->r_tv, &ss->ss_starttime, >=))
+ break;
+ r = NEXTQ(struct stream_replay *, r);
} while (r && r!=es->es_replay);
if (r == NULL)
- goto ok; /* No samples to replay */
+ goto ok; /* No samples to replay */
/* Then notify until stop */
do {
- if (timerisset(&ss->ss_stoptime) &&
- timercmp(&r->r_tv, &ss->ss_stoptime, >))
- break;
- if ((*ss->ss_fn)(h, 0, r->r_xml, ss->ss_arg) < 0)
- goto done;
- r = NEXTQ(struct stream_replay *, r);
+ if (timerisset(&ss->ss_stoptime) &&
+ timercmp(&r->r_tv, &ss->ss_stoptime, >))
+ break;
+ if ((*ss->ss_fn)(h, 0, r->r_xml, ss->ss_arg) < 0)
+ goto done;
+ r = NEXTQ(struct stream_replay *, r);
} while (r && r!=es->es_replay);
ok:
retval = 0;
@@ -750,15 +750,15 @@ stream_replay_notify(clicon_handle h,
*/
int
stream_replay_add(event_stream_t *es,
- struct timeval *tv,
- cxobj *xv)
+ struct timeval *tv,
+ cxobj *xv)
{
int retval = -1;
struct stream_replay *new;
if ((new = malloc(sizeof *new)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(new, 0, (sizeof *new));
new->r_tv = *tv;
@@ -785,7 +785,7 @@ struct replay_arg{
*/
static int
stream_replay_cb(int fd,
- void *arg)
+ void *arg)
{
int retval = -1;
struct replay_arg *ra= (struct replay_arg*)arg;
@@ -793,22 +793,22 @@ stream_replay_cb(int fd,
struct stream_subscription *ss;
if (ra == NULL)
- goto ok;
+ goto ok;
if (ra->ra_stream == NULL)
- goto ok;
+ goto ok;
if ((es = stream_find(ra->ra_h, ra->ra_stream)) == NULL)
- goto ok;
+ goto ok;
if ((ss = stream_ss_find(es, ra->ra_fn, ra->ra_arg)) == NULL)
- goto ok;
+ goto ok;
if (stream_replay_notify(ra->ra_h, es, ss) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
if (ra){
- if (ra->ra_stream)
- free(ra->ra_stream);
- free(ra);
+ if (ra->ra_stream)
+ free(ra->ra_stream);
+ free(ra);
}
return retval;
}
@@ -822,30 +822,30 @@ stream_replay_cb(int fd,
*/
int
stream_replay_trigger(clicon_handle h,
- char *stream,
- stream_fn_t fn,
- void *arg)
+ char *stream,
+ stream_fn_t fn,
+ void *arg)
{
int retval = -1;
struct timeval now;
struct replay_arg *ra;
if ((ra = malloc(sizeof(*ra))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(ra, 0, sizeof(*ra));
ra->ra_h = h;
if ((ra->ra_stream = strdup(stream)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
ra->ra_fn = fn;
ra->ra_arg = arg;
gettimeofday(&now, NULL);
if (clixon_event_reg_timeout(now, stream_replay_cb, ra,
- "create-subscribtion stream replay") < 0)
- goto done;
+ "create-subscribtion stream replay") < 0)
+ goto done;
retval = 0;
done:
return retval;
@@ -874,16 +874,16 @@ struct curlbuf{
*/
static size_t
curl_get_cb(void *ptr,
- size_t size,
- size_t nmemb,
- void *userdata)
+ size_t size,
+ size_t nmemb,
+ void *userdata)
{
struct curlbuf *buf = (struct curlbuf *)userdata;
int len;
len = size*nmemb;
if ((buf->b_buf = realloc(buf->b_buf, buf->b_len+len+1)) == NULL)
- return 0;
+ return 0;
memcpy(buf->b_buf+buf->b_len, ptr, len);
buf->b_len += len;
buf->b_buf[buf->b_len] = '\0';
@@ -900,8 +900,8 @@ curl_get_cb(void *ptr,
*/
static int
url_post(char *url,
- char *postfields,
- char **getdata)
+ char *postfields,
+ char **getdata)
{
int retval = -1;
CURL *curl = NULL;
@@ -911,15 +911,15 @@ url_post(char *url,
/* Try it with curl -X PUT -d '*/
clicon_debug(1, "%s: curl -X POST -d '%s' %s",
- __FUNCTION__, postfields, url);
+ __FUNCTION__, postfields, url);
/* Set up curl for doing the communication with the controller */
if ((curl = curl_easy_init()) == NULL) {
- clicon_debug(1, "curl_easy_init");
- goto done;
+ clicon_debug(1, "curl_easy_init");
+ goto done;
}
if ((err = malloc(CURL_ERROR_SIZE)) == NULL) {
- clicon_debug(1, "%s: malloc", __FUNCTION__);
- goto done;
+ clicon_debug(1, "%s: malloc", __FUNCTION__);
+ goto done;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_get_cb);
@@ -930,24 +930,24 @@ url_post(char *url,
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(postfields));
if (clicon_debug_get())
- curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
if ((errcode = curl_easy_perform(curl)) != CURLE_OK){
- clicon_debug(1, "%s: curl: %s(%d)", __FUNCTION__, err, errcode);
- retval = 0;
- goto done;
+ clicon_debug(1, "%s: curl: %s(%d)", __FUNCTION__, err, errcode);
+ retval = 0;
+ goto done;
}
if (getdata && cb.b_buf){
- *getdata = cb.b_buf;
- cb.b_buf = NULL;
+ *getdata = cb.b_buf;
+ cb.b_buf = NULL;
}
retval = 1;
done:
if (err)
- free(err);
+ free(err);
if (cb.b_buf)
- free(cb.b_buf);
+ free(cb.b_buf);
if (curl)
- curl_easy_cleanup(curl); /* cleanup */
+ curl_easy_cleanup(curl); /* cleanup */
return retval;
}
@@ -961,9 +961,9 @@ url_post(char *url,
*/
static int
stream_publish_cb(clicon_handle h,
- int op,
- cxobj *event,
- void *arg)
+ int op,
+ cxobj *event,
+ void *arg)
{
int retval = -1;
cbuf *u = NULL; /* stream pub (push) url */
@@ -974,39 +974,39 @@ stream_publish_cb(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (op != 0)
- goto ok;
+ goto ok;
/* Create pub url */
if ((u = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
if ((pub_prefix = clicon_option_str(h, "CLICON_STREAM_PUB")) == NULL){
- clicon_err(OE_CFG, ENOENT, "CLICON_STREAM_PUB not defined");
- goto done;
+ clicon_err(OE_CFG, ENOENT, "CLICON_STREAM_PUB not defined");
+ goto done;
}
cprintf(u, "%s/%s", pub_prefix, stream);
/* Create XML data as string */
if ((d = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
if (clixon_xml2cbuf(d, event, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
if (url_post(cbuf_get(u), /* url+stream */
- cbuf_get(d), /* postfields */
- &result) < 0) /* result as xml */
- goto done;
+ cbuf_get(d), /* postfields */
+ &result) < 0) /* result as xml */
+ goto done;
if (result)
- clicon_debug(1, "%s: %s", __FUNCTION__, result);
+ clicon_debug(1, "%s: %s", __FUNCTION__, result);
ok:
retval = 0;
done:
if (u)
- cbuf_free(u);
+ cbuf_free(u);
if (d)
- cbuf_free(d);
+ cbuf_free(d);
if (result)
- free(result);
+ free(result);
return retval;
}
#endif /* CLIXON_PUBLISH_STREAMS */
@@ -1015,13 +1015,13 @@ stream_publish_cb(clicon_handle h,
*/
int
stream_publish(clicon_handle h,
- char *stream)
+ char *stream)
{
#ifdef CLIXON_PUBLISH_STREAMS
int retval = -1;
if (stream_ss_add(h, stream, NULL, NULL, NULL, stream_publish_cb, (void*)stream) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -1039,8 +1039,8 @@ stream_publish_init()
int retval = -1;
if (curl_global_init(CURL_GLOBAL_ALL) != 0){
- clicon_err(OE_PLUGIN, errno, "curl_global_init");
- goto done;
+ clicon_err(OE_PLUGIN, errno, "curl_global_init");
+ goto done;
}
retval = 0;
done:
diff --git a/lib/src/clixon_string.c b/lib/src/clixon_string.c
index a602e4af..b1d387cb 100644
--- a/lib/src/clixon_string.c
+++ b/lib/src/clixon_string.c
@@ -81,8 +81,8 @@
*/
char **
clicon_strsep(char *string,
- char *delim,
- int *nvec0)
+ char *delim,
+ int *nvec0)
{
char **vec = NULL;
char *ptr;
@@ -94,24 +94,24 @@ clicon_strsep(char *string,
char *d;
if ((s = string)==NULL)
- goto done;
+ goto done;
while (*s){
- if ((d = index(delim, *s)) != NULL)
- nvec++;
- s++;
+ if ((d = index(delim, *s)) != NULL)
+ nvec++;
+ s++;
}
/* alloc vector and append copy of string */
siz = (nvec+1)* sizeof(char*) + strlen(string)+1;
if ((vec = (char**)malloc(siz)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(vec, 0, siz);
ptr = (char*)vec + (nvec+1)* sizeof(char*); /* this is where ptr starts */
strcpy(ptr, string);
i = 0;
while ((p = strsep(&ptr, delim)) != NULL)
- vec[i++] = p;
+ vec[i++] = p;
*nvec0 = nvec;
done:
return vec;
@@ -125,8 +125,8 @@ clicon_strsep(char *string,
*/
char *
clicon_strjoin(int argc,
- char **argv,
- char *delim)
+ char **argv,
+ char *delim)
{
int i;
int len;
@@ -134,17 +134,17 @@ clicon_strjoin(int argc,
len = 0;
for (i = 0; i < argc; i++)
- len += strlen(argv[i]);
+ len += strlen(argv[i]);
if (delim)
- len += (strlen(delim) * argc);
+ len += (strlen(delim) * argc);
len += 1; /* '\0' */
if ((str = malloc(len)) == NULL)
- return NULL;
+ return NULL;
memset(str, '\0', len);
for (i = 0; i < argc; i++) {
- if (i != 0)
- strncat(str, delim, len - strlen(str));
- strncat(str, argv[i], len - strlen(str));
+ if (i != 0)
+ strncat(str, delim, len - strlen(str));
+ strncat(str, argv[i], len - strlen(str));
}
return str;
}
@@ -158,30 +158,30 @@ clicon_strjoin(int argc,
*/
char*
clixon_string_del_join(char *str1,
- char *del,
- char *str2)
+ char *del,
+ char *str2)
{
char *str;
int len;
if (str2 == NULL){
- clicon_err(OE_UNIX, EINVAL, "str2 is NULL");
- return NULL;
+ clicon_err(OE_UNIX, EINVAL, "str2 is NULL");
+ return NULL;
}
len = strlen(str2) + 1;
if (str1)
- len += strlen(str1);
+ len += strlen(str1);
len += strlen(del);
if ((str = malloc(len)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- return NULL;
+ clicon_err(OE_UNIX, errno, "malloc");
+ return NULL;
}
if (str1){
- snprintf(str, len, "%s%s%s", str1, del, str2);
- free(str1);
+ snprintf(str, len, "%s%s%s", str1, del, str2);
+ free(str1);
}
else
- snprintf(str, len, "%s%s", del, str2);
+ snprintf(str, len, "%s%s", del, str2);
return str;
}
@@ -196,42 +196,42 @@ clixon_string_del_join(char *str1,
* char *a = NULL;
* char *b = NULL;
* if (clixon_strsplit(nodeid, ':', &a, &b) < 0)
- * goto done;
+ * goto done;
* if (a)
- * free(a);
+ * free(a);
* if (b)
- * free(b);
+ * free(b);
* @note caller need to free prefix and suffix after use
* @see clicon_strsep not just single split
*/
int
clixon_strsplit(char *string,
- const int delim,
- char **prefix,
- char **suffix)
+ const int delim,
+ char **prefix,
+ char **suffix)
{
int retval = -1;
char *str;
if ((str = strchr(string, delim)) == NULL){
- if (suffix && (*suffix = strdup(string)) == NULL){
- clicon_err(OE_YANG, errno, "strdup");
- goto done;
- }
+ if (suffix && (*suffix = strdup(string)) == NULL){
+ clicon_err(OE_YANG, errno, "strdup");
+ goto done;
+ }
}
else {
- if (prefix){
- if ((*prefix = strdup(string)) == NULL){
- clicon_err(OE_YANG, errno, "strdup");
- goto done;
- }
- (*prefix)[str-string] = '\0';
- }
- str++;
- if (suffix && (*suffix = strdup(str)) == NULL){
- clicon_err(OE_YANG, errno, "strdup");
- goto done;
- }
+ if (prefix){
+ if ((*prefix = strdup(string)) == NULL){
+ clicon_err(OE_YANG, errno, "strdup");
+ goto done;
+ }
+ (*prefix)[str-string] = '\0';
+ }
+ str++;
+ if (suffix && (*suffix = strdup(str)) == NULL){
+ clicon_err(OE_YANG, errno, "strdup");
+ goto done;
+ }
}
retval = 0;
done:
@@ -255,9 +255,9 @@ uri_unreserved(unsigned char in)
case 'P': case 'Q': case 'R': case 'S': case 'T':
case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
case '-': case '.': case '_': case '~':
- return 1;
+ return 1;
default:
- break;
+ break;
}
return 0;
}
@@ -281,7 +281,7 @@ uri_unreserved(unsigned char in)
*/
int
uri_percent_encode(char **encp,
- const char *fmt, ...)
+ const char *fmt, ...)
{
int retval = -1;
char *str = NULL; /* Expanded format string w stdarg */
@@ -296,8 +296,8 @@ uri_percent_encode(char **encp,
fmtlen = vsnprintf(NULL, 0, fmt, args) + 1;
va_end(args);
if ((str = malloc(fmtlen)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(str, 0, fmtlen);
va_start(args, fmt); /* real */
@@ -309,27 +309,27 @@ uri_percent_encode(char **encp,
/* This is max */
len = strlen(str)*3+1;
if ((enc = malloc(len)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(enc, 0, len);
len = strlen(str);
j = 0;
for (i=0; i 2 &&
- isxdigit(enc[i+1]) && isxdigit(enc[i+2])){
- hstr[0] = enc[i+1];
- hstr[1] = enc[i+2];
- hstr[2] = 0;
- str[j] = strtoul(hstr, &ptr, 16);
- i += 2;
- }
- else
- str[j] = enc[i];
- j++;
+ if (enc[i] == '%' && strlen(enc)-i > 2 &&
+ isxdigit(enc[i+1]) && isxdigit(enc[i+2])){
+ hstr[0] = enc[i+1];
+ hstr[1] = enc[i+2];
+ hstr[2] = 0;
+ str[j] = strtoul(hstr, &ptr, 16);
+ i += 2;
+ }
+ else
+ str[j] = enc[i];
+ j++;
}
str[j++] = '\0';
*strp = str;
retval = 0;
done:
if (retval < 0 && str)
- free(str);
+ free(str);
return retval;
}
@@ -413,7 +413,7 @@ uri_percent_decode(char *enc,
*/
int
xml_chardata_encode(char **escp,
- const char *fmt,...)
+ const char *fmt,...)
{
int retval = -1;
char *str = NULL; /* Expanded format string w stdarg */
@@ -431,8 +431,8 @@ xml_chardata_encode(char **escp,
fmtlen = vsnprintf(NULL, 0, fmt, args) + 1;
va_end(args);
if ((str = malloc(fmtlen)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(str, 0, fmtlen);
va_start(args, fmt); /* real */
@@ -445,36 +445,36 @@ xml_chardata_encode(char **escp,
len = 0; cdata = 0;
slen = strlen(str);
for (i=0; i", strlen("]]>")) == 0)
- cdata = 0;
- len++;
- }
- else
- switch (str[i]){
- case '&':
- len += strlen("&");
- break;
- case '<':
- if (strncmp(&str[i], "':
- len += strlen(">");
- break;
- default:
- len++;
- }
+ if (cdata){
+ if (strncmp(&str[i], "]]>", strlen("]]>")) == 0)
+ cdata = 0;
+ len++;
+ }
+ else
+ switch (str[i]){
+ case '&':
+ len += strlen("&");
+ break;
+ case '<':
+ if (strncmp(&str[i], "':
+ len += strlen(">");
+ break;
+ default:
+ len++;
+ }
}
len++; /* trailing \0 */
/* We know length, allocate encoding buffer */
if ((esc = malloc(len)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(esc, 0, len);
@@ -482,53 +482,53 @@ xml_chardata_encode(char **escp,
j = 0; cdata = 0;
slen = strlen(str);
for (i=0; i", strlen("]]>")) == 0){
- cdata = 0;
- esc[j++] = str[i++];
- esc[j++] = str[i++];
- }
- esc[j++] = str[i];
- }
- else
- switch (str[i]){
- case '&':
- if ((l=snprintf(&esc[j], 6, "&")) < 0){
- clicon_err(OE_UNIX, errno, "snprintf");
- goto done;
- }
- j += l;
- break;
- case '<':
- if (strncmp(&str[i], "':
- if ((l=snprintf(&esc[j], 5, ">")) < 0){
- clicon_err(OE_UNIX, errno, "snprintf");
- goto done;
- }
- j += l;
- break;
- default:
- esc[j++] = str[i];
- }
+ if (cdata){
+ if (strncmp(&str[i], "]]>", strlen("]]>")) == 0){
+ cdata = 0;
+ esc[j++] = str[i++];
+ esc[j++] = str[i++];
+ }
+ esc[j++] = str[i];
+ }
+ else
+ switch (str[i]){
+ case '&':
+ if ((l=snprintf(&esc[j], 6, "&")) < 0){
+ clicon_err(OE_UNIX, errno, "snprintf");
+ goto done;
+ }
+ j += l;
+ break;
+ case '<':
+ if (strncmp(&str[i], "':
+ if ((l=snprintf(&esc[j], 5, ">")) < 0){
+ clicon_err(OE_UNIX, errno, "snprintf");
+ goto done;
+ }
+ j += l;
+ break;
+ default:
+ esc[j++] = str[i];
+ }
}
*escp = esc;
retval = 0;
done:
if (str)
- free(str);
+ free(str);
if (retval < 0 && esc)
- free(esc);
+ free(esc);
return retval;
}
@@ -540,7 +540,7 @@ xml_chardata_encode(char **escp,
*/
int
xml_chardata_cbuf_append(cbuf *cb,
- char *str)
+ char *str)
{
int retval = -1;
int i;
@@ -554,33 +554,33 @@ xml_chardata_cbuf_append(cbuf *cb,
len = strlen(str);
for (i=0; i", strlen("]]>")) == 0){
- cdata = 0;
- cbuf_append(cb, str[i++]);
- cbuf_append(cb, str[i++]);
- }
- cbuf_append(cb, str[i]);
- }
- else
- switch (str[i]){
- case '&':
- cbuf_append_str(cb, "&");
- break;
- case '<':
- if (strncmp(&str[i], "':
- cbuf_append_str(cb, ">");
- break;
- default:
- cbuf_append(cb, str[i]);
- }
+ if (cdata){
+ if (strncmp(&str[i], "]]>", strlen("]]>")) == 0){
+ cdata = 0;
+ cbuf_append(cb, str[i++]);
+ cbuf_append(cb, str[i++]);
+ }
+ cbuf_append(cb, str[i]);
+ }
+ else
+ switch (str[i]){
+ case '&':
+ cbuf_append_str(cb, "&");
+ break;
+ case '<':
+ if (strncmp(&str[i], "':
+ cbuf_append_str(cb, ">");
+ break;
+ default:
+ cbuf_append(cb, str[i]);
+ }
}
retval = 0;
// done:
@@ -612,10 +612,10 @@ xml_chardata_cbuf_append(cbuf *cb,
*/
int
uri_str2cvec(char *string,
- char delim1,
- char delim2,
- int decode,
- cvec **cvp)
+ char delim1,
+ char delim2,
+ int decode,
+ cvec **cvp)
{
int retval = -1;
char *s;
@@ -627,66 +627,66 @@ uri_str2cvec(char *string,
cg_var *cv;
if ((s0 = strdup(string)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto err;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto err;
}
s = s0;
if ((cvv = cvec_new(0)) ==NULL){
- clicon_err(OE_UNIX, errno, "cvec_new");
- goto err;
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ goto err;
}
while (s != NULL) {
- /*
- * In the pointer algorithm below:
- * name1=val1; name2=val2;
- * ^ ^ ^
- * | | |
- * s val snext
- */
- if ((snext = index(s, delim1)) != NULL)
- *(snext++) = '\0';
- if ((val = index(s, delim2)) != NULL){
- *(val++) = '\0';
- if (decode){
- if (uri_percent_decode(val, &valu) < 0)
- goto err;
- }
- else
- if ((valu = strdup(val)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto err;
- }
- if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_add");
- goto err;
- }
- while ((strlen(s) > 0) && isblank(*s))
- s++;
- cv_name_set(cv, s);
- cv_string_set(cv, valu);
- free(valu); valu = NULL;
- }
- else{
- if (strlen(s)){
- if ((cv = cvec_add(cvv, CGV_EMPTY)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_add");
- goto err;
- }
- cv_name_set(cv, s);
- }
- }
- s = snext;
+ /*
+ * In the pointer algorithm below:
+ * name1=val1; name2=val2;
+ * ^ ^ ^
+ * | | |
+ * s val snext
+ */
+ if ((snext = index(s, delim1)) != NULL)
+ *(snext++) = '\0';
+ if ((val = index(s, delim2)) != NULL){
+ *(val++) = '\0';
+ if (decode){
+ if (uri_percent_decode(val, &valu) < 0)
+ goto err;
+ }
+ else
+ if ((valu = strdup(val)) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto err;
+ }
+ if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){
+ clicon_err(OE_UNIX, errno, "cvec_add");
+ goto err;
+ }
+ while ((strlen(s) > 0) && isblank(*s))
+ s++;
+ cv_name_set(cv, s);
+ cv_string_set(cv, valu);
+ free(valu); valu = NULL;
+ }
+ else{
+ if (strlen(s)){
+ if ((cv = cvec_add(cvv, CGV_EMPTY)) == NULL){
+ clicon_err(OE_UNIX, errno, "cvec_add");
+ goto err;
+ }
+ cv_name_set(cv, s);
+ }
+ }
+ s = snext;
}
retval = 0;
done:
*cvp = cvv;
if (s0)
- free(s0);
+ free(s0);
return retval;
err:
if (cvv){
- cvec_free(cvv);
- cvv = NULL;
+ cvec_free(cvv);
+ cvv = NULL;
}
goto done;
}
@@ -700,13 +700,13 @@ uri_str2cvec(char *string,
*/
const char *
clicon_int2str(const map_str2int *mstab,
- int i)
+ int i)
{
const struct map_str2int *ms;
for (ms = &mstab[0]; ms->ms_str; ms++)
- if (ms->ms_int == i)
- return ms->ms_str;
+ if (ms->ms_int == i)
+ return ms->ms_str;
return NULL;
}
@@ -719,13 +719,13 @@ clicon_int2str(const map_str2int *mstab,
*/
int
clicon_str2int(const map_str2int *mstab,
- char *str)
+ char *str)
{
const struct map_str2int *ms;
for (ms = &mstab[0]; ms->ms_str; ms++)
- if (strcmp(ms->ms_str, str) == 0)
- return ms->ms_int;
+ if (strcmp(ms->ms_str, str) == 0)
+ return ms->ms_int;
return -1;
}
@@ -742,30 +742,30 @@ clicon_str2int(const map_str2int *mstab,
*/
static int
str2int_search1(const map_str2int *mstab,
- char *str,
- int low,
- int upper,
- int len,
- int *found)
+ char *str,
+ int low,
+ int upper,
+ int len,
+ int *found)
{
const struct map_str2int *ms;
int mid;
int cmp;
if (upper < low)
- return 0; /* not found */
+ return 0; /* not found */
mid = (low + upper) / 2;
if (mid >= len) /* beyond range */
- return 0; /* not found */
+ return 0; /* not found */
ms = &mstab[mid];
if ((cmp = strcmp(str, ms->ms_str)) == 0){
- *found = ms->ms_int;
- return 1; /* found */
+ *found = ms->ms_int;
+ return 1; /* found */
}
else if (cmp < 0)
- return str2int_search1(mstab, str, low, mid-1, len, found);
+ return str2int_search1(mstab, str, low, mid-1, len, found);
else
- return str2int_search1(mstab, str, mid+1, upper, len, found);
+ return str2int_search1(mstab, str, mid+1, upper, len, found);
}
/*! Map from string to int using str2int map
@@ -778,13 +778,13 @@ str2int_search1(const map_str2int *mstab,
*/
int
clicon_str2int_search(const map_str2int *mstab,
- char *str,
- int len)
+ char *str,
+ int len)
{
int found;
if (str2int_search1(mstab, str, 0, len, len, &found))
- return found;
+ return found;
return -1; /* not found */
}
@@ -796,13 +796,13 @@ clicon_str2int_search(const map_str2int *mstab,
*/
char*
clicon_str2str(const map_str2str *mstab,
- char *str)
+ char *str)
{
const struct map_str2str *ms;
for (ms = &mstab[0]; ms->ms_s0; ms++)
- if (strcmp(ms->ms_s0, str) == 0)
- return ms->ms_s1;
+ if (strcmp(ms->ms_s0, str) == 0)
+ return ms->ms_s1;
return NULL;
}
@@ -816,17 +816,17 @@ clicon_str2str(const map_str2str *mstab,
* char *prefix = NULL;
* char *id = NULL;
* if (nodeid_split(nodeid, &prefix, &id) < 0)
- * goto done;
+ * goto done;
* if (prefix)
- * free(prefix);
+ * free(prefix);
* if (id)
- * free(id);
+ * free(id);
* @note caller need to free id and prefix after use
*/
int
nodeid_split(char *nodeid,
- char **prefix,
- char **id)
+ char **prefix,
+ char **id)
{
return clixon_strsplit(nodeid, ':', prefix, id);
}
@@ -842,12 +842,12 @@ clixon_trim(char *str)
int i;
while (strlen(s) && isblank(s[0])) /* trim from front */
- s++;
+ s++;
for (i=strlen(s)-1; i>=0; i--){ /* trim from rear */
- if (isblank(s[i]))
- s[i] = '\0';
- else
- break;
+ if (isblank(s[i]))
+ s[i] = '\0';
+ else
+ break;
}
return s;
}
@@ -859,18 +859,18 @@ clixon_trim(char *str)
*/
char *
clixon_trim2(char *str,
- char *trims)
+ char *trims)
{
char *s = str;
int i;
while (strlen(s) && index(trims, s[0])) /* trim from front */
- s++;
+ s++;
for (i=strlen(s)-1; i>=0; i--){ /* trim from rear */
- if (index(trims, s[i]))
- s[i] = '\0';
- else
- break;
+ if (index(trims, s[i]))
+ s[i] = '\0';
+ else
+ break;
}
return s;
}
@@ -884,14 +884,14 @@ clixon_trim2(char *str,
*/
int
clicon_strcmp(char *s1,
- char *s2)
+ char *s2)
{
if (s1 == NULL && s2 == NULL)
- return 0;
+ return 0;
if (s1 == NULL) /* empty string first */
- return -1;
+ return -1;
if (s2 == NULL)
- return 1;
+ return 1;
return strcmp(s1, s2);
}
@@ -901,7 +901,7 @@ clicon_strcmp(char *s1,
#ifndef HAVE_STRNDUP
char *
clicon_strndup(const char *str,
- size_t len)
+ size_t len)
{
char *new;
size_t slen;
@@ -946,17 +946,17 @@ main(int argc, char **argv)
int i;
if (argc != 2){
- usage(argv[0]);
- return 0;
+ usage(argv[0]);
+ return 0;
}
str0 = argv[1];
if ((vec = clicon_strsep(str0, " \t", &nvec)) == NULL)
- return -1;
+ return -1;
fprintf(stderr, "nvec: %d\n", nvec);
for (i=0; i nospec
- * x: <-- populate from modules
- */
- if ((ret = xml_bind_yang0(x, YB_MODULE, yspec, xerr)) < 0)
- goto done;
- if (ret == 0)
- failed++;
- break;
- default: /* shouldnt happen */
- break;
- } /* switch */
- /*! Look for YANG lists nodes and convert bodies to keys */
- xc = NULL;
- while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL)
- if (text_populate_list(xc) < 0)
- goto done;
+ /* Populate, ie associate xml nodes with yang specs
+ */
+ switch (yb){
+ case YB_MODULE_NEXT:
+ if ((ret = xml_bind_yang(x, YB_MODULE, yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ failed++;
+ break;
+ case YB_MODULE:
+ /* xt: nospec
+ * x: <-- populate from modules
+ */
+ if ((ret = xml_bind_yang0(x, YB_MODULE, yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ failed++;
+ break;
+ default: /* shouldnt happen */
+ break;
+ } /* switch */
+ /*! Look for YANG lists nodes and convert bodies to keys */
+ xc = NULL;
+ while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL)
+ if (text_populate_list(xc) < 0)
+ goto done;
}
if (failed)
- goto fail;
+ goto fail;
/* Sort the complete tree after parsing. Sorting is not really meaningful if Yang
not bound */
if (yb != YB_NONE)
- if (xml_sort_recurse(xt) < 0)
- goto done;
+ if (xml_sort_recurse(xt) < 0)
+ goto done;
retval = 1;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
clixon_text_syntax_parsel_exit(&ts);
return retval;
fail: /* invalid */
@@ -481,19 +481,19 @@ _text_syntax_parse(char *str,
*/
int
clixon_text_syntax_parse_string(char *str,
- yang_bind yb,
- yang_stmt *yspec,
- cxobj **xt,
- cxobj **xerr)
+ yang_bind yb,
+ yang_stmt *yspec,
+ cxobj **xt,
+ cxobj **xerr)
{
clicon_debug(1, "%s", __FUNCTION__);
if (xt==NULL){
- clicon_err(OE_XML, EINVAL, "xt is NULL");
- return -1;
+ clicon_err(OE_XML, EINVAL, "xt is NULL");
+ return -1;
}
if (*xt == NULL){
- if ((*xt = xml_new("top", NULL, CX_ELMNT)) == NULL)
- return -1;
+ if ((*xt = xml_new("top", NULL, CX_ELMNT)) == NULL)
+ return -1;
}
return _text_syntax_parse(str, yb, yspec, *xt, xerr);
}
@@ -530,10 +530,10 @@ clixon_text_syntax_parse_string(char *str,
*/
int
clixon_text_syntax_parse_file(FILE *fp,
- yang_bind yb,
- yang_stmt *yspec,
- cxobj **xt,
- cxobj **xerr)
+ yang_bind yb,
+ yang_stmt *yspec,
+ cxobj **xt,
+ cxobj **xerr)
{
int retval = -1;
int ret;
@@ -545,53 +545,53 @@ clixon_text_syntax_parse_file(FILE *fp,
int len = 0;
if (xt == NULL){
- clicon_err(OE_XML, EINVAL, "xt is NULL");
- return -1;
+ clicon_err(OE_XML, EINVAL, "xt is NULL");
+ return -1;
}
if ((textbuf = malloc(textbuflen)) == NULL){
- clicon_err(OE_XML, errno, "malloc");
- goto done;
+ clicon_err(OE_XML, errno, "malloc");
+ goto done;
}
memset(textbuf, 0, textbuflen);
ptr = textbuf;
while (1){
- if ((ret = fread(&ch, 1, 1, fp)) < 0){
- clicon_err(OE_XML, errno, "read");
- break;
- }
- if (ret != 0)
- textbuf[len++] = ch;
- if (ret == 0){
- if (*xt == NULL)
- if ((*xt = xml_new(TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
- goto done;
- if (len){
- if ((ret = _text_syntax_parse(ptr, yb, yspec, *xt, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- break;
- }
- if (len >= textbuflen-1){ /* Space: one for the null character */
- oldtextbuflen = textbuflen;
- textbuflen *= 2;
- if ((textbuf = realloc(textbuf, textbuflen)) == NULL){
- clicon_err(OE_XML, errno, "realloc");
- goto done;
- }
- memset(textbuf+oldtextbuflen, 0, textbuflen-oldtextbuflen);
- ptr = textbuf;
- }
+ if ((ret = fread(&ch, 1, 1, fp)) < 0){
+ clicon_err(OE_XML, errno, "read");
+ break;
+ }
+ if (ret != 0)
+ textbuf[len++] = ch;
+ if (ret == 0){
+ if (*xt == NULL)
+ if ((*xt = xml_new(TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
+ goto done;
+ if (len){
+ if ((ret = _text_syntax_parse(ptr, yb, yspec, *xt, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ break;
+ }
+ if (len >= textbuflen-1){ /* Space: one for the null character */
+ oldtextbuflen = textbuflen;
+ textbuflen *= 2;
+ if ((textbuf = realloc(textbuf, textbuflen)) == NULL){
+ clicon_err(OE_XML, errno, "realloc");
+ goto done;
+ }
+ memset(textbuf+oldtextbuflen, 0, textbuflen-oldtextbuflen);
+ ptr = textbuf;
+ }
}
retval = 1;
done:
if (retval < 0 && *xt){
- free(*xt);
- *xt = NULL;
+ free(*xt);
+ *xt = NULL;
}
if (textbuf)
- free(textbuf);
+ free(textbuf);
return retval;
fail:
retval = 0;
diff --git a/lib/src/clixon_text_syntax_parse.h b/lib/src/clixon_text_syntax_parse.h
index 56588a6a..4b0b6e47 100644
--- a/lib/src/clixon_text_syntax_parse.h
+++ b/lib/src/clixon_text_syntax_parse.h
@@ -66,4 +66,4 @@ int clixon_text_syntax_parsel_linenr(void);
int clixon_text_syntax_parselex(void *);
int clixon_text_syntax_parseparse(void *);
-#endif /* _CLIXON_TEXT_SYNTAX_PARSE_H_ */
+#endif /* _CLIXON_TEXT_SYNTAX_PARSE_H_ */
diff --git a/lib/src/clixon_text_syntax_parse.y b/lib/src/clixon_text_syntax_parse.y
index ca6be7d7..4e582e38 100644
--- a/lib/src/clixon_text_syntax_parse.y
+++ b/lib/src/clixon_text_syntax_parse.y
@@ -91,29 +91,29 @@
void
clixon_text_syntax_parseerror(void *arg,
- char *s)
+ char *s)
{
clixon_text_syntax_yacc *ts = (clixon_text_syntax_yacc *)arg;
clicon_err(OE_XML, XMLPARSE_ERRNO, "text_syntax_parse: line %d: %s: at or before: %s",
- ts->ts_linenum,
- s,
- clixon_text_syntax_parsetext);
+ ts->ts_linenum,
+ s,
+ clixon_text_syntax_parsetext);
return;
}
static cxobj*
text_add_value(cxobj *xn,
- char *value)
+ char *value)
{
cxobj *xb = NULL;
if ((xb = xml_new("body", xn, CX_BODY)) == NULL)
- goto done;
+ goto done;
if (xml_value_set(xb, value) < 0){
- xml_free(xb);
- xb = NULL;
- goto done;
+ xml_free(xb);
+ xb = NULL;
+ goto done;
}
done:
return xb;
@@ -123,7 +123,7 @@ text_add_value(cxobj *xn,
*/
static cxobj*
text_create_node(clixon_text_syntax_yacc *ts,
- char *name)
+ char *name)
{
cxobj *xn = NULL;
yang_stmt *ymod;
@@ -132,26 +132,26 @@ text_create_node(clixon_text_syntax_yacc *ts,
char *id = NULL;
if (nodeid_split(name, &prefix, &id) < 0)
- goto done;
+ goto done;
if ((xn = xml_new(id, NULL, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (prefix && ts->ts_yspec){
- /* Silently ignore if module name not found */
- if ((ymod = yang_find(ts->ts_yspec, Y_MODULE, prefix)) != NULL){
- if ((ns = yang_find_mynamespace(ymod)) == NULL){
- clicon_err(OE_YANG, 0, "No namespace");
- goto done;
- }
- /* Set default namespace */
- if (xmlns_set(xn, NULL, ns) < 0)
- goto done;
- }
+ /* Silently ignore if module name not found */
+ if ((ymod = yang_find(ts->ts_yspec, Y_MODULE, prefix)) != NULL){
+ if ((ns = yang_find_mynamespace(ymod)) == NULL){
+ clicon_err(OE_YANG, 0, "No namespace");
+ goto done;
+ }
+ /* Set default namespace */
+ if (xmlns_set(xn, NULL, ns) < 0)
+ goto done;
+ }
}
done:
if (prefix)
- free(prefix);
+ free(prefix);
if (id)
- free(id);
+ free(id);
return xn;
}
@@ -165,8 +165,8 @@ strjoin(char *str0,
len0 = str0?strlen(str0):0;
len = len0 + strlen(str1) + 1;
if ((str0 = realloc(str0, len)) == NULL){
- clicon_err(OE_YANG, errno, "realloc");
- return NULL;
+ clicon_err(OE_YANG, errno, "realloc");
+ return NULL;
}
strcpy(str0+len0, str1);
return str0;
@@ -176,8 +176,8 @@ strjoin(char *str0,
*/
static int
text_element_create(clixon_xvec *xvec0,
- cxobj *x1,
- clixon_xvec *xvec1)
+ cxobj *x1,
+ clixon_xvec *xvec1)
{
int retval = -1;
cxobj *xb;
@@ -185,13 +185,13 @@ text_element_create(clixon_xvec *xvec0,
int i;
for (i=0; istmt");
- if (clixon_child_xvec_append(_TS->ts_xtop, $1) < 0) YYERROR;
- clixon_xvec_free($1);
+ if (clixon_child_xvec_append(_TS->ts_xtop, $1) < 0) YYERROR;
+ clixon_xvec_free($1);
YYACCEPT; }
;
stmts : stmts stmt { _PARSE_DEBUG("stmts->stmts stmt");
if (clixon_xvec_merge($1, $2) < 0) YYERROR;
- clixon_xvec_free($2);
- $$ = $1;
+ clixon_xvec_free($2);
+ $$ = $1;
}
| { _PARSE_DEBUG("stmts->stmt");
if (($$ = clixon_xvec_new()) == NULL) YYERROR;
@@ -237,46 +237,46 @@ stmts : stmts stmt { _PARSE_DEBUG("stmts->stmts stmt");
stmt : id values ';' { _PARSE_DEBUG("stmt-> id value ;");
text_mark_bodies($2);
if (($$ = clixon_xvec_new()) == NULL) YYERROR;
- if (text_element_create($$, $1, $2) < 0) YYERROR;
- xml_free($1);
- clixon_xvec_free($2);
+ if (text_element_create($$, $1, $2) < 0) YYERROR;
+ xml_free($1);
+ clixon_xvec_free($2);
}
| id values '{' stmts '}' { _PARSE_DEBUG("stmt-> id values { stmts }");
text_mark_bodies($2);
- if (clixon_child_xvec_append($1, $2) < 0) YYERROR;
- clixon_xvec_free($2);
- if (clixon_child_xvec_append($1, $4) < 0) YYERROR;
- clixon_xvec_free($4);
+ if (clixon_child_xvec_append($1, $2) < 0) YYERROR;
+ clixon_xvec_free($2);
+ if (clixon_child_xvec_append($1, $4) < 0) YYERROR;
+ clixon_xvec_free($4);
if (($$ = clixon_xvec_new()) == NULL) YYERROR;
- if (clixon_xvec_append($$, $1) < 0) YYERROR;
- }
+ if (clixon_xvec_append($$, $1) < 0) YYERROR;
+ }
| id '[' values ']'
- { _PARSE_DEBUG("stmt-> id [ values ]");
+ { _PARSE_DEBUG("stmt-> id [ values ]");
if (($$ = clixon_xvec_new()) == NULL) YYERROR;
- if (text_element_create($$, $1, $3) < 0) YYERROR;
- xml_free($1);
- clixon_xvec_free($3);
- }
+ if (text_element_create($$, $1, $3) < 0) YYERROR;
+ xml_free($1);
+ clixon_xvec_free($3);
+ }
;
id : TOKEN { _PARSE_DEBUG("id->TOKEN");
if (($$ = text_create_node(_TS, $1)) == NULL) YYERROR;
- free($1);
+ free($1);
}
;
/* Array of body objects, possibly empty */
values : values value { _PARSE_DEBUG("values->values value");
cxobj* x;
- if ((x = text_add_value(NULL, $2)) == NULL) YYERROR;;
- free($2);
+ if ((x = text_add_value(NULL, $2)) == NULL) YYERROR;;
+ free($2);
if (clixon_xvec_append($1, x) < 0) YYERROR;
- $$ = $1;
+ $$ = $1;
}
| { _PARSE_DEBUG("values->value");
if (($$ = clixon_xvec_new()) == NULL) YYERROR;
- }
- ;
+ }
+ ;
/* Returns single string either as a single token or contained by double quotes */
value : TOKEN { _PARSE_DEBUG("value->TOKEN");
@@ -284,7 +284,7 @@ value : TOKEN { _PARSE_DEBUG("value->TOKEN");
}
| '"' substr '"' { _PARSE_DEBUG("value-> \" substr \"");
$$=$2;
- }
+ }
;
/* Value within quotes merged to single string, has separate lexical scope */
diff --git a/lib/src/clixon_uid.c b/lib/src/clixon_uid.c
index 8c55fabd..7d5a5541 100644
--- a/lib/src/clixon_uid.c
+++ b/lib/src/clixon_uid.c
@@ -71,7 +71,7 @@
*/
int
group_name2gid(const char *name,
- gid_t *gid)
+ gid_t *gid)
{
int retval = -1;
char buf[1024];
@@ -82,15 +82,15 @@ group_name2gid(const char *name,
gr = &g0;
/* This leaks memory in ubuntu */
if (getgrnam_r(name, gr, buf, sizeof(buf), >mp) < 0){
- clicon_err(OE_UNIX, errno, "getgrnam_r(%s)", name);
- goto done;
+ clicon_err(OE_UNIX, errno, "getgrnam_r(%s)", name);
+ goto done;
}
if (gtmp == NULL){
- clicon_err(OE_UNIX, 0, "No such group: %s", name);
- goto done;
+ clicon_err(OE_UNIX, 0, "No such group: %s", name);
+ goto done;
}
if (gid)
- *gid = gr->gr_gid;
+ *gid = gr->gr_gid;
retval = 0;
done:
return retval;
@@ -104,7 +104,7 @@ group_name2gid(const char *name,
*/
int
name2uid(const char *name,
- uid_t *uid)
+ uid_t *uid)
{
int retval = -1;
char buf[1024];
@@ -112,15 +112,15 @@ name2uid(const char *name,
struct passwd *pwbufp = NULL;
if (getpwnam_r(name, &pwbuf, buf, sizeof(buf), &pwbufp) != 0){
- clicon_err(OE_UNIX, errno, "getpwnam_r(%s)", name);
- goto done;
+ clicon_err(OE_UNIX, errno, "getpwnam_r(%s)", name);
+ goto done;
}
if (pwbufp == NULL){
- clicon_err(OE_UNIX, 0, "No such user: %s", name);
- goto done;
+ clicon_err(OE_UNIX, 0, "No such user: %s", name);
+ goto done;
}
if (uid)
- *uid = pwbufp->pw_uid;
+ *uid = pwbufp->pw_uid;
retval = 0;
done:
return retval;
@@ -134,7 +134,7 @@ name2uid(const char *name,
*/
int
uid2name(const uid_t uid,
- char **name)
+ char **name)
{
int retval = -1;
char buf[1024];
@@ -142,19 +142,19 @@ uid2name(const uid_t uid,
struct passwd *pwbufp = NULL;
if (getpwuid_r(uid, &pwbuf, buf, sizeof(buf), &pwbufp) != 0){
- clicon_err(OE_UNIX, errno, "getpwuid_r(%u)", uid);
- goto done;
+ clicon_err(OE_UNIX, errno, "getpwuid_r(%u)", uid);
+ goto done;
}
if (pwbufp == NULL){
- clicon_err(OE_UNIX, ENOENT, "No such user: %u", uid);
- goto done;
+ clicon_err(OE_UNIX, ENOENT, "No such user: %u", uid);
+ goto done;
}
if (name){
- if ((*name = strdup(pwbufp->pw_name)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
+ if ((*name = strdup(pwbufp->pw_name)) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
}
retval = 0;
done:
@@ -175,12 +175,12 @@ drop_priv_temp(uid_t new_uid)
/* XXX: implicit declaration of function 'setresuid' on travis */
if (setresuid(-1, new_uid, geteuid()) < 0){
- clicon_err(OE_UNIX, errno, "setresuid");
- goto done;
+ clicon_err(OE_UNIX, errno, "setresuid");
+ goto done;
}
if (geteuid() != new_uid){
- clicon_err(OE_UNIX, errno, "geteuid");
- goto done;
+ clicon_err(OE_UNIX, errno, "geteuid");
+ goto done;
}
retval = 0;
done:
@@ -204,18 +204,18 @@ drop_priv_perm(uid_t new_uid)
uid_t suid;
if (setresuid(new_uid, new_uid, new_uid) < 0){
- clicon_err(OE_UNIX, errno, "setresuid");
- goto done;
+ clicon_err(OE_UNIX, errno, "setresuid");
+ goto done;
}
if (getresuid(&ruid, &euid, &suid) < 0){
- clicon_err(OE_UNIX, errno, "getresuid");
- goto done;
+ clicon_err(OE_UNIX, errno, "getresuid");
+ goto done;
}
if (ruid != new_uid ||
- euid != new_uid ||
- suid != new_uid){
- clicon_err(OE_UNIX, EINVAL, "Non-matching uid");
- goto done;
+ euid != new_uid ||
+ suid != new_uid){
+ clicon_err(OE_UNIX, EINVAL, "Non-matching uid");
+ goto done;
}
retval = 0;
done:
@@ -237,16 +237,16 @@ restore_priv(void)
uid_t suid;
if (getresuid(&ruid, &euid, &suid) < 0){
- clicon_err(OE_UNIX, errno, "setresuid");
- goto done;
+ clicon_err(OE_UNIX, errno, "setresuid");
+ goto done;
}
if (setresuid(-1, suid, -1) < 0){
- clicon_err(OE_UNIX, errno, "setresuid");
- goto done;
+ clicon_err(OE_UNIX, errno, "setresuid");
+ goto done;
}
if (geteuid() != suid){
- clicon_err(OE_UNIX, EINVAL, "Non-matching uid");
- goto done;
+ clicon_err(OE_UNIX, EINVAL, "Non-matching uid");
+ goto done;
}
retval = 0;
done:
diff --git a/lib/src/clixon_validate.c b/lib/src/clixon_validate.c
index 7c45390a..fec8bcbf 100644
--- a/lib/src/clixon_validate.c
+++ b/lib/src/clixon_validate.c
@@ -114,9 +114,9 @@
*/
static int
validate_leafref(cxobj *xt,
- yang_stmt *ys,
- yang_stmt *ytype,
- cxobj **xret)
+ yang_stmt *ys,
+ yang_stmt *ytype,
+ cxobj **xret)
{
int retval = -1;
yang_stmt *ypath;
@@ -136,65 +136,65 @@ validate_leafref(cxobj *xt,
/* require instance */
if ((yreqi = yang_find(ytype, Y_REQUIRE_INSTANCE, NULL)) != NULL){
- if ((cv = yang_cv_get(yreqi)) != NULL) /* shouldnt happen */
- require_instance = cv_bool_get(cv);
+ if ((cv = yang_cv_get(yreqi)) != NULL) /* shouldnt happen */
+ require_instance = cv_bool_get(cv);
}
/* Find referred XML instances */
if (require_instance == 0)
- goto ok;
+ goto ok;
if ((ypath = yang_find(ytype, Y_PATH, NULL)) == NULL){
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cberr, "Leafref requires path statement");
- if (xret && netconf_missing_element_xml(xret, "application",
- yang_argument_get(ytype),
- cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cberr, "Leafref requires path statement");
+ if (xret && netconf_missing_element_xml(xret, "application",
+ yang_argument_get(ytype),
+ cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
}
if ((path_arg = yang_argument_get(ypath)) == NULL){
- clicon_err(OE_YANG, 0, "No argument for Y_PATH");
- goto done;
+ clicon_err(OE_YANG, 0, "No argument for Y_PATH");
+ goto done;
}
if ((leafrefbody = xml_body(xt)) == NULL)
- goto ok;
+ goto ok;
if (xml_nsctx_yang(ys, &nsc) < 0)
- goto done;
+ goto done;
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, path_arg) < 0)
- goto done;
+ goto done;
for (i = 0; i < xlen; i++) {
- x = xvec[i];
- if ((leafbody = xml_body(x)) == NULL)
- continue;
- if (strcmp(leafbody, leafrefbody) == 0)
- break;
+ x = xvec[i];
+ if ((leafbody = xml_body(x)) == NULL)
+ continue;
+ if (strcmp(leafbody, leafrefbody) == 0)
+ break;
}
if (i==xlen){
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- ymod = ys_module(ys);
- cprintf(cberr, "Leafref validation failed: No leaf %s matching path %s in %s.yang:%d",
- leafrefbody,
- path_arg,
- yang_argument_get(ymod),
- yang_linenum_get(ys));
- if (xret && netconf_bad_element_xml(xret, "application", leafrefbody, cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ ymod = ys_module(ys);
+ cprintf(cberr, "Leafref validation failed: No leaf %s matching path %s in %s.yang:%d",
+ leafrefbody,
+ path_arg,
+ yang_argument_get(ymod),
+ yang_linenum_get(ys));
+ if (xret && netconf_bad_element_xml(xret, "application", leafrefbody, cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
}
ok:
retval = 1;
done:
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (xvec)
- free(xvec);
+ free(xvec);
return retval;
fail:
retval = 0;
@@ -225,9 +225,9 @@ validate_leafref(cxobj *xt,
*/
static int
validate_identityref(cxobj *xt,
- yang_stmt *ys,
- yang_stmt *ytype,
- cxobj **xret)
+ yang_stmt *ys,
+ yang_stmt *ytype,
+ cxobj **xret)
{
int retval = -1;
char *node = NULL;
@@ -242,79 +242,79 @@ validate_identityref(cxobj *xt,
yang_stmt *ymod;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
/* Get idref value. Then see if this value is derived from ytype.
*/
if ((node = xml_body(xt)) == NULL){ /* It may not be empty */
- if (xret && netconf_bad_element_xml(xret, "application", xml_name(xt), "Identityref should not be empty") < 0)
- goto done;
- goto fail;
+ if (xret && netconf_bad_element_xml(xret, "application", xml_name(xt), "Identityref should not be empty") < 0)
+ goto done;
+ goto fail;
}
if (nodeid_split(node, &prefix, &id) < 0)
- goto done;
+ goto done;
/* This is the type's base reference */
if ((ybaseref = yang_find(ytype, Y_BASE, NULL)) == NULL){
- if (xret && netconf_missing_element_xml(xret, "application", yang_argument_get(ytype), "Identityref validation failed, no base") < 0)
- goto done;
- goto fail;
+ if (xret && netconf_missing_element_xml(xret, "application", yang_argument_get(ytype), "Identityref validation failed, no base") < 0)
+ goto done;
+ goto fail;
}
/* This is the actual base identity */
if ((ybaseid = yang_find_identity(ybaseref, yang_argument_get(ybaseref))) == NULL){
- if (xret && netconf_missing_element_xml(xret, "application", yang_argument_get(ybaseref), "Identityref validation failed, no base identity") < 0)
- goto done;
- goto fail;
+ if (xret && netconf_missing_element_xml(xret, "application", yang_argument_get(ybaseref), "Identityref validation failed, no base identity") < 0)
+ goto done;
+ goto fail;
}
/* idref from prefix:id to module:id */
if (prefix == NULL)
- ymod = ys_module(ys);
+ ymod = ys_module(ys);
else{ /* from prefix to name */
#if 1 /* IDENTITYREF_KLUDGE */
- ymod = yang_find_module_by_prefix_yspec(ys_spec(ys), prefix);
+ ymod = yang_find_module_by_prefix_yspec(ys_spec(ys), prefix);
#endif
}
if (ymod == NULL){
- cprintf(cberr, "Identityref validation failed, %s not derived from %s in %s.yang:%d",
- node,
- yang_argument_get(ybaseid),
- yang_argument_get(ys_module(ybaseid)),
- yang_linenum_get(ybaseid));
- if (xret && netconf_operation_failed_xml(xret, "application", cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
+ cprintf(cberr, "Identityref validation failed, %s not derived from %s in %s.yang:%d",
+ node,
+ yang_argument_get(ybaseid),
+ yang_argument_get(ys_module(ybaseid)),
+ yang_linenum_get(ybaseid));
+ if (xret && netconf_operation_failed_xml(xret, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
}
cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
- idref = cbuf_get(cb);
+ idref = cbuf_get(cb);
/* Here check if node is in the derived node list of the base identity
* The derived node list is a cvec computed XXX
*/
idrefvec = yang_cvec_get(ybaseid);
if (cvec_find(idrefvec, idref) == NULL){
- cprintf(cberr, "Identityref validation failed, %s not derived from %s in %s.yang:%d",
- node,
- yang_argument_get(ybaseid),
- yang_argument_get(ys_module(ybaseid)),
- yang_linenum_get(ybaseid));
- if (xret && netconf_operation_failed_xml(xret, "application", cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
+ cprintf(cberr, "Identityref validation failed, %s not derived from %s in %s.yang:%d",
+ node,
+ yang_argument_get(ybaseid),
+ yang_argument_get(ys_module(ybaseid)),
+ yang_linenum_get(ybaseid));
+ if (xret && netconf_operation_failed_xml(xret, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
}
retval = 1;
done:
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (id)
- free(id);
+ free(id);
if (prefix)
- free(prefix);
+ free(prefix);
return retval;
fail:
retval = 0;
@@ -365,8 +365,8 @@ validate_identityref(cxobj *xt,
*/
int
xml_yang_validate_rpc(clicon_handle h,
- cxobj *xrpc,
- cxobj **xret)
+ cxobj *xrpc,
+ cxobj **xret)
{
int retval = -1;
cxobj *xn; /* rpc name */
@@ -375,36 +375,36 @@ xml_yang_validate_rpc(clicon_handle h,
int ret;
if (strcmp(xml_name(xrpc), "rpc")){
- clicon_err(OE_XML, EINVAL, "Expected RPC");
- goto done;
+ clicon_err(OE_XML, EINVAL, "Expected RPC");
+ goto done;
}
rpcprefix = xml_prefix(xrpc);
if (xml2ns(xrpc, rpcprefix, &namespace) < 0)
- goto done;
+ goto done;
/* Only accept resolved NETCONF base namespace */
if (namespace == NULL || strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){
- if (xret && netconf_unknown_namespace_xml(xret, "protocol", rpcprefix, "No appropriate namespace associated with prefix")< 0)
- goto done;
- goto fail;
+ if (xret && netconf_unknown_namespace_xml(xret, "protocol", rpcprefix, "No appropriate namespace associated with prefix")< 0)
+ goto done;
+ goto fail;
}
xn = NULL;
/* xn is name of rpc, ie */
while ((xn = xml_child_each(xrpc, xn, CX_ELMNT)) != NULL) {
- if (xml_spec(xn) == NULL){
- if (xret && netconf_unknown_element_xml(xret, "application", xml_name(xn), NULL) < 0)
- goto done;
- goto fail;
- }
- if ((ret = xml_yang_validate_all(h, xn, xret)) < 0)
- goto done; /* error or validation fail */
- if (ret == 0)
- goto fail;
- if ((ret = xml_yang_validate_add(h, xn, xret)) < 0)
- goto done; /* error or validation fail */
- if (ret == 0)
- goto fail;
- if (xml_default_recurse(xn, 0) < 0)
- goto done;
+ if (xml_spec(xn) == NULL){
+ if (xret && netconf_unknown_element_xml(xret, "application", xml_name(xn), NULL) < 0)
+ goto done;
+ goto fail;
+ }
+ if ((ret = xml_yang_validate_all(h, xn, xret)) < 0)
+ goto done; /* error or validation fail */
+ if (ret == 0)
+ goto fail;
+ if ((ret = xml_yang_validate_add(h, xn, xret)) < 0)
+ goto done; /* error or validation fail */
+ if (ret == 0)
+ goto fail;
+ if (xml_default_recurse(xn, 0) < 0)
+ goto done;
}
// ok: /* pass validation */
retval = 1;
@@ -412,15 +412,15 @@ xml_yang_validate_rpc(clicon_handle h,
return retval;
fail:
if (xret && *xret && clixon_xml_attr_copy(xrpc, *xret, "message-id") < 0)
- goto done;
+ goto done;
retval = 0;
goto done;
}
int
xml_yang_validate_rpc_reply(clicon_handle h,
- cxobj *xrpc,
- cxobj **xret)
+ cxobj *xrpc,
+ cxobj **xret)
{
int retval = -1;
yang_stmt *yn=NULL; /* rpc name */
@@ -430,42 +430,42 @@ xml_yang_validate_rpc_reply(clicon_handle h,
int ret;
if (strcmp(xml_name(xrpc), "rpc-reply")){
- clicon_err(OE_XML, EINVAL, "Expected RPC");
- goto done;
+ clicon_err(OE_XML, EINVAL, "Expected RPC");
+ goto done;
}
rpcprefix = xml_prefix(xrpc);
if (xml2ns(xrpc, rpcprefix, &namespace) < 0)
- goto done;
+ goto done;
/* Only accept resolved NETCONF base namespace */
if (namespace == NULL || strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){
- if (xret && netconf_unknown_namespace_xml(xret, "protocol",
- rpcprefix?rpcprefix:"null",
- "No appropriate namespace associated with prefix")< 0)
- goto done;
- goto fail;
+ if (xret && netconf_unknown_namespace_xml(xret, "protocol",
+ rpcprefix?rpcprefix:"null",
+ "No appropriate namespace associated with prefix")< 0)
+ goto done;
+ goto fail;
}
xn = NULL;
/* xn is name of rpc, ie */
while ((xn = xml_child_each(xrpc, xn, CX_ELMNT)) != NULL) {
- /* OK and rpc-error are not explicit in ietf-netconf.yang. Why are they hardcoded ? */
- if (strcmp(xml_name(xn), "ok") == 0 || strcmp(xml_name(xn), "rpc-error") == 0){
- continue;
- }
- if ((yn = xml_spec(xn)) == NULL){
- if (xret && netconf_unknown_element_xml(xret, "application", xml_name(xn), NULL) < 0)
- goto done;
- goto fail;
- }
- if ((ret = xml_yang_validate_all(h, xn, xret)) < 0)
- goto done; /* error or validation fail */
- if (ret == 0)
- goto fail;
- if ((ret = xml_yang_validate_add(h, xn, xret)) < 0)
- goto done; /* error or validation fail */
- if (ret == 0)
- goto fail;
- if (xml_default_recurse(xn, 0) < 0)
- goto done;
+ /* OK and rpc-error are not explicit in ietf-netconf.yang. Why are they hardcoded ? */
+ if (strcmp(xml_name(xn), "ok") == 0 || strcmp(xml_name(xn), "rpc-error") == 0){
+ continue;
+ }
+ if ((yn = xml_spec(xn)) == NULL){
+ if (xret && netconf_unknown_element_xml(xret, "application", xml_name(xn), NULL) < 0)
+ goto done;
+ goto fail;
+ }
+ if ((ret = xml_yang_validate_all(h, xn, xret)) < 0)
+ goto done; /* error or validation fail */
+ if (ret == 0)
+ goto fail;
+ if ((ret = xml_yang_validate_add(h, xn, xret)) < 0)
+ goto done; /* error or validation fail */
+ if (ret == 0)
+ goto fail;
+ if (xml_default_recurse(xn, 0) < 0)
+ goto done;
}
// ok: /* pass validation */
retval = 1;
@@ -473,7 +473,7 @@ xml_yang_validate_rpc_reply(clicon_handle h,
return retval;
fail:
if (xret && *xret && clixon_xml_attr_copy(xrpc, *xret, "message-id") < 0)
- goto done;
+ goto done;
retval = 0;
goto done;
}
@@ -489,8 +489,8 @@ xml_yang_validate_rpc_reply(clicon_handle h,
*/
static int
check_choice(cxobj *xt,
- yang_stmt *yt,
- cxobj **xret)
+ yang_stmt *yt,
+ cxobj **xret)
{
int retval = -1;
yang_stmt *y;
@@ -502,48 +502,48 @@ check_choice(cxobj *xt,
cxobj *xp;
if ((ytp = yang_parent_get(yt)) == NULL)
- goto ok;
+ goto ok;
/* Return OK if xt is not choice */
switch (yang_keyword_get(ytp)){
case Y_CASE:
- ytcase = ytp;
- ytchoice = yang_parent_get(ytp);
- break;
+ ytcase = ytp;
+ ytchoice = yang_parent_get(ytp);
+ break;
case Y_CHOICE:
- ytchoice = ytp;
- break;
+ ytchoice = ytp;
+ break;
default:
- goto ok; /* Not choice */
- break;
+ goto ok; /* Not choice */
+ break;
}
if ((xp = xml_parent(xt)) == NULL)
- goto ok;
+ goto ok;
x = NULL; /* Find a child with same yang spec */
while ((x = xml_child_each(xp, x, CX_ELMNT)) != NULL) {
- if (x == xt)
- continue;
- y = xml_spec(x);
- if (y == yt) /* eg same list */
- continue;
- yp = yang_parent_get(y);
- switch (yang_keyword_get(yp)){
- case Y_CASE:
- if (yang_parent_get(yp) != ytchoice) /* Not same choice (not relevant) */
- continue;
- if (yp == ytcase) /* same choice but different case */
- continue;
- break;
- case Y_CHOICE:
- if (yp != ytchoice) /* Not same choice (not relevant) */
- continue;
- break;
- default:
- continue; /* not choice */
- break;
- }
- if (xret && netconf_bad_element_xml(xret, "application", xml_name(x), "Element in choice statement already exists") < 0)
- goto done;
- goto fail;
+ if (x == xt)
+ continue;
+ y = xml_spec(x);
+ if (y == yt) /* eg same list */
+ continue;
+ yp = yang_parent_get(y);
+ switch (yang_keyword_get(yp)){
+ case Y_CASE:
+ if (yang_parent_get(yp) != ytchoice) /* Not same choice (not relevant) */
+ continue;
+ if (yp == ytcase) /* same choice but different case */
+ continue;
+ break;
+ case Y_CHOICE:
+ if (yp != ytchoice) /* Not same choice (not relevant) */
+ continue;
+ break;
+ default:
+ continue; /* not choice */
+ break;
+ }
+ if (xret && netconf_bad_element_xml(xret, "application", xml_name(x), "Element in choice statement already exists") < 0)
+ goto done;
+ goto fail;
} /* while */
ok:
retval = 1;
@@ -569,8 +569,8 @@ check_choice(cxobj *xt,
*/
static int
check_list_key(cxobj *xt,
- yang_stmt *yt,
- cxobj **xret)
+ yang_stmt *yt,
+ cxobj **xret)
{
int retval = -1;
@@ -580,24 +580,24 @@ check_list_key(cxobj *xt,
char *keyname;
if (yt == NULL || !yang_config(yt) || yang_keyword_get(yt) != Y_LIST){
- clicon_err(OE_YANG, EINVAL, "yt is not a config true list node");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "yt is not a config true list node");
+ goto done;
}
yc = NULL;
while ((yc = yn_each(yt, yc)) != NULL) {
- if (yang_keyword_get(yc) != Y_KEY)
- continue;
- /* Check if a list does not have mandatory key leafs */
- cvk = yang_cvec_get(yt); /* Use Y_LIST cache, see ys_populate_list() */
- cvi = NULL;
- while ((cvi = cvec_each(cvk, cvi)) != NULL) {
- keyname = cv_string_get(cvi);
- if (xml_find_type(xt, NULL, keyname, CX_ELMNT) == NULL){
- if (xret && netconf_missing_element_xml(xret, "application", keyname, "Mandatory key") < 0)
- goto done;
- goto fail;
- }
- }
+ if (yang_keyword_get(yc) != Y_KEY)
+ continue;
+ /* Check if a list does not have mandatory key leafs */
+ cvk = yang_cvec_get(yt); /* Use Y_LIST cache, see ys_populate_list() */
+ cvi = NULL;
+ while ((cvi = cvec_each(cvk, cvi)) != NULL) {
+ keyname = cv_string_get(cvi);
+ if (xml_find_type(xt, NULL, keyname, CX_ELMNT) == NULL){
+ if (xret && netconf_missing_element_xml(xret, "application", keyname, "Mandatory key") < 0)
+ goto done;
+ goto fail;
+ }
+ }
}
retval = 1;
done:
@@ -613,41 +613,45 @@ check_list_key(cxobj *xt,
* @retval -1 Error
*/
static int
-choice_mandatory_check(yang_stmt *ycase,
- cxobj **xret)
+choice_mandatory_check(cxobj *xt,
+ yang_stmt *ycase,
+ cxobj **xret)
{
int retval = -1;
yang_stmt *yc = NULL;
cbuf *cb = NULL;
int fail = 0;
+ int ret;
while ((yc = yn_each(ycase, yc)) != NULL) {
- if (yang_mandatory(yc)){
- if (yang_flag_get(yc, YANG_FLAG_MARK))
- yang_flag_reset(yc, YANG_FLAG_MARK);
- else if (fail == 0){
- fail++;
- if (xret){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Mandatory variable %s in module %s",
- yang_argument_get(yc),
- yang_argument_get(ys_module(ycase)));
- if (netconf_missing_element_xml(xret, "application", yang_argument_get(yc), cbuf_get(cb)) < 0)
- goto done;
- }
- }
- }
+ if ((ret = yang_xml_mandatory(xt, yc)) < 0)
+ goto done;
+ if (ret == 1){
+ if (yang_flag_get(yc, YANG_FLAG_MARK))
+ yang_flag_reset(yc, YANG_FLAG_MARK);
+ else if (fail == 0){
+ fail++;
+ if (xret){
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Mandatory variable %s in module %s",
+ yang_argument_get(yc),
+ yang_argument_get(ys_module(ycase)));
+ if (netconf_missing_element_xml(xret, "application", yang_argument_get(yc), cbuf_get(cb)) < 0)
+ goto done;
+ }
+ }
+ }
}
if (fail)
- retval = 0;
+ retval = 0;
else
- retval = 1;
+ retval = 1;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -661,9 +665,9 @@ choice_mandatory_check(yang_stmt *ycase,
*/
static int
yang_ancestor_child(yang_stmt *ys,
- yang_stmt *ytop,
- yang_stmt **ym,
- yang_stmt **ymp)
+ yang_stmt *ytop,
+ yang_stmt **ym,
+ yang_stmt **ymp)
{
yang_stmt *y;
yang_stmt *yprev = NULL;
@@ -671,14 +675,14 @@ yang_ancestor_child(yang_stmt *ys,
y = ys;
while (y != NULL){
- yp = yang_parent_get(y);
- if (yp != NULL && yp == ytop){
- *ym = yprev;
- *ymp = y;
- return 1;
- }
- yprev = y;
- y = yp;
+ yp = yang_parent_get(y);
+ if (yp != NULL && yp == ytop){
+ *ym = yprev;
+ *ymp = y;
+ return 1;
+ }
+ yprev = y;
+ y = yp;
}
*ym = NULL;
*ymp = NULL;
@@ -711,8 +715,8 @@ yang_ancestor_child(yang_stmt *ys,
*/
static int
check_mandatory_case(cxobj *xt,
- yang_stmt *yc,
- cxobj **xret)
+ yang_stmt *yc,
+ cxobj **xret)
{
int retval = 0;
cxobj *x;
@@ -725,42 +729,46 @@ check_mandatory_case(cxobj *xt,
ycase = NULL;
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- if ((y = xml_spec(x)) != NULL &&
- yang_ancestor_child(y, yc, &ym, &ycnew) != 0 &&
- yang_keyword_get(ycnew) == Y_CASE){
- if (ym && yang_mandatory(ym)){
- if (yang_flag_get(ym, YANG_FLAG_MARK) != 0){
- clicon_debug(1, "%s Already marked, shouldnt happen", __FUNCTION__);
- }
- yang_flag_set(ym, YANG_FLAG_MARK);
- }
- if (ycase != NULL){
- if (ycnew != ycase){ /* End of case, new case */
- /* Check and clear marked mandatory */
- if ((ret = choice_mandatory_check(ycase, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- ycase = ycnew;
- }
- }
- else /* New case */
- ycase = ycnew;
- }
- else if (ycase != NULL){ /* End of case */
- /* Check and clear marked mandatory */
- if ((ret = choice_mandatory_check(ycase, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- ycase = NULL;
- }
+ if ((y = xml_spec(x)) != NULL &&
+ yang_ancestor_child(y, yc, &ym, &ycnew) != 0 &&
+ yang_keyword_get(ycnew) == Y_CASE){
+ if (ym){
+ if ((ret = yang_xml_mandatory(xt, ym)) < 0)
+ goto done;
+ if (ret == 1){
+ if (yang_flag_get(ym, YANG_FLAG_MARK) != 0){
+ clicon_debug(1, "%s Already marked, shouldnt happen", __FUNCTION__);
+ }
+ yang_flag_set(ym, YANG_FLAG_MARK);
+ }
+ }
+ if (ycase != NULL){
+ if (ycnew != ycase){ /* End of case, new case */
+ /* Check and clear marked mandatory */
+ if ((ret = choice_mandatory_check(xt, ycase, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ ycase = ycnew;
+ }
+ }
+ else /* New case */
+ ycase = ycnew;
+ }
+ else if (ycase != NULL){ /* End of case */
+ /* Check and clear marked mandatory */
+ if ((ret = choice_mandatory_check(xt, ycase, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ ycase = NULL;
+ }
}
if (ycase){
- if ((ret = choice_mandatory_check(ycase, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = choice_mandatory_check(xt, ycase, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
retval = 1;
done:
@@ -780,8 +788,8 @@ check_mandatory_case(cxobj *xt,
*/
static int
check_mandatory(cxobj *xt,
- yang_stmt *yt,
- cxobj **xret)
+ yang_stmt *yt,
+ cxobj **xret)
{
int retval = -1;
@@ -793,77 +801,79 @@ check_mandatory(cxobj *xt,
int ret;
if (yt == NULL || !yang_config(yt)){
- clicon_err(OE_YANG, EINVAL, "yt is not config true");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "yt is not config true");
+ goto done;
}
if (yang_keyword_get(yt) == Y_LIST){
- if ((ret = check_list_key(xt, yt, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = check_list_key(xt, yt, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
yc = NULL;
while ((yc = yn_each(yt, yc)) != NULL) {
- /* Choice is more complex because of choice/case structure and possibly hierarchical */
- if (yang_keyword_get(yc) == Y_CHOICE){
- if (yang_mandatory(yc)){
- x = NULL;
- while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- if ((y = xml_spec(x)) != NULL &&
- (yp = yang_choice(y)) != NULL &&
- yp == yc){
- break; /* leave loop with x set */
- }
- }
- if (x == NULL){
- /* @see RFC7950: 15.6 Error Message for Data That Violates
- * a Mandatory "choice" Statement */
- if (xret && netconf_missing_choice_xml(xret, xt, yang_argument_get(yc), NULL) < 0)
- goto done;
- goto fail;
- }
- }
- /*! Check mandatory nodes in case according to RFC7950 7.9.4 */
- if ((ret = check_mandatory_case(xt, yc, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- if (!yang_mandatory(yc)) /* Rest of yangs are immediate children */
- continue;
- switch (yang_keyword_get(yc)){
- case Y_CONTAINER:
- case Y_ANYDATA:
- case Y_ANYXML:
- case Y_LEAF:
- if (yang_config(yc)==0)
- break;
- /* Find a child with the mandatory yang */
- x = NULL;
- while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- if ((y = xml_spec(x)) != NULL
- && y==yc)
- break; /* got it */
- }
- if (x == NULL){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Mandatory variable of %s in module %s", xml_name(xt), yang_argument_get(ys_module(yc)));
- if (xret && netconf_missing_element_xml(xret, "application", yang_argument_get(yc), cbuf_get(cb)) < 0)
- goto done;
- goto fail;
- }
- break;
- default:
- break;
- } /* switch */
+ /* Choice is more complex because of choice/case structure and possibly hierarchical */
+ if (yang_keyword_get(yc) == Y_CHOICE){
+ if (yang_xml_mandatory(xt, yc)){
+ x = NULL;
+ while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
+ if ((y = xml_spec(x)) != NULL &&
+ (yp = yang_choice(y)) != NULL &&
+ yp == yc){
+ break; /* leave loop with x set */
+ }
+ }
+ if (x == NULL){
+ /* @see RFC7950: 15.6 Error Message for Data That Violates
+ * a Mandatory "choice" Statement */
+ if (xret && netconf_missing_choice_xml(xret, xt, yang_argument_get(yc), NULL) < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ /*! Check mandatory nodes in case according to RFC7950 7.9.4 */
+ if ((ret = check_mandatory_case(xt, yc, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ if ((ret = yang_xml_mandatory(xt, yc)) < 0) /* Rest of yangs are immediate children */
+ goto done;
+ if (ret == 0)
+ continue;
+ switch (yang_keyword_get(yc)){
+ case Y_CONTAINER:
+ case Y_ANYDATA:
+ case Y_ANYXML:
+ case Y_LEAF:
+ if (yang_config(yc)==0)
+ break;
+ /* Find a child with the mandatory yang */
+ x = NULL;
+ while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
+ if ((y = xml_spec(x)) != NULL
+ && y==yc)
+ break; /* got it */
+ }
+ if (x == NULL){
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Mandatory variable of %s in module %s", xml_name(xt), yang_argument_get(ys_module(yc)));
+ if (xret && netconf_missing_element_xml(xret, "application", yang_argument_get(yc), cbuf_get(cb)) < 0)
+ goto done;
+ goto fail;
+ }
+ break;
+ default:
+ break;
+ } /* switch */
}
retval = 1;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
fail:
retval = 0;
@@ -892,8 +902,8 @@ check_mandatory(cxobj *xt,
*/
int
xml_yang_validate_add(clicon_handle h,
- cxobj *xt,
- cxobj **xret)
+ cxobj *xt,
+ cxobj **xret)
{
int retval = -1;
cg_var *cv = NULL;
@@ -908,68 +918,68 @@ xml_yang_validate_add(clicon_handle h,
/* if not given by argument (overide) use default link
and !Node has a config sub-statement and it is false */
if ((yt = xml_spec(xt)) != NULL && yang_config(yt) != 0){
- if ((ret = check_choice(xt, yt, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- /* Check leaf values */
- switch (yang_keyword_get(yt)){
- case Y_LEAF:
- /* fall thru */
- case Y_LEAF_LIST:
- /* validate value against ranges, etc */
- if ((cv0 = yang_cv_get(yt)) == NULL)
- break;
- if ((cv = cv_dup(cv0)) == NULL){
- clicon_err(OE_UNIX, errno, "cv_dup");
- goto done;
- }
- /* In the union and leafref case, value is parsed as generic REST type,
- * needs to be reparsed when concrete type is selected
- * see ys_cv_validate_union_one and ys_cv_validate_leafref
- */
- if ((body = xml_body(xt)) == NULL){
- /* We do not allow ints to be empty. Otherwise NULL strings
- * are considered as "" */
- cvtype = cv_type_get(cv);
- if (cv_isint(cvtype) || cvtype == CGV_BOOL || cvtype == CGV_DEC64){
- if (xret && netconf_bad_element_xml(xret, "application", yang_argument_get(yt), "Invalid NULL value") < 0)
- goto done;
- goto fail;
- }
- }
- else{
- if (cv_parse1(body, cv, &reason) != 1){
- if (xret && netconf_bad_element_xml(xret, "application", yang_argument_get(yt), reason) < 0)
- goto done;
- goto fail;
- }
- }
- if ((ret = ys_cv_validate(h, cv, yt, NULL, &reason)) < 0)
- goto done;
- if (ret == 0){
- if (xret && netconf_bad_element_xml(xret, "application", yang_argument_get(yt), reason) < 0)
- goto done;
- goto fail;
- }
- break;
- default:
- break;
- }
+ if ((ret = check_choice(xt, yt, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ /* Check leaf values */
+ switch (yang_keyword_get(yt)){
+ case Y_LEAF:
+ /* fall thru */
+ case Y_LEAF_LIST:
+ /* validate value against ranges, etc */
+ if ((cv0 = yang_cv_get(yt)) == NULL)
+ break;
+ if ((cv = cv_dup(cv0)) == NULL){
+ clicon_err(OE_UNIX, errno, "cv_dup");
+ goto done;
+ }
+ /* In the union and leafref case, value is parsed as generic REST type,
+ * needs to be reparsed when concrete type is selected
+ * see ys_cv_validate_union_one and ys_cv_validate_leafref
+ */
+ if ((body = xml_body(xt)) == NULL){
+ /* We do not allow ints to be empty. Otherwise NULL strings
+ * are considered as "" */
+ cvtype = cv_type_get(cv);
+ if (cv_isint(cvtype) || cvtype == CGV_BOOL || cvtype == CGV_DEC64){
+ if (xret && netconf_bad_element_xml(xret, "application", yang_argument_get(yt), "Invalid NULL value") < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ else{
+ if (cv_parse1(body, cv, &reason) != 1){
+ if (xret && netconf_bad_element_xml(xret, "application", yang_argument_get(yt), reason) < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ if ((ret = ys_cv_validate(h, cv, yt, NULL, &reason)) < 0)
+ goto done;
+ if (ret == 0){
+ if (xret && netconf_bad_element_xml(xret, "application", yang_argument_get(yt), reason) < 0)
+ goto done;
+ goto fail;
+ }
+ break;
+ default:
+ break;
+ }
}
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- if ((ret = xml_yang_validate_add(h, x, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = xml_yang_validate_add(h, x, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
retval = 1;
done:
if (cv)
- cv_free(cv);
+ cv_free(cv);
if (reason)
- free(reason);
+ free(reason);
return retval;
fail:
retval = 0;
@@ -982,7 +992,7 @@ xml_yang_validate_add(clicon_handle h,
*/
int
xml_yang_validate_list_key_only(cxobj *xt,
- cxobj **xret)
+ cxobj **xret)
{
int retval = -1;
yang_stmt *yt; /* yang spec of xt going in */
@@ -992,19 +1002,19 @@ xml_yang_validate_list_key_only(cxobj *xt,
/* if not given by argument (overide) use default link
and !Node has a config sub-statement and it is false */
if ((yt = xml_spec(xt)) != NULL &&
- yang_config(yt) != 0 &&
- yang_keyword_get(yt) == Y_LIST){
- if ((ret = check_list_key(xt, yt, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ yang_config(yt) != 0 &&
+ yang_keyword_get(yt) == Y_LIST){
+ if ((ret = check_list_key(xt, yt, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- if ((ret = xml_yang_validate_list_key_only(x, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = xml_yang_validate_list_key_only(x, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
retval = 1;
done:
@@ -1016,10 +1026,10 @@ xml_yang_validate_list_key_only(cxobj *xt,
static int
xml_yang_validate_leaf_union(clicon_handle h,
- cxobj *xt,
- yang_stmt *yt,
- yang_stmt *yrestype,
- cxobj **xret)
+ cxobj *xt,
+ yang_stmt *yt,
+ yang_stmt *yrestype,
+ cxobj **xret)
{
int retval = -1;
int ret;
@@ -1028,39 +1038,39 @@ xml_yang_validate_leaf_union(clicon_handle h,
/* Enough that one is valid, eg returns 1,otherwise fail */
while ((yc = yn_each(yrestype, yc)) != NULL){
- if (yang_keyword_get(yc) != Y_TYPE)
- continue;
- ret = 1; /* If not leafref/identityref it is valid on this level */
- if (strcmp(yang_argument_get(yc), "leafref") == 0){
- if ((ret = validate_leafref(xt, yt, yc, &xret1)) < 0)
- goto done;
- }
- else if (strcmp(yang_argument_get(yc), "identityref") == 0){
- if ((ret = validate_identityref(xt, yt, yc, &xret1)) < 0)
- goto done;
- }
- else if (strcmp("union", yang_argument_get(yc)) == 0){
- if ((ret = xml_yang_validate_leaf_union(h, xt, yt, yc, &xret1)) < 0)
- goto done;
- }
- if (ret == 1)
- break;
- if (ret == 0 && xret1 != NULL) {
- /* If validation failed, save reason, reset error and continue,
- * save latest reason if nothing validates.
- */
- if (*xret)
- xml_free(*xret);
- *xret = xret1;
- xret1 = NULL;
- }
+ if (yang_keyword_get(yc) != Y_TYPE)
+ continue;
+ ret = 1; /* If not leafref/identityref it is valid on this level */
+ if (strcmp(yang_argument_get(yc), "leafref") == 0){
+ if ((ret = validate_leafref(xt, yt, yc, &xret1)) < 0)
+ goto done;
+ }
+ else if (strcmp(yang_argument_get(yc), "identityref") == 0){
+ if ((ret = validate_identityref(xt, yt, yc, &xret1)) < 0)
+ goto done;
+ }
+ else if (strcmp("union", yang_argument_get(yc)) == 0){
+ if ((ret = xml_yang_validate_leaf_union(h, xt, yt, yc, &xret1)) < 0)
+ goto done;
+ }
+ if (ret == 1)
+ break;
+ if (ret == 0 && xret1 != NULL) {
+ /* If validation failed, save reason, reset error and continue,
+ * save latest reason if nothing validates.
+ */
+ if (*xret)
+ xml_free(*xret);
+ *xret = xret1;
+ xret1 = NULL;
+ }
}
if (yc == NULL)
- goto fail;
+ goto fail;
retval = 1;
done:
if (xret1)
- xml_free(xret1);
+ xml_free(xret1);
return retval;
fail:
retval = 0;
@@ -1088,8 +1098,8 @@ xml_yang_validate_leaf_union(clicon_handle h,
*/
int
xml_yang_validate_all(clicon_handle h,
- cxobj *xt,
- cxobj **xret)
+ cxobj *xt,
+ cxobj **xret)
{
int retval = -1;
yang_stmt *yt; /* yang node associated with xt */
@@ -1108,141 +1118,141 @@ xml_yang_validate_all(clicon_handle h,
/* if not given by argument (overide) use default link
and !Node has a config sub-statement and it is false */
if ((yt = xml_spec(xt)) == NULL){
- if (clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1) {
- clicon_log(LOG_WARNING,
- "%s: %d: No YANG spec for %s, validation skipped",
- __FUNCTION__, __LINE__, xml_name(xt));
- goto ok;
- }
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Failed to find YANG spec of XML node: %s", xml_name(xt));
- if ((xp = xml_parent(xt)) != NULL)
- cprintf(cb, " with parent: %s", xml_name(xp));
- if (xml2ns(xt, xml_prefix(xt), &ns) < 0)
- goto done;
- if (ns)
- cprintf(cb, " in namespace: %s", ns);
- if (xret && netconf_unknown_element_xml(xret, "application", xml_name(xt), cbuf_get(cb)) < 0)
- goto done;
- goto fail;
+ if (clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1) {
+ clicon_log(LOG_WARNING,
+ "%s: %d: No YANG spec for %s, validation skipped",
+ __FUNCTION__, __LINE__, xml_name(xt));
+ goto ok;
+ }
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Failed to find YANG spec of XML node: %s", xml_name(xt));
+ if ((xp = xml_parent(xt)) != NULL)
+ cprintf(cb, " with parent: %s", xml_name(xp));
+ if (xml2ns(xt, xml_prefix(xt), &ns) < 0)
+ goto done;
+ if (ns)
+ cprintf(cb, " in namespace: %s", ns);
+ if (xret && netconf_unknown_element_xml(xret, "application", xml_name(xt), cbuf_get(cb)) < 0)
+ goto done;
+ goto fail;
}
if (yang_config(yt) != 0){
- if ((ret = check_mandatory(xt, yt, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- /* Node-specific validation */
- switch (yang_keyword_get(yt)){
- case Y_ANYXML:
- case Y_ANYDATA:
- goto ok;
- break;
- case Y_LEAF:
- /* fall thru */
- case Y_LEAF_LIST:
- /* Special case if leaf is leafref, then first check against
- current xml tree
- */
- /* Get base type yc */
- if (yang_type_get(yt, NULL, &yc, NULL, NULL, NULL, NULL, NULL) < 0)
- goto done;
- if (strcmp(yang_argument_get(yc), "leafref") == 0){
- if ((ret = validate_leafref(xt, yt, yc, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- else if (strcmp(yang_argument_get(yc), "identityref") == 0){
- if ((ret = validate_identityref(xt, yt, yc, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- else if (strcmp("union", yang_argument_get(yc)) == 0){
- if ((ret = xml_yang_validate_leaf_union(h, xt, yt, yc, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- break;
- default:
- break;
- }
- /* must sub-node RFC 7950 Sec 7.5.3. Can be several.
- * XXX. use yang path instead? */
- yc = NULL;
- while ((yc = yn_each(yt, yc)) != NULL) {
- if (yang_keyword_get(yc) != Y_MUST)
- continue;
- xpath = yang_argument_get(yc); /* "must" has xpath argument */
- /* the context node is the node in the accessible tree for
- * which the "must" statement is defined.
- * The set of namespace declarations is the set of all "import" statements'
- */
+ if (yang_check_when_xpath(xt, xml_parent(xt), yt, &hit, &nr, &xpath) < 0)
+ goto done;
+ if (hit && nr == 0){
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Failed WHEN condition of %s in module %s (WHEN xpath is %s)",
+ xml_name(xt),
+ yang_argument_get(ys_module(yt)),
+ xpath);
+ if (xret && netconf_operation_failed_xml(xret, "application",
+ cbuf_get(cb)) < 0)
+ goto done;
+ goto fail;
+ }
+ if ((ret = check_mandatory(xt, yt, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ /* Node-specific validation */
+ switch (yang_keyword_get(yt)){
+ case Y_ANYXML:
+ case Y_ANYDATA:
+ goto ok;
+ break;
+ case Y_LEAF:
+ /* fall thru */
+ case Y_LEAF_LIST:
+ /* Special case if leaf is leafref, then first check against
+ current xml tree
+ */
+ /* Get base type yc */
+ if (yang_type_get(yt, NULL, &yc, NULL, NULL, NULL, NULL, NULL) < 0)
+ goto done;
+ if (strcmp(yang_argument_get(yc), "leafref") == 0){
+ if ((ret = validate_leafref(xt, yt, yc, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ else if (strcmp(yang_argument_get(yc), "identityref") == 0){
+ if ((ret = validate_identityref(xt, yt, yc, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ else if (strcmp("union", yang_argument_get(yc)) == 0){
+ if ((ret = xml_yang_validate_leaf_union(h, xt, yt, yc, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ break;
+ default:
+ break;
+ }
+ /* must sub-node RFC 7950 Sec 7.5.3. Can be several.
+ * XXX. use yang path instead? */
+ yc = NULL;
+ while ((yc = yn_each(yt, yc)) != NULL) {
+ if (yang_keyword_get(yc) != Y_MUST)
+ continue;
+ xpath = yang_argument_get(yc); /* "must" has xpath argument */
+ /* the context node is the node in the accessible tree for
+ * which the "must" statement is defined.
+ * The set of namespace declarations is the set of all "import" statements'
+ */
if (xml_nsctx_yang(yc, &nsc) < 0)
goto done;
- if ((nr = xpath_vec_bool(xt, nsc, "%s", xpath)) < 0)
- goto done;
- if (!nr){
- ye = yang_find(yc, Y_ERROR_MESSAGE, NULL);
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Failed MUST xpath '%s' of '%s' in module %s",
- xpath, xml_name(xt), yang_argument_get(ys_module(yt)));
- if (xret && netconf_operation_failed_xml(xret, "application",
- ye?yang_argument_get(ye):cbuf_get(cb)) < 0)
- goto done;
- goto fail;
- }
- if (nsc){
- xml_nsctx_free(nsc);
- nsc = NULL;
- }
- }
- if (yang_check_when_xpath(xt, xml_parent(xt), yt, &hit, &nr, &xpath) < 0)
- goto done;
- if (hit && nr == 0){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Failed WHEN condition of %s in module %s (WHEN xpath is %s)",
- xml_name(xt),
- yang_argument_get(ys_module(yt)),
- xpath);
- if (xret && netconf_operation_failed_xml(xret, "application",
- cbuf_get(cb)) < 0)
- goto done;
- goto fail;
- }
+ if ((nr = xpath_vec_bool(xt, nsc, "%s", xpath)) < 0)
+ goto done;
+ if (!nr){
+ ye = yang_find(yc, Y_ERROR_MESSAGE, NULL);
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Failed MUST xpath '%s' of '%s' in module %s",
+ xpath, xml_name(xt), yang_argument_get(ys_module(yt)));
+ if (xret && netconf_operation_failed_xml(xret, "application",
+ ye?yang_argument_get(ye):cbuf_get(cb)) < 0)
+ goto done;
+ goto fail;
+ }
+ if (nsc){
+ xml_nsctx_free(nsc);
+ nsc = NULL;
+ }
+ }
}
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- if ((ret = xml_yang_validate_all(h, x, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = xml_yang_validate_all(h, x, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
/* Check unique and min-max after choice test for example*/
if (yang_config(yt) != 0){
- /* Checks if next level contains any unique list constraints */
- if ((ret = xml_yang_minmax_recurse(xt, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ /* Checks if next level contains any unique list constraints */
+ if ((ret = xml_yang_minmax_recurse(xt, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
ok:
retval = 1;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
return retval;
fail:
retval = 0;
@@ -1257,19 +1267,19 @@ xml_yang_validate_all(clicon_handle h,
*/
int
xml_yang_validate_all_top(clicon_handle h,
- cxobj *xt,
- cxobj **xret)
+ cxobj *xt,
+ cxobj **xret)
{
int ret;
cxobj *x;
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- if ((ret = xml_yang_validate_all(h, x, xret)) < 1)
- return ret;
+ if ((ret = xml_yang_validate_all(h, x, xret)) < 1)
+ return ret;
}
if ((ret = xml_yang_minmax_recurse(xt, xret)) < 1)
- return ret;
+ return ret;
return 1;
}
@@ -1281,8 +1291,8 @@ xml_yang_validate_all_top(clicon_handle h,
*/
int
rpc_reply_check(clicon_handle h,
- char *rpcname,
- cbuf *cbret)
+ char *rpcname,
+ cbuf *cbret)
{
int retval = -1;
cxobj *x = NULL;
@@ -1291,45 +1301,45 @@ rpc_reply_check(clicon_handle h,
yang_stmt *yspec;
if ((yspec = clicon_dbspec_yang(h)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No yang spec9");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "No yang spec9");
+ goto done;
}
/* Validate outgoing RPC */
if ((ret = clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, &x, NULL)) < 0)
- goto done;
+ goto done;
if (xml_child_nr(x) == 0){
- cbuf_reset(cbret);
- if (netconf_operation_failed(cbret, "application",
- "Internal error: Outgoing reply is empty")< 0)
- goto done;
- goto fail;
+ cbuf_reset(cbret);
+ if (netconf_operation_failed(cbret, "application",
+ "Internal error: Outgoing reply is empty")< 0)
+ goto done;
+ goto fail;
}
if (xml_rootchild(x, 0, &x) < 0)
- goto done;
+ goto done;
if ((ret = xml_bind_yang_rpc_reply(x, rpcname, yspec, &xret)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- clicon_debug(1, "%s failure when validating:%s", __FUNCTION__, cbuf_get(cbret));
- cbuf_reset(cbret);
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- goto fail;
+ clicon_debug(1, "%s failure when validating:%s", __FUNCTION__, cbuf_get(cbret));
+ cbuf_reset(cbret);
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ goto fail;
}
if ((ret = xml_yang_validate_rpc_reply(h, x, &xret)) < 0)
- goto done;
+ goto done;
if (ret == 0){
- clicon_debug(1, "%s failure when validating:%s", __FUNCTION__, cbuf_get(cbret));
- cbuf_reset(cbret);
- if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
- goto done;
- goto fail;
+ clicon_debug(1, "%s failure when validating:%s", __FUNCTION__, cbuf_get(cbret));
+ cbuf_reset(cbret);
+ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
+ goto done;
+ goto fail;
}
retval = 1;
done:
if (x)
- xml_free(x);
+ xml_free(x);
if (xret)
- xml_free(xret);
+ xml_free(xret);
return retval;
fail:
retval = 0;
diff --git a/lib/src/clixon_validate_minmax.c b/lib/src/clixon_validate_minmax.c
index 47c9a4f9..80976701 100644
--- a/lib/src/clixon_validate_minmax.c
+++ b/lib/src/clixon_validate_minmax.c
@@ -93,10 +93,10 @@
*/
static int
unique_search_xpath(cxobj *x,
- char *xpath,
- cvec *nsc,
- char ***svec,
- size_t *slen)
+ char *xpath,
+ cvec *nsc,
+ char ***svec,
+ size_t *slen)
{
int retval = -1;
cxobj **xvec = NULL;
@@ -108,30 +108,30 @@ unique_search_xpath(cxobj *x,
/* Collect tuples */
if (xpath_vec(x, nsc, "%s", &xvec, &xveclen, xpath) < 0)
- goto done;
+ goto done;
for (i=0; i 1 */
- while ((cvi = cvec_each(cvk, cvi)) != NULL){
- /* RFC7950: Sec 7.8.3.1: entries that do not have value for all
- * referenced leafs are not taken into account */
- str = cv_string_get(cvi);
- if (index(str, '/') != NULL){
- clicon_err(OE_YANG, 0, "Multiple descendant nodes not allowed (w /)");
- goto done;
- }
- if ((xi = xml_find(x, str)) == NULL)
- break;
- if ((bi = xml_body(xi)) == NULL)
- break;
- vec[i*clen + v++] = bi;
- }
- if (cvi==NULL){
- /* Last element (i) is newly inserted, see if it is already there */
- if (check_insert_duplicate(vec, i, clen, sorted) < 0){
- if (xret && netconf_data_not_unique_xml(xret, x, cvk) < 0)
- goto done;
- goto fail;
- }
- }
- x = xml_child_each(xt, x, CX_ELMNT);
- i++;
+ cvi = NULL;
+ v = 0; /* index in each tuple */
+ /* XXX Quadratic if clen > 1 */
+ while ((cvi = cvec_each(cvk, cvi)) != NULL){
+ /* RFC7950: Sec 7.8.3.1: entries that do not have value for all
+ * referenced leafs are not taken into account */
+ str = cv_string_get(cvi);
+ if (index(str, '/') != NULL){
+ clicon_err(OE_YANG, 0, "Multiple descendant nodes not allowed (w /)");
+ goto done;
+ }
+ if ((xi = xml_find(x, str)) == NULL)
+ break;
+ if ((bi = xml_body(xi)) == NULL)
+ break;
+ vec[i*clen + v++] = bi;
+ }
+ if (cvi==NULL){
+ /* Last element (i) is newly inserted, see if it is already there */
+ if (check_insert_duplicate(vec, i, clen, sorted) < 0){
+ if (xret && netconf_data_not_unique_xml(xret, x, cvk) < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ x = xml_child_each(xt, x, CX_ELMNT);
+ i++;
} while (x && y == xml_spec(x)); /* stop if list ends, others may follow */
ok:
/* It would be possible to cache vec here as an optimization */
retval = 1;
done:
if (vec)
- free(vec);
+ free(vec);
return retval;
fail:
retval = 0;
@@ -314,10 +314,10 @@ check_unique_list_direct(cxobj *x,
*/
static int
check_unique_list(cxobj *x,
- cxobj *xt,
- yang_stmt *y,
- yang_stmt *yu,
- cxobj **xret)
+ cxobj *xt,
+ yang_stmt *y,
+ yang_stmt *yu,
+ cxobj **xret)
{
int retval = -1;
cg_var *cvi; /* unique node name */
@@ -333,50 +333,50 @@ check_unique_list(cxobj *x,
/* Check if multiple direct children */
cvk = yang_cvec_get(yu);
if (cvec_len(cvk) > 1){
- retval = check_unique_list_direct(x, xt, y, yu, xret);
- goto done;
+ retval = check_unique_list_direct(x, xt, y, yu, xret);
+ goto done;
}
cvi = cvec_i(cvk, 0);
if (cvi == NULL || (xpath0 = cv_string_get(cvi)) == NULL){
- clicon_err(OE_YANG, 0, "No descendant schemanode");
- goto done;
+ clicon_err(OE_YANG, 0, "No descendant schemanode");
+ goto done;
}
/* Check if direct schmeanode-id , ie not xpath */
if (index(xpath0, '/') == NULL){
- retval = check_unique_list_direct(x, xt, y, yu, xret);
- goto done;
+ retval = check_unique_list_direct(x, xt, y, yu, xret);
+ goto done;
}
/* Here proper xpath with at least one slash (can there be a descendant schemanodeid w/o slash?) */
if (xml_nsctx_yang(yu, &nsc0) < 0)
- goto done;
+ goto done;
if ((ret = xpath2canonical(xpath0, nsc0, ys_spec(y),
- &xpath1, &nsc1, NULL)) < 0)
- goto done;
+ &xpath1, &nsc1, NULL)) < 0)
+ goto done;
if (ret == 0)
- goto fail; // XXX set xret
+ goto fail; // XXX set xret
do {
- /* Collect search results from one */
- if ((ret = unique_search_xpath(x, xpath1, nsc1, &svec, &slen)) < 0)
- goto done;
- if (ret == 0){
- if (xret && netconf_data_not_unique_xml(xret, x, cvk) < 0)
- goto done;
- goto fail;
- }
- x = xml_child_each(xt, x, CX_ELMNT);
+ /* Collect search results from one */
+ if ((ret = unique_search_xpath(x, xpath1, nsc1, &svec, &slen)) < 0)
+ goto done;
+ if (ret == 0){
+ if (xret && netconf_data_not_unique_xml(xret, x, cvk) < 0)
+ goto done;
+ goto fail;
+ }
+ x = xml_child_each(xt, x, CX_ELMNT);
} while (x && y == xml_spec(x)); /* stop if list ends, others may follow */
// ok:
/* It would be possible to cache vec here as an optimization */
retval = 1;
done:
if (nsc0)
- cvec_free(nsc0);
+ cvec_free(nsc0);
if (nsc1)
- cvec_free(nsc1);
+ cvec_free(nsc1);
if (xpath1)
- free(xpath1);
+ free(xpath1);
if (svec)
- free(svec);
+ free(svec);
return retval;
fail:
retval = 0;
@@ -397,9 +397,9 @@ check_unique_list(cxobj *x,
*/
static int
check_minmax(cxobj *xp,
- yang_stmt *y,
- int nr,
- cxobj **xret)
+ yang_stmt *y,
+ int nr,
+ cxobj **xret)
{
int retval = -1;
yang_stmt *ymin; /* yang min */
@@ -407,21 +407,21 @@ check_minmax(cxobj *xp,
cg_var *cv;
if ((ymin = yang_find(y, Y_MIN_ELEMENTS, NULL)) != NULL){
- cv = yang_cv_get(ymin);
- if (nr < cv_uint32_get(cv)){
- if (xret && netconf_minmax_elements_xml(xret, xp, yang_argument_get(y), 0) < 0)
- goto done;
- goto fail;
- }
+ cv = yang_cv_get(ymin);
+ if (nr < cv_uint32_get(cv)){
+ if (xret && netconf_minmax_elements_xml(xret, xp, yang_argument_get(y), 0) < 0)
+ goto done;
+ goto fail;
+ }
}
if ((ymax = yang_find(y, Y_MAX_ELEMENTS, NULL)) != NULL){
- cv = yang_cv_get(ymax);
- if (cv_uint32_get(cv) > 0 && /* 0 means unbounded */
- nr > cv_uint32_get(cv)){
- if (xret && netconf_minmax_elements_xml(xret, xp, yang_argument_get(y), 1) < 0)
- goto done;
- goto fail;
- }
+ cv = yang_cv_get(ymax);
+ if (cv_uint32_get(cv) > 0 && /* 0 means unbounded */
+ nr > cv_uint32_get(cv)){
+ if (xret && netconf_minmax_elements_xml(xret, xp, yang_argument_get(y), 1) < 0)
+ goto done;
+ goto fail;
+ }
}
retval = 1;
done:
@@ -442,32 +442,32 @@ check_minmax(cxobj *xp,
*/
static int
check_empty_list_minmax(cxobj *xt,
- yang_stmt *ye,
- cxobj **xret)
+ yang_stmt *ye,
+ cxobj **xret)
{
int retval = -1;
int ret;
yang_stmt *yprev = NULL;
if (yang_config(ye) == 1){
- if(yang_keyword_get(ye) == Y_CONTAINER &&
- yang_find(ye, Y_PRESENCE, NULL) == NULL){
- yprev = NULL;
- while ((yprev = yn_each(ye, yprev)) != NULL) {
- if ((ret = check_empty_list_minmax(xt, yprev, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- }
- else if (yang_keyword_get(ye) == Y_LIST ||
- yang_keyword_get(ye) == Y_LEAF_LIST){
- /* Check if the list length violates min/max */
- if ((ret = check_minmax(xt, ye, 0, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
+ if(yang_keyword_get(ye) == Y_CONTAINER &&
+ yang_find(ye, Y_PRESENCE, NULL) == NULL){
+ yprev = NULL;
+ while ((yprev = yn_each(ye, yprev)) != NULL) {
+ if ((ret = check_empty_list_minmax(xt, yprev, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ }
+ else if (yang_keyword_get(ye) == Y_LIST ||
+ yang_keyword_get(ye) == Y_LEAF_LIST){
+ /* Check if the list length violates min/max */
+ if ((ret = check_minmax(xt, ye, 0, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
}
retval = 1;
done:
@@ -479,9 +479,9 @@ check_empty_list_minmax(cxobj *xt,
static int
xml_yang_minmax_newlist(cxobj *x,
- cxobj *xt,
- yang_stmt *y,
- cxobj **xret)
+ cxobj *xt,
+ yang_stmt *y,
+ cxobj **xret)
{
int retval = -1;
yang_stmt *yu;
@@ -491,26 +491,26 @@ xml_yang_minmax_newlist(cxobj *x,
* First check unique keys direct children
*/
if ((ret = check_unique_list_direct(x, xt, y, y, xret)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* Check if there is a unique constraint on the list
*/
yu = NULL;
while ((yu = yn_each(y, yu)) != NULL) {
- if (yang_keyword_get(yu) != Y_UNIQUE)
- continue;
- /* Here is a list w unique constraints identified by:
- * its first element x, its yang spec y, its parent xt, and
- * a unique yang spec yu,
- * Two cases:
- * 1) multiple direct children (no prefixes), eg "a b"
- * 2) single xpath with canonical prefixes, eg "/ex:a/ex:b"
- */
- if ((ret = check_unique_list(x, xt, y, yu, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if (yang_keyword_get(yu) != Y_UNIQUE)
+ continue;
+ /* Here is a list w unique constraints identified by:
+ * its first element x, its yang spec y, its parent xt, and
+ * a unique yang spec yu,
+ * Two cases:
+ * 1) multiple direct children (no prefixes), eg "a b"
+ * 2) single xpath with canonical prefixes, eg "/ex:a/ex:b"
+ */
+ if ((ret = check_unique_list(x, xt, y, yu, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
retval = 1;
done:
@@ -538,10 +538,10 @@ xml_yang_minmax_newlist(cxobj *x,
*/
static int
xml_yang_minmax_gap_analysis(cxobj *xt,
- yang_stmt *y,
- yang_stmt *yt,
- yang_stmt **yep,
- cxobj **xret)
+ yang_stmt *y,
+ yang_stmt *yt,
+ yang_stmt **yep,
+ cxobj **xret)
{
int retval = -1;
yang_stmt *ye;
@@ -550,24 +550,24 @@ xml_yang_minmax_gap_analysis(cxobj *xt,
ye = *yep;
if (y && (ych = yang_choice(y)) == NULL)
- ych = y;
+ ych = y;
/* Gap analysis: Check if there is any empty list between y and yprevlist
* Note, does not detect empty choice list (too complicated)
*/
if (yt != NULL && ych != ye){
- /* Skip analysis if Yang spec is unknown OR
- * if we are still iterating the same Y_CASE w multiple lists
- */
- ye = yn_each(yt, ye);
- if (ye && ych != ye)
- do {
- if ((ret = check_empty_list_minmax(xt, ye, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- ye = yn_each(yt, ye);
- } while(ye != NULL && /* to avoid livelock (shouldnt happen) */
- ye != ych);
+ /* Skip analysis if Yang spec is unknown OR
+ * if we are still iterating the same Y_CASE w multiple lists
+ */
+ ye = yn_each(yt, ye);
+ if (ye && ych != ye)
+ do {
+ if ((ret = check_empty_list_minmax(xt, ye, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ ye = yn_each(yt, ye);
+ } while(ye != NULL && /* to avoid livelock (shouldnt happen) */
+ ye != ych);
}
*yep = ye;
retval = 1;
@@ -644,7 +644,7 @@ xml_yang_minmax_gap_analysis(cxobj *xt,
*/
int
xml_yang_minmax_recurse(cxobj *xt,
- cxobj **xret)
+ cxobj **xret)
{
int retval = -1;
cxobj *x = NULL;
@@ -658,71 +658,70 @@ xml_yang_minmax_recurse(cxobj *xt,
yt = xml_spec(xt); /* If yt == NULL, then no gap-analysis is done */
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL){
- clicon_debug(1, "%s x:%s", __FUNCTION__, xml_name(x));
- if ((y = xml_spec(x)) == NULL)
- continue;
- keyw = yang_keyword_get(y);
- if (keyw == Y_LIST || keyw == Y_LEAF_LIST){
- /* equal: just continue*/
- if (y == yprev){
- nr++;
- continue;
- }
- /* gap analysis */
- if ((ret = xml_yang_minmax_gap_analysis(xt, y, yt, &ye, xret)) < 0)
- goto done;
- /* check-minmax of previous list */
- if (ret &&
- yprev &&
- (yang_keyword_get(yprev) == Y_LIST || yang_keyword_get(yprev) == Y_LEAF_LIST)){
- /* Check if the list length violates min/max */
- if ((ret = check_minmax(xt, yprev, nr, xret)) < 0)
- goto done;
- }
- nr=1;
- /* new list check */
- if (ret &&
- keyw == Y_LIST)
- if ((ret = xml_yang_minmax_newlist(x, xt, y, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- yprev = y;
- }
- else{
- /* equal: error */
- if (y == yprev){
- /* Only lists and leaf-lists are allowed to be more than one */
- if (xret && netconf_minmax_elements_xml(xret, xml_parent(x), xml_name(x), 1) < 0)
- goto done;
- goto fail;
- }
- /* gap analysis */
- if ((ret = xml_yang_minmax_gap_analysis(xt, y, yt, &ye, xret)) < 0)
- goto done;
- /* check-minmax of previous list */
- if (ret &&
- yprev &&
- (yang_keyword_get(yprev) == Y_LIST || yang_keyword_get(yprev) == Y_LEAF_LIST)){
- /* Check if the list length violates min/max */
- if ((ret = check_minmax(xt, yprev, nr, xret)) < 0)
- goto done;
- nr = 0;
- }
- if (ret == 0)
- goto fail;
- if (keyw == Y_CONTAINER &&
- yang_find(y, Y_PRESENCE, NULL) == NULL){
- yang_stmt *yc = NULL;
- while ((yc = yn_each(y, yc)) != NULL) {
- if ((ret = xml_yang_minmax_recurse(x, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- }
- }
- yprev = y;
- }
+ if ((y = xml_spec(x)) == NULL)
+ continue;
+ keyw = yang_keyword_get(y);
+ if (keyw == Y_LIST || keyw == Y_LEAF_LIST){
+ /* equal: just continue*/
+ if (y == yprev){
+ nr++;
+ continue;
+ }
+ /* gap analysis */
+ if ((ret = xml_yang_minmax_gap_analysis(xt, y, yt, &ye, xret)) < 0)
+ goto done;
+ /* check-minmax of previous list */
+ if (ret &&
+ yprev &&
+ (yang_keyword_get(yprev) == Y_LIST || yang_keyword_get(yprev) == Y_LEAF_LIST)){
+ /* Check if the list length violates min/max */
+ if ((ret = check_minmax(xt, yprev, nr, xret)) < 0)
+ goto done;
+ }
+ nr=1;
+ /* new list check */
+ if (ret &&
+ keyw == Y_LIST)
+ if ((ret = xml_yang_minmax_newlist(x, xt, y, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ yprev = y;
+ }
+ else{
+ /* equal: error */
+ if (y == yprev){
+ /* Only lists and leaf-lists are allowed to be more than one */
+ if (xret && netconf_minmax_elements_xml(xret, xml_parent(x), xml_name(x), 1) < 0)
+ goto done;
+ goto fail;
+ }
+ /* gap analysis */
+ if ((ret = xml_yang_minmax_gap_analysis(xt, y, yt, &ye, xret)) < 0)
+ goto done;
+ /* check-minmax of previous list */
+ if (ret &&
+ yprev &&
+ (yang_keyword_get(yprev) == Y_LIST || yang_keyword_get(yprev) == Y_LEAF_LIST)){
+ /* Check if the list length violates min/max */
+ if ((ret = check_minmax(xt, yprev, nr, xret)) < 0)
+ goto done;
+ nr = 0;
+ }
+ if (ret == 0)
+ goto fail;
+ if (keyw == Y_CONTAINER &&
+ yang_find(y, Y_PRESENCE, NULL) == NULL){
+ yang_stmt *yc = NULL;
+ while ((yc = yn_each(y, yc)) != NULL) {
+ if ((ret = xml_yang_minmax_recurse(x, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ }
+ }
+ yprev = y;
+ }
}
/* After traversal checks;
gap analysis */
@@ -731,28 +730,28 @@ xml_yang_minmax_recurse(cxobj *xt,
* XXX: try to unify with xml_yang_minmax_gap_analysis()
*/
if ((ye = yn_each(yt, ye)) != NULL){
- do {
- if ((ret = check_empty_list_minmax(xt, ye, xret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- } while((ye = yn_each(yt, ye)) != NULL);
+ do {
+ if ((ret = check_empty_list_minmax(xt, ye, xret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ } while((ye = yn_each(yt, ye)) != NULL);
}
ret = 1;
#else
if ((ret = xml_yang_minmax_gap_analysis(xt, NULL, yt, &ye, xret)) < 0)
- goto done;
+ goto done;
#endif
/* check-minmax of previous list */
if (ret &&
- yprev &&
- (yang_keyword_get(yprev) == Y_LEAF || yang_keyword_get(yprev) == Y_LEAF_LIST)){
- /* Check if the list length violates min/max */
- if ((ret = check_minmax(xt, yprev, nr, xret)) < 0)
- goto done;
+ yprev &&
+ (yang_keyword_get(yprev) == Y_LEAF || yang_keyword_get(yprev) == Y_LEAF_LIST)){
+ /* Check if the list length violates min/max */
+ if ((ret = check_minmax(xt, yprev, nr, xret)) < 0)
+ goto done;
}
if (ret == 0)
- goto fail;
+ goto fail;
retval = 1;
done:
return retval;
diff --git a/lib/src/clixon_xml.c b/lib/src/clixon_xml.c
index e8dd1035..4bc37ea2 100644
--- a/lib/src/clixon_xml.c
+++ b/lib/src/clixon_xml.c
@@ -171,10 +171,10 @@ struct xml{
#endif
int _x_vector_i; /* internal use: xml_child_each */
int _x_i; /* internal use for stable sorting:
- see xml_enumerate and xml_cmp */
+ see xml_enumerate and xml_cmp */
/*----- next is body/attribute only */
cbuf *x_value_cb; /* attribute and body nodes have values (XXX: this consumes
- memory) cv? */
+ memory) cv? */
/*----- up to here is common to all next is element only */
struct xml **x_childvec; /* vector of children nodes (XXX: use clixon_vec ) */
int x_childvec_len;/* Number of children */
@@ -183,7 +183,7 @@ struct xml{
cvec *x_ns_cache; /* Cached vector of namespaces (set by bind-yang) */
yang_stmt *x_spec; /* Pointer to specification, eg yang,
- by reference, dont free */
+ by reference, dont free */
cg_var *x_cv; /* Cached value as cligen variable (set by xml_cmp) */
#ifdef XML_EXPLICIT_INDEX
struct search_index *x_search_index; /* explicit search index vectors */
@@ -204,7 +204,7 @@ struct xmlbody{
#endif
int _xb_vector_i; /* internal use: xml_child_each */
int _xb_i; /* internal use for sorting:
- see xml_enumerate and xml_cmp */
+ see xml_enumerate and xml_cmp */
cbuf *xb_value_cb; /* attribute and body nodes have values */
};
@@ -242,7 +242,7 @@ int
xml_stats_global(uint64_t *nr)
{
if (nr)
- *nr = _stats_xml_nr;
+ *nr = _stats_xml_nr;
return 0;
}
@@ -254,44 +254,44 @@ xml_stats_global(uint64_t *nr)
*/
static int
xml_stats_one(cxobj *x,
- size_t *szp)
+ size_t *szp)
{
size_t sz = 0;
if (x->x_name)
- sz += strlen(x->x_name) + 1;
+ sz += strlen(x->x_name) + 1;
if (x->x_prefix)
- sz += strlen(x->x_prefix) + 1;
+ sz += strlen(x->x_prefix) + 1;
switch (xml_type(x)){
case CX_ELMNT:
- sz += sizeof(struct xml);
- sz += x->x_childvec_max*sizeof(struct xml*);
- if (x->x_ns_cache)
- sz += cvec_size(x->x_ns_cache);
- if (x->x_cv)
- sz += cv_size(x->x_cv);
+ sz += sizeof(struct xml);
+ sz += x->x_childvec_max*sizeof(struct xml*);
+ if (x->x_ns_cache)
+ sz += cvec_size(x->x_ns_cache);
+ if (x->x_cv)
+ sz += cv_size(x->x_cv);
#ifdef XML_EXPLICIT_INDEX
- if (x->x_search_index){
- /* XXX: only one */
- sz += sizeof(struct search_index);
- if (x->x_search_index->si_name)
- sz += strlen(x->x_search_index->si_name)+1;
- if (x->x_search_index->si_xvec)
- sz += clixon_xvec_len(x->x_search_index->si_xvec)*sizeof(struct cxobj*);
- }
+ if (x->x_search_index){
+ /* XXX: only one */
+ sz += sizeof(struct search_index);
+ if (x->x_search_index->si_name)
+ sz += strlen(x->x_search_index->si_name)+1;
+ if (x->x_search_index->si_xvec)
+ sz += clixon_xvec_len(x->x_search_index->si_xvec)*sizeof(struct cxobj*);
+ }
#endif
- break;
+ break;
case CX_BODY:
case CX_ATTR:
- sz += sizeof(struct xmlbody);
- if (x->x_value_cb)
- sz += cbuf_buflen(x->x_value_cb);
- break;
+ sz += sizeof(struct xmlbody);
+ if (x->x_value_cb)
+ sz += cbuf_buflen(x->x_value_cb);
+ break;
default:
- break;
+ break;
}
if (szp)
- *szp = sz;
+ *szp = sz;
return 0;
}
@@ -304,27 +304,27 @@ xml_stats_one(cxobj *x,
*/
int
xml_stats(cxobj *xt,
- uint64_t *nrp,
- size_t *szp)
+ uint64_t *nrp,
+ size_t *szp)
{
int retval = -1;
size_t sz = 0;
cxobj *xc;
if (xt == NULL){
- clicon_err(OE_XML, EINVAL, "xml node is NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "xml node is NULL");
+ goto done;
}
*nrp += 1;
xml_stats_one(xt, &sz);
if (szp)
- *szp += sz;
+ *szp += sz;
xc = NULL;
while ((xc = xml_child_each(xt, xc, -1)) != NULL) {
- sz=0;
- xml_stats(xc, nrp, &sz);
- if (szp)
- *szp += sz;
+ sz=0;
+ xml_stats(xc, nrp, &sz);
+ if (szp)
+ *szp += sz;
}
retval = 0;
done:
@@ -342,7 +342,7 @@ char*
xml_name(cxobj *xn)
{
if (xn == NULL) {
- return NULL;
+ return NULL;
}
return xn->x_name;
}
@@ -355,17 +355,17 @@ xml_name(cxobj *xn)
*/
int
xml_name_set(cxobj *xn,
- char *name)
+ char *name)
{
if (xn->x_name){
- free(xn->x_name);
- xn->x_name = NULL;
+ free(xn->x_name);
+ xn->x_name = NULL;
}
if (name){
- if ((xn->x_name = strdup(name)) == NULL){
- clicon_err(OE_XML, errno, "strdup");
- return -1;
- }
+ if ((xn->x_name = strdup(name)) == NULL){
+ clicon_err(OE_XML, errno, "strdup");
+ return -1;
+ }
}
return 0;
}
@@ -388,17 +388,17 @@ xml_prefix(cxobj *xn)
*/
int
xml_prefix_set(cxobj *xn,
- char *prefix)
+ char *prefix)
{
if (xn->x_prefix){
- free(xn->x_prefix);
- xn->x_prefix = NULL;
+ free(xn->x_prefix);
+ xn->x_prefix = NULL;
}
if (prefix){
- if ((xn->x_prefix = strdup(prefix)) == NULL){
- clicon_err(OE_XML, errno, "strdup");
- return -1;
- }
+ if ((xn->x_prefix = strdup(prefix)) == NULL){
+ clicon_err(OE_XML, errno, "strdup");
+ return -1;
+ }
}
return 0;
}
@@ -412,12 +412,12 @@ xml_prefix_set(cxobj *xn,
*/
char*
nscache_get(cxobj *x,
- char *prefix)
+ char *prefix)
{
if (!is_element(x))
- return NULL;
+ return NULL;
if (x->x_ns_cache != NULL)
- return xml_nsctx_get(x->x_ns_cache, prefix);
+ return xml_nsctx_get(x->x_ns_cache, prefix);
return NULL;
}
@@ -430,13 +430,13 @@ nscache_get(cxobj *x,
*/
int
nscache_get_prefix(cxobj *x,
- char *namespace,
- char **prefix)
+ char *namespace,
+ char **prefix)
{
if (!is_element(x))
- return 0;
+ return 0;
if (x->x_ns_cache != NULL)
- return xml_nsctx_get_prefix(x->x_ns_cache, namespace, prefix);
+ return xml_nsctx_get_prefix(x->x_ns_cache, namespace, prefix);
return 0;
}
@@ -450,7 +450,7 @@ cvec *
nscache_get_all(cxobj *x)
{
if (!is_element(x))
- return NULL;
+ return NULL;
return x->x_ns_cache;
}
@@ -464,19 +464,19 @@ nscache_get_all(cxobj *x)
*/
int
nscache_set(cxobj *x,
- char *prefix,
- char *namespace)
+ char *prefix,
+ char *namespace)
{
int retval = -1;
if (!is_element(x))
- return 0;
+ return 0;
if (x->x_ns_cache == NULL){
- if ((x->x_ns_cache = xml_nsctx_init(prefix, namespace)) == NULL)
- goto done;
+ if ((x->x_ns_cache = xml_nsctx_init(prefix, namespace)) == NULL)
+ goto done;
}
else
- return xml_nsctx_add(x->x_ns_cache, prefix, namespace);
+ return xml_nsctx_add(x->x_ns_cache, prefix, namespace);
retval = 0;
done:
return retval;
@@ -491,15 +491,15 @@ nscache_set(cxobj *x,
*/
int
nscache_replace(cxobj *x,
- cvec *nsc)
+ cvec *nsc)
{
int retval = -1;
if (!is_element(x))
- return 0;
+ return 0;
if (x->x_ns_cache != NULL){
- xml_nsctx_free(x->x_ns_cache);
- x->x_ns_cache = NULL;
+ xml_nsctx_free(x->x_ns_cache);
+ x->x_ns_cache = NULL;
}
x->x_ns_cache = nsc;
retval = 0;
@@ -519,10 +519,10 @@ nscache_clear(cxobj *x)
{
if (!is_element(x))
- return 0;
+ return 0;
if (x->x_ns_cache != NULL){
- xml_nsctx_free(x->x_ns_cache);
- x->x_ns_cache = NULL;
+ xml_nsctx_free(x->x_ns_cache);
+ x->x_ns_cache = NULL;
}
return 0;
}
@@ -535,7 +535,7 @@ cxobj*
xml_parent(cxobj *xn)
{
if (xn == NULL) {
- return NULL;
+ return NULL;
}
return xn->x_up;
}
@@ -548,7 +548,7 @@ xml_parent(cxobj *xn)
*/
int
xml_parent_set(cxobj *xn,
- cxobj *parent)
+ cxobj *parent)
{
xn->x_up = parent;
return 0;
@@ -563,7 +563,7 @@ cxobj*
xml_parent_candidate(cxobj *xn)
{
if (xn == NULL) {
- return NULL;
+ return NULL;
}
return xn->x_up_candidate;
}
@@ -575,7 +575,7 @@ xml_parent_candidate(cxobj *xn)
*/
int
xml_parent_candidate_set(cxobj *xn,
- cxobj *parent)
+ cxobj *parent)
{
xn->x_up_candidate = parent;
return 0;
@@ -588,7 +588,7 @@ xml_parent_candidate_set(cxobj *xn,
*/
uint16_t
xml_flag(cxobj *xn,
- uint16_t flag)
+ uint16_t flag)
{
return xn->x_flags&flag;
}
@@ -599,7 +599,7 @@ xml_flag(cxobj *xn,
*/
int
xml_flag_set(cxobj *xn,
- uint16_t flag)
+ uint16_t flag)
{
xn->x_flags |= flag;
return 0;
@@ -611,7 +611,7 @@ xml_flag_set(cxobj *xn,
*/
int
xml_flag_reset(cxobj *xn,
- uint16_t flag)
+ uint16_t flag)
{
xn->x_flags &= ~flag;
return 0;
@@ -625,7 +625,7 @@ char*
xml_value(cxobj *xn)
{
if (!is_bodyattr(xn))
- return NULL;
+ return NULL;
return xn->x_value_cb?cbuf_get(xn->x_value_cb):NULL;
}
@@ -637,26 +637,26 @@ xml_value(cxobj *xn)
*/
int
xml_value_set(cxobj *xn,
- char *val)
+ char *val)
{
int retval = -1;
size_t sz;
if (!is_bodyattr(xn))
- return 0;
+ return 0;
if (val == NULL){
- clicon_err(OE_XML, EINVAL, "value is NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "value is NULL");
+ goto done;
}
sz = strlen(val)+1;
if (xn->x_value_cb == NULL){
- if ((xn->x_value_cb = cbuf_new_alloc(sz)) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
+ if ((xn->x_value_cb = cbuf_new_alloc(sz)) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
}
else
- cbuf_reset(xn->x_value_cb);
+ cbuf_reset(xn->x_value_cb);
cbuf_append_str(xn->x_value_cb, val);
retval = 0;
done:
@@ -671,27 +671,27 @@ xml_value_set(cxobj *xn,
*/
int
xml_value_append(cxobj *xn,
- char *val)
+ char *val)
{
int retval = -1;
size_t sz;
if (!is_bodyattr(xn))
- return 0;
+ return 0;
if (val == NULL){
- clicon_err(OE_XML, EINVAL, "value is NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "value is NULL");
+ goto done;
}
sz = strlen(val)+1;
if (xn->x_value_cb == NULL){
- if ((xn->x_value_cb = cbuf_new_alloc(sz)) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
+ if ((xn->x_value_cb = cbuf_new_alloc(sz)) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
}
if (cbuf_append_str(xn->x_value_cb, val) < 0){
- clicon_err(OE_XML, errno, "cprintf");
- goto done;
+ clicon_err(OE_XML, errno, "cprintf");
+ goto done;
}
retval = 0;
done:
@@ -706,7 +706,7 @@ enum cxobj_type
xml_type(cxobj *xn)
{
if (xn == NULL) {
- return CX_ERROR;
+ return CX_ERROR;
}
return xn->x_type;
}
@@ -718,7 +718,7 @@ xml_type(cxobj *xn)
*/
static enum cxobj_type
xml_type_set(cxobj *xn,
- enum cxobj_type type)
+ enum cxobj_type type)
{
enum cxobj_type old = xn->x_type;
@@ -736,10 +736,10 @@ int
xml_child_nr(cxobj *xn)
{
if (xn == NULL) {
- return 0;
+ return 0;
}
if (!is_element(xn))
- return 0;
+ return 0;
return xn->x_childvec_len;
}
@@ -752,16 +752,16 @@ xml_child_nr(cxobj *xn)
*/
int
xml_child_nr_notype(cxobj *xn,
- enum cxobj_type type)
+ enum cxobj_type type)
{
cxobj *x = NULL;
int nr = 0;
if (!is_element(xn))
- return 0;
+ return 0;
while ((x = xml_child_each(xn, x, -1)) != NULL) {
- if (xml_type(x) != type)
- nr++;
+ if (xml_type(x) != type)
+ nr++;
}
return nr;
}
@@ -775,15 +775,15 @@ xml_child_nr_notype(cxobj *xn,
*/
int
xml_child_nr_type(cxobj *xn,
- enum cxobj_type type)
+ enum cxobj_type type)
{
cxobj *x = NULL;
int len = 0;
if (!is_element(xn))
- return 0;
+ return 0;
while ((x = xml_child_each(xn, x, type)) != NULL)
- len++;
+ len++;
return len;
}
@@ -797,15 +797,15 @@ xml_child_nr_type(cxobj *xn,
*/
cxobj *
xml_child_i(cxobj *xn,
- int i)
+ int i)
{
if (xn == NULL || i < 0) {
- return NULL;
+ return NULL;
}
if (!is_element(xn))
- return NULL;
+ return NULL;
if (i < xn->x_childvec_len)
- return xn->x_childvec[i];
+ return xn->x_childvec[i];
return NULL;
}
@@ -818,17 +818,17 @@ xml_child_i(cxobj *xn,
*/
cxobj *
xml_child_i_type(cxobj *xn,
- int i,
- enum cxobj_type type)
+ int i,
+ enum cxobj_type type)
{
cxobj *x = NULL;
int it = 0;
if (!is_element(xn))
- return NULL;
+ return NULL;
while ((x = xml_child_each(xn, x, type)) != NULL) {
- if (x->x_type == type && (i == it++))
- return x;
+ if (x->x_type == type && (i == it++))
+ return x;
}
return NULL;
}
@@ -841,13 +841,13 @@ xml_child_i_type(cxobj *xn,
*/
cxobj *
xml_child_i_set(cxobj *xt,
- int i,
- cxobj *xc)
+ int i,
+ cxobj *xc)
{
if (!is_element(xt))
- return NULL;
+ return NULL;
if (i < xt->x_childvec_len)
- xt->x_childvec[i] = xc;
+ xt->x_childvec[i] = xc;
return 0;
}
@@ -861,17 +861,17 @@ xml_child_i_set(cxobj *xt,
*/
int
xml_child_order(cxobj *xp,
- cxobj *xc)
+ cxobj *xc)
{
cxobj *x = NULL;
int i = 0;
if (!is_element(xp))
- return -1;
+ return -1;
while ((x = xml_child_each(xp, x, -1)) != NULL) {
- if (x == xc)
- return i;
- i++;
+ if (x == xc)
+ return i;
+ i++;
}
return -1;
}
@@ -899,10 +899,10 @@ xml_child_order(cxobj *xp,
* cxobj *x = NULL;
* while ((x = xml_child_each(x_top, x, -1)) != NULL) {
* if (something){
- * if (xml_purge(x) < 0)
- * goto done;
- * x = xprev;
- * continue;
+ * if (xml_purge(x) < 0)
+ * goto done;
+ * x = xprev;
+ * continue;
* }
* xprev = x;
* }
@@ -911,28 +911,28 @@ xml_child_order(cxobj *xp,
*/
cxobj *
xml_child_each(cxobj *xparent,
- cxobj *xprev,
- enum cxobj_type type)
+ cxobj *xprev,
+ enum cxobj_type type)
{
int i;
cxobj *xn = NULL;
if (xparent == NULL)
- return NULL;
+ return NULL;
if (!is_element(xparent))
- return NULL;
+ return NULL;
for (i=xprev?xprev->_x_vector_i+1:0; ix_childvec_len; i++){
- xn = xparent->x_childvec[i];
- if (xn == NULL)
- continue;
- if (type != CX_ERROR && xml_type(xn) != type)
- continue;
- break; /* this is next object after previous */
+ xn = xparent->x_childvec[i];
+ if (xn == NULL)
+ continue;
+ if (type != CX_ERROR && xml_type(xn) != type)
+ continue;
+ break; /* this is next object after previous */
}
if (i < xparent->x_childvec_len) /* found */
- xn->_x_vector_i = i;
+ xn->_x_vector_i = i;
else
- xn = NULL;
+ xn = NULL;
return xn;
}
@@ -943,29 +943,29 @@ xml_child_each(cxobj *xparent,
*/
static int
xml_child_append(cxobj *xp,
- cxobj *xc)
+ cxobj *xc)
{
size_t start;
if (!is_element(xp))
- return 0;
+ return 0;
start = XML_CHILDVEC_SIZE_START;
/* Heurestics: if child is body only single child is expected, but element children may
* have siblings
*/
if (xml_type(xc) == CX_ELMNT)
- start = XML_CHILDVEC_SIZE_START_ELMNT;
+ start = XML_CHILDVEC_SIZE_START_ELMNT;
xp->x_childvec_len++;
if (xp->x_childvec_len > xp->x_childvec_max){
- if (xp->x_childvec_len < XML_CHILDVEC_SIZE_THRESHOLD)
- xp->x_childvec_max = xp->x_childvec_max?2*xp->x_childvec_max:start;
- else
- xp->x_childvec_max += XML_CHILDVEC_SIZE_THRESHOLD;
- xp->x_childvec = realloc(xp->x_childvec, xp->x_childvec_max*sizeof(cxobj*));
- if (xp->x_childvec == NULL){
- clicon_err(OE_XML, errno, "realloc");
- return -1;
- }
+ if (xp->x_childvec_len < XML_CHILDVEC_SIZE_THRESHOLD)
+ xp->x_childvec_max = xp->x_childvec_max?2*xp->x_childvec_max:start;
+ else
+ xp->x_childvec_max += XML_CHILDVEC_SIZE_THRESHOLD;
+ xp->x_childvec = realloc(xp->x_childvec, xp->x_childvec_max*sizeof(cxobj*));
+ if (xp->x_childvec == NULL){
+ clicon_err(OE_XML, errno, "realloc");
+ return -1;
+ }
}
xp->x_childvec[xp->x_childvec_len-1] = xc;
return 0;
@@ -978,24 +978,24 @@ xml_child_append(cxobj *xp,
*/
int
xml_child_insert_pos(cxobj *xp,
- cxobj *xc,
- int i)
+ cxobj *xc,
+ int i)
{
size_t size;
if (!is_element(xp))
- return 0;
+ return 0;
xp->x_childvec_len++;
if (xp->x_childvec_len > xp->x_childvec_max){
- if (xp->x_childvec_len < XML_CHILDVEC_SIZE_THRESHOLD)
- xp->x_childvec_max = xp->x_childvec_max?2*xp->x_childvec_max:XML_CHILDVEC_SIZE_START;
- else
- xp->x_childvec_max += XML_CHILDVEC_SIZE_THRESHOLD;
- xp->x_childvec = realloc(xp->x_childvec, xp->x_childvec_max*sizeof(cxobj*));
- if (xp->x_childvec == NULL){
- clicon_err(OE_XML, errno, "realloc");
- return -1;
- }
+ if (xp->x_childvec_len < XML_CHILDVEC_SIZE_THRESHOLD)
+ xp->x_childvec_max = xp->x_childvec_max?2*xp->x_childvec_max:XML_CHILDVEC_SIZE_START;
+ else
+ xp->x_childvec_max += XML_CHILDVEC_SIZE_THRESHOLD;
+ xp->x_childvec = realloc(xp->x_childvec, xp->x_childvec_max*sizeof(cxobj*));
+ if (xp->x_childvec == NULL){
+ clicon_err(OE_XML, errno, "realloc");
+ return -1;
+ }
}
size = (xml_child_nr(xp) - i - 1)*sizeof(cxobj *);
memmove(&xp->x_childvec[i+1], &xp->x_childvec[i], size);
@@ -1012,17 +1012,17 @@ xml_child_insert_pos(cxobj *xp,
*/
int
xml_childvec_set(cxobj *x,
- int len)
+ int len)
{
if (!is_element(x))
- return 0;
+ return 0;
x->x_childvec_len = len;
x->x_childvec_max = len;
if (x->x_childvec)
- free(x->x_childvec);
+ free(x->x_childvec);
if ((x->x_childvec = calloc(len, sizeof(cxobj*))) == NULL){
- clicon_err(OE_XML, errno, "calloc");
- return -1;
+ clicon_err(OE_XML, errno, "calloc");
+ return -1;
}
return 0;
}
@@ -1033,7 +1033,7 @@ cxobj **
xml_childvec_get(cxobj *x)
{
if (!is_element(x))
- return NULL;
+ return NULL;
return x->x_childvec;
}
@@ -1047,16 +1047,16 @@ xml_childvec_get(cxobj *x)
*/
int
clixon_child_xvec_append(cxobj *xn,
- clixon_xvec *xv)
+ clixon_xvec *xv)
{
int retval = -1;
cxobj *xc;
int i;
for (i=0; i_x_i = xml_child_nr(xp)-1;
+ xml_parent_set(x, xp);
+ if (xml_child_append(xp, x) < 0)
+ return NULL;
+ x->_x_i = xml_child_nr(xp)-1;
}
_stats_xml_nr++;
return x;
@@ -1132,25 +1132,25 @@ xml_new(char *name,
*/
cxobj *
xml_new_body(char *name,
- cxobj *parent,
- char *val)
+ cxobj *parent,
+ char *val)
{
cxobj *new_node = NULL;
cxobj *body_node;
if (!name || !parent || !val) {
- return NULL;
+ return NULL;
}
if ((new_node = xml_new(name, parent, CX_ELMNT)) == NULL) {
- return NULL;
+ return NULL;
}
if ((body_node = xml_new("body", new_node, CX_BODY)) == NULL ||
- xml_value_set(body_node, val) < 0) {
- xml_free(new_node);
- new_node = NULL;
- body_node = NULL;
+ xml_value_set(body_node, val) < 0) {
+ xml_free(new_node);
+ new_node = NULL;
+ body_node = NULL;
} else {
- xml_type_set(body_node, CX_BODY);
+ xml_type_set(body_node, CX_BODY);
}
return new_node;
}
@@ -1163,16 +1163,16 @@ yang_stmt *
xml_spec(cxobj *x)
{
if (!is_element(x))
- return NULL;
+ return NULL;
return x->x_spec;
}
int
xml_spec_set(cxobj *x,
- yang_stmt *spec)
+ yang_stmt *spec)
{
if (!is_element(x))
- return 0;
+ return 0;
x->x_spec = spec;
return 0;
}
@@ -1189,7 +1189,7 @@ cg_var *
xml_cv(cxobj *x)
{
if (!is_element(x))
- return NULL;
+ return NULL;
return x->x_cv;
}
@@ -1203,12 +1203,12 @@ xml_cv(cxobj *x)
*/
int
xml_cv_set(cxobj *x,
- cg_var *cv)
+ cg_var *cv)
{
if (!is_element(x))
- return 0;
+ return 0;
if (x->x_cv)
- cv_free(x->x_cv);
+ cv_free(x->x_cv);
x->x_cv = cv;
return 0;
}
@@ -1232,18 +1232,18 @@ xml_cv_set(cxobj *x,
*/
cxobj *
xml_find(cxobj *xp,
- char *name)
+ char *name)
{
cxobj *x = NULL;
if (xp == NULL || name == NULL) {
- return NULL;
+ return NULL;
}
if (!is_element(xp))
- return NULL;
+ return NULL;
while ((x = xml_child_each(xp, x, -1)) != NULL)
- if (strcmp(name, xml_name(x)) == 0)
- break; /* x is set */
+ if (strcmp(name, xml_name(x)) == 0)
+ break; /* x is set */
return x;
}
@@ -1259,7 +1259,7 @@ xml_find(cxobj *xp,
*/
int
xml_addsub(cxobj *xp,
- cxobj *xc)
+ cxobj *xc)
{
int retval = -1;
cxobj *oldp;
@@ -1269,39 +1269,39 @@ xml_addsub(cxobj *xp,
cxobj *xa;
if ((oldp = xml_parent(xc)) != NULL){
- /* Find child order i in old parent*/
- for (i=0; ix_childvec_len)
- if (xml_addsub(xw, xml_child_i(xp, 0)) < 0)
- goto done;
+ if (xml_addsub(xw, xml_child_i(xp, 0)) < 0)
+ goto done;
if (xml_addsub(xp, xw) < 0)
- goto done;
+ goto done;
done:
return xw;
}
@@ -1349,16 +1349,16 @@ xml_wrap_all(cxobj *xp,
*/
cxobj *
xml_wrap(cxobj *xc,
- char *tag)
+ char *tag)
{
cxobj *xw; /* new wrap node */
cxobj *xp; /* parent */
xp = xml_parent(xc);
if ((xw = xml_new(tag, xp, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
if (xml_addsub(xw, xc) < 0)
- goto done;
+ goto done;
done:
return xw;
}
@@ -1381,16 +1381,16 @@ xml_purge(cxobj *xc)
cxobj *xp;
if ((xp = xml_parent(xc)) != NULL){
- /* Find child order i in parent*/
- for (i=0; ix_childvec[i] = NULL;
xp->x_childvec_len--;
if (ix_childvec_len)
- memmove(&xp->x_childvec[i], &xp->x_childvec[i+1], (xp->x_childvec_len-i)*sizeof(cxobj*));
+ memmove(&xp->x_childvec[i], &xp->x_childvec[i+1], (xp->x_childvec_len-i)*sizeof(cxobj*));
#ifdef XML_EXPLICIT_INDEX
if (xml_type(xc) == CX_ELMNT){
- if (xml_search_index_p(xc))
- xml_search_child_rm(xp, xc);
+ if (xml_search_index_p(xc))
+ xml_search_child_rm(xp, xc);
}
#endif
@@ -1452,17 +1452,17 @@ xml_rm(cxobj *xc)
int i;
if ((xp = xml_parent(xc)) == NULL)
- goto ok;
+ goto ok;
/* Find child in parent XXX: search? */
x = NULL; i = 0;
while ((x = xml_child_each(xp, x, -1)) != NULL) {
- if (x == xc)
- break;
- i++;
+ if (x == xc)
+ break;
+ i++;
}
if (x != NULL)
- if (xml_child_rm(xp, i) < 0)
- goto done;
+ if (xml_child_rm(xp, i) < 0)
+ goto done;
ok:
retval = 0;
done:
@@ -1477,23 +1477,23 @@ xml_rm(cxobj *xc)
*/
int
xml_rm_children(cxobj *xp,
- enum cxobj_type type)
+ enum cxobj_type type)
{
int retval = -1;
cxobj *xc;
int i;
if (!is_element(xp))
- return 0;
+ return 0;
for (i=0; i_x_i = i++;
+ x->_x_i = i++;
return 0;
}
@@ -1623,9 +1623,9 @@ xml_enumerate_reset(cxobj *xp)
cxobj *x = NULL;
if (!is_element(xp))
- return 0;
+ return 0;
while ((x = xml_child_each(xp, x, -1)) != NULL)
- x->_x_i = 0;
+ x->_x_i = 0;
return 0;
}
@@ -1659,9 +1659,9 @@ xml_body(cxobj *xn)
cxobj *xb = NULL;
if (!is_element(xn))
- return NULL;
+ return NULL;
while ((xb = xml_child_each(xn, xb, CX_BODY)) != NULL)
- return xml_value(xb);
+ return xml_value(xb);
return NULL;
}
@@ -1677,9 +1677,9 @@ xml_body_get(cxobj *xt)
cxobj *xb = NULL;
if (!is_element(xt))
- return NULL;
+ return NULL;
while ((xb = xml_child_each(xt, xb, CX_BODY)) != NULL)
- return xb;
+ return xb;
return NULL;
}
@@ -1700,16 +1700,16 @@ xml_body_get(cxobj *xt)
*/
char *
xml_find_type_value(cxobj *xt,
- const char *prefix,
- const char *name,
- enum cxobj_type type)
+ const char *prefix,
+ const char *name,
+ enum cxobj_type type)
{
cxobj *x;
if (!is_element(xt))
- return NULL;
+ return NULL;
if ((x = xml_find_type(xt, prefix, name, type)) != NULL)
- return xml_value(x);
+ return xml_value(x);
return NULL;
}
@@ -1730,25 +1730,25 @@ xml_find_type_value(cxobj *xt,
*/
cxobj *
xml_find_type(cxobj *xt,
- const char *prefix,
- const char *name,
- enum cxobj_type type)
+ const char *prefix,
+ const char *name,
+ enum cxobj_type type)
{
cxobj *x = NULL;
int pmatch; /* prefix match */
char *xprefix; /* xprefix */
if (!is_element(xt))
- return NULL;
+ return NULL;
while ((x = xml_child_each(xt, x, type)) != NULL) {
- if (prefix){
- xprefix = xml_prefix(x);
- pmatch = xprefix ? strcmp(prefix,xprefix)==0 : 0;
- }
- else
- pmatch = 1;
- if (pmatch && (name==NULL || strcmp(name, xml_name(x)) == 0))
- return x;
+ if (prefix){
+ xprefix = xml_prefix(x);
+ pmatch = xprefix ? strcmp(prefix,xprefix)==0 : 0;
+ }
+ else
+ pmatch = 1;
+ if (pmatch && (name==NULL || strcmp(name, xml_name(x)) == 0))
+ return x;
}
return NULL;
}
@@ -1770,15 +1770,15 @@ xml_find_type(cxobj *xt,
*/
char *
xml_find_value(cxobj *xt,
- const char *name)
+ const char *name)
{
cxobj *x = NULL;
if (!is_element(xt))
- return NULL;
+ return NULL;
while ((x = xml_child_each(xt, x, -1)) != NULL)
- if (strcmp(name, xml_name(x)) == 0)
- return xml_value(x);
+ if (strcmp(name, xml_name(x)) == 0)
+ return xml_value(x);
return NULL;
}
@@ -1795,15 +1795,15 @@ xml_find_value(cxobj *xt,
*/
char *
xml_find_body(cxobj *xt,
- const char *name)
+ const char *name)
{
cxobj *x=NULL;
if (!is_element(xt))
- return NULL;
+ return NULL;
while ((x = xml_child_each(xt, x, -1)) != NULL)
- if (strcmp(name, xml_name(x)) == 0)
- return xml_body(x);
+ if (strcmp(name, xml_name(x)) == 0)
+ return xml_body(x);
return NULL;
}
@@ -1823,21 +1823,21 @@ xml_find_body(cxobj *xt,
*/
cxobj *
xml_find_body_obj(cxobj *xt,
- const char *name,
- char *val)
+ const char *name,
+ char *val)
{
cxobj *x = NULL;
char *bstr;
if (!is_element(xt))
- return NULL;
+ return NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- if (strcmp(name, xml_name(x)))
- continue;
- if ((bstr = xml_body(x)) == NULL)
- continue;
- if (strcmp(bstr, val) == 0)
- break; /* x is returned */
+ if (strcmp(name, xml_name(x)))
+ continue;
+ if ((bstr = xml_body(x)) == NULL)
+ continue;
+ if (strcmp(bstr, val) == 0)
+ break; /* x is returned */
}
return x;
}
@@ -1853,37 +1853,37 @@ xml_free(cxobj *x)
cxobj *xc;
if (x == NULL){
- return 0;
+ return 0;
}
if (x->x_name)
- free(x->x_name);
+ free(x->x_name);
if (x->x_prefix)
- free(x->x_prefix);
+ free(x->x_prefix);
switch (xml_type(x)){
case CX_ELMNT:
- for (i=0; ix_childvec_len; i++){
- if ((xc = x->x_childvec[i]) != NULL){
- xml_free(xc);
- x->x_childvec[i] = NULL;
- }
- }
- if (x->x_childvec)
- free(x->x_childvec);
- if (x->x_cv)
- cv_free(x->x_cv);
- if (x->x_ns_cache)
- xml_nsctx_free(x->x_ns_cache);
+ for (i=0; ix_childvec_len; i++){
+ if ((xc = x->x_childvec[i]) != NULL){
+ xml_free(xc);
+ x->x_childvec[i] = NULL;
+ }
+ }
+ if (x->x_childvec)
+ free(x->x_childvec);
+ if (x->x_cv)
+ cv_free(x->x_cv);
+ if (x->x_ns_cache)
+ xml_nsctx_free(x->x_ns_cache);
#ifdef XML_EXPLICIT_INDEX
- xml_search_index_free(x);
+ xml_search_index_free(x);
#endif
- break;
+ break;
case CX_BODY:
case CX_ATTR:
- if (x->x_value_cb)
- cbuf_free(x->x_value_cb);
- break;
+ if (x->x_value_cb)
+ cbuf_free(x->x_value_cb);
+ break;
default:
- break;
+ break;
}
free(x);
_stats_xml_nr--;
@@ -1898,36 +1898,36 @@ xml_free(cxobj *x)
*/
int
xml_copy_one(cxobj *x0,
- cxobj *x1)
+ cxobj *x1)
{
int retval = -1;
char *s;
if (x0 == NULL || x1 == NULL){
- clicon_err(OE_XML, EINVAL, "x0 or x1 is NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "x0 or x1 is NULL");
+ goto done;
}
xml_type_set(x1, xml_type(x0));
if ((s = xml_name(x0))) /* malloced string */
- if ((xml_name_set(x1, s)) < 0)
- goto done;
+ if ((xml_name_set(x1, s)) < 0)
+ goto done;
if ((s = xml_prefix(x0))) /* malloced string */
- if ((xml_prefix_set(x1, s)) < 0)
- goto done;
+ if ((xml_prefix_set(x1, s)) < 0)
+ goto done;
switch (xml_type(x0)){
case CX_ELMNT:
- xml_spec_set(x1, xml_spec(x0));
- break;
+ xml_spec_set(x1, xml_spec(x0));
+ break;
case CX_BODY:
case CX_ATTR:
- if ((s = xml_value(x0))){ /* malloced string */
- if (xml_value_set(x1, s) < 0)
- goto done;
+ if ((s = xml_value(x0))){ /* malloced string */
+ if (xml_value_set(x1, s) < 0)
+ goto done;
- }
- break;
+ }
+ break;
default:
- break;
+ break;
}
xml_flag_set(x1, xml_flag(x0, XML_FLAG_DEFAULT | XML_FLAG_TOP)); /* Maybe more flags */
retval = 0;
@@ -1952,20 +1952,20 @@ xml_copy_one(cxobj *x0,
*/
int
xml_copy(cxobj *x0,
- cxobj *x1)
+ cxobj *x1)
{
int retval = -1;
cxobj *x;
cxobj *xcopy;
if (xml_copy_one(x0, x1) <0)
- goto done;
+ goto done;
x = NULL;
while ((x = xml_child_each(x0, x, -1)) != NULL) {
- if ((xcopy = xml_new(xml_name(x), x1, xml_type(x))) == NULL)
- goto done;
- if (xml_copy(x, xcopy) < 0) /* recursion */
- goto done;
+ if ((xcopy = xml_new(xml_name(x), x1, xml_type(x))) == NULL)
+ goto done;
+ if (xml_copy(x, xcopy) < 0) /* recursion */
+ goto done;
}
retval = 0;
done:
@@ -1987,9 +1987,9 @@ xml_dup(cxobj *x0)
cxobj *x1;
if ((x1 = xml_new("new", NULL, xml_type(x0))) == NULL)
- return NULL;
+ return NULL;
if (xml_copy(x0, x1) < 0)
- return NULL;
+ return NULL;
return x1;
}
@@ -2015,14 +2015,14 @@ xml_dup(cxobj *x0)
*/
int
cxvec_append(cxobj *x,
- cxobj ***vec,
- int *len)
+ cxobj ***vec,
+ int *len)
{
int retval = -1;
if ((*vec = realloc(*vec, sizeof(cxobj *) * (*len+1))) == NULL){
- clicon_err(OE_XML, errno, "realloc");
- goto done;
+ clicon_err(OE_XML, errno, "realloc");
+ goto done;
}
(*vec)[(*len)++] = x;
retval = 0;
@@ -2051,14 +2051,14 @@ cxvec_append(cxobj *x,
*/
int
cxvec_prepend(cxobj *x,
- cxobj ***vec,
- int *len)
+ cxobj ***vec,
+ int *len)
{
int retval = -1;
if ((*vec = realloc(*vec, sizeof(cxobj *) * (*len+1))) == NULL){
- clicon_err(OE_XML, errno, "realloc");
- goto done;
+ clicon_err(OE_XML, errno, "realloc");
+ goto done;
}
memmove(&(*vec)[1], &(*vec)[0], sizeof(cxobj *) * (*len));
(*vec)[0] = x;
@@ -2098,32 +2098,32 @@ cxvec_prepend(cxobj *x,
*/
int
xml_apply(cxobj *xn,
- enum cxobj_type type,
- xml_applyfn_t fn,
- void *arg)
+ enum cxobj_type type,
+ xml_applyfn_t fn,
+ void *arg)
{
int retval = -1;
cxobj *x;
int ret;
if (!is_element(xn))
- return 0;
+ return 0;
x = NULL;
while ((x = xml_child_each(xn, x, type)) != NULL) {
- if ((ret = fn(x, arg)) < 0)
- goto done;
- if (ret == 2)
- continue; /* Abort this node, dont recurse */
- else if (ret == 1){
- retval = 1;
- goto done;
- }
- if ((ret = xml_apply(x, type, fn, arg)) < 0)
- goto done;
- if (ret == 1){
- retval = 1;
- goto done;
- }
+ if ((ret = fn(x, arg)) < 0)
+ goto done;
+ if (ret == 2)
+ continue; /* Abort this node, dont recurse */
+ else if (ret == 1){
+ retval = 1;
+ goto done;
+ }
+ if ((ret = xml_apply(x, type, fn, arg)) < 0)
+ goto done;
+ if (ret == 1){
+ retval = 1;
+ goto done;
+ }
}
retval = 0;
done:
@@ -2142,21 +2142,21 @@ xml_apply(cxobj *xn,
*/
int
xml_apply0(cxobj *xn,
- enum cxobj_type type,
- xml_applyfn_t fn,
- void *arg)
+ enum cxobj_type type,
+ xml_applyfn_t fn,
+ void *arg)
{
int retval = -1;
int ret;
if ((ret = fn(xn, arg)) < 0) /* -1, 0, 1, 2 */
- goto done;
+ goto done;
if (ret == 1)
- retval = 1;
+ retval = 1;
else if (ret > 1)
- retval = 0;
+ retval = 0;
else /* 0 */
- retval = xml_apply(xn, type, fn, arg);
+ retval = xml_apply(xn, type, fn, arg);
done:
return retval;
}
@@ -2184,21 +2184,21 @@ xml_apply0(cxobj *xn,
*/
int
xml_apply_ancestor(cxobj *xn,
- xml_applyfn_t fn,
- void *arg)
+ xml_applyfn_t fn,
+ void *arg)
{
int retval = -1;
cxobj *xp = NULL;
int ret;
while ((xp = xml_parent(xn)) != NULL) {
- if ((ret = fn(xp, arg)) < 0)
- goto done;
- if (ret > 0){
- retval = ret;
- goto done;
- }
- xn = xp;
+ if ((ret = fn(xp, arg)) < 0)
+ goto done;
+ if (ret > 0){
+ retval = ret;
+ goto done;
+ }
+ xn = xp;
}
retval = 0;
done:
@@ -2213,16 +2213,16 @@ xml_apply_ancestor(cxobj *xn,
*/
int
xml_isancestor(cxobj *x,
- cxobj *xpp)
+ cxobj *xpp)
{
cxobj *xp = NULL;
cxobj *xn = NULL;
xn = x;
while ((xp = xml_parent(xn)) != NULL) {
- if (xp == xpp)
- return 1;
- xn = xp;
+ if (xp == xpp)
+ return 1;
+ xn = xp;
}
return 0;
}
@@ -2239,7 +2239,7 @@ xml_root(cxobj *xn)
x = xn;
while ((xp = xml_parent(x)) != NULL)
- x = xp;
+ x = xp;
return x;
}
@@ -2253,23 +2253,23 @@ xml_root(cxobj *xn)
*/
int
xml_operation(char *opstr,
- enum operation_type *op)
+ enum operation_type *op)
{
if (strcmp("merge", opstr) == 0)
- *op = OP_MERGE;
+ *op = OP_MERGE;
else if (strcmp("replace", opstr) == 0)
- *op = OP_REPLACE;
+ *op = OP_REPLACE;
else if (strcmp("create", opstr) == 0)
- *op = OP_CREATE;
+ *op = OP_CREATE;
else if (strcmp("delete", opstr) == 0)
- *op = OP_DELETE;
+ *op = OP_DELETE;
else if (strcmp("remove", opstr) == 0)
- *op = OP_REMOVE;
+ *op = OP_REMOVE;
else if (strcmp("none", opstr) == 0)
- *op = OP_NONE;
+ *op = OP_NONE;
else{
- clicon_err(OE_XML, 0, "Bad-attribute operation: %s", opstr);
- return -1;
+ clicon_err(OE_XML, 0, "Bad-attribute operation: %s", opstr);
+ return -1;
}
return 0;
}
@@ -2287,22 +2287,22 @@ xml_operation2str(enum operation_type op)
{
switch (op){
case OP_MERGE:
- return "merge";
- break;
+ return "merge";
+ break;
case OP_REPLACE:
- return "replace";
- break;
+ return "replace";
+ break;
case OP_CREATE:
- return "create";
- break;
+ return "create";
+ break;
case OP_DELETE:
- return "delete";
- break;
+ return "delete";
+ break;
case OP_REMOVE:
- return "remove";
- break;
+ return "remove";
+ break;
default:
- return "none";
+ return "none";
}
}
/*! Map xml insert attribute from string to enumeration
@@ -2315,19 +2315,19 @@ xml_operation2str(enum operation_type op)
*/
int
xml_attr_insert2val(char *instr,
- enum insert_type *ins)
+ enum insert_type *ins)
{
if (strcmp("first", instr) == 0)
- *ins = INS_FIRST;
+ *ins = INS_FIRST;
else if (strcmp("last", instr) == 0)
- *ins = INS_LAST;
+ *ins = INS_LAST;
else if (strcmp("before", instr) == 0)
- *ins = INS_BEFORE;
+ *ins = INS_BEFORE;
else if (strcmp("after", instr) == 0)
- *ins = INS_AFTER;
+ *ins = INS_AFTER;
else{
- clicon_err(OE_XML, 0, "Bad-attribute operation: %s", instr);
- return -1;
+ clicon_err(OE_XML, 0, "Bad-attribute operation: %s", instr);
+ return -1;
}
return 0;
}
@@ -2339,8 +2339,8 @@ xml_attr_insert2val(char *instr,
*/
int
clicon_log_xml(int level,
- cxobj *x,
- const char *format, ...)
+ cxobj *x,
+ const char *format, ...)
{
va_list args;
size_t len;
@@ -2351,11 +2351,11 @@ clicon_log_xml(int level,
/* Print xml as cbuf */
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
if (clixon_xml2cbuf(cb, x, 0, 0, -1, 0) < 0)
- goto done;
+ goto done;
/* first round: compute length of debug message */
va_start(args, format);
len = vsnprintf(NULL, 0, format, args);
@@ -2363,20 +2363,20 @@ clicon_log_xml(int level,
/* Truncate long debug strings */
if ((trunc = clicon_log_string_limit_get()) && trunc < len)
- len = trunc;
+ len = trunc;
/* allocate a message string exactly fitting the message length */
if ((msg = malloc(len+1)) == NULL){
- fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
- goto done;
+ fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
+ goto done;
}
/* second round: compute write message from format and args */
va_start(args, format);
if (vsnprintf(msg, len+1, format, args) < 0){
- va_end(args);
- fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
- goto done;
+ va_end(args);
+ fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
+ goto done;
}
va_end(args);
@@ -2386,9 +2386,9 @@ clicon_log_xml(int level,
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (msg)
- free(msg);
+ free(msg);
return retval;
}
@@ -2412,23 +2412,23 @@ xml_search_index_p(cxobj *x)
/* The index variable has a yang spec */
if ((y = xml_spec(x)) == NULL)
- return 0;
+ return 0;
/* The index variable is a registered search index */
if (yang_flag_get(y, YANG_FLAG_INDEX) == 0)
- return 0;
+ return 0;
/* The index variable has a parent which has a LIST yang spec */
if ((xp = xml_parent(x)) == NULL)
- return 0;
+ return 0;
if ((y = xml_spec(xp)) == NULL)
- return 0;
+ return 0;
if (yang_keyword_get(y) != Y_LIST)
- return 0;
+ return 0;
/* The index variable has a grand-parent */
if (xml_parent(xp) == NULL)
- return 0;
+ return 0;
return 1;
}
-
+
/*! Free all search vector pairs of this XML node
* @param[in] x XML object
@@ -2441,12 +2441,12 @@ xml_search_index_free(cxobj *x)
struct search_index *si;
while ((si = x->x_search_index) != NULL) {
- DELQ(si, x->x_search_index, struct search_index *);
- if (si->si_name)
- free(si->si_name);
- if (si->si_xvec)
- clixon_xvec_free(si->si_xvec);
- free(si);
+ DELQ(si, x->x_search_index, struct search_index *);
+ if (si->si_name)
+ free(si->si_name);
+ if (si->si_xvec)
+ clixon_xvec_free(si->si_xvec);
+ free(si);
}
return 0;
}
@@ -2459,26 +2459,26 @@ xml_search_index_free(cxobj *x)
*/
static struct search_index *
xml_search_index_add(cxobj *x,
- char *name)
+ char *name)
{
struct search_index *si = NULL;
if ((si = malloc(sizeof(struct search_index))) == NULL){
- clicon_err(OE_XML, errno, "malloc");
- goto done;
+ clicon_err(OE_XML, errno, "malloc");
+ goto done;
}
memset(si, 0, sizeof(struct search_index));
if ((si->si_name = strdup(name)) == NULL){
- clicon_err(OE_XML, errno, "strdup");
- free(si);
- si = NULL;
- goto done;
+ clicon_err(OE_XML, errno, "strdup");
+ free(si);
+ si = NULL;
+ goto done;
}
if ((si->si_xvec = clixon_xvec_new()) == NULL){
- free(si->si_name);
- free(si);
- si = NULL;
- goto done;
+ free(si->si_name);
+ free(si);
+ si = NULL;
+ goto done;
}
ADDQ(si, x->x_search_index);
done:
@@ -2493,18 +2493,18 @@ xml_search_index_add(cxobj *x,
*/
static struct search_index *
xml_search_index_get(cxobj *x,
- char *name)
+ char *name)
{
struct search_index *si = NULL;
if ((si = x->x_search_index) != NULL) {
- do {
- if (strcmp(si->si_name, name) == 0){
- goto done;
- break;
- }
- si = NEXTQ(struct search_index *, si);
- } while (si && si != x->x_search_index);
+ do {
+ if (strcmp(si->si_name, name) == 0){
+ goto done;
+ break;
+ }
+ si = NEXTQ(struct search_index *, si);
+ } while (si && si != x->x_search_index);
}
done:
return si;
@@ -2520,20 +2520,20 @@ xml_search_index_get(cxobj *x,
*/
int
xml_search_vector_get(cxobj *xp,
- char *name,
- clixon_xvec **xvec)
+ char *name,
+ clixon_xvec **xvec)
{
struct search_index *si;
*xvec = NULL;
if ((si = xp->x_search_index) != NULL) {
- do {
- if (strcmp(si->si_name, name) == 0){
- *xvec = si->si_xvec;
- break;
- }
- si = NEXTQ(struct search_index *, si);
- } while (si && si != xp->x_search_index);
+ do {
+ if (strcmp(si->si_name, name) == 0){
+ *xvec = si->si_xvec;
+ break;
+ }
+ si = NEXTQ(struct search_index *, si);
+ } while (si && si != xp->x_search_index);
}
return 0;
}
@@ -2544,7 +2544,7 @@ xml_search_vector_get(cxobj *xp,
*/
int
xml_search_child_insert(cxobj *xp,
- cxobj *xi)
+ cxobj *xi)
{
int retval = -1;
char *indexvar;
@@ -2555,20 +2555,20 @@ xml_search_child_insert(cxobj *xp,
indexvar = xml_name(xi);
if ((xpp = xml_parent(xp)) == NULL)
- goto ok;
+ goto ok;
/* Find base vector in grandparent */
if ((si = xml_search_index_get(xpp, indexvar)) == NULL){
- /* If not found add base vector in grand-parent */
- if ((si = xml_search_index_add(xpp, indexvar)) == NULL)
- goto done;
+ /* If not found add base vector in grand-parent */
+ if ((si = xml_search_index_add(xpp, indexvar)) == NULL)
+ goto done;
}
/* Find element position using binary search and then remove */
len = clixon_xvec_len(si->si_xvec);
if ((i = xml_search_indexvar_binary_pos(xp, indexvar, si->si_xvec, 0, len, len, NULL)) < 0)
- goto done;
+ goto done;
assert(clixon_xvec_i(si->si_xvec, i) != xp);
if (clixon_xvec_insert_pos(si->si_xvec, xp, i) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
@@ -2581,7 +2581,7 @@ xml_search_child_insert(cxobj *xp,
*/
int
xml_search_child_rm(cxobj *xp,
- cxobj *xi)
+ cxobj *xi)
{
int retval = -1;
cxobj *xpp;
@@ -2593,19 +2593,19 @@ xml_search_child_rm(cxobj *xp,
indexvar = xml_name(xi);
if ((xpp = xml_parent(xp)) == NULL)
- goto ok;
+ goto ok;
/* Find base vector in grandparent */
if ((si = xml_search_index_get(xpp, indexvar)) == NULL)
- goto ok;
+ goto ok;
/* Find element using binary search and then remove */
len = clixon_xvec_len(si->si_xvec);
if ((i = xml_search_indexvar_binary_pos(xp, indexvar, si->si_xvec, 0, len, len, &eq)) < 0)
- goto done;
- // if (clixon_xvec_i(si->si_xvec, i) == xp)
+ goto done;
+ // if (clixon_xvec_i(si->si_xvec, i) == xp)
if (eq)
- if (clixon_xvec_rm_pos(si->si_xvec, i) < 0)
- goto done;
+ if (clixon_xvec_rm_pos(si->si_xvec, i) < 0)
+ goto done;
ok:
retval = 0;
done:
@@ -2633,33 +2633,33 @@ xml_search_child_rm(cxobj *xp,
*/
cxobj *
xml_child_index_each(cxobj *xparent,
- char *name,
- cxobj *xprev,
- enum cxobj_type type)
+ char *name,
+ cxobj *xprev,
+ enum cxobj_type type)
{
cxobj *xn = NULL;
clixon_xvec *xv = NULL;
int i;
if (xparent == NULL)
- return NULL;
+ return NULL;
if (!is_element(xparent))
- return NULL;
+ return NULL;
if (xml_search_vector_get(xparent, name, &xv) < 0)
- return NULL;
+ return NULL;
if (xv == NULL)
- return NULL;
+ return NULL;
for (i=xprev?xprev->_x_vector_i+1:0; i_x_vector_i = i;
+ xn->_x_vector_i = i;
else
- xn = NULL;
+ xn = NULL;
return xn;
}
diff --git a/lib/src/clixon_xml_bind.c b/lib/src/clixon_xml_bind.c
index daac2cfd..ef4fb7c8 100644
--- a/lib/src/clixon_xml_bind.c
+++ b/lib/src/clixon_xml_bind.c
@@ -119,15 +119,15 @@ strip_body_objects(cxobj *xt)
cxobj *xb;
if ((yt = xml_spec(xt)) != NULL){
- keyword = yang_keyword_get(yt);
- if (keyword == Y_LIST || keyword == Y_CONTAINER){
- xb = NULL;
- /* Quits if marked object, assume all are same */
- while ((xb = xml_find_type(xt, NULL, "body", CX_BODY)) != NULL &&
- !xml_flag(xb, XML_FLAG_BODYKEY)){
- xml_purge(xb);
- }
- }
+ keyword = yang_keyword_get(yt);
+ if (keyword == Y_LIST || keyword == Y_CONTAINER){
+ xb = NULL;
+ /* Quits if marked object, assume all are same */
+ while ((xb = xml_find_type(xt, NULL, "body", CX_BODY)) != NULL &&
+ !xml_flag(xb, XML_FLAG_BODYKEY)){
+ xml_purge(xb);
+ }
+ }
}
return 0;
@@ -146,8 +146,8 @@ strip_body_objects(cxobj *xt)
*/
static int
populate_self_parent(cxobj *xt,
- cxobj *xsibling,
- cxobj **xerr)
+ cxobj *xsibling,
+ cxobj **xerr)
{
int retval = -1;
yang_stmt *y = NULL; /* yang node */
@@ -161,80 +161,80 @@ populate_self_parent(cxobj *xt,
name = xml_name(xt);
/* optimization for massive lists - use the first element as role model */
if (xsibling &&
- xml_child_nr_type(xt, CX_ATTR) == 0){
- y = xml_spec(xsibling);
- goto set;
+ xml_child_nr_type(xt, CX_ATTR) == 0){
+ y = xml_spec(xsibling);
+ goto set;
}
xp = xml_parent(xt);
if (xp == NULL){
- if (xerr &&
- netconf_bad_element_xml(xerr, "application", name, "Missing parent") < 0)
- goto done;
- goto fail;
+ if (xerr &&
+ netconf_bad_element_xml(xerr, "application", name, "Missing parent") < 0)
+ goto done;
+ goto fail;
}
if ((yparent = xml_spec(xp)) == NULL){
- if (xerr &&
- netconf_bad_element_xml(xerr, "application", name, "Missing parent yang node") < 0)
- goto done;
- goto fail;
+ if (xerr &&
+ netconf_bad_element_xml(xerr, "application", name, "Missing parent yang node") < 0)
+ goto done;
+ goto fail;
}
if (yang_keyword_get(yparent) == Y_ANYXML || yang_keyword_get(yparent) == Y_ANYDATA){
- retval = 2;
- goto done;
+ retval = 2;
+ goto done;
}
if (xml2ns(xt, xml_prefix(xt), &ns) < 0)
- goto done;
+ goto done;
/* Special case since action is not a datanode */
if ((y = yang_find(yparent, Y_ACTION, name)) == NULL)
- if ((y = yang_find_datanode(yparent, name)) == NULL){
- if (_yang_unknown_anydata){
- /* Add dummy Y_ANYDATA yang stmt, see ysp_add */
- if ((y = yang_anydata_add(yparent, name)) < 0)
- goto done;
- xml_spec_set(xt, y);
- retval = 2; /* treat as anydata */
- clicon_log(LOG_WARNING,
- "%s: %d: No YANG spec for %s, anydata used",
- __FUNCTION__, __LINE__, name);
- goto done;
- }
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Failed to find YANG spec of XML node: %s", name);
- cprintf(cb, " with parent: %s", xml_name(xp));
- if (ns)
- cprintf(cb, " in namespace: %s", ns);
- if (xerr &&
- netconf_unknown_element_xml(xerr, "application", name, cbuf_get(cb)) < 0)
- goto done;
- goto fail;
- }
+ if ((y = yang_find_datanode(yparent, name)) == NULL){
+ if (_yang_unknown_anydata){
+ /* Add dummy Y_ANYDATA yang stmt, see ysp_add */
+ if ((y = yang_anydata_add(yparent, name)) < 0)
+ goto done;
+ xml_spec_set(xt, y);
+ retval = 2; /* treat as anydata */
+ clicon_log(LOG_WARNING,
+ "%s: %d: No YANG spec for %s, anydata used",
+ __FUNCTION__, __LINE__, name);
+ goto done;
+ }
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Failed to find YANG spec of XML node: %s", name);
+ cprintf(cb, " with parent: %s", xml_name(xp));
+ if (ns)
+ cprintf(cb, " in namespace: %s", ns);
+ if (xerr &&
+ netconf_unknown_element_xml(xerr, "application", name, cbuf_get(cb)) < 0)
+ goto done;
+ goto fail;
+ }
nsy = yang_find_mynamespace(y);
if (ns == NULL || nsy == NULL){
- if (xerr &&
- netconf_bad_element_xml(xerr, "application", name, "Missing namespace") < 0)
- goto done;
- goto fail;
+ if (xerr &&
+ netconf_bad_element_xml(xerr, "application", name, "Missing namespace") < 0)
+ goto done;
+ goto fail;
}
/* Assign spec only if namespaces match */
if (strcmp(ns, nsy) != 0){
- if (xerr &&
- netconf_bad_element_xml(xerr, "application", name, "Namespace mismatch") < 0)
- goto done;
- goto fail;
+ if (xerr &&
+ netconf_bad_element_xml(xerr, "application", name, "Namespace mismatch") < 0)
+ goto done;
+ goto fail;
}
set:
xml_spec_set(xt, y);
#ifdef XML_EXPLICIT_INDEX
if (xml_search_index_p(xt))
- xml_search_child_insert(xp, xt);
+ xml_search_child_insert(xp, xt);
#endif
retval = 1;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
fail:
retval = 0;
@@ -253,8 +253,8 @@ populate_self_parent(cxobj *xt,
*/
static int
populate_self_top(cxobj *xt,
- yang_stmt *yspec,
- cxobj **xerr)
+ yang_stmt *yspec,
+ cxobj **xerr)
{
int retval = -1;
yang_stmt *y = NULL; /* yang node */
@@ -267,78 +267,78 @@ populate_self_top(cxobj *xt,
name = xml_name(xt);
if (yspec == NULL){
- if (xerr &&
- netconf_bad_element_xml(xerr, "application", name, "Missing yang spec") < 0)
- goto done;
- goto fail;
+ if (xerr &&
+ netconf_bad_element_xml(xerr, "application", name, "Missing yang spec") < 0)
+ goto done;
+ goto fail;
}
if (ys_module_by_xml(yspec, xt, &ymod) < 0)
- goto done;
+ goto done;
if (xml2ns(xt, xml_prefix(xt), &ns) < 0)
- goto done;
+ goto done;
/* ymod is "real" module, name may belong to included submodule */
if (ymod == NULL){
- if (xerr){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Failed to find YANG spec of XML node: %s", name);
- if ((xp = xml_parent(xt)) != NULL)
- cprintf(cb, " with parent: %s", xml_name(xp));
- if (ns)
- cprintf(cb, " in namespace: %s", ns);
- if (netconf_unknown_element_xml(xerr, "application", name, cbuf_get(cb)) < 0)
- goto done;
- }
- goto fail;
+ if (xerr){
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Failed to find YANG spec of XML node: %s", name);
+ if ((xp = xml_parent(xt)) != NULL)
+ cprintf(cb, " with parent: %s", xml_name(xp));
+ if (ns)
+ cprintf(cb, " in namespace: %s", ns);
+ if (netconf_unknown_element_xml(xerr, "application", name, cbuf_get(cb)) < 0)
+ goto done;
+ }
+ goto fail;
}
if ((y = yang_find_schemanode(ymod, name)) == NULL){ /* also rpc */
- if (_yang_unknown_anydata){
- /* Add dummy Y_ANYDATA yang stmt, see ysp_add */
- if ((y = yang_anydata_add(ymod, name)) < 0)
- goto done;
- xml_spec_set(xt, y);
- retval = 2; /* treat as anydata */
- clicon_log(LOG_WARNING,
- "%s: %d: No YANG spec for %s, anydata used",
- __FUNCTION__, __LINE__, name);
- goto done;
- }
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Failed to find YANG spec of XML node: %s", name);
- if ((xp = xml_parent(xt)) != NULL)
- cprintf(cb, " with parent: %s", xml_name(xp));
- if (ns)
- cprintf(cb, " in namespace: %s", ns);
- if (xerr &&
- netconf_unknown_element_xml(xerr, "application", name, cbuf_get(cb)) < 0)
- goto done;
- goto fail;
+ if (_yang_unknown_anydata){
+ /* Add dummy Y_ANYDATA yang stmt, see ysp_add */
+ if ((y = yang_anydata_add(ymod, name)) < 0)
+ goto done;
+ xml_spec_set(xt, y);
+ retval = 2; /* treat as anydata */
+ clicon_log(LOG_WARNING,
+ "%s: %d: No YANG spec for %s, anydata used",
+ __FUNCTION__, __LINE__, name);
+ goto done;
+ }
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Failed to find YANG spec of XML node: %s", name);
+ if ((xp = xml_parent(xt)) != NULL)
+ cprintf(cb, " with parent: %s", xml_name(xp));
+ if (ns)
+ cprintf(cb, " in namespace: %s", ns);
+ if (xerr &&
+ netconf_unknown_element_xml(xerr, "application", name, cbuf_get(cb)) < 0)
+ goto done;
+ goto fail;
}
nsy = yang_find_mynamespace(y);
if (ns == NULL || nsy == NULL){
- if (xerr &&
- netconf_bad_element_xml(xerr, "application", name, "Missing namespace") < 0)
- goto done;
- goto fail;
+ if (xerr &&
+ netconf_bad_element_xml(xerr, "application", name, "Missing namespace") < 0)
+ goto done;
+ goto fail;
}
/* Assign spec only if namespaces match */
if (strcmp(ns, nsy) != 0){
- if (xerr &&
- netconf_bad_element_xml(xerr, "application", name, "Namespace mismatch") < 0)
- goto done;
- goto fail;
+ if (xerr &&
+ netconf_bad_element_xml(xerr, "application", name, "Namespace mismatch") < 0)
+ goto done;
+ goto fail;
}
xml_spec_set(xt, y);
retval = 1;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
fail:
retval = 0;
@@ -368,9 +368,9 @@ populate_self_top(cxobj *xt,
*/
int
xml_bind_yang(cxobj *xt,
- yang_bind yb,
- yang_stmt *yspec,
- cxobj **xerr)
+ yang_bind yb,
+ yang_stmt *yspec,
+ cxobj **xerr)
{
int retval = -1;
cxobj *xc; /* xml child */
@@ -379,10 +379,10 @@ xml_bind_yang(cxobj *xt,
strip_body_objects(xt);
xc = NULL; /* Apply on children */
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL) {
- if ((ret = xml_bind_yang0(xc, yb, yspec, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = xml_bind_yang0(xc, yb, yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
retval = 1;
done:
@@ -394,9 +394,9 @@ xml_bind_yang(cxobj *xt,
static int
xml_bind_yang0_opt(cxobj *xt,
- yang_bind yb,
- cxobj *xsibling,
- cxobj **xerr)
+ yang_bind yb,
+ cxobj *xsibling,
+ cxobj **xerr)
{
int retval = -1;
cxobj *xc; /* xml child */
@@ -411,44 +411,44 @@ xml_bind_yang0_opt(cxobj *xt,
switch (yb){
case YB_PARENT:
- if ((ret = populate_self_parent(xt, xsibling, xerr)) < 0)
- goto done;
- break;
+ if ((ret = populate_self_parent(xt, xsibling, xerr)) < 0)
+ goto done;
+ break;
default:
- clicon_err(OE_XML, EINVAL, "Invalid yang binding: %d", yb);
- goto done;
- break;
+ clicon_err(OE_XML, EINVAL, "Invalid yang binding: %d", yb);
+ goto done;
+ break;
}
if (ret == 0)
- goto fail;
+ goto fail;
else if (ret == 2) /* ret=2 for anyxml from parent^ */
- goto ok;
+ goto ok;
strip_body_objects(xt);
xc = NULL; /* Apply on children */
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL) {
- /* It is xml2ns in populate_self_parent that needs improvement */
- /* cache previous + prefix */
- name = xml_name(xc);
- prefix = xml_prefix(xc);
- if (yc0 != NULL &&
- clicon_strcmp(name0, name) == 0 &&
- clicon_strcmp(prefix0, prefix) == 0){
- if ((ret = xml_bind_yang0_opt(xc, YB_PARENT, xc0, xerr)) < 0)
- goto done;
- }
- else if (xsibling &&
- (xs = xml_find_type(xsibling, prefix, name, CX_ELMNT)) != NULL){
- if ((ret = xml_bind_yang0_opt(xc, YB_PARENT, xs, xerr)) < 0)
- goto done;
- }
- else if ((ret = xml_bind_yang0_opt(xc, YB_PARENT, NULL, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- xc0 = xc;
- yc0 = xml_spec(xc); /* cache */
- name0 = xml_name(xc);
- prefix0 = xml_prefix(xc);
+ /* It is xml2ns in populate_self_parent that needs improvement */
+ /* cache previous + prefix */
+ name = xml_name(xc);
+ prefix = xml_prefix(xc);
+ if (yc0 != NULL &&
+ clicon_strcmp(name0, name) == 0 &&
+ clicon_strcmp(prefix0, prefix) == 0){
+ if ((ret = xml_bind_yang0_opt(xc, YB_PARENT, xc0, xerr)) < 0)
+ goto done;
+ }
+ else if (xsibling &&
+ (xs = xml_find_type(xsibling, prefix, name, CX_ELMNT)) != NULL){
+ if ((ret = xml_bind_yang0_opt(xc, YB_PARENT, xs, xerr)) < 0)
+ goto done;
+ }
+ else if ((ret = xml_bind_yang0_opt(xc, YB_PARENT, NULL, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ xc0 = xc;
+ yc0 = xml_spec(xc); /* cache */
+ name0 = xml_name(xc);
+ prefix0 = xml_prefix(xc);
}
ok:
retval = 1;
@@ -473,9 +473,9 @@ xml_bind_yang0_opt(cxobj *xt,
*/
int
xml_bind_yang0(cxobj *xt,
- yang_bind yb,
- yang_stmt *yspec,
- cxobj **xerr)
+ yang_bind yb,
+ yang_stmt *yspec,
+ cxobj **xerr)
{
int retval = -1;
cxobj *xc; /* xml child */
@@ -483,32 +483,32 @@ xml_bind_yang0(cxobj *xt,
switch (yb){
case YB_MODULE:
- if ((ret = populate_self_top(xt, yspec, xerr)) < 0)
- goto done;
- break;
+ if ((ret = populate_self_top(xt, yspec, xerr)) < 0)
+ goto done;
+ break;
case YB_PARENT:
- if ((ret = populate_self_parent(xt, NULL, xerr)) < 0)
- goto done;
- break;
+ if ((ret = populate_self_parent(xt, NULL, xerr)) < 0)
+ goto done;
+ break;
case YB_NONE:
- ret = 1;
- break;
+ ret = 1;
+ break;
default:
- clicon_err(OE_XML, EINVAL, "Invalid yang binding: %d", yb);
- goto done;
- break;
+ clicon_err(OE_XML, EINVAL, "Invalid yang binding: %d", yb);
+ goto done;
+ break;
}
if (ret == 0)
- goto fail;
+ goto fail;
else if (ret == 2) /* ret=2 for anyxml from parent^ */
- goto ok;
+ goto ok;
strip_body_objects(xt);
xc = NULL; /* Apply on children */
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL) {
- if ((ret = xml_bind_yang0_opt(xc, YB_PARENT, NULL, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ if ((ret = xml_bind_yang0_opt(xc, YB_PARENT, NULL, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
ok:
retval = 1;
@@ -523,9 +523,9 @@ xml_bind_yang0(cxobj *xt,
*/
static int
xml_bind_yang_rpc_rpc(cxobj *x,
- yang_stmt *yrpc,
- char *rpcname,
- cxobj **xerr)
+ yang_stmt *yrpc,
+ char *rpcname,
+ cxobj **xerr)
{
int retval = -1;
cbuf *cb = NULL;
@@ -536,35 +536,35 @@ xml_bind_yang_rpc_rpc(cxobj *x,
xml_spec_set(x, yrpc); /* required for validate */
if ((yi = yang_find(yrpc, Y_INPUT, NULL)) == NULL){
- /* If no yang input spec but RPC has elements, return unknown element */
- if (xml_child_nr_type(x, CX_ELMNT) != 0){
- xc = xml_child_i_type(x, 0, CX_ELMNT); /* Pick first */
- name = xml_name(xc);
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Unrecognized parameter: %s in rpc: %s", name, rpcname);
- if (xerr &&
- netconf_unknown_element_xml(xerr, "application", name, cbuf_get(cb)) < 0)
- goto done;
- goto fail;
- }
+ /* If no yang input spec but RPC has elements, return unknown element */
+ if (xml_child_nr_type(x, CX_ELMNT) != 0){
+ xc = xml_child_i_type(x, 0, CX_ELMNT); /* Pick first */
+ name = xml_name(xc);
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Unrecognized parameter: %s in rpc: %s", name, rpcname);
+ if (xerr &&
+ netconf_unknown_element_xml(xerr, "application", name, cbuf_get(cb)) < 0)
+ goto done;
+ goto fail;
+ }
}
else{
- /* xml_bind_yang need to have parent with yang spec for
- * recursive population to work. Therefore, assign input yang
- * to rpc level although not 100% intuitive */
- xml_spec_set(x, yi);
- if ((ret = xml_bind_yang(x, YB_PARENT, NULL, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ /* xml_bind_yang need to have parent with yang spec for
+ * recursive population to work. Therefore, assign input yang
+ * to rpc level although not 100% intuitive */
+ xml_spec_set(x, yi);
+ if ((ret = xml_bind_yang(x, YB_PARENT, NULL, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
retval = 1;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
fail:
retval = 0;
@@ -580,8 +580,8 @@ xml_bind_yang_rpc_rpc(cxobj *x,
*/
static int
xml_bind_yang_rpc_action(cxobj *xn,
- yang_stmt *yspec,
- cxobj **xerr)
+ yang_stmt *yspec,
+ cxobj **xerr)
{
int retval = -1;
int ret;
@@ -589,13 +589,13 @@ xml_bind_yang_rpc_action(cxobj *xn,
yang_stmt *yi;;
if ((ret = xml_bind_yang(xn, YB_MODULE, yspec, xerr)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
/* Special case: bind "action" node to module for validate code to work */
if ((xi = xml_child_i_type(xn, 0, CX_ELMNT)) != NULL &&
- (yi = xml_spec(xi))){
- xml_spec_set(xn, ys_module(yi));
+ (yi = xml_spec(xi))){
+ xml_spec_set(xn, ys_module(yi));
}
retval = 1;
done:
@@ -624,8 +624,8 @@ xml_bind_yang_rpc_action(cxobj *xn,
*/
int
xml_bind_yang_rpc(cxobj *xrpc,
- yang_stmt *yspec,
- cxobj **xerr)
+ yang_stmt *yspec,
+ cxobj **xerr)
{
int retval = -1;
yang_stmt *yrpc = NULL; /* yang node */
@@ -639,90 +639,90 @@ xml_bind_yang_rpc(cxobj *xrpc,
opname = xml_name(xrpc);
if ((strcmp(opname, "hello")) == 0){
- /* Hello: dont bind, dont appear in any yang spec, just ensure there is nothing apart from
- * session-id or capabilities/capability tags
- * If erro, just log, drop and close, rpc-error should not be sent since it is not rpc
- * Actually, there are no error replies to hello messages according to any RFC, so
- * rpc error reply here is non-standard, but may be useful.
- */
- x = NULL;
- while ((x = xml_child_each(xrpc, x, CX_ELMNT)) != NULL) {
- name = xml_name(x);
- if (strcmp(name, "session-id") == 0)
- continue;
- else if (strcmp(name, "capabilities") == 0){
- xc = NULL;
- while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(xc), "capability") != 0){
- if (xerr &&
- netconf_unknown_element_xml(xerr, "protocol", xml_name(xc),
- "Unrecognized hello/capabilities element") < 0)
- goto done;
- goto fail;
- }
- }
- }
- else {
- if (xerr &&
- netconf_unknown_element_xml(xerr, "protocol", name, "Unrecognized hello element") < 0)
- goto done;
- clicon_err(OE_XML, EFAULT, "Unrecognized hello element: %s", name);
- goto fail;
- }
- }
- goto ok;
+ /* Hello: dont bind, dont appear in any yang spec, just ensure there is nothing apart from
+ * session-id or capabilities/capability tags
+ * If erro, just log, drop and close, rpc-error should not be sent since it is not rpc
+ * Actually, there are no error replies to hello messages according to any RFC, so
+ * rpc error reply here is non-standard, but may be useful.
+ */
+ x = NULL;
+ while ((x = xml_child_each(xrpc, x, CX_ELMNT)) != NULL) {
+ name = xml_name(x);
+ if (strcmp(name, "session-id") == 0)
+ continue;
+ else if (strcmp(name, "capabilities") == 0){
+ xc = NULL;
+ while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL) {
+ if (strcmp(xml_name(xc), "capability") != 0){
+ if (xerr &&
+ netconf_unknown_element_xml(xerr, "protocol", xml_name(xc),
+ "Unrecognized hello/capabilities element") < 0)
+ goto done;
+ goto fail;
+ }
+ }
+ }
+ else {
+ if (xerr &&
+ netconf_unknown_element_xml(xerr, "protocol", name, "Unrecognized hello element") < 0)
+ goto done;
+ clicon_err(OE_XML, EFAULT, "Unrecognized hello element: %s", name);
+ goto fail;
+ }
+ }
+ goto ok;
}
else if ((strcmp(opname, "notification")) == 0)
- goto ok;
+ goto ok;
else if ((strcmp(opname, "rpc")) == 0)
- ; /* continue */
+ ; /* continue */
else { /* Notify, rpc-reply? */
- if (xerr &&
- netconf_unknown_element_xml(xerr, "protocol", opname, "Unrecognized netconf operation") < 0)
- goto done;
- goto fail;
+ if (xerr &&
+ netconf_unknown_element_xml(xerr, "protocol", opname, "Unrecognized netconf operation") < 0)
+ goto done;
+ goto fail;
}
if (_netconf_message_id_optional == 0){
- /* RFC 6241 4.1:
- * The element has a mandatory attribute "message-id"
- */
- if (xml_find_type(xrpc, NULL, "message-id", CX_ATTR) == NULL){
- if (xerr &&
- netconf_missing_attribute_xml(xerr, "rpc", "message-id", "Incoming rpc") < 0)
- goto done;
- goto fail;
- }
+ /* RFC 6241 4.1:
+ * The element has a mandatory attribute "message-id"
+ */
+ if (xml_find_type(xrpc, NULL, "message-id", CX_ATTR) == NULL){
+ if (xerr &&
+ netconf_missing_attribute_xml(xerr, "rpc", "message-id", "Incoming rpc") < 0)
+ goto done;
+ goto fail;
+ }
}
x = NULL;
while ((x = xml_child_each(xrpc, x, CX_ELMNT)) != NULL) {
- rpcname = xml_name(x);
- if ((ret = xml_rpc_isaction(x)) < 0)
- goto done;
- if (ret == 1){
- if ((ret = xml_bind_yang_rpc_action(x, yspec, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
- goto ok;
- } /* if not action fall through */
- if (ys_module_by_xml(yspec, x, &ymod) < 0)
- goto done;
- if (ymod == NULL){
- if (xerr &&
- netconf_unknown_element_xml(xerr, "application", rpcname, "Unrecognized RPC (wrong namespace?)") < 0)
- goto done;
- goto fail;
- }
- if ((yrpc = yang_find(ymod, Y_RPC, rpcname)) == NULL){
- if (xerr &&
- netconf_unknown_element_xml(xerr, "application", rpcname, "Unrecognized RPC") < 0)
- goto done;
- goto fail;
- }
- if ((ret = xml_bind_yang_rpc_rpc(x, yrpc, rpcname, xerr)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ rpcname = xml_name(x);
+ if ((ret = xml_rpc_isaction(x)) < 0)
+ goto done;
+ if (ret == 1){
+ if ((ret = xml_bind_yang_rpc_action(x, yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
+ goto ok;
+ } /* if not action fall through */
+ if (ys_module_by_xml(yspec, x, &ymod) < 0)
+ goto done;
+ if (ymod == NULL){
+ if (xerr &&
+ netconf_unknown_element_xml(xerr, "application", rpcname, "Unrecognized RPC (wrong namespace?)") < 0)
+ goto done;
+ goto fail;
+ }
+ if ((yrpc = yang_find(ymod, Y_RPC, rpcname)) == NULL){
+ if (xerr &&
+ netconf_unknown_element_xml(xerr, "application", rpcname, "Unrecognized RPC") < 0)
+ goto done;
+ goto fail;
+ }
+ if ((ret = xml_bind_yang_rpc_rpc(x, yrpc, rpcname, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
ok:
retval = 1;
@@ -752,9 +752,9 @@ xml_bind_yang_rpc(cxobj *xrpc,
*/
int
xml_bind_yang_rpc_reply(cxobj *xrpc,
- char *name,
- yang_stmt *yspec,
- cxobj **xerr)
+ char *name,
+ yang_stmt *yspec,
+ cxobj **xerr)
{
int retval = -1;
yang_stmt *yrpc = NULL; /* yang node */
@@ -769,63 +769,63 @@ xml_bind_yang_rpc_reply(cxobj *xrpc,
opname = xml_name(xrpc);
if (strcmp(opname, "rpc-reply")){
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cberr, "Internal error, unrecognized netconf operation in backend reply, expected rpc-reply but received: %s", opname);
- if (xerr && netconf_operation_failed_xml(xerr, "application", cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cberr, "Internal error, unrecognized netconf operation in backend reply, expected rpc-reply but received: %s", opname);
+ if (xerr && netconf_operation_failed_xml(xerr, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
}
x = NULL;
while ((x = xml_child_each(xrpc, x, CX_ELMNT)) != NULL) {
- if (ys_module_by_xml(yspec, x, &ymod) < 0)
- goto done;
- if (ymod == NULL)
- continue;
- if ((yrpc = yang_find(ymod, Y_RPC, name)) == NULL)
- continue;
- // xml_spec_set(xrpc, yrpc);
- if ((yo = yang_find(yrpc, Y_OUTPUT, NULL)) == NULL)
- continue;
- /* xml_bind_yang need to have parent with yang spec for
- * recursive population to work. Therefore, assign input yang
- * to rpc level although not 100% intuitive */
- break;
+ if (ys_module_by_xml(yspec, x, &ymod) < 0)
+ goto done;
+ if (ymod == NULL)
+ continue;
+ if ((yrpc = yang_find(ymod, Y_RPC, name)) == NULL)
+ continue;
+ // xml_spec_set(xrpc, yrpc);
+ if ((yo = yang_find(yrpc, Y_OUTPUT, NULL)) == NULL)
+ continue;
+ /* xml_bind_yang need to have parent with yang spec for
+ * recursive population to work. Therefore, assign input yang
+ * to rpc level although not 100% intuitive */
+ break;
}
if (yo != NULL){
- xml_spec_set(xrpc, yo);
- /* Special case for ok and rpc-error */
- if ((xc = xml_child_i_type(xrpc, 0, CX_ELMNT)) != NULL &&
- (strcmp(xml_name(xc),"rpc-error") == 0
- || strcmp(xml_name(xc),"ok") == 0
- )){
- goto ok;
- }
- /* Use a temporary xml error tree since it is stringified in the original error on error */
- if ((ret = xml_bind_yang(xrpc, YB_PARENT, NULL, &xerr1)) < 0)
- goto done;
- if (ret == 0){
- if ((cberr = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cberr, "Internal error in backend reply: ");
- if (netconf_err2cb(xerr1, cberr) < 0)
- goto done;
- if (xerr && netconf_operation_failed_xml(xerr, "application", cbuf_get(cberr)) < 0)
- goto done;
- goto fail;
- }
+ xml_spec_set(xrpc, yo);
+ /* Special case for ok and rpc-error */
+ if ((xc = xml_child_i_type(xrpc, 0, CX_ELMNT)) != NULL &&
+ (strcmp(xml_name(xc),"rpc-error") == 0
+ || strcmp(xml_name(xc),"ok") == 0
+ )){
+ goto ok;
+ }
+ /* Use a temporary xml error tree since it is stringified in the original error on error */
+ if ((ret = xml_bind_yang(xrpc, YB_PARENT, NULL, &xerr1)) < 0)
+ goto done;
+ if (ret == 0){
+ if ((cberr = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cberr, "Internal error in backend reply: ");
+ if (netconf_err2cb(xerr1, cberr) < 0)
+ goto done;
+ if (xerr && netconf_operation_failed_xml(xerr, "application", cbuf_get(cberr)) < 0)
+ goto done;
+ goto fail;
+ }
}
ok:
retval = 1;
done:
if (cberr)
- cbuf_free(cberr);
+ cbuf_free(cberr);
if (xerr1)
- xml_free(xerr1);
+ xml_free(xerr1);
return retval;
fail:
retval = 0;
@@ -836,16 +836,16 @@ xml_bind_yang_rpc_reply(cxobj *xrpc,
*/
int
xml_bind_special(cxobj *xd,
- yang_stmt *yspec,
- char *schema_nodeid)
+ yang_stmt *yspec,
+ char *schema_nodeid)
{
int retval = -1;
yang_stmt *yd;
if (yang_abs_schema_nodeid(yspec, schema_nodeid, &yd) < 0)
- goto done;
+ goto done;
if (yd)
- xml_spec_set(xd, yd);
+ xml_spec_set(xd, yd);
retval = 0;
done:
return retval;
diff --git a/lib/src/clixon_xml_changelog.c b/lib/src/clixon_xml_changelog.c
index df99bc05..44dddc26 100644
--- a/lib/src/clixon_xml_changelog.c
+++ b/lib/src/clixon_xml_changelog.c
@@ -80,36 +80,36 @@
static int
changelog_rename(clicon_handle h,
- cxobj *xt,
- cxobj *xw,
- cvec *nsc,
- char *tag)
+ cxobj *xt,
+ cxobj *xw,
+ cvec *nsc,
+ char *tag)
{
int retval = -1;
xp_ctx *xctx = NULL;
char *str = NULL;
if (tag == NULL){
- clicon_err(OE_XML, 0, "tag required");
- goto done;
+ clicon_err(OE_XML, 0, "tag required");
+ goto done;
}
if (xpath_vec_ctx(xw, nsc, tag, 0, &xctx) < 0)
- goto done;
+ goto done;
if (ctx2string(xctx, &str) < 0)
- goto done;
+ goto done;
if (!strlen(str)){
- clicon_err(OE_XML, 0, "invalid rename tag: \"%s\"", str);
- goto done;
+ clicon_err(OE_XML, 0, "invalid rename tag: \"%s\"", str);
+ goto done;
}
if (xml_name_set(xw, str) < 0)
- goto done;
+ goto done;
// ok:
retval = 1;
done:
if (xctx)
- ctx_free(xctx);
+ ctx_free(xctx);
if (str)
- free(str);
+ free(str);
return retval;
// fail:
retval = 0;
@@ -119,9 +119,9 @@ changelog_rename(clicon_handle h,
/* replace target XML */
static int
changelog_replace(clicon_handle h,
- cxobj *xt,
- cxobj *xw,
- cxobj *xnew)
+ cxobj *xt,
+ cxobj *xw,
+ cxobj *xnew)
{
int retval = -1;
cxobj *x;
@@ -129,22 +129,22 @@ changelog_replace(clicon_handle h,
/* create a new node by parsing fttransform string and insert it at
target */
if (xnew == NULL){
- clicon_err(OE_XML, 0, "new required");
- goto done;
+ clicon_err(OE_XML, 0, "new required");
+ goto done;
}
/* replace: remove all children of target */
while ((x = xml_child_i(xw, 0)) != NULL)
- if (xml_purge(x) < 0)
- goto done;
+ if (xml_purge(x) < 0)
+ goto done;
/* replace: first single node under */
if (xml_child_nr(xnew) != 1){
- clicon_err(OE_XML, 0, "Single child to required");
- goto done;
+ clicon_err(OE_XML, 0, "Single child to required");
+ goto done;
}
x = xml_child_i(xnew, 0);
/* Copy from xnew to (now) empty target */
if (xml_copy(x, xw) < 0)
- goto done;
+ goto done;
retval = 1;
done:
return retval;
@@ -154,21 +154,21 @@ changelog_replace(clicon_handle h,
target */
static int
changelog_insert(clicon_handle h,
- cxobj *xt,
- cxobj *xw,
- cxobj *xnew)
+ cxobj *xt,
+ cxobj *xw,
+ cxobj *xnew)
{
int retval = -1;
cxobj *x;
if (xnew == NULL){
- clicon_err(OE_XML, 0, "new required");
- goto done;
+ clicon_err(OE_XML, 0, "new required");
+ goto done;
}
/* replace: add all new children to target */
while ((x = xml_child_i(xnew, 0)) != NULL)
- if (xml_addsub(xw, x) < 0)
- goto done;
+ if (xml_addsub(xw, x) < 0)
+ goto done;
// ok:
retval = 1;
done:
@@ -181,13 +181,13 @@ changelog_insert(clicon_handle h,
/* delete target */
static int
changelog_delete(clicon_handle h,
- cxobj *xt,
- cxobj *xw)
+ cxobj *xt,
+ cxobj *xw)
{
int retval = -1;
if (xml_purge(xw) < 0)
- goto done;
+ goto done;
retval = 1;
done:
return retval;
@@ -196,20 +196,20 @@ changelog_delete(clicon_handle h,
/* Move target node to location */
static int
changelog_move(clicon_handle h,
- cxobj *xt,
- cxobj *xw,
- cvec *nsc,
- char *dst)
+ cxobj *xt,
+ cxobj *xw,
+ cvec *nsc,
+ char *dst)
{
int retval = -1;
cxobj *xp; /* destination parent node */
if ((xp = xpath_first(xt, nsc, "%s", dst)) == NULL){
- clicon_err(OE_XML, 0, "path required");
- goto done;
+ clicon_err(OE_XML, 0, "path required");
+ goto done;
}
if (xml_addsub(xp, xw) < 0)
- goto done;
+ goto done;
retval = 1;
done:
return retval;
@@ -225,8 +225,8 @@ changelog_move(clicon_handle h,
*/
static int
changelog_op(clicon_handle h,
- cxobj *xt,
- cxobj *xi)
+ cxobj *xt,
+ cxobj *xi)
{
int retval = -1;
@@ -246,16 +246,16 @@ changelog_op(clicon_handle h,
/* Get namespace context from changelog item */
if (xml_nsctx_node(xi, &nsc) < 0)
- goto done;
+ goto done;
if ((op = xml_find_body(xi, "op")) == NULL)
- goto ok;
+ goto ok;
/* get common variables that may be used in the operations below */
tag = xml_find_body(xi, "tag");
dst = xml_find_body(xi, "dst");
xnew = xml_find(xi, "new");
whenxpath = xml_find_body(xi, "when");
if ((wxpath = xml_find_body(xi, "where")) == NULL)
- goto ok;
+ goto ok;
/* Get vector of target nodes meeting the where requirement */
if (xpath_vec(xt, nsc, "%s", &wvec, &wlen, wxpath) < 0)
goto done;
@@ -263,51 +263,51 @@ changelog_op(clicon_handle h,
xw = wvec[i];
/* If 'when' exists and is false, skip this target */
if (whenxpath){
- if (xpath_vec_ctx(xw, nsc, whenxpath, 0, &xctx) < 0)
- goto done;
- if ((ret = ctx2boolean(xctx)) < 0)
- goto done;
- if (xctx){
- ctx_free(xctx);
- xctx = NULL;
- }
- if (ret == 0)
- continue;
+ if (xpath_vec_ctx(xw, nsc, whenxpath, 0, &xctx) < 0)
+ goto done;
+ if ((ret = ctx2boolean(xctx)) < 0)
+ goto done;
+ if (xctx){
+ ctx_free(xctx);
+ xctx = NULL;
+ }
+ if (ret == 0)
+ continue;
}
/* Now switch on operation */
if (strcmp(op, "rename") == 0){
- ret = changelog_rename(h, xt, xw, nsc, tag);
+ ret = changelog_rename(h, xt, xw, nsc, tag);
}
else if (strcmp(op, "replace") == 0){
- ret = changelog_replace(h, xt, xw, xnew);
+ ret = changelog_replace(h, xt, xw, xnew);
}
else if (strcmp(op, "insert") == 0){
- ret = changelog_insert(h, xt, xw, xnew);
+ ret = changelog_insert(h, xt, xw, xnew);
}
else if (strcmp(op, "delete") == 0){
- ret = changelog_delete(h, xt, xw);
+ ret = changelog_delete(h, xt, xw);
}
else if (strcmp(op, "move") == 0){
- ret = changelog_move(h, xt, xw, nsc, dst);
+ ret = changelog_move(h, xt, xw, nsc, dst);
}
else{
- clicon_err(OE_XML, 0, "Unknown operation: %s", op);
- goto done;
+ clicon_err(OE_XML, 0, "Unknown operation: %s", op);
+ goto done;
}
if (ret < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto fail;
+ goto fail;
}
ok:
retval = 1;
done:
if (nsc)
- xml_nsctx_free(nsc);
+ xml_nsctx_free(nsc);
if (wvec)
- free(wvec);
+ free(wvec);
if (xctx)
- ctx_free(xctx);
+ ctx_free(xctx);
return retval;
fail:
retval = 0;
@@ -322,8 +322,8 @@ changelog_op(clicon_handle h,
*/
static int
changelog_iterate(clicon_handle h,
- cxobj *xt,
- cxobj *xch)
+ cxobj *xt,
+ cxobj *xch)
{
int retval = -1;
@@ -333,19 +333,19 @@ changelog_iterate(clicon_handle h,
int i;
if (xpath_vec(xch, NULL, "step", &vec, &veclen) < 0)
- goto done;
+ goto done;
/* Iterate through changelog items */
for (i=0; if) || tof) || to instead of :
- * Ie, no CX_BODY or CX_ELMNT child.
- */
- if (hasbody==0 && haselement==0)
- (*fn)(f, "/>");
- else{
- (*fn)(f, ">");
- if (pretty && hasbody == 0)
- (*fn)(f, "\n");
- xc = NULL;
- while ((xc = xml_child_each(x, xc, -1)) != NULL) {
- if (xml_type(xc) != CX_ATTR)
- if (xml2file_recurse(f, xc, level+1, pretty, fn, autocliext) <0)
- goto done;
- }
- if (pretty && hasbody==0)
- (*fn)(f, "%*s", level*XML_INDENT, "");
- (*fn)(f, "");
- if (namespace)
- (*fn)(f, "%s:", namespace);
- (*fn)(f, "%s>", name);
- }
- if (pretty)
- (*fn)(f, "\n");
- break;
+ (*fn)(f, "%*s<", pretty?(level*XML_INDENT):0, "");
+ if (namespace)
+ (*fn)(f, "%s:", namespace);
+ (*fn)(f, "%s", name);
+ hasbody = 0;
+ haselement = 0;
+ xc = NULL;
+ /* print attributes only */
+ while ((xc = xml_child_each(x, xc, -1)) != NULL) {
+ switch (xml_type(xc)){
+ case CX_ATTR:
+ if (xml2file_recurse(f, xc, level+1, pretty, fn, autocliext) <0)
+ goto done;
+ break;
+ case CX_BODY:
+ hasbody=1;
+ break;
+ case CX_ELMNT:
+ haselement=1;
+ break;
+ default:
+ break;
+ }
+ }
+ /* Check for special case instead of :
+ * Ie, no CX_BODY or CX_ELMNT child.
+ */
+ if (hasbody==0 && haselement==0)
+ (*fn)(f, "/>");
+ else{
+ (*fn)(f, ">");
+ if (pretty && hasbody == 0)
+ (*fn)(f, "\n");
+ xc = NULL;
+ while ((xc = xml_child_each(x, xc, -1)) != NULL) {
+ if (xml_type(xc) != CX_ATTR)
+ if (xml2file_recurse(f, xc, level+1, pretty, fn, autocliext) <0)
+ goto done;
+ }
+ if (pretty && hasbody==0)
+ (*fn)(f, "%*s", level*XML_INDENT, "");
+ (*fn)(f, "");
+ if (namespace)
+ (*fn)(f, "%s:", namespace);
+ (*fn)(f, "%s>", name);
+ }
+ if (pretty)
+ (*fn)(f, "\n");
+ break;
default:
- break;
+ break;
}/* switch */
ok:
retval = 0;
done:
if (encstr)
- free(encstr);
+ free(encstr);
return retval;
}
@@ -224,27 +224,27 @@ xml2file_recurse(FILE *f,
*/
int
clixon_xml2file(FILE *f,
- cxobj *xn,
- int level,
- int pretty,
- clicon_output_cb *fn,
- int skiptop,
- int autocliext)
+ cxobj *xn,
+ int level,
+ int pretty,
+ clicon_output_cb *fn,
+ int skiptop,
+ int autocliext)
{
int retval = 1;
cxobj *xc;
if (fn == NULL)
- fn = fprintf;
+ fn = fprintf;
if (skiptop){
- xc = NULL;
- while ((xc = xml_child_each(xn, xc, CX_ELMNT)) != NULL)
- if (xml2file_recurse(f, xc, level, pretty, fn, autocliext) < 0)
- goto done;
+ xc = NULL;
+ while ((xc = xml_child_each(xn, xc, CX_ELMNT)) != NULL)
+ if (xml2file_recurse(f, xc, level, pretty, fn, autocliext) < 0)
+ goto done;
}
else {
- if (xml2file_recurse(f, xn, level, pretty, fn, autocliext) < 0)
- goto done;
+ if (xml2file_recurse(f, xn, level, pretty, fn, autocliext) < 0)
+ goto done;
}
retval = 0;
done:
@@ -262,7 +262,7 @@ clixon_xml2file(FILE *f,
*/
int
xml_print(FILE *f,
- cxobj *x)
+ cxobj *x)
{
return xml2file_recurse(f, x, 0, 1, fprintf, 0);
}
@@ -271,34 +271,34 @@ xml_print(FILE *f,
*/
static int
xml_dump1(FILE *f,
- cxobj *x,
- int indent)
+ cxobj *x,
+ int indent)
{
cxobj *xc;
if (xml_type(x) != CX_ELMNT)
- return 0;
+ return 0;
fprintf(stderr, "%*s %s(%s)",
- indent*3, "",
- // x,
- xml_name(x),
- xml_type2str(xml_type(x)));
+ indent*3, "",
+ // x,
+ xml_name(x),
+ xml_type2str(xml_type(x)));
if (xml_flag(x, XML_FLAG_ADD))
- fprintf(stderr, " add");
+ fprintf(stderr, " add");
if (xml_flag(x, XML_FLAG_DEL))
- fprintf(stderr, " delete");
+ fprintf(stderr, " delete");
if (xml_flag(x, XML_FLAG_CHANGE))
- fprintf(stderr, " change");
+ fprintf(stderr, " change");
if (xml_flag(x, XML_FLAG_MARK))
- fprintf(stderr, " mark");
+ fprintf(stderr, " mark");
fprintf(stderr, "\n");
xc = NULL;
while ((xc = xml_child_each(x, xc, -1)) != NULL) {
- xml_dump1(f, xc, indent+1);
+ xml_dump1(f, xc, indent+1);
}
return 0;
}
-
+
/*! Dump cxobj structure with pointers and flags for debugging
*
* @param[in] f UNIX output stream
@@ -307,7 +307,7 @@ xml_dump1(FILE *f,
*/
int
xml_dump(FILE *f,
- cxobj *x)
+ cxobj *x)
{
return xml_dump1(f, x, 0);
}
@@ -322,10 +322,10 @@ xml_dump(FILE *f,
*/
static int
clixon_xml2cbuf1(cbuf *cb,
- cxobj *x,
- int level,
- int pretty,
- int32_t depth)
+ cxobj *x,
+ int level,
+ int pretty,
+ int32_t depth)
{
int retval = -1;
cxobj *xc;
@@ -336,80 +336,80 @@ clixon_xml2cbuf1(cbuf *cb,
char *val;
if (depth == 0)
- goto ok;
+ goto ok;
name = xml_name(x);
namespace = xml_prefix(x);
switch(xml_type(x)){
case CX_BODY:
- if ((val = xml_value(x)) == NULL) /* incomplete tree */
- break;
- if (xml_chardata_cbuf_append(cb, val) < 0)
- goto done;
- break;
+ if ((val = xml_value(x)) == NULL) /* incomplete tree */
+ break;
+ if (xml_chardata_cbuf_append(cb, val) < 0)
+ goto done;
+ break;
case CX_ATTR:
- cbuf_append_str(cb, " ");
- if (namespace){
- cbuf_append_str(cb, namespace);
- cbuf_append_str(cb, ":");
- }
- cprintf(cb, "%s=\"%s\"", name, xml_value(x));
- break;
+ cbuf_append_str(cb, " ");
+ if (namespace){
+ cbuf_append_str(cb, namespace);
+ cbuf_append_str(cb, ":");
+ }
+ cprintf(cb, "%s=\"%s\"", name, xml_value(x));
+ break;
case CX_ELMNT:
- if (pretty)
- cprintf(cb, "%*s<", level*XML_INDENT, "");
- else
- cbuf_append_str(cb, "<");
- if (namespace){
- cbuf_append_str(cb, namespace);
- cbuf_append_str(cb, ":");
- }
- cbuf_append_str(cb, name);
- hasbody = 0;
- haselement = 0;
- xc = NULL;
- /* print attributes only */
- while ((xc = xml_child_each(x, xc, -1)) != NULL)
- switch (xml_type(xc)){
- case CX_ATTR:
- if (clixon_xml2cbuf1(cb, xc, level+1, pretty, -1) < 0)
- goto done;
- break;
- case CX_BODY:
- hasbody=1;
- break;
- case CX_ELMNT:
- haselement=1;
- break;
- default:
- break;
- }
- /* Check for special case instead of */
- if (hasbody==0 && haselement==0)
- cbuf_append_str(cb, "/>");
- else{
- cbuf_append_str(cb, ">");
- if (pretty && hasbody == 0)
- cbuf_append_str(cb, "\n");
- xc = NULL;
- while ((xc = xml_child_each(x, xc, -1)) != NULL)
- if (xml_type(xc) != CX_ATTR)
- if (clixon_xml2cbuf1(cb, xc, level+1, pretty, depth-1) < 0)
- goto done;
- if (pretty && hasbody == 0)
- cprintf(cb, "%*s", level*XML_INDENT, "");
- cbuf_append_str(cb, "");
- if (namespace){
- cbuf_append_str(cb, namespace);
- cbuf_append_str(cb, ":");
- }
- cbuf_append_str(cb, name);
- cbuf_append_str(cb, ">");
- }
- if (pretty)
- cbuf_append_str(cb, "\n");
- break;
+ if (pretty)
+ cprintf(cb, "%*s<", level*XML_INDENT, "");
+ else
+ cbuf_append_str(cb, "<");
+ if (namespace){
+ cbuf_append_str(cb, namespace);
+ cbuf_append_str(cb, ":");
+ }
+ cbuf_append_str(cb, name);
+ hasbody = 0;
+ haselement = 0;
+ xc = NULL;
+ /* print attributes only */
+ while ((xc = xml_child_each(x, xc, -1)) != NULL)
+ switch (xml_type(xc)){
+ case CX_ATTR:
+ if (clixon_xml2cbuf1(cb, xc, level+1, pretty, -1) < 0)
+ goto done;
+ break;
+ case CX_BODY:
+ hasbody=1;
+ break;
+ case CX_ELMNT:
+ haselement=1;
+ break;
+ default:
+ break;
+ }
+ /* Check for special case instead of */
+ if (hasbody==0 && haselement==0)
+ cbuf_append_str(cb, "/>");
+ else{
+ cbuf_append_str(cb, ">");
+ if (pretty && hasbody == 0)
+ cbuf_append_str(cb, "\n");
+ xc = NULL;
+ while ((xc = xml_child_each(x, xc, -1)) != NULL)
+ if (xml_type(xc) != CX_ATTR)
+ if (clixon_xml2cbuf1(cb, xc, level+1, pretty, depth-1) < 0)
+ goto done;
+ if (pretty && hasbody == 0)
+ cprintf(cb, "%*s", level*XML_INDENT, "");
+ cbuf_append_str(cb, "");
+ if (namespace){
+ cbuf_append_str(cb, namespace);
+ cbuf_append_str(cb, ":");
+ }
+ cbuf_append_str(cb, name);
+ cbuf_append_str(cb, ">");
+ }
+ if (pretty)
+ cbuf_append_str(cb, "\n");
+ break;
default:
- break;
+ break;
}/* switch */
ok:
retval = 0;
@@ -439,24 +439,24 @@ clixon_xml2cbuf1(cbuf *cb,
*/
int
clixon_xml2cbuf(cbuf *cb,
- cxobj *xn,
- int level,
- int pretty,
- int32_t depth,
- int skiptop)
+ cxobj *xn,
+ int level,
+ int pretty,
+ int32_t depth,
+ int skiptop)
{
int retval = -1;
cxobj *xc;
if (skiptop){
- xc = NULL;
- while ((xc = xml_child_each(xn, xc, CX_ELMNT)) != NULL)
- if (clixon_xml2cbuf1(cb, xc, level, pretty, depth) < 0)
- goto done;
+ xc = NULL;
+ while ((xc = xml_child_each(xn, xc, CX_ELMNT)) != NULL)
+ if (clixon_xml2cbuf1(cb, xc, level, pretty, depth) < 0)
+ goto done;
}
else {
- if (clixon_xml2cbuf1(cb, xn, level, pretty, depth) < 0)
- goto done;
+ if (clixon_xml2cbuf1(cb, xn, level, pretty, depth) < 0)
+ goto done;
}
retval = 0;
done:
@@ -470,34 +470,34 @@ clixon_xml2cbuf(cbuf *cb,
*/
int
xmltree2cbuf(cbuf *cb,
- cxobj *x,
- int level)
+ cxobj *x,
+ int level)
{
cxobj *xc;
int i;
for (i=0; i <-- populate from parent
- */
- if ((ret = xml_bind_yang0(x, YB_PARENT, NULL, xerr)) < 0)
- goto done;
- if (ret == 0)
- failed++;
- break;
+ x = xy.xy_xvec[i];
+ /* Verify namespaces after parsing */
+ if (xml2ns_recurse(x) < 0)
+ goto done;
+ /* Populate, ie associate xml nodes with yang specs
+ */
+ switch (yb){
+ case YB_NONE:
+ break;
+ case YB_PARENT:
+ /* xt:n Has spec
+ * x: <-- populate from parent
+ */
+ if ((ret = xml_bind_yang0(x, YB_PARENT, NULL, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ failed++;
+ break;
- case YB_MODULE_NEXT:
- if ((ret = xml_bind_yang(x, YB_MODULE, yspec, xerr)) < 0)
- goto done;
- if (ret == 0)
- failed++;
- break;
- case YB_MODULE:
- /* xt: nospec
- * x: <-- populate from modules
- */
- if ((ret = xml_bind_yang0(x, YB_MODULE, yspec, xerr)) < 0)
- goto done;
- if (ret == 0)
- failed++;
- break;
- case YB_RPC:
- if ((ret = xml_bind_yang_rpc(x, yspec, xerr)) < 0)
- goto done;
- if (ret == 0){ /* Add message-id */
- if (*xerr && clixon_xml_attr_copy(x, *xerr, "message-id") < 0)
- goto done;
- failed++;
- }
- break;
- } /* switch */
+ case YB_MODULE_NEXT:
+ if ((ret = xml_bind_yang(x, YB_MODULE, yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ failed++;
+ break;
+ case YB_MODULE:
+ /* xt: nospec
+ * x: <-- populate from modules
+ */
+ if ((ret = xml_bind_yang0(x, YB_MODULE, yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ failed++;
+ break;
+ case YB_RPC:
+ if ((ret = xml_bind_yang_rpc(x, yspec, xerr)) < 0)
+ goto done;
+ if (ret == 0){ /* Add message-id */
+ if (*xerr && clixon_xml_attr_copy(x, *xerr, "message-id") < 0)
+ goto done;
+ failed++;
+ }
+ break;
+ } /* switch */
}
if (failed)
- goto fail;
+ goto fail;
/* Sort the complete tree after parsing. Sorting is not really meaningful if Yang
not bound */
if (yb != YB_NONE)
- if (xml_sort_recurse(xt) < 0)
- goto done;
+ if (xml_sort_recurse(xt) < 0)
+ goto done;
retval = 1;
done:
clixon_xml_parsel_exit(&xy);
if (xy.xy_parse_string != NULL)
- free(xy.xy_parse_string);
+ free(xy.xy_parse_string);
if (xy.xy_xvec)
- free(xy.xy_xvec);
+ free(xy.xy_xvec);
return retval;
fail: /* invalid */
retval = 0;
@@ -662,10 +662,10 @@ _xml_parse(const char *str,
*/
int
clixon_xml_parse_file(FILE *fp,
- yang_bind yb,
- yang_stmt *yspec,
- cxobj **xt,
- cxobj **xerr)
+ yang_bind yb,
+ yang_stmt *yspec,
+ cxobj **xt,
+ cxobj **xerr)
{
int retval = -1;
int ret;
@@ -678,56 +678,56 @@ clixon_xml_parse_file(FILE *fp,
int failed = 0;
if (xt==NULL || fp == NULL){
- clicon_err(OE_XML, EINVAL, "arg is NULL");
- return -1;
+ clicon_err(OE_XML, EINVAL, "arg is NULL");
+ return -1;
}
if (yb == YB_MODULE && yspec == NULL){
- clicon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE");
- return -1;
+ clicon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE");
+ return -1;
}
if ((xmlbuf = malloc(xmlbuflen)) == NULL){
- clicon_err(OE_XML, errno, "malloc");
- goto done;
+ clicon_err(OE_XML, errno, "malloc");
+ goto done;
}
memset(xmlbuf, 0, xmlbuflen);
ptr = xmlbuf;
while (1){
- if ((ret = fread(&ch, 1, 1, fp)) < 0){
- clicon_err(OE_XML, errno, "read");
- break;
- }
- if (ret != 0){
- xmlbuf[len++] = ch;
- }
- if (ret == 0) {
- if (*xt == NULL)
- if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
- goto done;
- if ((ret = _xml_parse(ptr, yb, yspec, *xt, xerr)) < 0)
- goto done;
- if (ret == 0)
- failed++;
- break;
- }
- if (len >= xmlbuflen-1){ /* Space: one for the null character */
- oldxmlbuflen = xmlbuflen;
- xmlbuflen *= 2;
- if ((xmlbuf = realloc(xmlbuf, xmlbuflen)) == NULL){
- clicon_err(OE_XML, errno, "realloc");
- goto done;
- }
- memset(xmlbuf+oldxmlbuflen, 0, xmlbuflen-oldxmlbuflen);
- ptr = xmlbuf;
- }
+ if ((ret = fread(&ch, 1, 1, fp)) < 0){
+ clicon_err(OE_XML, errno, "read");
+ break;
+ }
+ if (ret != 0){
+ xmlbuf[len++] = ch;
+ }
+ if (ret == 0) {
+ if (*xt == NULL)
+ if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
+ goto done;
+ if ((ret = _xml_parse(ptr, yb, yspec, *xt, xerr)) < 0)
+ goto done;
+ if (ret == 0)
+ failed++;
+ break;
+ }
+ if (len >= xmlbuflen-1){ /* Space: one for the null character */
+ oldxmlbuflen = xmlbuflen;
+ xmlbuflen *= 2;
+ if ((xmlbuf = realloc(xmlbuf, xmlbuflen)) == NULL){
+ clicon_err(OE_XML, errno, "realloc");
+ goto done;
+ }
+ memset(xmlbuf+oldxmlbuflen, 0, xmlbuflen-oldxmlbuflen);
+ ptr = xmlbuf;
+ }
} /* while */
retval = (failed==0) ? 1 : 0;
done:
if (retval < 0 && *xt){
- free(*xt);
- *xt = NULL;
+ free(*xt);
+ *xt = NULL;
}
if (xmlbuf)
- free(xmlbuf);
+ free(xmlbuf);
return retval;
}
@@ -757,22 +757,22 @@ clixon_xml_parse_file(FILE *fp,
*/
int
clixon_xml_parse_string(const char *str,
- yang_bind yb,
- yang_stmt *yspec,
- cxobj **xt,
- cxobj **xerr)
+ yang_bind yb,
+ yang_stmt *yspec,
+ cxobj **xt,
+ cxobj **xerr)
{
if (xt==NULL){
- clicon_err(OE_XML, EINVAL, "xt is NULL");
- return -1;
+ clicon_err(OE_XML, EINVAL, "xt is NULL");
+ return -1;
}
if (yb == YB_MODULE && yspec == NULL){
- clicon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE");
- return -1;
+ clicon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE");
+ return -1;
}
if (*xt == NULL){
- if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
- return -1;
+ if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
+ return -1;
}
return _xml_parse(str, yb, yspec, *xt, xerr);
}
@@ -803,10 +803,10 @@ clixon_xml_parse_string(const char *str,
*/
int
clixon_xml_parse_va(yang_bind yb,
- yang_stmt *yspec,
- cxobj **xtop,
- cxobj **xerr,
- const char *format, ...)
+ yang_stmt *yspec,
+ cxobj **xtop,
+ cxobj **xerr,
+ const char *format, ...)
{
int retval = -1;
va_list args;
@@ -817,8 +817,8 @@ clixon_xml_parse_va(yang_bind yb,
len = vsnprintf(NULL, 0, format, args) + 1;
va_end(args);
if ((str = malloc(len)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(str, 0, len);
va_start(args, format);
@@ -827,7 +827,7 @@ clixon_xml_parse_va(yang_bind yb,
retval = clixon_xml_parse_string(str, yb, yspec, xtop, xerr);
done:
if (str)
- free(str);
+ free(str);
return retval;
}
@@ -845,22 +845,22 @@ clixon_xml_parse_va(yang_bind yb,
*/
int
clixon_xml_attr_copy(cxobj *xin,
- cxobj *xout,
- char *name)
+ cxobj *xout,
+ char *name)
{
int retval = -1;
char *msgid;
cxobj *xa;
if (xin == NULL || xout == NULL){
- clicon_err(OE_XML, EINVAL, "xin or xout NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "xin or xout NULL");
+ goto done;
}
if ((msgid = xml_find_value(xin, name)) != NULL){
- if ((xa = xml_new(name, xout, CX_ATTR)) == NULL)
- goto done;
- if (xml_value_set(xa, msgid) < 0)
- goto done;
+ if ((xa = xml_new(name, xout, CX_ATTR)) == NULL)
+ goto done;
+ if (xml_value_set(xa, msgid) < 0)
+ goto done;
}
retval = 0;
done:
diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c
index 729df365..e9e903f8 100644
--- a/lib/src/clixon_xml_map.c
+++ b/lib/src/clixon_xml_map.c
@@ -98,12 +98,12 @@ isxmlns(cxobj *x)
char *prefix = NULL;
if (xml_type(x) != CX_ATTR)
- return 0;
+ return 0;
if (strcmp(xml_name(x), "xmlns")==0)
- return 1;
+ return 1;
if ((prefix = xml_prefix(x)) != NULL
- && strcmp(xml_prefix(x), "xmlns")==0)
- return 1;
+ && strcmp(xml_prefix(x), "xmlns")==0)
+ return 1;
return 0;
}
@@ -131,8 +131,8 @@ isxmlns(cxobj *x)
*/
int
xml2cvec(cxobj *xt,
- yang_stmt *yt,
- cvec **cvv0)
+ yang_stmt *yt,
+ cvec **cvv0)
{
int retval = -1;
cvec *cvv = NULL;
@@ -148,71 +148,71 @@ xml2cvec(cxobj *xt,
xc = NULL;
/* Tried to allocate whole cvv here, but some cg_vars may be invalid */
if ((cvv = cvec_new(0)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_new");
- goto err;
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ goto err;
}
xc = NULL;
/* Go through all children of the xml tree */
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL){
- name = xml_name(xc);
- if ((ys = yang_find_datanode(yt, name)) == NULL){
- clicon_debug(0, "%s: yang sanity problem: %s in xml but not present in yang under %s",
- __FUNCTION__, name, yang_argument_get(yt));
- if ((body = xml_body(xc)) != NULL){
- if ((cv = cv_new(CGV_STRING)) == NULL){
- clicon_err(OE_PLUGIN, errno, "cv_new");
- goto err;
- }
- cv_name_set(cv, name);
- if ((ret = cv_parse1(body, cv, &reason)) < 0){
- clicon_err(OE_PLUGIN, errno, "cv_parse %s",name);
- goto err;
- }
- /* If value is out-of-range, log and skip value, and continue */
- if (ret == 0){
- clicon_log(LOG_WARNING, "cv_parse %s: %s", name, reason);
- if (reason)
- free(reason);
- }
- else
- cvec_append_var(cvv, cv); /* Add to variable vector */
- cv_free(cv);
- }
- }
- else if ((ycv = yang_cv_get(ys)) != NULL){
- if ((body = xml_body(xc)) != NULL){
- if ((cv = cv_new(CGV_STRING)) == NULL){
- clicon_err(OE_PLUGIN, errno, "cv_new");
- goto err;
- }
- if (cv_cp(cv, ycv) < 0){
- clicon_err(OE_PLUGIN, errno, "cv_cp");
- goto err;
- }
- if ((ret = cv_parse1(body, cv, &reason)) < 0){
- clicon_err(OE_PLUGIN, errno, "cv_parse: %s", name);
- goto err;
- }
- if (ret == 0){
- clicon_log(LOG_WARNING, "cv_parse %s: %s", name, reason);
- if (reason)
- free(reason);
- }
- else
- cvec_append_var(cvv, cv); /* Add to variable vector */
- cv_free(cv);
- }
- }
+ name = xml_name(xc);
+ if ((ys = yang_find_datanode(yt, name)) == NULL){
+ clicon_debug(0, "%s: yang sanity problem: %s in xml but not present in yang under %s",
+ __FUNCTION__, name, yang_argument_get(yt));
+ if ((body = xml_body(xc)) != NULL){
+ if ((cv = cv_new(CGV_STRING)) == NULL){
+ clicon_err(OE_PLUGIN, errno, "cv_new");
+ goto err;
+ }
+ cv_name_set(cv, name);
+ if ((ret = cv_parse1(body, cv, &reason)) < 0){
+ clicon_err(OE_PLUGIN, errno, "cv_parse %s",name);
+ goto err;
+ }
+ /* If value is out-of-range, log and skip value, and continue */
+ if (ret == 0){
+ clicon_log(LOG_WARNING, "cv_parse %s: %s", name, reason);
+ if (reason)
+ free(reason);
+ }
+ else
+ cvec_append_var(cvv, cv); /* Add to variable vector */
+ cv_free(cv);
+ }
+ }
+ else if ((ycv = yang_cv_get(ys)) != NULL){
+ if ((body = xml_body(xc)) != NULL){
+ if ((cv = cv_new(CGV_STRING)) == NULL){
+ clicon_err(OE_PLUGIN, errno, "cv_new");
+ goto err;
+ }
+ if (cv_cp(cv, ycv) < 0){
+ clicon_err(OE_PLUGIN, errno, "cv_cp");
+ goto err;
+ }
+ if ((ret = cv_parse1(body, cv, &reason)) < 0){
+ clicon_err(OE_PLUGIN, errno, "cv_parse: %s", name);
+ goto err;
+ }
+ if (ret == 0){
+ clicon_log(LOG_WARNING, "cv_parse %s: %s", name, reason);
+ if (reason)
+ free(reason);
+ }
+ else
+ cvec_append_var(cvv, cv); /* Add to variable vector */
+ cv_free(cv);
+ }
+ }
}
if (clicon_debug_get() > 1){
- clicon_debug(2, "%s cvv:\n", __FUNCTION__);
- cvec_print(stderr, cvv);
+ clicon_debug(2, "%s cvv:\n", __FUNCTION__);
+ cvec_print(stderr, cvv);
}
*cvv0 = cvv;
return 0;
err:
if (cvv)
- cvec_free(cvv);
+ cvec_free(cvv);
return retval;
}
@@ -228,9 +228,9 @@ xml2cvec(cxobj *xt,
*/
int
cvec2xml_1(cvec *cvv,
- char *toptag,
- cxobj *xp,
- cxobj **xt0)
+ char *toptag,
+ cxobj *xp,
+ cxobj **xt0)
{
int retval = -1;
cxobj *xt = NULL;
@@ -243,32 +243,32 @@ cvec2xml_1(cvec *cvv,
cv = NULL;
while ((cv = cvec_each(cvv, cv)) != NULL)
- len++;
+ len++;
if ((xt = xml_new(toptag, xp, CX_ELMNT)) == NULL)
- goto err;
+ goto err;
if (xml_childvec_set(xt, len) < 0)
- goto err;
+ goto err;
cv = NULL;
i = 0;
while ((cv = cvec_each(cvv, cv)) != NULL) {
- if (cv_type_get(cv)==CGV_ERR || cv_name_get(cv) == NULL)
- continue;
- if ((xn = xml_new(cv_name_get(cv), NULL, CX_ELMNT)) == NULL) /* this leaks */
- goto err;
- xml_parent_set(xn, xt);
- xml_child_i_set(xt, i++, xn);
- if ((xb = xml_new("body", xn, CX_BODY)) == NULL) /* this leaks */
- goto err;
- val = cv2str_dup(cv);
- xml_value_set(xb, val); /* this leaks */
- if (val)
- free(val);
+ if (cv_type_get(cv)==CGV_ERR || cv_name_get(cv) == NULL)
+ continue;
+ if ((xn = xml_new(cv_name_get(cv), NULL, CX_ELMNT)) == NULL) /* this leaks */
+ goto err;
+ xml_parent_set(xn, xt);
+ xml_child_i_set(xt, i++, xn);
+ if ((xb = xml_new("body", xn, CX_BODY)) == NULL) /* this leaks */
+ goto err;
+ val = cv2str_dup(cv);
+ xml_value_set(xb, val); /* this leaks */
+ if (val)
+ free(val);
}
*xt0 = xt;
return 0;
err:
if (xt)
- xml_free(xt);
+ xml_free(xt);
return retval;
}
@@ -298,14 +298,14 @@ cvec2xml_1(cvec *cvv,
*/
static int
xml_diff1(cxobj *x0,
- cxobj *x1,
- cxobj ***x0vec,
- int *x0veclen,
- cxobj ***x1vec,
- int *x1veclen,
- cxobj ***changed_x0,
- cxobj ***changed_x1,
- int *changedlen)
+ cxobj *x1,
+ cxobj ***x0vec,
+ int *x0veclen,
+ cxobj ***x1vec,
+ int *x1veclen,
+ cxobj ***changed_x0,
+ cxobj ***changed_x1,
+ int *changedlen)
{
int retval = -1;
cxobj *x0c = NULL; /* x0 child */
@@ -321,71 +321,71 @@ xml_diff1(cxobj *x0,
x0c = xml_child_each(x0, x0c, CX_ELMNT);
x1c = xml_child_each(x1, x1c, CX_ELMNT);
for (;;){
- if (x0c == NULL && x1c == NULL)
- goto ok;
- else if (x0c == NULL){
- if (cxvec_append(x1c, x1vec, x1veclen) < 0)
- goto done;
- x1c = xml_child_each(x1, x1c, CX_ELMNT);
- continue;
- }
- else if (x1c == NULL){
- if (cxvec_append(x0c, x0vec, x0veclen) < 0)
- goto done;
- x0c = xml_child_each(x0, x0c, CX_ELMNT);
- continue;
- }
- /* Both x0c and x1c exists, check if they are yang-equal. */
- eq = xml_cmp(x0c, x1c, 0, 0, NULL);
- if (eq < 0){
- if (cxvec_append(x0c, x0vec, x0veclen) < 0)
- goto done;
- x0c = xml_child_each(x0, x0c, CX_ELMNT);
- continue;
- }
- else if (eq > 0){
- if (cxvec_append(x1c, x1vec, x1veclen) < 0)
- goto done;
- x1c = xml_child_each(x1, x1c, CX_ELMNT);
- continue;
- }
- else{ /* equal */
- /* xml-spec NULL could happen with anydata children for example,
- * if so, continute compare children but without yang
- */
- yc0 = xml_spec(x0c);
- yc1 = xml_spec(x1c);
- if (yc0 && yc1 && yc0 != yc1){ /* choice */
- if (cxvec_append(x0c, x0vec, x0veclen) < 0)
- goto done;
- if (cxvec_append(x1c, x1vec, x1veclen) < 0)
- goto done;
- }
- else
- if (yc0 && yang_keyword_get(yc0) == Y_LEAF){
- /* if x0c and x1c are leafs w bodies, then they may be changed */
- b1 = xml_body(x0c);
- b2 = xml_body(x1c);
- if (b1 == NULL && b2 == NULL)
- ;
- else if (b1 == NULL || b2 == NULL
- || strcmp(b1, b2) != 0
- ){
- if (cxvec_append(x0c, changed_x0, changedlen) < 0)
- goto done;
- (*changedlen)--; /* append two vectors */
- if (cxvec_append(x1c, changed_x1, changedlen) < 0)
- goto done;
- }
- }
- else if (xml_diff1(x0c, x1c,
- x0vec, x0veclen,
- x1vec, x1veclen,
- changed_x0, changed_x1, changedlen)< 0)
- goto done;
- }
- x0c = xml_child_each(x0, x0c, CX_ELMNT);
- x1c = xml_child_each(x1, x1c, CX_ELMNT);
+ if (x0c == NULL && x1c == NULL)
+ goto ok;
+ else if (x0c == NULL){
+ if (cxvec_append(x1c, x1vec, x1veclen) < 0)
+ goto done;
+ x1c = xml_child_each(x1, x1c, CX_ELMNT);
+ continue;
+ }
+ else if (x1c == NULL){
+ if (cxvec_append(x0c, x0vec, x0veclen) < 0)
+ goto done;
+ x0c = xml_child_each(x0, x0c, CX_ELMNT);
+ continue;
+ }
+ /* Both x0c and x1c exists, check if they are yang-equal. */
+ eq = xml_cmp(x0c, x1c, 0, 0, NULL);
+ if (eq < 0){
+ if (cxvec_append(x0c, x0vec, x0veclen) < 0)
+ goto done;
+ x0c = xml_child_each(x0, x0c, CX_ELMNT);
+ continue;
+ }
+ else if (eq > 0){
+ if (cxvec_append(x1c, x1vec, x1veclen) < 0)
+ goto done;
+ x1c = xml_child_each(x1, x1c, CX_ELMNT);
+ continue;
+ }
+ else{ /* equal */
+ /* xml-spec NULL could happen with anydata children for example,
+ * if so, continute compare children but without yang
+ */
+ yc0 = xml_spec(x0c);
+ yc1 = xml_spec(x1c);
+ if (yc0 && yc1 && yc0 != yc1){ /* choice */
+ if (cxvec_append(x0c, x0vec, x0veclen) < 0)
+ goto done;
+ if (cxvec_append(x1c, x1vec, x1veclen) < 0)
+ goto done;
+ }
+ else
+ if (yc0 && yang_keyword_get(yc0) == Y_LEAF){
+ /* if x0c and x1c are leafs w bodies, then they may be changed */
+ b1 = xml_body(x0c);
+ b2 = xml_body(x1c);
+ if (b1 == NULL && b2 == NULL)
+ ;
+ else if (b1 == NULL || b2 == NULL
+ || strcmp(b1, b2) != 0
+ ){
+ if (cxvec_append(x0c, changed_x0, changedlen) < 0)
+ goto done;
+ (*changedlen)--; /* append two vectors */
+ if (cxvec_append(x1c, changed_x1, changedlen) < 0)
+ goto done;
+ }
+ }
+ else if (xml_diff1(x0c, x1c,
+ x0vec, x0veclen,
+ x1vec, x1veclen,
+ changed_x0, changed_x1, changedlen)< 0)
+ goto done;
+ }
+ x0c = xml_child_each(x0, x0c, CX_ELMNT);
+ x1c = xml_child_each(x1, x1c, CX_ELMNT);
}
ok:
retval = 0;
@@ -408,15 +408,15 @@ xml_diff1(cxobj *x0,
*/
int
xml_diff(yang_stmt *yspec,
- cxobj *x0,
- cxobj *x1,
- cxobj ***first,
- int *firstlen,
- cxobj ***second,
- int *secondlen,
- cxobj ***changed_x0,
- cxobj ***changed_x1,
- int *changedlen)
+ cxobj *x0,
+ cxobj *x1,
+ cxobj ***first,
+ int *firstlen,
+ cxobj ***second,
+ int *secondlen,
+ cxobj ***changed_x0,
+ cxobj ***changed_x1,
+ int *changedlen)
{
int retval = -1;
@@ -424,22 +424,22 @@ xml_diff(yang_stmt *yspec,
*secondlen = 0;
*changedlen = 0;
if (x0 == NULL && x1 == NULL)
- return 0;
+ return 0;
if (x1 == NULL){
- if (cxvec_append(x0, first, firstlen) < 0)
- goto done;
- goto ok;
+ if (cxvec_append(x0, first, firstlen) < 0)
+ goto done;
+ goto ok;
}
if (x0 == NULL){
- if (cxvec_append(x0, second, secondlen) < 0)
- goto done;
- goto ok;
+ if (cxvec_append(x0, second, secondlen) < 0)
+ goto done;
+ goto ok;
}
if (xml_diff1(x0, x1,
- first, firstlen,
- second, secondlen,
- changed_x0, changed_x1, changedlen) < 0)
- goto done;
+ first, firstlen,
+ second, secondlen,
+ changed_x0, changed_x1, changedlen) < 0)
+ goto done;
ok:
retval = 0;
done:
@@ -463,9 +463,9 @@ xml_diff(yang_stmt *yspec,
*/
int
xml_tree_prune_flagged_sub(cxobj *xt,
- int flag,
- int test,
- int *upmark)
+ int flag,
+ int test,
+ int *upmark)
{
int retval = -1;
int submark;
@@ -481,55 +481,55 @@ xml_tree_prune_flagged_sub(cxobj *xt,
x = NULL;
xprev = x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- if (xml_flag(x, flag) == test?flag:0){
- /* Pass test */
- mark++;
- xprev = x;
- continue; /* mark and stop here */
- }
- /* If it is key dont remove it yet (see second round) */
- if (yt){
- if ((iskey = yang_key_match(yt, xml_name(x), NULL)) < 0)
- goto done;
- if (iskey){
- anykey++;
- xprev = x; /* skip if this is key */
- continue;
- }
- }
- if (xml_tree_prune_flagged_sub(x, flag, test, &submark) < 0)
- goto done;
- /* if xt is list and submark anywhere, then key subs are also marked
- */
- if (submark)
- mark++;
- else{ /* Safe with xml_child_each if last */
- if (xml_purge(x) < 0)
- goto done;
- x = xprev;
- }
- xprev = x;
+ if (xml_flag(x, flag) == test?flag:0){
+ /* Pass test */
+ mark++;
+ xprev = x;
+ continue; /* mark and stop here */
+ }
+ /* If it is key dont remove it yet (see second round) */
+ if (yt){
+ if ((iskey = yang_key_match(yt, xml_name(x), NULL)) < 0)
+ goto done;
+ if (iskey){
+ anykey++;
+ xprev = x; /* skip if this is key */
+ continue;
+ }
+ }
+ if (xml_tree_prune_flagged_sub(x, flag, test, &submark) < 0)
+ goto done;
+ /* if xt is list and submark anywhere, then key subs are also marked
+ */
+ if (submark)
+ mark++;
+ else{ /* Safe with xml_child_each if last */
+ if (xml_purge(x) < 0)
+ goto done;
+ x = xprev;
+ }
+ xprev = x;
}
/* Second round: if any keys were found, and no marks detected, purge now */
if (anykey && !mark){
- x = NULL;
- xprev = x = NULL;
- while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- /* If it is key remove it here */
- if (yt){
- if ((iskey = yang_key_match(yt, xml_name(x), NULL)) < 0)
- goto done;
- if (iskey && xml_purge(x) < 0)
- goto done;
- x = xprev;
- }
- xprev = x;
- }
+ x = NULL;
+ xprev = x = NULL;
+ while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
+ /* If it is key remove it here */
+ if (yt){
+ if ((iskey = yang_key_match(yt, xml_name(x), NULL)) < 0)
+ goto done;
+ if (iskey && xml_purge(x) < 0)
+ goto done;
+ x = xprev;
+ }
+ xprev = x;
+ }
}
retval = 0;
done:
if (upmark)
- *upmark = mark;
+ *upmark = mark;
return retval;
}
@@ -544,8 +544,8 @@ xml_tree_prune_flagged_sub(cxobj *xt,
*/
int
xml_tree_prune_flagged(cxobj *xt,
- int flag,
- int test)
+ int flag,
+ int test)
{
int retval = -1;
cxobj *x;
@@ -554,15 +554,15 @@ xml_tree_prune_flagged(cxobj *xt,
x = NULL;
xprev = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- if (xml_flag(x, flag) == (test?flag:0)){ /* Pass test means purge */
- if (xml_purge(x) < 0)
- goto done;
- x = xprev;
- continue;
- }
- if (xml_tree_prune_flagged(x, flag, test) < 0)
- goto done;
- xprev = x;
+ if (xml_flag(x, flag) == (test?flag:0)){ /* Pass test means purge */
+ if (xml_purge(x) < 0)
+ goto done;
+ x = xprev;
+ continue;
+ }
+ if (xml_tree_prune_flagged(x, flag, test) < 0)
+ goto done;
+ xprev = x;
}
retval = 0;
done:
@@ -580,8 +580,8 @@ xml_tree_prune_flagged(cxobj *xt,
*/
int
xml_tree_prune_flags(cxobj *xt,
- int flags,
- int mask)
+ int flags,
+ int mask)
{
int retval = -1;
cxobj *x;
@@ -590,15 +590,15 @@ xml_tree_prune_flags(cxobj *xt,
x = NULL;
xprev = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- if (xml_flag(x, mask) == flags){ /* Pass test means purge */
- if (xml_purge(x) < 0)
- goto done;
- x = xprev;
- continue;
- }
- if (xml_tree_prune_flags(x, flags, mask) < 0)
- goto done;
- xprev = x;
+ if (xml_flag(x, mask) == flags){ /* Pass test means purge */
+ if (xml_purge(x) < 0)
+ goto done;
+ x = xprev;
+ continue;
+ }
+ if (xml_tree_prune_flags(x, flags, mask) < 0)
+ goto done;
+ xprev = x;
}
retval = 0;
done:
@@ -614,9 +614,9 @@ xml_tree_prune_flags(cxobj *xt,
*/
static int
add_namespace(cxobj *x,
- cxobj *xp,
- char *prefix,
- char *namespace)
+ cxobj *xp,
+ char *prefix,
+ char *namespace)
{
int retval = -1;
cxobj *xa = NULL;
@@ -625,20 +625,20 @@ add_namespace(cxobj *x,
* end up in adding it to large number of siblings
*/
if (nscache_set(x, prefix, namespace) < 0)
- goto done;
+ goto done;
/* Create xmlns attribute to x1p/x1 XXX same code v */
if (prefix){
- if ((xa = xml_new(prefix, xp, CX_ATTR)) == NULL)
- goto done;
- if (xml_prefix_set(xa, "xmlns") < 0)
- goto done;
+ if ((xa = xml_new(prefix, xp, CX_ATTR)) == NULL)
+ goto done;
+ if (xml_prefix_set(xa, "xmlns") < 0)
+ goto done;
}
else{
- if ((xa = xml_new("xmlns", xp, CX_ATTR)) == NULL)
- goto done;
+ if ((xa = xml_new("xmlns", xp, CX_ATTR)) == NULL)
+ goto done;
}
if (xml_value_set(xa, namespace) < 0)
- goto done;
+ goto done;
xml_sort(xp); /* Ensure attr is first / XXX xml_insert? */
retval = 0;
done:
@@ -667,7 +667,7 @@ xml_namespace_change(cxobj *x,
if (xml2ns(x, xml_prefix(x), &ns0) < 0)
goto done;
if (ns0 && strcmp(ns0, ns) == 0)
- goto ok; /* Already has right namespace */
+ goto ok; /* Already has right namespace */
/* Is namespace already declared? */
if (xml2prefix(x, ns, &prefix0) == 1){
/* Yes it is declared and the prefix is prefix0 */
@@ -675,18 +675,18 @@ xml_namespace_change(cxobj *x,
goto done;
}
else{ /* Namespace does not exist, add it */
- /* Clear old prefix if any */
+ /* Clear old prefix if any */
if (xml_prefix_set(x, NULL) < 0)
goto done;
if (xml_type(x) == CX_ELMNT) /* If not element, do the namespace addition to the element */
- xp = x;
+ xp = x;
else
- xp = xml_parent(x);
+ xp = xml_parent(x);
if (add_namespace(x, xp, prefix, ns) < 0)
- goto done;
+ goto done;
/* Add prefix to x, if any */
if (prefix && xml_prefix_set(x, prefix) < 0)
- goto done;
+ goto done;
}
ok:
@@ -699,8 +699,8 @@ xml_namespace_change(cxobj *x,
*/
static int
xml_default_create1(yang_stmt *y,
- cxobj *xt,
- cxobj **xcp)
+ cxobj *xt,
+ cxobj **xcp)
{
int retval = -1;
char *namespace;
@@ -709,29 +709,29 @@ xml_default_create1(yang_stmt *y,
cxobj *xc = NULL;
if ((xc = xml_new(yang_argument_get(y), NULL, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
xml_spec_set(xc, y);
/* assign right prefix */
if ((namespace = yang_find_mynamespace(y)) != NULL){
- prefix = NULL;
- if ((ret = xml2prefix(xt, namespace, &prefix)) < 0)
- goto done;
- if (ret){ /* Namespace found, prefix returned in prefix */
- if (xml_prefix_set(xc, prefix) < 0)
- goto done;
- }
- else{ /* Namespace does not exist in target, must add it w xmlns attr.
- use source prefix */
- if (add_namespace(xc, xc, prefix, namespace) < 0)
- goto done;
- /* Add prefix to x, if any */
- if (prefix && xml_prefix_set(xc, prefix) < 0)
- goto done;
- }
+ prefix = NULL;
+ if ((ret = xml2prefix(xt, namespace, &prefix)) < 0)
+ goto done;
+ if (ret){ /* Namespace found, prefix returned in prefix */
+ if (xml_prefix_set(xc, prefix) < 0)
+ goto done;
+ }
+ else{ /* Namespace does not exist in target, must add it w xmlns attr.
+ use source prefix */
+ if (add_namespace(xc, xc, prefix, namespace) < 0)
+ goto done;
+ /* Add prefix to x, if any */
+ if (prefix && xml_prefix_set(xc, prefix) < 0)
+ goto done;
+ }
}
if (xml_addsub(xt, xc) < 0)
- goto done;
+ goto done;
*xcp = xc;
retval = 0;
done:
@@ -748,30 +748,30 @@ xml_default_create1(yang_stmt *y,
*/
static int
xml_default_create(yang_stmt *y,
- cxobj *xt,
- int top)
+ cxobj *xt,
+ int top)
{
int retval = -1;
cxobj *xc = NULL;
cxobj *xb;
char *str;
cg_var *cv;
-
+
if (xml_default_create1(y, xt, &xc) < 0)
- goto done;
+ goto done;
xml_flag_set(xc, XML_FLAG_DEFAULT);
if ((xb = xml_new("body", xc, CX_BODY)) == NULL)
- goto done;
+ goto done;
if ((cv = yang_cv_get(y)) == NULL){
- clicon_err(OE_UNIX, ENOENT, "No yang cv of %s", yang_argument_get(y));
- goto done;
+ clicon_err(OE_UNIX, ENOENT, "No yang cv of %s", yang_argument_get(y));
+ goto done;
}
if ((str = cv2str_dup(cv)) == NULL){
- clicon_err(OE_UNIX, errno, "cv2str_dup");
- goto done;
+ clicon_err(OE_UNIX, errno, "cv2str_dup");
+ goto done;
}
if (xml_value_set(xb, str) < 0)
- goto done;
+ goto done;
free(str);
retval = 0;
done:
@@ -787,40 +787,40 @@ xml_default_create(yang_stmt *y,
*/
static int
xml_nopresence_try(yang_stmt *yt,
- int *createp)
+ int *createp)
{
int retval = -1;
yang_stmt *y;
if (yt == NULL || yang_keyword_get(yt) != Y_CONTAINER){
- clicon_err(OE_XML, EINVAL, "yt argument is not container");
- goto done;
+ clicon_err(OE_XML, EINVAL, "yt argument is not container");
+ goto done;
}
*createp = 0;
y = NULL;
while ((y = yn_each(yt, y)) != NULL) {
- switch (yang_keyword_get(y)){
- case Y_LEAF:
- if (!cv_flag(yang_cv_get(y), V_UNSET)){ /* Default value exists */
- /* Need to create container */
- *createp = 1;
- goto ok;
- }
- break;
- case Y_CONTAINER:
- if (yang_find(y, Y_PRESENCE, NULL) == NULL){
- /* If this is non-presence, (and it does not exist in xt) call recursively
- * and create nodes if any default value exist first. Then continue and populate?
- */
- if (xml_nopresence_try(y, createp) < 0)
- goto done;
- if (*createp)
- goto ok;
- }
- break;
- default:
- break;
- } /* switch */
+ switch (yang_keyword_get(y)){
+ case Y_LEAF:
+ if (!cv_flag(yang_cv_get(y), V_UNSET)){ /* Default value exists */
+ /* Need to create container */
+ *createp = 1;
+ goto ok;
+ }
+ break;
+ case Y_CONTAINER:
+ if (yang_find(y, Y_PRESENCE, NULL) == NULL){
+ /* If this is non-presence, (and it does not exist in xt) call recursively
+ * and create nodes if any default value exist first. Then continue and populate?
+ */
+ if (xml_nopresence_try(y, createp) < 0)
+ goto done;
+ if (*createp)
+ goto ok;
+ }
+ break;
+ default:
+ break;
+ } /* switch */
}
ok:
retval = 0;
@@ -840,8 +840,8 @@ xml_nopresence_try(yang_stmt *yt,
*/
static int
xml_default1(yang_stmt *yt,
- cxobj *xt,
- int state)
+ cxobj *xt,
+ int state)
{
int retval = -1;
yang_stmt *yc;
@@ -854,77 +854,77 @@ xml_default1(yang_stmt *yt,
cg_var *cv;
if (xt == NULL){ /* No xml */
- clicon_err(OE_XML, EINVAL, "No XML argument");
- goto done;
+ clicon_err(OE_XML, EINVAL, "No XML argument");
+ goto done;
}
switch (yang_keyword_get(yt)){
case Y_MODULE:
case Y_SUBMODULE:
- top++;
+ top++;
case Y_CONTAINER: /* XXX maybe check for non-presence here as well */
case Y_LIST:
case Y_INPUT:
case Y_OUTPUT:
- yc = NULL;
- while ((yc = yn_each(yt, yc)) != NULL) {
- if (!state && !yang_config(yc))
- continue;
- switch (yang_keyword_get(yc)){
- case Y_LEAF:
- if ((cv = yang_cv_get(yc)) == NULL){
- clicon_err(OE_YANG,0, "Internal error: yang leaf %s not populated with cv as it should",
- yang_argument_get(yc));
- goto done;
- }
- if (!cv_flag(cv, V_UNSET)){ /* Default value exists */
- /* Check when condition */
- if (yang_check_when_xpath(NULL, xt, yc, &hit, &nr, &xpath) < 0)
- goto done;
- if (hit && nr == 0)
- break; /* Do not create default if xpath fails */
- if (xml_find_type(xt, NULL, yang_argument_get(yc), CX_ELMNT) == NULL){
- /* No such child exist, create this leaf */
- if (xml_default_create(yc, xt, top) < 0)
- goto done;
- xml_sort(xt);
- }
- }
- break;
- case Y_CONTAINER:
- if (yang_find(yc, Y_PRESENCE, NULL) == NULL){
- /* Check when condition */
- if (yang_check_when_xpath(NULL, xt, yc, &hit, &nr, &xpath) < 0)
- goto done;
- if (hit && nr == 0)
- break; /* Do not create default if xpath fails */
- /* If this is non-presence, (and it does not exist in xt) call
- * recursively and create nodes if any default value exist first.
- * Then continue and populate?
- */
- if (xml_find_type(xt, NULL, yang_argument_get(yc), CX_ELMNT) == NULL){
- /* No such container exist, recursively try if needed */
- if (xml_nopresence_try(yc, &create) < 0)
- goto done;
- if (create){
- /* Retval shows there is a default value need to create the
- * container */
- if (xml_default_create1(yc, xt, &xc) < 0)
- goto done;
- xml_sort(xt);
- /* Then call it recursively */
- if (xml_default1(yc, xc, state) < 0)
- goto done;
- }
- }
- }
- break;
- default:
- break;
- }
- }
- break;
+ yc = NULL;
+ while ((yc = yn_each(yt, yc)) != NULL) {
+ if (!state && !yang_config(yc))
+ continue;
+ switch (yang_keyword_get(yc)){
+ case Y_LEAF:
+ if ((cv = yang_cv_get(yc)) == NULL){
+ clicon_err(OE_YANG,0, "Internal error: yang leaf %s not populated with cv as it should",
+ yang_argument_get(yc));
+ goto done;
+ }
+ if (!cv_flag(cv, V_UNSET)){ /* Default value exists */
+ /* Check when condition */
+ if (yang_check_when_xpath(NULL, xt, yc, &hit, &nr, &xpath) < 0)
+ goto done;
+ if (hit && nr == 0)
+ break; /* Do not create default if xpath fails */
+ if (xml_find_type(xt, NULL, yang_argument_get(yc), CX_ELMNT) == NULL){
+ /* No such child exist, create this leaf */
+ if (xml_default_create(yc, xt, top) < 0)
+ goto done;
+ xml_sort(xt);
+ }
+ }
+ break;
+ case Y_CONTAINER:
+ if (yang_find(yc, Y_PRESENCE, NULL) == NULL){
+ /* Check when condition */
+ if (yang_check_when_xpath(NULL, xt, yc, &hit, &nr, &xpath) < 0)
+ goto done;
+ if (hit && nr == 0)
+ break; /* Do not create default if xpath fails */
+ /* If this is non-presence, (and it does not exist in xt) call
+ * recursively and create nodes if any default value exist first.
+ * Then continue and populate?
+ */
+ if (xml_find_type(xt, NULL, yang_argument_get(yc), CX_ELMNT) == NULL){
+ /* No such container exist, recursively try if needed */
+ if (xml_nopresence_try(yc, &create) < 0)
+ goto done;
+ if (create){
+ /* Retval shows there is a default value need to create the
+ * container */
+ if (xml_default_create1(yc, xt, &xc) < 0)
+ goto done;
+ xml_sort(xt);
+ /* Then call it recursively */
+ if (xml_default1(yc, xc, state) < 0)
+ goto done;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ break;
default:
- break;
+ break;
} /* switch */
retval = 0;
done:
@@ -941,17 +941,17 @@ xml_default1(yang_stmt *yt,
*/
static int
xml_default(cxobj *xt,
- int state)
+ int state)
{
int retval = -1;
yang_stmt *ys;
if ((ys = (yang_stmt*)xml_spec(xt)) == NULL){
- retval = 0;
- goto done;
+ retval = 0;
+ goto done;
}
if (xml_default1(ys, xt, state) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -966,22 +966,22 @@ xml_default(cxobj *xt,
*/
int
xml_default_recurse(cxobj *xn,
- int state)
+ int state)
{
int retval = -1;
cxobj *x;
yang_stmt *y;
if (xml_default(xn, state) < 0)
- goto done;
+ goto done;
x = NULL;
while ((x = xml_child_each(xn, x, CX_ELMNT)) != NULL) {
- if ((y = (yang_stmt*)xml_spec(x)) != NULL){
- if (!state && !yang_config(y))
- continue;
- }
- if (xml_default_recurse(x, state) < 0)
- goto done;
+ if ((y = (yang_stmt*)xml_spec(x)) != NULL){
+ if (!state && !yang_config(y))
+ continue;
+ }
+ if (xml_default_recurse(x, state) < 0)
+ goto done;
}
retval = 0;
done:
@@ -999,20 +999,20 @@ xml_default_recurse(cxobj *xn,
*/
static int
xml_global_defaults_create(cxobj *xt,
- yang_stmt *yspec,
- int state)
+ yang_stmt *yspec,
+ int state)
{
int retval = -1;
yang_stmt *ymod = NULL;
if (yspec == NULL || yang_keyword_get(yspec) != Y_SPEC){
- clicon_err(OE_XML, EINVAL, "yspec argument is not yang spec");
- goto done;
+ clicon_err(OE_XML, EINVAL, "yspec argument is not yang spec");
+ goto done;
}
while ((ymod = yn_each(yspec, ymod)) != NULL)
- if (xml_default1(ymod, xt, state) < 0)
- goto done;
+ if (xml_default1(ymod, xt, state) < 0)
+ goto done;
retval = 0;
done:
return retval;
@@ -1033,11 +1033,11 @@ xml_global_defaults_create(cxobj *xt,
*/
int
xml_global_defaults(clicon_handle h,
- cxobj *xt,
- cvec *nsc,
- const char *xpath,
- yang_stmt *yspec,
- int state)
+ cxobj *xt,
+ cvec *nsc,
+ const char *xpath,
+ yang_stmt *yspec,
+ int state)
{
int retval = -1;
db_elmnt de0 = {0,};
@@ -1055,48 +1055,48 @@ xml_global_defaults(clicon_handle h,
key = state ? "global-defaults-state" : "global-defaults-config";
/* First get or compute global xml tree cache */
if ((de = clicon_db_elmnt_get(h, key)) == NULL){
- /* Create it */
- if ((xcache = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
- goto done;
- if (xml_global_defaults_create(xcache, yspec, state) < 0)
- goto done;
- de0.de_xml = xcache;
- clicon_db_elmnt_set(h, key, &de0);
+ /* Create it */
+ if ((xcache = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
+ goto done;
+ if (xml_global_defaults_create(xcache, yspec, state) < 0)
+ goto done;
+ de0.de_xml = xcache;
+ clicon_db_elmnt_set(h, key, &de0);
}
else
- xcache = de->de_xml;
+ xcache = de->de_xml;
/* Here xcache has all global defaults. Now find the matching nodes
* XXX: nsc as 2nd argument
*/
if (xpath_vec(xcache, nsc, "%s", &xvec, &xlen, xpath?xpath:"/") < 0)
- goto done;
+ goto done;
/* Iterate through match vector
* For every node found in x0, mark the tree up to t1
*/
for (i=0; i) an action, ie name action and belong to YANG_XML_NAMESPACE?
* @param[in] xn XML node
* @retval 1 Yes, an action
@@ -2168,11 +2243,11 @@ xml_rpc_isaction(cxobj *xn)
char *ns = NULL;
if (strcmp(xml_name(xn), "action") != 0)
- goto fail;
+ goto fail;
if (xml2ns(xn, xml_prefix(xn), &ns) < 0)
- goto done;
+ goto done;
if (strcmp(YANG_XML_NAMESPACE, ns) != 0)
- goto fail;
+ goto fail;
retval = 1; // is action
done:
return retval;
@@ -2193,26 +2268,26 @@ xml_rpc_isaction(cxobj *xn)
*/
int
xml_find_action(cxobj *xn,
- int top,
- cxobj **xap)
+ int top,
+ cxobj **xap)
{
int retval = -1;
cxobj *xc = NULL;
yang_stmt *yc;
while ((xc = xml_child_each(xn, xc, CX_ELMNT)) != NULL) {
- if ((yc = xml_spec(xc)) == NULL)
- continue;
- if (!top && yang_keyword_get(yc) == Y_ACTION){
- *xap = xc;
- break;
- }
- if (yang_keyword_get(yc) != Y_CONTAINER && yang_keyword_get(yc) != Y_LIST)
- continue;
- /* XXX check key */
- if (xml_find_action(xc, 0, xap) < 0)
- goto done;
- break;
+ if ((yc = xml_spec(xc)) == NULL)
+ continue;
+ if (!top && yang_keyword_get(yc) == Y_ACTION){
+ *xap = xc;
+ break;
+ }
+ if (yang_keyword_get(yc) != Y_CONTAINER && yang_keyword_get(yc) != Y_LIST)
+ continue;
+ /* XXX check key */
+ if (xml_find_action(xc, 0, xap) < 0)
+ goto done;
+ break;
}
retval = 0;
done:
@@ -2229,10 +2304,10 @@ xml_find_action(cxobj *xn,
*/
int
purge_tagged_nodes(cxobj *xn,
- char *ns,
- char *name,
- char *value,
- int keepnode)
+ char *ns,
+ char *name,
+ char *value,
+ int keepnode)
{
int retval = -1;
cxobj *x;
@@ -2245,23 +2320,23 @@ purge_tagged_nodes(cxobj *xn,
x = NULL;
xprev = NULL;
while ((x = xml_child_each(xn, x, CX_ELMNT)) != NULL) {
- if ((ret = xml2prefix(x, ns, &prefix)) < 0)
- goto done;
- if (ret == 0)
- continue;
- if ((xa = xml_find_type(x, prefix, "default", CX_ATTR)) != NULL){
- if (!keepnode &&
- (v = xml_value(xa)) != NULL &&
- strcmp(v, value) == 0){
- xml_purge(x);
- x = xprev;
- continue;
- }
- xml_purge(xa); /* remove attribute regardless */
- }
- if (purge_tagged_nodes(x, ns, name, value, keepnode) < 0)
- goto done;
- xprev = x;
+ if ((ret = xml2prefix(x, ns, &prefix)) < 0)
+ goto done;
+ if (ret == 0)
+ continue;
+ if ((xa = xml_find_type(x, prefix, "default", CX_ATTR)) != NULL){
+ if (!keepnode &&
+ (v = xml_value(xa)) != NULL &&
+ strcmp(v, value) == 0){
+ xml_purge(x);
+ x = xprev;
+ continue;
+ }
+ xml_purge(xa); /* remove attribute regardless */
+ }
+ if (purge_tagged_nodes(x, ns, name, value, keepnode) < 0)
+ goto done;
+ xprev = x;
}
retval = 0;
done:
diff --git a/lib/src/clixon_xml_nsctx.c b/lib/src/clixon_xml_nsctx.c
index 78ef3911..d305af5b 100644
--- a/lib/src/clixon_xml_nsctx.c
+++ b/lib/src/clixon_xml_nsctx.c
@@ -78,7 +78,7 @@
* See rfc6241 3.1: urn:ietf:params:xml:ns:netconf:base:1.0.
*/
static int _USE_NAMESPACE_NETCONF_DEFAULT = 0;
-
+
/*! Set if use internal default namespace mechanism or not
*
* This function shouldnt really be here, it sets a local variable from the value of the
@@ -110,16 +110,16 @@ xml_nsctx_namespace_netconf_default(clicon_handle h)
*/
cvec *
xml_nsctx_init(char *prefix,
- char *ns)
+ char *ns)
{
cvec *cvv = NULL;
if ((cvv = cvec_new(0)) == NULL){
- clicon_err(OE_XML, errno, "cvec_new");
- goto done;
+ clicon_err(OE_XML, errno, "cvec_new");
+ goto done;
}
if (ns && xml_nsctx_add(cvv, prefix, ns) < 0)
- goto done;
+ goto done;
done:
return cvv;
}
@@ -136,7 +136,7 @@ xml_nsctx_free(cvec *nsc)
cvec *cvv = (cvec*)nsc;
if (cvv)
- cvec_free(cvv);
+ cvec_free(cvv);
return 0;
}
@@ -148,12 +148,12 @@ xml_nsctx_free(cvec *nsc)
*/
char*
xml_nsctx_get(cvec *cvv,
- char *prefix)
+ char *prefix)
{
cg_var *cv;
if ((cv = cvec_find(cvv, prefix)) != NULL)
- return cv_string_get(cv);
+ return cv_string_get(cv);
return NULL;
}
@@ -167,44 +167,44 @@ xml_nsctx_get(cvec *cvv,
*/
int
xml_nsctx_get_prefix(cvec *cvv,
- char *ns,
- char **prefix)
+ char *ns,
+ char **prefix)
{
cg_var *cv = NULL;
char *ns0 = NULL;
while ((cv = cvec_each(cvv, cv)) != NULL){
- if ((ns0 = cv_string_get(cv)) != NULL &&
- strcmp(ns0, ns) == 0){
- if (prefix)
- *prefix = cv_name_get(cv); /* can be NULL */
- return 1;
- }
+ if ((ns0 = cv_string_get(cv)) != NULL &&
+ strcmp(ns0, ns) == 0){
+ if (prefix)
+ *prefix = cv_name_get(cv); /* can be NULL */
+ return 1;
+ }
}
if (prefix)
- *prefix = NULL;
+ *prefix = NULL;
return 0;
}
/*! Set or replace namespace in namespace context
* @param[in] cvv Namespace context
* @param[in] prefix Namespace prefix, or NULL for default
- * @param[in] ns Cached namespace to set (assume non-null?)
+ * @param[in] ns Cached namespace to set (assume non-null?)
* @retval 0 OK
* @retval -1 Error
*/
int
xml_nsctx_add(cvec *cvv,
- char *prefix,
- char *ns)
+ char *prefix,
+ char *ns)
{
int retval = -1;
cg_var *cv;
if ((cv = cvec_find(cvv, prefix)) != NULL) /* found, replace that */
- cv_string_set(cv, ns);
+ cv_string_set(cv, ns);
else /* cvec exists, but not prefix */
- cvec_add_string(cvv, prefix, ns);
+ cvec_add_string(cvv, prefix, ns);
retval = 0;
// done:
return retval;
@@ -212,7 +212,7 @@ xml_nsctx_add(cvec *cvv,
static int
xml_nsctx_node1(cxobj *xn,
- cvec *nsc)
+ cvec *nsc)
{
int retval = -1;
cxobj *xa = NULL;
@@ -225,35 +225,35 @@ xml_nsctx_node1(cxobj *xn,
* xmlns="" prefix:NULL name:xmlns
*/
while ((xa = xml_child_each(xn, xa, CX_ATTR)) != NULL){
- pf = xml_prefix(xa);
- nm = xml_name(xa);
- if (pf == NULL){
- if (strcmp(nm, "xmlns")==0 && /* set default namespace context */
- xml_nsctx_get(nsc, NULL) == NULL){
- val = xml_value(xa);
- if (xml_nsctx_add(nsc, NULL, val) < 0)
- goto done;
- }
- }
- else
- if (strcmp(pf, "xmlns")==0 && /* set prefixed namespace context */
- xml_nsctx_get(nsc, nm) == NULL){
- val = xml_value(xa);
- if (xml_nsctx_add(nsc, nm, val) < 0)
- goto done;
- }
+ pf = xml_prefix(xa);
+ nm = xml_name(xa);
+ if (pf == NULL){
+ if (strcmp(nm, "xmlns")==0 && /* set default namespace context */
+ xml_nsctx_get(nsc, NULL) == NULL){
+ val = xml_value(xa);
+ if (xml_nsctx_add(nsc, NULL, val) < 0)
+ goto done;
+ }
+ }
+ else
+ if (strcmp(pf, "xmlns")==0 && /* set prefixed namespace context */
+ xml_nsctx_get(nsc, nm) == NULL){
+ val = xml_value(xa);
+ if (xml_nsctx_add(nsc, nm, val) < 0)
+ goto done;
+ }
}
if ((xp = xml_parent(xn)) == NULL){
- if (_USE_NAMESPACE_NETCONF_DEFAULT){
- /* If not default namespace defined, use the base netconf ns as default */
- if (xml_nsctx_get(nsc, NULL) == NULL)
- if (xml_nsctx_add(nsc, NULL, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
- }
+ if (_USE_NAMESPACE_NETCONF_DEFAULT){
+ /* If not default namespace defined, use the base netconf ns as default */
+ if (xml_nsctx_get(nsc, NULL) == NULL)
+ if (xml_nsctx_add(nsc, NULL, NETCONF_BASE_NAMESPACE) < 0)
+ goto done;
+ }
}
else
- if (xml_nsctx_node1(xp, nsc) < 0)
- goto done;
+ if (xml_nsctx_node1(xp, nsc) < 0)
+ goto done;
retval = 0;
done:
return retval;
@@ -278,17 +278,17 @@ xml_nsctx_node1(cxobj *xn,
*/
int
xml_nsctx_node(cxobj *xn,
- cvec **ncp)
+ cvec **ncp)
{
int retval = -1;
cvec *nc = NULL;
if ((nc = cvec_new(0)) == NULL){
- clicon_err(OE_XML, errno, "cvec_new");
- goto done;
+ clicon_err(OE_XML, errno, "cvec_new");
+ goto done;
}
if (xml_nsctx_node1(xn, nc) < 0)
- goto done;
+ goto done;
*ncp = nc;
retval = 0;
done:
@@ -315,7 +315,7 @@ xml_nsctx_node(cxobj *xn,
*/
int
xml_nsctx_yang(yang_stmt *yn,
- cvec **ncp)
+ cvec **ncp)
{
int retval = -1;
cvec *nc = NULL;
@@ -332,30 +332,30 @@ xml_nsctx_yang(yang_stmt *yn,
char *myprefix;
if (yang_keyword_get(yn) == Y_SPEC){
- clicon_err(OE_YANG, EINVAL, "yang spec node is invalid argument");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "yang spec node is invalid argument");
+ goto done;
}
if ((nc = cvec_new(0)) == NULL){
- clicon_err(OE_XML, errno, "cvec_new");
- goto done;
+ clicon_err(OE_XML, errno, "cvec_new");
+ goto done;
}
if ((myprefix = yang_find_myprefix(yn)) == NULL){
- clicon_err(OE_YANG, ENOENT, "My yang prefix not found");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "My yang prefix not found");
+ goto done;
}
if ((mynamespace = yang_find_mynamespace(yn)) == NULL){
- clicon_err(OE_YANG, ENOENT, "My yang namespace not found");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "My yang namespace not found");
+ goto done;
}
/* Add my prefix and default namespace (from real module) */
if (xml_nsctx_add(nc, NULL, mynamespace) < 0)
- goto done;
+ goto done;
if (xml_nsctx_add(nc, myprefix, mynamespace) < 0)
- goto done;
+ goto done;
/* Find top-most module or sub-module and get prefixes from that */
if ((ymod = ys_module(yn)) == NULL){
- clicon_err(OE_YANG, ENOENT, "My yang module not found");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "My yang module not found");
+ goto done;
}
yspec = yang_parent_get(ymod); /* Assume yspec exists */
@@ -363,22 +363,22 @@ xml_nsctx_yang(yang_stmt *yn,
*/
y = NULL;
while ((y = yn_each(ymod, y)) != NULL) {
- if (yang_keyword_get(y) == Y_IMPORT){
- if ((name = yang_argument_get(y)) == NULL)
- continue; /* Just skip - shouldnt happen) */
- if ((yp = yang_find(y, Y_PREFIX, NULL)) == NULL)
- continue;
- if ((prefix = yang_argument_get(yp)) == NULL)
- continue;
- if ((ym = yang_find(yspec, Y_MODULE, name)) == NULL)
- continue;
- if ((yns = yang_find(ym, Y_NAMESPACE, NULL)) == NULL)
- continue;
- if ((namespace = yang_argument_get(yns)) == NULL)
- continue;
- if (xml_nsctx_add(nc, prefix, namespace) < 0)
- goto done;
- }
+ if (yang_keyword_get(y) == Y_IMPORT){
+ if ((name = yang_argument_get(y)) == NULL)
+ continue; /* Just skip - shouldnt happen) */
+ if ((yp = yang_find(y, Y_PREFIX, NULL)) == NULL)
+ continue;
+ if ((prefix = yang_argument_get(yp)) == NULL)
+ continue;
+ if ((ym = yang_find(yspec, Y_MODULE, name)) == NULL)
+ continue;
+ if ((yns = yang_find(ym, Y_NAMESPACE, NULL)) == NULL)
+ continue;
+ if ((namespace = yang_argument_get(yns)) == NULL)
+ continue;
+ if (xml_nsctx_add(nc, prefix, namespace) < 0)
+ goto done;
+ }
}
*ncp = nc;
retval = 0;
@@ -400,14 +400,14 @@ xml_nsctx_yang(yang_stmt *yn,
* cvec *nsc = NULL;
* yang_stmt *yspec = clicon_dbspec_yang(h);
* if (xml_nsctx_yangspec(yspec, &nsc) < 0)
- * goto done;
+ * goto done;
* ...
* cvec_free(nsc);
* @endcode
*/
int
xml_nsctx_yangspec(yang_stmt *yspec,
- cvec **ncp)
+ cvec **ncp)
{
int retval = -1;
cvec *nc = NULL;
@@ -416,25 +416,25 @@ xml_nsctx_yangspec(yang_stmt *yspec,
yang_stmt *ynamespace;
if ((nc = cvec_new(0)) == NULL){
- clicon_err(OE_XML, errno, "cvec_new");
- goto done;
+ clicon_err(OE_XML, errno, "cvec_new");
+ goto done;
}
ymod = NULL;
while ((ymod = yn_each(yspec, ymod)) != NULL){
- if (yang_keyword_get(ymod) != Y_MODULE)
- continue;
- if ((yprefix = yang_find(ymod, Y_PREFIX, NULL)) == NULL)
- continue;
- if ((ynamespace = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL)
- continue;
- if (xml_nsctx_add(nc, yang_argument_get(yprefix), yang_argument_get(ynamespace)) < 0)
- goto done;
+ if (yang_keyword_get(ymod) != Y_MODULE)
+ continue;
+ if ((yprefix = yang_find(ymod, Y_PREFIX, NULL)) == NULL)
+ continue;
+ if ((ynamespace = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL)
+ continue;
+ if (xml_nsctx_add(nc, yang_argument_get(yprefix), yang_argument_get(ynamespace)) < 0)
+ goto done;
}
/* Add base netconf namespace as default and "nc" prefix */
if (xml_nsctx_add(nc, NULL, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
if (xml_nsctx_add(nc, NETCONF_BASE_PREFIX, NETCONF_BASE_NAMESPACE) < 0)
- goto done;
+ goto done;
*ncp = nc;
retval = 0;
done:
@@ -454,16 +454,16 @@ xml_nsctx_yangspec(yang_stmt *yspec,
*/
int
xml_nsctx_cbuf(cbuf *cb,
- cvec *nsc)
+ cvec *nsc)
{
cg_var *cv = NULL;
char *prefix;
while ((cv = cvec_each(nsc, cv)) != NULL){
- cprintf(cb, " xmlns");
- if ((prefix = cv_name_get(cv)))
- cprintf(cb, ":%s", prefix);
- cprintf(cb, "=\"%s\"", cv_string_get(cv));
+ cprintf(cb, " xmlns");
+ if ((prefix = cv_name_get(cv)))
+ cprintf(cb, ":%s", prefix);
+ cprintf(cb, "=\"%s\"", cv_string_get(cv));
}
return 0;
}
@@ -493,37 +493,37 @@ xml2ns(cxobj *x,
cxobj *xp;
if ((ns = nscache_get(x, prefix)) != NULL)
- goto ok;
+ goto ok;
if (prefix != NULL) /* xmlns:="" */
- ns = xml_find_type_value(x, "xmlns", prefix, CX_ATTR);
+ ns = xml_find_type_value(x, "xmlns", prefix, CX_ATTR);
else{ /* xmlns="" */
- ns = xml_find_type_value(x, NULL, "xmlns", CX_ATTR);
+ ns = xml_find_type_value(x, NULL, "xmlns", CX_ATTR);
}
/* namespace not found, try parent */
if (ns == NULL){
- if ((xp = xml_parent(x)) != NULL){
- if (xml2ns(xp, prefix, &ns) < 0)
- goto done;
- }
- /* If no parent, return default namespace if defined */
- else if (_USE_NAMESPACE_NETCONF_DEFAULT){
- if (prefix == NULL)
- ns = NETCONF_BASE_NAMESPACE;
- else
- ns = NULL;
- }
+ if ((xp = xml_parent(x)) != NULL){
+ if (xml2ns(xp, prefix, &ns) < 0)
+ goto done;
+ }
+ /* If no parent, return default namespace if defined */
+ else if (_USE_NAMESPACE_NETCONF_DEFAULT){
+ if (prefix == NULL)
+ ns = NETCONF_BASE_NAMESPACE;
+ else
+ ns = NULL;
+ }
}
/* Set default namespace cache (since code is at this point,
* no cache was found
* If not, this is devastating when populating deep yang structures
*/
if (ns &&
- xml_child_nr(x) > 1 && /* Dont set cache if few children: if 1 child typically a body */
- nscache_set(x, prefix, ns) < 0)
- goto done;
+ xml_child_nr(x) > 1 && /* Dont set cache if few children: if 1 child typically a body */
+ nscache_set(x, prefix, ns) < 0)
+ goto done;
ok:
if (namespace)
- *namespace = ns;
+ *namespace = ns;
retval = 0;
done:
return retval;
@@ -544,17 +544,17 @@ xml2ns_recurse(cxobj *xt)
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
- if ((prefix = xml_prefix(x)) != NULL){
- namespace = NULL;
- if (xml2ns(x, prefix, &namespace) < 0)
- goto done;
- if (namespace == NULL){
- clicon_err(OE_XML, ENOENT, "No namespace associated with %s:%s", prefix, xml_name(x));
- goto done;
- }
- }
- if (xml2ns_recurse(x) < 0)
- goto done;
+ if ((prefix = xml_prefix(x)) != NULL){
+ namespace = NULL;
+ if (xml2ns(x, prefix, &namespace) < 0)
+ goto done;
+ if (namespace == NULL){
+ clicon_err(OE_XML, ENOENT, "No namespace associated with %s:%s", prefix, xml_name(x));
+ goto done;
+ }
+ }
+ if (xml2ns_recurse(x) < 0)
+ goto done;
}
retval = 0;
done:
@@ -571,27 +571,27 @@ xml2ns_recurse(cxobj *xt)
*/
int
xmlns_set(cxobj *x,
- char *prefix,
- char *ns)
+ char *prefix,
+ char *ns)
{
int retval = -1;
cxobj *xa;
if (prefix != NULL){ /* xmlns:="" */
- if ((xa = xml_new(prefix, x, CX_ATTR)) == NULL)
- goto done;
- if (xml_prefix_set(xa, "xmlns") < 0)
- goto done;
+ if ((xa = xml_new(prefix, x, CX_ATTR)) == NULL)
+ goto done;
+ if (xml_prefix_set(xa, "xmlns") < 0)
+ goto done;
}
else{ /* xmlns="" */
- if ((xa = xml_new("xmlns", x, CX_ATTR)) == NULL)
- goto done;
+ if ((xa = xml_new("xmlns", x, CX_ATTR)) == NULL)
+ goto done;
}
if (xml_value_set(xa, ns) < 0)
- goto done;
+ goto done;
/* (re)set namespace cache (as used in xml2ns) */
if (ns && nscache_set(x, prefix, ns) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -607,7 +607,7 @@ xmlns_set(cxobj *x,
*/
int
xmlns_set_all(cxobj *x,
- cvec *nsc)
+ cvec *nsc)
{
int retval = -1;
char *ns;
@@ -615,18 +615,18 @@ xmlns_set_all(cxobj *x,
cg_var *cv = NULL;
while ((cv = cvec_each(nsc, cv)) != NULL){
- pf = cv_name_get(cv);
- /* Check already added */
- if (pf != NULL) /* xmlns:="" */
- ns = xml_find_type_value(x, "xmlns", pf, CX_ATTR);
- else{ /* xmlns="" */
- ns = xml_find_type_value(x, NULL, "xmlns", CX_ATTR);
- }
- if (ns)
- continue;
- ns = cv_string_get(cv);
- if (ns && xmlns_set(x, pf, ns) < 0)
- goto done;
+ pf = cv_name_get(cv);
+ /* Check already added */
+ if (pf != NULL) /* xmlns:="" */
+ ns = xml_find_type_value(x, "xmlns", pf, CX_ATTR);
+ else{ /* xmlns="" */
+ ns = xml_find_type_value(x, NULL, "xmlns", CX_ATTR);
+ }
+ if (ns)
+ continue;
+ ns = cv_string_get(cv);
+ if (ns && xmlns_set(x, pf, ns) < 0)
+ goto done;
}
retval = 0;
done:
@@ -645,8 +645,8 @@ xmlns_set_all(cxobj *x,
*/
int
xml2prefix(cxobj *xn,
- char *namespace,
- char **prefixp)
+ char *namespace,
+ char **prefixp)
{
int retval = -1;
cxobj *xa = NULL;
@@ -656,44 +656,44 @@ xml2prefix(cxobj *xn,
int ret;
if (nscache_get_prefix(xn, namespace, &prefix) == 1) /* found */
- goto found;
+ goto found;
xa = NULL;
while ((xa = xml_child_each(xn, xa, CX_ATTR)) != NULL) {
- /* xmlns=namespace */
- if (strcmp("xmlns", xml_name(xa)) == 0){
- if (strcmp(xml_value(xa), namespace) == 0){
- if (nscache_set(xn, NULL, namespace) < 0)
- goto done;
- prefix = NULL; /* Maybe should set all caches in ns:s children? */
- goto found;
- }
- }
- /* xmlns:prefix=namespace */
- else if ((xaprefix=xml_prefix(xa)) != NULL &&
- strcmp("xmlns", xaprefix) == 0){
- if (strcmp(xml_value(xa), namespace) == 0){
- prefix = xml_name(xa);
- if (nscache_set(xn, prefix, namespace) < 0)
- goto done;
- goto found;
- }
- }
+ /* xmlns=namespace */
+ if (strcmp("xmlns", xml_name(xa)) == 0){
+ if (strcmp(xml_value(xa), namespace) == 0){
+ if (nscache_set(xn, NULL, namespace) < 0)
+ goto done;
+ prefix = NULL; /* Maybe should set all caches in ns:s children? */
+ goto found;
+ }
+ }
+ /* xmlns:prefix=namespace */
+ else if ((xaprefix=xml_prefix(xa)) != NULL &&
+ strcmp("xmlns", xaprefix) == 0){
+ if (strcmp(xml_value(xa), namespace) == 0){
+ prefix = xml_name(xa);
+ if (nscache_set(xn, prefix, namespace) < 0)
+ goto done;
+ goto found;
+ }
+ }
}
if ((xp = xml_parent(xn)) != NULL){
- if ((ret = xml2prefix(xp, namespace, &prefix)) < 0)
- goto done;
- if (ret == 1){
- if (nscache_set(xn, prefix, namespace) < 0)
- goto done;
- goto found;
- }
+ if ((ret = xml2prefix(xp, namespace, &prefix)) < 0)
+ goto done;
+ if (ret == 1){
+ if (nscache_set(xn, prefix, namespace) < 0)
+ goto done;
+ goto found;
+ }
}
retval = 0;
done:
return retval;
found:
if (prefixp)
- *prefixp = prefix;
+ *prefixp = prefix;
retval = 1;
goto done;
}
diff --git a/lib/src/clixon_xml_parse.h b/lib/src/clixon_xml_parse.h
index b99643d6..4766d79d 100644
--- a/lib/src/clixon_xml_parse.h
+++ b/lib/src/clixon_xml_parse.h
@@ -73,4 +73,4 @@ int clixon_xml_parsel_linenr(void);
int clixon_xml_parselex(void *);
int clixon_xml_parseparse(void *);
-#endif /* _CLIXON_XML_PARSE_H_ */
+#endif /* _CLIXON_XML_PARSE_H_ */
diff --git a/lib/src/clixon_xml_parse.l b/lib/src/clixon_xml_parse.l
index d6970e5e..620c4984 100644
--- a/lib/src/clixon_xml_parse.l
+++ b/lib/src/clixon_xml_parse.l
@@ -80,9 +80,9 @@ int clixon_xml_parsewrap(void)
* From https://www.w3.org/TR/2008/REC-xml-20081126:
* [4]* NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] ...
* [4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7|
- * [5] Name ::= NameStartChar (NameChar)*
+ * [5] Name ::= NameStartChar (NameChar)*
* NOTE: From https://www.w3.org/TR/2009/REC-xml-names-20091208:
- * [4] NCName ::= Name - (Char* ':' Char*) An XML Name, minus the ":"
+ * [4] NCName ::= Name - (Char* ':' Char*) An XML Name, minus the ":"
* --> namestart and name below is NCNAME
*/
@@ -140,7 +140,7 @@ ncname {namestart}{namechar}*
\n { clixon_xml_parselval.string = "\n"; _XY->xy_linenum++;return WHITESPACE; }
[^&\r\n \t\<]+ { clixon_xml_parselval.string = yytext; return CHARDATA; /* Optimized */}
- /* @see xml_chardata_encode */
+ /* @see xml_chardata_encode */
"amp;" { BEGIN(_XY->xy_lex_state); clixon_xml_parselval.string = "&"; return CHARDATA;}
"lt;" { BEGIN(_XY->xy_lex_state); clixon_xml_parselval.string = "<"; return CHARDATA;}
"gt;" { BEGIN(_XY->xy_lex_state); clixon_xml_parselval.string = ">"; return CHARDATA;}
diff --git a/lib/src/clixon_xml_parse.y b/lib/src/clixon_xml_parse.y
index 8a94642f..8041a45f 100644
--- a/lib/src/clixon_xml_parse.y
+++ b/lib/src/clixon_xml_parse.y
@@ -93,12 +93,12 @@
void
clixon_xml_parseerror(void *_xy,
- char *s)
+ char *s)
{
clicon_err(OE_XML, XMLPARSE_ERRNO, "xml_parse: line %d: %s: at or before: %s",
- _XY->xy_linenum,
- s,
- clixon_xml_parsetext);
+ _XY->xy_linenum,
+ s,
+ clixon_xml_parsetext);
return;
}
@@ -110,7 +110,7 @@ clixon_xml_parseerror(void *_xy,
*/
static int
xml_parse_content(clixon_xml_yacc *xy,
- char *str)
+ char *str)
{
cxobj *xn = xy->xy_xelement;
cxobj *xp = xy->xy_xparent;
@@ -118,11 +118,11 @@ xml_parse_content(clixon_xml_yacc *xy,
xy->xy_xelement = NULL; /* init */
if (xn == NULL){
- if ((xn = xml_new("body", xp, CX_BODY)) == NULL)
- goto done;
+ if ((xn = xml_new("body", xp, CX_BODY)) == NULL)
+ goto done;
}
if (xml_value_append(xn, str) < 0)
- goto done;
+ goto done;
xy->xy_xelement = xn;
retval = 0;
done:
@@ -135,7 +135,7 @@ xml_parse_content(clixon_xml_yacc *xy,
*/
static int
xml_parse_whitespace(clixon_xml_yacc *xy,
- char *str)
+ char *str)
{
cxobj *xn = xy->xy_xelement;
cxobj *xp = xy->xy_xparent;
@@ -150,15 +150,15 @@ xml_parse_whitespace(clixon_xml_yacc *xy,
* then the whitespace body is pretty-prints and should be stripped (later)
*/
for (i=0; ixy_xelement = xn;
ok:
retval = 0;
@@ -168,15 +168,15 @@ xml_parse_whitespace(clixon_xml_yacc *xy,
static int
xml_parse_version(clixon_xml_yacc *xy,
- char *ver)
+ char *ver)
{
if(strcmp(ver, "1.0")){
- clicon_err(OE_XML, XMLPARSE_ERRNO, "Unsupported XML version: %s expected 1.0", ver);
- free(ver);
- return -1;
+ clicon_err(OE_XML, XMLPARSE_ERRNO, "Unsupported XML version: %s expected 1.0", ver);
+ free(ver);
+ return -1;
}
if (ver)
- free(ver);
+ free(ver);
return 0;
}
@@ -195,12 +195,12 @@ xml_parse_version(clixon_xml_yacc *xy,
*/
static int
xml_parse_encoding(clixon_xml_yacc *xy,
- char *enc)
+ char *enc)
{
if(strcasecmp(enc, "UTF-8")){
- clicon_err(OE_XML, XMLPARSE_ERRNO, "Unsupported XML encoding: %s expected UTF-8", enc);
- free(enc);
- return -1;
+ clicon_err(OE_XML, XMLPARSE_ERRNO, "Unsupported XML encoding: %s expected UTF-8", enc);
+ free(enc);
+ return -1;
}
return 0;
}
@@ -214,8 +214,8 @@ xml_parse_encoding(clixon_xml_yacc *xy,
*/
static int
xml_parse_prefixed_name(clixon_xml_yacc *xy,
- char *prefix,
- char *name)
+ char *prefix,
+ char *name)
{
int retval = -1;
cxobj *x;
@@ -223,23 +223,23 @@ xml_parse_prefixed_name(clixon_xml_yacc *xy,
xp = xy->xy_xparent;
if ((x = xml_new(name, xp, CX_ELMNT)) == NULL)
- goto done;
+ goto done;
/* Cant check namespaces here since local xmlns attributes loaded after */
if (xml_prefix_set(x, prefix) < 0)
- goto done;
+ goto done;
xy->xy_xelement = x;
/* If topmost, add to top-list created list */
if (xp == xy->xy_xtop){
- if (cxvec_append(x, &xy->xy_xvec, &xy->xy_xlen) < 0)
- goto done;
+ if (cxvec_append(x, &xy->xy_xvec, &xy->xy_xlen) < 0)
+ goto done;
}
retval = 0;
done:
if (prefix)
- free(prefix);
+ free(prefix);
if (name)
- free(name);
+ free(name);
return retval;
}
@@ -255,9 +255,9 @@ static int
xml_parse_endslash_mid(clixon_xml_yacc *xy)
{
if (xy->xy_xelement != NULL)
- xy->xy_xelement = xml_parent(xy->xy_xelement);
+ xy->xy_xelement = xml_parent(xy->xy_xelement);
else
- xy->xy_xelement = xy->xy_xparent;
+ xy->xy_xelement = xy->xy_xparent;
xy->xy_xparent = xml_parent(xy->xy_xelement);
return 0;
}
@@ -280,8 +280,8 @@ xml_parse_endslash_post(clixon_xml_yacc *xy)
*/
static int
xml_parse_bslash(clixon_xml_yacc *xy,
- char *prefix,
- char *name)
+ char *prefix,
+ char *name)
{
int retval = -1;
cxobj *x = xy->xy_xelement;
@@ -294,11 +294,11 @@ xml_parse_bslash(clixon_xml_yacc *xy,
name0 = xml_name(x);
/* Check name or prerix unequal from begin-tag */
if (clicon_strcmp(name0, name) ||
- clicon_strcmp(prefix0, prefix)){
- clicon_err(OE_XML, XMLPARSE_ERRNO, "Sanity check failed: %s%s%s vs %s%s%s",
- prefix0?prefix0:"", prefix0?":":"", name0,
- prefix?prefix:"", prefix?":":"", name);
- goto done;
+ clicon_strcmp(prefix0, prefix)){
+ clicon_err(OE_XML, XMLPARSE_ERRNO, "Sanity check failed: %s%s%s vs %s%s%s",
+ prefix0?prefix0:"", prefix0?":":"", name0,
+ prefix?prefix:"", prefix?":":"", name);
+ goto done;
}
/* Strip pretty-print. Ad-hoc algorithm
* It ok with x:[body], but not with x:[ex,body]
@@ -310,17 +310,17 @@ xml_parse_bslash(clixon_xml_yacc *xy,
*/
xc = NULL;
while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL)
- break;
+ break;
if (xc != NULL){ /* at least one element */
- if (xml_rm_children(x, CX_BODY) < 0) /* remove all bodies */
- goto done;
+ if (xml_rm_children(x, CX_BODY) < 0) /* remove all bodies */
+ goto done;
}
retval = 0;
done:
if (prefix)
- free(prefix);
+ free(prefix);
if (name)
- free(name);
+ free(name);
return retval;
}
@@ -331,27 +331,27 @@ xml_parse_bslash(clixon_xml_yacc *xy,
*/
static int
xml_parse_attr(clixon_xml_yacc *xy,
- char *prefix,
- char *name,
- char *attval)
+ char *prefix,
+ char *name,
+ char *attval)
{
int retval = -1;
cxobj *xa = NULL;
if ((xa = xml_find_type(xy->xy_xelement, prefix, name, CX_ATTR)) == NULL){
- if ((xa = xml_new(name, xy->xy_xelement, CX_ATTR)) == NULL)
- goto done;
- if (xml_prefix_set(xa, prefix) < 0)
- goto done;
+ if ((xa = xml_new(name, xy->xy_xelement, CX_ATTR)) == NULL)
+ goto done;
+ if (xml_prefix_set(xa, prefix) < 0)
+ goto done;
}
if (xml_value_set(xa, attval) < 0)
- goto done;
+ goto done;
retval = 0;
done:
free(name);
if (prefix)
- free(prefix);
+ free(prefix);
free(attval);
return retval;
}
@@ -362,47 +362,47 @@ xml_parse_attr(clixon_xml_yacc *xy,
/* [1] document ::= prolog element Misc* */
document : prolog element misclist MY_EOF
{ _PARSE_DEBUG("document->prolog element misc* ACCEPT");
- YYACCEPT; }
+ YYACCEPT; }
| elist MY_EOF
- { _PARSE_DEBUG("document->elist ACCEPT"); /* internal exception*/
- YYACCEPT; }
+ { _PARSE_DEBUG("document->elist ACCEPT"); /* internal exception*/
+ YYACCEPT; }
;
/* [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? */
prolog : xmldcl misclist
{ _PARSE_DEBUG("prolog->xmldcl misc*"); }
| misclist
- { _PARSE_DEBUG("prolog->misc*"); }
+ { _PARSE_DEBUG("prolog->misc*"); }
;
misclist : misclist misc { _PARSE_DEBUG("misclist->misclist misc"); }
| { _PARSE_DEBUG("misclist->"); }
;
-/* [27] Misc ::= Comment | PI | S */
+/* [27] Misc ::= Comment | PI | S */
misc : comment { _PARSE_DEBUG("misc->comment"); }
- | pi { _PARSE_DEBUG("misc->pi"); }
+ | pi { _PARSE_DEBUG("misc->pi"); }
| WHITESPACE { _PARSE_DEBUG("misc->white space"); }
- ;
+ ;
-/* [23] XMLDecl ::= ''*/
+/* [23] XMLDecl ::= ''*/
xmldcl : BXMLDCL verinfo encodingdecl sddecl EQMARK
- { _PARSE_DEBUG("xmldcl->verinfo encodingdecl? sddecl?"); }
+ { _PARSE_DEBUG("xmldcl->verinfo encodingdecl? sddecl?"); }
;
verinfo : VER '=' '\"' STRING '\"'
{ if (xml_parse_version(_XY, $4) <0) YYABORT;
- _PARSE_DEBUG("verinfo->version=\"STRING\"");}
+ _PARSE_DEBUG("verinfo->version=\"STRING\"");}
| VER '=' '\'' STRING '\''
- { if (xml_parse_version(_XY, $4) <0) YYABORT;
- _PARSE_DEBUG("verinfo->version='STRING'");}
+ { if (xml_parse_version(_XY, $4) <0) YYABORT;
+ _PARSE_DEBUG("verinfo->version='STRING'");}
;
encodingdecl : ENC '=' '\"' STRING '\"'
{ if (xml_parse_encoding(_XY, $4) <0) YYABORT; if ($4)free($4);
- _PARSE_DEBUG("encodingdecl-> encoding = \" STRING \"");}
+ _PARSE_DEBUG("encodingdecl-> encoding = \" STRING \"");}
| ENC '=' '\'' STRING '\''
- { if (xml_parse_encoding(_XY, $4) <0) YYABORT; if ($4)free($4);
- _PARSE_DEBUG("encodingdecl-> encoding = ' STRING '");}
+ { if (xml_parse_encoding(_XY, $4) <0) YYABORT; if ($4)free($4);
+ _PARSE_DEBUG("encodingdecl-> encoding = ' STRING '");}
|
;
@@ -413,7 +413,7 @@ sddecl : SD '=' '\"' STRING '\"' {if ($4)free($4);}
/* [39] element ::= EmptyElemTag | STag content ETag */
element : '<' qname attrs element1
{ _PARSE_DEBUG("element -> < qname attrs element1"); }
- ;
+ ;
qname : NAME { if (xml_parse_prefixed_name(_XY, NULL, $1) < 0) YYABORT;
_PARSE_DEBUG("qname -> NAME");}
@@ -431,11 +431,11 @@ element1 : ESLASH {_XY->xy_xelement = NULL;
endtag : BSLASH NAME '>'
{ _PARSE_DEBUG("endtag -> < NAME>");
- if (xml_parse_bslash(_XY, NULL, $2) < 0) YYABORT; }
+ if (xml_parse_bslash(_XY, NULL, $2) < 0) YYABORT; }
| BSLASH NAME ':' NAME '>'
{ if (xml_parse_bslash(_XY, $2, $4) < 0) YYABORT;
- _PARSE_DEBUG("endtag -> < NAME:NAME >"); }
+ _PARSE_DEBUG("endtag -> < NAME:NAME >"); }
;
elist : elist content { _PARSE_DEBUG("elist -> elist content"); }
@@ -458,7 +458,7 @@ comment : BCOMMENT ECOMMENT
pi : BQMARK NAME EQMARK {_PARSE_DEBUG("pi -> NAME ?>"); free($2); }
| BQMARK NAME STRING EQMARK
- { _PARSE_DEBUG("pi -> NAME STRING ?>"); free($2); free($3);}
+ { _PARSE_DEBUG("pi -> NAME STRING ?>"); free($2); free($3);}
;
diff --git a/lib/src/clixon_xml_sort.c b/lib/src/clixon_xml_sort.c
index d1b81e7e..6321c688 100644
--- a/lib/src/clixon_xml_sort.c
+++ b/lib/src/clixon_xml_sort.c
@@ -85,7 +85,7 @@
*/
static int
xml_cv_cache(cxobj *x,
- cg_var **cvp)
+ cg_var **cvp)
{
int retval = -1;
cg_var *cv = NULL;
@@ -97,49 +97,49 @@ xml_cv_cache(cxobj *x,
int options = 0;
uint8_t fraction = 0;
char *body;
-
+
if ((body = xml_body(x)) == NULL)
- body="";
+ body="";
if ((cv = xml_cv(x)) != NULL)
- goto ok;
+ goto ok;
if ((y = xml_spec(x)) == NULL){
- clicon_err(OE_XML, EFAULT, "Yang binding missing for xml symbol %s, body:%s", xml_name(x), body);
- goto done;
+ clicon_err(OE_XML, EFAULT, "Yang binding missing for xml symbol %s, body:%s", xml_name(x), body);
+ goto done;
}
if (yang_type_get(y, NULL, &yrestype, &options, NULL, NULL, NULL, &fraction) < 0)
- goto done;
+ goto done;
yang2cv_type(yang_argument_get(yrestype), &cvtype);
if (cvtype==CGV_ERR){
- clicon_err(OE_YANG, errno, "yang->cligen type %s mapping failed",
- yang_argument_get(yrestype));
- goto done;
+ clicon_err(OE_YANG, errno, "yang->cligen type %s mapping failed",
+ yang_argument_get(yrestype));
+ goto done;
}
if ((cv = cv_new(cvtype)) == NULL){
- clicon_err(OE_YANG, errno, "cv_new");
- goto done;
+ clicon_err(OE_YANG, errno, "cv_new");
+ goto done;
}
if (cvtype == CGV_DEC64)
- cv_dec64_n_set(cv, fraction);
-
+ cv_dec64_n_set(cv, fraction);
+
if ((ret = cv_parse1(body, cv, &reason)) < 0){
- clicon_err(OE_YANG, errno, "cv_parse1");
- goto done;
+ clicon_err(OE_YANG, errno, "cv_parse1");
+ goto done;
}
if (ret == 0){
- clicon_err(OE_YANG, EINVAL, "cv parse error: %s\n", reason);
- goto done;
+ clicon_err(OE_YANG, EINVAL, "cv parse error: %s\n", reason);
+ goto done;
}
if (xml_cv_set(x, cv) < 0)
- goto done;
+ goto done;
ok:
*cvp = cv;
cv = NULL;
retval = 0;
done:
if (reason)
- free(reason);
+ free(reason);
if (cv)
- cv_free(cv);
+ cv_free(cv);
return retval;
}
@@ -150,8 +150,8 @@ xml_cv_cache_clear(cxobj *xt)
cxobj *x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL)
- if (xml_cv_set(x, NULL) < 0)
- goto done;
+ if (xml_cv_set(x, NULL) < 0)
+ goto done;
retval = 0;
done:
return retval;
@@ -197,10 +197,10 @@ xml_cv_cache_clear(cxobj *xt)
*/
int
xml_cmp(cxobj *x1,
- cxobj *x2,
- int same,
- int skip1,
- char *indexvar)
+ cxobj *x2,
+ int same,
+ int skip1,
+ char *indexvar)
{
yang_stmt *y1;
yang_stmt *y2;
@@ -222,29 +222,29 @@ xml_cmp(cxobj *x1,
enum cxobj_type xt2;
if (x1==NULL || x2==NULL)
- goto done; /* shouldnt happen */
+ goto done; /* shouldnt happen */
/* Sort according to attributes first */
if ((xt1 = xml_type(x1)) != (xt2 = xml_type(x2))){
- if (xt1 == CX_ATTR){
- equal = -1;
- goto done;
- }
- else if (xt2 == CX_ATTR){
- equal = 1;
- goto done;
- }
+ if (xt1 == CX_ATTR){
+ equal = -1;
+ goto done;
+ }
+ else if (xt2 == CX_ATTR){
+ equal = 1;
+ goto done;
+ }
}
/* Here x1 and x2 are same type */
y1 = xml_spec(x1);
y2 = xml_spec(x2);
if (same){
- nr1 = xml_enumerate_get(x1);
- nr2 = xml_enumerate_get(x2);
+ nr1 = xml_enumerate_get(x1);
+ nr2 = xml_enumerate_get(x2);
}
if (y1==NULL && y2==NULL){
- if (same)
- equal = nr1-nr2;
- goto done;
+ if (same)
+ equal = nr1-nr2;
+ goto done;
}
if (y1==NULL){
equal = -1;
@@ -255,12 +255,12 @@ xml_cmp(cxobj *x1,
goto done;
}
if (y1 != y2){
- /* XXX handle errors */
- yi1 = yang_order(y1);
- yi2 = yang_order(y2);
- /* this is for choice */
- if ((equal = yi1-yi2) != 0)
- goto done;
+ /* XXX handle errors */
+ yi1 = yang_order(y1);
+ yi2 = yang_order(y2);
+ /* this is for choice */
+ if ((equal = yi1-yi2) != 0)
+ goto done;
}
/* Now y1==y2, same Yang spec, can only be list or leaf-list,
* But first check exceptions, eg config false or ordered-by user
@@ -270,118 +270,118 @@ xml_cmp(cxobj *x1,
* existing list.
*/
if (same &&
- (
+ (
#ifndef STATE_ORDERED_BY_SYSTEM
- yang_config(y1)==0 ||
+ yang_config(y1)==0 ||
#endif
- yang_find(y1, Y_ORDERED_BY, "user") != NULL)){
- equal = nr1-nr2;
- goto done; /* Ordered by user or state data : maintain existing order */
- }
+ yang_find(y1, Y_ORDERED_BY, "user") != NULL)){
+ equal = nr1-nr2;
+ goto done; /* Ordered by user or state data : maintain existing order */
+ }
switch (yang_keyword_get(y1)){
case Y_LEAF_LIST: /* Match with name and value */
- b1 = xml_body(x1);
- b2 = xml_body(x2);
- if (b1 == NULL && b2 == NULL)
- ;
- else if (b1 == NULL)
- equal = -1;
- else if (b2 == NULL)
- equal = 1;
- else{
- if (xml_cv_cache(x1, &cv1) < 0) /* error case */
- goto done;
- if (xml_cv_cache(x2, &cv2) < 0) /* error case */
- goto done;
- if (cv1 != NULL && cv2 != NULL)
- equal = cv_cmp(cv1, cv2);
- else if (cv1 == NULL && cv2 == NULL)
- equal = 0;
- else if (cv1 == NULL)
- equal = -1;
- else
- equal = 1;
- }
- break;
+ b1 = xml_body(x1);
+ b2 = xml_body(x2);
+ if (b1 == NULL && b2 == NULL)
+ ;
+ else if (b1 == NULL)
+ equal = -1;
+ else if (b2 == NULL)
+ equal = 1;
+ else{
+ if (xml_cv_cache(x1, &cv1) < 0) /* error case */
+ goto done;
+ if (xml_cv_cache(x2, &cv2) < 0) /* error case */
+ goto done;
+ if (cv1 != NULL && cv2 != NULL)
+ equal = cv_cmp(cv1, cv2);
+ else if (cv1 == NULL && cv2 == NULL)
+ equal = 0;
+ else if (cv1 == NULL)
+ equal = -1;
+ else
+ equal = 1;
+ }
+ break;
case Y_LIST: /* Match with key values */
- if (indexvar != NULL){
+ if (indexvar != NULL){
#ifdef XML_EXPLICIT_INDEX
- x1b = xml_find(x1, indexvar);
- x2b = xml_find(x2, indexvar);
- if (x1b == NULL && x2b == NULL)
- ;
- else if (x1b == NULL)
- equal = -1;
- else if (x2b == NULL)
- equal = 1;
- else{
- b1 = xml_body(x1b);
- b2 = xml_body(x2b);
- if (b1 == NULL && b2 == NULL)
- ;
- else if (b1 == NULL)
- equal = -1;
- else if (b2 == NULL)
- equal = 1;
- else{
- if (xml_cv_cache(x1b, &cv1) < 0) /* error case */
- goto done;
- if (xml_cv_cache(x2b, &cv2) < 0) /* error case */
- goto done;
- assert(cv1 && cv2);
- equal = cv_cmp(cv1, cv2);
- }
- }
- if (equal)
- break;
+ x1b = xml_find(x1, indexvar);
+ x2b = xml_find(x2, indexvar);
+ if (x1b == NULL && x2b == NULL)
+ ;
+ else if (x1b == NULL)
+ equal = -1;
+ else if (x2b == NULL)
+ equal = 1;
+ else{
+ b1 = xml_body(x1b);
+ b2 = xml_body(x2b);
+ if (b1 == NULL && b2 == NULL)
+ ;
+ else if (b1 == NULL)
+ equal = -1;
+ else if (b2 == NULL)
+ equal = 1;
+ else{
+ if (xml_cv_cache(x1b, &cv1) < 0) /* error case */
+ goto done;
+ if (xml_cv_cache(x2b, &cv2) < 0) /* error case */
+ goto done;
+ assert(cv1 && cv2);
+ equal = cv_cmp(cv1, cv2);
+ }
+ }
+ if (equal)
+ break;
#endif /* XML_EXPLICIT_INDEX */
- }
- else {
- /* Use Y_LIST cache (see struct yang_stmt) */
- cvk = yang_cvec_get(y1); /* Use Y_LIST cache, see ys_populate_list() */
- cvi = NULL;
- while ((cvi = cvec_each(cvk, cvi)) != NULL) {
- keyname = cv_string_get(cvi); /* operational data may have NULL keys*/
- x1b = xml_find(x1, keyname);
- /* match1: key matching skipped for keys not in x1 (see explanation) */
- if (skip1 && x1b == NULL)
- continue;
- x2b = xml_find(x2, keyname);
- if (x1b == NULL && x2b == NULL)
- ;
- else if (x1b == NULL)
- equal = -1;
- else if (x2b == NULL)
- equal = 1;
- else{
- b1 = xml_body(x1b);
- b2 = xml_body(x2b);
- if (b1 == NULL && b2 == NULL)
- ;
- else if (b1 == NULL)
- equal = -1;
- else if (b2 == NULL)
- equal = 1;
- else{
- if (xml_cv_cache(x1b, &cv1) < 0) /* error case */
- goto done;
- if (xml_cv_cache(x2b, &cv2) < 0) /* error case */
- goto done;
- assert(cv1 && cv2);
- equal = cv_cmp(cv1, cv2);
- }
- }
- if (equal)
- break;
- } /* while cvi */
- }
- break;
+ }
+ else {
+ /* Use Y_LIST cache (see struct yang_stmt) */
+ cvk = yang_cvec_get(y1); /* Use Y_LIST cache, see ys_populate_list() */
+ cvi = NULL;
+ while ((cvi = cvec_each(cvk, cvi)) != NULL) {
+ keyname = cv_string_get(cvi); /* operational data may have NULL keys*/
+ x1b = xml_find(x1, keyname);
+ /* match1: key matching skipped for keys not in x1 (see explanation) */
+ if (skip1 && x1b == NULL)
+ continue;
+ x2b = xml_find(x2, keyname);
+ if (x1b == NULL && x2b == NULL)
+ ;
+ else if (x1b == NULL)
+ equal = -1;
+ else if (x2b == NULL)
+ equal = 1;
+ else{
+ b1 = xml_body(x1b);
+ b2 = xml_body(x2b);
+ if (b1 == NULL && b2 == NULL)
+ ;
+ else if (b1 == NULL)
+ equal = -1;
+ else if (b2 == NULL)
+ equal = 1;
+ else{
+ if (xml_cv_cache(x1b, &cv1) < 0) /* error case */
+ goto done;
+ if (xml_cv_cache(x2b, &cv2) < 0) /* error case */
+ goto done;
+ assert(cv1 && cv2);
+ equal = cv_cmp(cv1, cv2);
+ }
+ }
+ if (equal)
+ break;
+ } /* while cvi */
+ }
+ break;
default:
- /* This is a very special case such as for two choices - which is not validation correct, but we
- should sort them according to nr1, nr2 since their yang is equal order */
- if (same)
- equal = nr1-nr2;
- break;
+ /* This is a very special case such as for two choices - which is not validation correct, but we
+ should sort them according to nr1, nr2 since their yang is equal order */
+ if (same)
+ equal = nr1-nr2;
+ break;
} /* switch */
done:
clicon_debug(3, "%s %s %s eq:%d nr: %d %d yi: %d %d", __FUNCTION__, xml_name(x1), xml_name(x2), equal, nr1, nr2, yi1, yi2);
@@ -393,7 +393,7 @@ xml_cmp(cxobj *x1,
*/
static int
xml_cmp_qsort(const void* arg1,
- const void* arg2)
+ const void* arg2)
{
return xml_cmp(*(struct xml**)arg1, *(struct xml**)arg2, 1, 0, NULL);
}
@@ -414,8 +414,8 @@ xml_sort(cxobj *x)
yang_stmt *ys;
/* Abort sort if non-config (=state) data */
- if ((ys = xml_spec(x)) != 0 && yang_config(ys)==0)
- return 1;
+ if ((ys = xml_spec(x)) != 0 && yang_config(ys)==0)
+ return 1;
#endif
xml_enumerate_children(x); /* This is to make sorting "stable", ie not change existing order */
qsort(xml_childvec_get(x), xml_child_nr(x), sizeof(cxobj *), xml_cmp_qsort);
@@ -434,19 +434,19 @@ xml_sort_recurse(cxobj *xn)
ret = xml_sort_verify(xn, NULL);
if (ret == 1) /* This node is not sortable */
- goto ok;
+ goto ok;
if (ret == -1){ /* not sorted */
- if ((ret = xml_sort(xn)) < 0)
- goto done;
- if (ret == 1) /* This node is not sortable */
- goto ok;
+ if ((ret = xml_sort(xn)) < 0)
+ goto done;
+ if (ret == 1) /* This node is not sortable */
+ goto ok;
}
if (xml_cv_cache_clear(xn) < 0)
- goto done;
+ goto done;
x = NULL;
while ((x = xml_child_each(xn, x, CX_ELMNT)) != NULL) {
- if (xml_sort_recurse(x) < 0)
- goto done;
+ if (xml_sort_recurse(x) < 0)
+ goto done;
}
ok:
retval = 0;
@@ -467,11 +467,11 @@ xml_sort_recurse(cxobj *xn)
*/
static int
xml_find_keys_notsorted(cxobj *xp,
- cxobj *x1,
- int yangi,
- int mid,
- int skip1,
- clixon_xvec *xvec)
+ cxobj *x1,
+ int yangi,
+ int mid,
+ int skip1,
+ clixon_xvec *xvec)
{
int retval = -1;
int i;
@@ -480,30 +480,30 @@ xml_find_keys_notsorted(cxobj *xp,
int yi;
for (i=mid+1; i=0; i--){ /* Then decrement */
- xc = xml_child_i(xp, i);
- yc = xml_spec(xc);
- if ((yi = yang_order(yc)) < -1)
- goto done;
- if (yangi != yi) /* wrong yang */
- break;
- if (xml_cmp(xc, x1, 0, skip1, NULL) == 0){
- if (clixon_xvec_append(xvec, xc) < 0)
- goto done;
- goto ok; /* found */
- }
+ xc = xml_child_i(xp, i);
+ yc = xml_spec(xc);
+ if ((yi = yang_order(yc)) < -1)
+ goto done;
+ if (yangi != yi) /* wrong yang */
+ break;
+ if (xml_cmp(xc, x1, 0, skip1, NULL) == 0){
+ if (clixon_xvec_append(xvec, xc) < 0)
+ goto done;
+ goto ok; /* found */
+ }
}
ok:
retval = 0;
@@ -523,12 +523,12 @@ xml_find_keys_notsorted(cxobj *xp,
*/
static int
search_multi_equals(cxobj **childvec,
- size_t childlen,
- cxobj *x1,
- int yangi,
- int mid,
- int skip1,
- clixon_xvec *xvec)
+ size_t childlen,
+ cxobj *x1,
+ int yangi,
+ int mid,
+ int skip1,
+ clixon_xvec *xvec)
{
int retval = -1;
int i;
@@ -537,28 +537,28 @@ search_multi_equals(cxobj **childvec,
int yi;
for (i=mid-1; i>=0; i--){ /* First decrement */
- xc = childvec[i];
- yc = xml_spec(xc);
- if ((yi = yang_order(yc)) < -1)
- goto done;
- if (yangi != yi) /* wrong yang */
- break;
- if (xml_cmp(x1, xc, 0, skip1, NULL) != 0)
- break;
- if (clixon_xvec_prepend(xvec, xc) < 0)
- goto done;
+ xc = childvec[i];
+ yc = xml_spec(xc);
+ if ((yi = yang_order(yc)) < -1)
+ goto done;
+ if (yangi != yi) /* wrong yang */
+ break;
+ if (xml_cmp(x1, xc, 0, skip1, NULL) != 0)
+ break;
+ if (clixon_xvec_prepend(xvec, xc) < 0)
+ goto done;
}
for (i=mid+1; i=0; i--){ /* First decrement */
- xc = clixon_xvec_i(childvec, i);
- yc = xml_spec(xc);
- if ((yi = yang_order(yc)) < -1)
- goto done;
- if (yangi != yi) /* wrong yang */
- break;
- if (xml_cmp(x1, xc, 0, skip1, NULL) != 0)
- break;
- if (clixon_xvec_prepend(xvec, xc) < 0)
- goto done;
+ xc = clixon_xvec_i(childvec, i);
+ yc = xml_spec(xc);
+ if ((yi = yang_order(yc)) < -1)
+ goto done;
+ if (yangi != yi) /* wrong yang */
+ break;
+ if (xml_cmp(x1, xc, 0, skip1, NULL) != 0)
+ break;
+ if (clixon_xvec_prepend(xvec, xc) < 0)
+ goto done;
}
for (i=mid+1; iupper %d %d", low, upper);
- goto done;
+ clicon_err(OE_XML, 0, "low>upper %d %d", low, upper);
+ goto done;
}
if (low == upper){
- retval = low;
- goto done;
+ retval = low;
+ goto done;
}
mid = (low + upper) / 2;
if (mid >= max){ /* beyond range */
- clicon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper);
- goto done;
+ clicon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper);
+ goto done;
}
xc = clixon_xvec_i(ivec, mid);
/* >0 means search upper interval, <0 lower interval, = 0 is equal */
@@ -656,25 +656,25 @@ xml_search_indexvar_binary_pos(cxobj *x1,
if (low +1 == upper){ /* termination criterium */
}
if (cmp == 0){
- retval = mid; /* equal */
- if (eq)
- *eq = 1;
- goto done;
+ retval = mid; /* equal */
+ if (eq)
+ *eq = 1;
+ goto done;
}
else {
- if (low +1 == upper){ /* termination criterium */
- if (eq) /* No exact match */
- *eq = 0;
- if (cmp < 0) /* return either 0 if cmp<0 or +1 if cmp>0 */
- retval = mid;
- else
- retval = mid+1;
- goto done;
- }
- if (cmp < 0)
- return xml_search_indexvar_binary_pos(x1, indexvar, ivec, low, mid, max, eq);
- else
- return xml_search_indexvar_binary_pos(x1, indexvar, ivec, mid+1, upper, max, eq);
+ if (low +1 == upper){ /* termination criterium */
+ if (eq) /* No exact match */
+ *eq = 0;
+ if (cmp < 0) /* return either 0 if cmp<0 or +1 if cmp>0 */
+ retval = mid;
+ else
+ retval = mid+1;
+ goto done;
+ }
+ if (cmp < 0)
+ return xml_search_indexvar_binary_pos(x1, indexvar, ivec, low, mid, max, eq);
+ else
+ return xml_search_indexvar_binary_pos(x1, indexvar, ivec, mid+1, upper, max, eq);
}
done:
return retval;
@@ -682,12 +682,12 @@ xml_search_indexvar_binary_pos(cxobj *x1,
static int
xml_search_indexvar(cxobj *xp,
- cxobj *x1,
- int yangi,
- int low,
- int upper,
- char *indexvar,
- clixon_xvec *xvec)
+ cxobj *x1,
+ int yangi,
+ int low,
+ int upper,
+ char *indexvar,
+ clixon_xvec *xvec)
{
int retval = -1;
clixon_xvec *ivec = NULL;
@@ -698,22 +698,22 @@ xml_search_indexvar(cxobj *xp,
/* Check if (exactly one) explicit indexes in cvk */
if (xml_search_vector_get(xp, indexvar, &ivec) < 0)
- goto done;
+ goto done;
if (ivec){
- ilen = clixon_xvec_len(ivec);
- if ((pos = xml_search_indexvar_binary_pos(x1, indexvar,
- ivec, 0,
- ilen, ilen, &eq)) < 0)
- goto done;
- if (eq){ /* Found */
- xc = clixon_xvec_i(ivec, pos);
- if (clixon_xvec_append(xvec, xc) < 0)
- goto done;
- /* there may be more? */
- if (search_multi_equals_xvec(ivec, x1, yangi, pos,
- 0, xvec) < 0)
- goto done;
- }
+ ilen = clixon_xvec_len(ivec);
+ if ((pos = xml_search_indexvar_binary_pos(x1, indexvar,
+ ivec, 0,
+ ilen, ilen, &eq)) < 0)
+ goto done;
+ if (eq){ /* Found */
+ xc = clixon_xvec_i(ivec, pos);
+ if (clixon_xvec_append(xvec, xc) < 0)
+ goto done;
+ /* there may be more? */
+ if (search_multi_equals_xvec(ivec, x1, yangi, pos,
+ 0, xvec) < 0)
+ goto done;
+ }
}
retval = 0;
done:
@@ -736,14 +736,14 @@ xml_search_indexvar(cxobj *xp,
*/
static int
xml_search_binary(cxobj *xp,
- cxobj *x1,
- int sorted,
- int yangi,
- int low,
- int upper,
- int skip1,
- char *indexvar,
- clixon_xvec *xvec)
+ cxobj *x1,
+ int sorted,
+ int yangi,
+ int low,
+ int upper,
+ int skip1,
+ char *indexvar,
+ clixon_xvec *xvec)
{
int retval = -1;
int mid;
@@ -753,44 +753,44 @@ xml_search_binary(cxobj *xp,
int yi;
if (upper < low)
- goto ok;
+ goto ok;
mid = (low + upper) / 2;
if (mid >= xml_child_nr(xp)) /* beyond range */
- goto ok;
+ goto ok;
xc = xml_child_i(xp, mid);
if ((y = xml_spec(xc)) == NULL)
- goto ok;
+ goto ok;
if ((yi = yang_order(y)) < -1)
- goto done;
+ goto done;
cmp = yangi - yi;
/* Here is right yang order == same yang? */
if (cmp == 0){
#ifdef XML_EXPLICIT_INDEX
- if (indexvar){
- if (xml_search_indexvar(xp, x1, yangi, low, upper, indexvar, xvec) < 0)
- goto done;
- goto ok;
- }
+ if (indexvar){
+ if (xml_search_indexvar(xp, x1, yangi, low, upper, indexvar, xvec) < 0)
+ goto done;
+ goto ok;
+ }
#endif
- /* >0 means search upper interval, <0 lower interval, = 0 is equal */
- cmp = xml_cmp(x1, xc, 0, skip1, NULL);
- if (cmp && !sorted){ /* Ordered by user (if not equal) */
- retval = xml_find_keys_notsorted(xp, x1, yangi, mid, skip1, xvec);
- goto done;
- }
+ /* >0 means search upper interval, <0 lower interval, = 0 is equal */
+ cmp = xml_cmp(x1, xc, 0, skip1, NULL);
+ if (cmp && !sorted){ /* Ordered by user (if not equal) */
+ retval = xml_find_keys_notsorted(xp, x1, yangi, mid, skip1, xvec);
+ goto done;
+ }
}
if (cmp == 0){
- if (clixon_xvec_append(xvec, xc) < 0)
- goto done;
- /* there may be more? */
- if (search_multi_equals(xml_childvec_get(xp), xml_child_nr(xp),
- x1, yangi, mid, skip1, xvec) < 0)
- goto done;
+ if (clixon_xvec_append(xvec, xc) < 0)
+ goto done;
+ /* there may be more? */
+ if (search_multi_equals(xml_childvec_get(xp), xml_child_nr(xp),
+ x1, yangi, mid, skip1, xvec) < 0)
+ goto done;
}
else if (cmp < 0)
- xml_search_binary(xp, x1, sorted, yangi, low, mid-1, skip1, indexvar, xvec);
+ xml_search_binary(xp, x1, sorted, yangi, low, mid-1, skip1, indexvar, xvec);
else
- xml_search_binary(xp, x1, sorted, yangi, mid+1, upper, skip1, indexvar, xvec);
+ xml_search_binary(xp, x1, sorted, yangi, mid+1, upper, skip1, indexvar, xvec);
ok:
retval = 0;
done:
@@ -815,11 +815,11 @@ xml_search_binary(cxobj *xp,
*/
static int
xml_search_yang(cxobj *xp,
- cxobj *x1,
- yang_stmt *yc,
- int skip1,
- char *indexvar,
- clixon_xvec *xvec)
+ cxobj *x1,
+ yang_stmt *yc,
+ int skip1,
+ char *indexvar,
+ clixon_xvec *xvec)
{
int retval = -1;
cxobj *xa;
@@ -829,27 +829,27 @@ xml_search_yang(cxobj *xp,
int yangi;
if (xp == NULL){
- clicon_err(OE_XML, EINVAL, "xp is NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "xp is NULL");
+ goto done;
}
upper = xml_child_nr(xp);
/* Assume if there are any attributes, they are first in the list, mask
them by raising low to skip them */
for (low=0; low=0; i--){ /* decrement */
- xc = xml_child_i(xp, i);
- yc = xml_spec(xc);
- if (yc != yn){
- retval = i+1;
- goto done;
- }
- }
- retval = i+1;
- break;
+ for (i=mid-1; i>=0; i--){ /* decrement */
+ xc = xml_child_i(xp, i);
+ yc = xml_spec(xc);
+ if (yc != yn){
+ retval = i+1;
+ goto done;
+ }
+ }
+ retval = i+1;
+ break;
case INS_LAST:
- for (i=mid+1; i upper){ /* beyond range */
- clicon_err(OE_XML, 0, "low>upper %d %d", low, upper);
- goto done;
+ clicon_err(OE_XML, 0, "low>upper %d %d", low, upper);
+ goto done;
}
if (low == upper){
- retval = low;
- goto done;
+ retval = low;
+ goto done;
}
mid = (low + upper) / 2;
if (mid >= xml_child_nr(xp)){ /* beyond range */
- clicon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper);
- goto done;
+ clicon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper);
+ goto done;
}
xc = xml_child_i(xp, mid);
if ((yc = xml_spec(xc)) == NULL){
- if (xml_type(xc) != CX_ELMNT)
- clicon_err(OE_XML, 0, "No spec found %s (wrong xml type:%s)",
- xml_name(xc), xml_type2str(xml_type(xc)));
- else
- clicon_err(OE_XML, 0, "No spec found %s", xml_name(xc));
- goto done;
+ if (xml_type(xc) != CX_ELMNT)
+ clicon_err(OE_XML, 0, "No spec found %s (wrong xml type:%s)",
+ xml_name(xc), xml_type2str(xml_type(xc)));
+ else
+ clicon_err(OE_XML, 0, "No spec found %s", xml_name(xc));
+ goto done;
}
if (yc == yn){ /* Same yang */
- if (userorder){ /* append: increment linearly until no longer equal */
- retval = xml_insert_userorder(xp, xn, yn, mid, ins, key_val, nsc_key);
- goto done;
- }
- else /* Ordered by system */
- cmp = xml_cmp(xn, xc, 0, 0, NULL);
+ if (userorder){ /* append: increment linearly until no longer equal */
+ retval = xml_insert_userorder(xp, xn, yn, mid, ins, key_val, nsc_key);
+ goto done;
+ }
+ else /* Ordered by system */
+ cmp = xml_cmp(xn, xc, 0, 0, NULL);
}
else{ /* Not equal yang - compute diff */
- if ((yi = yang_order(yc)) < -1)
- goto done;
- cmp = yni - yi;
- /* One case is a choice where
- * xc = , xn =
- * same order but different yang spec
- */
+ if ((yi = yang_order(yc)) < -1)
+ goto done;
+ cmp = yni - yi;
+ /* One case is a choice where
+ * xc = , xn =
+ * same order but different yang spec
+ */
}
if (low +1 == upper){ /* termination criterium */
- if (cmp<0) {
- retval = mid;
- goto done;
- }
- retval = mid+1;
- goto done;
+ if (cmp<0) {
+ retval = mid;
+ goto done;
+ }
+ retval = mid+1;
+ goto done;
}
if (cmp == 0){
- retval = mid;
- goto done;
+ retval = mid;
+ goto done;
}
else if (cmp < 0)
- return xml_insert2(xp, xn, yn, yni, userorder, ins, key_val, nsc_key, low, mid);
+ return xml_insert2(xp, xn, yn, yni, userorder, ins, key_val, nsc_key, low, mid);
else
- return xml_insert2(xp, xn, yn, yni, userorder, ins, key_val, nsc_key, mid+1, upper);
+ return xml_insert2(xp, xn, yn, yni, userorder, ins, key_val, nsc_key, mid+1, upper);
done:
return retval;
}
@@ -1055,10 +1055,10 @@ xml_insert2(cxobj *xp,
*/
int
xml_insert(cxobj *xp,
- cxobj *xi,
- enum insert_type ins,
- char *key_val,
- cvec *nsc_key)
+ cxobj *xi,
+ enum insert_type ins,
+ char *key_val,
+ cvec *nsc_key)
{
int retval = -1;
cxobj *xa;
@@ -1073,35 +1073,35 @@ xml_insert(cxobj *xp,
* added as a child
*/
if (xml_parent(xi) != NULL){
- clicon_err(OE_XML, 0, "XML node %s should not have parent", xml_name(xi));
- goto done;
+ clicon_err(OE_XML, 0, "XML node %s should not have parent", xml_name(xi));
+ goto done;
}
if ((y = xml_spec(xi)) == NULL){
- clicon_err(OE_XML, 0, "No spec found %s", xml_name(xi));
- goto done;
+ clicon_err(OE_XML, 0, "No spec found %s", xml_name(xi));
+ goto done;
}
upper = xml_child_nr(xp);
/* Assume if there are any attributes, they are first in the list, mask
them by raising low to skip them */
for (low=0; low 0)
- goto done;
- }
- xprev = x;
- }
+ xml_enumerate_children(x0);
+ while ((x = xml_child_each(x0, x, -1)) != NULL) {
+ if (xprev != NULL){ /* Check xprev <= x */
+ if (xml_cmp(xprev, x, 1, 0, NULL) > 0)
+ goto done;
+ }
+ xprev = x;
+ }
}
retval = 0;
done:
@@ -1162,9 +1162,9 @@ xml_sort_verify(cxobj *x0,
*/
int
match_base_child(cxobj *x0,
- cxobj *x1c,
- yang_stmt *yc,
- cxobj **x0cp)
+ cxobj *x1c,
+ yang_stmt *yc,
+ cxobj **x0cp)
{
int retval = -1;
cvec *cvk = NULL; /* vector of index keys */
@@ -1176,40 +1176,40 @@ match_base_child(cxobj *x0,
*x0cp = NULL; /* init return value */
/* Revert to simple xml lookup if no yang */
if (yc == NULL){
- *x0cp = xml_find(x0, xml_name(x1c));
- goto ok;
+ *x0cp = xml_find(x0, xml_name(x1c));
+ goto ok;
}
switch (yang_keyword_get(yc)){
- case Y_CONTAINER: /* Equal regardless */
- case Y_LEAF: /* Equal regardless */
- break;
+ case Y_CONTAINER: /* Equal regardless */
+ case Y_LEAF: /* Equal regardless */
+ break;
case Y_LEAF_LIST: /* Match with name and value */
- if (xml_body(x1c) == NULL) /* Treat as empty string */
- goto ok;
- break;
+ if (xml_body(x1c) == NULL) /* Treat as empty string */
+ goto ok;
+ break;
case Y_LIST: /* Match with key values */
- cvk = yang_cvec_get(yc); /* Use Y_LIST cache, see ys_populate_list() */
- cvi = NULL;
- while ((cvi = cvec_each(cvk, cvi)) != NULL) {
- keyname = cv_string_get(cvi);
- if ((xb = xml_find(x1c, keyname)) == NULL)
- goto ok;
- }
+ cvk = yang_cvec_get(yc); /* Use Y_LIST cache, see ys_populate_list() */
+ cvi = NULL;
+ while ((cvi = cvec_each(cvk, cvi)) != NULL) {
+ keyname = cv_string_get(cvi);
+ if ((xb = xml_find(x1c, keyname)) == NULL)
+ goto ok;
+ }
default:
- break;
+ break;
}
if ((xvec = clixon_xvec_new()) == NULL)
- goto done;
+ goto done;
/* Get match. */
if (xml_search_yang(x0, x1c, yc, 0, 0, xvec) < 0)
- goto done;
+ goto done;
if (clixon_xvec_len(xvec))
- *x0cp = clixon_xvec_i(xvec, 0);
+ *x0cp = clixon_xvec_i(xvec, 0);
ok:
retval = 0;
done:
if (xvec)
- clixon_xvec_free(xvec);
+ clixon_xvec_free(xvec);
return retval;
}
@@ -1217,9 +1217,9 @@ match_base_child(cxobj *x0,
*/
static int
xml_find_noyang_cvk(char *ns0,
- cxobj *xc,
- cvec *cvk,
- clixon_xvec *xvec)
+ cxobj *xc,
+ cvec *cvk,
+ clixon_xvec *xvec)
{
int retval = -1;
cg_var *cvi;
@@ -1232,39 +1232,39 @@ xml_find_noyang_cvk(char *ns0,
cvi = NULL;
/* Loop through index variables. xc should match all, on exit if cvi=NULL it macthes */
while ((cvi = cvec_each(cvk, cvi)) != NULL) {
- keyname = cv_name_get(cvi);
- keyval = cv_string_get(cvi);
- if (keyname==NULL || strcmp(keyname, ".")==0){ /* Index variable on form .= (self) */
- body = xml_body(xc);
- if ((body==NULL && (keyval==NULL || strlen(keyval) == 0)) || /* both null, break */
- (body != NULL && strcmp(body, keyval) == 0)) /* Name match, break */
- continue; /* match */
- break; /* nomatch */
- }
- else{
- /* Index variable on form =
- * Loop through children of the matched x (to match keyname and value) */
- xcc = NULL;
- while ((xcc = xml_child_each(xc, xcc, CX_ELMNT)) != NULL) {
- if (xml2ns(xcc, xml_prefix(xcc), &ns) < 0)
- goto done;
- if (strcmp(ns0, ns) != 0) /* Namespace does not match, skip */
- continue;
- if (strcmp(keyname, xml_name(xcc)) != 0) /* Name does not match, skip */
- continue;
- body = xml_body(xcc);
- if (body==NULL && (keyval==NULL || strlen(keyval) == 0)) /* both null, break */
- break;
- if (body != NULL && strcmp(body, keyval) == 0) /* Name match, break */
- break;
- }
- if (xcc == NULL)
- break; /* No match found */
- }
+ keyname = cv_name_get(cvi);
+ keyval = cv_string_get(cvi);
+ if (keyname==NULL || strcmp(keyname, ".")==0){ /* Index variable on form .= (self) */
+ body = xml_body(xc);
+ if ((body==NULL && (keyval==NULL || strlen(keyval) == 0)) || /* both null, break */
+ (body != NULL && strcmp(body, keyval) == 0)) /* Name match, break */
+ continue; /* match */
+ break; /* nomatch */
+ }
+ else{
+ /* Index variable on form =
+ * Loop through children of the matched x (to match keyname and value) */
+ xcc = NULL;
+ while ((xcc = xml_child_each(xc, xcc, CX_ELMNT)) != NULL) {
+ if (xml2ns(xcc, xml_prefix(xcc), &ns) < 0)
+ goto done;
+ if (strcmp(ns0, ns) != 0) /* Namespace does not match, skip */
+ continue;
+ if (strcmp(keyname, xml_name(xcc)) != 0) /* Name does not match, skip */
+ continue;
+ body = xml_body(xcc);
+ if (body==NULL && (keyval==NULL || strlen(keyval) == 0)) /* both null, break */
+ break;
+ if (body != NULL && strcmp(body, keyval) == 0) /* Name match, break */
+ break;
+ }
+ if (xcc == NULL)
+ break; /* No match found */
+ }
}
if (cvi == NULL) /* means we iterated through all indexes without breaks */
- if (clixon_xvec_append(xvec, xc) < 0)
- goto done;
+ if (clixon_xvec_append(xvec, xc) < 0)
+ goto done;
retval = 0;
done:
return retval;
@@ -1275,10 +1275,10 @@ xml_find_noyang_cvk(char *ns0,
*/
static int
xml_find_noyang_name(cxobj *xp,
- char *ns0,
- char *name,
- cvec *cvk,
- clixon_xvec *xvec)
+ char *ns0,
+ char *name,
+ cvec *cvk,
+ clixon_xvec *xvec)
{
int retval = -1;
@@ -1286,28 +1286,28 @@ xml_find_noyang_name(cxobj *xp,
char *ns;
if (name == NULL || ns0 == NULL){
- clicon_err(OE_XML, EINVAL, "name and namespace required");
- goto done;
+ clicon_err(OE_XML, EINVAL, "name and namespace required");
+ goto done;
}
/* Go through children linearly */
xc = NULL;
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL) {
- ns = NULL;
- if (xml2ns(xc, xml_prefix(xc), &ns) < 0)
- goto done;
- if (ns == NULL)
- continue;
- if (strcmp(ns0, ns) != 0) /* Namespace does not match, skip */
- continue;
- if (strcmp(name, xml_name(xc)) != 0) /* Namespace does not match, skip */
- continue;
- if (cvk){ /* Check indexes */
- if (xml_find_noyang_cvk(ns0, xc, cvk, xvec) < 0)
- goto done;
- }
- else /* No index variables: just add node to found list */
- if (clixon_xvec_append(xvec, xc) < 0)
- goto done;
+ ns = NULL;
+ if (xml2ns(xc, xml_prefix(xc), &ns) < 0)
+ goto done;
+ if (ns == NULL)
+ continue;
+ if (strcmp(ns0, ns) != 0) /* Namespace does not match, skip */
+ continue;
+ if (strcmp(name, xml_name(xc)) != 0) /* Namespace does not match, skip */
+ continue;
+ if (cvk){ /* Check indexes */
+ if (xml_find_noyang_cvk(ns0, xc, cvk, xvec) < 0)
+ goto done;
+ }
+ else /* No index variables: just add node to found list */
+ if (clixon_xvec_append(xvec, xc) < 0)
+ goto done;
}
retval = 0;
done:
@@ -1333,9 +1333,9 @@ xml_find_noyang_name(cxobj *xp,
*/
static int
xml_find_index_yang(cxobj *xp,
- yang_stmt *yc,
- cvec *cvk,
- clixon_xvec *xvec)
+ yang_stmt *yc,
+ cvec *cvk,
+ clixon_xvec *xvec)
{
int retval = -1;
cxobj *xc = NULL;
@@ -1353,106 +1353,106 @@ xml_find_index_yang(cxobj *xp,
char *indexvar = NULL;
if (xp == NULL){
- clicon_err(OE_XML, EINVAL, "xp is NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "xp is NULL");
+ goto done;
}
name = yang_argument_get(yc);
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
switch (yang_keyword_get(yc)){
case Y_LIST:
- cprintf(cb, "<%s>", name);
- ycvk = yang_cvec_get(yc); /* Check that those are proper index keys */
- cvi = NULL;
- if (cvk == NULL){ /* If list and no keys, all should match */
- revert++;
- break;
- }
- i = 0;
- while ((cvi = cvec_each(cvk, cvi)) != NULL) {
- if ((kname = cv_name_get(cvi)) == NULL){
- clicon_err(OE_YANG, ENOENT, "missing yang key name in cvk");
- goto done;
- }
- /* Parameter in cvk is not key or not in right key order, then we cannot call
- * xml_find_keys and we need to revert to noyang
- */
- if ((ycv = cvec_i(ycvk, i)) == NULL || strcmp(kname, cv_string_get(ycv))){
- revert++;
- break;
- }
- if (xml_chardata_encode(&encstr, "%s", cv_string_get(cvi)) < 0)
- goto done;
- cprintf(cb, "<%s>%s%s>", kname, encstr, kname);
- free(encstr);
- i++;
- }
- if (revert)
- break;
- cprintf(cb, "%s>", name);
- break;
+ cprintf(cb, "<%s>", name);
+ ycvk = yang_cvec_get(yc); /* Check that those are proper index keys */
+ cvi = NULL;
+ if (cvk == NULL){ /* If list and no keys, all should match */
+ revert++;
+ break;
+ }
+ i = 0;
+ while ((cvi = cvec_each(cvk, cvi)) != NULL) {
+ if ((kname = cv_name_get(cvi)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "missing yang key name in cvk");
+ goto done;
+ }
+ /* Parameter in cvk is not key or not in right key order, then we cannot call
+ * xml_find_keys and we need to revert to noyang
+ */
+ if ((ycv = cvec_i(ycvk, i)) == NULL || strcmp(kname, cv_string_get(ycv))){
+ revert++;
+ break;
+ }
+ if (xml_chardata_encode(&encstr, "%s", cv_string_get(cvi)) < 0)
+ goto done;
+ cprintf(cb, "<%s>%s%s>", kname, encstr, kname);
+ free(encstr);
+ i++;
+ }
+ if (revert)
+ break;
+ cprintf(cb, "%s>", name);
+ break;
case Y_LEAF_LIST:
- if (cvec_len(cvk) != 1){
- clicon_err(OE_YANG, ENOENT, "expected exactly one leaf-list key");
- goto done;
- }
- cvi = cvec_i(cvk, 0);
- if (xml_chardata_encode(&encstr, "%s", cv_string_get(cvi)) < 0)
- goto done;
- cprintf(cb, "<%s>%s%s>", name, encstr, name);
- free(encstr);
- break;
+ if (cvec_len(cvk) != 1){
+ clicon_err(OE_YANG, ENOENT, "expected exactly one leaf-list key");
+ goto done;
+ }
+ cvi = cvec_i(cvk, 0);
+ if (xml_chardata_encode(&encstr, "%s", cv_string_get(cvi)) < 0)
+ goto done;
+ cprintf(cb, "<%s>%s%s>", name, encstr, name);
+ free(encstr);
+ break;
default:
- cprintf(cb, "<%s/>", name);
- break;
+ cprintf(cb, "<%s/>", name);
+ break;
}
#ifdef XML_EXPLICIT_INDEX
if (revert){
- char *iname;
- yang_stmt *yi;
- if (cvec_len(cvk) != 1 ||
- (cvi = cvec_i(cvk, 0)) == NULL ||
- (iname = cv_name_get(cvi)) == NULL ||
- (yi = yang_find_datanode(yc, iname)) == NULL ||
- yang_flag_get(yi, YANG_FLAG_INDEX) == 0)
- goto revert;
- cbuf_reset(cb);
- if (xml_chardata_encode(&encstr, "%s", cv_string_get(cvi)) < 0)
- goto done;
- cprintf(cb, "<%s><%s>%s%s>%s>", name, iname, encstr, iname, name);
- free(encstr);
- indexvar = iname;
+ char *iname;
+ yang_stmt *yi;
+ if (cvec_len(cvk) != 1 ||
+ (cvi = cvec_i(cvk, 0)) == NULL ||
+ (iname = cv_name_get(cvi)) == NULL ||
+ (yi = yang_find_datanode(yc, iname)) == NULL ||
+ yang_flag_get(yi, YANG_FLAG_INDEX) == 0)
+ goto revert;
+ cbuf_reset(cb);
+ if (xml_chardata_encode(&encstr, "%s", cv_string_get(cvi)) < 0)
+ goto done;
+ cprintf(cb, "<%s><%s>%s%s>%s>", name, iname, encstr, iname, name);
+ free(encstr);
+ indexvar = iname;
}
#else
if (revert)
- goto revert;
+ goto revert;
#endif
if (clixon_xml_parse_string(cbuf_get(cb), YB_NONE, NULL, &xc, NULL) < 0)
- goto done;
+ goto done;
if (xml_rootchild(xc, 0, &xc) < 0)
- goto done;
+ goto done;
/* Populate created XML tree with yang specs */
if (xml_spec_set(xc, yc) < 0)
- goto done;
+ goto done;
xk = NULL;
while ((xk = xml_child_each(xc, xk, CX_ELMNT)) != NULL) {
- if ((yk = yang_find(yc, Y_LEAF, xml_name(xk))) == NULL){
- clicon_err(OE_YANG, ENOENT, "yang spec of key %s not found", xml_name(xk));
- goto done;
- }
- if (xml_spec_set(xk, yk) < 0)
- goto done;
+ if ((yk = yang_find(yc, Y_LEAF, xml_name(xk))) == NULL){
+ clicon_err(OE_YANG, ENOENT, "yang spec of key %s not found", xml_name(xk));
+ goto done;
+ }
+ if (xml_spec_set(xk, yk) < 0)
+ goto done;
}
if (xml_search_yang(xp, xc, yc, 1, indexvar, xvec) < 0)
- goto done;
+ goto done;
retval = 1; /* OK */
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (xc)
- xml_free(xc);
+ xml_free(xc);
return retval;
revert: /* means give up yang/key search, try next (eg explicit/noyang) */
retval = 0;
@@ -1513,45 +1513,45 @@ xml_find_index_yang(cxobj *xp,
*/
int
clixon_xml_find_index(cxobj *xp,
- yang_stmt *yp,
- char *ns,
- char *name,
- cvec *cvk,
- clixon_xvec *xvec)
+ yang_stmt *yp,
+ char *ns,
+ char *name,
+ cvec *cvk,
+ clixon_xvec *xvec)
{
int retval = -1;
int ret;
yang_stmt *yc = NULL;
if (xvec == NULL){
- clicon_err(OE_YANG, EINVAL, "xvec");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "xvec");
+ goto done;
}
if (name == NULL){
- clicon_err(OE_YANG, EINVAL, "name");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "name");
+ goto done;
}
if (yp == NULL)
- yp = xml_spec(xp);
+ yp = xml_spec(xp);
if (yp){/* 2. YANG spec of parent + name derives yc. If not found use just name. */
- if (yang_keyword_get(yp) == Y_SPEC)
- yp = yang_find_module_by_namespace(yp, ns);
- if (yp)
- yc = yang_find_datanode(yp, name);
+ if (yang_keyword_get(yp) == Y_SPEC)
+ yp = yang_find_module_by_namespace(yp, ns);
+ if (yp)
+ yc = yang_find_datanode(yp, name);
}
if (yc){
- if ((ret = xml_find_index_yang(xp, yc, cvk, xvec)) < 0)
- goto done;
- if (ret == 0){ /* This means yang method did not work for some reason
- * such as not being list key indexes in cvk, for example
- */
- if (xml_find_noyang_name(xp, ns, name, cvk, xvec) < 0)
- goto done;
- }
+ if ((ret = xml_find_index_yang(xp, yc, cvk, xvec)) < 0)
+ goto done;
+ if (ret == 0){ /* This means yang method did not work for some reason
+ * such as not being list key indexes in cvk, for example
+ */
+ if (xml_find_noyang_name(xp, ns, name, cvk, xvec) < 0)
+ goto done;
+ }
}
else
- if (xml_find_noyang_name(xp, ns, name, cvk, xvec) < 0)
- goto done;
+ if (xml_find_noyang_name(xp, ns, name, cvk, xvec) < 0)
+ goto done;
retval = 0;
done:
return retval;
@@ -1569,9 +1569,9 @@ clixon_xml_find_index(cxobj *xp,
*/
int
clixon_xml_find_pos(cxobj *xp,
- yang_stmt *yc,
- uint32_t pos,
- clixon_xvec *xvec)
+ yang_stmt *yc,
+ uint32_t pos,
+ clixon_xvec *xvec)
{
int retval = -1;
cxobj *xc = NULL;
@@ -1579,20 +1579,20 @@ clixon_xml_find_pos(cxobj *xp,
uint32_t u;
if (yc == NULL){
- clicon_err(OE_YANG, ENOENT, "yang spec not found");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "yang spec not found");
+ goto done;
}
name = yang_argument_get(yc);
u = 0;
xc = NULL;
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL) {
- if (strcmp(name, xml_name(xc)))
- continue;
- if (pos == u++){ /* Found */
- if (clixon_xvec_append(xvec, xc) < 0)
- goto done;
- break;
- }
+ if (strcmp(name, xml_name(xc)))
+ continue;
+ if (pos == u++){ /* Found */
+ if (clixon_xvec_append(xvec, xc) < 0)
+ goto done;
+ break;
+ }
}
retval = 0;
done:
diff --git a/lib/src/clixon_xml_vec.c b/lib/src/clixon_xml_vec.c
index ab4b5003..d640ce97 100644
--- a/lib/src/clixon_xml_vec.c
+++ b/lib/src/clixon_xml_vec.c
@@ -94,16 +94,16 @@ clixon_xvec_inc(clixon_xvec *xv)
xv->xv_len++;
if (xv->xv_len > xv->xv_max){
- if (xv->xv_max < XVEC_MAX_DEFAULT)
- xv->xv_max = XVEC_MAX_DEFAULT;
- else if (xv->xv_max < XVEC_MAX_THRESHOLD)
- xv->xv_max *= 2; /* Double the space - exponential */
- else
- xv->xv_max += XVEC_MAX_THRESHOLD; /* Add - linear growth */
- if ((xv->xv_vec = realloc(xv->xv_vec, sizeof(cxobj *) * xv->xv_max)) == NULL){
- clicon_err(OE_XML, errno, "realloc");
- goto done;
- }
+ if (xv->xv_max < XVEC_MAX_DEFAULT)
+ xv->xv_max = XVEC_MAX_DEFAULT;
+ else if (xv->xv_max < XVEC_MAX_THRESHOLD)
+ xv->xv_max *= 2; /* Double the space - exponential */
+ else
+ xv->xv_max += XVEC_MAX_THRESHOLD; /* Add - linear growth */
+ if ((xv->xv_vec = realloc(xv->xv_vec, sizeof(cxobj *) * xv->xv_max)) == NULL){
+ clicon_err(OE_XML, errno, "realloc");
+ goto done;
+ }
}
retval = 0;
done:
@@ -123,8 +123,8 @@ clixon_xvec_new(void)
clixon_xvec *xv = NULL;
if ((xv = malloc(sizeof(*xv))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xv, 0, sizeof(*xv));
xv->xv_len = 0;
@@ -146,15 +146,15 @@ clixon_xvec_dup(clixon_xvec *xv0)
clixon_xvec *xv1 = NULL; /* retval */
if ((xv1 = clixon_xvec_new()) == NULL)
- goto done;
+ goto done;
*xv1 = *xv0;
xv1->xv_vec = NULL;
if (xv1->xv_max &&
- (xv1->xv_vec = calloc(xv1->xv_max, sizeof(cxobj*))) == NULL){
- clicon_err(OE_UNIX, errno, "calloc");
- free(xv1);
- xv1 = NULL;
- goto done;
+ (xv1->xv_vec = calloc(xv1->xv_max, sizeof(cxobj*))) == NULL){
+ clicon_err(OE_UNIX, errno, "calloc");
+ free(xv1);
+ xv1 = NULL;
+ goto done;
}
memcpy(xv1->xv_vec, xv0->xv_vec, xv0->xv_len*sizeof(cxobj*));
done:
@@ -167,9 +167,9 @@ int
clixon_xvec_free(clixon_xvec *xv)
{
if (xv->xv_vec)
- free(xv->xv_vec);
+ free(xv->xv_vec);
if (xv)
- free(xv);
+ free(xv);
return 0;
}
@@ -190,12 +190,12 @@ clixon_xvec_len(clixon_xvec *xv)
*/
cxobj*
clixon_xvec_i(clixon_xvec *xv,
- int i)
+ int i)
{
if (i < xv->xv_len)
- return xv->xv_vec[i];
+ return xv->xv_vec[i];
else
- return NULL;
+ return NULL;
}
/*! Return whole XML object vector and null it in original xvec, essentially moving it
@@ -210,24 +210,24 @@ clixon_xvec_i(clixon_xvec *xv,
*/
int
clixon_xvec_extract(clixon_xvec *xv,
- cxobj ***xvec,
- int *xlen,
- int *xmax)
+ cxobj ***xvec,
+ int *xlen,
+ int *xmax)
{
int retval = -1;
if (xv == NULL){
- clicon_err(OE_XML, EINVAL, "xv is NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "xv is NULL");
+ goto done;
}
*xvec = xv->xv_vec;
*xlen = xv->xv_len;
if (xmax)
- *xmax = xv->xv_max;
+ *xmax = xv->xv_max;
if (xv->xv_vec != NULL){
- xv->xv_len = 0;
- xv->xv_max = 0;
- xv->xv_vec = NULL;
+ xv->xv_len = 0;
+ xv->xv_max = 0;
+ xv->xv_vec = NULL;
}
retval = 0;
done:
@@ -248,13 +248,13 @@ clixon_xvec_extract(clixon_xvec *xv,
*/
int
clixon_xvec_append(clixon_xvec *xv,
- cxobj *x)
-
+ cxobj *x)
+
{
int retval = -1;
if (clixon_xvec_inc(xv) < 0)
- goto done;
+ goto done;
xv->xv_vec[xv->xv_len-1] = x;
retval = 0;
done:
@@ -274,17 +274,17 @@ clixon_xvec_append(clixon_xvec *xv,
*/
int
clixon_xvec_merge(clixon_xvec *xv0,
- clixon_xvec *xv1)
+ clixon_xvec *xv1)
{
int retval = -1;
cxobj *x;
int i;
for (i=0; ixv_vec[xv0->xv_len-1] = x;
+ x = clixon_xvec_i(xv1, i);
+ if (clixon_xvec_inc(xv0) < 0)
+ goto done;
+ xv0->xv_vec[xv0->xv_len-1] = x;
}
retval = 0;
done:
@@ -305,12 +305,12 @@ clixon_xvec_merge(clixon_xvec *xv0,
*/
int
clixon_xvec_prepend(clixon_xvec *xv,
- cxobj *x)
+ cxobj *x)
{
int retval = -1;
if (clixon_xvec_inc(xv) < 0)
- goto done;
+ goto done;
memmove(&xv->xv_vec[1], &xv->xv_vec[0], sizeof(cxobj *) * (xv->xv_len-1));
xv->xv_vec[0] = x;
retval = 0;
@@ -328,14 +328,14 @@ clixon_xvec_prepend(clixon_xvec *xv,
*/
int
clixon_xvec_insert_pos(clixon_xvec *xv,
- cxobj *x,
- int i)
+ cxobj *x,
+ int i)
{
int retval = -1;
size_t size;
if (clixon_xvec_inc(xv) < 0)
- goto done;
+ goto done;
size = (xv->xv_len - i -1)*sizeof(cxobj *);
memmove(&xv->xv_vec[i+1], &xv->xv_vec[i], size);
xv->xv_vec[i] = x;
@@ -353,7 +353,7 @@ clixon_xvec_insert_pos(clixon_xvec *xv,
*/
int
clixon_xvec_rm_pos(clixon_xvec *xv,
- int i)
+ int i)
{
size_t size;
@@ -372,13 +372,13 @@ clixon_xvec_rm_pos(clixon_xvec *xv,
*/
int
clixon_xvec_print(FILE *f,
- clixon_xvec *xv)
+ clixon_xvec *xv)
{
int i;
for (i=0; ixv_len; i++)
- if (clixon_xml2file(f, xv->xv_vec[i], 0, 1, fprintf, 0, 0) < 0)
- return -1;
+ if (clixon_xml2file(f, xv->xv_vec[i], 0, 1, fprintf, 0, 0) < 0)
+ return -1;
return 0;
}
diff --git a/lib/src/clixon_xpath.c b/lib/src/clixon_xpath.c
index 62d28e6f..1bf1dff9 100644
--- a/lib/src/clixon_xpath.c
+++ b/lib/src/clixon_xpath.c
@@ -177,30 +177,30 @@ xpath_tree_int2str(int nodetype)
/*! Print XPATH parse tree */
static int
xpath_tree_print0(cbuf *cb,
- xpath_tree *xs,
- int level)
+ xpath_tree *xs,
+ int level)
{
cprintf(cb, "%*s%s:", level*3, "", xpath_tree_int2str(xs->xs_type));
if (xs->xs_s0)
- cprintf(cb, "\"%s\" ", xs->xs_s0);
+ cprintf(cb, "\"%s\" ", xs->xs_s0);
if (xs->xs_s1)
- cprintf(cb,"\"%s\" ", xs->xs_s1);
+ cprintf(cb,"\"%s\" ", xs->xs_s1);
if (xs->xs_int)
- switch (xs->xs_type){
- case XP_STEP:
- cprintf(cb, "%s", axis_type_int2str(xs->xs_int));
- break;
- default:
- cprintf(cb, "%d ", xs->xs_int);
- break;
- }
+ switch (xs->xs_type){
+ case XP_STEP:
+ cprintf(cb, "%s", axis_type_int2str(xs->xs_int));
+ break;
+ default:
+ cprintf(cb, "%d ", xs->xs_int);
+ break;
+ }
if (xs->xs_strnr)
- cprintf(cb,"%s ", xs->xs_strnr);
+ cprintf(cb,"%s ", xs->xs_strnr);
cprintf(cb, "\n");
if (xs->xs_c0)
- xpath_tree_print0(cb, xs->xs_c0,level+1);
+ xpath_tree_print0(cb, xs->xs_c0,level+1);
if (xs->xs_c1)
- xpath_tree_print0(cb, xs->xs_c1, level+1);
+ xpath_tree_print0(cb, xs->xs_c1, level+1);
return 0;
}
@@ -210,7 +210,7 @@ xpath_tree_print0(cbuf *cb,
*/
int
xpath_tree_print_cb(cbuf *cb,
- xpath_tree *xs)
+ xpath_tree *xs)
{
xpath_tree_print0(cb, xs, 0);
return 0;
@@ -223,17 +223,17 @@ xpath_tree_print_cb(cbuf *cb,
*/
int
xpath_tree_print(FILE *f,
- xpath_tree *xs)
+ xpath_tree *xs)
{
int retval = -1;
cbuf *cb = NULL;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
if (xpath_tree_print0(cb, xs, 0) < 0)
- goto done;
+ goto done;
fprintf(f, "%s", cbuf_get(cb));
retval = 0;
done:
@@ -247,101 +247,101 @@ xpath_tree_print(FILE *f,
*/
int
xpath_tree2cbuf(xpath_tree *xs,
- cbuf *xcb)
+ cbuf *xcb)
{
int retval = -1;
/* 1. Before first child */
switch (xs->xs_type){
case XP_ABSPATH:
- if (xs->xs_int == A_DESCENDANT_OR_SELF)
- cprintf(xcb, "/");
- cprintf(xcb, "/");
- break;
+ if (xs->xs_int == A_DESCENDANT_OR_SELF)
+ cprintf(xcb, "/");
+ cprintf(xcb, "/");
+ break;
case XP_STEP:
- switch (xs->xs_int){
- case A_SELF:
- cprintf(xcb, ".");
- break;
- case A_PARENT:
- cprintf(xcb, "..");
- break;
- default:
- break;
- }
- break;
+ switch (xs->xs_int){
+ case A_SELF:
+ cprintf(xcb, ".");
+ break;
+ case A_PARENT:
+ cprintf(xcb, "..");
+ break;
+ default:
+ break;
+ }
+ break;
case XP_NODE: /* s0 is namespace prefix, s1 is name */
- if (xs->xs_s0)
- cprintf(xcb, "%s:", xs->xs_s0);
- cprintf(xcb, "%s", xs->xs_s1);
- break;
+ if (xs->xs_s0)
+ cprintf(xcb, "%s:", xs->xs_s0);
+ cprintf(xcb, "%s", xs->xs_s1);
+ break;
case XP_PRIME_NR:
- cprintf(xcb, "%s", xs->xs_strnr?xs->xs_strnr:"0");
- break;
+ cprintf(xcb, "%s", xs->xs_strnr?xs->xs_strnr:"0");
+ break;
case XP_PRIME_STR:
- cprintf(xcb, "'%s'", xs->xs_s0?xs->xs_s0:"");
- break;
+ cprintf(xcb, "'%s'", xs->xs_s0?xs->xs_s0:"");
+ break;
case XP_PRIME_FN:
- if (xs->xs_s0)
- cprintf(xcb, "%s(", xs->xs_s0);
- break;
+ if (xs->xs_s0)
+ cprintf(xcb, "%s(", xs->xs_s0);
+ break;
default:
- break;
+ break;
}
/* 2. First child */
if (xs->xs_c0 && xpath_tree2cbuf(xs->xs_c0, xcb) < 0)
- goto done;
+ goto done;
/* 3. Between first and second child */
switch (xs->xs_type){
case XP_AND: /* and or */
case XP_ADD: /* div mod + * - */
- if (xs->xs_c1)
- cprintf(xcb, " %s ", clicon_int2str(xpopmap, xs->xs_int));
- break;
+ if (xs->xs_c1)
+ cprintf(xcb, " %s ", clicon_int2str(xpopmap, xs->xs_int));
+ break;
case XP_RELEX: /* !=, >= <= < > = */
case XP_UNION: /* | */
- if (xs->xs_c1)
- cprintf(xcb, "%s", clicon_int2str(xpopmap, xs->xs_int));
- break;
+ if (xs->xs_c1)
+ cprintf(xcb, "%s", clicon_int2str(xpopmap, xs->xs_int));
+ break;
case XP_PATHEXPR:
- /* [19] PathExpr ::= | FilterExpr '/' RelativeLocationPath
- | FilterExpr '//' RelativeLocationPath
- */
- if (xs->xs_s0)
- cprintf(xcb, "%s", xs->xs_s0);
- break;
+ /* [19] PathExpr ::= | FilterExpr '/' RelativeLocationPath
+ | FilterExpr '//' RelativeLocationPath
+ */
+ if (xs->xs_s0)
+ cprintf(xcb, "%s", xs->xs_s0);
+ break;
case XP_RELLOCPATH:
- if (xs->xs_c1){
- if (xs->xs_int == A_DESCENDANT_OR_SELF)
- cprintf(xcb, "/");
- cprintf(xcb, "/");
- }
- break;
+ if (xs->xs_c1){
+ if (xs->xs_int == A_DESCENDANT_OR_SELF)
+ cprintf(xcb, "/");
+ cprintf(xcb, "/");
+ }
+ break;
case XP_PRED:
- if (xs->xs_c1)
- cprintf(xcb, "[");
- break;
+ if (xs->xs_c1)
+ cprintf(xcb, "[");
+ break;
case XP_EXP:
- if (xs->xs_c0 && xs->xs_c1) /* Function name and two arguments, insert , */
- cprintf(xcb, ",");
- break;
+ if (xs->xs_c0 && xs->xs_c1) /* Function name and two arguments, insert , */
+ cprintf(xcb, ",");
+ break;
default:
- break;
+ break;
}
/* 4. Second child */
if (xs->xs_c1 && xpath_tree2cbuf(xs->xs_c1, xcb) < 0)
- goto done;
+ goto done;
/* 5. After second child */
switch (xs->xs_type){
case XP_PRED:
- if (xs->xs_c1)
- cprintf(xcb, "]");
- break;
+ if (xs->xs_c1)
+ cprintf(xcb, "]");
+ break;
case XP_PRIME_FN:
- if (xs->xs_s0)
- cprintf(xcb, ")");
+ if (xs->xs_s0)
+ cprintf(xcb, ")");
default:
- break;
+ break;
}
retval = 0;
done:
@@ -350,14 +350,14 @@ xpath_tree2cbuf(xpath_tree *xs,
static int
xpath_tree_append(xpath_tree *xt,
- xpath_tree ***vec,
- size_t *len)
+ xpath_tree ***vec,
+ size_t *len)
{
int retval = -1;
if ((*vec = realloc(*vec, sizeof(xpath_tree *) * (*len+1))) == NULL){
- clicon_err(OE_XML, errno, "realloc");
- goto done;
+ clicon_err(OE_XML, errno, "realloc");
+ goto done;
}
(*vec)[(*len)++] = xt;
retval = 0;
@@ -377,9 +377,9 @@ xpath_tree_append(xpath_tree *xt,
*/
int
xpath_tree_eq(xpath_tree *xt1, /* pattern */
- xpath_tree *xt2,
- xpath_tree ***vec,
- size_t *len)
+ xpath_tree *xt2,
+ xpath_tree ***vec,
+ size_t *len)
{
int retval = -1; /* Error */
xpath_tree *xc1;
@@ -389,64 +389,64 @@ xpath_tree_eq(xpath_tree *xt1, /* pattern */
/* node type */
if (xt1->xs_type != xt2->xs_type
#if 1 /* special case that they are expressions but of different types */
- && !((xt1->xs_type == XP_PRIME_NR || xt1->xs_type == XP_PRIME_STR) &&
- (xt2->xs_type == XP_PRIME_NR || xt2->xs_type == XP_PRIME_STR))
+ && !((xt1->xs_type == XP_PRIME_NR || xt1->xs_type == XP_PRIME_STR) &&
+ (xt2->xs_type == XP_PRIME_NR || xt2->xs_type == XP_PRIME_STR))
#endif
- ){
- clicon_debug(2, "%s type %s vs %s\n", __FUNCTION__,
- xpath_tree_int2str(xt1->xs_type),
- xpath_tree_int2str(xt2->xs_type));
- goto neq;
+ ){
+ clicon_debug(2, "%s type %s vs %s\n", __FUNCTION__,
+ xpath_tree_int2str(xt1->xs_type),
+ xpath_tree_int2str(xt2->xs_type));
+ goto neq;
}
/* check match, if set, store and go directly to ok */
if (xt1->xs_match){
- if (xpath_tree_append(xt2, vec, len) < 0)
- goto done;
- goto eq;
+ if (xpath_tree_append(xt2, vec, len) < 0)
+ goto done;
+ goto eq;
}
if (xt1->xs_int != xt2->xs_int){
- clicon_debug(2, "%s int\n", __FUNCTION__);
- goto neq;
+ clicon_debug(2, "%s int\n", __FUNCTION__);
+ goto neq;
}
if (xt1->xs_double != xt2->xs_double){
- clicon_debug(2, "%s double\n", __FUNCTION__);
- goto neq;
+ clicon_debug(2, "%s double\n", __FUNCTION__);
+ goto neq;
}
if (clicon_strcmp(xt1->xs_s0, xt2->xs_s0)){
- clicon_debug(2, "%s s0\n", __FUNCTION__);
- goto neq;
+ clicon_debug(2, "%s s0\n", __FUNCTION__);
+ goto neq;
}
if (clicon_strcmp(xt1->xs_s1, xt2->xs_s1)){
- clicon_debug(2, "%s s1\n", __FUNCTION__);
- goto neq;
+ clicon_debug(2, "%s s1\n", __FUNCTION__);
+ goto neq;
}
xc1 = xt1->xs_c0;
xc2 = xt2->xs_c0;
if (xc1 == NULL && xc2 == NULL)
- ;
+ ;
else{
- if (xc1 == NULL || xc2 == NULL){
- clicon_debug(2, "%s NULL\n", __FUNCTION__);
- goto neq;
- }
- if ((ret = xpath_tree_eq(xc1, xc2, vec, len)) < 0)
- goto done;
- if (ret == 0)
- goto neq;
+ if (xc1 == NULL || xc2 == NULL){
+ clicon_debug(2, "%s NULL\n", __FUNCTION__);
+ goto neq;
+ }
+ if ((ret = xpath_tree_eq(xc1, xc2, vec, len)) < 0)
+ goto done;
+ if (ret == 0)
+ goto neq;
}
xc1 = xt1->xs_c1;
xc2 = xt2->xs_c1;
if (xc1 == NULL && xc2 == NULL)
- ;
+ ;
else{
- if (xc1 == NULL || xc2 == NULL){
- clicon_debug(2, "%s NULL\n", __FUNCTION__);
- goto neq;
- }
- if ((ret = xpath_tree_eq(xc1, xc2, vec, len)) < 0)
- goto done;
- if (ret == 0)
- goto neq;
+ if (xc1 == NULL || xc2 == NULL){
+ clicon_debug(2, "%s NULL\n", __FUNCTION__);
+ goto neq;
+ }
+ if ((ret = xpath_tree_eq(xc1, xc2, vec, len)) < 0)
+ goto done;
+ if (ret == 0)
+ goto neq;
}
eq:
retval = 1; /* equal */
@@ -464,7 +464,7 @@ xpath_tree_eq(xpath_tree *xt1, /* pattern */
*/
xpath_tree *
xpath_tree_traverse(xpath_tree *xt,
- ...)
+ ...)
{
va_list ap;
int i;
@@ -472,16 +472,16 @@ xpath_tree_traverse(xpath_tree *xt,
va_start(ap, xt);
for (i = va_arg(ap, int); i >= 0; i = va_arg(ap, int)){
- switch (i){
- case 0:
- xs = xs->xs_c0;
- break;
- case 1:
- xs = xs->xs_c1;
- break;
- default:
- break;
- }
+ switch (i){
+ case 0:
+ xs = xs->xs_c0;
+ break;
+ case 1:
+ xs = xs->xs_c1;
+ break;
+ default:
+ break;
+ }
}
va_end(ap);
return xs;
@@ -495,15 +495,15 @@ int
xpath_tree_free(xpath_tree *xs)
{
if (xs->xs_strnr)
- free(xs->xs_strnr);
+ free(xs->xs_strnr);
if (xs->xs_s0)
- free(xs->xs_s0);
+ free(xs->xs_s0);
if (xs->xs_s1)
- free(xs->xs_s1);
+ free(xs->xs_s1);
if (xs->xs_c0)
- xpath_tree_free(xs->xs_c0);
+ xpath_tree_free(xs->xs_c0);
if (xs->xs_c1)
- xpath_tree_free(xs->xs_c1);
+ xpath_tree_free(xs->xs_c1);
free(xs);
return 0;
}
@@ -518,58 +518,58 @@ xpath_tree_free(xpath_tree *xs)
* if (xpath_parse(xpath, &xpt) < 0)
* err;
* if (xpt)
- * xpath_tree_free(xpt);
+ * xpath_tree_free(xpt);
* @endcode
* @see xpath_tree_free
* @see xpath_tree2cbuf for unparsing, ie producing an original xpath string
*/
int
xpath_parse(const char *xpath,
- xpath_tree **xptree)
+ xpath_tree **xptree)
{
int retval = -1;
clixon_xpath_yacc xpy = {0,};
cbuf *cb = NULL;
if (xpath == NULL){
- clicon_err(OE_XML, EINVAL, "XPath is NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "XPath is NULL");
+ goto done;
}
xpy.xpy_parse_string = xpath;
xpy.xpy_name = "xpath parser";
xpy.xpy_linenum = 1;
if (xpath_scan_init(&xpy) < 0)
- goto done;
+ goto done;
if (xpath_parse_init(&xpy) < 0)
- goto done;
+ goto done;
clicon_debug(2,"%s",__FUNCTION__);
if (clixon_xpath_parseparse(&xpy) != 0) { /* yacc returns 1 on error */
- clicon_log(LOG_NOTICE, "XPATH error: on line %d", xpy.xpy_linenum);
- if (clicon_errno == 0)
- clicon_err(OE_XML, 0, "XPATH parser error with no error code (should not happen)");
- xpath_scan_exit(&xpy);
- goto done;
+ clicon_log(LOG_NOTICE, "XPATH error: on line %d", xpy.xpy_linenum);
+ if (clicon_errno == 0)
+ clicon_err(OE_XML, 0, "XPATH parser error with no error code (should not happen)");
+ xpath_scan_exit(&xpy);
+ goto done;
}
if (clicon_debug_get() > 1){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- xpath_tree_print_cb(cb, xpy.xpy_top);
- clicon_debug(2, "xpath parse tree:\n%s", cbuf_get(cb));
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ xpath_tree_print_cb(cb, xpy.xpy_top);
+ clicon_debug(2, "xpath parse tree:\n%s", cbuf_get(cb));
}
xpath_parse_exit(&xpy);
xpath_scan_exit(&xpy);
if (xptree){
- *xptree = xpy.xpy_top;
- xpy.xpy_top = NULL;
+ *xptree = xpy.xpy_top;
+ xpy.xpy_top = NULL;
}
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (xpy.xpy_top)
- xpath_tree_free(xpy.xpy_top);
+ xpath_tree_free(xpy.xpy_top);
return retval;
}
@@ -588,37 +588,37 @@ xpath_parse(const char *xpath,
* if (xpath_vec_ctx(x, NULL, xpath, 0, &xc) < 0)
* err;
* if (xc)
- * ctx_free(xc);
+ * ctx_free(xc);
* @endcode
*/
int
xpath_vec_ctx(cxobj *xcur,
- cvec *nsc,
- const char *xpath,
- int localonly,
- xp_ctx **xrp)
+ cvec *nsc,
+ const char *xpath,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
xpath_tree *xptree = NULL;
xp_ctx xc = {0,};
if (xpath_parse(xpath, &xptree) < 0)
- goto done;
+ goto done;
xc.xc_type = XT_NODESET;
xc.xc_node = xcur;
xc.xc_initial = xcur;
if (cxvec_append(xcur, &xc.xc_nodeset, &xc.xc_size) < 0)
- goto done;
+ goto done;
if (xp_eval(&xc, xptree, nsc, localonly, xrp) < 0)
- goto done;
+ goto done;
if (xc.xc_nodeset){
- free(xc.xc_nodeset);
- xc.xc_nodeset = NULL;
+ free(xc.xc_nodeset);
+ xc.xc_nodeset = NULL;
}
retval = 0;
done:
if (xptree)
- xpath_tree_free(xptree);
+ xpath_tree_free(xptree);
return retval;
}
@@ -645,9 +645,9 @@ xpath_vec_ctx(cxobj *xcur,
*/
cxobj *
xpath_first(cxobj *xcur,
- cvec *nsc,
- const char *xpformat,
- ...)
+ cvec *nsc,
+ const char *xpformat,
+ ...)
{
cxobj *cx = NULL;
va_list ap;
@@ -660,26 +660,26 @@ xpath_first(cxobj *xcur,
va_end(ap);
/* allocate a message string exactly fitting the message length */
if ((xpath = malloc(len+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* second round: compute write message from reason and args */
va_start(ap, xpformat);
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
- clicon_err(OE_UNIX, errno, "vsnprintf");
- va_end(ap);
- goto done;
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ va_end(ap);
+ goto done;
}
va_end(ap);
if (xpath_vec_ctx(xcur, nsc, xpath, 0, &xr) < 0)
- goto done;
+ goto done;
if (xr && xr->xc_type == XT_NODESET && xr->xc_size)
- cx = xr->xc_nodeset[0];
+ cx = xr->xc_nodeset[0];
done:
if (xr)
- ctx_free(xr);
+ ctx_free(xr);
if (xpath)
- free(xpath);
+ free(xpath);
return cx;
}
@@ -705,8 +705,8 @@ xpath_first(cxobj *xcur,
*/
cxobj *
xpath_first_localonly(cxobj *xcur,
- const char *xpformat,
- ...)
+ const char *xpformat,
+ ...)
{
cxobj *cx = NULL;
va_list ap;
@@ -719,26 +719,26 @@ xpath_first_localonly(cxobj *xcur,
va_end(ap);
/* allocate a message string exactly fitting the message length */
if ((xpath = malloc(len+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* second round: compute write message from reason and args */
va_start(ap, xpformat);
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
- clicon_err(OE_UNIX, errno, "vsnprintf");
- va_end(ap);
- goto done;
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ va_end(ap);
+ goto done;
}
va_end(ap);
if (xpath_vec_ctx(xcur, NULL, xpath, 1, &xr) < 0)
- goto done;
+ goto done;
if (xr && xr->xc_type == XT_NODESET && xr->xc_size)
- cx = xr->xc_nodeset[0];
+ cx = xr->xc_nodeset[0];
done:
if (xr)
- ctx_free(xr);
+ ctx_free(xr);
if (xpath)
- free(xpath);
+ free(xpath);
return cx;
}
@@ -766,49 +766,49 @@ xpath_first_localonly(cxobj *xcur,
*/
int
xpath_vec(cxobj *xcur,
- cvec *nsc,
- const char *xpformat,
- cxobj ***vec,
- size_t *veclen,
- ...)
+ cvec *nsc,
+ const char *xpformat,
+ cxobj ***vec,
+ size_t *veclen,
+ ...)
{
int retval = -1;
va_list ap;
size_t len;
char *xpath = NULL;
xp_ctx *xr = NULL;
-
+
va_start(ap, veclen);
len = vsnprintf(NULL, 0, xpformat, ap);
va_end(ap);
/* allocate an xpath string exactly fitting the length */
if ((xpath = malloc(len+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* second round: actually compute xpath string content */
va_start(ap, veclen);
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
- clicon_err(OE_UNIX, errno, "vsnprintf");
- va_end(ap);
- goto done;
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ va_end(ap);
+ goto done;
}
va_end(ap);
*vec=NULL;
*veclen = 0;
if (xpath_vec_ctx(xcur, nsc, xpath, 0, &xr) < 0)
- goto done;
+ goto done;
if (xr && xr->xc_type == XT_NODESET){
- *vec = xr->xc_nodeset;
- xr->xc_nodeset = NULL;
- *veclen = xr->xc_size;
+ *vec = xr->xc_nodeset;
+ xr->xc_nodeset = NULL;
+ *veclen = xr->xc_size;
}
retval = 0;
done:
if (xr)
- ctx_free(xr);
+ ctx_free(xr);
if (xpath)
- free(xpath);
+ free(xpath);
return retval;
}
@@ -838,12 +838,12 @@ xpath_vec(cxobj *xcur,
*/
int
xpath_vec_flag(cxobj *xcur,
- cvec *nsc,
- const char *xpformat,
- uint16_t flags,
- cxobj ***vec,
- int *veclen,
- ...)
+ cvec *nsc,
+ const char *xpformat,
+ uint16_t flags,
+ cxobj ***vec,
+ int *veclen,
+ ...)
{
int retval = -1;
va_list ap;
@@ -858,35 +858,35 @@ xpath_vec_flag(cxobj *xcur,
va_end(ap);
/* allocate a message string exactly fitting the message length */
if ((xpath = malloc(len+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* second round: compute write message from reason and args */
va_start(ap, veclen);
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
- clicon_err(OE_UNIX, errno, "vsnprintf");
- va_end(ap);
- goto done;
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ va_end(ap);
+ goto done;
}
va_end(ap);
*vec=NULL;
*veclen = 0;
if (xpath_vec_ctx(xcur, nsc, xpath, 0, &xr) < 0)
- goto done;
+ goto done;
if (xr && xr->xc_type == XT_NODESET){
- for (i=0; ixc_size; i++){
- x = xr->xc_nodeset[i];
- if (flags==0x0 || xml_flag(x, flags))
- if (cxvec_append(x, vec, veclen) < 0)
- goto done;
- }
+ for (i=0; ixc_size; i++){
+ x = xr->xc_nodeset[i];
+ if (flags==0x0 || xml_flag(x, flags))
+ if (cxvec_append(x, vec, veclen) < 0)
+ goto done;
+ }
}
retval = 0;
done:
if (xr)
- ctx_free(xr);
+ ctx_free(xr);
if (xpath)
- free(xpath);
+ free(xpath);
return retval;
}
@@ -901,9 +901,9 @@ xpath_vec_flag(cxobj *xcur,
*/
int
xpath_vec_bool(cxobj *xcur,
- cvec *nsc,
- const char *xpformat,
- ...)
+ cvec *nsc,
+ const char *xpformat,
+ ...)
{
int retval = -1;
va_list ap;
@@ -916,26 +916,26 @@ xpath_vec_bool(cxobj *xcur,
va_end(ap);
/* allocate a message string exactly fitting the message length */
if ((xpath = malloc(len+1)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
/* second round: compute write message from reason and args */
va_start(ap, xpformat);
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
- clicon_err(OE_UNIX, errno, "vsnprintf");
- va_end(ap);
- goto done;
+ clicon_err(OE_UNIX, errno, "vsnprintf");
+ va_end(ap);
+ goto done;
}
va_end(ap);
if (xpath_vec_ctx(xcur, nsc, xpath, 0, &xr) < 0)
- goto done;
+ goto done;
if (xr)
- retval = ctx2boolean(xr);
+ retval = ctx2boolean(xr);
done:
if (xr)
- ctx_free(xr);
+ ctx_free(xr);
if (xpath)
- free(xpath);
+ free(xpath);
return retval;
}
@@ -952,10 +952,10 @@ xpath_vec_bool(cxobj *xcur,
*/
static int
traverse_canonical(xpath_tree *xs,
- yang_stmt *yspec,
- cvec *nsc0,
- cvec *nsc1,
- cbuf **reason)
+ yang_stmt *yspec,
+ cvec *nsc0,
+ cvec *nsc1,
+ cbuf **reason)
{
int retval = -1;
char *prefix0;
@@ -967,67 +967,67 @@ traverse_canonical(xpath_tree *xs,
switch (xs->xs_type){
case XP_NODE: /* s0 is namespace prefix, s1 is name */
- /* Nodetest = * needs no prefix */
- if (xs->xs_s1 && strcmp(xs->xs_s1, "*") == 0)
- break;
- prefix0 = xs->xs_s0;
- if ((namespace = xml_nsctx_get(nsc0, prefix0)) == NULL){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "No namespace found for prefix: %s", prefix0);
- if (reason)
- *reason = cb;
- goto failed;
- }
- if ((ymod = yang_find_module_by_namespace(yspec, namespace)) == NULL){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "No modules found for namespace: %s", namespace);
- if (reason)
- *reason = cb;
- goto failed;
- }
- if ((prefix1 = yang_find_myprefix(ymod)) == NULL){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "No prefix found in module: %s", yang_argument_get(ymod));
- if (reason)
- *reason = cb;
- goto failed;
- }
- if (xml_nsctx_get(nsc1, prefix1) == NULL)
- if (xml_nsctx_add(nsc1, prefix1, namespace) < 0)
- goto done;
- if (prefix0==NULL || strcmp(prefix0, prefix1) != 0){
- if (xs->xs_s0)
- free(xs->xs_s0);
- if ((xs->xs_s0 = strdup(prefix1)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- }
- break;
+ /* Nodetest = * needs no prefix */
+ if (xs->xs_s1 && strcmp(xs->xs_s1, "*") == 0)
+ break;
+ prefix0 = xs->xs_s0;
+ if ((namespace = xml_nsctx_get(nsc0, prefix0)) == NULL){
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "No namespace found for prefix: %s", prefix0);
+ if (reason)
+ *reason = cb;
+ goto failed;
+ }
+ if ((ymod = yang_find_module_by_namespace(yspec, namespace)) == NULL){
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "No modules found for namespace: %s", namespace);
+ if (reason)
+ *reason = cb;
+ goto failed;
+ }
+ if ((prefix1 = yang_find_myprefix(ymod)) == NULL){
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "No prefix found in module: %s", yang_argument_get(ymod));
+ if (reason)
+ *reason = cb;
+ goto failed;
+ }
+ if (xml_nsctx_get(nsc1, prefix1) == NULL)
+ if (xml_nsctx_add(nsc1, prefix1, namespace) < 0)
+ goto done;
+ if (prefix0==NULL || strcmp(prefix0, prefix1) != 0){
+ if (xs->xs_s0)
+ free(xs->xs_s0);
+ if ((xs->xs_s0 = strdup(prefix1)) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ }
+ break;
default:
- break;
- }
+ break;
+ }
if (xs->xs_c0){
- if ((ret = traverse_canonical(xs->xs_c0, yspec, nsc0, nsc1, reason)) < 0)
- goto done;
- if (ret == 0)
- goto failed;
+ if ((ret = traverse_canonical(xs->xs_c0, yspec, nsc0, nsc1, reason)) < 0)
+ goto done;
+ if (ret == 0)
+ goto failed;
}
if (xs->xs_c1){
- if ((ret = traverse_canonical(xs->xs_c1, yspec, nsc0, nsc1, reason)) < 0)
- goto done;
- if (ret == 0)
- goto failed;
- }
+ if ((ret = traverse_canonical(xs->xs_c1, yspec, nsc0, nsc1, reason)) < 0)
+ goto done;
+ if (ret == 0)
+ goto failed;
+ }
retval = 1;
done:
return retval;
@@ -1068,11 +1068,11 @@ traverse_canonical(xpath_tree *xs,
*/
int
xpath2canonical(const char *xpath0,
- cvec *nsc0,
- yang_stmt *yspec,
- char **xpath1,
- cvec **nsc1p,
- cbuf **cbreason)
+ cvec *nsc0,
+ yang_stmt *yspec,
+ char **xpath1,
+ cvec **nsc1p,
+ cbuf **cbreason)
{
int retval = -1;
xpath_tree *xpt = NULL;
@@ -1082,42 +1082,42 @@ xpath2canonical(const char *xpath0,
/* Parse input xpath into an xpath-tree */
if (xpath_parse(xpath0, &xpt) < 0)
- goto done;
+ goto done;
/* Create new nsc */
if ((nsc1 = xml_nsctx_init(NULL, NULL)) == NULL)
- goto done;
+ goto done;
/* Traverse tree to find prefixes, transform them to canonical form and
* create a canonical network namespace
*/
if ((ret = traverse_canonical(xpt, yspec, nsc0, nsc1, cbreason)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto failed;
+ goto failed;
/* Print tree with new prefixes */
if ((xcb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
}
if (xpath_tree2cbuf(xpt, xcb) < 0)
- goto done;
+ goto done;
if (xpath1){
- if ((*xpath1 = strdup(cbuf_get(xcb))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
+ if ((*xpath1 = strdup(cbuf_get(xcb))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
}
if (nsc1p){
- *nsc1p = nsc1;
- nsc1 = NULL;
+ *nsc1p = nsc1;
+ nsc1 = NULL;
}
retval = 1;
done:
if (xcb)
- cbuf_free(xcb);
+ cbuf_free(xcb);
if (nsc1)
- xml_nsctx_free(nsc1);
+ xml_nsctx_free(nsc1);
if (xpt)
- xpath_tree_free(xpt);
+ xpath_tree_free(xpt);
return retval;
failed:
retval = 0;
@@ -1134,30 +1134,30 @@ xpath2canonical(const char *xpath0,
*/
int
xpath_count(cxobj *xcur,
- cvec *nsc,
- const char *xpath,
- uint32_t *count)
+ cvec *nsc,
+ const char *xpath,
+ uint32_t *count)
{
int retval = -1;
xp_ctx *xc = NULL;
cbuf *cb = NULL;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
cprintf(cb, "count(%s)", xpath);
if (xpath_vec_ctx(xcur, nsc, cbuf_get(cb), 0, &xc) < 0)
- goto done;
+ goto done;
if (xc && xc->xc_type == XT_NUMBER && xc->xc_number != NAN)
- *count = (uint32_t)xc->xc_number;
+ *count = (uint32_t)xc->xc_number;
else
- *count = 0;
+ *count = 0;
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (xc)
- ctx_free(xc);
+ ctx_free(xc);
return retval;
}
diff --git a/lib/src/clixon_xpath_ctx.c b/lib/src/clixon_xpath_ctx.c
index 10d2daac..df6d1a3e 100644
--- a/lib/src/clixon_xpath_ctx.c
+++ b/lib/src/clixon_xpath_ctx.c
@@ -79,9 +79,9 @@ int
ctx_free(xp_ctx *xc)
{
if (xc->xc_nodeset)
- free(xc->xc_nodeset);
+ free(xc->xc_nodeset);
if (xc->xc_string)
- free(xc->xc_string);
+ free(xc->xc_string);
free(xc);
return 0;
}
@@ -93,23 +93,23 @@ ctx_dup(xp_ctx *xc0)
xp_ctx *xc = NULL;
if ((xc = malloc(sizeof(*xc))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xc, 0, sizeof(*xc));
*xc = *xc0;
if (xc0->xc_size){
- if ((xc->xc_nodeset = calloc(xc0->xc_size, sizeof(cxobj*))) == NULL){
- clicon_err(OE_UNIX, errno, "calloc");
- goto done;
- }
- memcpy(xc->xc_nodeset, xc0->xc_nodeset, xc->xc_size*sizeof(cxobj*));
+ if ((xc->xc_nodeset = calloc(xc0->xc_size, sizeof(cxobj*))) == NULL){
+ clicon_err(OE_UNIX, errno, "calloc");
+ goto done;
+ }
+ memcpy(xc->xc_nodeset, xc0->xc_nodeset, xc->xc_size*sizeof(cxobj*));
}
if (xc0->xc_string)
- if ((xc->xc_string = strdup(xc0->xc_string)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
+ if ((xc->xc_string = strdup(xc0->xc_string)) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
done:
return xc;
}
@@ -122,35 +122,35 @@ ctx_dup(xp_ctx *xc0)
*/
int
ctx_print_cb(cbuf *cb,
- xp_ctx *xc,
- int ind,
- char *str)
+ xp_ctx *xc,
+ int ind,
+ char *str)
{
static int indent = 0;
int i;
if (ind<0)
- indent += ind;
+ indent += ind;
cprintf(cb, "%*s%s ", indent, "", str?str:"");
if (ind>0)
- indent += ind;
+ indent += ind;
if (xc){
- cprintf(cb, "%s: ", (char*)clicon_int2str(ctxmap, xc->xc_type));
- switch (xc->xc_type){
- case XT_NODESET:
- for (i=0; ixc_size; i++)
- cprintf(cb, "%s ", xml_name(xc->xc_nodeset[i]));
- break;
- case XT_BOOL:
- cprintf(cb, "%s", xc->xc_bool?"true":"false");
- break;
- case XT_NUMBER:
- cprintf(cb, "%lf", xc->xc_number);
- break;
- case XT_STRING:
- cprintf(cb, "%s", xc->xc_string);
- break;
- }
+ cprintf(cb, "%s: ", (char*)clicon_int2str(ctxmap, xc->xc_type));
+ switch (xc->xc_type){
+ case XT_NODESET:
+ for (i=0; ixc_size; i++)
+ cprintf(cb, "%s ", xml_name(xc->xc_nodeset[i]));
+ break;
+ case XT_BOOL:
+ cprintf(cb, "%s", xc->xc_bool?"true":"false");
+ break;
+ case XT_NUMBER:
+ cprintf(cb, "%lf", xc->xc_number);
+ break;
+ case XT_STRING:
+ cprintf(cb, "%s", xc->xc_string);
+ break;
+ }
}
return 0;
}
@@ -162,22 +162,22 @@ ctx_print_cb(cbuf *cb,
*/
int
ctx_print(FILE *f,
- xp_ctx *xc,
- char *str)
+ xp_ctx *xc,
+ char *str)
{
int retval = -1;
cbuf *cb = NULL;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
ctx_print_cb(cb, xc, 0, str);
fprintf(f, "%s", cbuf_get(cb));
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -197,17 +197,17 @@ ctx2boolean(xp_ctx *xc)
int b = -1;
switch (xc->xc_type){
case XT_NODESET:
- b = (xc->xc_size != 0);
- break;
+ b = (xc->xc_size != 0);
+ break;
case XT_BOOL:
- b = xc->xc_bool;
- break;
+ b = xc->xc_bool;
+ break;
case XT_NUMBER:
- b = (xc->xc_number != 0.0 && xc->xc_number != NAN);
- break;
+ b = (xc->xc_number != 0.0 && xc->xc_number != NAN);
+ break;
case XT_STRING:
- b = (xc->xc_string && strlen(xc->xc_string));
- break;
+ b = (xc->xc_string && strlen(xc->xc_string));
+ break;
}
return b;
}
@@ -221,7 +221,7 @@ ctx2boolean(xp_ctx *xc)
*/
int
ctx2string(xp_ctx *xc,
- char **str0)
+ char **str0)
{
int retval = -1;
char *str = NULL;
@@ -230,39 +230,39 @@ ctx2string(xp_ctx *xc,
switch (xc->xc_type){
case XT_NODESET:
- if (xc->xc_size && (b = xml_body(xc->xc_nodeset[0]))){
- if ((str = strdup(b)) == NULL){
- clicon_err(OE_XML, errno, "strdup");
- goto done;
- }
- }
- else
- if ((str = strdup("")) == NULL){
- clicon_err(OE_XML, errno, "strdup");
- goto done;
- }
- break;
+ if (xc->xc_size && (b = xml_body(xc->xc_nodeset[0]))){
+ if ((str = strdup(b)) == NULL){
+ clicon_err(OE_XML, errno, "strdup");
+ goto done;
+ }
+ }
+ else
+ if ((str = strdup("")) == NULL){
+ clicon_err(OE_XML, errno, "strdup");
+ goto done;
+ }
+ break;
case XT_BOOL:
- if ((str = strdup(xc->xc_bool == 0?"false":"true")) == NULL){
- clicon_err(OE_XML, errno, "strdup");
- goto done;
- }
- break;
+ if ((str = strdup(xc->xc_bool == 0?"false":"true")) == NULL){
+ clicon_err(OE_XML, errno, "strdup");
+ goto done;
+ }
+ break;
case XT_NUMBER:
- len = snprintf(NULL, 0, "%0lf", xc->xc_number);
- len++;
- if ((str = malloc(len)) == NULL){
- clicon_err(OE_XML, errno, "malloc");
- goto done;
- }
- snprintf(str, len, "%0lf", xc->xc_number);
- break;
+ len = snprintf(NULL, 0, "%0lf", xc->xc_number);
+ len++;
+ if ((str = malloc(len)) == NULL){
+ clicon_err(OE_XML, errno, "malloc");
+ goto done;
+ }
+ snprintf(str, len, "%0lf", xc->xc_number);
+ break;
case XT_STRING:
- if ((str = strdup(xc->xc_string)) == NULL){
- clicon_err(OE_XML, errno, "strdup");
- goto done;
- }
- break;
+ if ((str = strdup(xc->xc_string)) == NULL){
+ clicon_err(OE_XML, errno, "strdup");
+ goto done;
+ }
+ break;
}
*str0 = str;
retval = 0;
@@ -278,7 +278,7 @@ ctx2string(xp_ctx *xc,
*/
int
ctx2number(xp_ctx *xc,
- double *n0)
+ double *n0)
{
int retval = -1;
char *str = NULL;
@@ -286,27 +286,27 @@ ctx2number(xp_ctx *xc,
switch (xc->xc_type){
case XT_NODESET:
- if (ctx2string(xc, &str) < 0)
- goto done;
- if (sscanf(str, "%lf",&n) != 1)
- n = NAN;
- break;
+ if (ctx2string(xc, &str) < 0)
+ goto done;
+ if (sscanf(str, "%lf",&n) != 1)
+ n = NAN;
+ break;
case XT_BOOL:
- n = (double)xc->xc_bool;
- break;
+ n = (double)xc->xc_bool;
+ break;
case XT_NUMBER:
- n = xc->xc_number;
- break;
+ n = xc->xc_number;
+ break;
case XT_STRING:
- if (sscanf(xc->xc_string, "%lf",&n) != 1)
- n = NAN;
- break;
+ if (sscanf(xc->xc_string, "%lf",&n) != 1)
+ n = NAN;
+ break;
}
*n0 = n;
retval = 0;
done:
if (str)
- free(str);
+ free(str);
return retval;
}
@@ -314,11 +314,11 @@ ctx2number(xp_ctx *xc,
*/
int
ctx_nodeset_replace(xp_ctx *xc,
- cxobj **vec,
- size_t veclen)
+ cxobj **vec,
+ size_t veclen)
{
if (xc->xc_nodeset)
- free(xc->xc_nodeset);
+ free(xc->xc_nodeset);
xc->xc_nodeset = vec;
xc->xc_size = veclen;
return 0;
diff --git a/lib/src/clixon_xpath_eval.c b/lib/src/clixon_xpath_eval.c
index 459e1720..6a5f4a2f 100644
--- a/lib/src/clixon_xpath_eval.c
+++ b/lib/src/clixon_xpath_eval.c
@@ -116,8 +116,8 @@ const map_str2int xpopmap[] = {
*/
static int
nodetest_eval_node(cxobj *x,
- xpath_tree *xs,
- cvec *nsc)
+ xpath_tree *xs,
+ cvec *nsc)
{
int retval = -1;
char *name1 = xml_name(x);
@@ -129,16 +129,16 @@ nodetest_eval_node(cxobj *x,
/* Namespaces is s0, name is s1 */
if (strcmp(xs->xs_s1, "*")==0)
- return 1;
+ return 1;
/* get namespace of xml tree */
if (xml2ns(x, prefix1, &nsxml) < 0)
- goto done;
+ goto done;
prefix2 = xs->xs_s0;
name2 = xs->xs_s1;
/* Before going into namespaces, check name equality and filter out noteq */
if (strcmp(name1, name2) != 0){
- retval = 0; /* no match */
- goto done;
+ retval = 0; /* no match */
+ goto done;
}
/* Here names are equal
* Now look for namespaces
@@ -148,36 +148,36 @@ nodetest_eval_node(cxobj *x,
* (2) without yang
*/
if (nsc != NULL) { /* solution (1) */
- nsxpath = xml_nsctx_get(nsc, prefix2);
- if (nsxml != NULL && nsxpath != NULL)
- retval = (strcmp(nsxml, nsxpath) == 0);
- else if (nsxpath == NULL){
- /* We have a namespace from xml, but none in yang.
- * This can happen in eg augments and ../foo, where foo is
- * augmented from another namespace
- */
- retval = 1;
- }
- else
- retval = (nsxml == nsxpath); /* True only if both are NULL */
+ nsxpath = xml_nsctx_get(nsc, prefix2);
+ if (nsxml != NULL && nsxpath != NULL)
+ retval = (strcmp(nsxml, nsxpath) == 0);
+ else if (nsxpath == NULL){
+ /* We have a namespace from xml, but none in yang.
+ * This can happen in eg augments and ../foo, where foo is
+ * augmented from another namespace
+ */
+ retval = 1;
+ }
+ else
+ retval = (nsxml == nsxpath); /* True only if both are NULL */
}
else{ /* solution (2) */
- if (prefix1 == NULL && prefix2 == NULL)
- retval = 1;
- else if (prefix1 == NULL || prefix2 == NULL)
- retval = 0;
- else
- retval = strcmp(prefix1, prefix2) == 0;
+ if (prefix1 == NULL && prefix2 == NULL)
+ retval = 1;
+ else if (prefix1 == NULL || prefix2 == NULL)
+ retval = 0;
+ else
+ retval = strcmp(prefix1, prefix2) == 0;
}
#if 0 /* debugging */
/* If retval == 0 here, then there is name match, but not ns match */
if (retval == 0){
- fprintf(stderr, "%s NOMATCH xml: (%s)%s\n\t\t xpath: (%s)%s\n", __FUNCTION__,
- name1, nsxml,
- name2, nsxpath);
+ fprintf(stderr, "%s NOMATCH xml: (%s)%s\n\t\t xpath: (%s)%s\n", __FUNCTION__,
+ name1, nsxml,
+ name2, nsxpath);
}
#endif
- done: /* retval set in preceding statement */
+ done: /* retval set in preceding statement */
return retval;
}
@@ -186,8 +186,8 @@ nodetest_eval_node(cxobj *x,
*/
static int
nodetest_eval_node_localonly(cxobj *x,
- xpath_tree *xs,
- cvec *nsc)
+ xpath_tree *xs,
+ cvec *nsc)
{
int retval = -1;
char *name1 = xml_name(x);
@@ -195,17 +195,17 @@ nodetest_eval_node_localonly(cxobj *x,
/* Namespaces is s0, name is s1 */
if (strcmp(xs->xs_s1, "*")==0){
- retval = 1;
- goto done;
+ retval = 1;
+ goto done;
}
name2 = xs->xs_s1;
/* Before going into namespaces, check name equality and filter out noteq */
if (strcmp(name1, name2) == 0){
- retval = 1;
- goto done;
+ retval = 1;
+ goto done;
}
retval = 0; /* no match */
- done: /* retval set in preceding statement */
+ done: /* retval set in preceding statement */
return retval;
}
@@ -222,27 +222,27 @@ nodetest_eval_node_localonly(cxobj *x,
*/
static int
nodetest_eval(cxobj *x,
- xpath_tree *xs,
- cvec *nsc,
- int localonly)
+ xpath_tree *xs,
+ cvec *nsc,
+ int localonly)
{
int retval = 0; /* NB: no match is default (not error) */
if (xs->xs_type == XP_NODE){
- if (localonly)
- retval = nodetest_eval_node_localonly(x, xs, nsc);
- else
- retval = nodetest_eval_node(x, xs, nsc);
+ if (localonly)
+ retval = nodetest_eval_node_localonly(x, xs, nsc);
+ else
+ retval = nodetest_eval_node(x, xs, nsc);
}
else if (xs->xs_type == XP_NODE_FN){
- switch (xs->xs_int){
- case XPATHFN_NODE:
- case XPATHFN_TEXT:
- retval = 1;
- break;
- default:
- break;
- }
+ switch (xs->xs_int){
+ case XPATHFN_NODE:
+ case XPATHFN_TEXT:
+ retval = 1;
+ break;
+ default:
+ break;
+ }
}
/* note, retval set by previous statement */
return retval;
@@ -260,13 +260,13 @@ nodetest_eval(cxobj *x,
*/
int
nodetest_recursive(cxobj *xn,
- xpath_tree *nodetest,
- int node_type,
- uint16_t flags,
- cvec *nsc,
- int localonly,
- cxobj ***vec0,
- int *vec0len)
+ xpath_tree *nodetest,
+ int node_type,
+ uint16_t flags,
+ cvec *nsc,
+ int localonly,
+ cxobj ***vec0,
+ int *vec0len)
{
int retval = -1;
cxobj *xsub;
@@ -275,15 +275,15 @@ nodetest_recursive(cxobj *xn,
xsub = NULL;
while ((xsub = xml_child_each(xn, xsub, node_type)) != NULL) {
- if (nodetest_eval(xsub, nodetest, nsc, localonly) == 1){
- clicon_debug(2, "%s %x %x", __FUNCTION__, flags, xml_flag(xsub, flags));
- if (flags==0x0 || xml_flag(xsub, flags))
- if (cxvec_append(xsub, &vec, &veclen) < 0)
- goto done;
- // continue; /* Dont go deeper */
- }
- if (nodetest_recursive(xsub, nodetest, node_type, flags, nsc, localonly, &vec, &veclen) < 0)
- goto done;
+ if (nodetest_eval(xsub, nodetest, nsc, localonly) == 1){
+ clicon_debug(2, "%s %x %x", __FUNCTION__, flags, xml_flag(xsub, flags));
+ if (flags==0x0 || xml_flag(xsub, flags))
+ if (cxvec_append(xsub, &vec, &veclen) < 0)
+ goto done;
+ // continue; /* Dont go deeper */
+ }
+ if (nodetest_recursive(xsub, nodetest, node_type, flags, nsc, localonly, &vec, &veclen) < 0)
+ goto done;
}
retval = 0;
*vec0 = vec;
@@ -308,10 +308,10 @@ nodetest_recursive(cxobj *xn,
*/
static int
xp_eval_step(xp_ctx *xc0,
- xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
int i;
@@ -326,118 +326,118 @@ xp_eval_step(xp_ctx *xc0,
/* Create new xc */
if ((xc = ctx_dup(xc0)) == NULL)
- goto done;
+ goto done;
switch (xs->xs_int){
case A_ANCESTOR:
- break;
+ break;
case A_ANCESTOR_OR_SELF:
- break;
+ break;
case A_ATTRIBUTE: /* principal node type is attribute */
- break;
+ break;
case A_CHILD:
- if (xc->xc_descendant){
- for (i=0; ixc_size; i++){
- xv = xc->xc_nodeset[i];
- if (nodetest_recursive(xv, nodetest, CX_ELMNT, 0x0, nsc, localonly, &vec, &veclen) < 0)
- goto done;
- }
- xc->xc_descendant = 0;
- }
- else{
- for (i=0; ixc_size; i++){
- xv = xc->xc_nodeset[i];
- x = NULL;
- if ((ret = xpath_optimize_check(xs, xv, &vec, &veclen)) < 0)
- goto done;
- if (ret == 0){/* regular code, no optimization made */
- while ((x = xml_child_each(xv, x, CX_ELMNT)) != NULL) {
- /* xs->xs_c0 is nodetest */
- if (nodetest == NULL ||
- nodetest_eval(x, nodetest, nsc, localonly) == 1){
- if (cxvec_append(x, &vec, &veclen) < 0)
- goto done;
- }
- }
- }
- }
- }
- ctx_nodeset_replace(xc, vec, veclen);
- break;
+ if (xc->xc_descendant){
+ for (i=0; ixc_size; i++){
+ xv = xc->xc_nodeset[i];
+ if (nodetest_recursive(xv, nodetest, CX_ELMNT, 0x0, nsc, localonly, &vec, &veclen) < 0)
+ goto done;
+ }
+ xc->xc_descendant = 0;
+ }
+ else{
+ for (i=0; ixc_size; i++){
+ xv = xc->xc_nodeset[i];
+ x = NULL;
+ if ((ret = xpath_optimize_check(xs, xv, &vec, &veclen)) < 0)
+ goto done;
+ if (ret == 0){/* regular code, no optimization made */
+ while ((x = xml_child_each(xv, x, CX_ELMNT)) != NULL) {
+ /* xs->xs_c0 is nodetest */
+ if (nodetest == NULL ||
+ nodetest_eval(x, nodetest, nsc, localonly) == 1){
+ if (cxvec_append(x, &vec, &veclen) < 0)
+ goto done;
+ }
+ }
+ }
+ }
+ }
+ ctx_nodeset_replace(xc, vec, veclen);
+ break;
case A_DESCENDANT_OR_SELF:
- for (i=0; ixc_size; i++){
- xv = xc->xc_nodeset[i];
- if (nodetest_recursive(xv, xs->xs_c0, CX_ELMNT, 0x0, nsc, localonly, &vec, &veclen) < 0)
- goto done;
- }
- for (i=0; ixc_nodeset, &xc->xc_size) < 0)
- goto done;
- }
- if (vec){
- free(vec);
- vec = NULL;
- }
- break;
+ for (i=0; ixc_size; i++){
+ xv = xc->xc_nodeset[i];
+ if (nodetest_recursive(xv, xs->xs_c0, CX_ELMNT, 0x0, nsc, localonly, &vec, &veclen) < 0)
+ goto done;
+ }
+ for (i=0; ixc_nodeset, &xc->xc_size) < 0)
+ goto done;
+ }
+ if (vec){
+ free(vec);
+ vec = NULL;
+ }
+ break;
case A_DESCENDANT:
- for (i=0; ixc_size; i++){
- xv = xc->xc_nodeset[i];
- if (nodetest_recursive(xv, xs->xs_c0, CX_ELMNT, 0x0, nsc, localonly, &vec, &veclen) < 0)
- goto done;
- }
- ctx_nodeset_replace(xc, vec, veclen);
- break;
+ for (i=0; ixc_size; i++){
+ xv = xc->xc_nodeset[i];
+ if (nodetest_recursive(xv, xs->xs_c0, CX_ELMNT, 0x0, nsc, localonly, &vec, &veclen) < 0)
+ goto done;
+ }
+ ctx_nodeset_replace(xc, vec, veclen);
+ break;
case A_FOLLOWING:
- break;
+ break;
case A_FOLLOWING_SIBLING:
- break;
+ break;
case A_NAMESPACE: /* principal node type is namespace */
- break;
+ break;
case A_PARENT:
- veclen = xc->xc_size;
- vec = xc->xc_nodeset;
- xc->xc_size = 0;
- xc->xc_nodeset = NULL;
- for (i=0; ixc_size;
+ vec = xc->xc_nodeset;
+ xc->xc_size = 0;
+ xc->xc_nodeset = NULL;
+ for (i=0; ixc_nodeset, &xc->xc_size) < 0)
- goto done;
- }
- if (vec){
- free(vec);
- vec = NULL;
- }
- break;
+ )
+ if (cxvec_append(xp, &xc->xc_nodeset, &xc->xc_size) < 0)
+ goto done;
+ }
+ if (vec){
+ free(vec);
+ vec = NULL;
+ }
+ break;
case A_PRECEDING:
- break;
+ break;
case A_PRECEDING_SIBLING:
- break;
+ break;
case A_SELF:
- break;
+ break;
default:
- clicon_err(OE_XML, 0, "No such axisname: %d", xs->xs_int);
- goto done;
- break;
+ clicon_err(OE_XML, 0, "No such axisname: %d", xs->xs_int);
+ goto done;
+ break;
}
if (xs->xs_c1){
- if (xp_eval(xc, xs->xs_c1, nsc, localonly, xrp) < 0)
- goto done;
+ if (xp_eval(xc, xs->xs_c1, nsc, localonly, xrp) < 0)
+ goto done;
}
else{
- *xrp = xc;
- xc = NULL;
+ *xrp = xc;
+ xc = NULL;
}
assert(*xrp);
retval = 0;
done:
if (xc)
- ctx_free(xc);
+ ctx_free(xc);
return retval;
}
@@ -467,10 +467,10 @@ xp_eval_step(xp_ctx *xc0,
*/
static int
xp_eval_predicate(xp_ctx *xc,
- xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr0 = NULL;
@@ -481,80 +481,80 @@ xp_eval_predicate(xp_ctx *xc,
xp_ctx *xcc;
if (xs->xs_c0 != NULL){ /* eval previous predicates */
- if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
- goto done;
+ if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
+ goto done;
}
else{ /* empty */
- if ((xr0 = ctx_dup(xc)) == NULL)
- goto done;
+ if ((xr0 = ctx_dup(xc)) == NULL)
+ goto done;
}
if (xs->xs_c1){ /* Second child */
- /* Loop over each node in the nodeset */
- assert (xr0->xc_type == XT_NODESET);
- if ((xr1 = malloc(sizeof(*xr1))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
- }
- memset(xr1, 0, sizeof(*xr1));
- xr1->xc_type = XT_NODESET;
- xr1->xc_node = xc->xc_node;
- xr1->xc_initial = xc->xc_initial;
- for (i=0; ixc_size; i++){
- x = xr0->xc_nodeset[i];
- /* Create new context */
- if ((xcc = malloc(sizeof(*xcc))) == NULL){
- clicon_err(OE_XML, errno, "malloc");
- goto done;
- }
- memset(xcc, 0, sizeof(*xcc));
- xcc->xc_type = XT_NODESET;
- xcc->xc_initial = xc->xc_initial;
- xcc->xc_node = x;
- xcc->xc_position = i;
- /* For each node in the node-set to be filtered, the PredicateExpr is
- * evaluated with that node as the context node */
- if (cxvec_append(x, &xcc->xc_nodeset, &xcc->xc_size) < 0)
- goto done;
- if (xp_eval(xcc, xs->xs_c1, nsc, localonly, &xrc) < 0)
- goto done;
- if (xcc)
- ctx_free(xcc);
- if (xrc->xc_type == XT_NUMBER){
- /* If the result is a number, the result will be converted to true
- if the number is equal to the context position */
- if ((int)xrc->xc_number == i)
- if (cxvec_append(x, &xr1->xc_nodeset, &xr1->xc_size) < 0)
- goto done;
- }
- else {
- /* if PredicateExpr evaluates to true for that node, the node is
- included in the new node-set */
- if (ctx2boolean(xrc))
- if (cxvec_append(x, &xr1->xc_nodeset, &xr1->xc_size) < 0)
- goto done;
- }
- if (xrc)
- ctx_free(xrc);
- }
+ /* Loop over each node in the nodeset */
+ assert (xr0->xc_type == XT_NODESET);
+ if ((xr1 = malloc(sizeof(*xr1))) == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
+ }
+ memset(xr1, 0, sizeof(*xr1));
+ xr1->xc_type = XT_NODESET;
+ xr1->xc_node = xc->xc_node;
+ xr1->xc_initial = xc->xc_initial;
+ for (i=0; ixc_size; i++){
+ x = xr0->xc_nodeset[i];
+ /* Create new context */
+ if ((xcc = malloc(sizeof(*xcc))) == NULL){
+ clicon_err(OE_XML, errno, "malloc");
+ goto done;
+ }
+ memset(xcc, 0, sizeof(*xcc));
+ xcc->xc_type = XT_NODESET;
+ xcc->xc_initial = xc->xc_initial;
+ xcc->xc_node = x;
+ xcc->xc_position = i;
+ /* For each node in the node-set to be filtered, the PredicateExpr is
+ * evaluated with that node as the context node */
+ if (cxvec_append(x, &xcc->xc_nodeset, &xcc->xc_size) < 0)
+ goto done;
+ if (xp_eval(xcc, xs->xs_c1, nsc, localonly, &xrc) < 0)
+ goto done;
+ if (xcc)
+ ctx_free(xcc);
+ if (xrc->xc_type == XT_NUMBER){
+ /* If the result is a number, the result will be converted to true
+ if the number is equal to the context position */
+ if ((int)xrc->xc_number == i)
+ if (cxvec_append(x, &xr1->xc_nodeset, &xr1->xc_size) < 0)
+ goto done;
+ }
+ else {
+ /* if PredicateExpr evaluates to true for that node, the node is
+ included in the new node-set */
+ if (ctx2boolean(xrc))
+ if (cxvec_append(x, &xr1->xc_nodeset, &xr1->xc_size) < 0)
+ goto done;
+ }
+ if (xrc)
+ ctx_free(xrc);
+ }
}
if (xr0 == NULL && xr1 == NULL){
- clicon_err(OE_XML, EFAULT, "Internal error: no result produced");
- goto done;
+ clicon_err(OE_XML, EFAULT, "Internal error: no result produced");
+ goto done;
}
if (xr1){
- *xrp = xr1;
- xr1 = NULL;
+ *xrp = xr1;
+ xr1 = NULL;
}
else if (xr0){
- *xrp = xr0;
- xr0 = NULL;
+ *xrp = xr0;
+ xr0 = NULL;
}
retval = 0;
done:
if (xr0)
- ctx_free(xr0);
+ ctx_free(xr0);
if (xr1)
- ctx_free(xr1);
+ ctx_free(xr1);
return retval;
}
@@ -569,9 +569,9 @@ xp_eval_predicate(xp_ctx *xc,
*/
static int
xp_logop(xp_ctx *xc1,
- xp_ctx *xc2,
- enum xp_op op,
- xp_ctx **xrp)
+ xp_ctx *xc2,
+ enum xp_op op,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr = NULL;
@@ -579,27 +579,27 @@ xp_logop(xp_ctx *xc1,
int b2;
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_initial = xc1->xc_initial;
xr->xc_type = XT_BOOL;
if ((b1 = ctx2boolean(xc1)) < 0)
- goto done;
+ goto done;
if ((b2 = ctx2boolean(xc2)) < 0)
- goto done;
+ goto done;
switch (op){
case XO_AND:
- xr->xc_bool = b1 && b2;
- break;
+ xr->xc_bool = b1 && b2;
+ break;
case XO_OR:
- xr->xc_bool = b1 || b2;
- break;
+ xr->xc_bool = b1 || b2;
+ break;
default:
- clicon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context",
- __FUNCTION__, clicon_int2str(xpopmap,op));
- goto done;
+ clicon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context",
+ __FUNCTION__, clicon_int2str(xpopmap,op));
+ goto done;
}
*xrp = xr;
retval = 0;
@@ -619,9 +619,9 @@ xp_logop(xp_ctx *xc1,
*/
static int
xp_numop(xp_ctx *xc1,
- xp_ctx *xc2,
- enum xp_op op,
- xp_ctx **xrp)
+ xp_ctx *xc2,
+ enum xp_op op,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr = NULL;
@@ -629,40 +629,40 @@ xp_numop(xp_ctx *xc1,
double n2;
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_initial = xc1->xc_initial;
xr->xc_type = XT_NUMBER;
if (ctx2number(xc1, &n1) < 0)
- goto done;
+ goto done;
if (ctx2number(xc2, &n2) < 0)
- goto done;
+ goto done;
if (isnan(n1) || isnan(n2))
- xr->xc_number = NAN;
+ xr->xc_number = NAN;
else
- switch (op){
- case XO_DIV:
- xr->xc_number = n1/n2;
- break;
- case XO_MOD:
- xr->xc_number = ((int)n1)%((int)n2);
- break;
- case XO_ADD:
- xr->xc_number = n1+n2;
- break;
- case XO_MULT:
- xr->xc_number = n1*n2;
- break;
- case XO_SUB:
- xr->xc_number = n1-n2;
- break;
- default:
- clicon_err(OE_UNIX, errno, "Invalid operator %s in this context",
- clicon_int2str(xpopmap,op));
- goto done;
- }
+ switch (op){
+ case XO_DIV:
+ xr->xc_number = n1/n2;
+ break;
+ case XO_MOD:
+ xr->xc_number = ((int)n1)%((int)n2);
+ break;
+ case XO_ADD:
+ xr->xc_number = n1+n2;
+ break;
+ case XO_MULT:
+ xr->xc_number = n1*n2;
+ break;
+ case XO_SUB:
+ xr->xc_number = n1-n2;
+ break;
+ default:
+ clicon_err(OE_UNIX, errno, "Invalid operator %s in this context",
+ clicon_int2str(xpopmap,op));
+ goto done;
+ }
*xrp = xr;
retval = 0;
done:
@@ -692,9 +692,9 @@ xp_numop(xp_ctx *xc1,
*/
static int
xp_relop(xp_ctx *xc1,
- xp_ctx *xc2,
- enum xp_op op,
- xp_ctx **xrp)
+ xp_ctx *xc2,
+ enum xp_op op,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr = NULL;
@@ -709,206 +709,206 @@ xp_relop(xp_ctx *xc1,
double n1, n2;
if (xc1 == NULL || xc2 == NULL){
- clicon_err(OE_UNIX, EINVAL, "xc1 or xc2 NULL");
- goto done;
+ clicon_err(OE_UNIX, EINVAL, "xc1 or xc2 NULL");
+ goto done;
}
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_initial = xc1->xc_initial;
xr->xc_type = XT_BOOL;
if (xc1->xc_type == xc2->xc_type){ /* cases (2-3) above */
- switch (xc1->xc_type){
- case XT_NODESET:
- /* If both are node-sets, then it is true iff the string value of one
- node in the first node-set and one in the second node-set is true */
- for (i=0; ixc_size; i++){
- if ((s1 = xml_body(xc1->xc_nodeset[i])) == NULL){
- xr->xc_bool = 0;
- goto ok;
- }
- for (j=0; jxc_size; j++){
- if ((s2 = xml_body(xc2->xc_nodeset[j])) == NULL){
- xr->xc_bool = 0;
- goto ok;
- }
- switch(op){
- case XO_EQ:
- xr->xc_bool = (strcmp(s1, s2)==0);
- break;
- case XO_NE:
- xr->xc_bool = (strcmp(s1, s2)!=0);
- break;
- case XO_GE:
- xr->xc_bool = (strcmp(s1, s2)>=0);
- break;
- case XO_LE:
- xr->xc_bool = (strcmp(s1, s2)<=0);
- break;
- case XO_LT:
- xr->xc_bool = (strcmp(s1, s2)<0);
- break;
- case XO_GT:
- xr->xc_bool = (strcmp(s1, s2)>0);
- break;
- default:
- clicon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op));
- goto done;
- break;
- }
- if (xr->xc_bool) /* enough to find a single node */
- break;
- }
- if (xr->xc_bool) /* enough to find a single node */
- break;
- }
- break;
- case XT_BOOL:
- xr->xc_bool = (xc1->xc_bool == xc2->xc_bool);
- break;
- case XT_NUMBER:
- switch(op){
- case XO_EQ:
- xr->xc_bool = (xc1->xc_number == xc2->xc_number);
- break;
- case XO_NE:
- xr->xc_bool = (xc1->xc_number != xc2->xc_number);
- break;
- case XO_GE:
- xr->xc_bool = (xc1->xc_number >= xc2->xc_number);
- break;
- case XO_LE:
- xr->xc_bool = (xc1->xc_number <= xc2->xc_number);
- break;
- case XO_LT:
- xr->xc_bool = (xc1->xc_number < xc2->xc_number);
- break;
- case XO_GT:
- xr->xc_bool = (xc1->xc_number > xc2->xc_number);
- break;
- default:
- clicon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op));
- goto done;
- break;
- }
- break;
- case XT_STRING:
- xr->xc_bool = (strcmp(xc1->xc_string, xc2->xc_string)==0);
- break;
- } /* switch xc1 */
+ switch (xc1->xc_type){
+ case XT_NODESET:
+ /* If both are node-sets, then it is true iff the string value of one
+ node in the first node-set and one in the second node-set is true */
+ for (i=0; ixc_size; i++){
+ if ((s1 = xml_body(xc1->xc_nodeset[i])) == NULL){
+ xr->xc_bool = 0;
+ goto ok;
+ }
+ for (j=0; jxc_size; j++){
+ if ((s2 = xml_body(xc2->xc_nodeset[j])) == NULL){
+ xr->xc_bool = 0;
+ goto ok;
+ }
+ switch(op){
+ case XO_EQ:
+ xr->xc_bool = (strcmp(s1, s2)==0);
+ break;
+ case XO_NE:
+ xr->xc_bool = (strcmp(s1, s2)!=0);
+ break;
+ case XO_GE:
+ xr->xc_bool = (strcmp(s1, s2)>=0);
+ break;
+ case XO_LE:
+ xr->xc_bool = (strcmp(s1, s2)<=0);
+ break;
+ case XO_LT:
+ xr->xc_bool = (strcmp(s1, s2)<0);
+ break;
+ case XO_GT:
+ xr->xc_bool = (strcmp(s1, s2)>0);
+ break;
+ default:
+ clicon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op));
+ goto done;
+ break;
+ }
+ if (xr->xc_bool) /* enough to find a single node */
+ break;
+ }
+ if (xr->xc_bool) /* enough to find a single node */
+ break;
+ }
+ break;
+ case XT_BOOL:
+ xr->xc_bool = (xc1->xc_bool == xc2->xc_bool);
+ break;
+ case XT_NUMBER:
+ switch(op){
+ case XO_EQ:
+ xr->xc_bool = (xc1->xc_number == xc2->xc_number);
+ break;
+ case XO_NE:
+ xr->xc_bool = (xc1->xc_number != xc2->xc_number);
+ break;
+ case XO_GE:
+ xr->xc_bool = (xc1->xc_number >= xc2->xc_number);
+ break;
+ case XO_LE:
+ xr->xc_bool = (xc1->xc_number <= xc2->xc_number);
+ break;
+ case XO_LT:
+ xr->xc_bool = (xc1->xc_number < xc2->xc_number);
+ break;
+ case XO_GT:
+ xr->xc_bool = (xc1->xc_number > xc2->xc_number);
+ break;
+ default:
+ clicon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op));
+ goto done;
+ break;
+ }
+ break;
+ case XT_STRING:
+ xr->xc_bool = (strcmp(xc1->xc_string, xc2->xc_string)==0);
+ break;
+ } /* switch xc1 */
}
else if (xc1->xc_type != XT_NODESET &&
- xc2->xc_type != XT_NODESET){
- clicon_err(OE_XML, 0, "Mixed types not supported, %d %d", xc1->xc_type, xc2->xc_type);
- goto done;
+ xc2->xc_type != XT_NODESET){
+ clicon_err(OE_XML, 0, "Mixed types not supported, %d %d", xc1->xc_type, xc2->xc_type);
+ goto done;
}
else{ /* one is nodeset, ie (1) above */
- if (xc2->xc_type == XT_NODESET){
- xc = xc2;
- xc2 = xc1;
- xc1 = xc;
- reverse++; /* reverse */
- }
- /* xc1 is nodeset
- * xc2 is something else */
- switch (xc2->xc_type){
- case XT_BOOL:
- /* comparison on the boolean and the result of converting the
- node-set to a boolean using the boolean function is true. */
- b = ctx2boolean(xc1);
- switch(op){
- case XO_EQ:
- xr->xc_bool = (b == xc2->xc_bool);
- break;
- case XO_NE:
- xr->xc_bool = (b != xc2->xc_bool);
- break;
- default:
- clicon_err(OE_XML, 0, "Operator %s not supported for nodeset and bool", clicon_int2str(xpopmap,op));
- goto done;
- break;
- } /* switch op */
- break;
- case XT_STRING:
- /* If one object to be compared is a node-set and the
- other is a string, then the comparison will be true if and only
- if there is a node in the node-set such that the result of
- performing the comparison on the string-value of the node and
- the other string is true.*/
- s2 = xc2->xc_string;
- for (i=0; ixc_size; i++){
- x = xc1->xc_nodeset[i]; /* node in nodeset */
- s1 = xml_body(x);
- switch(op){
- case XO_EQ:
- if (s1 == NULL && s2 == NULL)
- xr->xc_bool = 1;
- else if (s1 == NULL && strlen(s2) == 0)
- xr->xc_bool = 1;
- else if (strlen(s1) == 0 && s2 == NULL)
- xr->xc_bool = 1;
- else
- xr->xc_bool = (strcmp(s1, s2)==0);
- break;
- case XO_NE:
- if (s1 == NULL || s2 == NULL)
- xr->xc_bool = !(s1==NULL && s2 == NULL);
- else
- xr->xc_bool = (strcmp(s1, s2));
- break;
- default:
- clicon_err(OE_XML, 0, "Operator %s not supported for nodeset and string", clicon_int2str(xpopmap,op));
- goto done;
- break;
- }
- if (xr->xc_bool) /* enough to find a single node */
- break;
- }
- break;
- case XT_NUMBER:
- for (i=0; ixc_size; i++){
- x = xc1->xc_nodeset[i]; /* node in nodeset */
- if (sscanf(xml_body(x), "%lf", &n1) != 1)
- n1 = NAN;
- n2 = xc2->xc_number;
- switch(op){
- case XO_EQ:
- xr->xc_bool = (n1 == n2);
- break;
- case XO_NE:
- xr->xc_bool = (n1 != n2);
- break;
- case XO_GE:
- xr->xc_bool = reverse?(n2 >= n1):(n1 >= n2);
- break;
- case XO_LE:
- xr->xc_bool = reverse?(n2 <= n1):(n1 <= n2);
- break;
- case XO_LT:
- xr->xc_bool = reverse?(n2 < n1):(n1 < n2);
- break;
- case XO_GT:
- xr->xc_bool = reverse?(n2 > n1):(n1 > n2);
- break;
- default:
- clicon_err(OE_XML, 0, "Operator %s not supported for nodeset and number", clicon_int2str(xpopmap,op));
- goto done;
- break;
- }
- if (xr->xc_bool) /* enough to find a single node */
- break;
- }
- break;
- default:
- clicon_err(OE_XML, 0, "Type %d not supported", xc2->xc_type);
- } /* switch type */
+ if (xc2->xc_type == XT_NODESET){
+ xc = xc2;
+ xc2 = xc1;
+ xc1 = xc;
+ reverse++; /* reverse */
+ }
+ /* xc1 is nodeset
+ * xc2 is something else */
+ switch (xc2->xc_type){
+ case XT_BOOL:
+ /* comparison on the boolean and the result of converting the
+ node-set to a boolean using the boolean function is true. */
+ b = ctx2boolean(xc1);
+ switch(op){
+ case XO_EQ:
+ xr->xc_bool = (b == xc2->xc_bool);
+ break;
+ case XO_NE:
+ xr->xc_bool = (b != xc2->xc_bool);
+ break;
+ default:
+ clicon_err(OE_XML, 0, "Operator %s not supported for nodeset and bool", clicon_int2str(xpopmap,op));
+ goto done;
+ break;
+ } /* switch op */
+ break;
+ case XT_STRING:
+ /* If one object to be compared is a node-set and the
+ other is a string, then the comparison will be true if and only
+ if there is a node in the node-set such that the result of
+ performing the comparison on the string-value of the node and
+ the other string is true.*/
+ s2 = xc2->xc_string;
+ for (i=0; ixc_size; i++){
+ x = xc1->xc_nodeset[i]; /* node in nodeset */
+ s1 = xml_body(x);
+ switch(op){
+ case XO_EQ:
+ if (s1 == NULL && s2 == NULL)
+ xr->xc_bool = 1;
+ else if (s1 == NULL && strlen(s2) == 0)
+ xr->xc_bool = 1;
+ else if (strlen(s1) == 0 && s2 == NULL)
+ xr->xc_bool = 1;
+ else
+ xr->xc_bool = (strcmp(s1, s2)==0);
+ break;
+ case XO_NE:
+ if (s1 == NULL || s2 == NULL)
+ xr->xc_bool = !(s1==NULL && s2 == NULL);
+ else
+ xr->xc_bool = (strcmp(s1, s2));
+ break;
+ default:
+ clicon_err(OE_XML, 0, "Operator %s not supported for nodeset and string", clicon_int2str(xpopmap,op));
+ goto done;
+ break;
+ }
+ if (xr->xc_bool) /* enough to find a single node */
+ break;
+ }
+ break;
+ case XT_NUMBER:
+ for (i=0; ixc_size; i++){
+ x = xc1->xc_nodeset[i]; /* node in nodeset */
+ if (sscanf(xml_body(x), "%lf", &n1) != 1)
+ n1 = NAN;
+ n2 = xc2->xc_number;
+ switch(op){
+ case XO_EQ:
+ xr->xc_bool = (n1 == n2);
+ break;
+ case XO_NE:
+ xr->xc_bool = (n1 != n2);
+ break;
+ case XO_GE:
+ xr->xc_bool = reverse?(n2 >= n1):(n1 >= n2);
+ break;
+ case XO_LE:
+ xr->xc_bool = reverse?(n2 <= n1):(n1 <= n2);
+ break;
+ case XO_LT:
+ xr->xc_bool = reverse?(n2 < n1):(n1 < n2);
+ break;
+ case XO_GT:
+ xr->xc_bool = reverse?(n2 > n1):(n1 > n2);
+ break;
+ default:
+ clicon_err(OE_XML, 0, "Operator %s not supported for nodeset and number", clicon_int2str(xpopmap,op));
+ goto done;
+ break;
+ }
+ if (xr->xc_bool) /* enough to find a single node */
+ break;
+ }
+ break;
+ default:
+ clicon_err(OE_XML, 0, "Type %d not supported", xc2->xc_type);
+ } /* switch type */
}
ok:
/* Just ensure bool is 0 or 1 */
if (xr->xc_type == XT_BOOL && xr->xc_bool != 0)
- xr->xc_bool = 1;
+ xr->xc_bool = 1;
*xrp = xr;
retval = 0;
done:
@@ -926,33 +926,33 @@ xp_relop(xp_ctx *xc1,
*/
static int
xp_union(xp_ctx *xc1,
- xp_ctx *xc2,
- enum xp_op op,
- xp_ctx **xrp)
+ xp_ctx *xc2,
+ enum xp_op op,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr = NULL;
int i;
if (op != XO_UNION){
- clicon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context",
- __FUNCTION__, clicon_int2str(xpopmap,op));
- goto done;
+ clicon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context",
+ __FUNCTION__, clicon_int2str(xpopmap,op));
+ goto done;
}
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_initial = xc1->xc_initial;
xr->xc_type = XT_NODESET;
for (i=0; ixc_size; i++)
- if (cxvec_append(xc1->xc_nodeset[i], &xr->xc_nodeset, &xr->xc_size) < 0)
- goto done;
+ if (cxvec_append(xc1->xc_nodeset[i], &xr->xc_nodeset, &xr->xc_size) < 0)
+ goto done;
for (i=0; ixc_size; i++){
- if (cxvec_append(xc2->xc_nodeset[i], &xr->xc_nodeset, &xr->xc_size) < 0)
- goto done;
+ if (cxvec_append(xc2->xc_nodeset[i], &xr->xc_nodeset, &xr->xc_size) < 0)
+ goto done;
}
*xrp = xr;
retval = 0;
@@ -974,10 +974,10 @@ xp_union(xp_ctx *xc1,
*/
int
xp_eval(xp_ctx *xc,
- xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
cxobj *x;
@@ -987,255 +987,255 @@ xp_eval(xp_ctx *xc,
int use_xr0 = 0; /* In 2nd child use transitively result of 1st child */
if (clicon_debug_get() > 1)
- ctx_print(stderr, xc, xpath_tree_int2str(xs->xs_type));
+ ctx_print(stderr, xc, xpath_tree_int2str(xs->xs_type));
/* Pre-actions before check first child c0
*/
switch (xs->xs_type){
case XP_RELLOCPATH:
- if (xs->xs_int == A_DESCENDANT_OR_SELF)
- xc->xc_descendant = 1; /* XXX need to set to 0 in sub */
- break;
+ if (xs->xs_int == A_DESCENDANT_OR_SELF)
+ xc->xc_descendant = 1; /* XXX need to set to 0 in sub */
+ break;
case XP_ABSPATH:
- /* Set context node to top node, and nodeset to that node only */
- x = xc->xc_node;
+ /* Set context node to top node, and nodeset to that node only */
+ x = xc->xc_node;
#ifdef XML_PARENT_CANDIDATE
- while (xml_parent(x) != NULL || xml_parent_candidate(x) != NULL)
- x = xml_parent(x)?xml_parent(x):xml_parent_candidate(x);
+ while (xml_parent(x) != NULL || xml_parent_candidate(x) != NULL)
+ x = xml_parent(x)?xml_parent(x):xml_parent_candidate(x);
#else
- while (xml_parent(x) != NULL)
- x = xml_parent(x);
+ while (xml_parent(x) != NULL)
+ x = xml_parent(x);
#endif
- xc->xc_node = x;
- xc->xc_nodeset[0] = x;
- xc->xc_size=1;
- /* // is short for /descendant-or-self::node()/ */
- if (xs->xs_int == A_DESCENDANT_OR_SELF)
- xc->xc_descendant = 1; /* XXX need to set to 0 in sub */
- break;
+ xc->xc_node = x;
+ xc->xc_nodeset[0] = x;
+ xc->xc_size=1;
+ /* // is short for /descendant-or-self::node()/ */
+ if (xs->xs_int == A_DESCENDANT_OR_SELF)
+ xc->xc_descendant = 1; /* XXX need to set to 0 in sub */
+ break;
case XP_STEP: /* XP_NODE is first argument -not called explicitly */
- if (xp_eval_step(xc, xs, nsc, localonly, xrp) < 0)
- goto done;
- goto ok; /* Skip generic child traverse */
- break;
+ if (xp_eval_step(xc, xs, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok; /* Skip generic child traverse */
+ break;
case XP_PRED:
- if (xp_eval_predicate(xc, xs, nsc, localonly, xrp) < 0)
- goto done;
- goto ok;
- break;
+ if (xp_eval_predicate(xc, xs, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
case XP_PRIME_FN:
- if (xs->xs_s0){
- switch (xs->xs_int){
- case XPATHFN_CURRENT:
- if (xp_function_current(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
- goto done;
- goto ok;
- break;
- case XPATHFN_DEREF:
- if (xp_function_deref(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
- goto done;
- goto ok;
- break;
- case XPATHFN_DERIVED_FROM:
- if (xp_function_derived_from(xc, xs->xs_c0, nsc, localonly, 0, xrp) < 0)
- goto done;
- goto ok;
- break;
- case XPATHFN_DERIVED_FROM_OR_SELF:
- if (xp_function_derived_from(xc, xs->xs_c0, nsc, localonly, 1, xrp) < 0)
- goto done;
- goto ok;
- break;
- case XPATHFN_BIT_IS_SET:
- if (xp_function_bit_is_set(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
- goto done;
- goto ok;
- break;
- case XPATHFN_POSITION:
- if (xp_function_position(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
- goto done;
- goto ok;
- break;
- case XPATHFN_COUNT:
- if (xp_function_count(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
- goto done;
- goto ok;
- break;
- case XPATHFN_NAME:
- if (xp_function_name(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
- goto done;
- goto ok;
- break;
- case XPATHFN_CONTAINS:
- if (xp_function_contains(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
- goto done;
- goto ok;
- break;
- case XPATHFN_BOOLEAN:
- if (xp_function_boolean(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
- goto done;
- goto ok;
- break;
- case XPATHFN_NOT:
- if (xp_function_not(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
- goto done;
- goto ok;
- break;
- case XPATHFN_TRUE:
- if (xp_function_true(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
- goto done;
- goto ok;
- break;
- case XPATHFN_FALSE:
- if (xp_function_false(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
- goto done;
- goto ok;
- break;
- default:
- clicon_err(OE_XML, EFAULT, "XPATH function not implemented: %s", xs->xs_s0);
- goto done;
- break;
- }
- }
- break;
+ if (xs->xs_s0){
+ switch (xs->xs_int){
+ case XPATHFN_CURRENT:
+ if (xp_function_current(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ case XPATHFN_DEREF:
+ if (xp_function_deref(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ case XPATHFN_DERIVED_FROM:
+ if (xp_function_derived_from(xc, xs->xs_c0, nsc, localonly, 0, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ case XPATHFN_DERIVED_FROM_OR_SELF:
+ if (xp_function_derived_from(xc, xs->xs_c0, nsc, localonly, 1, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ case XPATHFN_BIT_IS_SET:
+ if (xp_function_bit_is_set(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ case XPATHFN_POSITION:
+ if (xp_function_position(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ case XPATHFN_COUNT:
+ if (xp_function_count(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ case XPATHFN_NAME:
+ if (xp_function_name(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ case XPATHFN_CONTAINS:
+ if (xp_function_contains(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ case XPATHFN_BOOLEAN:
+ if (xp_function_boolean(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ case XPATHFN_NOT:
+ if (xp_function_not(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ case XPATHFN_TRUE:
+ if (xp_function_true(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ case XPATHFN_FALSE:
+ if (xp_function_false(xc, xs->xs_c0, nsc, localonly, xrp) < 0)
+ goto done;
+ goto ok;
+ break;
+ default:
+ clicon_err(OE_XML, EFAULT, "XPATH function not implemented: %s", xs->xs_s0);
+ goto done;
+ break;
+ }
+ }
+ break;
default:
- break;
+ break;
}
/* Eval first child c0
*/
if (xs->xs_c0){
- if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
- goto done;
+ if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
+ goto done;
}
/* Actions between first and second child
*/
switch (xs->xs_type){
case XP_EXP:
- break;
+ break;
case XP_AND:
- break;
+ break;
case XP_RELEX: /* relexpr --> addexpr | relexpr relop addexpr */
- break;
+ break;
case XP_ADD: /* combine mult and add ops */
- break;
+ break;
case XP_UNION:
- break;
+ break;
case XP_PATHEXPR:
- if (xs->xs_c1)
- use_xr0++;
- break;
+ if (xs->xs_c1)
+ use_xr0++;
+ break;
case XP_FILTEREXPR:
- break;
+ break;
case XP_LOCPATH:
- break;
+ break;
case XP_ABSPATH:
- use_xr0++;
- /* Special case, no c0 or c1, single "/" */
- if (xs->xs_c0 == NULL){
- if ((xr0 = malloc(sizeof(*xr0))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
- }
- memset(xr0, 0, sizeof(*xr0));
- xr0->xc_initial = xc->xc_initial;
- xr0->xc_type = XT_NODESET;
- x = NULL;
- while ((x = xml_child_each(xc->xc_node, x, CX_ELMNT)) != NULL) {
- if (cxvec_append(x, &xr0->xc_nodeset, &xr0->xc_size) < 0)
- goto done;
- }
- }
- break;
+ use_xr0++;
+ /* Special case, no c0 or c1, single "/" */
+ if (xs->xs_c0 == NULL){
+ if ((xr0 = malloc(sizeof(*xr0))) == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
+ }
+ memset(xr0, 0, sizeof(*xr0));
+ xr0->xc_initial = xc->xc_initial;
+ xr0->xc_type = XT_NODESET;
+ x = NULL;
+ while ((x = xml_child_each(xc->xc_node, x, CX_ELMNT)) != NULL) {
+ if (cxvec_append(x, &xr0->xc_nodeset, &xr0->xc_size) < 0)
+ goto done;
+ }
+ }
+ break;
case XP_RELLOCPATH:
- use_xr0++;
- if (xs->xs_int == A_DESCENDANT_OR_SELF)
- xc->xc_descendant = 1; /* XXX need to set to 0 in sub */
- break;
+ use_xr0++;
+ if (xs->xs_int == A_DESCENDANT_OR_SELF)
+ xc->xc_descendant = 1; /* XXX need to set to 0 in sub */
+ break;
case XP_NODE:
- break;
+ break;
case XP_NODE_FN:
- break;
+ break;
case XP_PRI0:
- break;
+ break;
case XP_PRIME_NR: /* primaryexpr -> [] */
- if ((xr0 = malloc(sizeof(*xr0))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
- }
- memset(xr0, 0, sizeof(*xr0));
- xr0->xc_initial = xc->xc_initial;
- xr0->xc_type = XT_NUMBER;
- xr0->xc_number = xs->xs_double;
- break;
+ if ((xr0 = malloc(sizeof(*xr0))) == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
+ }
+ memset(xr0, 0, sizeof(*xr0));
+ xr0->xc_initial = xc->xc_initial;
+ xr0->xc_type = XT_NUMBER;
+ xr0->xc_number = xs->xs_double;
+ break;
case XP_PRIME_STR:
- if ((xr0 = malloc(sizeof(*xr0))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
- }
- memset(xr0, 0, sizeof(*xr0));
- xr0->xc_initial = xc->xc_initial;
- xr0->xc_type = XT_STRING;
- xr0->xc_string = xs->xs_s0?strdup(xs->xs_s0):NULL;
- break;
+ if ((xr0 = malloc(sizeof(*xr0))) == NULL){
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
+ }
+ memset(xr0, 0, sizeof(*xr0));
+ xr0->xc_initial = xc->xc_initial;
+ xr0->xc_type = XT_STRING;
+ xr0->xc_string = xs->xs_s0?strdup(xs->xs_s0):NULL;
+ break;
default:
- break;
+ break;
}
/* Eval second child c1
* Note, some operators like locationpath, need transitive context (use_xr0)
*/
if (xs->xs_c1){
- if (xp_eval(use_xr0?xr0:xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
- goto done;
- /* Actions after second child
- */
- switch (xs->xs_type){
- case XP_AND: /* combine and and or ops */
- if (xp_logop(xr0, xr1, xs->xs_int, &xr2) < 0)
- goto done;
- break;
- case XP_RELEX: /* relexpr --> addexpr | relexpr relop addexpr */
- if (xp_relop(xr0, xr1, xs->xs_int, &xr2) < 0)
- goto done;
- break;
- case XP_ADD: /* combine mult and add ops */
- if (xp_numop(xr0, xr1, xs->xs_int, &xr2) < 0)
- goto done;
- break;
- case XP_UNION: /* combine and and or ops */
- if (xp_union(xr0, xr1, xs->xs_int, &xr2) < 0)
- goto done;
- default:
- break;
- }
+ if (xp_eval(use_xr0?xr0:xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
+ goto done;
+ /* Actions after second child
+ */
+ switch (xs->xs_type){
+ case XP_AND: /* combine and and or ops */
+ if (xp_logop(xr0, xr1, xs->xs_int, &xr2) < 0)
+ goto done;
+ break;
+ case XP_RELEX: /* relexpr --> addexpr | relexpr relop addexpr */
+ if (xp_relop(xr0, xr1, xs->xs_int, &xr2) < 0)
+ goto done;
+ break;
+ case XP_ADD: /* combine mult and add ops */
+ if (xp_numop(xr0, xr1, xs->xs_int, &xr2) < 0)
+ goto done;
+ break;
+ case XP_UNION: /* combine and and or ops */
+ if (xp_union(xr0, xr1, xs->xs_int, &xr2) < 0)
+ goto done;
+ default:
+ break;
+ }
}
xc->xc_descendant = 0;
if (xr0 == NULL && xr1 == NULL && xr2 == NULL){
- clicon_err(OE_XML, EFAULT, "Internal error: no result produced");
- goto done;
+ clicon_err(OE_XML, EFAULT, "Internal error: no result produced");
+ goto done;
}
if (xr2){
- *xrp = xr2;
- xr2 = NULL;
+ *xrp = xr2;
+ xr2 = NULL;
}
else if (xr1){
- *xrp = xr1;
- xr1 = NULL;
+ *xrp = xr1;
+ xr1 = NULL;
}
else
- if (xr0){
- *xrp = xr0;
- xr0 = NULL;
- }
+ if (xr0){
+ *xrp = xr0;
+ xr0 = NULL;
+ }
ok:
if (clicon_debug_get() > 1)
- ctx_print(stderr, *xrp, xpath_tree_int2str(xs->xs_type));
+ ctx_print(stderr, *xrp, xpath_tree_int2str(xs->xs_type));
retval = 0;
done:
if (xr2)
- ctx_free(xr2);
+ ctx_free(xr2);
if (xr1)
- ctx_free(xr1);
+ ctx_free(xr1);
if (xr0)
- ctx_free(xr0);
+ ctx_free(xr0);
return retval;
} /* xp_eval */
diff --git a/lib/src/clixon_xpath_function.c b/lib/src/clixon_xpath_function.c
index 5d4fc2ee..430f90ac 100644
--- a/lib/src/clixon_xpath_function.c
+++ b/lib/src/clixon_xpath_function.c
@@ -136,10 +136,10 @@ xp_fnname_int2str(enum clixon_xpath_function code)
int
xp_function_current(xp_ctx *xc0,
- struct xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ struct xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
cxobj **vec = NULL;
@@ -147,25 +147,25 @@ xp_function_current(xp_ctx *xc0,
xp_ctx *xc = NULL;
if ((xc = ctx_dup(xc0)) == NULL)
- goto done;
+ goto done;
if (cxvec_append(xc->xc_initial, &vec, &veclen) < 0)
- goto done;
+ goto done;
ctx_nodeset_replace(xc, vec, veclen);
*xrp = xc;
xc = NULL;
retval = 0;
done:
if (xc)
- ctx_free(xc);
+ ctx_free(xc);
return retval;
}
int
xp_function_deref(xp_ctx *xc0,
- struct xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ struct xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xc = NULL;
@@ -181,32 +181,32 @@ xp_function_deref(xp_ctx *xc0,
/* Create new xc */
if ((xc = ctx_dup(xc0)) == NULL)
- goto done;
+ goto done;
for (i=0; ixc_size; i++){
- xv = xc->xc_nodeset[i];
- if ((ys = xml_spec(xv)) == NULL)
- continue;
- /* Get base type yc */
- if (yang_type_get(ys, NULL, &yt, NULL, NULL, NULL, NULL, NULL) < 0)
- goto done;
- if (strcmp(yang_argument_get(yt), "leafref") == 0){
- if ((ypath = yang_find(yt, Y_PATH, NULL)) != NULL){
- path = yang_argument_get(ypath);
- if ((xref = xpath_first(xv, nsc, "%s", path)) != NULL)
- if (cxvec_append(xref, &vec, &veclen) < 0)
- goto done;
- }
- ctx_nodeset_replace(xc, vec, veclen);
- }
- else if (strcmp(yang_argument_get(yt), "identityref") == 0){
- }
+ xv = xc->xc_nodeset[i];
+ if ((ys = xml_spec(xv)) == NULL)
+ continue;
+ /* Get base type yc */
+ if (yang_type_get(ys, NULL, &yt, NULL, NULL, NULL, NULL, NULL) < 0)
+ goto done;
+ if (strcmp(yang_argument_get(yt), "leafref") == 0){
+ if ((ypath = yang_find(yt, Y_PATH, NULL)) != NULL){
+ path = yang_argument_get(ypath);
+ if ((xref = xpath_first(xv, nsc, "%s", path)) != NULL)
+ if (cxvec_append(xref, &vec, &veclen) < 0)
+ goto done;
+ }
+ ctx_nodeset_replace(xc, vec, veclen);
+ }
+ else if (strcmp(yang_argument_get(yt), "identityref") == 0){
+ }
}
*xrp = xc;
xc = NULL;
retval = 0;
done:
if (xc)
- ctx_free(xc);
+ ctx_free(xc);
return retval;
}
@@ -219,9 +219,9 @@ xp_function_deref(xp_ctx *xc0,
*/
static int
derived_from_one(char *baseidentity,
- cvec *nsc,
- cxobj *xleaf,
- int self)
+ cvec *nsc,
+ cxobj *xleaf,
+ int self)
{
int retval = -1;
yang_stmt *yleaf;
@@ -237,16 +237,16 @@ derived_from_one(char *baseidentity,
/* Split baseidentity to get its id (w/o prefix) */
if (nodeid_split(baseidentity, NULL, &baseid) < 0)
- goto done;
+ goto done;
if ((yleaf = xml_spec(xleaf)) == NULL)
- goto nomatch;
+ goto nomatch;
if (yang_keyword_get(yleaf) != Y_LEAF && yang_keyword_get(yleaf) != Y_LEAF_LIST)
- goto nomatch;
+ goto nomatch;
/* Node is of type identityref */
if (yang_type_get(yleaf, NULL, &ytype, NULL, NULL, NULL, NULL, NULL) < 0)
- goto done;
+ goto done;
if (ytype == NULL || strcmp(yang_argument_get(ytype), "identityref"))
- goto nomatch;
+ goto nomatch;
/* Find if the derivation chain is: identity ->...-> ytype
* Example:
* identity is ex:ethernet
@@ -255,50 +255,50 @@ derived_from_one(char *baseidentity,
*/
/* Just get the object corresponding to the base identity */
if ((ybaseid = yang_find_identity_nsc(ys_spec(yleaf), baseidentity, nsc)) == NULL)
- goto nomatch;
+ goto nomatch;
/* Get its list of derived identities */
idrefvec = yang_cvec_get(ybaseid);
/* Get and split the leaf id reference */
if ((node = xml_body(xleaf)) == NULL) /* It may not be empty */
- goto nomatch;
+ goto nomatch;
if (nodeid_split(node, &prefix, &id) < 0)
- goto done;
+ goto done;
/* Get its module (prefixes are not used here) */
if (prefix == NULL)
- ymod = ys_module(yleaf);
+ ymod = ys_module(yleaf);
else{ /* from prefix to name */
#if 1 /* IDENTITYREF_KLUDGE */
- ymod = yang_find_module_by_prefix_yspec(ys_spec(yleaf), prefix);
+ ymod = yang_find_module_by_prefix_yspec(ys_spec(yleaf), prefix);
#endif
}
if (ymod == NULL)
- goto nomatch;
+ goto nomatch;
/* self special case, ie that the xleaf has a ref to itself */
if (self &&
- ymod == ys_module(ybaseid) &&
- strcmp(baseid, id) == 0){
- ; /* match */
+ ymod == ys_module(ybaseid) &&
+ strcmp(baseid, id) == 0){
+ ; /* match */
}
else {
- /* Allocate cbuf */
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
- if (cvec_find(idrefvec, cbuf_get(cb)) == NULL)
- goto nomatch;
+ /* Allocate cbuf */
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
+ if (cvec_find(idrefvec, cbuf_get(cb)) == NULL)
+ goto nomatch;
}
retval = 1;
done:
if (baseid)
- free(baseid);
+ free(baseid);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (id)
- free(id);
+ free(id);
if (prefix)
- free(prefix);
+ free(prefix);
return retval;
nomatch:
retval = 0;
@@ -322,11 +322,11 @@ derived_from_one(char *baseidentity,
*/
int
xp_function_derived_from(xp_ctx *xc,
- struct xpath_tree *xs,
- cvec *nsc,
- int localonly,
- int self,
- xp_ctx **xrp)
+ struct xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ int self,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr0 = NULL;
@@ -337,33 +337,33 @@ xp_function_derived_from(xp_ctx *xc,
int ret = 0;
if (xs == NULL || xs->xs_c0 == NULL || xs->xs_c1 == NULL){
- clicon_err(OE_XML, EINVAL, "derived-from expects but did not get two arguments");
- goto done;
+ clicon_err(OE_XML, EINVAL, "derived-from expects but did not get two arguments");
+ goto done;
}
/* contains two arguments in xs: boolean derived-from(node-set, string) */
/* This evolves to a set of (identityref) nodes */
- if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
- goto done;
+ if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
+ goto done;
if (xr0->xc_type != XT_NODESET)
- goto done;
+ goto done;
/* This evolves to a string identity */
- if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
- goto done;
+ if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
+ goto done;
if (ctx2string(xr1, &identity) < 0)
- goto done;
+ goto done;
/* Allocate a return struct of type boolean */
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_type = XT_BOOL;
/* ANY node is an identityref and its value an identity that is derived ... */
for (i=0; ixc_size; i++){
- if ((ret = derived_from_one(identity, nsc, xr0->xc_nodeset[i], self)) < 0)
- goto done;
- if (ret == 1)
- break;
+ if ((ret = derived_from_one(identity, nsc, xr0->xc_nodeset[i], self)) < 0)
+ goto done;
+ if (ret == 1)
+ break;
}
xr->xc_bool = ret;
*xrp = xr;
@@ -371,11 +371,11 @@ xp_function_derived_from(xp_ctx *xc,
retval = 0;
done:
if (xr0)
- ctx_free(xr0);
+ ctx_free(xr0);
if (xr1)
- ctx_free(xr1);
+ ctx_free(xr1);
if (identity)
- free(identity);
+ free(identity);
return retval;
}
@@ -401,10 +401,10 @@ xp_function_derived_from(xp_ctx *xc,
*/
int
xp_function_bit_is_set(xp_ctx *xc,
- struct xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ struct xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr = NULL;
@@ -415,20 +415,20 @@ xp_function_bit_is_set(xp_ctx *xc,
char *body;
if (xs == NULL || xs->xs_c0 == NULL || xs->xs_c1 == NULL){
- clicon_err(OE_XML, EINVAL, "contains expects but did not get two arguments");
- goto done;
+ clicon_err(OE_XML, EINVAL, "contains expects but did not get two arguments");
+ goto done;
}
/* First node-set argument */
- if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
- goto done;
+ if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
+ goto done;
/* Second string argument */
- if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
- goto done;
+ if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
+ goto done;
if (ctx2string(xr1, &s1) < 0)
- goto done;
+ goto done;
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_type = XT_BOOL;
@@ -437,19 +437,19 @@ xp_function_bit_is_set(xp_ctx *xc,
* its value has the bit "bit-name" set
*/
if (xr0->xc_size &&
- (x = xr0->xc_nodeset[0]) != NULL &&
- (body = xml_body(x)) != NULL){
- xr->xc_bool = strstr(body, s1) != NULL;
+ (x = xr0->xc_nodeset[0]) != NULL &&
+ (body = xml_body(x)) != NULL){
+ xr->xc_bool = strstr(body, s1) != NULL;
}
*xrp = xr;
retval = 0;
done:
if (xr0)
- ctx_free(xr0);
+ ctx_free(xr0);
if (xr1)
- ctx_free(xr1);
+ ctx_free(xr1);
if (s1)
- free(s1);
+ free(s1);
return retval;
}
@@ -466,17 +466,17 @@ xp_function_bit_is_set(xp_ctx *xc,
*/
int
xp_function_position(xp_ctx *xc,
- struct xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ struct xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr = NULL;
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_initial = xc->xc_initial;
@@ -494,24 +494,24 @@ xp_function_position(xp_ctx *xc,
*/
int
xp_function_count(xp_ctx *xc,
- struct xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ struct xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr = NULL;
xp_ctx *xr0 = NULL;
if (xs == NULL || xs->xs_c0 == NULL){
- clicon_err(OE_XML, EINVAL, "count expects but did not get one argument");
- goto done;
+ clicon_err(OE_XML, EINVAL, "count expects but did not get one argument");
+ goto done;
}
- if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
- goto done;
+ if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
+ goto done;
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_type = XT_NUMBER;
@@ -520,7 +520,7 @@ xp_function_count(xp_ctx *xc,
retval = 0;
done:
if (xr0)
- ctx_free(xr0);
+ ctx_free(xr0);
return retval;
}
@@ -533,10 +533,10 @@ xp_function_count(xp_ctx *xc,
*/
int
xp_function_name(xp_ctx *xc,
- struct xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ struct xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr = NULL;
@@ -546,33 +546,33 @@ xp_function_name(xp_ctx *xc,
cxobj *x;
if (xs == NULL || xs->xs_c0 == NULL){
- clicon_err(OE_XML, EINVAL, "not expects but did not get one argument");
- goto done;
+ clicon_err(OE_XML, EINVAL, "not expects but did not get one argument");
+ goto done;
}
- if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
- goto done;
+ if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
+ goto done;
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_type = XT_STRING;
for (i=0; ixc_size; i++){
- if ((x = xr0->xc_nodeset[i]) == NULL)
- continue;
- if ((xr->xc_string = strdup(xml_name(x))) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
- }
- break;
+ if ((x = xr0->xc_nodeset[i]) == NULL)
+ continue;
+ if ((xr->xc_string = strdup(xml_name(x))) == NULL){
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
+ }
+ break;
}
*xrp = xr;
retval = 0;
done:
if (xr0)
- ctx_free(xr0);
+ ctx_free(xr0);
if (s0)
- free(s0);
+ free(s0);
return retval;
}
@@ -588,10 +588,10 @@ xp_function_name(xp_ctx *xc,
*/
int
xp_function_contains(xp_ctx *xc,
- struct xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ struct xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr0 = NULL;
@@ -601,21 +601,21 @@ xp_function_contains(xp_ctx *xc,
char *s1 = NULL;
if (xs == NULL || xs->xs_c0 == NULL || xs->xs_c1 == NULL){
- clicon_err(OE_XML, EINVAL, "contains expects but did not get two arguments");
- goto done;
+ clicon_err(OE_XML, EINVAL, "contains expects but did not get two arguments");
+ goto done;
}
/* contains two arguments in xs: boolean contains(string, string) */
- if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
- goto done;
+ if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
+ goto done;
if (ctx2string(xr0, &s0) < 0)
- goto done;
- if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
- goto done;
+ goto done;
+ if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
+ goto done;
if (ctx2string(xr1, &s1) < 0)
- goto done;
+ goto done;
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_type = XT_BOOL;
@@ -625,13 +625,13 @@ xp_function_contains(xp_ctx *xc,
retval = 0;
done:
if (xr0)
- ctx_free(xr0);
+ ctx_free(xr0);
if (xr1)
- ctx_free(xr1);
+ ctx_free(xr1);
if (s0)
- free(s0);
+ free(s0);
if (s1)
- free(s1);
+ free(s1);
return retval;
}
@@ -647,10 +647,10 @@ xp_function_contains(xp_ctx *xc,
*/
int
xp_function_boolean(xp_ctx *xc,
- struct xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ struct xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr = NULL;
@@ -658,15 +658,15 @@ xp_function_boolean(xp_ctx *xc,
int bool;
if (xs == NULL || xs->xs_c0 == NULL){
- clicon_err(OE_XML, EINVAL, "not expects but did not get one argument");
- goto done;
+ clicon_err(OE_XML, EINVAL, "not expects but did not get one argument");
+ goto done;
}
- if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
- goto done;
+ if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
+ goto done;
bool = ctx2boolean(xr0);
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_type = XT_BOOL;
@@ -675,7 +675,7 @@ xp_function_boolean(xp_ctx *xc,
retval = 0;
done:
if (xr0)
- ctx_free(xr0);
+ ctx_free(xr0);
return retval;
}
@@ -685,13 +685,13 @@ xp_function_boolean(xp_ctx *xc,
*/
int
xp_function_not(xp_ctx *xc,
- struct xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ struct xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
if (xp_function_boolean(xc, xs, nsc, localonly, xrp) < 0)
- return -1;
+ return -1;
(*xrp)->xc_bool = !(*xrp)->xc_bool;
return 0;
}
@@ -702,17 +702,17 @@ xp_function_not(xp_ctx *xc,
*/
int
xp_function_true(xp_ctx *xc,
- struct xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ struct xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr = NULL;
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_type = XT_BOOL;
@@ -729,17 +729,17 @@ xp_function_true(xp_ctx *xc,
*/
int
xp_function_false(xp_ctx *xc,
- struct xpath_tree *xs,
- cvec *nsc,
- int localonly,
- xp_ctx **xrp)
+ struct xpath_tree *xs,
+ cvec *nsc,
+ int localonly,
+ xp_ctx **xrp)
{
int retval = -1;
xp_ctx *xr = NULL;
if ((xr = malloc(sizeof(*xr))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xr, 0, sizeof(*xr));
xr->xc_type = XT_BOOL;
diff --git a/lib/src/clixon_xpath_optimize.c b/lib/src/clixon_xpath_optimize.c
index 02c60cb0..e553d3e2 100644
--- a/lib/src/clixon_xpath_optimize.c
+++ b/lib/src/clixon_xpath_optimize.c
@@ -106,7 +106,7 @@ xpath_optimize_exit(void)
{
#ifdef XPATH_LIST_OPTIMIZE
if (_xmtop)
- xpath_tree_free(_xmtop);
+ xpath_tree_free(_xmtop);
#endif
}
@@ -117,37 +117,37 @@ xpath_optimize_exit(void)
*/
int
xpath_optimize_init(xpath_tree **xm,
- xpath_tree **xe)
+ xpath_tree **xe)
{
int retval = -1;
xpath_tree *xs;
if (_xm == NULL){
- /* Initialize xpath-tree */
- if (xpath_parse("_x[_y='_z']", &_xmtop) < 0)
- goto done;
- /* Go down two steps */
- if ((_xm = xpath_tree_traverse(_xmtop, 0, 0, -1)) == NULL)
- goto done;
- /* get nodetest tree (_x) */
- if ((xs = xpath_tree_traverse(_xm, 0, -1)) == NULL)
- goto done;
- xs->xs_match++;
- /* get predicates [_y=_z][z=2] */
- if ((xs = xpath_tree_traverse(_xm, 1, -1)) == NULL)
- goto done;
- xs->xs_match++;
- /* get expression [_y=_z] */
- if ((_xe = xpath_tree_traverse(xs, 1, -1)) == NULL)
- goto done;
- /* get keyname (_y) */
- if ((xs = xpath_tree_traverse(_xe, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1)) == NULL)
- goto done;
- xs->xs_match++; /* in loop_preds get name in xs_s1 XXX: leaf-list is different */
- /* get keyval (_z) */
- if ((xs = xpath_tree_traverse(_xe, 0, 0, 1, 0, 0, 0, 0, -1)) == NULL)
- goto done;
- xs->xs_match++; /* in loop_preds get value in xs_s0 or xs_strnr */
+ /* Initialize xpath-tree */
+ if (xpath_parse("_x[_y='_z']", &_xmtop) < 0)
+ goto done;
+ /* Go down two steps */
+ if ((_xm = xpath_tree_traverse(_xmtop, 0, 0, -1)) == NULL)
+ goto done;
+ /* get nodetest tree (_x) */
+ if ((xs = xpath_tree_traverse(_xm, 0, -1)) == NULL)
+ goto done;
+ xs->xs_match++;
+ /* get predicates [_y=_z][z=2] */
+ if ((xs = xpath_tree_traverse(_xm, 1, -1)) == NULL)
+ goto done;
+ xs->xs_match++;
+ /* get expression [_y=_z] */
+ if ((_xe = xpath_tree_traverse(xs, 1, -1)) == NULL)
+ goto done;
+ /* get keyname (_y) */
+ if ((xs = xpath_tree_traverse(_xe, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1)) == NULL)
+ goto done;
+ xs->xs_match++; /* in loop_preds get name in xs_s1 XXX: leaf-list is different */
+ /* get keyval (_z) */
+ if ((xs = xpath_tree_traverse(_xe, 0, 0, 1, 0, 0, 0, 0, -1)) == NULL)
+ goto done;
+ xs->xs_match++; /* in loop_preds get value in xs_s0 or xs_strnr */
}
*xm = _xm;
*xe = _xe;
@@ -169,8 +169,8 @@ xpath_optimize_init(xpath_tree **xm,
*/
static int
loop_preds(xpath_tree *xt,
- xpath_tree *xepat,
- cvec *cvk)
+ xpath_tree *xepat,
+ cvec *cvk)
{
int retval = -1;
int ret;
@@ -178,34 +178,34 @@ loop_preds(xpath_tree *xt,
xpath_tree **vec = NULL;
size_t veclen = 0;
cg_var *cvi;
-
+
if (xt->xs_type == XP_PRED && xt->xs_c0){
- if ((ret = loop_preds(xt->xs_c0, xepat, cvk)) < 0)
- goto done;
- if (ret == 0)
- goto ok;
+ if ((ret = loop_preds(xt->xs_c0, xepat, cvk)) < 0)
+ goto done;
+ if (ret == 0)
+ goto ok;
}
if ((xe = xt->xs_c1) && (xe->xs_type == XP_EXP)){
- if ((ret = xpath_tree_eq(xepat, xe, &vec, &veclen)) < 0)
- goto done;
- if (ret == 0)
- goto ok;
- if (veclen != 2)
- goto ok;
- if ((cvi = cvec_add(cvk, CGV_STRING)) == NULL){
- clicon_err(OE_XML, errno, "cvec_add");
- goto done;
- }
- cv_name_set(cvi, vec[0]->xs_s1);
- if (vec[1]->xs_type == XP_PRIME_NR)
- cv_string_set(cvi, vec[1]->xs_strnr);
- else
- cv_string_set(cvi, vec[1]->xs_s0);
+ if ((ret = xpath_tree_eq(xepat, xe, &vec, &veclen)) < 0)
+ goto done;
+ if (ret == 0)
+ goto ok;
+ if (veclen != 2)
+ goto ok;
+ if ((cvi = cvec_add(cvk, CGV_STRING)) == NULL){
+ clicon_err(OE_XML, errno, "cvec_add");
+ goto done;
+ }
+ cv_name_set(cvi, vec[0]->xs_s1);
+ if (vec[1]->xs_type == XP_PRIME_NR)
+ cv_string_set(cvi, vec[1]->xs_strnr);
+ else
+ cv_string_set(cvi, vec[1]->xs_s0);
}
retval = 1;
done:
if (vec)
- free(vec);
+ free(vec);
return retval;
ok: /* no match, not special case */
retval = 0;
@@ -228,8 +228,8 @@ loop_preds(xpath_tree *xt,
*/
static int
xpath_list_optimize_fn(xpath_tree *xt,
- cxobj *xv,
- clixon_xvec *xvec)
+ cxobj *xv,
+ clixon_xvec *xvec)
{
int retval = -1;
xpath_tree *xm = NULL;
@@ -249,15 +249,15 @@ xpath_list_optimize_fn(xpath_tree *xt,
/* revert to non-optimized if no yang */
if ((yp = xml_spec(xv)) == NULL)
- goto ok;
+ goto ok;
/* or if not config data (state data should not be ordered) */
if (yang_config_ancestor(yp) == 0)
- goto ok;
+ goto ok;
/* Check that there is no "outer" list. */
ypp = yp;
do {
- if (yang_keyword_get(ypp) == Y_LIST)
- goto ok;
+ if (yang_keyword_get(ypp) == Y_LIST)
+ goto ok;
} while((ypp = yang_parent_get(ypp)) != NULL);
/* Check yang and that only a list with key as index is a special case can do bin search
* That is, ONLY check optimize cases of this type:_x[_y='_z']
@@ -267,49 +267,49 @@ xpath_list_optimize_fn(xpath_tree *xt,
/* Here is where pattern is checked for equality and where variable binding is made (if
* equal) */
if ((ret = xpath_tree_eq(xm, xt, &vec, &veclen)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto ok; /* no match */
+ goto ok; /* no match */
if (veclen != 2)
- goto ok;
+ goto ok;
name = vec[0]->xs_s1;
/* Extract variables */
if ((yc = yang_find(yp, Y_LIST, name)) == NULL)
#ifdef NOTYET /* leaf-list is not detected by xpath optimize detection */
- if ((yc = yang_find(yp, Y_LEAF_LIST, name)) == NULL) /* XXX */
+ if ((yc = yang_find(yp, Y_LEAF_LIST, name)) == NULL) /* XXX */
#endif
- goto ok;
+ goto ok;
/* Validate keys */
if ((cvv = yang_cvec_get(yc)) == NULL)
- goto ok;
+ goto ok;
xtp = vec[1];
if ((cvk = cvec_new(0)) == NULL){
- clicon_err(OE_YANG, errno, "cvec_new");
- goto done;
+ clicon_err(OE_YANG, errno, "cvec_new");
+ goto done;
}
if ((ret = loop_preds(xtp, xem, cvk)) < 0)
- goto done;
+ goto done;
if (ret == 0)
- goto ok;
+ goto ok;
if (cvec_len(cvv) != cvec_len(cvk))
- goto ok;
+ goto ok;
i = 0;
cvi = NULL;
while ((cvi = cvec_each(cvk, cvi)) != NULL) {
- if (strcmp(cv_name_get(cvi), cv_string_get(cvec_i(cvv,i))))
- goto ok;
- i++;
+ if (strcmp(cv_name_get(cvi), cv_string_get(cvec_i(cvv,i))))
+ goto ok;
+ i++;
}
/* Use 2a form since yc allready given to compute cvk */
if (clixon_xml_find_index(xv, yp, NULL, name, cvk, xvec) < 0)
- goto done;
+ goto done;
retval = 1; /* match */
done:
if (vec)
- free(vec);
+ free(vec);
if (cvk)
- cvec_free(cvk);
+ cvec_free(cvk);
return retval;
ok: /* no match, not special case */
retval = 0;
@@ -327,30 +327,30 @@ xpath_list_optimize_fn(xpath_tree *xt,
int
xpath_optimize_check(xpath_tree *xs,
cxobj *xv,
- cxobj ***xvec0,
- int *xlen0)
+ cxobj ***xvec0,
+ int *xlen0)
{
#ifdef XPATH_LIST_OPTIMIZE
int ret;
clixon_xvec *xvec = NULL;
if (!_optimize_enable)
- return 0; /* use regular code */
+ return 0; /* use regular code */
if ((xvec = clixon_xvec_new()) == NULL)
- return -1;
+ return -1;
/* Glue code since xpath code uses (old) cxobj ** and search code uses (new) clixon_xvec */
if ((ret = xpath_list_optimize_fn(xs, xv, xvec)) < 0)
- return -1;
+ return -1;
if (ret == 1){
- if (clixon_xvec_extract(xvec, xvec0, xlen0, NULL) < 0)
- return -1;
- clixon_xvec_free(xvec);
- _optimize_hits++;
- return 1; /* Optimized */
+ if (clixon_xvec_extract(xvec, xvec0, xlen0, NULL) < 0)
+ return -1;
+ clixon_xvec_free(xvec);
+ _optimize_hits++;
+ return 1; /* Optimized */
}
else{
- clixon_xvec_free(xvec);
- return 0; /* use regular code */
+ clixon_xvec_free(xvec);
+ return 0; /* use regular code */
}
#else
return 0; /* use regular code */
diff --git a/lib/src/clixon_xpath_parse.h b/lib/src/clixon_xpath_parse.h
index 74ebdf96..569edfa4 100644
--- a/lib/src/clixon_xpath_parse.h
+++ b/lib/src/clixon_xpath_parse.h
@@ -68,4 +68,4 @@ int clixon_xpath_parselex(void *);
int clixon_xpath_parseparse(void *);
void clixon_xpath_parseerror(void *, char*);
-#endif /* _CLIXON_XPATH_PARSE_H_ */
+#endif /* _CLIXON_XPATH_PARSE_H_ */
diff --git a/lib/src/clixon_xpath_parse.y b/lib/src/clixon_xpath_parse.y
index 77c50ad3..321b199f 100644
--- a/lib/src/clixon_xpath_parse.y
+++ b/lib/src/clixon_xpath_parse.y
@@ -154,14 +154,14 @@ extern int clixon_xpath_parseget_lineno (void); /*XXX obsolete ? */
void
clixon_xpath_parseerror(void *_xpy,
- char *s)
+ char *s)
{
errno = 0;
clicon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'", /* Note lineno here is xpath, not yang */
- _XPY->xpy_name,
- _XPY->xpy_linenum ,
- s,
- clixon_xpath_parsetext);
+ _XPY->xpy_name,
+ _XPY->xpy_linenum ,
+ s,
+ clixon_xpath_parsetext);
return;
}
@@ -200,21 +200,21 @@ xp_new(enum xp_type type,
xpath_tree *xs = NULL;
if ((xs = malloc(sizeof(xpath_tree))) == NULL){
- clicon_err(OE_XML, errno, "malloc");
- goto done;
+ clicon_err(OE_XML, errno, "malloc");
+ goto done;
}
memset(xs, 0, sizeof(*xs));
xs->xs_type = type;
xs->xs_int = i0;
if (numstr){
- xs->xs_strnr = numstr;
- if (sscanf(numstr, "%lf", &xs->xs_double) == EOF){
- clicon_err(OE_XML, errno, "sscanf");
- goto done;
- }
+ xs->xs_strnr = numstr;
+ if (sscanf(numstr, "%lf", &xs->xs_double) == EOF){
+ clicon_err(OE_XML, errno, "sscanf");
+ goto done;
+ }
}
else
- xs->xs_double = 0.0;
+ xs->xs_double = 0.0;
xs->xs_s0 = s0;
xs->xs_s1 = s1;
xs->xs_c0 = c0;
@@ -232,8 +232,8 @@ xp_new(enum xp_type type,
*/
static xpath_tree *
xp_primary_function(clixon_xpath_yacc *xpy,
- char *name,
- xpath_tree *xpt)
+ char *name,
+ xpath_tree *xpt)
{
xpath_tree *xtret = NULL;
enum clixon_xpath_function fn;
@@ -241,13 +241,13 @@ xp_primary_function(clixon_xpath_yacc *xpy,
int ret;
if ((ret = xp_fnname_str2int(name)) < 0){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Unknown xpath function \"%s\"", name);
- clixon_xpath_parseerror(xpy, cbuf_get(cb));
- goto done;
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Unknown xpath function \"%s\"", name);
+ clixon_xpath_parseerror(xpy, cbuf_get(cb));
+ goto done;
}
fn = ret;
switch (fn){
@@ -272,14 +272,14 @@ xp_primary_function(clixon_xpath_yacc *xpy,
case XPATHFN_FLOOR:
case XPATHFN_CEILING:
case XPATHFN_ROUND:
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "XPATH function \"%s\" is not implemented", name);
- clixon_xpath_parseerror(xpy, cbuf_get(cb));
- goto done;
- break;
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "XPATH function \"%s\" is not implemented", name);
+ clixon_xpath_parseerror(xpy, cbuf_get(cb));
+ goto done;
+ break;
case XPATHFN_CURRENT: /* Group of implemented xpath functions */
case XPATHFN_DEREF:
case XPATHFN_DERIVED_FROM:
@@ -293,26 +293,26 @@ xp_primary_function(clixon_xpath_yacc *xpy,
case XPATHFN_NOT:
case XPATHFN_TRUE:
case XPATHFN_FALSE:
- break;
+ break;
default:
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Unknown xpath function \"%s\"", name);
- clixon_xpath_parseerror(xpy, cbuf_get(cb));
- goto done;
- break;
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Unknown xpath function \"%s\"", name);
+ clixon_xpath_parseerror(xpy, cbuf_get(cb));
+ goto done;
+ break;
}
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
xtret = xp_new(XP_PRIME_FN, fn, NULL, name, NULL, xpt, NULL);
name = NULL;
done:
if (name)
- free(name);
+ free(name);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return xtret;
}
@@ -325,51 +325,51 @@ xp_primary_function(clixon_xpath_yacc *xpy,
*/
static xpath_tree *
xp_nodetest_function(clixon_xpath_yacc *xpy,
- char *name)
+ char *name)
{
xpath_tree *xtret = NULL;
cbuf *cb = NULL;
enum clixon_xpath_function fn;
if ((fn = xp_fnname_str2int(name)) < 0){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Unknown xpath function \"%s\"", name);
- clixon_xpath_parseerror(xpy, cbuf_get(cb));
- goto done;
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Unknown xpath function \"%s\"", name);
+ clixon_xpath_parseerror(xpy, cbuf_get(cb));
+ goto done;
}
switch (fn){
case XPATHFN_COMMENT: /* Group of not implemented node functions */
case XPATHFN_PROCESSING_INSTRUCTIONS:
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "XPATH function \"%s\" is not implemented", name);
- clixon_xpath_parseerror(xpy, cbuf_get(cb));
- goto done;
- break;
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "XPATH function \"%s\" is not implemented", name);
+ clixon_xpath_parseerror(xpy, cbuf_get(cb));
+ goto done;
+ break;
case XPATHFN_TEXT: /* Group of implemented node functions */
case XPATHFN_NODE:
- break;
+ break;
default:
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Unknown xpath nodetest function \"%s\"", name);
- clixon_xpath_parseerror(xpy, cbuf_get(cb));
- goto done;
- break;
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Unknown xpath nodetest function \"%s\"", name);
+ clixon_xpath_parseerror(xpy, cbuf_get(cb));
+ goto done;
+ break;
}
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
xtret = xp_new(XP_NODE_FN, fn, NULL, name, NULL, NULL, NULL);
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return xtret;
}
@@ -382,23 +382,23 @@ xp_nodetest_function(clixon_xpath_yacc *xpy,
*/
static int
xp_axisname_function(clixon_xpath_yacc *xpy,
- char *name)
+ char *name)
{
int fn = -1;
cbuf *cb = NULL;
if ((fn = axis_type_str2int(name)) < 0){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_XML, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "Unknown xpath axisname \"%s\"", name);
- clixon_xpath_parseerror(xpy, cbuf_get(cb));
- goto done;
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_XML, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "Unknown xpath axisname \"%s\"", name);
+ clixon_xpath_parseerror(xpy, cbuf_get(cb));
+ goto done;
}
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return fn;
}
@@ -463,57 +463,57 @@ rellocpath : step { $$=xp_new(XP_RELLOCPATH,A_NAN,NULL,NULL,NUL
step : nodetest predicates
{ $$=xp_new(XP_STEP, A_CHILD, NULL, NULL, NULL, $1, $2);
- _PARSE_DEBUG("step->nodetest predicates"); }
+ _PARSE_DEBUG("step->nodetest predicates"); }
| axisspec nodetest predicates
- {$$=xp_new(XP_STEP, $1, NULL, NULL, NULL, $2, $3);
- _PARSE_DEBUG1("step->axisspec(%d) nodetest", $1); }
+ {$$=xp_new(XP_STEP, $1, NULL, NULL, NULL, $2, $3);
+ _PARSE_DEBUG1("step->axisspec(%d) nodetest", $1); }
| abbreviatedstep { $$ = $1; }
- ;
+ ;
abbreviatedstep : '.' predicates { $$=xp_new(XP_STEP,A_SELF, NULL,NULL, NULL, NULL, $2); _PARSE_DEBUG("step-> ."); }
| DOUBLEDOT predicates { $$=xp_new(XP_STEP, A_PARENT, NULL,NULL, NULL, NULL, $2); _PARSE_DEBUG("step-> .."); }
;
-/* [5] AxisSpecifier::= AxisName '::'
+/* [5] AxisSpecifier::= AxisName '::'
| AbbreviatedAxisSpecifier
*/
axisspec : NCNAME DOUBLECOLON
{ if (($$=xp_axisname_function(_XPY, $1)) < 0) YYERROR;
- free($1);
- _PARSE_DEBUG2("axisspec-> AXISNAME(%s -> %d) ::", $1, $$);
- }
+ free($1);
+ _PARSE_DEBUG2("axisspec-> AXISNAME(%s -> %d) ::", $1, $$);
+ }
| abbreviatedaxisspec
- { $$ = $1; }
+ { $$ = $1; }
;
-/* [13] AbbreviatedAxisSpecifier ::= '@'?
+/* [13] AbbreviatedAxisSpecifier ::= '@'?
* empty built into 2nd step rule
*/
abbreviatedaxisspec :'@' { $$=A_ATTRIBUTE; _PARSE_DEBUG("axisspec-> @"); }
;
nodetest : nametest { $$ = $1;
- _PARSE_DEBUG("nodetest-> nametest");}
+ _PARSE_DEBUG("nodetest-> nametest");}
| NODETYPE ')'
- { if (($$ = xp_nodetest_function(_XPY, $1)) == NULL) YYERROR;
- _PARSE_DEBUG1("nodetest-> nodetype(%s)", $1);
- }
+ { if (($$ = xp_nodetest_function(_XPY, $1)) == NULL) YYERROR;
+ _PARSE_DEBUG1("nodetest-> nodetype(%s)", $1);
+ }
;
nametest : ADDOP
{ char *str;
- str = strdup(clicon_int2str(xpopmap,$1));
- $$=xp_new(XP_NODE,A_NAN,NULL, NULL, str, NULL, NULL);
- _PARSE_DEBUG("nametest-> *"); }
+ str = strdup(clicon_int2str(xpopmap,$1));
+ $$=xp_new(XP_NODE,A_NAN,NULL, NULL, str, NULL, NULL);
+ _PARSE_DEBUG("nametest-> *"); }
| NCNAME
- { $$=xp_new(XP_NODE,A_NAN,NULL, NULL, $1, NULL, NULL);
- _PARSE_DEBUG1("nametest-> name[%s]",$1); }
+ { $$=xp_new(XP_NODE,A_NAN,NULL, NULL, $1, NULL, NULL);
+ _PARSE_DEBUG1("nametest-> name[%s]",$1); }
| NCNAME ':' NCNAME
- { $$=xp_new(XP_NODE,A_NAN,NULL, $1, $3, NULL, NULL);
- _PARSE_DEBUG2("nametest-> name[%s] : name[%s]", $1, $3); }
+ { $$=xp_new(XP_NODE,A_NAN,NULL, $1, $3, NULL, NULL);
+ _PARSE_DEBUG2("nametest-> name[%s] : name[%s]", $1, $3); }
| NCNAME ':' '*'
- { $$=xp_new(XP_NODE,A_NAN,NULL, $1, NULL, NULL, NULL);
- _PARSE_DEBUG1("nametest-> name[%s] : *", $1); }
+ { $$=xp_new(XP_NODE,A_NAN,NULL, $1, NULL, NULL, NULL);
+ _PARSE_DEBUG1("nametest-> name[%s] : *", $1); }
;
/* evaluates to boolean */
@@ -530,37 +530,37 @@ args : args ',' expr { $$=xp_new(XP_EXP,A_NAN,NULL,NULL,NULL,$1, $3);
_PARSE_DEBUG("args -> args expr");}
| expr { $$=xp_new(XP_EXP,A_NAN,NULL,NULL,NULL,$1, NULL);
_PARSE_DEBUG("args -> expr "); }
- ;
+ ;
literal : QUOTE string QUOTE
{ $$=xp_new(XP_PRIME_STR,A_NAN,NULL, $2, NULL, NULL, NULL);
- _PARSE_DEBUG("literal-> \" string \""); }
+ _PARSE_DEBUG("literal-> \" string \""); }
| QUOTE QUOTE
- { $$=xp_new(XP_PRIME_STR,A_NAN,NULL, strdup(""), NULL, NULL, NULL);
- _PARSE_DEBUG("primaryexpr-> \" \""); }
+ { $$=xp_new(XP_PRIME_STR,A_NAN,NULL, strdup(""), NULL, NULL, NULL);
+ _PARSE_DEBUG("primaryexpr-> \" \""); }
| APOST string APOST
- { $$=xp_new(XP_PRIME_STR,A_NAN,NULL, $2, NULL, NULL, NULL);
- _PARSE_DEBUG("primaryexpr-> ' string '"); }
+ { $$=xp_new(XP_PRIME_STR,A_NAN,NULL, $2, NULL, NULL, NULL);
+ _PARSE_DEBUG("primaryexpr-> ' string '"); }
| APOST APOST
- { $$=xp_new(XP_PRIME_STR,A_NAN,NULL, strdup(""), NULL, NULL, NULL);
- _PARSE_DEBUG("primaryexpr-> ' '"); }
+ { $$=xp_new(XP_PRIME_STR,A_NAN,NULL, strdup(""), NULL, NULL, NULL);
+ _PARSE_DEBUG("primaryexpr-> ' '"); }
;
functioncall : NCNAME '(' ')'
{ /* XXX warning: rule useless in parser due to conflicts */
if (($$ = xp_primary_function(_XPY, $1, NULL)) == NULL) YYERROR;
- _PARSE_DEBUG("primaryexpr-> functionname ()"); }
+ _PARSE_DEBUG("primaryexpr-> functionname ()"); }
| NCNAME '(' args ')'
- { if (($$ = xp_primary_function(_XPY, $1, $3)) == NULL) YYERROR;
- _PARSE_DEBUG("primaryexpr-> functionname (arguments)"); }
+ { if (($$ = xp_primary_function(_XPY, $1, $3)) == NULL) YYERROR;
+ _PARSE_DEBUG("primaryexpr-> functionname (arguments)"); }
;
string : string CHARS {
- int len = strlen($1);
- $$ = realloc($1, len+strlen($2) + 1);
- sprintf($$+len, "%s", $2);
- free($2);
- _PARSE_DEBUG("string-> string CHAR");
+ int len = strlen($1);
+ $$ = realloc($1, len+strlen($2) + 1);
+ sprintf($$+len, "%s", $2);
+ free($2);
+ _PARSE_DEBUG("string-> string CHAR");
}
| CHARS { _PARSE_DEBUG("string-> "); }
;
diff --git a/lib/src/clixon_xpath_yang.c b/lib/src/clixon_xpath_yang.c
index d4cda571..44ea1fab 100644
--- a/lib/src/clixon_xpath_yang.c
+++ b/lib/src/clixon_xpath_yang.c
@@ -88,14 +88,14 @@ xy_dup(xp_yang_ctx *xy0)
xp_yang_ctx *xy = NULL;
if ((xy = malloc(sizeof(*xy))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(xy, 0, sizeof(*xy));
if (xy0)
- *xy = *xy0;
+ *xy = *xy0;
else
- xy->xy_type = XT_NODESET;
+ xy->xy_type = XT_NODESET;
done:
return xy;
}
@@ -110,17 +110,17 @@ xy_dup(xp_yang_ctx *xy0)
*/
static int
xp_yang_op_eq(xp_yang_ctx *xy1,
- xp_yang_ctx *xy2,
- xp_yang_ctx **xyr)
+ xp_yang_ctx *xy2,
+ xp_yang_ctx **xyr)
{
int retval = -1;
xp_yang_ctx *xy = NULL;
if ((xy = xy_dup(xy1)) == NULL)
- goto done;
+ goto done;
if (xy1 == NULL || xy2 == NULL || xy1->xy_node == NULL || xy2->xy_node == NULL){
- clicon_err(OE_YANG, EINVAL, "Invalid path-arg (Error in xy1 or xy2) ");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "Invalid path-arg (Error in xy1 or xy2) ");
+ goto done;
}
xy->xy_type = XT_BOOL;
xy->xy_bool = 1;
@@ -142,8 +142,8 @@ xp_yang_op_eq(xp_yang_ctx *xy1,
*/
static int
xp_yang_eval_step(xp_yang_ctx *xy0,
- xpath_tree *xptree,
- xp_yang_ctx **xyr)
+ xpath_tree *xptree,
+ xp_yang_ctx **xyr)
{
int retval = -1;
xpath_tree *nodetest; /* needed if child */
@@ -154,67 +154,67 @@ xp_yang_eval_step(xp_yang_ctx *xy0,
/* Create new xy */
if ((xy = xy_dup(xy0)) == NULL)
- goto done;
+ goto done;
ys = xy->xy_node;
switch (xptree->xs_int){
case A_CHILD:
- if ((nodetest = xptree->xs_c0) == NULL){
- clicon_err(OE_YANG, 0, "child step nodetest expected");
- goto done;
- }
- switch (nodetest->xs_type){
- case XP_NODE:
- if ((prefix = nodetest->xs_s0) != NULL){
- /* XXX: Kludge with prefixes */
- if (yang_keyword_get(ys) == Y_SPEC){ /* This means top */
- if ((ys1 = yang_find_module_by_prefix_yspec(ys, prefix)) != NULL)
- ys = ys1;
- }
- else if (yang_keyword_get(ys) == Y_MODULE){ /* This means top */
- if ((ys1 = yang_find_module_by_prefix(ys, prefix)) == NULL)
- ys1 = yang_find_module_by_prefix_yspec(ys_spec(ys), prefix);
- if (ys1 != NULL)
- ys = ys1;
- }
- }
- xy->xy_node = yang_find_schemanode(ys, nodetest->xs_s1);
- if (xy->xy_node == NULL){
- *xyr = xy;
- xy = NULL;
- goto ok;
- }
- break;
- case XP_NODE_FN:
- break;
- default:
- clicon_err(OE_YANG, 0, "Invalid xpath-tree nodetest: %s",
- xpath_tree_int2str(nodetest->xs_type));
- goto done;
- break;
- } /* nodetest xs_type */
- break;
+ if ((nodetest = xptree->xs_c0) == NULL){
+ clicon_err(OE_YANG, 0, "child step nodetest expected");
+ goto done;
+ }
+ switch (nodetest->xs_type){
+ case XP_NODE:
+ if ((prefix = nodetest->xs_s0) != NULL){
+ /* XXX: Kludge with prefixes */
+ if (yang_keyword_get(ys) == Y_SPEC){ /* This means top */
+ if ((ys1 = yang_find_module_by_prefix_yspec(ys, prefix)) != NULL)
+ ys = ys1;
+ }
+ else if (yang_keyword_get(ys) == Y_MODULE){ /* This means top */
+ if ((ys1 = yang_find_module_by_prefix(ys, prefix)) == NULL)
+ ys1 = yang_find_module_by_prefix_yspec(ys_spec(ys), prefix);
+ if (ys1 != NULL)
+ ys = ys1;
+ }
+ }
+ xy->xy_node = yang_find_schemanode(ys, nodetest->xs_s1);
+ if (xy->xy_node == NULL){
+ *xyr = xy;
+ xy = NULL;
+ goto ok;
+ }
+ break;
+ case XP_NODE_FN:
+ break;
+ default:
+ clicon_err(OE_YANG, 0, "Invalid xpath-tree nodetest: %s",
+ xpath_tree_int2str(nodetest->xs_type));
+ goto done;
+ break;
+ } /* nodetest xs_type */
+ break;
case A_PARENT:
- xy->xy_node = yang_parent_get(ys);
- break;
+ xy->xy_node = yang_parent_get(ys);
+ break;
default:
- clicon_err(OE_YANG, 0, "Invalid path-arg step: %s",
- axis_type_int2str(xptree->xs_int));
- goto done;
- break;
+ clicon_err(OE_YANG, 0, "Invalid path-arg step: %s",
+ axis_type_int2str(xptree->xs_int));
+ goto done;
+ break;
}
if (xptree->xs_c1){
- if (xp_yang_eval(xy, xptree->xs_c1, xyr) < 0)
- goto done;
+ if (xp_yang_eval(xy, xptree->xs_c1, xyr) < 0)
+ goto done;
}
else{
- *xyr = xy;
- xy = NULL;
+ *xyr = xy;
+ xy = NULL;
}
ok:
retval = 0;
done:
if (xy)
- free(xy);
+ free(xy);
return retval;
}
@@ -229,41 +229,41 @@ xp_yang_eval_step(xp_yang_ctx *xy0,
*/
static int
xp_yang_eval_predicate(xp_yang_ctx *xy,
- xpath_tree *xptree,
- xp_yang_ctx **xyr)
+ xpath_tree *xptree,
+ xp_yang_ctx **xyr)
{
int retval = -1;
xp_yang_ctx *xy0 = NULL;
xp_yang_ctx *xy1 = NULL;
if (xptree->xs_c0 != NULL){ /* eval previous predicates */
- if (xp_yang_eval(xy, xptree->xs_c0, &xy0) < 0)
- goto done;
+ if (xp_yang_eval(xy, xptree->xs_c0, &xy0) < 0)
+ goto done;
}
else{ /* empty */
- if ((xy0 = xy_dup(xy)) == NULL)
- goto done;
+ if ((xy0 = xy_dup(xy)) == NULL)
+ goto done;
}
if (xptree->xs_c1){ /* Second child */
- // if ((xy1 = xy_dup(xy)) == NULL)
- // goto done;
- /* the PredicateExpr is evaluated with the node as the context node */
- if (xp_yang_eval(xy0, xptree->xs_c1, &xy1) < 0)
- goto done;
- /* Check xrc: if "true" then xyr=xy0? */
- if (xy1->xy_type == XT_BOOL && xy1->xy_bool)
- ;
- else
- xy0->xy_node = NULL;
+ // if ((xy1 = xy_dup(xy)) == NULL)
+ // goto done;
+ /* the PredicateExpr is evaluated with the node as the context node */
+ if (xp_yang_eval(xy0, xptree->xs_c1, &xy1) < 0)
+ goto done;
+ /* Check xrc: if "true" then xyr=xy0? */
+ if (xy1->xy_type == XT_BOOL && xy1->xy_bool)
+ ;
+ else
+ xy0->xy_node = NULL;
}
*xyr = xy0;
xy0 = NULL;
retval = 0;
done:
if (xy0)
- free(xy0);
+ free(xy0);
if (xy1)
- free(xy1);
+ free(xy1);
return retval;
}
@@ -278,8 +278,8 @@ xp_yang_eval_predicate(xp_yang_ctx *xy,
*/
static int
xp_yang_eval(xp_yang_ctx *xy,
- xpath_tree *xptree,
- xp_yang_ctx **xyr)
+ xpath_tree *xptree,
+ xp_yang_ctx **xyr)
{
int retval = -1;
int use_xy0 = 0;
@@ -289,7 +289,7 @@ xp_yang_eval(xp_yang_ctx *xy,
/* If empty npodeset, quit, cannot continue */
if (xy->xy_type == XT_NODESET && xy->xy_node == NULL)
- goto ok;
+ goto ok;
/* Pre-actions before check first child c0
*/
switch (xptree->xs_type){
@@ -297,136 +297,136 @@ xp_yang_eval(xp_yang_ctx *xy,
case XP_AND:
case XP_ADD:
case XP_UNION:
- if (xptree->xs_c1 != NULL){
- clicon_err(OE_XML, 0, "Function %s having two args is invalid for path-arg", xptree->xs_s0);
- goto done;
- }
- break;
+ if (xptree->xs_c1 != NULL){
+ clicon_err(OE_XML, 0, "Function %s having two args is invalid for path-arg", xptree->xs_s0);
+ goto done;
+ }
+ break;
case XP_RELEX:
case XP_PATHEXPR:
case XP_FILTEREXPR:
- break;
+ break;
case XP_LOCPATH:
case XP_NODE:
case XP_NODE_FN:
- break;
+ break;
case XP_RELLOCPATH:
- break;
+ break;
case XP_PRIME_FN:
- if (xptree->xs_s0){
- switch (xptree->xs_int){
- case XPATHFN_CURRENT:
- if ((*xyr = xy_dup(xy)) == NULL)
- goto done;
- (*xyr)->xy_node = (*xyr)->xy_initial;
- goto ok;
- break;
- default:
- clicon_err(OE_XML, 0, "Function %s invalid for path-arg", xptree->xs_s0);
- goto done;
- }
- }
- break;
+ if (xptree->xs_s0){
+ switch (xptree->xs_int){
+ case XPATHFN_CURRENT:
+ if ((*xyr = xy_dup(xy)) == NULL)
+ goto done;
+ (*xyr)->xy_node = (*xyr)->xy_initial;
+ goto ok;
+ break;
+ default:
+ clicon_err(OE_XML, 0, "Function %s invalid for path-arg", xptree->xs_s0);
+ goto done;
+ }
+ }
+ break;
case XP_PRIME_STR:
- if ((*xyr = xy_dup(xy)) == NULL)
- goto done;
- goto ok;
- break;
+ if ((*xyr = xy_dup(xy)) == NULL)
+ goto done;
+ goto ok;
+ break;
case XP_ABSPATH:
- /* Set context node to top node, and nodeset to that node only */
- if (yang_keyword_get(xy->xy_node) != Y_SPEC)
- xy->xy_node = ys_module(xy->xy_node);
- break;
+ /* Set context node to top node, and nodeset to that node only */
+ if (yang_keyword_get(xy->xy_node) != Y_SPEC)
+ xy->xy_node = ys_module(xy->xy_node);
+ break;
case XP_PRED:
- if (xp_yang_eval_predicate(xy, xptree, xyr) < 0)
- goto done;
- goto ok; /* Skip generic child traverse */
- break;
+ if (xp_yang_eval_predicate(xy, xptree, xyr) < 0)
+ goto done;
+ goto ok; /* Skip generic child traverse */
+ break;
case XP_STEP: /* XP_NODE is first argument -not called explicitly */
- if (xp_yang_eval_step(xy, xptree, xyr) < 0)
- goto done;
- goto ok; /* Skip generic child traverse */
- break;
+ if (xp_yang_eval_step(xy, xptree, xyr) < 0)
+ goto done;
+ goto ok; /* Skip generic child traverse */
+ break;
default: /* Here we explicitly fail on node types for those not appearing in path-arg */
- clicon_err(OE_YANG, 0, "Invalid xpath-tree node name: %s",
- xpath_tree_int2str(xptree->xs_type));
- goto done;
- break;
+ clicon_err(OE_YANG, 0, "Invalid xpath-tree node name: %s",
+ xpath_tree_int2str(xptree->xs_type));
+ goto done;
+ break;
}
/* Eval first child c0
*/
if (xptree->xs_c0){
- if (xp_yang_eval(xy, xptree->xs_c0, &xy0) < 0)
- goto done;
+ if (xp_yang_eval(xy, xptree->xs_c0, &xy0) < 0)
+ goto done;
}
/* Actions between first and second child
*/
switch (xptree->xs_type){
case XP_RELLOCPATH:
case XP_ABSPATH:
- use_xy0++;
- break;
+ use_xy0++;
+ break;
case XP_PATHEXPR:
- if (xptree->xs_c1)
- use_xy0++;
- break;
+ if (xptree->xs_c1)
+ use_xy0++;
+ break;
default:
- break;
+ break;
}
/* Eval second child c1
* Note, some operators like locationpath, need transitive context (use_xr0)
*/
if (xptree->xs_c1){
- if (xp_yang_eval(use_xy0?xy0:xy, xptree->xs_c1, &xy1) < 0)
- goto done;
- /* Actions after second child
- */
- switch (xptree->xs_type){
- case XP_RELEX: /* relexpr --> addexpr | relexpr relop addexpr */
- /* Check op: only EQ allowed in path-arg */
- if (xptree->xs_int != XO_EQ){
- clicon_err(OE_YANG, 0, "Invalid xpath-tree relational operator: %d, only eq allowed",
- xptree->xs_int);
- goto done;
- }
- if (xp_yang_op_eq(xy0, xy1, &xy2) < 0)
- goto done;
- break;
- default:
- break;
- }
+ if (xp_yang_eval(use_xy0?xy0:xy, xptree->xs_c1, &xy1) < 0)
+ goto done;
+ /* Actions after second child
+ */
+ switch (xptree->xs_type){
+ case XP_RELEX: /* relexpr --> addexpr | relexpr relop addexpr */
+ /* Check op: only EQ allowed in path-arg */
+ if (xptree->xs_int != XO_EQ){
+ clicon_err(OE_YANG, 0, "Invalid xpath-tree relational operator: %d, only eq allowed",
+ xptree->xs_int);
+ goto done;
+ }
+ if (xp_yang_op_eq(xy0, xy1, &xy2) < 0)
+ goto done;
+ break;
+ default:
+ break;
+ }
}
if (xy0 == NULL && xy1 == NULL && xy2 == NULL){
- if (xptree->xs_type == XP_ABSPATH){
- if ((*xyr = xy_dup(xy)) == NULL)
- goto done;
- }
- else {
- clicon_err(OE_XML, EFAULT, "Internal error: no result produced");
- goto done;
- }
+ if (xptree->xs_type == XP_ABSPATH){
+ if ((*xyr = xy_dup(xy)) == NULL)
+ goto done;
+ }
+ else {
+ clicon_err(OE_XML, EFAULT, "Internal error: no result produced");
+ goto done;
+ }
}
if (xy2){
- *xyr = xy2;
- xy2 = NULL;
+ *xyr = xy2;
+ xy2 = NULL;
}
else if (xy1){
- *xyr = xy1;
- xy1 = NULL;
+ *xyr = xy1;
+ xy1 = NULL;
}
else if (xy0){
- *xyr = xy0;
- xy0 = NULL;
+ *xyr = xy0;
+ xy0 = NULL;
}
ok:
retval = 0;
done:
if (xy2)
- free(xy2);
+ free(xy2);
if (xy1)
- free(xy1);
+ free(xy1);
if (xy0)
- free(xy0);
+ free(xy0);
return retval;
}
@@ -458,8 +458,8 @@ xp_yang_eval(xp_yang_ctx *xy,
*/
int
yang_path_arg(yang_stmt *ys,
- const char *path_arg,
- yang_stmt **yref)
+ const char *path_arg,
+ yang_stmt **yref)
{
int retval = -1;
xpath_tree *xptree = NULL;
@@ -467,26 +467,26 @@ yang_path_arg(yang_stmt *ys,
xp_yang_ctx *xy = NULL;
if (path_arg == NULL){
- clicon_err(OE_XML, EINVAL, "path-arg is NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "path-arg is NULL");
+ goto done;
}
if (xpath_parse(path_arg, &xptree) < 0)
- goto done;
+ goto done;
if ((xy = xy_dup(NULL)) == NULL)
- goto done;
+ goto done;
xy->xy_node = ys;
xy->xy_initial = ys;
if (xp_yang_eval(xy, xptree, &xyr) < 0)
- goto done;
+ goto done;
if (xyr != NULL)
- *yref = xyr->xy_node;
+ *yref = xyr->xy_node;
retval = 0;
done:
if (xptree)
- xpath_tree_free(xptree);
+ xpath_tree_free(xptree);
if (xyr)
- free(xyr);
+ free(xyr);
if (xy)
- free(xy);
+ free(xy);
return retval;
}
diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c
index 5e47ed26..d22988f3 100644
--- a/lib/src/clixon_yang.c
+++ b/lib/src/clixon_yang.c
@@ -167,7 +167,7 @@ static const map_str2int ykmap[] = {
{"yang-version", Y_YANG_VERSION},
{"yin-element", Y_YIN_ELEMENT},
{"yang-specification", Y_SPEC}, /* XXX: NOTE NOT YANG STATEMENT, reserved
- for top level spec */
+ for top level spec */
{NULL, -1}
};
@@ -193,7 +193,7 @@ yang_len_get(yang_stmt *ys)
*/
yang_stmt *
yang_child_i(yang_stmt *ys,
- int i)
+ int i)
{
return ys->ys_stmt[i];
}
@@ -241,7 +241,7 @@ yang_argument_get(yang_stmt *ys)
*/
int
yang_argument_set(yang_stmt *ys,
- char *arg)
+ char *arg)
{
ys->ys_argument = arg; /* not strdup/copied */
return 0;
@@ -264,10 +264,10 @@ yang_cv_get(yang_stmt *ys)
*/
int
yang_cv_set(yang_stmt *ys,
- cg_var *cv)
+ cg_var *cv)
{
if (cv != NULL && ys->ys_cv != NULL)
- cv_free(ys->ys_cv);
+ cv_free(ys->ys_cv);
ys->ys_cv = cv;
return 0;
}
@@ -289,10 +289,10 @@ yang_cvec_get(yang_stmt *ys)
*/
int
yang_cvec_set(yang_stmt *ys,
- cvec *cvv)
+ cvec *cvv)
{
if (ys->ys_cvec)
- cvec_free(ys->ys_cvec);
+ cvec_free(ys->ys_cvec);
ys->ys_cvec = cvv;
return 0;
}
@@ -304,7 +304,7 @@ yang_cvec_set(yang_stmt *ys,
*/
uint16_t
yang_flag_get(yang_stmt *ys,
- uint16_t flag)
+ uint16_t flag)
{
return ys->ys_flags&flag;
}
@@ -315,7 +315,7 @@ yang_flag_get(yang_stmt *ys,
*/
int
yang_flag_set(yang_stmt *ys,
- uint16_t flag)
+ uint16_t flag)
{
ys->ys_flags |= flag;
return 0;
@@ -327,7 +327,7 @@ yang_flag_set(yang_stmt *ys,
*/
int
yang_flag_reset(yang_stmt *ys,
- uint16_t flag)
+ uint16_t flag)
{
ys->ys_flags &= ~flag;
return 0;
@@ -360,18 +360,18 @@ yang_when_xpath_get(yang_stmt *ys)
*/
int
yang_when_xpath_set(yang_stmt *ys,
- char *xpath)
+ char *xpath)
{
int retval = -1;
if (xpath == NULL){
- clicon_err(OE_YANG, EINVAL, "xpath is NULL");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "xpath is NULL");
+ goto done;
}
if ((ys->ys_when_xpath = strdup(xpath)) == NULL){
- clicon_err(OE_YANG, errno, "strdup");
- goto done;
-
+ clicon_err(OE_YANG, errno, "strdup");
+ goto done;
+
}
retval = 0;
done:
@@ -403,13 +403,13 @@ yang_when_nsc_get(yang_stmt *ys)
*/
int
yang_when_nsc_set(yang_stmt *ys,
- cvec *nsc)
+ cvec *nsc)
{
int retval = -1;
if (nsc && (ys->ys_when_nsc = cvec_dup(nsc)) == NULL){
- clicon_err(OE_YANG, errno, "cvec_dup");
- goto done;
+ clicon_err(OE_YANG, errno, "cvec_dup");
+ goto done;
}
retval = 0;
done:
@@ -438,11 +438,11 @@ yang_filename_get(yang_stmt *ys)
*/
int
yang_filename_set(yang_stmt *ys,
- const char *filename)
+ const char *filename)
{
if ((ys->ys_filename = strdup(filename)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- return -1;
+ clicon_err(OE_UNIX, errno, "strdup");
+ return -1;
}
return 0;
}
@@ -465,7 +465,7 @@ yang_linenum_get(yang_stmt *ys)
*/
int
yang_linenum_set(yang_stmt *ys,
- int linenum)
+ int linenum)
{
ys->ys_linenum = linenum;
return 0;
@@ -484,7 +484,7 @@ int
yang_stats_global(uint64_t *nr)
{
if (nr)
- *nr = _stats_yang_nr;
+ *nr = _stats_yang_nr;
return 0;
}
@@ -496,7 +496,7 @@ yang_stats_global(uint64_t *nr)
*/
static int
yang_stats_one(yang_stmt *y,
- size_t *szp)
+ size_t *szp)
{
size_t sz = 0;
yang_type_cache *yc;
@@ -504,28 +504,28 @@ yang_stats_one(yang_stmt *y,
sz += sizeof(struct yang_stmt);
sz += y->ys_len*sizeof(struct yang_stmt*);
if (y->ys_argument)
- sz += strlen(y->ys_argument) + 1;
+ sz += strlen(y->ys_argument) + 1;
if (y->ys_cv)
- sz += cv_size(y->ys_cv);
+ sz += cv_size(y->ys_cv);
if (y->ys_cvec)
- sz += cvec_size(y->ys_cvec);
+ sz += cvec_size(y->ys_cvec);
if ((yc = y->ys_typecache) != NULL){
- sz += sizeof(struct yang_type_cache);
- if (yc->yc_cvv)
- sz += cvec_size(yc->yc_cvv);
- if (yc->yc_patterns)
- sz += cvec_size(yc->yc_patterns);
- if (yc->yc_regexps)
- sz += cvec_size(yc->yc_regexps);
+ sz += sizeof(struct yang_type_cache);
+ if (yc->yc_cvv)
+ sz += cvec_size(yc->yc_cvv);
+ if (yc->yc_patterns)
+ sz += cvec_size(yc->yc_patterns);
+ if (yc->yc_regexps)
+ sz += cvec_size(yc->yc_regexps);
}
if (y->ys_when_xpath)
- sz += strlen(y->ys_when_xpath) + 1;
+ sz += strlen(y->ys_when_xpath) + 1;
if (y->ys_when_nsc)
- sz += cvec_size(y->ys_when_nsc);
+ sz += cvec_size(y->ys_when_nsc);
if (y->ys_filename)
- sz += strlen(y->ys_filename) + 1;
+ sz += strlen(y->ys_filename) + 1;
if (szp)
- *szp = sz;
+ *szp = sz;
return 0;
}
@@ -538,27 +538,27 @@ yang_stats_one(yang_stmt *y,
*/
int
yang_stats(yang_stmt *yt,
- uint64_t *nrp,
- size_t *szp)
+ uint64_t *nrp,
+ size_t *szp)
{
int retval = -1;
size_t sz = 0;
yang_stmt *ys;
if (yt == NULL){
- clicon_err(OE_XML, EINVAL, "yang spec is NULL");
- goto done;
+ clicon_err(OE_XML, EINVAL, "yang spec is NULL");
+ goto done;
}
*nrp += 1;
yang_stats_one(yt, &sz);
if (szp)
- *szp += sz;
+ *szp += sz;
ys = NULL;
while ((ys = yn_each(yt, ys)) != NULL) {
- sz = 0;
- yang_stats(ys, nrp, &sz);
- if (szp)
- *szp += sz;
+ sz = 0;
+ yang_stats(ys, nrp, &sz);
+ if (szp)
+ *szp += sz;
}
retval = 0;
done:
@@ -577,8 +577,8 @@ yspec_new(void)
yang_stmt *yspec;
if ((yspec = malloc(sizeof(*yspec))) == NULL){
- clicon_err(OE_YANG, errno, "malloc");
- return NULL;
+ clicon_err(OE_YANG, errno, "malloc");
+ return NULL;
}
memset(yspec, 0, sizeof(*yspec));
yspec->ys_keyword = Y_SPEC;
@@ -597,16 +597,16 @@ ys_new(enum rfc_6020 keyw)
cvec *cvv;
if ((ys = malloc(sizeof(*ys))) == NULL){
- clicon_err(OE_YANG, errno, "malloc");
- return NULL;
+ clicon_err(OE_YANG, errno, "malloc");
+ return NULL;
}
memset(ys, 0, sizeof(*ys));
ys->ys_keyword = keyw;
/* The cvec contains stmt-specific variables. Only few stmts need variables so the
cvec could be lazily created to save some heap and cycles. */
if ((cvv = cvec_new(0)) == NULL){
- clicon_err(OE_YANG, errno, "cvec_new");
- return NULL;
+ clicon_err(OE_YANG, errno, "cvec_new");
+ return NULL;
}
yang_cvec_set(ys, cvv);
_stats_yang_nr++;
@@ -623,46 +623,46 @@ ys_new(enum rfc_6020 keyw)
*/
int
ys_free1(yang_stmt *ys,
- int self)
+ int self)
{
cg_var *cv;
rpc_callback_t *rc;
if (ys->ys_argument){
- free(ys->ys_argument);
- ys->ys_argument = NULL;
+ free(ys->ys_argument);
+ ys->ys_argument = NULL;
}
if ((cv = yang_cv_get(ys)) != NULL){
- yang_cv_set(ys, NULL); /* only frees on replace */
- cv_free(cv);
+ yang_cv_set(ys, NULL); /* only frees on replace */
+ cv_free(cv);
}
if (ys->ys_cvec){
- cvec_free(ys->ys_cvec);
- ys->ys_cvec = NULL;
+ cvec_free(ys->ys_cvec);
+ ys->ys_cvec = NULL;
}
if (ys->ys_typecache){
- yang_type_cache_free(ys->ys_typecache);
- ys->ys_typecache = NULL;
+ yang_type_cache_free(ys->ys_typecache);
+ ys->ys_typecache = NULL;
}
if (ys->ys_when_xpath)
- free(ys->ys_when_xpath);
+ free(ys->ys_when_xpath);
if (ys->ys_when_nsc)
- cvec_free(ys->ys_when_nsc);
+ cvec_free(ys->ys_when_nsc);
if (ys->ys_stmt)
- free(ys->ys_stmt);
+ free(ys->ys_stmt);
if (ys->ys_filename)
- free(ys->ys_filename);
+ free(ys->ys_filename);
while((rc = ys->ys_action_cb) != NULL) {
- DELQ(rc, ys->ys_action_cb, rpc_callback_t *);
- if (rc->rc_namespace)
- free(rc->rc_namespace);
- if (rc->rc_name)
- free(rc->rc_name);
- free(rc);
+ DELQ(rc, ys->ys_action_cb, rpc_callback_t *);
+ if (rc->rc_namespace)
+ free(rc->rc_namespace);
+ if (rc->rc_name)
+ free(rc->rc_name);
+ free(rc);
}
if (self){
- free(ys);
- _stats_yang_nr--;
+ free(ys);
+ _stats_yang_nr--;
}
return 0;
}
@@ -678,19 +678,19 @@ ys_free1(yang_stmt *ys,
*/
yang_stmt *
ys_prune(yang_stmt *yp,
- int i)
+ int i)
{
size_t size;
yang_stmt *yc = NULL;
if (i >= yp->ys_len)
- goto done;
+ goto done;
yc = yp->ys_stmt[i];
if (i < yp->ys_len - 1){
- size = (yp->ys_len - i - 1)*sizeof(struct yang_stmt *);
- memmove(&yp->ys_stmt[i],
- &yp->ys_stmt[i+1],
- size);
+ size = (yp->ys_len - i - 1)*sizeof(struct yang_stmt *);
+ memmove(&yp->ys_stmt[i],
+ &yp->ys_stmt[i+1],
+ size);
}
yp->ys_len--;
yp->ys_stmt[yp->ys_len] = NULL;
@@ -715,18 +715,18 @@ ys_prune_self(yang_stmt *ys)
int i;
if ((yp = yang_parent_get(ys)) != NULL){
- yc = NULL;
- i = 0;
- /* Find order of ys in child-list */
- while ((yc = yn_each(yp, yc)) != NULL) {
- if (ys == yc)
- break;
- i++;
- }
- if (yc != NULL){
- assert(yc == ys);
- ys_prune(yp, i);
- }
+ yc = NULL;
+ i = 0;
+ /* Find order of ys in child-list */
+ while ((yc = yn_each(yp, yc)) != NULL) {
+ if (ys == yc)
+ break;
+ i++;
+ }
+ if (yc != NULL){
+ assert(yc == ys);
+ ys_prune(yp, i);
+ }
}
retval = 0;
// done:
@@ -743,13 +743,13 @@ ys_freechildren(yang_stmt *ys)
yang_stmt *yc;
for (i=0; iys_len; i++){
- if ((yc = ys->ys_stmt[i]) != NULL)
- ys_free(yc);
+ if ((yc = ys->ys_stmt[i]) != NULL)
+ ys_free(yc);
}
ys->ys_len = 0;
if (ys->ys_stmt){
- free(ys->ys_stmt);
- ys->ys_stmt = NULL;
+ free(ys->ys_stmt);
+ ys->ys_stmt = NULL;
}
return 0;
}
@@ -774,8 +774,8 @@ yn_realloc(yang_stmt *yn)
yn->ys_len++;
if ((yn->ys_stmt = realloc(yn->ys_stmt, (yn->ys_len)*sizeof(yang_stmt *))) == 0){
- clicon_err(OE_YANG, errno, "realloc");
- return -1;
+ clicon_err(OE_YANG, errno, "realloc");
+ return -1;
}
yn->ys_stmt[yn->ys_len - 1] = NULL; /* init field */
return 0;
@@ -807,50 +807,50 @@ ys_cp(yang_stmt *ynew,
memcpy(ynew, yold, sizeof(*yold));
ynew->ys_parent = NULL;
if (yold->ys_stmt)
- if ((ynew->ys_stmt = calloc(yold->ys_len, sizeof(yang_stmt *))) == NULL){
- clicon_err(OE_YANG, errno, "calloc");
- goto done;
- }
+ if ((ynew->ys_stmt = calloc(yold->ys_len, sizeof(yang_stmt *))) == NULL){
+ clicon_err(OE_YANG, errno, "calloc");
+ goto done;
+ }
if (yold->ys_argument)
- if ((ynew->ys_argument = strdup(yold->ys_argument)) == NULL){
- clicon_err(OE_YANG, errno, "strdup");
- goto done;
- }
+ if ((ynew->ys_argument = strdup(yold->ys_argument)) == NULL){
+ clicon_err(OE_YANG, errno, "strdup");
+ goto done;
+ }
yang_cv_set(ynew, NULL);
if ((cvo = yang_cv_get(yold)) != NULL){
- if ((cvn = cv_dup(cvo)) == NULL){
- clicon_err(OE_YANG, errno, "cv_dup");
- goto done;
- }
- yang_cv_set(ynew, cvn);
+ if ((cvn = cv_dup(cvo)) == NULL){
+ clicon_err(OE_YANG, errno, "cv_dup");
+ goto done;
+ }
+ yang_cv_set(ynew, cvn);
}
if (yold->ys_cvec)
- if ((ynew->ys_cvec = cvec_dup(yold->ys_cvec)) == NULL){
- clicon_err(OE_YANG, errno, "cvec_dup");
- goto done;
- }
+ if ((ynew->ys_cvec = cvec_dup(yold->ys_cvec)) == NULL){
+ clicon_err(OE_YANG, errno, "cvec_dup");
+ goto done;
+ }
if (yold->ys_typecache){
- ynew->ys_typecache = NULL;
- if (yang_type_cache_cp(ynew, yold) < 0)
- goto done;
+ ynew->ys_typecache = NULL;
+ if (yang_type_cache_cp(ynew, yold) < 0)
+ goto done;
}
if (yold->ys_when_xpath)
- if ((ynew->ys_when_xpath = strdup(yold->ys_when_xpath)) == NULL){
- clicon_err(OE_YANG, errno, "strdup");
- goto done;
- }
+ if ((ynew->ys_when_xpath = strdup(yold->ys_when_xpath)) == NULL){
+ clicon_err(OE_YANG, errno, "strdup");
+ goto done;
+ }
if (yold->ys_when_nsc){
- if ((ynew->ys_when_nsc = cvec_dup(yold->ys_when_nsc)) == NULL){
- clicon_err(OE_YANG, errno, "cvec_dup");
- goto done;
- }
+ if ((ynew->ys_when_nsc = cvec_dup(yold->ys_when_nsc)) == NULL){
+ clicon_err(OE_YANG, errno, "cvec_dup");
+ goto done;
+ }
}
for (i=0; iys_len; i++){
- yco = yold->ys_stmt[i];
- if ((ycn = ys_dup(yco)) == NULL)
- goto done;
- ynew->ys_stmt[i] = ycn;
- ycn->ys_parent = ynew;
+ yco = yold->ys_stmt[i];
+ if ((ycn = ys_dup(yco)) == NULL)
+ goto done;
+ ynew->ys_stmt[i] = ycn;
+ ycn->ys_parent = ynew;
}
retval = 0;
done:
@@ -873,14 +873,14 @@ ys_dup(yang_stmt *old)
yang_stmt *nw;
if ((nw = ys_new(old->ys_keyword)) == NULL)
- return NULL;
+ return NULL;
if (nw->ys_cvec){
- cvec_free(nw->ys_cvec);
- nw->ys_cvec = NULL;
+ cvec_free(nw->ys_cvec);
+ nw->ys_cvec = NULL;
}
if (ys_cp(nw, old) < 0){
- ys_free(nw);
- return NULL;
+ ys_free(nw);
+ return NULL;
}
return nw;
}
@@ -900,7 +900,7 @@ ys_dup(yang_stmt *old)
*/
int
ys_replace(yang_stmt *yorig,
- yang_stmt *yfrom)
+ yang_stmt *yfrom)
{
int retval = -1;
yang_stmt *yp; /* parent */
@@ -910,15 +910,15 @@ ys_replace(yang_stmt *yorig,
/* Remove old yangs all children */
yc = NULL;
while ((yc = yn_each(yorig, yc)) != NULL)
- ys_free(yc);
+ ys_free(yc);
if (yorig->ys_stmt){
- free(yorig->ys_stmt);
- yorig->ys_stmt = NULL;
- yorig->ys_len = 0;
+ free(yorig->ys_stmt);
+ yorig->ys_stmt = NULL;
+ yorig->ys_len = 0;
}
ys_free1(yorig, 0); /* Remove all in yold except the actual object */
if (ys_cp(yorig, yfrom) < 0)
- goto done;
+ goto done;
yorig->ys_parent = yp;
retval = 0;
done:
@@ -936,12 +936,12 @@ ys_replace(yang_stmt *yorig,
*/
int
yn_insert(yang_stmt *ys_parent,
- yang_stmt *ys_child)
+ yang_stmt *ys_child)
{
int pos = ys_parent->ys_len;
if (yn_realloc(ys_parent) < 0)
- return -1;
+ return -1;
ys_parent->ys_stmt[pos] = ys_child;
ys_child->ys_parent = ys_parent;
return 0;
@@ -951,12 +951,12 @@ yn_insert(yang_stmt *ys_parent,
*/
int
yn_insert1(yang_stmt *ys_parent,
- yang_stmt *ys_child)
+ yang_stmt *ys_child)
{
int pos = ys_parent->ys_len;
if (yn_realloc(ys_parent) < 0)
- return -1;
+ return -1;
ys_parent->ys_stmt[pos] = ys_child;
return 0;
}
@@ -976,25 +976,25 @@ yn_insert1(yang_stmt *ys_parent,
*/
yang_stmt *
yn_each(yang_stmt *yparent,
- yang_stmt *yprev)
+ yang_stmt *yprev)
{
int i;
yang_stmt *yc = NULL;
if (yparent == NULL)
- return NULL;
+ return NULL;
for (i=yprev?yprev->_ys_vector_i+1:0; iys_len; i++){
- if ((yc = yparent->ys_stmt[i]) == NULL){
- assert(yc); /* XXX Check if happens */
- continue;
- }
- /* make room for other conditionals */
- break; /* this is next object after previous */
+ if ((yc = yparent->ys_stmt[i]) == NULL){
+ assert(yc); /* XXX Check if happens */
+ continue;
+ }
+ /* make room for other conditionals */
+ break; /* this is next object after previous */
}
if (i < yparent->ys_len) /* found */
- yc->_ys_vector_i = i;
+ yc->_ys_vector_i = i;
else
- yc = NULL;
+ yc = NULL;
return yc;
}
@@ -1011,8 +1011,8 @@ yn_each(yang_stmt *yparent,
*/
yang_stmt *
yang_find(yang_stmt *yn,
- int keyword,
- const char *argument)
+ int keyword,
+ const char *argument)
{
yang_stmt *ys = NULL;
int i;
@@ -1022,30 +1022,30 @@ yang_find(yang_stmt *yn,
yang_stmt *ym;
for (i=0; iys_len; i++){
- ys = yn->ys_stmt[i];
- if (keyword == 0 || ys->ys_keyword == keyword){
- if (argument == NULL ||
- (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0)){
- yret = ys;
- break;
- }
- }
+ ys = yn->ys_stmt[i];
+ if (keyword == 0 || ys->ys_keyword == keyword){
+ if (argument == NULL ||
+ (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0)){
+ yret = ys;
+ break;
+ }
+ }
}
/* Special case: if not match and yang node is module or submodule, extend
* search to include submodules */
if (yret == NULL &&
- (yang_keyword_get(yn) == Y_MODULE ||
- yang_keyword_get(yn) == Y_SUBMODULE)){
- yspec = ys_spec(yn);
- for (i=0; iys_len; i++){
- ys = yn->ys_stmt[i];
- if (yang_keyword_get(ys) == Y_INCLUDE){
- name = yang_argument_get(ys);
- if ((ym = yang_find_module_by_name(yspec, name)) != NULL &&
- (yret = yang_find(ym, keyword, argument)) != NULL)
- break;
- }
- }
+ (yang_keyword_get(yn) == Y_MODULE ||
+ yang_keyword_get(yn) == Y_SUBMODULE)){
+ yspec = ys_spec(yn);
+ for (i=0; iys_len; i++){
+ ys = yn->ys_stmt[i];
+ if (yang_keyword_get(ys) == Y_INCLUDE){
+ name = yang_argument_get(ys);
+ if ((ym = yang_find_module_by_name(yspec, name)) != NULL &&
+ (yret = yang_find(ym, keyword, argument)) != NULL)
+ break;
+ }
+ }
}
return yret;
}
@@ -1062,22 +1062,22 @@ yang_find(yang_stmt *yn,
*/
int
yang_match(yang_stmt *yn,
- int keyword,
- char *argument)
+ int keyword,
+ char *argument)
{
yang_stmt *ys = NULL;
int i;
int match = 0;
for (i=0; iys_len; i++){
- ys = yn->ys_stmt[i];
- if (keyword == 0 || ys->ys_keyword == keyword){
- if (argument == NULL)
- match++;
- else
- if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0)
- match++;
- }
+ ys = yn->ys_stmt[i];
+ if (keyword == 0 || ys->ys_keyword == keyword){
+ if (argument == NULL)
+ match++;
+ else
+ if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0)
+ match++;
+ }
}
return match;
}
@@ -1092,7 +1092,7 @@ yang_match(yang_stmt *yn,
*/
yang_stmt *
yang_find_datanode(yang_stmt *yn,
- char *argument)
+ char *argument)
{
yang_stmt *ys = NULL;
yang_stmt *yc = NULL;
@@ -1102,53 +1102,53 @@ yang_find_datanode(yang_stmt *yn,
ys = NULL;
while ((ys = yn_each(yn, ys)) != NULL){
- if (yang_keyword_get(ys) == Y_CHOICE){ /* Look for its children */
- yc = NULL;
- while ((yc = yn_each(ys, yc)) != NULL){
- if (yang_keyword_get(yc) == Y_CASE) /* Look for its children */
- ysmatch = yang_find_datanode(yc, argument);
- else
- if (yang_datanode(yc)){
- if (argument == NULL)
- ysmatch = yc;
- else
- if (yc->ys_argument && strcmp(argument, yc->ys_argument) == 0)
- ysmatch = yc;
- }
- if (ysmatch)
- goto match; // maybe break?
- }
- } /* Y_CHOICE */
- else if (yang_keyword_get(ys) == Y_INPUT ||
- yang_keyword_get(ys) == Y_OUTPUT){ /* Look for its children */
- if ((ysmatch = yang_find_datanode(ys, argument)) != NULL)
- break;
- }
- else if (yang_datanode(ys)){
- if (argument == NULL)
- ysmatch = ys;
- else
- if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0)
- ysmatch = ys;
- if (ysmatch)
- goto match; // maybe break?
- }
+ if (yang_keyword_get(ys) == Y_CHOICE){ /* Look for its children */
+ yc = NULL;
+ while ((yc = yn_each(ys, yc)) != NULL){
+ if (yang_keyword_get(yc) == Y_CASE) /* Look for its children */
+ ysmatch = yang_find_datanode(yc, argument);
+ else
+ if (yang_datanode(yc)){
+ if (argument == NULL)
+ ysmatch = yc;
+ else
+ if (yc->ys_argument && strcmp(argument, yc->ys_argument) == 0)
+ ysmatch = yc;
+ }
+ if (ysmatch)
+ goto match; // maybe break?
+ }
+ } /* Y_CHOICE */
+ else if (yang_keyword_get(ys) == Y_INPUT ||
+ yang_keyword_get(ys) == Y_OUTPUT){ /* Look for its children */
+ if ((ysmatch = yang_find_datanode(ys, argument)) != NULL)
+ break;
+ }
+ else if (yang_datanode(ys)){
+ if (argument == NULL)
+ ysmatch = ys;
+ else
+ if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0)
+ ysmatch = ys;
+ if (ysmatch)
+ goto match; // maybe break?
+ }
}
/* Special case: if not match and yang node is module or submodule, extend
* search to include submodules */
if (ysmatch == NULL &&
- (yang_keyword_get(yn) == Y_MODULE ||
- yang_keyword_get(yn) == Y_SUBMODULE)){
- yspec = ys_spec(yn);
- ys = NULL;
- while ((ys = yn_each(yn, ys)) != NULL){
- if (yang_keyword_get(ys) == Y_INCLUDE){
- name = yang_argument_get(ys);
- yc = yang_find_module_by_name(yspec, name);
- if ((ysmatch = yang_find_datanode(yc, argument)) != NULL)
- break;
- }
- }
+ (yang_keyword_get(yn) == Y_MODULE ||
+ yang_keyword_get(yn) == Y_SUBMODULE)){
+ yspec = ys_spec(yn);
+ ys = NULL;
+ while ((ys = yn_each(yn, ys)) != NULL){
+ if (yang_keyword_get(ys) == Y_INCLUDE){
+ name = yang_argument_get(ys);
+ yc = yang_find_module_by_name(yspec, name);
+ if ((ysmatch = yang_find_datanode(yc, argument)) != NULL)
+ break;
+ }
+ }
}
match:
return ysmatch;
@@ -1163,7 +1163,7 @@ yang_find_datanode(yang_stmt *yn,
*/
yang_stmt *
yang_find_schemanode(yang_stmt *yn,
- char *argument)
+ char *argument)
{
yang_stmt *ys = NULL;
yang_stmt *yc = NULL;
@@ -1173,60 +1173,60 @@ yang_find_schemanode(yang_stmt *yn,
int i, j;
for (i=0; iys_len; i++){
- ys = yn->ys_stmt[i];
- if (yang_keyword_get(ys) == Y_CHOICE){
- /* First check choice itself */
- if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0){
- ysmatch = ys;
- goto match;
- }
- /* Then look for its children (case) */
- for (j=0; jys_len; j++){
- yc = ys->ys_stmt[j];
- if (yang_keyword_get(yc) == Y_CASE) /* Look for its children */
- ysmatch = yang_find_schemanode(yc, argument);
- else
- if (yang_schemanode(yc)){
- if (argument == NULL)
- ysmatch = yc;
- else
- if (yc->ys_argument && strcmp(argument, yc->ys_argument) == 0)
- ysmatch = yc;
- }
- if (ysmatch)
- goto match;
- }
- } /* Y_CHOICE */
- else
- if (yang_schemanode(ys)){
- if (strcmp(argument, "input") == 0 && yang_keyword_get(ys) == Y_INPUT)
- ysmatch = ys;
- else if (strcmp(argument, "output") == 0 && yang_keyword_get(ys) == Y_OUTPUT)
- ysmatch = ys;
- else if (argument == NULL)
- ysmatch = ys;
- else
- if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0)
- ysmatch = ys;
- if (ysmatch)
- goto match;
- }
+ ys = yn->ys_stmt[i];
+ if (yang_keyword_get(ys) == Y_CHOICE){
+ /* First check choice itself */
+ if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0){
+ ysmatch = ys;
+ goto match;
+ }
+ /* Then look for its children (case) */
+ for (j=0; jys_len; j++){
+ yc = ys->ys_stmt[j];
+ if (yang_keyword_get(yc) == Y_CASE) /* Look for its children */
+ ysmatch = yang_find_schemanode(yc, argument);
+ else
+ if (yang_schemanode(yc)){
+ if (argument == NULL)
+ ysmatch = yc;
+ else
+ if (yc->ys_argument && strcmp(argument, yc->ys_argument) == 0)
+ ysmatch = yc;
+ }
+ if (ysmatch)
+ goto match;
+ }
+ } /* Y_CHOICE */
+ else
+ if (yang_schemanode(ys)){
+ if (strcmp(argument, "input") == 0 && yang_keyword_get(ys) == Y_INPUT)
+ ysmatch = ys;
+ else if (strcmp(argument, "output") == 0 && yang_keyword_get(ys) == Y_OUTPUT)
+ ysmatch = ys;
+ else if (argument == NULL)
+ ysmatch = ys;
+ else
+ if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0)
+ ysmatch = ys;
+ if (ysmatch)
+ goto match;
+ }
}
/* Special case: if not match and yang node is module or submodule, extend
* search to include submodules */
if (ysmatch == NULL &&
- (yang_keyword_get(yn) == Y_MODULE ||
- yang_keyword_get(yn) == Y_SUBMODULE)){
- yspec = ys_spec(yn);
- for (i=0; iys_len; i++){
- ys = yn->ys_stmt[i];
- if (yang_keyword_get(ys) == Y_INCLUDE){
- name = yang_argument_get(ys);
- yc = yang_find_module_by_name(yspec, name);
- if ((ysmatch = yang_find_schemanode(yc, argument)) != NULL)
- break;
- }
- }
+ (yang_keyword_get(yn) == Y_MODULE ||
+ yang_keyword_get(yn) == Y_SUBMODULE)){
+ yspec = ys_spec(yn);
+ for (i=0; iys_len; i++){
+ ys = yn->ys_stmt[i];
+ if (yang_keyword_get(ys) == Y_INCLUDE){
+ name = yang_argument_get(ys);
+ yc = yang_find_module_by_name(yspec, name);
+ if ((ysmatch = yang_find_schemanode(yc, argument)) != NULL)
+ break;
+ }
+ }
}
match:
return ysmatch;
@@ -1251,14 +1251,14 @@ yang_find_myprefix(yang_stmt *ys)
/* Not good enough with submodule, must be actual module */
if (ys_real_module(ys, &ymod) < 0)
- goto done;
+ goto done;
if (ymod == NULL){
- clicon_err(OE_YANG, ENOENT, "Internal error: no module");
- goto done;
+ clicon_err(OE_YANG, ENOENT, "Internal error: no module");
+ goto done;
}
if ((yprefix = yang_find(ymod, Y_PREFIX, NULL)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No prefix found for module %s", yang_argument_get(ymod));
- goto done;
+ clicon_err(OE_YANG, ENOENT, "No prefix found for module %s", yang_argument_get(ymod));
+ goto done;
}
prefix = yang_argument_get(yprefix);
done:
@@ -1283,10 +1283,10 @@ yang_find_mynamespace(yang_stmt *ys)
char *ns = NULL;
if (ys_real_module(ys, &ymod) < 0)
- goto done;
+ goto done;
if ((ynamespace = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No namespace found for module %s", yang_argument_get(ymod));
- goto done;
+ clicon_err(OE_YANG, ENOENT, "No namespace found for module %s", yang_argument_get(ymod));
+ goto done;
}
ns = yang_argument_get(ynamespace);
done:
@@ -1298,7 +1298,7 @@ yang_find_mynamespace(yang_stmt *ys)
* (global) namespace of a module, but you do not know the local prefix
* used to access it in XML.
* @param[in] ys Yang statement in module tree (or module itself)
- * @param[in] ns Namespace URI as char* pointer into yang tree
+ * @param[in] ns Namespace URI as char* pointer into yang tree
* @param[out] prefix Local prefix to access module with (direct pointer)
* @retval -1 Error
* @retval 0 Not found
@@ -1315,8 +1315,8 @@ yang_find_mynamespace(yang_stmt *ys)
*/
int
yang_find_prefix_by_namespace(yang_stmt *ys,
- char *ns,
- char **prefix)
+ char *ns,
+ char **prefix)
{
int retval = -1;
yang_stmt *my_ymod; /* My module */
@@ -1329,30 +1329,30 @@ yang_find_prefix_by_namespace(yang_stmt *ys,
clicon_debug(2, "%s", __FUNCTION__);
if (prefix == NULL){
- clicon_err(OE_YANG, EINVAL, "prefix is NULL");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "prefix is NULL");
+ goto done;
}
/* First check if namespace is my own module */
myns = yang_find_mynamespace(ys);
if (strcmp(myns, ns) == 0){
- *prefix = yang_find_myprefix(ys); /* or NULL? */
- goto found;
+ *prefix = yang_find_myprefix(ys); /* or NULL? */
+ goto found;
}
/* Next, find namespaces in imported modules */
yspec = ys_spec(ys);
if ((ymod = yang_find_module_by_namespace(yspec, ns)) == NULL)
- goto notfound;
+ goto notfound;
modname = yang_argument_get(ymod);
my_ymod = ys_module(ys);
/* Loop through import statements to find a match with ymod */
yimport = NULL;
while ((yimport = yn_each(my_ymod, yimport)) != NULL) {
- if (yang_keyword_get(yimport) == Y_IMPORT &&
- strcmp(modname, yang_argument_get(yimport)) == 0){ /* match */
- yprefix = yang_find(yimport, Y_PREFIX, NULL);
- *prefix = yang_argument_get(yprefix);
- goto found;
- }
+ if (yang_keyword_get(yimport) == Y_IMPORT &&
+ strcmp(modname, yang_argument_get(yimport)) == 0){ /* match */
+ yprefix = yang_find(yimport, Y_PREFIX, NULL);
+ *prefix = yang_argument_get(yprefix);
+ goto found;
+ }
}
notfound:
retval = 0; /* not found */
@@ -1368,7 +1368,7 @@ yang_find_prefix_by_namespace(yang_stmt *ys,
*
* @param[in] ys Yang statement in module tree (or module itself)
* @param[in] prefix Local prefix to access module with (direct pointer)
- * @param[out] ns Namespace URI as char* pointer into yang tree
+ * @param[out] ns Namespace URI as char* pointer into yang tree
* @retval -1 Error
* @retval 0 Not found
* @retval 1 Found
@@ -1384,20 +1384,20 @@ yang_find_prefix_by_namespace(yang_stmt *ys,
*/
int
yang_find_namespace_by_prefix(yang_stmt *ys,
- char *prefix,
- char **ns)
+ char *prefix,
+ char **ns)
{
int retval = -1;
yang_stmt *ym;
if (ns == NULL){
- clicon_err(OE_YANG, EINVAL, "ns is NULL");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "ns is NULL");
+ goto done;
}
if ((ym = yang_find_module_by_prefix(ys, prefix)) == NULL)
- goto notfound;
+ goto notfound;
if ((*ns = yang_find_mynamespace(ym)) == NULL)
- goto notfound;
+ goto notfound;
retval = 1; /* found */
done:
return retval;
@@ -1420,13 +1420,13 @@ yang_myroot(yang_stmt *ys)
kw = yang_keyword_get(ys);
if (ys==NULL || kw==Y_SPEC || kw == Y_MODULE || kw == Y_SUBMODULE)
- return NULL;
+ return NULL;
yp = yang_parent_get(ys);
while((yp = yang_parent_get(ys)) != NULL) {
- kw = yang_keyword_get(yp);
- if (kw == Y_MODULE || kw == Y_SUBMODULE)
- return ys;
- ys = yp;
+ kw = yang_keyword_get(yp);
+ if (kw == Y_MODULE || kw == Y_SUBMODULE)
+ return ys;
+ ys = yp;
}
return NULL;
}
@@ -1439,16 +1439,16 @@ yang_choice(yang_stmt *y)
yang_stmt *yp;
if ((yp = y->ys_parent) != NULL){
- switch (yang_keyword_get(yp)){
- case Y_CHOICE:
- return yp;
- break;
- case Y_CASE:
- return yang_parent_get(yp);
- break;
- default:
- break;
- }
+ switch (yang_keyword_get(yp)){
+ case Y_CHOICE:
+ return yp;
+ break;
+ case Y_CASE:
+ return yang_parent_get(yp);
+ break;
+ default:
+ break;
+ }
}
return NULL;
}
@@ -1467,8 +1467,8 @@ yang_choice(yang_stmt *y)
*/
static int
yang_order1_choice(yang_stmt *yp,
- yang_stmt *y,
- int *index)
+ yang_stmt *y,
+ int *index)
{
yang_stmt *ys;
yang_stmt *yc;
@@ -1479,31 +1479,31 @@ yang_order1_choice(yang_stmt *yp,
index0 = *index;
for (i=0; iys_len; i++){ /* Loop through choice */
- ys = yp->ys_stmt[i];
- if (ys->ys_keyword == Y_CASE){ /* Loop through case */
- *index = index0;
- for (j=0; jys_len; j++){
- yc = ys->ys_stmt[j];
- if (yc->ys_keyword == Y_CHOICE){
- if (yang_order1_choice(yc, y, index) == 1) /* If one of the choices is "y" */
- return 1;
- }
- else {
- if (yang_datanode(yc) && yc == y){
- // *index = index0 + j;
- return 1;
- }
- (*index)++;
- }
- }
- if (*index-index0 > max)
- max = *index-index0;
- }
- else {
- max = 1; /* Shortcut, no case */
- if (yang_datanode(ys) && ys == y)
- return 1;
- }
+ ys = yp->ys_stmt[i];
+ if (ys->ys_keyword == Y_CASE){ /* Loop through case */
+ *index = index0;
+ for (j=0; jys_len; j++){
+ yc = ys->ys_stmt[j];
+ if (yc->ys_keyword == Y_CHOICE){
+ if (yang_order1_choice(yc, y, index) == 1) /* If one of the choices is "y" */
+ return 1;
+ }
+ else {
+ if (yang_datanode(yc) && yc == y){
+ // *index = index0 + j;
+ return 1;
+ }
+ (*index)++;
+ }
+ }
+ if (*index-index0 > max)
+ max = *index-index0;
+ }
+ else {
+ max = 1; /* Shortcut, no case */
+ if (yang_datanode(ys) && ys == y)
+ return 1;
+ }
}
*index += max;
return 0;
@@ -1518,32 +1518,32 @@ yang_order1_choice(yang_stmt *yp,
*/
static int
yang_order1(yang_stmt *yp,
- yang_stmt *y,
- int *index)
+ yang_stmt *y,
+ int *index)
{
int retval = -1;
yang_stmt *ys;
int i;
for (i=0; iys_len; i++){
- ys = yp->ys_stmt[i];
- if (ys->ys_keyword == Y_CHOICE){
- if (yang_order1_choice(ys, y, index) == 1) /* If one of the choices is "y" */
- break;
- }
- else {
- if (!yang_datanode(ys) &&
- yang_keyword_get(ys) != Y_ACTION) /* action is special case */
- continue;
- if (ys == y)
- break;
- (*index)++;
- }
+ ys = yp->ys_stmt[i];
+ if (ys->ys_keyword == Y_CHOICE){
+ if (yang_order1_choice(ys, y, index) == 1) /* If one of the choices is "y" */
+ break;
+ }
+ else {
+ if (!yang_datanode(ys) &&
+ yang_keyword_get(ys) != Y_ACTION) /* action is special case */
+ continue;
+ if (ys == y)
+ break;
+ (*index)++;
+ }
}
if (i < yp->ys_len) /* break -> found */
- retval = 0;
+ retval = 0;
else
- assert(0); // XXX
+ assert(0); // XXX
return retval;
}
@@ -1567,8 +1567,8 @@ yang_order(yang_stmt *y)
int tot = 0;
if (y == NULL){
- retval = -1;
- goto done;
+ retval = -1;
+ goto done;
}
/* Some special handling if yp is choice (or case)
* if so, the real parent (from an xml point of view) is the parents
@@ -1576,7 +1576,7 @@ yang_order(yang_stmt *y)
*/
yp = yang_parent_get(y);
while (yang_keyword_get(yp) == Y_CASE || yang_keyword_get(yp) == Y_CHOICE)
- yp = yp->ys_parent;
+ yp = yp->ys_parent;
/* XML nodes with yang specs that are children of modules are special -
* In clixon, they are seen as an "implicit" container where the XML can come from different
@@ -1585,17 +1585,17 @@ yang_order(yang_stmt *y)
* The order of x and y cannot be compared within a single yang module since they belong to different
*/
if (yang_keyword_get(yp) == Y_MODULE || yang_keyword_get(yp) == Y_SUBMODULE){
- ypp = yang_parent_get(yp); /* yang spec */
- for (i=0; iys_len; i++){ /* iterate through other modules */
- ym = ypp->ys_stmt[i];
- if (yp == ym)
- break;
- tot += ym->ys_len;
- }
+ ypp = yang_parent_get(yp); /* yang spec */
+ for (i=0; iys_len; i++){ /* iterate through other modules */
+ ym = ypp->ys_stmt[i];
+ if (yp == ym)
+ break;
+ tot += ym->ys_len;
+ }
}
if (yang_order1(yp, y, &j) < 0){
- clicon_err(OE_YANG, 0, "YANG node %s not ordered: not found", yang_argument_get(y));
- goto done;
+ clicon_err(OE_YANG, 0, "YANG node %s not ordered: not found", yang_argument_get(y));
+ goto done;
}
retval = tot + j;
done:
@@ -1625,8 +1625,8 @@ yang_str2key(char *str)
*/
int
ys_module_by_xml(yang_stmt *yspec,
- cxobj *xt,
- yang_stmt **ymodp)
+ cxobj *xt,
+ yang_stmt **ymodp)
{
int retval = -1;
yang_stmt *ym = NULL; /* module */
@@ -1634,18 +1634,18 @@ ys_module_by_xml(yang_stmt *yspec,
char *ns = NULL; /* namespace URI */
if (ymodp)
- *ymodp = NULL;
+ *ymodp = NULL;
prefix = xml_prefix(xt);
if (xml2ns(xt, prefix, &ns) < 0) /* prefix may be NULL */
- goto done;
+ goto done;
/* No namespace found, give up */
if (ns == NULL)
- goto ok;
+ goto ok;
/* We got the namespace, now get the module */
ym = yang_find_module_by_namespace(yspec, ns);
/* Set result param */
if (ymodp && ym)
- *ymodp = ym;
+ *ymodp = ym;
ok:
retval = 0;
done:
@@ -1667,21 +1667,21 @@ ys_module(yang_stmt *ys)
yang_stmt *yn;
if (ys==NULL || ys->ys_keyword==Y_SPEC)
- return NULL;
+ return NULL;
if (ys->ys_keyword == Y_MODULE || ys->ys_keyword == Y_SUBMODULE)
- return ys;
+ return ys;
while (ys != NULL &&
- ys->ys_keyword != Y_MODULE &&
- ys->ys_keyword != Y_SUBMODULE){
- if (ys->ys_mymodule){ /* shortcut due to augment */
- ys = ys->ys_mymodule;
- break;
- }
- yn = ys->ys_parent;
- /* Some extra stuff to ensure ys is a stmt */
- if (yn && yn->ys_keyword == Y_SPEC)
- yn = NULL;
- ys = (yang_stmt*)yn;
+ ys->ys_keyword != Y_MODULE &&
+ ys->ys_keyword != Y_SUBMODULE){
+ if (ys->ys_mymodule){ /* shortcut due to augment */
+ ys = ys->ys_mymodule;
+ break;
+ }
+ yn = ys->ys_parent;
+ /* Some extra stuff to ensure ys is a stmt */
+ if (yn && yn->ys_keyword == Y_SPEC)
+ yn = NULL;
+ ys = (yang_stmt*)yn;
}
/* Here it is either NULL or is a typedef-kind yang-stmt */
return ys;
@@ -1699,7 +1699,7 @@ ys_module(yang_stmt *ys)
*/
int
ys_real_module(yang_stmt *ys,
- yang_stmt **ymod)
+ yang_stmt **ymod)
{
int retval = -1;
yang_stmt *ym = NULL;
@@ -1709,27 +1709,27 @@ ys_real_module(yang_stmt *ys,
yang_stmt *yspec;
if (ymod == NULL){
- clicon_err(OE_YANG, EINVAL, "ymod is NULL");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "ymod is NULL");
+ goto done;
}
if ((ym = ys_module(ys)) != NULL){
- yspec = ys_spec(ym);
- while (ym && yang_keyword_get(ym) == Y_SUBMODULE){
- if ((yb = yang_find(ym, Y_BELONGS_TO, NULL)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No belongs-to statement of submodule %s", yang_argument_get(ym)); /* shouldnt happen */
- goto done;
- }
- if ((name = yang_argument_get(yb)) == NULL){
- clicon_err(OE_YANG, ENOENT, "Belongs-to statement of submodule %s has no argument", yang_argument_get(ym)); /* shouldnt happen */
- goto done;
- }
- if ((ysubm = yang_find_module_by_name(yspec, name)) == NULL){
- clicon_err(OE_YANG, ENOENT, "submodule %s references non-existent module %s in its belongs-to statement",
- yang_argument_get(ym), name);
- goto done;
- }
- ym = ysubm;
- }
+ yspec = ys_spec(ym);
+ while (ym && yang_keyword_get(ym) == Y_SUBMODULE){
+ if ((yb = yang_find(ym, Y_BELONGS_TO, NULL)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "No belongs-to statement of submodule %s", yang_argument_get(ym)); /* shouldnt happen */
+ goto done;
+ }
+ if ((name = yang_argument_get(yb)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "Belongs-to statement of submodule %s has no argument", yang_argument_get(ym)); /* shouldnt happen */
+ goto done;
+ }
+ if ((ysubm = yang_find_module_by_name(yspec, name)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "submodule %s references non-existent module %s in its belongs-to statement",
+ yang_argument_get(ym), name);
+ goto done;
+ }
+ ym = ysubm;
+ }
}
*ymod = ym;
retval = 0;
@@ -1750,8 +1750,8 @@ ys_spec(yang_stmt *ys)
yang_stmt *yn;
while (ys != NULL && ys->ys_keyword != Y_SPEC){
- yn = ys->ys_parent;
- ys = (yang_stmt*)yn;
+ yn = ys->ys_parent;
+ ys = (yang_stmt*)yn;
}
/* Here it is either NULL or is a typedef-kind yang-stmt */
return (yang_stmt*)ys;
@@ -1765,8 +1765,8 @@ quotedstring(char *s)
int i;
for (i=0; iys_keyword));
- fprintf(f, " %s", ym->ys_argument);
- if ((yrev = yang_find(ym, Y_REVISION, NULL)) != NULL){
- fprintf(f, "@%u", cv_uint32_get(yang_cv_get(yrev)));
- }
- fprintf(f, ".yang");
- fprintf(f, "\n");
+ fprintf(f, "%s", yang_key2str(ym->ys_keyword));
+ fprintf(f, " %s", ym->ys_argument);
+ if ((yrev = yang_find(ym, Y_REVISION, NULL)) != NULL){
+ fprintf(f, "@%u", cv_uint32_get(yang_cv_get(yrev)));
+ }
+ fprintf(f, ".yang");
+ fprintf(f, "\n");
}
return 0;
}
@@ -1844,7 +1844,7 @@ yang_spec_print(FILE *f,
*/
int
yang_spec_dump(yang_stmt *yspec,
- int dbglevel)
+ int dbglevel)
{
int retval = -1;
yang_stmt *ym = NULL;
@@ -1852,23 +1852,23 @@ yang_spec_dump(yang_stmt *yspec,
cbuf *cb = NULL;
if ((cb = cbuf_new()) ==NULL){
- clicon_err(OE_YANG, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_YANG, errno, "cbuf_new");
+ goto done;
}
while ((ym = yn_each(yspec, ym)) != NULL) {
- cprintf(cb, "%s", yang_key2str(ym->ys_keyword));
- cprintf(cb, " %s", ym->ys_argument);
- if ((yrev = yang_find(ym, Y_REVISION, NULL)) != NULL){
- cprintf(cb, "@%u", cv_uint32_get(yang_cv_get(yrev)));
- }
- cprintf(cb, ".yang");
- clicon_debug(dbglevel, "%s", cbuf_get(cb));
- cbuf_reset(cb);
+ cprintf(cb, "%s", yang_key2str(ym->ys_keyword));
+ cprintf(cb, " %s", ym->ys_argument);
+ if ((yrev = yang_find(ym, Y_REVISION, NULL)) != NULL){
+ cprintf(cb, "@%u", cv_uint32_get(yang_cv_get(yrev)));
+ }
+ cprintf(cb, ".yang");
+ clicon_debug(dbglevel, "%s", cbuf_get(cb));
+ cbuf_reset(cb);
}
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -1885,30 +1885,30 @@ yang_spec_dump(yang_stmt *yspec,
*/
int
yang_print_cbuf(cbuf *cb,
- yang_stmt *yn,
- int marginal)
+ yang_stmt *yn,
+ int marginal)
{
yang_stmt *ys = NULL;
while ((ys = yn_each(yn, ys)) != NULL) {
- if (ys->ys_keyword == Y_UNKNOWN){ /* dont print unknown - proxy for extension*/
- cprintf(cb, "%*s", marginal-1, "");
- }
- else
- cprintf(cb, "%*s%s", marginal, "", yang_key2str(ys->ys_keyword));
- if (ys->ys_argument){
- if (quotedstring(ys->ys_argument))
- cprintf(cb, " \"%s\"", ys->ys_argument);
- else
- cprintf(cb, " %s", ys->ys_argument);
- }
- if (ys->ys_len){
- cprintf(cb, " {\n");
- yang_print_cbuf(cb, ys, marginal+3);
- cprintf(cb, "%*s%s\n", marginal, "", "}");
- }
- else
- cprintf(cb, ";\n");
+ if (ys->ys_keyword == Y_UNKNOWN){ /* dont print unknown - proxy for extension*/
+ cprintf(cb, "%*s", marginal-1, "");
+ }
+ else
+ cprintf(cb, "%*s%s", marginal, "", yang_key2str(ys->ys_keyword));
+ if (ys->ys_argument){
+ if (quotedstring(ys->ys_argument))
+ cprintf(cb, " \"%s\"", ys->ys_argument);
+ else
+ cprintf(cb, " %s", ys->ys_argument);
+ }
+ if (ys->ys_len){
+ cprintf(cb, " {\n");
+ yang_print_cbuf(cb, ys, marginal+3);
+ cprintf(cb, "%*s%s\n", marginal, "", "}");
+ }
+ else
+ cprintf(cb, ";\n");
}
return 0;
}
@@ -1923,7 +1923,7 @@ yang_print_cbuf(cbuf *cb,
*/
int
yang_deviation(yang_stmt *ys,
- void *arg)
+ void *arg)
{
int retval = -1;
@@ -1940,112 +1940,112 @@ yang_deviation(yang_stmt *ys,
int max;
if (yang_keyword_get(ys) != Y_DEVIATION)
- goto ok;
+ goto ok;
/* Absolute schema node identifier identifying target node */
if ((nodeid = yang_argument_get(ys)) == NULL){
- clicon_err(OE_YANG, EINVAL, "No argument to deviation");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "No argument to deviation");
+ goto done;
}
/* Get target node */
if (yang_abs_schema_nodeid(ys, nodeid, &ytarget) < 0)
- goto done;
+ goto done;
if (ytarget == NULL){
- clicon_log(LOG_WARNING, "deviation %s: target not found", nodeid);
- goto ok;
- /* The RFC does not explicitly say the target node MUST exist
- clicon_err(OE_YANG, 0, "schemanode sanity check of %s", nodeid);
- goto done;
- */
+ clicon_log(LOG_WARNING, "deviation %s: target not found", nodeid);
+ goto ok;
+ /* The RFC does not explicitly say the target node MUST exist
+ clicon_err(OE_YANG, 0, "schemanode sanity check of %s", nodeid);
+ goto done;
+ */
}
/* Go through deviates of deviation */
yd = NULL;
while ((yd = yn_each(ys, yd)) != NULL) {
- /* description / if-feature / reference */
- if (yang_keyword_get(yd) != Y_DEVIATE)
- continue;
- devop = yang_argument_get(yd);
- if (strcmp(devop, "not-supported") == 0){
- if (ys_prune_self(ytarget) < 0)
- goto done;
- if (ys_free(ytarget) < 0)
- goto done;
- goto ok; /* Target node removed, no other deviates possible */
- }
- else if (strcmp(devop, "add") == 0){
- yc = NULL;
- while ((yc = yn_each(yd, yc)) != NULL) {
- /* If a property can only appear once, the property MUST NOT exist in the target node. */
- kw = yang_keyword_get(yc);
- if (yang_find(ytarget, kw, NULL) != NULL){
- if (yang_cardinality_interval(h,
- yang_keyword_get(ytarget),
- kw,
- &min,
- &max) < 0)
- goto done;
- if (max == 1){
- clicon_err(OE_YANG, 0, "deviation %s: \"%s %s\" added but node already exist in target %s",
- nodeid,
- yang_key2str(kw), yang_argument_get(yc),
- yang_argument_get(ytarget));
- goto done;
- }
- }
- /* Make a copy of deviate child and insert. */
- if ((yc1 = ys_dup(yc)) == NULL)
- goto done;
- if (yn_insert(ytarget, yc1) < 0)
- goto done;
- }
- }
- else if (strcmp(devop, "replace") == 0){
- yc = NULL;
- while ((yc = yn_each(yd, yc)) != NULL) {
- /* The properties to replace MUST exist in the target node.*/
- kw = yang_keyword_get(yc);
- if ((ytc = yang_find(ytarget, kw, NULL)) == NULL){
- clicon_err(OE_YANG, 0, "deviation %s: \"%s %s\" replaced but node does not exist in target %s",
- nodeid,
- yang_key2str(kw), yang_argument_get(yc),
- yang_argument_get(ytarget));
- goto done;
- }
- /* Remove old */
- if (ys_prune_self(ytc) < 0)
- goto done;
- if (ys_free(ytc) < 0)
- goto done;
- /* Make a copy of deviate child and insert. */
- if ((yc1 = ys_dup(yc)) == NULL)
- goto done;
- if (yn_insert(ytarget, yc1) < 0)
- goto done;
- }
- }
- else if (strcmp(devop, "delete") == 0){
- yc = NULL;
- while ((yc = yn_each(yd, yc)) != NULL) {
- /* The substatement's keyword MUST match a corresponding keyword in the target node, and the
- * argument's string MUST be equal to the corresponding keyword's argument string in the
- * target node. */
- kw = yang_keyword_get(yc);
- if ((ytc = yang_find(ytarget, kw, NULL)) == NULL){
- clicon_err(OE_YANG, 0, "deviation %s: \"%s %s\" replaced but node does not exist in target %s",
- nodeid,
- yang_key2str(kw), yang_argument_get(yc),
- yang_argument_get(ytarget));
- goto done;
- }
- if (ys_prune_self(ytc) < 0)
- goto done;
- if (ys_free(ytc) < 0)
- goto done;
- }
- }
- else{ /* Shouldnt happen, lex/yacc takes it */
- clicon_err(OE_YANG, EINVAL, "%s: invalid deviate operator", devop);
- goto done;
- }
+ /* description / if-feature / reference */
+ if (yang_keyword_get(yd) != Y_DEVIATE)
+ continue;
+ devop = yang_argument_get(yd);
+ if (strcmp(devop, "not-supported") == 0){
+ if (ys_prune_self(ytarget) < 0)
+ goto done;
+ if (ys_free(ytarget) < 0)
+ goto done;
+ goto ok; /* Target node removed, no other deviates possible */
+ }
+ else if (strcmp(devop, "add") == 0){
+ yc = NULL;
+ while ((yc = yn_each(yd, yc)) != NULL) {
+ /* If a property can only appear once, the property MUST NOT exist in the target node. */
+ kw = yang_keyword_get(yc);
+ if (yang_find(ytarget, kw, NULL) != NULL){
+ if (yang_cardinality_interval(h,
+ yang_keyword_get(ytarget),
+ kw,
+ &min,
+ &max) < 0)
+ goto done;
+ if (max == 1){
+ clicon_err(OE_YANG, 0, "deviation %s: \"%s %s\" added but node already exist in target %s",
+ nodeid,
+ yang_key2str(kw), yang_argument_get(yc),
+ yang_argument_get(ytarget));
+ goto done;
+ }
+ }
+ /* Make a copy of deviate child and insert. */
+ if ((yc1 = ys_dup(yc)) == NULL)
+ goto done;
+ if (yn_insert(ytarget, yc1) < 0)
+ goto done;
+ }
+ }
+ else if (strcmp(devop, "replace") == 0){
+ yc = NULL;
+ while ((yc = yn_each(yd, yc)) != NULL) {
+ /* The properties to replace MUST exist in the target node.*/
+ kw = yang_keyword_get(yc);
+ if ((ytc = yang_find(ytarget, kw, NULL)) == NULL){
+ clicon_err(OE_YANG, 0, "deviation %s: \"%s %s\" replaced but node does not exist in target %s",
+ nodeid,
+ yang_key2str(kw), yang_argument_get(yc),
+ yang_argument_get(ytarget));
+ goto done;
+ }
+ /* Remove old */
+ if (ys_prune_self(ytc) < 0)
+ goto done;
+ if (ys_free(ytc) < 0)
+ goto done;
+ /* Make a copy of deviate child and insert. */
+ if ((yc1 = ys_dup(yc)) == NULL)
+ goto done;
+ if (yn_insert(ytarget, yc1) < 0)
+ goto done;
+ }
+ }
+ else if (strcmp(devop, "delete") == 0){
+ yc = NULL;
+ while ((yc = yn_each(yd, yc)) != NULL) {
+ /* The substatement's keyword MUST match a corresponding keyword in the target node, and the
+ * argument's string MUST be equal to the corresponding keyword's argument string in the
+ * target node. */
+ kw = yang_keyword_get(yc);
+ if ((ytc = yang_find(ytarget, kw, NULL)) == NULL){
+ clicon_err(OE_YANG, 0, "deviation %s: \"%s %s\" replaced but node does not exist in target %s",
+ nodeid,
+ yang_key2str(kw), yang_argument_get(yc),
+ yang_argument_get(ytarget));
+ goto done;
+ }
+ if (ys_prune_self(ytc) < 0)
+ goto done;
+ if (ys_free(ytc) < 0)
+ goto done;
+ }
+ }
+ else{ /* Shouldnt happen, lex/yacc takes it */
+ clicon_err(OE_YANG, EINVAL, "%s: invalid deviate operator", devop);
+ goto done;
+ }
}
ok:
retval = 0;
@@ -2069,7 +2069,7 @@ yang_deviation(yang_stmt *ys,
*/
static int
ys_populate_leaf(clicon_handle h,
- yang_stmt *ys)
+ yang_stmt *ys)
{
int retval = -1;
cg_var *cv = NULL;
@@ -2089,21 +2089,21 @@ ys_populate_leaf(clicon_handle h,
yparent = ys->ys_parent; /* Find parent: list/container */
/* 1. Find type specification and set cv type accordingly */
if (yang_type_get(ys, &origtype, &yrestype, &options, NULL, NULL, NULL, &fraction_digits) < 0)
- goto done;
+ goto done;
restype = yrestype?yrestype->ys_argument:NULL;
if (clicon_type2cv(origtype, restype, ys, &cvtype) < 0) /* This handles non-resolved also */
- goto done;
+ goto done;
/* 2. Create the CV using cvtype and name it */
if ((cv = cv_new(cvtype)) == NULL){
- clicon_err(OE_YANG, errno, "cv_new");
- goto done;
+ clicon_err(OE_YANG, errno, "cv_new");
+ goto done;
}
if (options & YANG_OPTIONS_FRACTION_DIGITS && cvtype == CGV_DEC64) /* XXX: Seems misplaced? / too specific */
- cv_dec64_n_set(cv, fraction_digits);
+ cv_dec64_n_set(cv, fraction_digits);
if (cv_name_set(cv, ys->ys_argument) == NULL){
- clicon_err(OE_YANG, errno, "cv_new_set");
- goto done;
+ clicon_err(OE_YANG, errno, "cv_new_set");
+ goto done;
}
/* get parent of where type is defined, can be original object */
ytypedef = yrestype?yang_parent_get(yrestype):ys;
@@ -2113,45 +2113,45 @@ ys_populate_leaf(clicon_handle h,
* 3a) First check local default
*/
if ((ydef = yang_find(ys, Y_DEFAULT, NULL)) != NULL){
- if ((cvret = cv_parse1(ydef->ys_argument, cv, &reason)) < 0){ /* error */
- clicon_err(OE_YANG, errno, "parsing cv");
- goto done;
- }
- if (cvret == 0){ /* parsing failed */
- clicon_err(OE_YANG, errno, "Parsing CV: %s", reason);
- free(reason);
- goto done;
- }
+ if ((cvret = cv_parse1(ydef->ys_argument, cv, &reason)) < 0){ /* error */
+ clicon_err(OE_YANG, errno, "parsing cv");
+ goto done;
+ }
+ if (cvret == 0){ /* parsing failed */
+ clicon_err(OE_YANG, errno, "Parsing CV: %s", reason);
+ free(reason);
+ goto done;
+ }
}
/* 2. then check typedef default */
else if (ytypedef != ys &&
- (ydef = yang_find(ytypedef, Y_DEFAULT, NULL)) != NULL) {
- if ((cvret = cv_parse1(ydef->ys_argument, cv, &reason)) < 0){ /* error */
- clicon_err(OE_YANG, errno, "parsing cv");
- goto done;
- }
- if (cvret == 0){ /* parsing failed */
- clicon_err(OE_YANG, errno, "Parsing CV: %s", reason);
- free(reason);
- goto done;
- }
+ (ydef = yang_find(ytypedef, Y_DEFAULT, NULL)) != NULL) {
+ if ((cvret = cv_parse1(ydef->ys_argument, cv, &reason)) < 0){ /* error */
+ clicon_err(OE_YANG, errno, "parsing cv");
+ goto done;
+ }
+ if (cvret == 0){ /* parsing failed */
+ clicon_err(OE_YANG, errno, "Parsing CV: %s", reason);
+ free(reason);
+ goto done;
+ }
}
else{
- /* 3b. If not default value, indicate empty cv. */
- cv_flag_set(cv, V_UNSET); /* no value (no default) */
+ /* 3b. If not default value, indicate empty cv. */
+ cv_flag_set(cv, V_UNSET); /* no value (no default) */
}
/* 4. Check if leaf is part of list, if key exists mark leaf as key/unique */
if (yparent && yparent->ys_keyword == Y_LIST){
- if ((ret = yang_key_match(yparent, ys->ys_argument, NULL)) < 0)
- goto done;
+ if ((ret = yang_key_match(yparent, ys->ys_argument, NULL)) < 0)
+ goto done;
}
yang_cv_set(ys, cv);
retval = 0;
done:
if (origtype)
- free(origtype);
+ free(origtype);
if (cv && retval < 0)
- cv_free(cv);
+ cv_free(cv);
return retval;
}
@@ -2161,16 +2161,16 @@ ys_populate_leaf(clicon_handle h,
*/
static int
ys_populate_list(clicon_handle h,
- yang_stmt *ys)
+ yang_stmt *ys)
{
yang_stmt *ykey;
cvec *cvv;
if ((ykey = yang_find(ys, Y_KEY, NULL)) == NULL)
- return 0;
+ return 0;
if ((cvv = yang_arg2cvec(ykey, " ")) == NULL)
- return -1;
+ return -1;
yang_cvec_set(ys, cvv);
return 0;
}
@@ -2180,10 +2180,10 @@ ys_populate_list(clicon_handle h,
*/
static int
bound_add(yang_stmt *ys,
- enum cv_type cvtype,
- char *name,
- char *val,
- uint8_t fraction_digits)
+ enum cv_type cvtype,
+ char *name,
+ char *val,
+ uint8_t fraction_digits)
{
int retval = -1;
cg_var *cv;
@@ -2191,27 +2191,27 @@ bound_add(yang_stmt *ys,
int ret = 1;
if ((cv = cvec_add(ys->ys_cvec, cvtype)) == NULL){
- clicon_err(OE_YANG, errno, "cvec_add");
- goto done;
+ clicon_err(OE_YANG, errno, "cvec_add");
+ goto done;
}
if (cv_name_set(cv, name) == NULL){
- clicon_err(OE_YANG, errno, "cv_name_set(%s)", name);
- goto done;
+ clicon_err(OE_YANG, errno, "cv_name_set(%s)", name);
+ goto done;
}
if (cvtype == CGV_DEC64)
- cv_dec64_n_set(cv, fraction_digits);
+ cv_dec64_n_set(cv, fraction_digits);
if (strcmp(val, "min") == 0)
- cv_min_set(cv);
+ cv_min_set(cv);
else if (strcmp(val, "max") == 0)
- cv_max_set(cv);
+ cv_max_set(cv);
else if ((ret = cv_parse1(val, cv, &reason)) < 0){
- clicon_err(OE_YANG, errno, "cv_parse1");
- goto done;
+ clicon_err(OE_YANG, errno, "cv_parse1");
+ goto done;
}
if (ret == 0){ /* parsing failed */
- clicon_err(OE_YANG, errno, "range statement %s: %s", val, reason);
- free(reason);
- goto done;
+ clicon_err(OE_YANG, errno, "range statement %s: %s", val, reason);
+ free(reason);
+ goto done;
}
retval = 0;
done:
@@ -2222,8 +2222,8 @@ bound_add(yang_stmt *ys,
*/
static int
range_parse(yang_stmt *ys,
- enum cv_type cvtype,
- uint8_t fraction_digits)
+ enum cv_type cvtype,
+ uint8_t fraction_digits)
{
int retval = -1;
char **vec = NULL;
@@ -2233,25 +2233,25 @@ range_parse(yang_stmt *ys,
char *v2;
if ((vec = clicon_strsep(ys->ys_argument, "|", &nvec)) == NULL)
- goto done;
+ goto done;
for (i=0; iys_parent; /* Find parent: type */
if (yparent->ys_keyword != Y_TYPE){
- clicon_err(OE_YANG, 0, "parent should be type");
- goto done;
+ clicon_err(OE_YANG, 0, "parent should be type");
+ goto done;
}
if (yang_type_resolve(ys, ys, (yang_stmt*)yparent, &yrestype,
- &options, NULL, NULL, NULL, &fraction_digits) < 0)
- goto done;
+ &options, NULL, NULL, NULL, &fraction_digits) < 0)
+ goto done;
if (yrestype == NULL){
- clicon_err(OE_YANG, 0, "result-type should not be NULL");
- goto done;
+ clicon_err(OE_YANG, 0, "result-type should not be NULL");
+ goto done;
}
restype = yrestype?yrestype->ys_argument:NULL;
if (nodeid_split(yang_argument_get(yparent), NULL, &origtype) < 0)
- goto done;
+ goto done;
/* This handles non-resolved also */
if (clicon_type2cv(origtype, restype, ys, &cvtype) < 0)
- goto done;
+ goto done;
if (!cv_isint(cvtype) && cvtype != CGV_DEC64){
- clicon_err(OE_YANG, 0, "The range substatement only applies to int types, not to type: %s", origtype);
- goto done;
+ clicon_err(OE_YANG, 0, "The range substatement only applies to int types, not to type: %s", origtype);
+ goto done;
}
if (range_parse(ys, cvtype, fraction_digits) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (origtype)
- free(origtype);
+ free(origtype);
return retval;
}
@@ -2331,7 +2331,7 @@ ys_populate_range(clicon_handle h,
*/
static int
ys_populate_length(clicon_handle h,
- yang_stmt *ys)
+ yang_stmt *ys)
{
int retval = -1;
yang_stmt *yparent; /* type */
@@ -2339,12 +2339,12 @@ ys_populate_length(clicon_handle h,
yparent = ys->ys_parent; /* Find parent: type */
if (yparent->ys_keyword != Y_TYPE){
- clicon_err(OE_YANG, 0, "parent should be type");
- goto done;
+ clicon_err(OE_YANG, 0, "parent should be type");
+ goto done;
}
cvtype = CGV_UINT64;
if (range_parse(ys, cvtype, 0) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -2357,29 +2357,29 @@ ys_populate_length(clicon_handle h,
*/
static int
ys_populate_type(clicon_handle h,
- yang_stmt *ys)
+ yang_stmt *ys)
{
int retval = -1;
yang_stmt *ybase;
if (strcmp(ys->ys_argument, "decimal64") == 0){
- if (yang_find(ys, Y_FRACTION_DIGITS, NULL) == NULL){
- clicon_err(OE_YANG, 0, "decimal64 type requires fraction-digits sub-statement");
- goto done;
- }
+ if (yang_find(ys, Y_FRACTION_DIGITS, NULL) == NULL){
+ clicon_err(OE_YANG, 0, "decimal64 type requires fraction-digits sub-statement");
+ goto done;
+ }
}
else
if (strcmp(ys->ys_argument, "identityref") == 0){
- if ((ybase = yang_find(ys, Y_BASE, NULL)) == NULL){
- clicon_err(OE_YANG, 0, "identityref type requires base sub-statement");
- goto done;
- }
- if ((yang_find_identity(ys, ybase->ys_argument)) == NULL){
- clicon_err(OE_YANG, 0, "Identity %s not found (base type of %s)",
- ybase->ys_argument, ys->ys_argument);
- goto done;
- }
+ if ((ybase = yang_find(ys, Y_BASE, NULL)) == NULL){
+ clicon_err(OE_YANG, 0, "identityref type requires base sub-statement");
+ goto done;
+ }
+ if ((yang_find_identity(ys, ybase->ys_argument)) == NULL){
+ clicon_err(OE_YANG, 0, "Identity %s not found (base type of %s)",
+ ybase->ys_argument, ys->ys_argument);
+ goto done;
+ }
}
retval = 0;
done:
@@ -2399,8 +2399,8 @@ ys_populate_type(clicon_handle h,
*/
static int
ys_populate_identity(clicon_handle h,
- yang_stmt *ys,
- char *idref)
+ yang_stmt *ys,
+ char *idref)
{
int retval = -1;
yang_stmt *yc = NULL;
@@ -2417,63 +2417,63 @@ ys_populate_identity(clicon_handle h,
* The idref is (here) in "canonical form": :
*/
if (idref == NULL){
- /* Create derived identity through prefix:id if not recursively called*/
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- if (nodeid_split(yang_argument_get(ys), &prefix, &id) < 0)
- goto done;
- if ((ymod = ys_module(ys)) == NULL){
- clicon_err(OE_YANG, ENOENT, "No module found");
- goto done;
- }
- cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
- idref = cbuf_get(cb);
+ /* Create derived identity through prefix:id if not recursively called*/
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ if (nodeid_split(yang_argument_get(ys), &prefix, &id) < 0)
+ goto done;
+ if ((ymod = ys_module(ys)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "No module found");
+ goto done;
+ }
+ cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
+ idref = cbuf_get(cb);
}
/* Iterate through all base statements and check the base identity exists
* AND populate the base identity recursively
*/
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL) {
- if (yc->ys_keyword != Y_BASE)
- continue;
- baseid = yang_argument_get(yc); /* on the form: prefix:id */
- if (((ybaseid = yang_find_identity(ys, baseid))) == NULL){
- clicon_err(OE_YANG, ENOENT, "No such identity: %s", baseid);
- goto done;
- }
- // continue; /* root identity */
- /* Check if derived id is already in base identifier
- * note that cvec is always created in ys_new()
- */
- idrefvec = yang_cvec_get(ybaseid);
- if (cvec_find(idrefvec, idref) != NULL)
- continue;
- /* Add derived id to ybaseid */
- if ((cv = cv_new(CGV_STRING)) == NULL){
- clicon_err(OE_UNIX, errno, "cv_new");
- goto done;
- }
- /* add prefix */
- cv_name_set(cv, idref);
- cvec_append_var(idrefvec, cv); /* cv copied */
- if (cv){
- cv_free(cv);
- cv = NULL;
- }
- /* Transitive to the root */
- if (ys_populate_identity(h, ybaseid, idref) < 0)
- goto done;
+ if (yc->ys_keyword != Y_BASE)
+ continue;
+ baseid = yang_argument_get(yc); /* on the form: prefix:id */
+ if (((ybaseid = yang_find_identity(ys, baseid))) == NULL){
+ clicon_err(OE_YANG, ENOENT, "No such identity: %s", baseid);
+ goto done;
+ }
+ // continue; /* root identity */
+ /* Check if derived id is already in base identifier
+ * note that cvec is always created in ys_new()
+ */
+ idrefvec = yang_cvec_get(ybaseid);
+ if (cvec_find(idrefvec, idref) != NULL)
+ continue;
+ /* Add derived id to ybaseid */
+ if ((cv = cv_new(CGV_STRING)) == NULL){
+ clicon_err(OE_UNIX, errno, "cv_new");
+ goto done;
+ }
+ /* add prefix */
+ cv_name_set(cv, idref);
+ cvec_append_var(idrefvec, cv); /* cv copied */
+ if (cv){
+ cv_free(cv);
+ cv = NULL;
+ }
+ /* Transitive to the root */
+ if (ys_populate_identity(h, ybaseid, idref) < 0)
+ goto done;
}
retval = 0;
done:
if (prefix)
- free(prefix);
+ free(prefix);
if (id)
- free(id);
+ free(id);
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -2488,19 +2488,19 @@ ys_populate_identity(clicon_handle h,
*/
int
if_feature(yang_stmt *yspec,
- char *module,
- char *feature)
+ char *module,
+ char *feature)
{
yang_stmt *ym; /* module */
yang_stmt *yf; /* feature */
cg_var *cv;
if ((ym = yang_find_module_by_name(yspec, module)) == NULL)
- return 0;
+ return 0;
if ((yf = yang_find(ym, Y_FEATURE, feature)) == NULL)
- return 0;
+ return 0;
if ((cv = yang_cv_get(yf)) == NULL)
- return 0;
+ return 0;
return cv_bool_get(cv);
}
@@ -2512,7 +2512,7 @@ if_feature(yang_stmt *yspec,
*/
static int
ys_populate_feature(clicon_handle h,
- yang_stmt *ys)
+ yang_stmt *ys)
{
int retval = -1;
cxobj *x;
@@ -2529,40 +2529,40 @@ ys_populate_feature(clicon_handle h,
* Bootstrapping: A feature is enabled if found in clixon-config
*/
if ((x = clicon_conf_xml(h)) == NULL)
- goto ok;
+ goto ok;
if ((ymod = ys_module(ys)) == NULL){
- clicon_err(OE_YANG, 0, "module not found");
- goto done;
+ clicon_err(OE_YANG, 0, "module not found");
+ goto done;
}
module = ymod->ys_argument;
feature = ys->ys_argument;
xc = NULL;
while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL && found == 0) {
- m = NULL;
- f = NULL;
- if (strcmp(xml_name(xc), "CLICON_FEATURE") != 0)
- continue;
- /* CLICON_FEATURE is on the form :.
- * Split on colon to get module(m) and feature(f) respectively */
- if (nodeid_split(xml_body(xc), &m, &f) < 0)
- goto done;
- if (m && f &&
- (strcmp(m,"*")==0 ||
- strcmp(m, module)==0) &&
- (strcmp(f,"*")==0 ||
- strcmp(f, feature)==0))
- found = 1;
- if (m) free(m);
- if (f) free(f);
+ m = NULL;
+ f = NULL;
+ if (strcmp(xml_name(xc), "CLICON_FEATURE") != 0)
+ continue;
+ /* CLICON_FEATURE is on the form :.
+ * Split on colon to get module(m) and feature(f) respectively */
+ if (nodeid_split(xml_body(xc), &m, &f) < 0)
+ goto done;
+ if (m && f &&
+ (strcmp(m,"*")==0 ||
+ strcmp(m, module)==0) &&
+ (strcmp(f,"*")==0 ||
+ strcmp(f, feature)==0))
+ found = 1;
+ if (m) free(m);
+ if (f) free(f);
}
if ((cv = cv_new(CGV_BOOL)) == NULL){
- clicon_err(OE_YANG, errno, "cv_new");
- goto done;
+ clicon_err(OE_YANG, errno, "cv_new");
+ goto done;
}
cv_name_set(cv, feature);
cv_bool_set(cv, found);
if (found)
- clicon_debug(1, "%s %s:%s", __FUNCTION__, module, feature);
+ clicon_debug(1, "%s %s:%s", __FUNCTION__, module, feature);
yang_cv_set(ys, cv);
ok:
retval = 0;
@@ -2576,12 +2576,12 @@ ys_populate_feature(clicon_handle h,
*/
static int
ys_populate_unique(clicon_handle h,
- yang_stmt *ys)
+ yang_stmt *ys)
{
cvec *cvv;
if ((cvv = yang_arg2cvec(ys, " ")) == NULL)
- return -1;
+ return -1;
yang_cvec_set(ys, cvv);
return 0;
}
@@ -2603,7 +2603,7 @@ ys_populate_unique(clicon_handle h,
*/
static int
ys_populate_unknown(clicon_handle h,
- yang_stmt *ys)
+ yang_stmt *ys)
{
int retval = -1;
yang_stmt *ymod;
@@ -2616,31 +2616,31 @@ ys_populate_unknown(clicon_handle h,
/* Find extension, if found, store it as unknown, if not,
break for error */
if (nodeid_split(yang_argument_get(ys), &prefix, &id) < 0)
- goto done;
+ goto done;
if ((ymod = yang_find_module_by_prefix(ys, prefix)) == NULL){
- clicon_err(OE_YANG, ENOENT, "Extension \"%s:%s\", module not found", prefix, id);
- goto done;
+ clicon_err(OE_YANG, ENOENT, "Extension \"%s:%s\", module not found", prefix, id);
+ goto done;
}
/* To find right binding eg after grouping/uses */
ys->ys_mymodule = ys_module(ys);
if ((yext = yang_find(ymod, Y_EXTENSION, id)) == NULL){
- clicon_err(OE_YANG, ENOENT, "Extension \"%s:%s\" not found", prefix, id);
- goto done;
+ clicon_err(OE_YANG, ENOENT, "Extension \"%s:%s\" not found", prefix, id);
+ goto done;
}
/* Optional argument (only if "argument") - save it in ys_cv */
if ((cv = yang_cv_get(ys)) != NULL &&
- (argument = cv_string_get(cv)) != NULL){
- if (yang_find(yext, Y_ARGUMENT, NULL) == NULL &&
- argument != NULL){
- clicon_err(OE_YANG, 0, "No argument specified in extension %s, but argument %s present when used", yang_argument_get(ys), argument);
- goto done;
- }
+ (argument = cv_string_get(cv)) != NULL){
+ if (yang_find(yext, Y_ARGUMENT, NULL) == NULL &&
+ argument != NULL){
+ clicon_err(OE_YANG, 0, "No argument specified in extension %s, but argument %s present when used", yang_argument_get(ys), argument);
+ goto done;
+ }
}
#ifdef XML_EXPLICIT_INDEX
/* Add explicit index extension */
if ((retval = yang_search_index_extension(h, yext, ys)) < 0) {
- clicon_debug(1, "plugin_extension() failed");
- return -1;
+ clicon_debug(1, "plugin_extension() failed");
+ return -1;
}
#endif
/* Make extension callbacks that may alter yang structure
@@ -2648,13 +2648,13 @@ ys_populate_unknown(clicon_handle h,
* at yang parse time
*/
if (clixon_plugin_extension_all(h, yext, ys) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (prefix)
- free(prefix);
+ free(prefix);
if (id)
- free(id);
+ free(id);
return retval;
}
@@ -2667,7 +2667,7 @@ ys_populate_unknown(clicon_handle h,
*/
static int
ys_populate_module_submodule(clicon_handle h,
- yang_stmt *ym)
+ yang_stmt *ym)
{
int retval = -1;
yang_stmt *yp;
@@ -2679,31 +2679,31 @@ ys_populate_module_submodule(clicon_handle h,
/* Modules but not submodules have prefixes */
if ((yp = yang_find(ym, Y_PREFIX, NULL)) != NULL)
- p0 = yang_argument_get(yp);
+ p0 = yang_argument_get(yp);
yi = NULL;
while ((yi = yn_each(ym, yi)) != NULL) {
- if (yang_keyword_get(yi) != Y_IMPORT)
- continue;
- yp = yang_find(yi, Y_PREFIX, NULL);
- pi = yang_argument_get(yp);
- if (p0 && strcmp(p0, pi) == 0){ /* Check top-level */
- clicon_err(OE_YANG, EFAULT, "Prefix %s in module %s is not unique but should be (see RFC 7950 7.1.4)",
- pi, yang_argument_get(ym));
- goto done;
- }
- /* Check rest of imports */
- yi2 = yi;
- while ((yi2 = yn_each(ym, yi2)) != NULL) {
- if (yang_keyword_get(yi2) != Y_IMPORT)
- continue;
- yp = yang_find(yi2, Y_PREFIX, NULL);
- pi2 = yang_argument_get(yp);
- if (strcmp(pi2, pi) == 0){
- clicon_err(OE_YANG, EFAULT, "Prefix %s in module %s is not unique but should be (see RFC 7950 7.1.4)",
- pi, yang_argument_get(ym));
- goto done;
- }
- }
+ if (yang_keyword_get(yi) != Y_IMPORT)
+ continue;
+ yp = yang_find(yi, Y_PREFIX, NULL);
+ pi = yang_argument_get(yp);
+ if (p0 && strcmp(p0, pi) == 0){ /* Check top-level */
+ clicon_err(OE_YANG, EFAULT, "Prefix %s in module %s is not unique but should be (see RFC 7950 7.1.4)",
+ pi, yang_argument_get(ym));
+ goto done;
+ }
+ /* Check rest of imports */
+ yi2 = yi;
+ while ((yi2 = yn_each(ym, yi2)) != NULL) {
+ if (yang_keyword_get(yi2) != Y_IMPORT)
+ continue;
+ yp = yang_find(yi2, Y_PREFIX, NULL);
+ pi2 = yang_argument_get(yp);
+ if (strcmp(pi2, pi) == 0){
+ clicon_err(OE_YANG, EFAULT, "Prefix %s in module %s is not unique but should be (see RFC 7950 7.1.4)",
+ pi, yang_argument_get(ym));
+ goto done;
+ }
+ }
}
retval = 0;
done:
@@ -2725,47 +2725,47 @@ ys_populate_module_submodule(clicon_handle h,
*/
int
ys_populate(yang_stmt *ys,
- void *arg)
+ void *arg)
{
int retval = -1;
clicon_handle h = (clicon_handle)arg;
switch(ys->ys_keyword){
case Y_IDENTITY:
- if (ys_populate_identity(h, ys, NULL) < 0)
- goto done;
- break;
+ if (ys_populate_identity(h, ys, NULL) < 0)
+ goto done;
+ break;
case Y_LENGTH:
- if (ys_populate_length(h, ys) < 0)
- goto done;
- break;
+ if (ys_populate_length(h, ys) < 0)
+ goto done;
+ break;
case Y_LIST:
- if (ys_populate_list(h, ys) < 0)
- goto done;
- break;
+ if (ys_populate_list(h, ys) < 0)
+ goto done;
+ break;
case Y_MODULE:
case Y_SUBMODULE:
- if (ys_populate_module_submodule(h, ys) < 0)
- goto done;
- break;
+ if (ys_populate_module_submodule(h, ys) < 0)
+ goto done;
+ break;
case Y_RANGE:
- if (ys_populate_range(h, ys) < 0)
- goto done;
- break;
+ if (ys_populate_range(h, ys) < 0)
+ goto done;
+ break;
case Y_TYPE:
- if (ys_populate_type(h, ys) < 0)
- goto done;
- break;
+ if (ys_populate_type(h, ys) < 0)
+ goto done;
+ break;
case Y_UNIQUE:
- if (ys_populate_unique(h, ys) < 0)
- goto done;
- break;
+ if (ys_populate_unique(h, ys) < 0)
+ goto done;
+ break;
case Y_UNKNOWN:
- if (ys_populate_unknown(h, ys) < 0)
- goto done;
- break;
+ if (ys_populate_unknown(h, ys) < 0)
+ goto done;
+ break;
default:
- break;
+ break;
}
retval = 0;
done:
@@ -2777,7 +2777,7 @@ ys_populate(yang_stmt *ys,
*/
int
ys_populate2(yang_stmt *ys,
- void *arg)
+ void *arg)
{
int retval = -1;
clicon_handle h = (clicon_handle)arg;
@@ -2785,17 +2785,17 @@ ys_populate2(yang_stmt *ys,
switch(ys->ys_keyword){
case Y_LEAF:
case Y_LEAF_LIST:
- if (ys_populate_leaf(h, ys) < 0)
- goto done;
- break;
+ if (ys_populate_leaf(h, ys) < 0)
+ goto done;
+ break;
case Y_MANDATORY: /* call yang_mandatory() to check if set */
case Y_CONFIG:
case Y_REQUIRE_INSTANCE:
- if (ys_parse(ys, CGV_BOOL) == NULL)
- goto done;
- break;
+ if (ys_parse(ys, CGV_BOOL) == NULL)
+ goto done;
+ break;
default:
- break;
+ break;
}
retval = 0;
done:
@@ -2814,7 +2814,7 @@ ys_populate2(yang_stmt *ys,
*/
int
yang_features(clicon_handle h,
- yang_stmt *yt)
+ yang_stmt *yt)
{
int retval = -1;
int i;
@@ -2826,48 +2826,48 @@ yang_features(clicon_handle h,
i = 0;
while (iys_len){
- ys = yt->ys_stmt[i];
- if (ys->ys_keyword == Y_IF_FEATURE){
- /* Parse the if-feature-expr string using yang sub-parser */
- if ((ymod = ys_module(ys)) != NULL)
- mainfile = yang_filename_get(ymod);
- ret = 0;
- if (yang_subparse(yang_argument_get(ys), ys, YA_IF_FEATURE, mainfile, 1, &ret) < 0)
- goto done;
- clicon_debug(1, "%s %s %d", __FUNCTION__, yang_argument_get(ys), ret);
- if (ret == 0)
- goto disabled;
- }
- else if (ys->ys_keyword == Y_FEATURE){
- if (ys_populate_feature(h, ys) < 0)
- goto done;
- }
- else
- switch (yang_features(h, ys)){
- case -1: /* error */
- goto done;
- break;
- case 0: /* disabled: remove ys */
- /* Change datanodes YANG to ANYDATA, other nodes are removed
- */
- if (yang_datanode(ys) && yang_config_ancestor(ys)){
- ys->ys_keyword = Y_ANYDATA;
- ys_freechildren(ys);
- ys->ys_len = 0;
- yang_flag_set(ys, YANG_FLAG_DISABLED);
- break;
- }
- for (j=i+1; jys_len; j++)
- yt->ys_stmt[j-1] = yt->ys_stmt[j];
- yt->ys_len--;
- yt->ys_stmt[yt->ys_len] = NULL;
- ys_free(ys);
- continue; /* Don't increment i */
- break;
- default: /* ok */
- break;
- }
- i++;
+ ys = yt->ys_stmt[i];
+ if (ys->ys_keyword == Y_IF_FEATURE){
+ /* Parse the if-feature-expr string using yang sub-parser */
+ if ((ymod = ys_module(ys)) != NULL)
+ mainfile = yang_filename_get(ymod);
+ ret = 0;
+ if (yang_subparse(yang_argument_get(ys), ys, YA_IF_FEATURE, mainfile, 1, &ret) < 0)
+ goto done;
+ clicon_debug(1, "%s %s %d", __FUNCTION__, yang_argument_get(ys), ret);
+ if (ret == 0)
+ goto disabled;
+ }
+ else if (ys->ys_keyword == Y_FEATURE){
+ if (ys_populate_feature(h, ys) < 0)
+ goto done;
+ }
+ else
+ switch (yang_features(h, ys)){
+ case -1: /* error */
+ goto done;
+ break;
+ case 0: /* disabled: remove ys */
+ /* Change datanodes YANG to ANYDATA, other nodes are removed
+ */
+ if (yang_datanode(ys) && yang_config_ancestor(ys)){
+ ys->ys_keyword = Y_ANYDATA;
+ ys_freechildren(ys);
+ ys->ys_len = 0;
+ yang_flag_set(ys, YANG_FLAG_DISABLED);
+ break;
+ }
+ for (j=i+1; jys_len; j++)
+ yt->ys_stmt[j-1] = yt->ys_stmt[j];
+ yt->ys_len--;
+ yt->ys_stmt[yt->ys_len] = NULL;
+ ys_free(ys);
+ continue; /* Don't increment i */
+ break;
+ default: /* ok */
+ break;
+ }
+ i++;
}
retval = 1;
done:
@@ -2903,10 +2903,10 @@ yang_features(clicon_handle h,
*/
int
yang_apply(yang_stmt *yn,
- enum rfc_6020 keyword,
- yang_applyfn_t fn,
- int depth,
- void *arg)
+ enum rfc_6020 keyword,
+ yang_applyfn_t fn,
+ int depth,
+ void *arg)
{
int retval = -1;
yang_stmt *ys = NULL;
@@ -2914,23 +2914,23 @@ yang_apply(yang_stmt *yn,
int ret;
if (depth <= 0){
- if ((int)keyword == -1 || keyword == yn->ys_keyword){
- if ((ret = fn(yn, arg)) < 0)
- goto done;
- if (ret > 0){
- retval = ret;
- goto done;
- }
- }
+ if ((int)keyword == -1 || keyword == yn->ys_keyword){
+ if ((ret = fn(yn, arg)) < 0)
+ goto done;
+ if (ret > 0){
+ retval = ret;
+ goto done;
+ }
+ }
}
for (i=0; iys_len; i++){
- ys = yn->ys_stmt[i];
- if ((ret = yang_apply(ys, keyword, fn, depth-1, arg)) < 0)
- goto done;
- if (ret > 0){
- retval = ret;
- goto done;
- }
+ ys = yn->ys_stmt[i];
+ if ((ret = yang_apply(ys, keyword, fn, depth-1, arg)) < 0)
+ goto done;
+ if (ret > 0){
+ retval = ret;
+ goto done;
+ }
}
retval = 0;
done:
@@ -2953,11 +2953,11 @@ yang_datanode(yang_stmt *ys)
keyw = yang_keyword_get(ys);
return (keyw == Y_CONTAINER ||
- keyw == Y_LEAF ||
- keyw == Y_LIST ||
- keyw == Y_LEAF_LIST ||
- keyw == Y_ANYXML ||
- keyw == Y_ANYDATA);
+ keyw == Y_LEAF ||
+ keyw == Y_LIST ||
+ keyw == Y_LEAF_LIST ||
+ keyw == Y_ANYXML ||
+ keyw == Y_ANYDATA);
}
/*! All the work for schema_nodeid functions both absolute and descendant
@@ -2980,10 +2980,10 @@ yang_datanode(yang_stmt *ys)
*/
static int
schema_nodeid_iterate(yang_stmt *yn,
- yang_stmt *yspec,
- cvec *nodeid_cvv,
- cvec *nsc,
- yang_stmt **yres)
+ yang_stmt *yspec,
+ cvec *nodeid_cvv,
+ cvec *nsc,
+ yang_stmt **yres)
{
int retval = -1;
yang_stmt *ymod;
@@ -2998,45 +2998,45 @@ schema_nodeid_iterate(yang_stmt *yn,
/* Iterate over node identifiers /prefix:id/... */
cv = NULL;
while ((cv = cvec_each(nodeid_cvv, cv)) != NULL){
- prefix = cv_name_get(cv);
- id = cv_string_get(cv);
- /* Top level is repeated from abs case, but here this is done to match with
- * matching module below
- * Get namespace */
- if ((ns = xml_nsctx_get(nsc, prefix)) == NULL){
- clicon_err(OE_YANG, EFAULT, "No namespace for prefix: %s in schema node identifier in module %s",
- prefix,
- yang_argument_get(ys_module(yn)));
- goto done;
- }
- /* Get yang module */
- if ((ymod = yang_find_module_by_namespace(yspec, ns)) == NULL){
- clicon_err(OE_YANG, EFAULT, "No module for namespace: %s", ns);
- goto done;
- }
- ys = yang_find_schemanode(yp, id);
- /* Special case: if rpc/action, an empty input/output may need to be created, it is optional but may
- * still be referenced.
- * XXX: maybe input/output should always be created when rpc/action is created?
- */
- if (ys == NULL &&
- (yang_keyword_get(yp) == Y_RPC || yang_keyword_get(yp) == Y_ACTION) &&
- (strcmp(id, "input") == 0 || strcmp(id, "output") == 0)){
- enum rfc_6020 kw;
- kw = clicon_str2int(ykmap, id);
- /* Add ys as id to yp */
- if ((ys = ys_new(kw)) == NULL)
- goto done;
- if (yn_insert(yp, ys) < 0) /* Insert into hierarchy */
- goto done;
- }
- if (ys == NULL){
- clicon_debug(1, "%s: %s not found, last id found:%s",
- __FUNCTION__, id, yang_argument_get(yp));
- goto ok;
- }
- yp = ys; /* ys is matched */
- ys = NULL;
+ prefix = cv_name_get(cv);
+ id = cv_string_get(cv);
+ /* Top level is repeated from abs case, but here this is done to match with
+ * matching module below
+ * Get namespace */
+ if ((ns = xml_nsctx_get(nsc, prefix)) == NULL){
+ clicon_err(OE_YANG, EFAULT, "No namespace for prefix: %s in schema node identifier in module %s",
+ prefix,
+ yang_argument_get(ys_module(yn)));
+ goto done;
+ }
+ /* Get yang module */
+ if ((ymod = yang_find_module_by_namespace(yspec, ns)) == NULL){
+ clicon_err(OE_YANG, EFAULT, "No module for namespace: %s", ns);
+ goto done;
+ }
+ ys = yang_find_schemanode(yp, id);
+ /* Special case: if rpc/action, an empty input/output may need to be created, it is optional but may
+ * still be referenced.
+ * XXX: maybe input/output should always be created when rpc/action is created?
+ */
+ if (ys == NULL &&
+ (yang_keyword_get(yp) == Y_RPC || yang_keyword_get(yp) == Y_ACTION) &&
+ (strcmp(id, "input") == 0 || strcmp(id, "output") == 0)){
+ enum rfc_6020 kw;
+ kw = clicon_str2int(ykmap, id);
+ /* Add ys as id to yp */
+ if ((ys = ys_new(kw)) == NULL)
+ goto done;
+ if (yn_insert(yp, ys) < 0) /* Insert into hierarchy */
+ goto done;
+ }
+ if (ys == NULL){
+ clicon_debug(1, "%s: %s not found, last id found:%s",
+ __FUNCTION__, id, yang_argument_get(yp));
+ goto ok;
+ }
+ yp = ys; /* ys is matched */
+ ys = NULL;
} /* while cv */
assert(yp && yang_schemanode((yang_stmt*)yp));
*yres = (yang_stmt*)yp;
@@ -3062,8 +3062,8 @@ schema_nodeid_iterate(yang_stmt *yn,
*/
int
yang_abs_schema_nodeid(yang_stmt *yn,
- char *schema_nodeid,
- yang_stmt **yres)
+ char *schema_nodeid,
+ yang_stmt **yres)
{
int retval = -1;
cvec *nodeid_cvv = NULL;
@@ -3076,66 +3076,66 @@ yang_abs_schema_nodeid(yang_stmt *yn,
char *str;
if ((yspec = ys_spec(yn)) == NULL){
- clicon_err(OE_YANG, EINVAL, "No yang spec");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "No yang spec");
+ goto done;
}
*yres = NULL;
/* check absolute schema_nodeid */
if (schema_nodeid[0] != '/'){
- clicon_err(OE_YANG, EINVAL, "absolute schema nodeid should start with /");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "absolute schema nodeid should start with /");
+ goto done;
}
/* Split nodeid on the form /p0:i0/p1:i1 to a cvec with [name:p0 value:i0][...]
*/
if (uri_str2cvec(schema_nodeid, '/', ':', 1, &nodeid_cvv) < 0)
- goto done;
+ goto done;
if (cvec_len(nodeid_cvv) == 0)
- goto ok;
+ goto ok;
/* If p0 is NULL an entry will be: [i0] which needs to be transformed to [NULL:i0] */
cv = NULL;
while ((cv = cvec_each(nodeid_cvv, cv)) != NULL){
- if (cv_type_get(cv) != CGV_STRING)
+ if (cv_type_get(cv) != CGV_STRING)
cv_type_set(cv, CGV_STRING);
- if ((str = cv_string_get(cv)) == NULL || !strlen(str)){
- if (cv_string_set(cv, cv_name_get(cv)) < 0){
- clicon_err(OE_UNIX, errno, "cv_string_set");
- goto done;
- }
- cv_name_set(cv, NULL);
- }
+ if ((str = cv_string_get(cv)) == NULL || !strlen(str)){
+ if (cv_string_set(cv, cv_name_get(cv)) < 0){
+ clicon_err(OE_UNIX, errno, "cv_string_set");
+ goto done;
+ }
+ cv_name_set(cv, NULL);
+ }
}
/* Make a namespace context from yang for the prefixes (names) of nodeid_cvv */
if (yang_keyword_get(yn) == Y_SPEC){
- if (xml_nsctx_yangspec(yn, &nsc) < 0)
- goto done;
+ if (xml_nsctx_yangspec(yn, &nsc) < 0)
+ goto done;
}
else if (xml_nsctx_yang(yn, &nsc) < 0)
- goto done;
+ goto done;
/* Since this is an _absolute_ schema nodeid start from top
* Get namespace */
cv = cvec_i(nodeid_cvv, 0);
prefix = cv_name_get(cv);
if ((ns = xml_nsctx_get(nsc, prefix)) == NULL){
- clicon_err(OE_YANG, EFAULT, "No namespace for prefix: %s in schema node identifier: %s",
- prefix, schema_nodeid);
- goto done;
+ clicon_err(OE_YANG, EFAULT, "No namespace for prefix: %s in schema node identifier: %s",
+ prefix, schema_nodeid);
+ goto done;
}
/* Get yang module */
if ((ymod = yang_find_module_by_namespace(yspec, ns)) == NULL){
- clicon_err(OE_YANG, EFAULT, "No module for namespace: %s in schema node identifier: %s",
- ns, schema_nodeid);
- goto done;
+ clicon_err(OE_YANG, EFAULT, "No module for namespace: %s in schema node identifier: %s",
+ ns, schema_nodeid);
+ goto done;
}
/* Iterate through cvv to find schemanode using ymod as starting point (since it is absolute) */
if (schema_nodeid_iterate(ymod, yspec, nodeid_cvv, nsc, yres) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
if (nodeid_cvv)
- cvec_free(nodeid_cvv);
+ cvec_free(nodeid_cvv);
if (nsc)
- cvec_free(nsc);
+ cvec_free(nsc);
return retval;
}
@@ -3152,8 +3152,8 @@ yang_abs_schema_nodeid(yang_stmt *yn,
*/
int
yang_desc_schema_nodeid(yang_stmt *yn,
- char *schema_nodeid,
- yang_stmt **yres)
+ char *schema_nodeid,
+ yang_stmt **yres)
{
int retval = -1;
cvec *nodeid_cvv = NULL;
@@ -3163,115 +3163,56 @@ yang_desc_schema_nodeid(yang_stmt *yn,
cvec *nsc = NULL;
if (schema_nodeid == NULL || strlen(schema_nodeid) == 0){
- clicon_err(OE_YANG, EINVAL, "nodeid is empty");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "nodeid is empty");
+ goto done;
}
if ((yspec = ys_spec(yn)) == NULL){
- clicon_err(OE_YANG, EINVAL, "No yang spec");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "No yang spec");
+ goto done;
}
*yres = NULL;
/* check absolute schema_nodeid */
if (schema_nodeid[0] == '/'){
- clicon_err(OE_YANG, EINVAL, "descendant schema nodeid should not start with /");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "descendant schema nodeid should not start with /");
+ goto done;
}
/* Split nodeid on the form /p0:i0/p1:i1 to a cvec with [name:p0 value:i0][...]
*/
if (uri_str2cvec(schema_nodeid, '/', ':', 1, &nodeid_cvv) < 0)
- goto done;
+ goto done;
if (cvec_len(nodeid_cvv) == 0)
- goto ok;
+ goto ok;
/* If p0 is NULL an entry will be: [i0] which needs to be transformed to [NULL:i0] */
cv = NULL;
while ((cv = cvec_each(nodeid_cvv, cv)) != NULL){
- if (cv_type_get(cv) != CGV_STRING)
- cv_type_set(cv, CGV_STRING);
- if ((str = cv_string_get(cv)) == NULL || !strlen(str)){
- if (cv_string_set(cv, cv_name_get(cv)) < 0){
- clicon_err(OE_UNIX, errno, "cv_string_set");
- goto done;
- }
- cv_name_set(cv, NULL);
- }
+ if (cv_type_get(cv) != CGV_STRING)
+ cv_type_set(cv, CGV_STRING);
+ if ((str = cv_string_get(cv)) == NULL || !strlen(str)){
+ if (cv_string_set(cv, cv_name_get(cv)) < 0){
+ clicon_err(OE_UNIX, errno, "cv_string_set");
+ goto done;
+ }
+ cv_name_set(cv, NULL);
+ }
}
/* Make a namespace context from yang for the prefixes (names) of nodeid_cvv
* Requires yn exist in hierarchy
*/
if (xml_nsctx_yang(yn, &nsc) < 0)
- goto done;
+ goto done;
/* Iterate through cvv to find schemanode using yn as relative starting point */
if (schema_nodeid_iterate(yn, yspec, nodeid_cvv, nsc, yres) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
if (nsc)
- cvec_free(nsc);
+ cvec_free(nsc);
if (nodeid_cvv)
- cvec_free(nodeid_cvv);
+ cvec_free(nodeid_cvv);
return retval;
}
-/*! Check if this leaf is mandatory or not
- * Note: one can cache this value in ys_cvec instead of functionally evaluating it.
- * @retval 1 yang statement is leaf and it has a mandatory sub-stmt with value true
- * @retval 0 The negation of conditions for return value 1.
- * @see RFC7950 Sec 3:
- * o mandatory node: A mandatory node is one of:
- * 1) A leaf, choice, anydata, or anyxml node with a "mandatory"
- * statement with the value "true".
- * 2) # see below
- * 3) A container node without a "presence" statement and that has at
- * least one mandatory node as a child.
- *
- * @note There is also this statement
- * 2) A list or leaf-list node with a "min-elements" statement with a
- * value greater than zero.
- * which we ignore here since:
- * (a) it does not consider the XML siblings and therefore returns false positives
- * (b) where the actual check is catched by check_list_unique_minmax()
- */
-int
-yang_mandatory(yang_stmt *ys)
-{
- yang_stmt *ym;
- cg_var *cv;
-
- /* 1) A leaf, choice, anydata, or anyxml node with a "mandatory"
- * statement with the value "true". */
- if (ys->ys_keyword == Y_LEAF || ys->ys_keyword == Y_CHOICE ||
- ys->ys_keyword == Y_ANYDATA || ys->ys_keyword == Y_ANYXML){
- if ((ym = yang_find(ys, Y_MANDATORY, NULL)) != NULL){
- if ((cv = yang_cv_get(ym)) != NULL) /* shouldnt happen */
- return cv_bool_get(cv);
- }
- }
-#if 0 /* See note above */
- /* 2) A list or leaf-list node with a "min-elements" statement with a
- * value greater than zero. */
- else if (ys->ys_keyword == Y_LIST || ys->ys_keyword == Y_LEAF_LIST){
- if ((ym = yang_find(ys, Y_MIN_ELEMENTS, NULL)) != NULL){
- cv = yang_cv_get(ym);
- return cv_uint32_get(cv) > 0; /* Not true if XML considered */
- }
- }
-#endif
- /* 3) A container node without a "presence" statement and that has at
- * least one mandatory node as a child. */
- else if (ys->ys_keyword == Y_CONTAINER &&
- yang_find(ys, Y_PRESENCE, NULL) == NULL){
- yang_stmt *yc;
- int i;
- for (i=0; iys_len; i++){
- yc = ys->ys_stmt[i];
- if (yang_mandatory(yc))
- return 1;
- }
- }
- return 0;
-}
-
/*! Return config state of this node
* @param[in] ys Yang statement
* @retval 0 If node has a config sub-statement and it is false
@@ -3284,9 +3225,9 @@ yang_config(yang_stmt *ys)
yang_stmt *ym;
if ((ym = yang_find(ys, Y_CONFIG, NULL)) != NULL){
- if (yang_cv_get(ym) == NULL) /* shouldnt happen */
- return 1;
- return cv_bool_get(yang_cv_get(ym));
+ if (yang_cv_get(ym) == NULL) /* shouldnt happen */
+ return 1;
+ return cv_bool_get(yang_cv_get(ym));
}
return 1;
}
@@ -3306,23 +3247,23 @@ yang_config_ancestor(yang_stmt *ys)
yp = ys;
do {
#ifdef USE_CONFIG_FLAG_CACHE
- if (yang_flag_get(yp, YANG_FLAG_CONFIG_CACHE))
- return yang_flag_get(yp, YANG_FLAG_CONFIG_VALUE)?1:0;
+ if (yang_flag_get(yp, YANG_FLAG_CONFIG_CACHE))
+ return yang_flag_get(yp, YANG_FLAG_CONFIG_VALUE)?1:0;
#endif
- if (yang_config(yp) == 0){
+ if (yang_config(yp) == 0){
#ifdef USE_CONFIG_FLAG_CACHE
- yang_flag_set(yp, YANG_FLAG_CONFIG_CACHE);
- yang_flag_reset(yp, YANG_FLAG_CONFIG_VALUE);
+ yang_flag_set(yp, YANG_FLAG_CONFIG_CACHE);
+ yang_flag_reset(yp, YANG_FLAG_CONFIG_VALUE);
#endif
- return 0;
- }
- if (yang_keyword_get(yp) == Y_INPUT || yang_keyword_get(yp) == Y_OUTPUT || yang_keyword_get(yp) == Y_NOTIFICATION){
+ return 0;
+ }
+ if (yang_keyword_get(yp) == Y_INPUT || yang_keyword_get(yp) == Y_OUTPUT || yang_keyword_get(yp) == Y_NOTIFICATION){
#ifdef USE_CONFIG_FLAG_CACHE
- yang_flag_set(yp, YANG_FLAG_CONFIG_CACHE);
- yang_flag_reset(yp, YANG_FLAG_CONFIG_VALUE);
+ yang_flag_set(yp, YANG_FLAG_CONFIG_CACHE);
+ yang_flag_reset(yp, YANG_FLAG_CONFIG_VALUE);
#endif
- return 0;
- }
+ return 0;
+ }
} while((yp = yang_parent_get(yp)) != NULL);
#ifdef USE_CONFIG_FLAG_CACHE
yang_flag_set(ys, YANG_FLAG_CONFIG_CACHE);
@@ -3350,7 +3291,7 @@ yang_config_ancestor(yang_stmt *ys)
*/
cvec *
yang_arg2cvec(yang_stmt *ys,
- char *delim)
+ char *delim)
{
char **vec = NULL;
int i;
@@ -3359,23 +3300,23 @@ yang_arg2cvec(yang_stmt *ys,
cg_var *cv;
if ((vec = clicon_strsep(ys->ys_argument, " ", &nvec)) == NULL)
- goto done;
+ goto done;
if ((cvv = cvec_new(nvec)) == NULL){
- clicon_err(OE_YANG, errno, "cvec_new");
- goto done;
+ clicon_err(OE_YANG, errno, "cvec_new");
+ goto done;
}
for (i = 0; i < nvec; i++) {
- cv = cvec_i(cvv, i);
- cv_type_set(cv, CGV_STRING);
- if ((cv_string_set(cv, vec[i])) == NULL){
- clicon_err(OE_YANG, errno, "cv_string_set");
- cvv = NULL;
- goto done;
- }
+ cv = cvec_i(cvv, i);
+ cv_type_set(cv, CGV_STRING);
+ if ((cv_string_set(cv, vec[i])) == NULL){
+ clicon_err(OE_YANG, errno, "cv_string_set");
+ cvv = NULL;
+ goto done;
+ }
}
done:
if (vec)
- free(vec);
+ free(vec);
return cvv;
}
@@ -3393,8 +3334,8 @@ yang_arg2cvec(yang_stmt *ys,
*/
int
yang_key_match(yang_stmt *yn,
- char *name,
- int *lastkey)
+ char *name,
+ int *lastkey)
{
int retval = -1;
yang_stmt *ys = NULL;
@@ -3404,29 +3345,29 @@ yang_key_match(yang_stmt *yn,
cg_var *cv;
for (i=0; iys_len; i++){
- ys = yn->ys_stmt[i];
- if (ys->ys_keyword == Y_KEY){
- if ((cvv = yang_arg2cvec(ys, " ")) == NULL)
- goto done;
- j = 0;
- cv = NULL;
- while ((cv = cvec_each(cvv, cv)) != NULL) {
- j++;
- if (strcmp(name, cv_string_get(cv)) == 0){
- if (j == cvec_len(cvv) && lastkey)
- *lastkey = 1;
- retval = 1; /* match */
- goto done;
- }
- }
- cvec_free(cvv);
- cvv = NULL;
- }
+ ys = yn->ys_stmt[i];
+ if (ys->ys_keyword == Y_KEY){
+ if ((cvv = yang_arg2cvec(ys, " ")) == NULL)
+ goto done;
+ j = 0;
+ cv = NULL;
+ while ((cv = cvec_each(cvv, cv)) != NULL) {
+ j++;
+ if (strcmp(name, cv_string_get(cv)) == 0){
+ if (j == cvec_len(cvv) && lastkey)
+ *lastkey = 1;
+ retval = 1; /* match */
+ goto done;
+ }
+ }
+ cvec_free(cvv);
+ cvv = NULL;
+ }
}
retval = 0;
done:
if (cvv)
- cvec_free(cvv);
+ cvec_free(cvv);
return retval;
}
@@ -3436,36 +3377,36 @@ yang_key_match(yang_stmt *yn,
*/
int
yang_type_cache_set(yang_stmt *ys,
- yang_stmt *resolved,
- int options,
- cvec *cvv,
- cvec *patterns,
- uint8_t fraction)
+ yang_stmt *resolved,
+ int options,
+ cvec *cvv,
+ cvec *patterns,
+ uint8_t fraction)
{
int retval = -1;
yang_type_cache *ycache;
if (ys->ys_typecache != NULL){
- clicon_err(OE_YANG, EEXIST, "yang type cache");
- goto done;
+ clicon_err(OE_YANG, EEXIST, "yang type cache");
+ goto done;
}
if ((ys->ys_typecache = (yang_type_cache *)malloc(sizeof(*ycache))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
ycache = ys->ys_typecache;
memset(ycache, 0, sizeof(*ycache));
ycache->yc_resolved = resolved;
ycache->yc_options = options;
if (cvv){
- if ((ycache->yc_cvv = cvec_dup(cvv)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_dup");
- goto done;
- }
+ if ((ycache->yc_cvv = cvec_dup(cvv)) == NULL){
+ clicon_err(OE_UNIX, errno, "cvec_dup");
+ goto done;
+ }
}
if (patterns && (ycache->yc_patterns = cvec_dup(patterns)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_dup");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_dup");
+ goto done;
}
ycache->yc_fraction = fraction;
retval = 0;
@@ -3479,8 +3420,8 @@ yang_type_cache_set(yang_stmt *ys,
*/
int
yang_type_cache_regexp_set(yang_stmt *ytype,
- int rxmode,
- cvec *regexps)
+ int rxmode,
+ cvec *regexps)
{
int retval = -1;
yang_type_cache *ycache;
@@ -3491,8 +3432,8 @@ yang_type_cache_regexp_set(yang_stmt *ytype,
assert(ycache->yc_regexps == NULL);
ycache->yc_rxmode = rxmode;
if ((ycache->yc_regexps = cvec_dup(regexps)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_dup");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_dup");
+ goto done;
}
retval = 0;
done:
@@ -3507,13 +3448,13 @@ yang_type_cache_regexp_set(yang_stmt *ytype,
*/
int
yang_type_cache_get(yang_stmt *ytype,
- yang_stmt **resolved,
- int *options,
- cvec **cvv,
- cvec *patterns,
- int *rxmode,
- cvec *regexps,
- uint8_t *fraction)
+ yang_stmt **resolved,
+ int *options,
+ cvec **cvv,
+ cvec *patterns,
+ int *rxmode,
+ cvec *regexps,
+ uint8_t *fraction)
{
int retval = -1;
cg_var *cv = NULL;
@@ -3521,29 +3462,29 @@ yang_type_cache_get(yang_stmt *ytype,
ycache = ytype->ys_typecache;
if (ycache == NULL){ /* No cache return 0 */
- retval = 0;
- goto done;
+ retval = 0;
+ goto done;
}
if (resolved)
- *resolved = ycache->yc_resolved;
+ *resolved = ycache->yc_resolved;
if (options)
- *options = ycache->yc_options;
+ *options = ycache->yc_options;
if (cvv)
- *cvv = ycache->yc_cvv;
+ *cvv = ycache->yc_cvv;
if (patterns){
- cv = NULL;
- while ((cv = cvec_each(ycache->yc_patterns, cv)) != NULL)
- cvec_append_var(patterns, cv);
+ cv = NULL;
+ while ((cv = cvec_each(ycache->yc_patterns, cv)) != NULL)
+ cvec_append_var(patterns, cv);
}
if (regexps){
- cv = NULL;
- while ((cv = cvec_each(ycache->yc_regexps, cv)) != NULL)
- cvec_append_var(regexps, cv);
+ cv = NULL;
+ while ((cv = cvec_each(ycache->yc_regexps, cv)) != NULL)
+ cvec_append_var(regexps, cv);
}
if (rxmode)
- *rxmode = ycache->yc_rxmode;
+ *rxmode = ycache->yc_rxmode;
if (fraction)
- *fraction = ycache->yc_fraction;
+ *fraction = ycache->yc_fraction;
retval = 1; /* cache exists and is returned OK */
done:
return retval;
@@ -3553,7 +3494,7 @@ yang_type_cache_get(yang_stmt *ytype,
*/
static int
yang_type_cache_cp(yang_stmt *ynew,
- yang_stmt *yold)
+ yang_stmt *yold)
{
int retval = -1;
int options;
@@ -3564,22 +3505,22 @@ yang_type_cache_cp(yang_stmt *ynew,
int ret;
if ((patterns = cvec_new(0)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ goto done;
}
/* Note, regexps are not copied since they are voids, if they were, they
* could not be freed in a simple way since copies are made at augment/group
*/
if ((ret = yang_type_cache_get(yold,
- &resolved, &options, &cvv, patterns, NULL, NULL, &fraction)) < 0)
- goto done;
+ &resolved, &options, &cvv, patterns, NULL, NULL, &fraction)) < 0)
+ goto done;
if (ret == 1 &&
- yang_type_cache_set(ynew, resolved, options, cvv, patterns, fraction) < 0)
- goto done;
+ yang_type_cache_set(ynew, resolved, options, cvv, patterns, fraction) < 0)
+ goto done;
retval = 0;
done:
if (patterns)
- cvec_free(patterns);
+ cvec_free(patterns);
return retval;
}
@@ -3592,34 +3533,34 @@ yang_type_cache_free(yang_type_cache *ycache)
void *p;
if (ycache->yc_cvv)
- cvec_free(ycache->yc_cvv);
+ cvec_free(ycache->yc_cvv);
if (ycache->yc_patterns)
- cvec_free(ycache->yc_patterns);
+ cvec_free(ycache->yc_patterns);
if (ycache->yc_regexps){
- cv = NULL;
- while ((cv = cvec_each(ycache->yc_regexps, cv)) != NULL){
- /* need to store mode since clicon_handle is not available */
- switch (ycache->yc_rxmode){
- case REGEXP_POSIX:
- cligen_regex_posix_free(cv_void_get(cv));
- if ((p = cv_void_get(cv)) != NULL){
- free(p);
- cv_void_set(cv, NULL);
- }
- break;
- case REGEXP_LIBXML2:
- cligen_regex_libxml2_free(cv_void_get(cv));
- /* Note, already freed in libxml2 case */
- if ((p = cv_void_get(cv)) != NULL){
- cv_void_set(cv, NULL);
- }
- break;
- default:
- break;
- }
+ cv = NULL;
+ while ((cv = cvec_each(ycache->yc_regexps, cv)) != NULL){
+ /* need to store mode since clicon_handle is not available */
+ switch (ycache->yc_rxmode){
+ case REGEXP_POSIX:
+ cligen_regex_posix_free(cv_void_get(cv));
+ if ((p = cv_void_get(cv)) != NULL){
+ free(p);
+ cv_void_set(cv, NULL);
+ }
+ break;
+ case REGEXP_LIBXML2:
+ cligen_regex_libxml2_free(cv_void_get(cv));
+ /* Note, already freed in libxml2 case */
+ if ((p = cv_void_get(cv)) != NULL){
+ cv_void_set(cv, NULL);
+ }
+ break;
+ default:
+ break;
+ }
- }
- cvec_free(ycache->yc_regexps);
+ }
+ cvec_free(ycache->yc_regexps);
}
free(ycache);
return 0;
@@ -3636,21 +3577,21 @@ yang_type_cache_free(yang_type_cache *ycache)
*/
yang_stmt *
yang_anydata_add(yang_stmt *yp,
- char *name0)
+ char *name0)
{
yang_stmt *ys = NULL;
char *name = NULL;
if ((ys = ys_new(Y_ANYDATA)) == NULL)
- goto done;
+ goto done;
if ((name = strdup(name0)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
yang_argument_set(ys, name);
if (yp && yn_insert(yp, ys) < 0){ /* Insert into hierarchy */
- ys = NULL;
- goto done;
+ ys = NULL;
+ goto done;
}
done:
return ys;
@@ -3679,10 +3620,10 @@ yang_anydata_add(yang_stmt *yp,
*/
int
yang_extension_value(yang_stmt *ys,
- char *name,
- char *ns,
- int *exist,
- char **value)
+ char *name,
+ char *ns,
+ int *exist,
+ char **value)
{
int retval = -1;
yang_stmt *yext;
@@ -3693,42 +3634,42 @@ yang_extension_value(yang_stmt *ys,
int ret;
if (ys == NULL){
- clicon_err(OE_YANG, EINVAL, "ys is NULL");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "ys is NULL");
+ goto done;
}
if (exist)
- *exist = 0;
+ *exist = 0;
if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
yext = NULL; /* This loop gets complicated in the case the extension is augmented */
while ((yext = yn_each(ys, yext)) != NULL) {
- if (yang_keyword_get(yext) != Y_UNKNOWN)
- continue;
- if ((ymod = ys_module(yext)) == NULL)
- continue;
- if ((ret = yang_find_prefix_by_namespace(ymod, ns, &prefix)) < 0)
- goto done;
- if (ret == 0) /* not found (this may happen in augment and maybe should be treated otherwise) */
- continue;
- cbuf_reset(cb);
- cprintf(cb, "%s:%s", prefix, name);
- if (strcmp(yang_argument_get(yext), cbuf_get(cb)) != 0)
- continue;
- break;
+ if (yang_keyword_get(yext) != Y_UNKNOWN)
+ continue;
+ if ((ymod = ys_module(yext)) == NULL)
+ continue;
+ if ((ret = yang_find_prefix_by_namespace(ymod, ns, &prefix)) < 0)
+ goto done;
+ if (ret == 0) /* not found (this may happen in augment and maybe should be treated otherwise) */
+ continue;
+ cbuf_reset(cb);
+ cprintf(cb, "%s:%s", prefix, name);
+ if (strcmp(yang_argument_get(yext), cbuf_get(cb)) != 0)
+ continue;
+ break;
}
if (yext != NULL){ /* Found */
- if (exist)
- *exist = 1;
- if (value &&
- (cv = yang_cv_get(yext)) != NULL)
- *value = cv_string_get(cv);
+ if (exist)
+ *exist = 1;
+ if (value &&
+ (cv = yang_cv_get(yext)) != NULL)
+ *value = cv_string_get(cv);
}
retval = 0;
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
return retval;
}
@@ -3736,7 +3677,7 @@ yang_extension_value(yang_stmt *ys,
/* Sort substatements with when:s last */
static int
yang_sort_subelements_fn(const void* arg1,
- const void* arg2)
+ const void* arg2)
{
yang_stmt *ys1 = *(yang_stmt **)arg1;
yang_stmt *ys2 = *(yang_stmt **)arg2;
@@ -3746,11 +3687,11 @@ yang_sort_subelements_fn(const void* arg1,
w1 = yang_find(ys1, Y_WHEN, NULL) != NULL;
w2 = yang_find(ys2, Y_WHEN, NULL) != NULL;
if (w1 == w2)
- return ys1->_ys_vector_i - ys2->_ys_vector_i;
+ return ys1->_ys_vector_i - ys2->_ys_vector_i;
else if (w1)
- return 1;
+ return 1;
else if (w2)
- return -1;
+ return -1;
else return ys1->_ys_vector_i - ys2->_ys_vector_i;
}
#endif
@@ -3770,12 +3711,12 @@ yang_sort_subelements(yang_stmt *ys)
#ifdef YANG_ORDERING_WHEN_LAST
if ((yang_keyword_get(ys) == Y_CONTAINER ||
- yang_keyword_get(ys) == Y_LIST)){
- yang_stmt *yc = NULL;
+ yang_keyword_get(ys) == Y_LIST)){
+ yang_stmt *yc = NULL;
- /* This enumerates _ys_vector_i in ys->ys_stmt vector */
- while ((yc = yn_each(ys, yc)) != NULL) ;
- qsort(ys->ys_stmt, ys->ys_len, sizeof(ys), yang_sort_subelements_fn);
+ /* This enumerates _ys_vector_i in ys->ys_stmt vector */
+ while ((yc = yn_each(ys, yc)) != NULL) ;
+ qsort(ys->ys_stmt, ys->ys_len, sizeof(ys), yang_sort_subelements_fn);
}
#endif
@@ -3802,9 +3743,9 @@ yang_list_index_add(yang_stmt *ys)
yang_stmt *yp;
if ((yp = yang_parent_get(ys)) == NULL ||
- yang_keyword_get(yp) != Y_LIST){
- clicon_log(LOG_WARNING, "search_index should in a list");
- goto ok;
+ yang_keyword_get(yp) != Y_LIST){
+ clicon_log(LOG_WARNING, "search_index should in a list");
+ goto ok;
}
yang_flag_set(ys, YANG_FLAG_INDEX);
ok:
@@ -3823,8 +3764,8 @@ yang_list_index_add(yang_stmt *ys)
*/
int
yang_search_index_extension(clicon_handle h,
- yang_stmt *yext,
- yang_stmt *ys)
+ yang_stmt *yext,
+ yang_stmt *ys)
{
int retval = -1;
char *extname;
@@ -3836,11 +3777,11 @@ yang_search_index_extension(clicon_handle h,
modname = yang_argument_get(ymod);
extname = yang_argument_get(yext);
if (strcmp(modname, "clixon-config") != 0 || strcmp(extname, "search_index") != 0)
- goto ok;
+ goto ok;
clicon_debug(1, "%s Enabled extension:%s:%s", __FUNCTION__, modname, extname);
yp = yang_parent_get(ys);
if (yang_list_index_add(yp) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
@@ -3864,7 +3805,7 @@ yang_search_index_extension(clicon_handle h,
*/
int
yang_single_child_type(yang_stmt *ys,
- enum rfc_6020 subkeyw)
+ enum rfc_6020 subkeyw)
{
yang_stmt *yc = NULL;
@@ -3874,27 +3815,27 @@ yang_single_child_type(yang_stmt *ys,
/* Match parent */
/* If container, check it is Non-presence */
if (yang_keyword_get(ys) == Y_CONTAINER){
- if (yang_find(ys, Y_PRESENCE, NULL) != NULL)
- return 0;
+ if (yang_find(ys, Y_PRESENCE, NULL) != NULL)
+ return 0;
}
/* Ensure a single list child and no other data nodes */
i = 0; /* Number of list nodes */
while ((yc = yn_each(ys, yc)) != NULL) {
- keyw = yang_keyword_get(yc);
- /* case/choice could hide anything so disqualify those */
- if (keyw == Y_CASE || keyw == Y_CHOICE)
- break;
- if (!yang_datanode(yc)) /* Allowed, check next */
- continue;
- if (keyw != subkeyw) /* Another datanode than subkeyw */
- break;
- if (i++>0) /* More than one list (or could this work?) */
- break;
+ keyw = yang_keyword_get(yc);
+ /* case/choice could hide anything so disqualify those */
+ if (keyw == Y_CASE || keyw == Y_CHOICE)
+ break;
+ if (!yang_datanode(yc)) /* Allowed, check next */
+ continue;
+ if (keyw != subkeyw) /* Another datanode than subkeyw */
+ break;
+ if (i++>0) /* More than one list (or could this work?) */
+ break;
}
if (yc != NULL) /* break from loop */
- return 0;
+ return 0;
if (i != 1) /* List found */
- return 0;
+ return 0;
return 1; /* Passed all tests: yes you can hide this keyword */
}
@@ -3912,13 +3853,13 @@ yang_action_cb_get(yang_stmt *ys)
*/
int
yang_action_cb_add(yang_stmt *ys,
- void *arg)
+ void *arg)
{
rpc_callback_t *rc = (rpc_callback_t *)arg;
if (rc == NULL){
- clicon_err(OE_YANG, EINVAL, "arg is NULL");
- return -1;
+ clicon_err(OE_YANG, EINVAL, "arg is NULL");
+ return -1;
}
ADDQ(rc, ys->ys_action_cb);
return 0;
diff --git a/lib/src/clixon_yang_cardinality.c b/lib/src/clixon_yang_cardinality.c
index 3ba51143..5175efa3 100644
--- a/lib/src/clixon_yang_cardinality.c
+++ b/lib/src/clixon_yang_cardinality.c
@@ -480,8 +480,8 @@ static int _yc_exist[Y_SPEC] = {0,};
*/
int
yang_cardinality(clicon_handle h,
- yang_stmt *yt,
- char *modname)
+ yang_stmt *yt,
+ char *modname)
{
int retval = -1;
yang_stmt *ys = NULL;
@@ -495,69 +495,69 @@ yang_cardinality(clicon_handle h,
pk = yang_keyword_get(yt);
if (_yc_exist[pk] == 0)
- goto ok;
+ goto ok;
/* 1) For all children, if neither in 0..n, 0..1, 1 or 1..n ->ERROR
* Also: check monotonically increasing order
*/
order = 0;
ys = NULL;
while ((ys = yn_each(yt, ys)) != NULL) {
- ck = yang_keyword_get(ys);
- if (pk == Y_UNKNOWN || ck == Y_UNKNOWN) /* special case */
- continue;
- /* Find entry in yang cardinality table from parent/child keyword pair */
- if ((yc = _yc_search[pk][ck]) == NULL){
- clicon_err(OE_YANG, 0, "%s: \"%s\"(%s) is child of \"%s\"(%s), but should not be",
- modname,
- yang_key2str(ck),
- yang_argument_get(ys),
- yang_key2str(pk),
- yang_argument_get(yt));
- goto done;
- }
- if (order > yc->yc_order){
- clicon_err(OE_YANG, 0, "%s: yang node \"%s\"(%s) which is child of \"%s\"(%s) is not in correct order (should not be after \"%s\"(%s))",
- modname,
- yang_key2str(ck),
- yang_argument_get(ys),
- yang_key2str(pk),
- yang_argument_get(yt),
- yang_key2str(yang_keyword_get(yprev)),
- yang_argument_get(yprev));
- goto done;
- }
- if (order < yc->yc_order)
- order = yc->yc_order;
- yprev = ys;
+ ck = yang_keyword_get(ys);
+ if (pk == Y_UNKNOWN || ck == Y_UNKNOWN) /* special case */
+ continue;
+ /* Find entry in yang cardinality table from parent/child keyword pair */
+ if ((yc = _yc_search[pk][ck]) == NULL){
+ clicon_err(OE_YANG, 0, "%s: \"%s\"(%s) is child of \"%s\"(%s), but should not be",
+ modname,
+ yang_key2str(ck),
+ yang_argument_get(ys),
+ yang_key2str(pk),
+ yang_argument_get(yt));
+ goto done;
+ }
+ if (order > yc->yc_order){
+ clicon_err(OE_YANG, 0, "%s: yang node \"%s\"(%s) which is child of \"%s\"(%s) is not in correct order (should not be after \"%s\"(%s))",
+ modname,
+ yang_key2str(ck),
+ yang_argument_get(ys),
+ yang_key2str(pk),
+ yang_argument_get(yt),
+ yang_key2str(yang_keyword_get(yprev)),
+ yang_argument_get(yprev));
+ goto done;
+ }
+ if (order < yc->yc_order)
+ order = yc->yc_order;
+ yprev = ys;
}
/* 2) For all in 1 and 1..n list, if 0 such children ->ERROR */
for (i=0; iyc_min &&
- yang_find(yt, yc->yc_child, NULL) == NULL){
- clicon_err(OE_YANG, 0, "%s: \"%s\" is missing but is mandatory child of \"%s\"",
- modname, yang_key2str(yc->yc_child), yang_key2str(pk));
- goto done;
- }
- if (yc->yc_maxyc_child, NULL)) > yc->yc_max){
- clicon_err(OE_YANG, 0, "%s: \"%s\" has %d children of type \"%s\", but only %d allowed",
- modname,
- yang_key2str(pk),
- nr,
- yang_key2str(yc->yc_child),
- yc->yc_max);
- goto done;
- }
+ yc = _yc_search[pk][i];
+ if (yc == NULL)
+ continue;
+ if (yc->yc_min &&
+ yang_find(yt, yc->yc_child, NULL) == NULL){
+ clicon_err(OE_YANG, 0, "%s: \"%s\" is missing but is mandatory child of \"%s\"",
+ modname, yang_key2str(yc->yc_child), yang_key2str(pk));
+ goto done;
+ }
+ if (yc->yc_maxyc_child, NULL)) > yc->yc_max){
+ clicon_err(OE_YANG, 0, "%s: \"%s\" has %d children of type \"%s\", but only %d allowed",
+ modname,
+ yang_key2str(pk),
+ nr,
+ yang_key2str(yc->yc_child),
+ yc->yc_max);
+ goto done;
+ }
}
/* 4) Recurse */
i = 0;
while (i< yang_len_get(yt)){ /* Note, children may be removed cant use yn_each */
- ys = yang_child_i(yt, i++);
- if (yang_cardinality(h, ys, modname) < 0)
- goto done;
+ ys = yang_child_i(yt, i++);
+ if (yang_cardinality(h, ys, modname) < 0)
+ goto done;
}
ok:
retval = 0;
@@ -575,18 +575,18 @@ yang_cardinality(clicon_handle h,
*/
int
yang_cardinality_interval(clicon_handle h,
- enum rfc_6020 parent_key,
- enum rfc_6020 child_key,
- int *min,
- int *max)
+ enum rfc_6020 parent_key,
+ enum rfc_6020 child_key,
+ int *min,
+ int *max)
{
int retval = -1;
const struct ycard *ycplist; /* ycard parent table*/
if ((ycplist = _yc_search[parent_key][child_key]) == NULL){
- clicon_err(OE_YANG, EINVAL, "keys %d %d do not have cardinality",
- parent_key, child_key);
- goto done;
+ clicon_err(OE_YANG, EINVAL, "keys %d %d do not have cardinality",
+ parent_key, child_key);
+ goto done;
}
*min = ycplist->yc_min;
*max = ycplist->yc_max;
@@ -602,8 +602,8 @@ yang_cardinality_init(clicon_handle h)
const struct ycard *yc;
for (yc = &_yclist[0]; (int)yc->yc_parent; yc++){
- _yc_exist[yc->yc_parent] = 1;
- _yc_search[yc->yc_parent][yc->yc_child] = yc;
+ _yc_exist[yc->yc_parent] = 1;
+ _yc_search[yc->yc_parent][yc->yc_child] = yc;
}
return 0;
}
diff --git a/lib/src/clixon_yang_cardinality.h b/lib/src/clixon_yang_cardinality.h
index 3f613623..4ef3c7ef 100644
--- a/lib/src/clixon_yang_cardinality.h
+++ b/lib/src/clixon_yang_cardinality.h
@@ -42,4 +42,4 @@ int yang_cardinality(clicon_handle h, yang_stmt *yt, char *modname);
int yang_cardinality_interval(clicon_handle h, enum rfc_6020 parent_key, enum rfc_6020 child_key, int *min, int *max);
int yang_cardinality_init(clicon_handle h);
-#endif /* _CLIXON_YANG_CARDINALITY_H_ */
+#endif /* _CLIXON_YANG_CARDINALITY_H_ */
diff --git a/lib/src/clixon_yang_internal.h b/lib/src/clixon_yang_internal.h
index 7570fa71..3654ff83 100644
--- a/lib/src/clixon_yang_internal.h
+++ b/lib/src/clixon_yang_internal.h
@@ -46,7 +46,7 @@
*/
struct yang_type_cache{
int yc_options; /* See YANG_OPTIONS_* that determines pattern/
- fraction fields. */
+ fraction fields. */
cvec *yc_cvv; /* Range and length restriction. (if YANG_OPTION_
LENGTH|RANGE. Can be a vector if multiple
ranges*/
@@ -75,27 +75,27 @@ struct yang_stmt{
1) Augmented nodes "belong" to the module where the
augment is declared, which may be differnt from
the direct ancestor module
- 2) Unknown nodes "belong" to where the extension is
+ 2) Unknown nodes "belong" to where the extension is
declared
*/
cg_var *ys_cv; /* cligen variable. See ys_populate()
- Following stmts have cv:s:
- leaf: for default value
- leaf-list,
- config: boolean true or false
- mandatory: boolean true or false
- require-instance: true or false
- fraction-digits for fraction-digits
- revision (uint32)
- unknown-stmt (optional argument)
- */
+ Following stmts have cv:s:
+ leaf: for default value
+ leaf-list,
+ config: boolean true or false
+ mandatory: boolean true or false
+ require-instance: true or false
+ fraction-digits for fraction-digits
+ revision (uint32)
+ unknown-stmt (optional argument)
+ */
cvec *ys_cvec; /* List of stmt-specific variables
- Y_RANGE: range_min, range_max
- Y_LIST: vector of keys
- Y_TYPE & identity: store all derived
- types as : list
- Y_UNIQUE: vector of descendant schema node ids
- */
+ Y_RANGE: range_min, range_max
+ Y_LIST: vector of keys
+ Y_TYPE & identity: store all derived
+ types as : list
+ Y_UNIQUE: vector of descendant schema node ids
+ */
yang_type_cache *ys_typecache; /* If ys_keyword==Y_TYPE, cache all typedef data except unions */
char *ys_when_xpath; /* Special conditional for a "when"-associated augment/uses xpath */
cvec *ys_when_nsc; /* Special conditional for a "when"-associated augment/uses namespace ctx */
diff --git a/lib/src/clixon_yang_module.c b/lib/src/clixon_yang_module.c
index dd27239d..74af4394 100644
--- a/lib/src/clixon_yang_module.c
+++ b/lib/src/clixon_yang_module.c
@@ -88,8 +88,8 @@ modstate_diff_new(void)
modstate_diff_t *md;
if ((md = malloc(sizeof(modstate_diff_t))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- return NULL;
+ clicon_err(OE_UNIX, errno, "malloc");
+ return NULL;
}
memset(md, 0, sizeof(modstate_diff_t));
return md;
@@ -99,11 +99,11 @@ int
modstate_diff_free(modstate_diff_t *md)
{
if (md == NULL)
- return 0;
+ return 0;
if (md->md_content_id)
free(md->md_content_id);
if (md->md_diff)
- xml_free(md->md_diff);
+ xml_free(md->md_diff);
free(md);
return 0;
}
@@ -120,21 +120,21 @@ yang_modules_init(clicon_handle h)
int retval = -1;
yang_stmt *yspec;
- yspec = clicon_dbspec_yang(h);
+ yspec = clicon_dbspec_yang(h);
if (!clicon_option_bool(h, "CLICON_YANG_LIBRARY"))
- goto ok;
+ goto ok;
/* Ensure module-set-id is set */
if (!clicon_option_exists(h, "CLICON_MODULE_SET_ID")){
- clicon_err(OE_CFG, ENOENT, "CLICON_MODULE_SET_ID must be defined when CLICON_YANG_LIBRARY is enabled");
- goto done;
+ clicon_err(OE_CFG, ENOENT, "CLICON_MODULE_SET_ID must be defined when CLICON_YANG_LIBRARY is enabled");
+ goto done;
}
/* Ensure revision exists is set */
if (yang_spec_parse_module(h, "ietf-yang-library", NULL, yspec)< 0)
- goto done;
+ goto done;
/* Find revision */
if (yang_modules_revision(h) == NULL){
- clicon_err(OE_CFG, ENOENT, "Yang client library yang spec has no revision");
- goto done;
+ clicon_err(OE_CFG, ENOENT, "Yang client library yang spec has no revision");
+ goto done;
}
ok:
retval = 0;
@@ -157,10 +157,10 @@ yang_modules_revision(clicon_handle h)
yspec = clicon_dbspec_yang(h);
if ((ymod = yang_find(yspec, Y_MODULE, "ietf-yang-library")) != NULL ||
- (ymod = yang_find(yspec, Y_SUBMODULE, "ietf-yang-library")) != NULL){
- if ((yrev = yang_find(ymod, Y_REVISION, NULL)) != NULL){
- revision = yang_argument_get(yrev);
- }
+ (ymod = yang_find(yspec, Y_SUBMODULE, "ietf-yang-library")) != NULL){
+ if ((yrev = yang_find(ymod, Y_REVISION, NULL)) != NULL){
+ revision = yang_argument_get(yrev);
+ }
}
return revision;
}
@@ -173,10 +173,10 @@ yang_modules_revision(clicon_handle h)
*/
static int
yms_build(clicon_handle h,
- yang_stmt *yspec,
- char *msid,
- int brief,
- cbuf *cb)
+ yang_stmt *yspec,
+ char *msid,
+ int brief,
+ cbuf *cb)
{
int retval = -1;
yang_stmt *ylib = NULL; /* ietf-yang-library */
@@ -190,80 +190,80 @@ yms_build(clicon_handle h,
char *name;
if ((ylib = yang_find(yspec, Y_MODULE, module)) == NULL &&
- (ylib = yang_find(yspec, Y_SUBMODULE, module)) == NULL){
+ (ylib = yang_find(yspec, Y_SUBMODULE, module)) == NULL){
clicon_err(OE_YANG, 0, "%s not found", module);
goto done;
}
if ((yns = yang_find(ylib, Y_NAMESPACE, NULL)) == NULL){
- clicon_err(OE_YANG, 0, "%s yang namespace not found", module);
- goto done;
+ clicon_err(OE_YANG, 0, "%s yang namespace not found", module);
+ goto done;
}
if (clicon_option_bool(h, "CLICON_MODULE_LIBRARY_RFC7895")){
- cprintf(cb,"", yang_argument_get(yns));
- cprintf(cb,"%s ", msid);
+ cprintf(cb,"", yang_argument_get(yns));
+ cprintf(cb,"%s ", msid);
}
else { /* RFC 8525 */
- cprintf(cb,"", yang_argument_get(yns));
- cprintf(cb,"%s ", msid);
- cprintf(cb,"default ");
+ cprintf(cb,"", yang_argument_get(yns));
+ cprintf(cb,"%s ", msid);
+ cprintf(cb,"default ");
}
ymod = NULL;
while ((ymod = yn_each(yspec, ymod)) != NULL) {
- if (yang_keyword_get(ymod) != Y_MODULE)
- continue;
- cprintf(cb,"");
- cprintf(cb,"%s ", yang_argument_get(ymod));
- if ((ys = yang_find(ymod, Y_REVISION, NULL)) != NULL)
- cprintf(cb,"%s ", yang_argument_get(ys));
- else{
- /* RFC7895 1 If no (such) revision statement exists, the module's or
- submodule's revision is the zero-length string. */
- cprintf(cb," ");
- }
- if ((ys = yang_find(ymod, Y_NAMESPACE, NULL)) != NULL)
- cprintf(cb,"%s ", yang_argument_get(ys));
- else
- cprintf(cb," ");
- /* This follows order in rfc 7895: feature, conformance-type,
- submodules */
- if (!brief){
- yc = NULL;
- while ((yc = yn_each(ymod, yc)) != NULL) {
- switch(yang_keyword_get(yc)){
- case Y_FEATURE:
- if (yang_cv_get(yc) && cv_bool_get(yang_cv_get(yc)))
- cprintf(cb,"%s ", yang_argument_get(yc));
- break;
- default:
- break;
- }
- }
- if (clicon_option_bool(h, "CLICON_MODULE_LIBRARY_RFC7895"))
- cprintf(cb, "implement ");
- }
- yinc = NULL;
- while ((yinc = yn_each(ymod, yinc)) != NULL) {
- if (yang_keyword_get(yinc) != Y_INCLUDE)
- continue;
- cprintf(cb,"");
- name = yang_argument_get(yinc);
- cprintf(cb,"%s ", name);
- if ((ysub = yang_find(yspec, Y_SUBMODULE, name)) != NULL){
- if ((ys = yang_find(ysub, Y_REVISION, NULL)) != NULL)
- cprintf(cb,"%s ", yang_argument_get(ys));
- else
- cprintf(cb," ");
- }
- cprintf(cb," ");
- }
- cprintf(cb," ");
+ if (yang_keyword_get(ymod) != Y_MODULE)
+ continue;
+ cprintf(cb,"");
+ cprintf(cb,"%s ", yang_argument_get(ymod));
+ if ((ys = yang_find(ymod, Y_REVISION, NULL)) != NULL)
+ cprintf(cb,"%s ", yang_argument_get(ys));
+ else{
+ /* RFC7895 1 If no (such) revision statement exists, the module's or
+ submodule's revision is the zero-length string. */
+ cprintf(cb," ");
+ }
+ if ((ys = yang_find(ymod, Y_NAMESPACE, NULL)) != NULL)
+ cprintf(cb,"%s ", yang_argument_get(ys));
+ else
+ cprintf(cb," ");
+ /* This follows order in rfc 7895: feature, conformance-type,
+ submodules */
+ if (!brief){
+ yc = NULL;
+ while ((yc = yn_each(ymod, yc)) != NULL) {
+ switch(yang_keyword_get(yc)){
+ case Y_FEATURE:
+ if (yang_cv_get(yc) && cv_bool_get(yang_cv_get(yc)))
+ cprintf(cb,"%s ", yang_argument_get(yc));
+ break;
+ default:
+ break;
+ }
+ }
+ if (clicon_option_bool(h, "CLICON_MODULE_LIBRARY_RFC7895"))
+ cprintf(cb, "implement ");
+ }
+ yinc = NULL;
+ while ((yinc = yn_each(ymod, yinc)) != NULL) {
+ if (yang_keyword_get(yinc) != Y_INCLUDE)
+ continue;
+ cprintf(cb,"");
+ name = yang_argument_get(yinc);
+ cprintf(cb,"%s ", name);
+ if ((ysub = yang_find(yspec, Y_SUBMODULE, name)) != NULL){
+ if ((ys = yang_find(ysub, Y_REVISION, NULL)) != NULL)
+ cprintf(cb,"%s ", yang_argument_get(ys));
+ else
+ cprintf(cb," ");
+ }
+ cprintf(cb," ");
+ }
+ cprintf(cb," ");
}
if (clicon_option_bool(h, "CLICON_MODULE_LIBRARY_RFC7895")){
- cprintf(cb," ");
+ cprintf(cb," ");
}
else{
- cprintf(cb," ");
+ cprintf(cb," ");
}
retval = 0;
done:
@@ -303,8 +303,8 @@ int
yang_modules_state_get(clicon_handle h,
yang_stmt *yspec,
char *xpath,
- cvec *nsc,
- int brief,
+ cvec *nsc,
+ int brief,
cxobj **xret)
{
int retval = -1;
@@ -319,66 +319,66 @@ yang_modules_state_get(clicon_handle h,
msid = clicon_option_str(h, "CLICON_MODULE_SET_ID"); /* In RFC 8525 changed to "content-id" */
if ((xc = clicon_modst_cache_get(h, brief)) != NULL){
- cxobj *xw; /* tmp top wrap object */
- /* xc is here: ...
- * need to wrap it for xpath: */
- /* xc is also original tree, need to copy it */
- if ((xw = xml_wrap(xc, "top")) == NULL)
- goto done;
+ cxobj *xw; /* tmp top wrap object */
+ /* xc is here: ...
+ * need to wrap it for xpath: */
+ /* xc is also original tree, need to copy it */
+ if ((xw = xml_wrap(xc, "top")) == NULL)
+ goto done;
if (xpath_first(xw, nsc, "%s", xpath)){
if ((x = xml_dup(xc)) == NULL) /* Make copy and use below */
goto done;
}
- if (xml_rootchild_node(xw, xc) < 0) /* Unwrap x / free xw */
- goto done;
+ if (xml_rootchild_node(xw, xc) < 0) /* Unwrap x / free xw */
+ goto done;
}
else { /* No cache -> build the tree */
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, 0, "clicon buffer");
- goto done;
- }
- /* Build a cb string: ... */
- if (yms_build(h, yspec, msid, brief, cb) < 0)
- goto done;
- /* Parse cb, x is on the form: ...
- * Note, list is not sorted since it is state (should not be)
- */
- if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, &x, NULL) < 0){
- if (xret && netconf_operation_failed_xml(xret, "protocol", clicon_err_reason)< 0)
- goto done;
- goto fail;
- }
- if (xml_rootchild(x, 0, &x) < 0)
- goto done;
- /* x is now: ... */
- if (clicon_modst_cache_set(h, brief, x) < 0) /* move to fn above? */
- goto done;
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, 0, "clicon buffer");
+ goto done;
+ }
+ /* Build a cb string: ... */
+ if (yms_build(h, yspec, msid, brief, cb) < 0)
+ goto done;
+ /* Parse cb, x is on the form: ...
+ * Note, list is not sorted since it is state (should not be)
+ */
+ if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, &x, NULL) < 0){
+ if (xret && netconf_operation_failed_xml(xret, "protocol", clicon_err_reason)< 0)
+ goto done;
+ goto fail;
+ }
+ if (xml_rootchild(x, 0, &x) < 0)
+ goto done;
+ /* x is now: ... */
+ if (clicon_modst_cache_set(h, brief, x) < 0) /* move to fn above? */
+ goto done;
}
if (x){ /* x is here a copy (This code is ugly and I think wrong) */
- /* Wrap x (again) with new top-level node "top" which xpath wants */
- if ((x = xml_wrap(x, "top")) < 0)
- goto done;
- /* extract xpath part of module-state tree */
- if (xpath_vec(x, nsc, "%s", &xvec, &xlen, xpath?xpath:"/") < 0)
- goto done;
- if (xvec != NULL){
- for (i=0; imd_status == 0) /* No modstate in startup */
- goto ok;
+ goto ok;
/* Iterate through xml modified module state
* Note top-level here is typically module-set
*/
xmod = NULL;
while ((xmod = xml_child_each(msd->md_diff, xmod, CX_ELMNT)) != NULL) {
- /* Extract namespace */
- if ((ns = xml_find_body(xmod, "namespace")) == NULL)
- goto done;
- /* Extract revisions and make callbacks */
- if ((ret = mod_ns_upgrade(h, xt, xmod, ns, cbret)) < 0)
- goto done;
- if (ret == 0)
- goto fail;
+ /* Extract namespace */
+ if ((ns = xml_find_body(xmod, "namespace")) == NULL)
+ goto done;
+ /* Extract revisions and make callbacks */
+ if ((ret = mod_ns_upgrade(h, xt, xmod, ns, cbret)) < 0)
+ goto done;
+ if (ret == 0)
+ goto fail;
}
ok:
retval = 1;
@@ -509,7 +509,7 @@ clixon_module_upgrade(clicon_handle h,
*/
yang_stmt *
yang_find_module_by_prefix(yang_stmt *ys,
- char *prefix)
+ char *prefix)
{
yang_stmt *yimport;
yang_stmt *yprefix;
@@ -519,36 +519,36 @@ yang_find_module_by_prefix(yang_stmt *ys,
char *myprefix;
if ((yspec = ys_spec(ys)) == NULL){
- clicon_err(OE_YANG, 0, "My yang spec not found");
- goto done;
+ clicon_err(OE_YANG, 0, "My yang spec not found");
+ goto done;
}
/* First try own module */
if ((my_ymod = ys_module(ys)) == NULL){
- clicon_err(OE_YANG, 0, "My yang module not found");
- goto done;
+ clicon_err(OE_YANG, 0, "My yang module not found");
+ goto done;
}
myprefix = yang_find_myprefix(ys);
if (myprefix && strcmp(myprefix, prefix) == 0){
- ymod = my_ymod;
- goto done;
+ ymod = my_ymod;
+ goto done;
}
/* If no match, try imported modules */
yimport = NULL;
while ((yimport = yn_each(my_ymod, yimport)) != NULL) {
- if (yang_keyword_get(yimport) != Y_IMPORT)
- continue;
- if ((yprefix = yang_find(yimport, Y_PREFIX, NULL)) != NULL &&
- strcmp(yang_argument_get(yprefix), prefix) == 0){
- break;
- }
+ if (yang_keyword_get(yimport) != Y_IMPORT)
+ continue;
+ if ((yprefix = yang_find(yimport, Y_PREFIX, NULL)) != NULL &&
+ strcmp(yang_argument_get(yprefix), prefix) == 0){
+ break;
+ }
}
if (yimport){
- if ((ymod = yang_find(yspec, Y_MODULE, yang_argument_get(yimport))) == NULL){
- clicon_err(OE_YANG, 0, "No module or sub-module found with prefix %s",
- prefix);
- yimport = NULL;
- goto done; /* unresolved */
- }
+ if ((ymod = yang_find(yspec, Y_MODULE, yang_argument_get(yimport))) == NULL){
+ clicon_err(OE_YANG, 0, "No module or sub-module found with prefix %s",
+ prefix);
+ yimport = NULL;
+ goto done; /* unresolved */
+ }
}
done:
return ymod;
@@ -561,16 +561,16 @@ yang_find_module_by_prefix(yang_stmt *ys,
*/
yang_stmt *
yang_find_module_by_prefix_yspec(yang_stmt *yspec,
- char *prefix)
+ char *prefix)
{
yang_stmt *ymod = NULL;
yang_stmt *yprefix;
while ((ymod = yn_each(yspec, ymod)) != NULL)
- if (yang_keyword_get(ymod) == Y_MODULE &&
- (yprefix = yang_find(ymod, Y_PREFIX, NULL)) != NULL &&
- strcmp(yang_argument_get(yprefix), prefix) == 0)
- return ymod;
+ if (yang_keyword_get(ymod) == Y_MODULE &&
+ (yprefix = yang_find(ymod, Y_PREFIX, NULL)) != NULL &&
+ strcmp(yang_argument_get(yprefix), prefix) == 0)
+ return ymod;
return NULL;
}
@@ -586,15 +586,15 @@ yang_find_module_by_prefix_yspec(yang_stmt *yspec,
*/
yang_stmt *
yang_find_module_by_namespace(yang_stmt *yspec,
- char *ns)
+ char *ns)
{
yang_stmt *ymod = NULL;
if (ns == NULL)
- goto done;
+ goto done;
while ((ymod = yn_each(yspec, ymod)) != NULL) {
- if (yang_find(ymod, Y_NAMESPACE, ns) != NULL)
- break;
+ if (yang_find(ymod, Y_NAMESPACE, ns) != NULL)
+ break;
}
done:
return ymod;
@@ -612,25 +612,25 @@ yang_find_module_by_namespace(yang_stmt *yspec,
*/
yang_stmt *
yang_find_module_by_namespace_revision(yang_stmt *yspec,
- const char *ns,
- const char *rev)
+ const char *ns,
+ const char *rev)
{
yang_stmt *ymod = NULL;
yang_stmt *yrev;
char *rev1;
if (ns == NULL || rev == NULL){
- clicon_err(OE_CFG, EINVAL, "No ns or rev");
- goto done;
+ clicon_err(OE_CFG, EINVAL, "No ns or rev");
+ goto done;
}
while ((ymod = yn_each(yspec, ymod)) != NULL) {
- if (yang_find(ymod, Y_NAMESPACE, ns) != NULL)
- /* Get FIRST revision */
- if ((yrev = yang_find(ymod, Y_REVISION, NULL)) != NULL){
- rev1 = yang_argument_get(yrev);
- if (strcmp(rev, rev1) == 0)
- break; /* return this ymod */
- }
+ if (yang_find(ymod, Y_NAMESPACE, ns) != NULL)
+ /* Get FIRST revision */
+ if ((yrev = yang_find(ymod, Y_REVISION, NULL)) != NULL){
+ rev1 = yang_argument_get(yrev);
+ if (strcmp(rev, rev1) == 0)
+ break; /* return this ymod */
+ }
}
done:
return ymod;
@@ -648,30 +648,30 @@ yang_find_module_by_namespace_revision(yang_stmt *yspec,
*/
yang_stmt *
yang_find_module_by_name_revision(yang_stmt *yspec,
- const char *name,
- const char *rev)
+ const char *name,
+ const char *rev)
{
yang_stmt *ymod = NULL;
yang_stmt *yrev;
char *rev1;
if (name == NULL){
- clicon_err(OE_CFG, EINVAL, "No ns or rev");
- goto done;
+ clicon_err(OE_CFG, EINVAL, "No ns or rev");
+ goto done;
}
while ((ymod = yn_each(yspec, ymod)) != NULL) {
- if (yang_keyword_get(ymod) != Y_MODULE)
- continue;
- if (strcmp(yang_argument_get(ymod), name) != 0)
- continue;
- if (rev == NULL)
- break; /* Matching revision is NULL, match that */
- /* Get FIRST revision */
- if ((yrev = yang_find(ymod, Y_REVISION, NULL)) != NULL){
- rev1 = yang_argument_get(yrev);
- if (strcmp(rev, rev1) == 0)
- break; /* return this ymod */
- }
+ if (yang_keyword_get(ymod) != Y_MODULE)
+ continue;
+ if (strcmp(yang_argument_get(ymod), name) != 0)
+ continue;
+ if (rev == NULL)
+ break; /* Matching revision is NULL, match that */
+ /* Get FIRST revision */
+ if ((yrev = yang_find(ymod, Y_REVISION, NULL)) != NULL){
+ rev1 = yang_argument_get(yrev);
+ if (strcmp(rev, rev1) == 0)
+ break; /* return this ymod */
+ }
}
done:
return ymod;
@@ -688,14 +688,14 @@ yang_find_module_by_name_revision(yang_stmt *yspec,
*/
yang_stmt *
yang_find_module_by_name(yang_stmt *yspec,
- char *name)
+ char *name)
{
yang_stmt *ymod = NULL;
while ((ymod = yn_each(yspec, ymod)) != NULL)
- if ((yang_keyword_get(ymod) == Y_MODULE || yang_keyword_get(ymod) == Y_SUBMODULE) &&
- strcmp(yang_argument_get(ymod), name)==0)
- return ymod;
+ if ((yang_keyword_get(ymod) == Y_MODULE || yang_keyword_get(ymod) == Y_SUBMODULE) &&
+ strcmp(yang_argument_get(ymod), name)==0)
+ return ymod;
return NULL;
}
@@ -713,8 +713,8 @@ yang_find_module_by_name(yang_stmt *yspec,
*/
static int
ietf_yang_metadata_extension_cb(clicon_handle h,
- yang_stmt *yext,
- yang_stmt *ys)
+ yang_stmt *yext,
+ yang_stmt *ys)
{
int retval = -1;
char *extname;
@@ -726,7 +726,7 @@ ietf_yang_metadata_extension_cb(clicon_handle h,
modname = yang_argument_get(ymod);
extname = yang_argument_get(yext);
if (strcmp(modname, "ietf-yang-metadata") != 0 || strcmp(extname, "annotation") != 0)
- goto ok;
+ goto ok;
name = cv_string_get(yang_cv_get(ys));
clicon_debug(1, "%s Enabled extension:%s:%s:%s", __FUNCTION__, modname, extname, name);
/* XXX Nothing yet - this should signal that xml attribute annotations are allowed
@@ -751,29 +751,29 @@ ietf_yang_metadata_extension_cb(clicon_handle h,
*/
int
yang_metadata_annotation_check(cxobj *xa,
- yang_stmt *ymod,
- int *ismeta)
+ yang_stmt *ymod,
+ int *ismeta)
{
int retval = -1;
yang_stmt *yma = NULL;
char *name;
cg_var *cv;
-
+
/* Loop through annotations */
while ((yma = yn_each(ymod, yma)) != NULL){
- /* Assume here md:annotation is written using canonical prefix */
- if (yang_keyword_get(yma) != Y_UNKNOWN)
- continue;
- if (strcmp(yang_argument_get(yma), "md:annotation") != 0)
- continue;
- if ((cv = yang_cv_get(yma)) != NULL &&
- (name = cv_string_get(cv)) != NULL){
- if (strcmp(name, xml_name(xa)) == 0){
- /* XXX: yang_find(yma,Y_TYPE,0) */
- *ismeta = 1;
- break;
- }
- }
+ /* Assume here md:annotation is written using canonical prefix */
+ if (yang_keyword_get(yma) != Y_UNKNOWN)
+ continue;
+ if (strcmp(yang_argument_get(yma), "md:annotation") != 0)
+ continue;
+ if ((cv = yang_cv_get(yma)) != NULL &&
+ (name = cv_string_get(cv)) != NULL){
+ if (strcmp(name, xml_name(xa)) == 0){
+ /* XXX: yang_find(yma,Y_TYPE,0) */
+ *ismeta = 1;
+ break;
+ }
+ }
}
retval = 0;
// done:
@@ -794,7 +794,7 @@ yang_metadata_init(clicon_handle h)
* yang-data extension for api-root top-level restconf function.
*/
if (clixon_pseudo_plugin(h, "pseudo yang metadata", &cp) < 0)
- goto done;
+ goto done;
clixon_plugin_api_get(cp)->ca_extension = ietf_yang_metadata_extension_cb;
retval = 0;
done:
diff --git a/lib/src/clixon_yang_parse.h b/lib/src/clixon_yang_parse.h
index 3c67af55..95646097 100644
--- a/lib/src/clixon_yang_parse.h
+++ b/lib/src/clixon_yang_parse.h
@@ -53,7 +53,7 @@ struct ys_stack{
struct clixon_yang_yacc {
char *yy_name; /* Name of syntax, typically filename
- (for error string) */
+ (for error string) */
int yy_linenum; /* Number of \n in parsed buffer */
char *yy_parse_string; /* original (copy of) parse string */
void *yy_lexbuf; /* internal parse buffer from lex */
@@ -70,10 +70,10 @@ typedef struct clixon_yang_yacc clixon_yang_yacc;
*/
struct yang_userdata{
char *du_indexvar; /* (clicon) This command is a list and
- this string is the key/index of the list
- */
+ this string is the key/index of the list
+ */
char *du_yang; /* (clicon) Save yang key for cli
- generation */
+ generation */
int du_optional; /* (clicon) Optional element in list */
struct cg_var *du_default; /* default value(clicon) */
char du_vector; /* (clicon) Possibly more than one element */
@@ -100,4 +100,4 @@ void clixon_yang_parseerror(void *_ya, char*);
int ystack_pop(clixon_yang_yacc *ya);
struct ys_stack *ystack_push(clixon_yang_yacc *ya, yang_stmt *yn);
-#endif /* _CLIXON_YANG_PARSE_H_ */
+#endif /* _CLIXON_YANG_PARSE_H_ */
diff --git a/lib/src/clixon_yang_parse.l b/lib/src/clixon_yang_parse.l
index 3e785020..5c6cc2aa 100644
--- a/lib/src/clixon_yang_parse.l
+++ b/lib/src/clixon_yang_parse.l
@@ -272,10 +272,10 @@ identifier [A-Za-z_][A-Za-z0-9_\-\.]*
BEGIN(_YY->yy_lex_state);
str[0] = '\\';
str[1] = yytext[0];
- str[2] = '\0';
+ str[2] = '\0';
clixon_yang_parselval.string = str;
return CHARS; }
-
+
[^*\n]* /* eat anything that's not a '*' */
"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
"*"+"/" BEGIN(_YY->yy_lex_state);
diff --git a/lib/src/clixon_yang_parse.y b/lib/src/clixon_yang_parse.y
index a29e0536..bcae6a16 100644
--- a/lib/src/clixon_yang_parse.y
+++ b/lib/src/clixon_yang_parse.y
@@ -217,13 +217,13 @@ extern int clixon_yang_parseget_lineno (void);
*/
void
clixon_yang_parseerror(void *_yy,
- char *s)
+ char *s)
{
clicon_err(OE_YANG, 0, "%s on line %d: %s at or before: '%s'",
- _YY->yy_name,
- _YY->yy_linenum ,
- s,
- clixon_yang_parsetext);
+ _YY->yy_name,
+ _YY->yy_linenum ,
+ s,
+ clixon_yang_parsetext);
return;
}
@@ -249,11 +249,11 @@ ystack_pop(clixon_yang_yacc *yy)
struct ys_stack *ystack;
if ((ystack = yy->yy_stack) == NULL){
- clicon_err(OE_YANG, 0, "ystack is NULL");
- return -1;
+ clicon_err(OE_YANG, 0, "ystack is NULL");
+ return -1;
}
if (yang_sort_subelements(ystack->ys_node) < 0)
- return -1;
+ return -1;
yy->yy_stack = ystack->ys_next;
free(ystack);
return 0;
@@ -265,13 +265,13 @@ ystack_pop(clixon_yang_yacc *yy)
*/
struct ys_stack *
ystack_push(clixon_yang_yacc *yy,
- yang_stmt *yn)
+ yang_stmt *yn)
{
struct ys_stack *ystack;
if ((ystack = malloc(sizeof(*ystack))) == NULL) {
- clicon_err(OE_YANG, errno, "malloc");
- return NULL;
+ clicon_err(OE_YANG, errno, "malloc");
+ return NULL;
}
memset(ystack, 0, sizeof(*ystack));
ystack->ys_node = yn;
@@ -291,9 +291,9 @@ ystack_push(clixon_yang_yacc *yy,
*/
static yang_stmt *
ysp_add(clixon_yang_yacc *yy,
- enum rfc_6020 keyword,
- char *argument,
- char *extra)
+ enum rfc_6020 keyword,
+ char *argument,
+ char *extra)
{
struct ys_stack *ystack = yy->yy_stack;
yang_stmt *ys = NULL;
@@ -301,26 +301,26 @@ ysp_add(clixon_yang_yacc *yy,
ystack = yy->yy_stack;
if (ystack == NULL){
- clicon_err(OE_YANG, errno, "No stack");
- goto err;
+ clicon_err(OE_YANG, errno, "No stack");
+ goto err;
}
if ((yn = ystack->ys_node) == NULL){
- clicon_err(OE_YANG, errno, "No ys_node");
- goto err;
+ clicon_err(OE_YANG, errno, "No ys_node");
+ goto err;
}
if ((ys = ys_new(keyword)) == NULL)
- goto err;
+ goto err;
/* NOTE: does not make a copy of string, ie argument is 'consumed' here */
yang_argument_set(ys, argument);
if (yn_insert(yn, ys) < 0) /* Insert into hierarchy */
- goto err;
+ goto err;
yang_linenum_set(ys, yy->yy_linenum); /* For error/debugging */
if (ys_parse_sub(ys, yy->yy_name, extra) < 0) /* Check statement-specific syntax */
- goto err2; /* dont free since part of tree */
+ goto err2; /* dont free since part of tree */
return ys;
err:
if (ys)
- ys_free(ys);
+ ys_free(ys);
err2:
return NULL;
}
@@ -334,16 +334,16 @@ ysp_add(clixon_yang_yacc *yy,
*/
static yang_stmt *
ysp_add_push(clixon_yang_yacc *yy,
- enum rfc_6020 keyword,
- char *argument,
- char *extra)
+ enum rfc_6020 keyword,
+ char *argument,
+ char *extra)
{
yang_stmt *ys;
if ((ys = ysp_add(yy, keyword, argument, extra)) == NULL)
- return NULL;
+ return NULL;
if (ystack_push(yy, ys) == NULL)
- return NULL;
+ return NULL;
return ys;
}
@@ -371,7 +371,7 @@ module_stmt : K_MODULE identifier_str
}
'{' module_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("module_stmt");
- _PARSE_DEBUG("module_stmt -> id-arg-str { module-substmts }");}
+ _PARSE_DEBUG("module_stmt -> id-arg-str { module-substmts }");}
;
module_substmts : module_substmts module_substmt
@@ -394,7 +394,7 @@ submodule_stmt : K_SUBMODULE identifier_str
{ if ((_YY->yy_module = ysp_add_push(_yy, Y_SUBMODULE, $2, NULL)) == NULL) _YYERROR("submodule_stmt"); }
'{' submodule_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("submodule_stmt");
- _PARSE_DEBUG("submodule_stmt -> id-arg-str { submodule-substmts }");}
+ _PARSE_DEBUG("submodule_stmt -> id-arg-str { submodule-substmts }");}
;
submodule_substmts : submodule_substmts submodule_substmt
@@ -450,7 +450,7 @@ submodule_header_stmt : yang_version_stmt
/* yang-version-stmt = yang-version-keyword yang-version-arg-str */
yang_version_stmt : K_YANG_VERSION string stmtend
- { if (ysp_add(_yy, Y_YANG_VERSION, $2, NULL) == NULL) _YYERROR("yang_version_stmt");
+ { if (ysp_add(_yy, Y_YANG_VERSION, $2, NULL) == NULL) _YYERROR("yang_version_stmt");
_PARSE_DEBUG("yang-version-stmt -> YANG-VERSION string"); }
;
@@ -459,7 +459,7 @@ import_stmt : K_IMPORT identifier_str
{ if (ysp_add_push(_yy, Y_IMPORT, $2, NULL) == NULL) _YYERROR("import_stmt"); }
'{' import_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("import_stmt");
- _PARSE_DEBUG("import-stmt -> IMPORT id-arg-str { import-substmts }");}
+ _PARSE_DEBUG("import-stmt -> IMPORT id-arg-str { import-substmts }");}
;
import_substmts : import_substmts import_substmt
@@ -475,11 +475,11 @@ import_substmt : prefix_stmt { _PARSE_DEBUG("import-stmt -> prefix-stmt")
;
include_stmt : K_INCLUDE identifier_str ';'
- { if (ysp_add(_yy, Y_INCLUDE, $2, NULL)== NULL) _YYERROR("include_stmt");
+ { if (ysp_add(_yy, Y_INCLUDE, $2, NULL)== NULL) _YYERROR("include_stmt");
_PARSE_DEBUG("include-stmt -> id-str"); }
| K_INCLUDE identifier_str
- { if (ysp_add_push(_yy, Y_INCLUDE, $2, NULL) == NULL) _YYERROR("include_stmt"); }
- '{' include_substmts '}'
+ { if (ysp_add_push(_yy, Y_INCLUDE, $2, NULL) == NULL) _YYERROR("include_stmt"); }
+ '{' include_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("include_stmt");
_PARSE_DEBUG("include-stmt -> id-str { include-substmts }"); }
;
@@ -498,13 +498,13 @@ include_substmt : revision_date_stmt { _PARSE_DEBUG("include-stmt -> revision-da
/* namespace-stmt = namespace-keyword sep uri-str */
namespace_stmt : K_NAMESPACE string stmtend
- { if (ysp_add(_yy, Y_NAMESPACE, $2, NULL)== NULL) _YYERROR("namespace_stmt");
+ { if (ysp_add(_yy, Y_NAMESPACE, $2, NULL)== NULL) _YYERROR("namespace_stmt");
_PARSE_DEBUG("namespace-stmt -> NAMESPACE string"); }
;
prefix_stmt : K_PREFIX identifier_str stmtend /* XXX prefix-arg-str */
- { if (ysp_add(_yy, Y_PREFIX, $2, NULL)== NULL) _YYERROR("prefix_stmt");
- _PARSE_DEBUG("prefix-stmt -> PREFIX string ;");}
+ { if (ysp_add(_yy, Y_PREFIX, $2, NULL)== NULL) _YYERROR("prefix_stmt");
+ _PARSE_DEBUG("prefix-stmt -> PREFIX string ;");}
;
belongs_to_stmt : K_BELONGS_TO identifier_str
@@ -512,43 +512,43 @@ belongs_to_stmt : K_BELONGS_TO identifier_str
'{' prefix_stmt '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("belongs_to_stmt");
- _PARSE_DEBUG("belongs-to-stmt -> BELONGS-TO id-arg-str { prefix-stmt } ");
- }
+ _PARSE_DEBUG("belongs-to-stmt -> BELONGS-TO id-arg-str { prefix-stmt } ");
+ }
;
organization_stmt: K_ORGANIZATION string stmtend
- { if (ysp_add(_yy, Y_ORGANIZATION, $2, NULL)== NULL) _YYERROR("belongs_to_stmt");
- _PARSE_DEBUG("organization-stmt -> ORGANIZATION string ;");}
+ { if (ysp_add(_yy, Y_ORGANIZATION, $2, NULL)== NULL) _YYERROR("belongs_to_stmt");
+ _PARSE_DEBUG("organization-stmt -> ORGANIZATION string ;");}
;
contact_stmt : K_CONTACT string stmtend
- { if (ysp_add(_yy, Y_CONTACT, $2, NULL)== NULL) _YYERROR("contact_stmt");
+ { if (ysp_add(_yy, Y_CONTACT, $2, NULL)== NULL) _YYERROR("contact_stmt");
_PARSE_DEBUG("contact-stmt -> CONTACT string"); }
;
description_stmt : K_DESCRIPTION string stmtend
- { if (ysp_add(_yy, Y_DESCRIPTION, $2, NULL)== NULL) _YYERROR("description_stmt");
- _PARSE_DEBUG("description-stmt -> DESCRIPTION string ;");}
+ { if (ysp_add(_yy, Y_DESCRIPTION, $2, NULL)== NULL) _YYERROR("description_stmt");
+ _PARSE_DEBUG("description-stmt -> DESCRIPTION string ;");}
;
reference_stmt : K_REFERENCE string stmtend
- { if (ysp_add(_yy, Y_REFERENCE, $2, NULL)== NULL) _YYERROR("reference_stmt");
- _PARSE_DEBUG("reference-stmt -> REFERENCE string ;");}
+ { if (ysp_add(_yy, Y_REFERENCE, $2, NULL)== NULL) _YYERROR("reference_stmt");
+ _PARSE_DEBUG("reference-stmt -> REFERENCE string ;");}
;
units_stmt : K_UNITS string ';'
- { if (ysp_add(_yy, Y_UNITS, $2, NULL)== NULL) _YYERROR("units_stmt");
+ { if (ysp_add(_yy, Y_UNITS, $2, NULL)== NULL) _YYERROR("units_stmt");
_PARSE_DEBUG("units-stmt -> UNITS string"); }
;
revision_stmt : K_REVISION string ';' /* XXX date-arg-str */
- { if (ysp_add(_yy, Y_REVISION, $2, NULL) == NULL) _YYERROR("revision_stmt");
- _PARSE_DEBUG("revision-stmt -> date-arg-str ;"); }
+ { if (ysp_add(_yy, Y_REVISION, $2, NULL) == NULL) _YYERROR("revision_stmt");
+ _PARSE_DEBUG("revision-stmt -> date-arg-str ;"); }
| K_REVISION string
- { if (ysp_add_push(_yy, Y_REVISION, $2, NULL) == NULL) _YYERROR("revision_stmt"); }
+ { if (ysp_add_push(_yy, Y_REVISION, $2, NULL) == NULL) _YYERROR("revision_stmt"); }
'{' revision_substmts '}' /* XXX date-arg-str */
{ if (ystack_pop(_yy) < 0) _YYERROR("revision_stmt");
- _PARSE_DEBUG("revision-stmt -> date-arg-str { revision-substmts }"); }
+ _PARSE_DEBUG("revision-stmt -> date-arg-str { revision-substmts }"); }
;
revision_substmts : revision_substmts revision_substmt
@@ -572,19 +572,19 @@ revision_stmts : revision_stmts revision_stmt
;
revision_date_stmt : K_REVISION_DATE string stmtend /* XXX date-arg-str */
- { if (ysp_add(_yy, Y_REVISION_DATE, $2, NULL) == NULL) _YYERROR("revision_date_stmt");
- _PARSE_DEBUG("revision-date-stmt -> date;"); }
+ { if (ysp_add(_yy, Y_REVISION_DATE, $2, NULL) == NULL) _YYERROR("revision_date_stmt");
+ _PARSE_DEBUG("revision-date-stmt -> date;"); }
;
extension_stmt : K_EXTENSION identifier_str ';'
- { if (ysp_add(_yy, Y_EXTENSION, $2, NULL) == NULL) _YYERROR("extension_stmt");
+ { if (ysp_add(_yy, Y_EXTENSION, $2, NULL) == NULL) _YYERROR("extension_stmt");
_PARSE_DEBUG("extenstion-stmt -> EXTENSION id-str ;"); }
| K_EXTENSION identifier_str
- { if (ysp_add_push(_yy, Y_EXTENSION, $2, NULL) == NULL) _YYERROR("extension_stmt"); }
- '{' extension_substmts '}'
- { if (ystack_pop(_yy) < 0) _YYERROR("extension_stmt");
+ { if (ysp_add_push(_yy, Y_EXTENSION, $2, NULL) == NULL) _YYERROR("extension_stmt"); }
+ '{' extension_substmts '}'
+ { if (ystack_pop(_yy) < 0) _YYERROR("extension_stmt");
_PARSE_DEBUG("extension-stmt -> EXTENSION id-str { extension-substmts }"); }
- ;
+ ;
/* extension substmts */
extension_substmts : extension_substmts extension_substmt
@@ -603,12 +603,12 @@ extension_substmt : argument_stmt { _PARSE_DEBUG("extension-substmt -> argume
argument_stmt : K_ARGUMENT identifier_str ';'
{ if (ysp_add(_yy, Y_ARGUMENT, $2, NULL) == NULL) _YYERROR("argument_stmt");
- _PARSE_DEBUG("argument-stmt -> ARGUMENT identifier ;"); }
+ _PARSE_DEBUG("argument-stmt -> ARGUMENT identifier ;"); }
| K_ARGUMENT identifier_str
- { if (ysp_add_push(_yy, Y_ARGUMENT, $2, NULL) == NULL) _YYERROR("argument_stmt"); }
+ { if (ysp_add_push(_yy, Y_ARGUMENT, $2, NULL) == NULL) _YYERROR("argument_stmt"); }
'{' argument_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("argument_stmt");
- _PARSE_DEBUG("argument-stmt -> ARGUMENT { argument-substmts }"); }
+ _PARSE_DEBUG("argument-stmt -> ARGUMENT { argument-substmts }"); }
;
/* argument substmts */
@@ -630,13 +630,13 @@ yin_element_stmt1 : K_YIN_ELEMENT bool_str stmtend {free($2);}
/* Identity */
identity_stmt : K_IDENTITY identifier_str ';'
{ if (ysp_add(_yy, Y_IDENTITY, $2, NULL) == NULL) _YYERROR("identity_stmt");
- _PARSE_DEBUG("identity-stmt -> IDENTITY string ;"); }
+ _PARSE_DEBUG("identity-stmt -> IDENTITY string ;"); }
| K_IDENTITY identifier_str
- { if (ysp_add_push(_yy, Y_IDENTITY, $2, NULL) == NULL) _YYERROR("identity_stmt"); }
- '{' identity_substmts '}'
+ { if (ysp_add_push(_yy, Y_IDENTITY, $2, NULL) == NULL) _YYERROR("identity_stmt"); }
+ '{' identity_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("identity_stmt");
- _PARSE_DEBUG("identity-stmt -> IDENTITY string { identity-substmts }"); }
+ _PARSE_DEBUG("identity-stmt -> IDENTITY string { identity-substmts }"); }
;
identity_substmts : identity_substmts identity_substmt
@@ -655,16 +655,16 @@ identity_substmt : if_feature_stmt { _PARSE_DEBUG("identity-substmt -> if-feat
;
base_stmt : K_BASE identifier_ref_arg_str stmtend
- { if (ysp_add(_yy, Y_BASE, $2, NULL)== NULL) _YYERROR("base_stmt");
+ { if (ysp_add(_yy, Y_BASE, $2, NULL)== NULL) _YYERROR("base_stmt");
_PARSE_DEBUG("base-stmt -> BASE identifier-ref-arg-str"); }
;
/* Feature */
feature_stmt : K_FEATURE identifier_str ';'
- { if (ysp_add(_yy, Y_FEATURE, $2, NULL) == NULL) _YYERROR("feature_stmt");
- _PARSE_DEBUG("feature-stmt -> FEATURE id-arg-str ;"); }
+ { if (ysp_add(_yy, Y_FEATURE, $2, NULL) == NULL) _YYERROR("feature_stmt");
+ _PARSE_DEBUG("feature-stmt -> FEATURE id-arg-str ;"); }
| K_FEATURE identifier_str
- { if (ysp_add_push(_yy, Y_FEATURE, $2, NULL) == NULL) _YYERROR("feature_stmt"); }
+ { if (ysp_add_push(_yy, Y_FEATURE, $2, NULL) == NULL) _YYERROR("feature_stmt"); }
'{' feature_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("feature_stmt");
_PARSE_DEBUG("feature-stmt -> FEATURE id-arg-str { feature-substmts }"); }
@@ -687,7 +687,7 @@ feature_substmt : if_feature_stmt { _PARSE_DEBUG("feature-substmt -> if-featu
/* if-feature-stmt = if-feature-keyword sep if-feature-expr-str */
if_feature_stmt : K_IF_FEATURE if_feature_expr_str stmtend
- { if (ysp_add(_yy, Y_IF_FEATURE, $2, NULL) == NULL) _YYERROR("if_feature_stmt");
+ { if (ysp_add(_yy, Y_IF_FEATURE, $2, NULL) == NULL) _YYERROR("if_feature_stmt");
_PARSE_DEBUG("if-feature-stmt -> IF-FEATURE if-feature-expr-str"); }
;
@@ -696,16 +696,16 @@ if_feature_stmt : K_IF_FEATURE if_feature_expr_str stmtend
*/
if_feature_expr_str : string
{ $$=$1;
- _PARSE_DEBUG("if-feature-expr-str -> string that matches the rule if-feature-expr");
- }
+ _PARSE_DEBUG("if-feature-expr-str -> string that matches the rule if-feature-expr");
+ }
;
/* Typedef */
typedef_stmt : K_TYPEDEF identifier_str
{ if (ysp_add_push(_yy, Y_TYPEDEF, $2, NULL) == NULL) _YYERROR("typedef_stmt"); }
- '{' typedef_substmts '}'
+ '{' typedef_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("typedef_stmt");
- _PARSE_DEBUG("typedef-stmt -> TYPEDEF id-arg-str { typedef-substmts }"); }
+ _PARSE_DEBUG("typedef-stmt -> TYPEDEF id-arg-str { typedef-substmts }"); }
;
typedef_substmts : typedef_substmts typedef_substmt
@@ -726,11 +726,11 @@ typedef_substmt : type_stmt { _PARSE_DEBUG("typedef-substmt -> type-stm
/* Type */
type_stmt : K_TYPE identifier_ref_arg_str ';'
- { if (ysp_add(_yy, Y_TYPE, $2, NULL) == NULL) _YYERROR("type_stmt");
- _PARSE_DEBUG("type-stmt -> TYPE identifier-ref-arg-str ;");}
+ { if (ysp_add(_yy, Y_TYPE, $2, NULL) == NULL) _YYERROR("type_stmt");
+ _PARSE_DEBUG("type-stmt -> TYPE identifier-ref-arg-str ;");}
| K_TYPE identifier_ref_arg_str
- { if (ysp_add_push(_yy, Y_TYPE, $2, NULL) == NULL) _YYERROR("type_stmt");
- }
+ { if (ysp_add_push(_yy, Y_TYPE, $2, NULL) == NULL) _YYERROR("type_stmt");
+ }
'{' type_body_stmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("type_stmt");
_PARSE_DEBUG("type-stmt -> TYPE identifier-ref-arg-str { type-body-stmts }");}
@@ -771,14 +771,14 @@ type_body_stmt/* numerical-restrictions */
/* range-stmt */
range_stmt : K_RANGE string ';' /* XXX range-arg-str */
- { if (ysp_add(_yy, Y_RANGE, $2, NULL) == NULL) _YYERROR("range_stmt");
- _PARSE_DEBUG("range-stmt -> RANGE string ;"); }
+ { if (ysp_add(_yy, Y_RANGE, $2, NULL) == NULL) _YYERROR("range_stmt");
+ _PARSE_DEBUG("range-stmt -> RANGE string ;"); }
| K_RANGE string
- { if (ysp_add_push(_yy, Y_RANGE, $2, NULL) == NULL) _YYERROR("range_stmt"); }
- '{' range_substmts '}'
+ { if (ysp_add_push(_yy, Y_RANGE, $2, NULL) == NULL) _YYERROR("range_stmt"); }
+ '{' range_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("range_stmt");
- _PARSE_DEBUG("range-stmt -> RANGE string { range-substmts }"); }
+ _PARSE_DEBUG("range-stmt -> RANGE string { range-substmts }"); }
;
range_substmts : range_substmts range_substmt
@@ -796,7 +796,7 @@ range_substmt : error_message_stmt { _PARSE_DEBUG("range-substmt -> error-mess
/* fraction-digits-stmt = fraction-digits-keyword fraction-digits-arg-str */
fraction_digits_stmt : K_FRACTION_DIGITS string stmtend
- { if (ysp_add(_yy, Y_FRACTION_DIGITS, $2, NULL) == NULL) _YYERROR("fraction_digits_stmt");
+ { if (ysp_add(_yy, Y_FRACTION_DIGITS, $2, NULL) == NULL) _YYERROR("fraction_digits_stmt");
_PARSE_DEBUG("fraction-digits-stmt -> FRACTION-DIGITS string"); }
;
@@ -814,14 +814,14 @@ meta_stmt : organization_stmt { _PARSE_DEBUG("meta-stmt -> organization-s
/* length-stmt */
length_stmt : K_LENGTH string ';' /* XXX length-arg-str */
- { if (ysp_add(_yy, Y_LENGTH, $2, NULL) == NULL) _YYERROR("length_stmt");
- _PARSE_DEBUG("length-stmt -> LENGTH string ;"); }
+ { if (ysp_add(_yy, Y_LENGTH, $2, NULL) == NULL) _YYERROR("length_stmt");
+ _PARSE_DEBUG("length-stmt -> LENGTH string ;"); }
| K_LENGTH string
- { if (ysp_add_push(_yy, Y_LENGTH, $2, NULL) == NULL) _YYERROR("length_stmt"); }
- '{' length_substmts '}'
+ { if (ysp_add_push(_yy, Y_LENGTH, $2, NULL) == NULL) _YYERROR("length_stmt"); }
+ '{' length_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("length_stmt");
- _PARSE_DEBUG("length-stmt -> LENGTH string { length-substmts }"); }
+ _PARSE_DEBUG("length-stmt -> LENGTH string { length-substmts }"); }
;
length_substmts : length_substmts length_substmt
@@ -839,14 +839,14 @@ length_substmt : error_message_stmt { _PARSE_DEBUG("length-substmt -> error-mes
/* Pattern */
pattern_stmt : K_PATTERN string ';'
- { if (ysp_add(_yy, Y_PATTERN, $2, NULL) == NULL) _YYERROR("pattern_stmt");
- _PARSE_DEBUG("pattern-stmt -> PATTERN string ;"); }
+ { if (ysp_add(_yy, Y_PATTERN, $2, NULL) == NULL) _YYERROR("pattern_stmt");
+ _PARSE_DEBUG("pattern-stmt -> PATTERN string ;"); }
| K_PATTERN string
- { if (ysp_add_push(_yy, Y_PATTERN, $2, NULL) == NULL) _YYERROR("pattern_stmt"); }
- '{' pattern_substmts '}'
+ { if (ysp_add_push(_yy, Y_PATTERN, $2, NULL) == NULL) _YYERROR("pattern_stmt"); }
+ '{' pattern_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("pattern_stmt");
- _PARSE_DEBUG("pattern-stmt -> PATTERN string { pattern-substmts }"); }
+ _PARSE_DEBUG("pattern-stmt -> PATTERN string { pattern-substmts }"); }
;
pattern_substmts : pattern_substmts pattern_substmt
@@ -865,24 +865,24 @@ pattern_substmt : modifier_stmt { _PARSE_DEBUG("pattern-substmt -> modifier-s
;
modifier_stmt : K_MODIFIER string stmtend
- { if (ysp_add(_yy, Y_MODIFIER, $2, NULL)== NULL) _YYERROR("modifier_stmt");
+ { if (ysp_add(_yy, Y_MODIFIER, $2, NULL)== NULL) _YYERROR("modifier_stmt");
_PARSE_DEBUG("modifier-stmt -> MODIFIER string"); }
;
default_stmt : K_DEFAULT string stmtend
- { if (ysp_add(_yy, Y_DEFAULT, $2, NULL)== NULL) _YYERROR("default_stmt");
+ { if (ysp_add(_yy, Y_DEFAULT, $2, NULL)== NULL) _YYERROR("default_stmt");
_PARSE_DEBUG("default-stmt -> DEFAULT string"); }
;
/* enum-stmt */
enum_stmt : K_ENUM string ';'
- { if (ysp_add(_yy, Y_ENUM, $2, NULL) == NULL) _YYERROR("enum_stmt");
- _PARSE_DEBUG("enum-stmt -> ENUM string ;"); }
+ { if (ysp_add(_yy, Y_ENUM, $2, NULL) == NULL) _YYERROR("enum_stmt");
+ _PARSE_DEBUG("enum-stmt -> ENUM string ;"); }
| K_ENUM string
- { if (ysp_add_push(_yy, Y_ENUM, $2, NULL) == NULL) _YYERROR("enum_stmt"); }
- '{' enum_substmts '}'
+ { if (ysp_add_push(_yy, Y_ENUM, $2, NULL) == NULL) _YYERROR("enum_stmt"); }
+ '{' enum_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("enum_stmt");
- _PARSE_DEBUG("enum-stmt -> ENUM string { enum-substmts }"); }
+ _PARSE_DEBUG("enum-stmt -> ENUM string { enum-substmts }"); }
;
enum_substmts : enum_substmts enum_substmt
@@ -901,24 +901,24 @@ enum_substmt : if_feature_stmt { _PARSE_DEBUG("enum-substmt -> if-feature-
;
path_stmt : K_PATH string stmtend /* XXX: path-arg-str */
- { if (ysp_add(_yy, Y_PATH, $2, NULL)== NULL) _YYERROR("path_stmt");
+ { if (ysp_add(_yy, Y_PATH, $2, NULL)== NULL) _YYERROR("path_stmt");
_PARSE_DEBUG("path-stmt -> PATH string"); }
;
require_instance_stmt : K_REQUIRE_INSTANCE bool_str stmtend
- { if (ysp_add(_yy, Y_REQUIRE_INSTANCE, $2, NULL)== NULL) _YYERROR("require_instance_stmt");
+ { if (ysp_add(_yy, Y_REQUIRE_INSTANCE, $2, NULL)== NULL) _YYERROR("require_instance_stmt");
_PARSE_DEBUG("require-instance-stmt -> REQUIRE-INSTANCE string"); }
;
/* bit-stmt */
bit_stmt : K_BIT identifier_str ';'
- { if (ysp_add(_yy, Y_BIT, $2, NULL) == NULL) _YYERROR("bit_stmt");
- _PARSE_DEBUG("bit-stmt -> BIT string ;"); }
+ { if (ysp_add(_yy, Y_BIT, $2, NULL) == NULL) _YYERROR("bit_stmt");
+ _PARSE_DEBUG("bit-stmt -> BIT string ;"); }
| K_BIT identifier_str
- { if (ysp_add_push(_yy, Y_BIT, $2, NULL) == NULL) _YYERROR("bit_stmt"); }
- '{' bit_substmts '}'
+ { if (ysp_add_push(_yy, Y_BIT, $2, NULL) == NULL) _YYERROR("bit_stmt"); }
+ '{' bit_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("bit_stmt");
- _PARSE_DEBUG("bit-stmt -> BIT string { bit-substmts }"); }
+ _PARSE_DEBUG("bit-stmt -> BIT string { bit-substmts }"); }
;
bit_substmts : bit_substmts bit_substmt
@@ -937,51 +937,51 @@ bit_substmt : if_feature_stmt { _PARSE_DEBUG("bit-substmt -> if-feature-s
/* position-stmt = position-keyword position-value-arg-str */
position_stmt : K_POSITION integer_value_str stmtend
- { if (ysp_add(_yy, Y_POSITION, $2, NULL) == NULL) _YYERROR("position_stmt");
+ { if (ysp_add(_yy, Y_POSITION, $2, NULL) == NULL) _YYERROR("position_stmt");
_PARSE_DEBUG("position-stmt -> POSITION integer-value"); }
;
/* status-stmt = status-keyword sep status-arg-str XXX: current-keyword*/
status_stmt : K_STATUS string stmtend
- { if (ysp_add(_yy, Y_STATUS, $2, NULL) == NULL) _YYERROR("status_stmt");
+ { if (ysp_add(_yy, Y_STATUS, $2, NULL) == NULL) _YYERROR("status_stmt");
_PARSE_DEBUG("status-stmt -> STATUS string"); }
;
config_stmt : K_CONFIG bool_str stmtend
- { if (ysp_add(_yy, Y_CONFIG, $2, NULL) == NULL) _YYERROR("config_stmt");
+ { if (ysp_add(_yy, Y_CONFIG, $2, NULL) == NULL) _YYERROR("config_stmt");
_PARSE_DEBUG("config-stmt -> CONFIG config-arg-str"); }
;
/* mandatory-stmt = mandatory-keyword mandatory-arg-str */
mandatory_stmt : K_MANDATORY bool_str stmtend
{ yang_stmt *ys;
- if ((ys = ysp_add(_yy, Y_MANDATORY, $2, NULL))== NULL) _YYERROR("mandatory_stmt");
- _PARSE_DEBUG("mandatory-stmt -> MANDATORY mandatory-arg-str ;");}
+ if ((ys = ysp_add(_yy, Y_MANDATORY, $2, NULL))== NULL) _YYERROR("mandatory_stmt");
+ _PARSE_DEBUG("mandatory-stmt -> MANDATORY mandatory-arg-str ;");}
;
presence_stmt : K_PRESENCE string stmtend
{ yang_stmt *ys;
- if ((ys = ysp_add(_yy, Y_PRESENCE, $2, NULL))== NULL) _YYERROR("presence_stmt");
- _PARSE_DEBUG("presence-stmt -> PRESENCE string ;");}
+ if ((ys = ysp_add(_yy, Y_PRESENCE, $2, NULL))== NULL) _YYERROR("presence_stmt");
+ _PARSE_DEBUG("presence-stmt -> PRESENCE string ;");}
;
/* ordered-by-stmt = ordered-by-keyword sep ordered-by-arg-str */
ordered_by_stmt : K_ORDERED_BY string stmtend
{ yang_stmt *ys;
- if ((ys = ysp_add(_yy, Y_ORDERED_BY, $2, NULL))== NULL) _YYERROR("ordered_by_stmt");
- _PARSE_DEBUG("ordered-by-stmt -> ORDERED-BY ordered-by-arg ;");}
+ if ((ys = ysp_add(_yy, Y_ORDERED_BY, $2, NULL))== NULL) _YYERROR("ordered_by_stmt");
+ _PARSE_DEBUG("ordered-by-stmt -> ORDERED-BY ordered-by-arg ;");}
;
/* must-stmt */
must_stmt : K_MUST string ';'
- { if (ysp_add(_yy, Y_MUST, $2, NULL) == NULL) _YYERROR("must_stmt");
- _PARSE_DEBUG("must-stmt -> MUST string ;"); }
+ { if (ysp_add(_yy, Y_MUST, $2, NULL) == NULL) _YYERROR("must_stmt");
+ _PARSE_DEBUG("must-stmt -> MUST string ;"); }
| K_MUST string
- { if (ysp_add_push(_yy, Y_MUST, $2, NULL) == NULL) _YYERROR("must_stmt"); }
- '{' must_substmts '}'
+ { if (ysp_add_push(_yy, Y_MUST, $2, NULL) == NULL) _YYERROR("must_stmt"); }
+ '{' must_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("must_stmt");
- _PARSE_DEBUG("must-stmt -> MUST string { must-substmts }"); }
+ _PARSE_DEBUG("must-stmt -> MUST string { must-substmts }"); }
;
must_substmts : must_substmts must_substmt
@@ -999,40 +999,40 @@ must_substmt : error_message_stmt { _PARSE_DEBUG("must-substmt -> error-messa
/* error-message-stmt */
error_message_stmt : K_ERROR_MESSAGE string stmtend
- { if (ysp_add(_yy, Y_ERROR_MESSAGE, $2, NULL) == NULL) _YYERROR("error_message_stmt");
- _PARSE_DEBUG("error-message-stmt -> ERROR-MESSAGE string"); }
+ { if (ysp_add(_yy, Y_ERROR_MESSAGE, $2, NULL) == NULL) _YYERROR("error_message_stmt");
+ _PARSE_DEBUG("error-message-stmt -> ERROR-MESSAGE string"); }
;
error_app_tag_stmt : K_ERROR_APP_TAG string stmtend
- { if (ysp_add(_yy, Y_ERROR_MESSAGE, $2, NULL) == NULL) _YYERROR("error_message_stmt");
- _PARSE_DEBUG("error-app-tag-stmt -> ERROR-APP-TAG string"); }
+ { if (ysp_add(_yy, Y_ERROR_MESSAGE, $2, NULL) == NULL) _YYERROR("error_message_stmt");
+ _PARSE_DEBUG("error-app-tag-stmt -> ERROR-APP-TAG string"); }
;
/* min-elements-stmt = min-elements-keyword min-value-arg-str */
min_elements_stmt : K_MIN_ELEMENTS integer_value_str stmtend
- { if (ysp_add(_yy, Y_MIN_ELEMENTS, $2, NULL)== NULL) _YYERROR("min_elements_stmt");
- _PARSE_DEBUG("min-elements-stmt -> MIN-ELEMENTS integer ;");}
+ { if (ysp_add(_yy, Y_MIN_ELEMENTS, $2, NULL)== NULL) _YYERROR("min_elements_stmt");
+ _PARSE_DEBUG("min-elements-stmt -> MIN-ELEMENTS integer ;");}
;
/* max-elements-stmt = max-elements-keyword ("unbounded"|integer-value)
* XXX cannot use integer-value
*/
max_elements_stmt : K_MAX_ELEMENTS string stmtend
- { if (ysp_add(_yy, Y_MAX_ELEMENTS, $2, NULL)== NULL) _YYERROR("max_elements_stmt");
- _PARSE_DEBUG("max-elements-stmt -> MIN-ELEMENTS integer ;");}
+ { if (ysp_add(_yy, Y_MAX_ELEMENTS, $2, NULL)== NULL) _YYERROR("max_elements_stmt");
+ _PARSE_DEBUG("max-elements-stmt -> MIN-ELEMENTS integer ;");}
;
value_stmt : K_VALUE integer_value_str stmtend
- { if (ysp_add(_yy, Y_VALUE, $2, NULL) == NULL) _YYERROR("value_stmt");
+ { if (ysp_add(_yy, Y_VALUE, $2, NULL) == NULL) _YYERROR("value_stmt");
_PARSE_DEBUG("value-stmt -> VALUE integer-value"); }
;
/* Grouping */
grouping_stmt : K_GROUPING identifier_str
{ if (ysp_add_push(_yy, Y_GROUPING, $2, NULL) == NULL) _YYERROR("grouping_stmt"); }
- '{' grouping_substmts '}'
+ '{' grouping_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("grouping_stmt");
- _PARSE_DEBUG("grouping-stmt -> GROUPING id-arg-str { grouping-substmts }"); }
+ _PARSE_DEBUG("grouping-stmt -> GROUPING id-arg-str { grouping-substmts }"); }
;
grouping_substmts : grouping_substmts grouping_substmt
@@ -1056,10 +1056,10 @@ grouping_substmt : status_stmt { _PARSE_DEBUG("grouping-substmt -> status-
/* container */
container_stmt : K_CONTAINER identifier_str ';'
- { if (ysp_add(_yy, Y_CONTAINER, $2, NULL) == NULL) _YYERROR("container_stmt");
+ { if (ysp_add(_yy, Y_CONTAINER, $2, NULL) == NULL) _YYERROR("container_stmt");
_PARSE_DEBUG("container-stmt -> CONTAINER id-arg-str ;");}
| K_CONTAINER identifier_str
- { if (ysp_add_push(_yy, Y_CONTAINER, $2, NULL) == NULL) _YYERROR("container_stmt"); }
+ { if (ysp_add_push(_yy, Y_CONTAINER, $2, NULL) == NULL) _YYERROR("container_stmt"); }
'{' container_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("container_stmt");
_PARSE_DEBUG("container-stmt -> CONTAINER id-arg-str { container-substmts }");}
@@ -1087,10 +1087,10 @@ container_substmt : when_stmt { _PARSE_DEBUG("container-substmt -> when-st
;
leaf_stmt : K_LEAF identifier_str ';'
- { if (ysp_add(_yy, Y_LEAF, $2, NULL) == NULL) _YYERROR("leaf_stmt");
- _PARSE_DEBUG("leaf-stmt -> LEAF id-arg-str ;");}
+ { if (ysp_add(_yy, Y_LEAF, $2, NULL) == NULL) _YYERROR("leaf_stmt");
+ _PARSE_DEBUG("leaf-stmt -> LEAF id-arg-str ;");}
| K_LEAF identifier_str
- { if (ysp_add_push(_yy, Y_LEAF, $2, NULL) == NULL) _YYERROR("leaf_stmt"); }
+ { if (ysp_add_push(_yy, Y_LEAF, $2, NULL) == NULL) _YYERROR("leaf_stmt"); }
'{' leaf_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("leaf_stmt");
_PARSE_DEBUG("leaf-stmt -> LEAF id-arg-str { lead-substmts }");}
@@ -1117,10 +1117,10 @@ leaf_substmt : when_stmt { _PARSE_DEBUG("leaf-substmt -> when-stmt")
/* leaf-list */
leaf_list_stmt : K_LEAF_LIST identifier_str ';'
- { if (ysp_add(_yy, Y_LEAF_LIST, $2, NULL) == NULL) _YYERROR("leaf_list_stmt");
- _PARSE_DEBUG("leaf-list-stmt -> LEAF id-arg-str ;");}
+ { if (ysp_add(_yy, Y_LEAF_LIST, $2, NULL) == NULL) _YYERROR("leaf_list_stmt");
+ _PARSE_DEBUG("leaf-list-stmt -> LEAF id-arg-str ;");}
| K_LEAF_LIST identifier_str
- { if (ysp_add_push(_yy, Y_LEAF_LIST, $2, NULL) == NULL) _YYERROR("leaf_list_stmt"); }
+ { if (ysp_add_push(_yy, Y_LEAF_LIST, $2, NULL) == NULL) _YYERROR("leaf_list_stmt"); }
'{' leaf_list_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("leaf_list_stmt");
_PARSE_DEBUG("leaf-list-stmt -> LEAF-LIST id-arg-str { lead-substmts }");}
@@ -1148,13 +1148,13 @@ leaf_list_substmt : when_stmt { _PARSE_DEBUG("leaf-list-substmt -> when-s
;
list_stmt : K_LIST identifier_str ';'
- { if (ysp_add(_yy, Y_LIST, $2, NULL) == NULL) _YYERROR("list_stmt");
- _PARSE_DEBUG("list-stmt -> LIST id-arg-str ;"); }
+ { if (ysp_add(_yy, Y_LIST, $2, NULL) == NULL) _YYERROR("list_stmt");
+ _PARSE_DEBUG("list-stmt -> LIST id-arg-str ;"); }
| K_LIST identifier_str
- { if (ysp_add_push(_yy, Y_LIST, $2, NULL) == NULL) _YYERROR("list_stmt"); }
- '{' list_substmts '}'
+ { if (ysp_add_push(_yy, Y_LIST, $2, NULL) == NULL) _YYERROR("list_stmt"); }
+ '{' list_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("list_stmt");
- _PARSE_DEBUG("list-stmt -> LIST id-arg-str { list-substmts }"); }
+ _PARSE_DEBUG("list-stmt -> LIST id-arg-str { list-substmts }"); }
;
list_substmts : list_substmts list_substmt
@@ -1186,25 +1186,25 @@ list_substmt : when_stmt { _PARSE_DEBUG("list-substmt -> when-stmt")
/* key-stmt = key-keyword sep key-arg-str */
key_stmt : K_KEY string stmtend
- { if (ysp_add(_yy, Y_KEY, $2, NULL)== NULL) _YYERROR("key_stmt");
- _PARSE_DEBUG("key-stmt -> KEY id-arg-str ;");}
+ { if (ysp_add(_yy, Y_KEY, $2, NULL)== NULL) _YYERROR("key_stmt");
+ _PARSE_DEBUG("key-stmt -> KEY id-arg-str ;");}
;
/* unique-stmt = unique-keyword unique-arg-str */
unique_stmt : K_UNIQUE string stmtend
- { if (ysp_add(_yy, Y_UNIQUE, $2, NULL)== NULL) _YYERROR("unique_stmt");
- _PARSE_DEBUG("key-stmt -> KEY id-arg-str ;");}
+ { if (ysp_add(_yy, Y_UNIQUE, $2, NULL)== NULL) _YYERROR("unique_stmt");
+ _PARSE_DEBUG("key-stmt -> KEY id-arg-str ;");}
;
/* choice */
choice_stmt : K_CHOICE identifier_str ';'
- { if (ysp_add(_yy, Y_CHOICE, $2, NULL) == NULL) _YYERROR("choice_stmt");
- _PARSE_DEBUG("choice-stmt -> CHOICE id-arg-str ;"); }
+ { if (ysp_add(_yy, Y_CHOICE, $2, NULL) == NULL) _YYERROR("choice_stmt");
+ _PARSE_DEBUG("choice-stmt -> CHOICE id-arg-str ;"); }
| K_CHOICE identifier_str
- { if (ysp_add_push(_yy, Y_CHOICE, $2, NULL) == NULL) _YYERROR("choice_stmt"); }
- '{' choice_substmts '}'
+ { if (ysp_add_push(_yy, Y_CHOICE, $2, NULL) == NULL) _YYERROR("choice_stmt"); }
+ '{' choice_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("choice_stmt");
- _PARSE_DEBUG("choice-stmt -> CHOICE id-arg-str { choice-substmts }"); }
+ _PARSE_DEBUG("choice-stmt -> CHOICE id-arg-str { choice-substmts }"); }
;
choice_substmts : choice_substmts choice_substmt
@@ -1229,13 +1229,13 @@ choice_substmt : when_stmt { _PARSE_DEBUG("choice-substmt -> when-stmt
/* case */
case_stmt : K_CASE identifier_str ';'
- { if (ysp_add(_yy, Y_CASE, $2, NULL) == NULL) _YYERROR("case_stmt");
- _PARSE_DEBUG("case-stmt -> CASE id-arg-str ;"); }
+ { if (ysp_add(_yy, Y_CASE, $2, NULL) == NULL) _YYERROR("case_stmt");
+ _PARSE_DEBUG("case-stmt -> CASE id-arg-str ;"); }
| K_CASE identifier_str
- { if (ysp_add_push(_yy, Y_CASE, $2, NULL) == NULL) _YYERROR("case_stmt"); }
- '{' case_substmts '}'
+ { if (ysp_add_push(_yy, Y_CASE, $2, NULL) == NULL) _YYERROR("case_stmt"); }
+ '{' case_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("case_stmt");
- _PARSE_DEBUG("case-stmt -> CASE id-arg-str { case-substmts }"); }
+ _PARSE_DEBUG("case-stmt -> CASE id-arg-str { case-substmts }"); }
;
case_substmts : case_substmts case_substmt
@@ -1255,24 +1255,24 @@ case_substmt : when_stmt { _PARSE_DEBUG("case-substmt -> when-stmt")
;
anydata_stmt : K_ANYDATA identifier_str ';'
- { if (ysp_add(_yy, Y_ANYDATA, $2, NULL) == NULL) _YYERROR("anydata_stmt");
- _PARSE_DEBUG("anydata-stmt -> ANYDATA id-arg-str ;"); }
+ { if (ysp_add(_yy, Y_ANYDATA, $2, NULL) == NULL) _YYERROR("anydata_stmt");
+ _PARSE_DEBUG("anydata-stmt -> ANYDATA id-arg-str ;"); }
| K_ANYDATA identifier_str
- { if (ysp_add_push(_yy, Y_ANYDATA, $2, NULL) == NULL) _YYERROR("anydata_stmt"); }
- '{' anyxml_substmts '}'
+ { if (ysp_add_push(_yy, Y_ANYDATA, $2, NULL) == NULL) _YYERROR("anydata_stmt"); }
+ '{' anyxml_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("anydata_stmt");
- _PARSE_DEBUG("anydata-stmt -> ANYDATA id-arg-str { anyxml-substmts }"); }
+ _PARSE_DEBUG("anydata-stmt -> ANYDATA id-arg-str { anyxml-substmts }"); }
;
/* anyxml */
anyxml_stmt : K_ANYXML identifier_str ';'
- { if (ysp_add(_yy, Y_ANYXML, $2, NULL) == NULL) _YYERROR("anyxml_stmt");
- _PARSE_DEBUG("anyxml-stmt -> ANYXML id-arg-str ;"); }
+ { if (ysp_add(_yy, Y_ANYXML, $2, NULL) == NULL) _YYERROR("anyxml_stmt");
+ _PARSE_DEBUG("anyxml-stmt -> ANYXML id-arg-str ;"); }
| K_ANYXML identifier_str
- { if (ysp_add_push(_yy, Y_ANYXML, $2, NULL) == NULL) _YYERROR("anyxml_stmt"); }
- '{' anyxml_substmts '}'
+ { if (ysp_add_push(_yy, Y_ANYXML, $2, NULL) == NULL) _YYERROR("anyxml_stmt"); }
+ '{' anyxml_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("anyxml_stmt");
- _PARSE_DEBUG("anyxml-stmt -> ANYXML id-arg-str { anyxml-substmts }"); }
+ _PARSE_DEBUG("anyxml-stmt -> ANYXML id-arg-str { anyxml-substmts }"); }
;
anyxml_substmts : anyxml_substmts anyxml_substmt
@@ -1290,19 +1290,19 @@ anyxml_substmt : when_stmt { _PARSE_DEBUG("anyxml-substmt -> when-stmt
| description_stmt { _PARSE_DEBUG("anyxml-substmt -> description-stmt"); }
| reference_stmt { _PARSE_DEBUG("anyxml-substmt -> reference-stmt"); }
| ustring ':' ustring ';' { free($1); free($3);
- _PARSE_DEBUG("anyxml-substmt -> anyxml extension"); }
+ _PARSE_DEBUG("anyxml-substmt -> anyxml extension"); }
| unknown_stmt { _PARSE_DEBUG("anyxml-substmt -> unknown-stmt");}
;
/* uses-stmt = uses-keyword identifier-ref-arg-str */
uses_stmt : K_USES identifier_ref_arg_str ';'
- { if (ysp_add(_yy, Y_USES, $2, NULL) == NULL) _YYERROR("uses_stmt");
- _PARSE_DEBUG("uses-stmt -> USES identifier-ref-arg-str ;"); }
+ { if (ysp_add(_yy, Y_USES, $2, NULL) == NULL) _YYERROR("uses_stmt");
+ _PARSE_DEBUG("uses-stmt -> USES identifier-ref-arg-str ;"); }
| K_USES identifier_ref_arg_str
- { if (ysp_add_push(_yy, Y_USES, $2, NULL) == NULL) _YYERROR("uses_stmt"); }
- '{' uses_substmts '}'
+ { if (ysp_add_push(_yy, Y_USES, $2, NULL) == NULL) _YYERROR("uses_stmt"); }
+ '{' uses_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("uses_stmt");
- _PARSE_DEBUG("uses-stmt -> USES identifier-ref-arg-str { uses-substmts }"); }
+ _PARSE_DEBUG("uses-stmt -> USES identifier-ref-arg-str { uses-substmts }"); }
;
uses_substmts : uses_substmts uses_substmt
@@ -1324,19 +1324,19 @@ uses_substmt : when_stmt { _PARSE_DEBUG("uses-substmt -> when-stmt")
/* refine-stmt = refine-keyword sep refine-arg-str */
refine_stmt : K_REFINE refine_arg_str ';'
- { if (ysp_add(_yy, Y_REFINE, $2, NULL) == NULL) _YYERROR("refine_stmt");
- _PARSE_DEBUG("refine-stmt -> REFINE id-arg-str ;"); }
+ { if (ysp_add(_yy, Y_REFINE, $2, NULL) == NULL) _YYERROR("refine_stmt");
+ _PARSE_DEBUG("refine-stmt -> REFINE id-arg-str ;"); }
| K_REFINE refine_arg_str '{'
- { if (ysp_add_push(_yy, Y_REFINE, $2, NULL) == NULL) _YYERROR("refine_stmt"); }
- refine_substmts '}'
+ { if (ysp_add_push(_yy, Y_REFINE, $2, NULL) == NULL) _YYERROR("refine_stmt"); }
+ refine_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("refine_stmt");
- _PARSE_DEBUG("refine-stmt -> REFINE id-arg-str { refine-substmts }"); }
+ _PARSE_DEBUG("refine-stmt -> REFINE id-arg-str { refine-substmts }"); }
;
refine_substmts : refine_substmts refine_substmt
{ _PARSE_DEBUG("refine-substmts -> refine-substmts refine-substmt"); }
| refine_substmt
- { _PARSE_DEBUG("refine-substmts -> refine-substmt"); }
+ { _PARSE_DEBUG("refine-substmts -> refine-substmt"); }
;
refine_substmt : if_feature_stmt { _PARSE_DEBUG("refine-substmt -> if-feature-stmt"); }
@@ -1358,7 +1358,7 @@ refine_substmt : if_feature_stmt { _PARSE_DEBUG("refine-substmt -> if-feature-
*/
refine_arg_str : string
{ $$ = $1;
- _PARSE_DEBUG("refine-arg-str -> < a string that matches the rule refine-arg >"); }
+ _PARSE_DEBUG("refine-arg-str -> < a string that matches the rule refine-arg >"); }
;
/* uses-augment-stmt = augment-keyword uses-augment-arg-str
@@ -1368,17 +1368,17 @@ uses_augment_stmt : K_AUGMENT uses_augment_arg_str
{ if (ysp_add_push(_yy, Y_AUGMENT, $2, NULL) == NULL) _YYERROR("uses_augment_stmt"); }
'{' augment_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("uses_augment_stmt");
- _PARSE_DEBUG("uses-augment-stmt -> AUGMENT uses-augment-arg-str { augment-substmts }"); }
-
+ _PARSE_DEBUG("uses-augment-stmt -> AUGMENT uses-augment-arg-str { augment-substmts }"); }
+
/* augment-stmt = augment-keyword sep augment-arg-str
* augment_stmt : K_AUGMENT abs_schema_nodeid_strs
* Same keyword as in uses-augment-stmt, but here is sub of (sub)module
*/
augment_stmt : K_AUGMENT augment_arg_str
{ if (ysp_add_push(_yy, Y_AUGMENT, $2, NULL) == NULL) _YYERROR("augment_stmt"); }
- '{' augment_substmts '}'
+ '{' augment_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("augment_stmt");
- _PARSE_DEBUG("augment-stmt -> AUGMENT abs-schema-node-str { augment-substmts }"); }
+ _PARSE_DEBUG("augment-stmt -> AUGMENT abs-schema-node-str { augment-substmts }"); }
;
augment_substmts : augment_substmts augment_substmt
@@ -1405,7 +1405,7 @@ augment_substmt : when_stmt { _PARSE_DEBUG("augment-substmt -> when-stm
*/
augment_arg_str : string
{ $$ = $1;
- _PARSE_DEBUG("augment-arg-str -> < a string that matches the rule augment-arg >"); }
+ _PARSE_DEBUG("augment-arg-str -> < a string that matches the rule augment-arg >"); }
;
/* uses-augment-arg-str = < a string that matches the rule uses-augment-arg >
@@ -1413,18 +1413,18 @@ augment_arg_str : string
*/
uses_augment_arg_str : string
{ $$ = $1;
- _PARSE_DEBUG("uses-augment-arg-str -> < a string that matches the rule uses-augment-arg >"); }
+ _PARSE_DEBUG("uses-augment-arg-str -> < a string that matches the rule uses-augment-arg >"); }
;
/* when */
when_stmt : K_WHEN string ';'
- { if (ysp_add(_yy, Y_WHEN, $2, NULL) == NULL) _YYERROR("when_stmt");
- _PARSE_DEBUG("when-stmt -> WHEN string ;"); }
+ { if (ysp_add(_yy, Y_WHEN, $2, NULL) == NULL) _YYERROR("when_stmt");
+ _PARSE_DEBUG("when-stmt -> WHEN string ;"); }
| K_WHEN string
- { if (ysp_add_push(_yy, Y_WHEN, $2, NULL) == NULL) _YYERROR("when_stmt"); }
- '{' when_substmts '}'
+ { if (ysp_add_push(_yy, Y_WHEN, $2, NULL) == NULL) _YYERROR("when_stmt"); }
+ '{' when_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("when_stmt");
- _PARSE_DEBUG("when-stmt -> WHEN string { when-substmts }"); }
+ _PARSE_DEBUG("when-stmt -> WHEN string { when-substmts }"); }
;
when_substmts : when_substmts when_substmt
@@ -1440,13 +1440,13 @@ when_substmt : description_stmt { _PARSE_DEBUG("when-substmt -> description-stm
/* rpc */
rpc_stmt : K_RPC identifier_str ';'
- { if (ysp_add(_yy, Y_RPC, $2, NULL) == NULL) _YYERROR("rpc_stmt");
- _PARSE_DEBUG("rpc-stmt -> RPC id-arg-str ;"); }
+ { if (ysp_add(_yy, Y_RPC, $2, NULL) == NULL) _YYERROR("rpc_stmt");
+ _PARSE_DEBUG("rpc-stmt -> RPC id-arg-str ;"); }
| K_RPC identifier_str
- { if (ysp_add_push(_yy, Y_RPC, $2, NULL) == NULL) _YYERROR("rpc_stmt"); }
- '{' rpc_substmts '}'
+ { if (ysp_add_push(_yy, Y_RPC, $2, NULL) == NULL) _YYERROR("rpc_stmt"); }
+ '{' rpc_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("rpc_stmt");
- _PARSE_DEBUG("rpc-stmt -> RPC id-arg-str { rpc-substmts }"); }
+ _PARSE_DEBUG("rpc-stmt -> RPC id-arg-str { rpc-substmts }"); }
;
rpc_substmts : rpc_substmts rpc_substmt
@@ -1469,24 +1469,24 @@ rpc_substmt : if_feature_stmt { _PARSE_DEBUG("rpc-substmt -> if-feature-stmt"
/* action */
action_stmt : K_ACTION identifier_str ';'
- { if (ysp_add(_yy, Y_ACTION, $2, NULL) == NULL) _YYERROR("action_stmt");
- _PARSE_DEBUG("action-stmt -> ACTION id-arg-str ;"); }
+ { if (ysp_add(_yy, Y_ACTION, $2, NULL) == NULL) _YYERROR("action_stmt");
+ _PARSE_DEBUG("action-stmt -> ACTION id-arg-str ;"); }
| K_ACTION identifier_str
- { if (ysp_add_push(_yy, Y_ACTION, $2, NULL) == NULL) _YYERROR("action_stmt"); }
- '{' rpc_substmts '}'
+ { if (ysp_add_push(_yy, Y_ACTION, $2, NULL) == NULL) _YYERROR("action_stmt"); }
+ '{' rpc_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("action_stmt");
- _PARSE_DEBUG("action-stmt -> ACTION id-arg-str { rpc-substmts }"); }
+ _PARSE_DEBUG("action-stmt -> ACTION id-arg-str { rpc-substmts }"); }
;
/* notification */
notification_stmt : K_NOTIFICATION identifier_str ';'
- { if (ysp_add(_yy, Y_NOTIFICATION, $2, NULL) == NULL) _YYERROR("notification_stmt");
- _PARSE_DEBUG("notification-stmt -> NOTIFICATION id-arg-str ;"); }
+ { if (ysp_add(_yy, Y_NOTIFICATION, $2, NULL) == NULL) _YYERROR("notification_stmt");
+ _PARSE_DEBUG("notification-stmt -> NOTIFICATION id-arg-str ;"); }
| K_NOTIFICATION identifier_str
- { if (ysp_add_push(_yy, Y_NOTIFICATION, $2, NULL) == NULL) _YYERROR("notification_stmt"); }
- '{' notification_substmts '}'
+ { if (ysp_add_push(_yy, Y_NOTIFICATION, $2, NULL) == NULL) _YYERROR("notification_stmt"); }
+ '{' notification_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("notification_stmt");
- _PARSE_DEBUG("notification-stmt -> NOTIFICATION id-arg-str { notification-substmts }"); }
+ _PARSE_DEBUG("notification-stmt -> NOTIFICATION id-arg-str { notification-substmts }"); }
;
notification_substmts : notification_substmts notification_substmt
@@ -1509,9 +1509,9 @@ notification_substmt : if_feature_stmt { _PARSE_DEBUG("notification-substmt ->
deviation_stmt : K_DEVIATION string
{ if (ysp_add_push(_yy, Y_DEVIATION, $2, NULL) == NULL) _YYERROR("deviation_stmt"); }
- '{' deviation_substmts '}'
+ '{' deviation_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("deviation_stmt");
- _PARSE_DEBUG("deviation-stmt -> DEVIATION id-arg-str { notification-substmts }"); }
+ _PARSE_DEBUG("deviation-stmt -> DEVIATION id-arg-str { notification-substmts }"); }
;
deviation_substmts : deviation_substmts deviation_substmt
@@ -1526,7 +1526,7 @@ deviation_substmt : description_stmt { _PARSE_DEBUG("deviation-substmt -> descr
| deviate_add_stmt { _PARSE_DEBUG("deviation-stmt -> deviate-add-stmt");}
| deviate_delete_stmt { _PARSE_DEBUG("deviation-stmt -> deviate-delete-stmt");}
| deviate_replace_stmt { _PARSE_DEBUG("deviation-stmt -> deviate-replace-stmt");}
- ;
+ ;
not_supported_keyword_str : D_NOT_SUPPORTED
| '"' D_NOT_SUPPORTED '"'
@@ -1535,8 +1535,8 @@ not_supported_keyword_str : D_NOT_SUPPORTED
deviate_not_supported_stmt
: K_DEVIATE not_supported_keyword_str ';'
- { if (ysp_add(_yy, Y_DEVIATE, strdup("not-supported"), NULL) == NULL) _YYERROR("notification_stmt");
- _PARSE_DEBUG("deviate-not-supported-stmt -> DEVIATE not-supported ;"); }
+ { if (ysp_add(_yy, Y_DEVIATE, strdup("not-supported"), NULL) == NULL) _YYERROR("notification_stmt");
+ _PARSE_DEBUG("deviate-not-supported-stmt -> DEVIATE not-supported ;"); }
;
add_keyword_str : D_ADD
@@ -1546,12 +1546,12 @@ add_keyword_str : D_ADD
deviate_add_stmt : K_DEVIATE add_keyword_str ';'
{ if (ysp_add(_yy, Y_DEVIATE, strdup("add"), NULL) == NULL) _YYERROR("notification_stmt");
- _PARSE_DEBUG("deviate-add-stmt -> DEVIATE add ;"); }
+ _PARSE_DEBUG("deviate-add-stmt -> DEVIATE add ;"); }
| K_DEVIATE add_keyword_str
- { if (ysp_add_push(_yy, Y_DEVIATE, strdup("add"), NULL) == NULL) _YYERROR("deviate_stmt"); }
- '{' deviate_add_substmts '}'
+ { if (ysp_add_push(_yy, Y_DEVIATE, strdup("add"), NULL) == NULL) _YYERROR("deviate_stmt"); }
+ '{' deviate_add_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("deviate_stmt");
- _PARSE_DEBUG("deviate-add-stmt -> DEVIATE add { deviate-substmts }"); }
+ _PARSE_DEBUG("deviate-add-stmt -> DEVIATE add { deviate-substmts }"); }
;
deviate_add_substmts : deviate_add_substmts deviate_add_substmt
@@ -1578,12 +1578,12 @@ delete_keyword_str : D_DELETE
deviate_delete_stmt : K_DEVIATE delete_keyword_str ';'
{ if (ysp_add(_yy, Y_DEVIATE, strdup("delete"), NULL) == NULL) _YYERROR("notification_stmt");
- _PARSE_DEBUG("deviate-delete-stmt -> DEVIATE delete ;"); }
+ _PARSE_DEBUG("deviate-delete-stmt -> DEVIATE delete ;"); }
| K_DEVIATE delete_keyword_str
- { if (ysp_add_push(_yy, Y_DEVIATE, strdup("delete"), NULL) == NULL) _YYERROR("deviate_stmt"); }
- '{' deviate_delete_substmts '}'
+ { if (ysp_add_push(_yy, Y_DEVIATE, strdup("delete"), NULL) == NULL) _YYERROR("deviate_stmt"); }
+ '{' deviate_delete_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("deviate_stmt");
- _PARSE_DEBUG("deviate-delete-stmt -> DEVIATE delete { deviate-delete-substmts }"); }
+ _PARSE_DEBUG("deviate-delete-stmt -> DEVIATE delete { deviate-delete-substmts }"); }
;
deviate_delete_substmts : deviate_delete_substmts deviate_delete_substmt
@@ -1605,12 +1605,12 @@ replace_keyword_str : D_REPLACE
deviate_replace_stmt : K_DEVIATE replace_keyword_str ';'
{ if (ysp_add(_yy, Y_DEVIATE, strdup("replace"), NULL) == NULL) _YYERROR("notification_stmt");
- _PARSE_DEBUG("deviate-replace-stmt -> DEVIATE replace ;"); }
+ _PARSE_DEBUG("deviate-replace-stmt -> DEVIATE replace ;"); }
| K_DEVIATE replace_keyword_str
- { if (ysp_add_push(_yy, Y_DEVIATE, strdup("replace"), NULL) == NULL) _YYERROR("deviate_stmt"); }
- '{' deviate_replace_substmts '}'
+ { if (ysp_add_push(_yy, Y_DEVIATE, strdup("replace"), NULL) == NULL) _YYERROR("deviate_stmt"); }
+ '{' deviate_replace_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("deviate_stmt");
- _PARSE_DEBUG("deviate-replace-stmt -> DEVIATE replace { deviate-replace-substmts }"); }
+ _PARSE_DEBUG("deviate-replace-stmt -> DEVIATE replace { deviate-replace-substmts }"); }
;
deviate_replace_substmts : deviate_replace_substmts deviate_replace_substmt
@@ -1638,39 +1638,39 @@ deviate_replace_substmt : type_stmt { _PARSE_DEBUG("deviate-replace-subs
*/
unknown_stmt : ustring ':' ustring optsep ';'
{
- char *id;
- if ((id=clixon_string_del_join($1, ":", $3)) == NULL) _YYERROR("unknown_stmt");
- free($3);
- if (ysp_add(_yy, Y_UNKNOWN, id, NULL) == NULL) _YYERROR("unknown_stmt");
- _PARSE_DEBUG("unknown-stmt -> ustring : ustring ;");
- }
+ char *id;
+ if ((id=clixon_string_del_join($1, ":", $3)) == NULL) _YYERROR("unknown_stmt");
+ free($3);
+ if (ysp_add(_yy, Y_UNKNOWN, id, NULL) == NULL) _YYERROR("unknown_stmt");
+ _PARSE_DEBUG("unknown-stmt -> ustring : ustring ;");
+ }
| ustring ':' ustring sep string optsep ';'
- {
- char *id;
- if ((id=clixon_string_del_join($1, ":", $3)) == NULL) _YYERROR("unknown_stmt");
- free($3);
- if (ysp_add(_yy, Y_UNKNOWN, id, $5) == NULL){ _YYERROR("unknown_stmt"); }
- _PARSE_DEBUG("unknown-stmt -> ustring : ustring sep string ;");
- }
+ {
+ char *id;
+ if ((id=clixon_string_del_join($1, ":", $3)) == NULL) _YYERROR("unknown_stmt");
+ free($3);
+ if (ysp_add(_yy, Y_UNKNOWN, id, $5) == NULL){ _YYERROR("unknown_stmt"); }
+ _PARSE_DEBUG("unknown-stmt -> ustring : ustring sep string ;");
+ }
| ustring ':' ustring optsep
{
- char *id;
- if ((id=clixon_string_del_join($1, ":", $3)) == NULL) _YYERROR("unknown_stmt");
- free($3);
- if (ysp_add_push(_yy, Y_UNKNOWN, id, NULL) == NULL) _YYERROR("unknown_stmt"); }
- '{' unknown_substmts '}'
- { if (ystack_pop(_yy) < 0) _YYERROR("unknown_stmt");
- _PARSE_DEBUG("unknown-stmt -> ustring : ustring { yang-stmts }"); }
+ char *id;
+ if ((id=clixon_string_del_join($1, ":", $3)) == NULL) _YYERROR("unknown_stmt");
+ free($3);
+ if (ysp_add_push(_yy, Y_UNKNOWN, id, NULL) == NULL) _YYERROR("unknown_stmt"); }
+ '{' unknown_substmts '}'
+ { if (ystack_pop(_yy) < 0) _YYERROR("unknown_stmt");
+ _PARSE_DEBUG("unknown-stmt -> ustring : ustring { yang-stmts }"); }
| ustring ':' ustring sep string optsep
- {
- char *id;
- if ((id=clixon_string_del_join($1, ":", $3)) == NULL) _YYERROR("unknown_stmt");
- free($3);
- if (ysp_add_push(_yy, Y_UNKNOWN, id, $5) == NULL) _YYERROR("unknown_stmt"); }
- '{' unknown_substmts '}'
- { if (ystack_pop(_yy) < 0) _YYERROR("unknown_stmt");
- _PARSE_DEBUG("unknown-stmt -> ustring : ustring string { yang-stmts }"); }
- ;
+ {
+ char *id;
+ if ((id=clixon_string_del_join($1, ":", $3)) == NULL) _YYERROR("unknown_stmt");
+ free($3);
+ if (ysp_add_push(_yy, Y_UNKNOWN, id, $5) == NULL) _YYERROR("unknown_stmt"); }
+ '{' unknown_substmts '}'
+ { if (ystack_pop(_yy) < 0) _YYERROR("unknown_stmt");
+ _PARSE_DEBUG("unknown-stmt -> ustring : ustring string { yang-stmts }"); }
+ ;
unknown_substmts : unknown_substmts unknown_substmt
{ _PARSE_DEBUG("unknown-substmts -> unknown-substmts unknown-substmt"); }
@@ -1794,15 +1794,15 @@ short_case_stmt : container_stmt { _PARSE_DEBUG("short-case-substmt -> contain
/* input */
input_stmt : K_INPUT
{ if (ysp_add_push(_yy, Y_INPUT, NULL, NULL) == NULL) _YYERROR("input_stmt"); }
- '{' input_substmts '}'
+ '{' input_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("input_stmt");
- _PARSE_DEBUG("input-stmt -> INPUT { input-substmts }"); }
+ _PARSE_DEBUG("input-stmt -> INPUT { input-substmts }"); }
;
input_substmts : input_substmts input_substmt
{ _PARSE_DEBUG("input-substmts -> input-substmts input-substmt"); }
| input_substmt
- { _PARSE_DEBUG("input-substmts -> input-substmt"); }
+ { _PARSE_DEBUG("input-substmts -> input-substmt"); }
;
input_substmt : typedef_stmt { _PARSE_DEBUG("input-substmt -> typedef-stmt"); }
@@ -1814,64 +1814,64 @@ input_substmt : typedef_stmt { _PARSE_DEBUG("input-substmt -> typedef-st
/* output */
output_stmt : K_OUTPUT /* XXX reuse input-substatements since they are same */
{ if (ysp_add_push(_yy, Y_OUTPUT, NULL, NULL) == NULL) _YYERROR("output_stmt"); }
- '{' input_substmts '}'
+ '{' input_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("output_stmt");
- _PARSE_DEBUG("output-stmt -> OUTPUT { input-substmts }"); }
+ _PARSE_DEBUG("output-stmt -> OUTPUT { input-substmts }"); }
;
/* XXX this is not the "string" rule in Section 14, rather it is the string as described in 6.1
*/
string : qstrings { $$=$1;
- _PARSE_DEBUG("string -> qstrings"); }
+ _PARSE_DEBUG("string -> qstrings"); }
| ustring { $$=$1;
- _PARSE_DEBUG( "string -> ustring"); }
- ;
+ _PARSE_DEBUG( "string -> ustring"); }
+ ;
/* quoted string */
qstrings : qstrings '+' qstring
{
- int len = strlen($1);
- $$ = realloc($1, len + strlen($3) + 1);
- sprintf($$+len, "%s", $3);
- free($3);
- _PARSE_DEBUG("qstrings-> qstrings '+' qstring");
- }
+ int len = strlen($1);
+ $$ = realloc($1, len + strlen($3) + 1);
+ sprintf($$+len, "%s", $3);
+ free($3);
+ _PARSE_DEBUG("qstrings-> qstrings '+' qstring");
+ }
| qstring
{ $$=$1;
- _PARSE_DEBUG("qstrings-> qstring"); }
+ _PARSE_DEBUG("qstrings-> qstring"); }
;
qstring : '"' ustring '"' { $$=$2;
- _PARSE_DEBUG("qstring-> \" ustring \"");}
+ _PARSE_DEBUG("qstring-> \" ustring \"");}
| '"' '"' { $$=strdup("");
- _PARSE_DEBUG("qstring-> \" \"");}
+ _PARSE_DEBUG("qstring-> \" \"");}
| '\'' ustring '\'' { $$=$2;
- _PARSE_DEBUG("qstring-> ' ustring '"); }
+ _PARSE_DEBUG("qstring-> ' ustring '"); }
| '\'' '\'' { $$=strdup("");
- _PARSE_DEBUG("qstring-> ' '");}
+ _PARSE_DEBUG("qstring-> ' '");}
;
/* unquoted string */
ustring : ustring CHARS
{
- int len = strlen($1);
- $$ = realloc($1, len+strlen($2) + 1);
- sprintf($$+len, "%s", $2);
- _PARSE_DEBUG1("ustring-> string + CHARS(%s)", $2);
- free($2);
- }
+ int len = strlen($1);
+ $$ = realloc($1, len+strlen($2) + 1);
+ sprintf($$+len, "%s", $2);
+ _PARSE_DEBUG1("ustring-> string + CHARS(%s)", $2);
+ free($2);
+ }
| CHARS
- { _PARSE_DEBUG1("ustring-> CHARS(%s)", $1); $$=$1; }
+ { _PARSE_DEBUG1("ustring-> CHARS(%s)", $1); $$=$1; }
| ERRCHARS
{ _PARSE_DEBUG1("ustring-> ERRCHARS(%s)", $1); _YYERROR("Invalid string chars"); }
;
identifier_str : '"' IDENTIFIER '"' { $$ = $2;
- _PARSE_DEBUG("identifier_str -> \" IDENTIFIER \" ");}
+ _PARSE_DEBUG("identifier_str -> \" IDENTIFIER \" ");}
| '\'' IDENTIFIER '\'' { $$ = $2;
- _PARSE_DEBUG("identifier_str -> ' IDENTIFIER ' ");}
+ _PARSE_DEBUG("identifier_str -> ' IDENTIFIER ' ");}
| IDENTIFIER { $$ = $1;
- _PARSE_DEBUG("identifier_str -> IDENTIFIER ");}
+ _PARSE_DEBUG("identifier_str -> IDENTIFIER ");}
;
integer_value_str : '"' INT '"' { $$=$2; }
@@ -1880,11 +1880,11 @@ integer_value_str : '"' INT '"' { $$=$2; }
;
bool_str : '"' BOOL '"' { $$ = $2;
- _PARSE_DEBUG("bool_str -> \" BOOL \" ");}
+ _PARSE_DEBUG("bool_str -> \" BOOL \" ");}
| '\'' BOOL '\'' { $$ = $2;
- _PARSE_DEBUG("bool_str -> ' BOOL ' ");}
+ _PARSE_DEBUG("bool_str -> ' BOOL ' ");}
| BOOL { $$ = $1;
- _PARSE_DEBUG("bool_str -> BOOL ");}
+ _PARSE_DEBUG("bool_str -> BOOL ");}
;
@@ -1895,7 +1895,7 @@ bool_str : '"' BOOL '"' { $$ = $2;
*/
identifier_ref_arg_str : string
{ $$ = $1;
- _PARSE_DEBUG("identifier-ref-arg-str -> < a string that matches the rule identifier-ref-arg >"); }
+ _PARSE_DEBUG("identifier-ref-arg-str -> < a string that matches the rule identifier-ref-arg >"); }
;
/* optsep = *(WSP / line-break) */
diff --git a/lib/src/clixon_yang_parse_lib.c b/lib/src/clixon_yang_parse_lib.c
index 01b16bc3..9d10a524 100644
--- a/lib/src/clixon_yang_parse_lib.c
+++ b/lib/src/clixon_yang_parse_lib.c
@@ -110,8 +110,8 @@ static int yang_expand_grouping(yang_stmt *yn);
*/
static yang_stmt *
ys_grouping_module_resolve(yang_stmt *ymod,
- yang_stmt *yspec,
- char *name)
+ yang_stmt *yspec,
+ char *name)
{
yang_stmt *yinc;
yang_stmt *ysubm;
@@ -121,27 +121,27 @@ ys_grouping_module_resolve(yang_stmt *ymod,
/* Find grouping from own sub/module */
if ((ygrouping = yang_find(ymod, Y_GROUPING, name)) != NULL)
- goto done;
+ goto done;
/* Find top-level module */
if (ys_real_module(ymod, &yrealmod) < 0)
- goto done;
+ goto done;
if (yrealmod == ymod) /* skip if module, continue if submodule */
- goto done;
+ goto done;
/* Find grouping from real module */
if ((ygrouping = yang_find(yrealmod, Y_GROUPING, name)) != NULL)
- goto done;
+ goto done;
/* Find grouping from sub-modules */
yinc = NULL;
while ((yinc = yn_each(yrealmod, yinc)) != NULL){
- if (yang_keyword_get(yinc) != Y_INCLUDE)
- continue;
- submname = yang_argument_get(yinc);
- if ((ysubm = yang_find_module_by_name(yspec, submname)) == NULL)
- continue;
- if (ysubm == ymod)
- continue;
- if ((ygrouping = yang_find(ysubm, Y_GROUPING, name)) != NULL)
- break;
+ if (yang_keyword_get(yinc) != Y_INCLUDE)
+ continue;
+ submname = yang_argument_get(yinc);
+ if ((ysubm = yang_find_module_by_name(yspec, submname)) == NULL)
+ continue;
+ if (ysubm == ymod)
+ continue;
+ if ((ygrouping = yang_find(ysubm, Y_GROUPING, name)) != NULL)
+ break;
}
done:
return ygrouping;
@@ -157,9 +157,9 @@ ys_grouping_module_resolve(yang_stmt *ymod,
*/
static int
ys_grouping_resolve(yang_stmt *yuses,
- char *prefix,
- char *name,
- yang_stmt **ygrouping0)
+ char *prefix,
+ char *name,
+ yang_stmt **ygrouping0)
{
int retval = -1;
yang_stmt *ymod;
@@ -172,24 +172,24 @@ ys_grouping_resolve(yang_stmt *yuses,
yspec = ys_spec(yuses);
/* find the grouping associated with argument and expand(?) */
if (prefix){ /* Go to top and find import that matches */
- if ((ymod = yang_find_module_by_prefix(yuses, prefix)) != NULL)
- ygrouping = ys_grouping_module_resolve(ymod, yspec, name);
+ if ((ymod = yang_find_module_by_prefix(yuses, prefix)) != NULL)
+ ygrouping = ys_grouping_module_resolve(ymod, yspec, name);
}
else {
- ys = yuses; /* Check upwards in hierarchy for matching groupings */
- while (1){
- if ((yp = yang_parent_get(ys)) == NULL)
- break;
- if ((keyw = yang_keyword_get(yp)) == Y_SPEC)
- break;
- else if (keyw == Y_MODULE || keyw == Y_SUBMODULE){ /* Try submodules */
- ygrouping = ys_grouping_module_resolve(yp, yspec, name);
- break;
- }
- else if ((ygrouping = yang_find(yp, Y_GROUPING, name)) != NULL) /* Here find grouping */
- break;
- ys = (yang_stmt*)yp; /* Proceed to next level */
- }
+ ys = yuses; /* Check upwards in hierarchy for matching groupings */
+ while (1){
+ if ((yp = yang_parent_get(ys)) == NULL)
+ break;
+ if ((keyw = yang_keyword_get(yp)) == Y_SPEC)
+ break;
+ else if (keyw == Y_MODULE || keyw == Y_SUBMODULE){ /* Try submodules */
+ ygrouping = ys_grouping_module_resolve(yp, yspec, name);
+ break;
+ }
+ else if ((ygrouping = yang_find(yp, Y_GROUPING, name)) != NULL) /* Here find grouping */
+ break;
+ ys = (yang_stmt*)yp; /* Proceed to next level */
+ }
}
*ygrouping0 = ygrouping;
retval = 0;
@@ -216,7 +216,7 @@ ys_grouping_resolve(yang_stmt *yuses,
*/
static int
yang_augment_node(clicon_handle h,
- yang_stmt *ys)
+ yang_stmt *ys)
{
int retval = -1;
char *schema_nodeid;
@@ -231,147 +231,147 @@ yang_augment_node(clicon_handle h,
enum rfc_6020 childkey;
if ((ymod = ys_module(ys)) == NULL){
- clicon_err(OE_YANG, 0, "My yang module not found");
- goto done;
+ clicon_err(OE_YANG, 0, "My yang module not found");
+ goto done;
}
/* */
schema_nodeid = yang_argument_get(ys);
clicon_debug(2, "%s %s", __FUNCTION__, schema_nodeid);
/* Find the target */
if (yang_abs_schema_nodeid(ys, schema_nodeid, &ytarget) < 0)
- goto done;
+ goto done;
if (ytarget == NULL){
- if (clicon_option_bool(h, "CLICON_YANG_AUGMENT_ACCEPT_BROKEN")){
- /* Log a warning and proceed if augment target not found
- * This may be necessary with some broken models
- */
- clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: target node %s not found",
- yang_argument_get(ys_module(ys)),
- schema_nodeid);
- goto ok;
- }
- else{
- /* Fail with fatal error if augment target not found
- * This is "correct"
- */
- clicon_err(OE_YANG, 0, "Augment failed in module %s: target node %s not found",
- yang_argument_get(ys_module(ys)),
- schema_nodeid);
- goto done;
- }
+ if (clicon_option_bool(h, "CLICON_YANG_AUGMENT_ACCEPT_BROKEN")){
+ /* Log a warning and proceed if augment target not found
+ * This may be necessary with some broken models
+ */
+ clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: target node %s not found",
+ yang_argument_get(ys_module(ys)),
+ schema_nodeid);
+ goto ok;
+ }
+ else{
+ /* Fail with fatal error if augment target not found
+ * This is "correct"
+ */
+ clicon_err(OE_YANG, 0, "Augment failed in module %s: target node %s not found",
+ yang_argument_get(ys_module(ys)),
+ schema_nodeid);
+ goto done;
+ }
}
/* The target node MUST be either a container, list, choice, case, input, output, or notification node.
* which means it is slightly different than a schema-nodeid ? */
targetkey = yang_keyword_get(ytarget);
if (targetkey == Y_ANYDATA)
- goto ok;
+ goto ok;
/* Find when statement, if present */
if ((ywhen = yang_find(ys, Y_WHEN, NULL)) != NULL){
- wxpath = yang_argument_get(ywhen);
- if (xml_nsctx_yang(ywhen, &wnsc) < 0)
- goto done;
+ wxpath = yang_argument_get(ywhen);
+ if (xml_nsctx_yang(ywhen, &wnsc) < 0)
+ goto done;
}
/* Extend ytarget with ys' schemanode children */
yc0 = NULL;
while ((yc0 = yn_each(ys, yc0)) != NULL) {
- childkey = yang_keyword_get(yc0);
- /* Only shemanodes and extensions */
- if (!yang_schemanode(yc0) && childkey != Y_UNKNOWN)
- continue;
- switch (targetkey){
- case Y_CONTAINER:
- case Y_LIST:
- /* If the target node is a container or list node, the "action" and
- "notification" statements can be used within the "augment" statement.
- */
- if (childkey != Y_ACTION && childkey != Y_NOTIFICATION && childkey != Y_UNKNOWN &&
- childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST &&
- childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE){
- /* Special case if yc0 is disabled by if-feature=false, then it is transformed to ANYDATA
- */
- if (yang_flag_get(yc0, YANG_FLAG_DISABLED) == 0)
- clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s of type %s cannot be added to target node %s (see RFC 7950 Sec 17)",
- yang_argument_get(ys_module(ys)),
- yang_argument_get(yc0),
- yang_key2str(childkey),
- schema_nodeid);
- goto ok;
- }
- break;
- case Y_CASE:
- case Y_INPUT:
- case Y_OUTPUT:
- case Y_NOTIFICATION:
- /* If the target node is a container, list, case, input, output, or
- notification node, the "container", "leaf", "list", "leaf-list",
- "uses", and "choice" statements can be used within the "augment"
- statement. */
- if (childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST &&
- childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE &&
- childkey != Y_UNKNOWN){
- clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s",
- yang_argument_get(ys_module(ys)),
- yang_key2str(childkey),
- childkey,
- schema_nodeid);
- goto ok;
- }
- break;
- case Y_CHOICE:
- /* If the target node is a choice node, the "case" statement or a
- shorthand "case" statement (see Section 7.9.2) can be used within the
- "augment" statement.
- XXX could be more or less anything?
- As a shorthand, the "case" statement can be omitted if the branch
- contains a single "anydata", "anyxml", "choice", "container", "leaf",
- "list", or "leaf-list" statement.
- */
- if (childkey != Y_CASE && childkey != Y_ANYDATA && childkey != Y_ANYXML &&
- childkey != Y_CHOICE && childkey != Y_CONTAINER && childkey != Y_LEAF &&
- childkey != Y_LIST && childkey != Y_LEAF_LIST){
+ childkey = yang_keyword_get(yc0);
+ /* Only shemanodes and extensions */
+ if (!yang_schemanode(yc0) && childkey != Y_UNKNOWN)
+ continue;
+ switch (targetkey){
+ case Y_CONTAINER:
+ case Y_LIST:
+ /* If the target node is a container or list node, the "action" and
+ "notification" statements can be used within the "augment" statement.
+ */
+ if (childkey != Y_ACTION && childkey != Y_NOTIFICATION && childkey != Y_UNKNOWN &&
+ childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST &&
+ childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE){
+ /* Special case if yc0 is disabled by if-feature=false, then it is transformed to ANYDATA
+ */
+ if (yang_flag_get(yc0, YANG_FLAG_DISABLED) == 0)
+ clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s of type %s cannot be added to target node %s (see RFC 7950 Sec 17)",
+ yang_argument_get(ys_module(ys)),
+ yang_argument_get(yc0),
+ yang_key2str(childkey),
+ schema_nodeid);
+ goto ok;
+ }
+ break;
+ case Y_CASE:
+ case Y_INPUT:
+ case Y_OUTPUT:
+ case Y_NOTIFICATION:
+ /* If the target node is a container, list, case, input, output, or
+ notification node, the "container", "leaf", "list", "leaf-list",
+ "uses", and "choice" statements can be used within the "augment"
+ statement. */
+ if (childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST &&
+ childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE &&
+ childkey != Y_UNKNOWN){
+ clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s",
+ yang_argument_get(ys_module(ys)),
+ yang_key2str(childkey),
+ childkey,
+ schema_nodeid);
+ goto ok;
+ }
+ break;
+ case Y_CHOICE:
+ /* If the target node is a choice node, the "case" statement or a
+ shorthand "case" statement (see Section 7.9.2) can be used within the
+ "augment" statement.
+ XXX could be more or less anything?
+ As a shorthand, the "case" statement can be omitted if the branch
+ contains a single "anydata", "anyxml", "choice", "container", "leaf",
+ "list", or "leaf-list" statement.
+ */
+ if (childkey != Y_CASE && childkey != Y_ANYDATA && childkey != Y_ANYXML &&
+ childkey != Y_CHOICE && childkey != Y_CONTAINER && childkey != Y_LEAF &&
+ childkey != Y_LIST && childkey != Y_LEAF_LIST){
- clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s",
- yang_argument_get(ys_module(ys)),
- yang_key2str(childkey),
- childkey,
- schema_nodeid);
- goto ok;
- }
- break;
- default:
- break;
- }
+ clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s",
+ yang_argument_get(ys_module(ys)),
+ yang_key2str(childkey),
+ childkey,
+ schema_nodeid);
+ goto ok;
+ }
+ break;
+ default:
+ break;
+ }
- if ((yc = ys_dup(yc0)) == NULL)
- goto done;
- yc->ys_mymodule = ymod;
+ if ((yc = ys_dup(yc0)) == NULL)
+ goto done;
+ yc->ys_mymodule = ymod;
- if (yn_insert(ytarget, yc) < 0)
- goto done;
- /* If there is an associated when statement, add a special when struct to the yang
- * see xml_yang_validate_all
- */
- if (ywhen){
- if (yang_when_xpath_set(yc, wxpath) < 0)
- goto done;
- if (yang_when_nsc_set(yc, wnsc) < 0)
- goto done;
- }
- /* Note: ys_populate2 called as a special case here since the inserted child is
- * not covered by Step 9 in yang_parse_post
- */
- if (ys_populate2(yc, h) < 0)
- goto done;
- if (yang_apply(yc, -1, ys_populate2, 1, (void*)h) < 0)
- goto done;
+ if (yn_insert(ytarget, yc) < 0)
+ goto done;
+ /* If there is an associated when statement, add a special when struct to the yang
+ * see xml_yang_validate_all
+ */
+ if (ywhen){
+ if (yang_when_xpath_set(yc, wxpath) < 0)
+ goto done;
+ if (yang_when_nsc_set(yc, wnsc) < 0)
+ goto done;
+ }
+ /* Note: ys_populate2 called as a special case here since the inserted child is
+ * not covered by Step 9 in yang_parse_post
+ */
+ if (ys_populate2(yc, h) < 0)
+ goto done;
+ if (yang_apply(yc, -1, ys_populate2, 1, (void*)h) < 0)
+ goto done;
}
ok:
retval = 0;
done:
if (wnsc)
- cvec_free(wnsc);
+ cvec_free(wnsc);
return retval;
}
@@ -386,7 +386,7 @@ yang_augment_node(clicon_handle h,
*/
static int
yang_augment_module(clicon_handle h,
- yang_stmt *ymod)
+ yang_stmt *ymod)
{
int retval = -1;
@@ -394,14 +394,14 @@ yang_augment_module(clicon_handle h,
ys = NULL;
while ((ys = yn_each(ymod, ys)) != NULL){
- switch (yang_keyword_get(ys)){
- case Y_AUGMENT: /* top-level */
- if (yang_augment_node(h, ys) < 0)
- goto done;
- break;
- default:
- break;
- }
+ switch (yang_keyword_get(ys)){
+ case Y_AUGMENT: /* top-level */
+ if (yang_augment_node(h, ys) < 0)
+ goto done;
+ break;
+ default:
+ break;
+ }
}
retval = 0;
done:
@@ -418,7 +418,7 @@ yang_augment_module(clicon_handle h,
*/
static int
ys_do_refine(yang_stmt *yr,
- yang_stmt *yt)
+ yang_stmt *yt)
{
int retval = -1;
yang_stmt *yrc; /* refine child */
@@ -432,44 +432,44 @@ ys_do_refine(yang_stmt *yr,
*/
yrc = NULL;
while ((yrc = yn_each(yr, yrc)) != NULL) {
- keyw = yang_keyword_get(yrc);
- switch (keyw){
- case Y_DEFAULT: /* remove old, add new */
- case Y_DESCRIPTION:
- case Y_REFERENCE:
- case Y_CONFIG:
- case Y_MANDATORY:
- case Y_PRESENCE:
- case Y_MIN_ELEMENTS:
- case Y_MAX_ELEMENTS:
- case Y_EXTENSION:
- /* Remove old matching, dont increment due to prune in loop */
- for (i=0; iys_stmt[i];
- if (keyw != yang_keyword_get(ytc)){
- i++;
- continue;
- }
- ys_prune(yt, i);
- ys_free(ytc);
- }
- /* fall through and add if not found */
- case Y_MUST: /* keep old, add new */
- case Y_IF_FEATURE:
- break;
- default:
- break;
- }
+ keyw = yang_keyword_get(yrc);
+ switch (keyw){
+ case Y_DEFAULT: /* remove old, add new */
+ case Y_DESCRIPTION:
+ case Y_REFERENCE:
+ case Y_CONFIG:
+ case Y_MANDATORY:
+ case Y_PRESENCE:
+ case Y_MIN_ELEMENTS:
+ case Y_MAX_ELEMENTS:
+ case Y_EXTENSION:
+ /* Remove old matching, dont increment due to prune in loop */
+ for (i=0; iys_stmt[i];
+ if (keyw != yang_keyword_get(ytc)){
+ i++;
+ continue;
+ }
+ ys_prune(yt, i);
+ ys_free(ytc);
+ }
+ /* fall through and add if not found */
+ case Y_MUST: /* keep old, add new */
+ case Y_IF_FEATURE:
+ break;
+ default:
+ break;
+ }
}
/* Second, add the node(s) */
yrc = NULL;
while ((yrc = yn_each(yr, yrc)) != NULL) {
- keyw = yang_keyword_get(yrc);
- /* Make copy */
- if ((yrc1 = ys_dup(yrc)) == NULL)
- goto done;
- if (yn_insert(yt, yrc1) < 0)
- goto done;
+ keyw = yang_keyword_get(yrc);
+ /* Make copy */
+ if ((yrc1 = ys_dup(yrc)) == NULL)
+ goto done;
+ if (yn_insert(yt, yrc1) < 0)
+ goto done;
}
retval = 0;
done:
@@ -485,23 +485,23 @@ ys_do_refine(yang_stmt *yr,
*/
static int
ys_iskey(yang_stmt *y,
- yang_stmt *yp)
+ yang_stmt *yp)
{
cvec *cvv;
cg_var *cv;
char *name;
if (yang_keyword_get(y) != Y_LEAF)
- return 0;
+ return 0;
if (yang_keyword_get(yp) != Y_LIST)
- return 0;
+ return 0;
if ((cvv = yang_cvec_get(yp)) == NULL)
- return 0;
+ return 0;
name = yang_argument_get(y);
cv = NULL;
while ((cv = cvec_each(cvv, cv)) != NULL) {
- if (strcmp(name, cv_string_get(cv)) == 0)
- return 1;
+ if (strcmp(name, cv_string_get(cv)) == 0)
+ return 1;
}
return 0;
}
@@ -514,8 +514,8 @@ ys_iskey(yang_stmt *y,
*/
static int
yang_expand_uses_node(yang_stmt *yn,
- yang_stmt *ys,
- int i)
+ yang_stmt *ys,
+ int i)
{
int retval = -1;
char *id = NULL;
@@ -535,41 +535,41 @@ yang_expand_uses_node(yang_stmt *yn,
/* Split argument into prefix and name */
if (nodeid_split(yang_argument_get(ys), &prefix, &id) < 0)
- goto done;
+ goto done;
if (ys_grouping_resolve(ys, prefix, id, &ygrouping) < 0)
- goto done;
+ goto done;
if (ygrouping == NULL){
- clicon_log(LOG_NOTICE, "%s: Yang error : grouping \"%s\" not found in module \"%s\"",
- __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
- goto done;
+ clicon_log(LOG_NOTICE, "%s: Yang error : grouping \"%s\" not found in module \"%s\"",
+ __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
+ goto done;
}
/* Check so that this uses statement is not a descendant of the grouping
*/
yp = yn;
do {
- if (yp == ygrouping){
- clicon_err(OE_YANG, EFAULT, "Yang use of grouping %s in module %s is defined inside the grouping (recursion), see RFC 7950 Sec 7.12: A grouping MUST NOT reference itself",
- yang_argument_get(ys),
- yang_argument_get(ys_module(yn))
- );
- goto done;
- }
+ if (yp == ygrouping){
+ clicon_err(OE_YANG, EFAULT, "Yang use of grouping %s in module %s is defined inside the grouping (recursion), see RFC 7950 Sec 7.12: A grouping MUST NOT reference itself",
+ yang_argument_get(ys),
+ yang_argument_get(ys_module(yn))
+ );
+ goto done;
+ }
} while((yp = yang_parent_get(yp)) != NULL);
if (yang_flag_get(ygrouping, YANG_FLAG_MARK) == 0){
- /* Check mark flag to see if this grouping has been expanded before,
- * here below in the traverse section
- * A mark could be completely normal (several uses) or it could be a recursion.
- */
- yang_flag_set(ygrouping, YANG_FLAG_MARK); /* Mark as (being) expanded */
- if (yang_expand_grouping(ygrouping) < 0)
- goto done;
+ /* Check mark flag to see if this grouping has been expanded before,
+ * here below in the traverse section
+ * A mark could be completely normal (several uses) or it could be a recursion.
+ */
+ yang_flag_set(ygrouping, YANG_FLAG_MARK); /* Mark as (being) expanded */
+ if (yang_expand_grouping(ygrouping) < 0)
+ goto done;
}
/* Make a copy of the grouping, then make refinements to this copy
* Note this ygrouping2 object does not have a parent and does not work in many
* functions which assume a full hierarchy, use the original ygrouping in those cases.
*/
if ((ygrouping2 = ys_dup(ygrouping)) == NULL)
- goto done;
+ goto done;
/* Only replace data/schemanodes and unknowns:
* Compute the number of such nodes, and extend the child vector with that below
@@ -577,99 +577,99 @@ yang_expand_uses_node(yang_stmt *yn,
glen = 0;
yg = NULL;
while ((yg = yn_each(ygrouping2, yg)) != NULL) {
- if (yang_schemanode(yg) || yang_keyword_get(yg) == Y_UNKNOWN)
- glen++;
+ if (yang_schemanode(yg) || yang_keyword_get(yg) == Y_UNKNOWN)
+ glen++;
}
/*
* yn is parent: the children of ygrouping replaces ys.
* Is there a case when glen == 0? YES AND THIS BREAKS
*/
if (glen != 1){
- size = (yang_len_get(yn) - i - 1)*sizeof(struct yang_stmt *);
- yn->ys_len += glen - 1;
- if (glen && (yn->ys_stmt = realloc(yn->ys_stmt, (yang_len_get(yn))*sizeof(yang_stmt *))) == 0){
- clicon_err(OE_YANG, errno, "realloc");
- goto done;
- }
- /* Then move all existing elements up from i+1 (not uses-stmt) */
- if (size)
- memmove(&yn->ys_stmt[i+glen],
- &yn->ys_stmt[i+1],
- size);
+ size = (yang_len_get(yn) - i - 1)*sizeof(struct yang_stmt *);
+ yn->ys_len += glen - 1;
+ if (glen && (yn->ys_stmt = realloc(yn->ys_stmt, (yang_len_get(yn))*sizeof(yang_stmt *))) == 0){
+ clicon_err(OE_YANG, errno, "realloc");
+ goto done;
+ }
+ /* Then move all existing elements up from i+1 (not uses-stmt) */
+ if (size)
+ memmove(&yn->ys_stmt[i+glen],
+ &yn->ys_stmt[i+1],
+ size);
}
/* Find when statement, if present */
if ((ywhen = yang_find(ys, Y_WHEN, NULL)) != NULL){
- wxpath = yang_argument_get(ywhen);
- if (xml_nsctx_yang(ywhen, &wnsc) < 0)
- goto done;
+ wxpath = yang_argument_get(ywhen);
+ if (xml_nsctx_yang(ywhen, &wnsc) < 0)
+ goto done;
}
/* Note: yang_desc_schema_nodeid() requires ygrouping2 to be in yspec tree,
* cannot be dangling, insert into tree here and then prune immediately after while loop
*/
if (yn_insert(yang_parent_get(ygrouping), ygrouping2) < 0)
- goto done;
+ goto done;
/* Iterate through refinements and modify grouping copy
* See RFC 7950 7.13.2 yrt is the refine target node
*/
yr = NULL;
while ((yr = yn_each(ys, yr)) != NULL) {
- yang_stmt *yrt; /* refine target node */
- if (yang_keyword_get(yr) != Y_REFINE)
- continue;
- /* Find a node */
- if (yang_desc_schema_nodeid(ygrouping2,
- yang_argument_get(yr),
- &yrt) < 0)
- goto done;
- /* Not found, try next */
- if (yrt == NULL)
- continue;
- /* Refine ANYDATA does not make sense */
- if (yang_keyword_get(yrt) == Y_ANYDATA || yang_keyword_get(yrt) == Y_ANYXML)
- continue;
- /* Do the actual refinement */
- if (ys_do_refine(yr, yrt) < 0)
- goto done;
+ yang_stmt *yrt; /* refine target node */
+ if (yang_keyword_get(yr) != Y_REFINE)
+ continue;
+ /* Find a node */
+ if (yang_desc_schema_nodeid(ygrouping2,
+ yang_argument_get(yr),
+ &yrt) < 0)
+ goto done;
+ /* Not found, try next */
+ if (yrt == NULL)
+ continue;
+ /* Refine ANYDATA does not make sense */
+ if (yang_keyword_get(yrt) == Y_ANYDATA || yang_keyword_get(yrt) == Y_ANYXML)
+ continue;
+ /* Do the actual refinement */
+ if (ys_do_refine(yr, yrt) < 0)
+ goto done;
} /* while yr */
/* Note: prune here to make dangling again after while loop */
if (ys_prune_self(ygrouping2) < 0)
- goto done;
+ goto done;
/* Then copy and insert each child element from ygrouping2 to yn */
k=0;
for (j=0; jys_stmt[j]; /* Child of refined copy */
- /* Only replace data/schemanodes */
- if (!yang_schemanode(yg) && yang_keyword_get(yg) != Y_UNKNOWN){
- ys_free(yg);
- continue;
- }
- /* If there is an associated when statement, add a special when struct to the yang
- * see xml_yang_validate_all
- */
- if (ywhen){
- if (ys_iskey(yg, yn)){
- /* RFC 7950 Sec 7.21.5:
- * If a key leaf is defined in a grouping that is used in a list, the
- * "uses" statement MUST NOT have a "when" statement.
- */
-
- clicon_err(OE_YANG, 0, "Key leaf '%s' defined in grouping '%s' is used in a 'uses' statement, This is not allowed according to RFC 7950 Sec 7.21.5",
- yang_argument_get(yg),
- yang_argument_get(ygrouping)
- );
- goto done;
- }
- if (yang_when_xpath_set(yg, wxpath) < 0)
- goto done;
- if (yang_when_nsc_set(yg, wnsc) < 0)
- goto done;
- }
- /* This is for extensions that allow list keys to be optional, see restconf_main_extension_cb */
- if (yang_flag_get(ys, YANG_FLAG_NOKEY))
- yang_flag_set(yg, YANG_FLAG_NOKEY);
- yn->ys_stmt[i+k] = yg;
- yg->ys_parent = yn;
- k++;
+ yg = ygrouping2->ys_stmt[j]; /* Child of refined copy */
+ /* Only replace data/schemanodes */
+ if (!yang_schemanode(yg) && yang_keyword_get(yg) != Y_UNKNOWN){
+ ys_free(yg);
+ continue;
+ }
+ /* If there is an associated when statement, add a special when struct to the yang
+ * see xml_yang_validate_all
+ */
+ if (ywhen){
+ if (ys_iskey(yg, yn)){
+ /* RFC 7950 Sec 7.21.5:
+ * If a key leaf is defined in a grouping that is used in a list, the
+ * "uses" statement MUST NOT have a "when" statement.
+ */
+
+ clicon_err(OE_YANG, 0, "Key leaf '%s' defined in grouping '%s' is used in a 'uses' statement, This is not allowed according to RFC 7950 Sec 7.21.5",
+ yang_argument_get(yg),
+ yang_argument_get(ygrouping)
+ );
+ goto done;
+ }
+ if (yang_when_xpath_set(yg, wxpath) < 0)
+ goto done;
+ if (yang_when_nsc_set(yg, wnsc) < 0)
+ goto done;
+ }
+ /* This is for extensions that allow list keys to be optional, see restconf_main_extension_cb */
+ if (yang_flag_get(ys, YANG_FLAG_NOKEY))
+ yang_flag_set(yg, YANG_FLAG_NOKEY);
+ yn->ys_stmt[i+k] = yg;
+ yg->ys_parent = yn;
+ k++;
}
/* Remove 'uses' node */
ys_free(ys);
@@ -680,11 +680,11 @@ yang_expand_uses_node(yang_stmt *yn,
retval = 0;
done:
if (wnsc)
- cvec_free(wnsc);
+ cvec_free(wnsc);
if (prefix)
- free(prefix);
+ free(prefix);
if (id)
- free(id);
+ free(id);
return retval;
}
@@ -712,35 +712,35 @@ yang_expand_grouping(yang_stmt *yn)
/* Cannot use yang_apply here since child-list is modified (is destructive) */
i = 0;
while (i < yang_len_get(yn)){
- ys = yn->ys_stmt[i];
- switch (yang_keyword_get(ys)){
- case Y_USES:
- if (yang_expand_uses_node(yn, ys, i) < 0)
- goto done;
- break; /* Note same child is re-iterated since it may be changed */
- default:
- i++;
- break;
- }
+ ys = yn->ys_stmt[i];
+ switch (yang_keyword_get(ys)){
+ case Y_USES:
+ if (yang_expand_uses_node(yn, ys, i) < 0)
+ goto done;
+ break; /* Note same child is re-iterated since it may be changed */
+ default:
+ i++;
+ break;
+ }
}
/* Second pass since length may have changed */
for (i=0; iys_stmt[i];
- if (yang_keyword_get(ys) == Y_GROUPING){
- /* Check mark flag to see if this grouping has been expanded before, here or in the
- * 'uses' section
- * A mark could be completely normal (several uses) or it could be a recursion.
- */
- if (yang_flag_get(ys, YANG_FLAG_MARK) == 0){
- yang_flag_set(ys, YANG_FLAG_MARK); /* Mark as (being) expanded */
- if (yang_expand_grouping(ys) < 0)
- goto done;
- }
- }
- else{
- if (yang_expand_grouping(ys) < 0)
- goto done;
- }
+ ys = yn->ys_stmt[i];
+ if (yang_keyword_get(ys) == Y_GROUPING){
+ /* Check mark flag to see if this grouping has been expanded before, here or in the
+ * 'uses' section
+ * A mark could be completely normal (several uses) or it could be a recursion.
+ */
+ if (yang_flag_get(ys, YANG_FLAG_MARK) == 0){
+ yang_flag_set(ys, YANG_FLAG_MARK); /* Mark as (being) expanded */
+ if (yang_expand_grouping(ys) < 0)
+ goto done;
+ }
+ }
+ else{
+ if (yang_expand_grouping(ys) < 0)
+ goto done;
+ }
}
retval = 0;
done:
@@ -761,15 +761,15 @@ yang_expand_grouping(yang_stmt *yn)
*/
static yang_stmt *
yang_parse_str(char *str,
- const char *name, /* just for errs */
- yang_stmt *yspec)
+ const char *name, /* just for errs */
+ yang_stmt *yspec)
{
clixon_yang_yacc yy = {0,};
yang_stmt *ymod = NULL;
if (yspec == NULL){
- clicon_err(OE_YANG, 0, "Yang parse need top level yang spec");
- goto done;
+ clicon_err(OE_YANG, 0, "Yang parse need top level yang spec");
+ goto done;
}
yy.yy_name = (char*)name;
yy.yy_linenum = 1;
@@ -777,36 +777,36 @@ yang_parse_str(char *str,
yy.yy_stack = NULL;
yy.yy_module = NULL; /* this is the return value - the module/sub-module */
if (ystack_push(&yy, yspec) == NULL)
- goto done;
+ goto done;
if (strlen(str)){ /* Not empty */
- if (yang_scan_init(&yy) < 0)
- goto done;
- if (yang_parse_init(&yy) < 0)
- goto done;
- if (clixon_yang_parseparse(&yy) != 0) { /* yacc returns 1 on error */
- clicon_log(LOG_NOTICE, "Yang error: %s on line %d", name, yy.yy_linenum);
- if (clicon_errno == 0)
- clicon_err(OE_YANG, 0, "yang parser error with no error code (should not happen)");
- yang_parse_exit(&yy);
- yang_scan_exit(&yy);
- goto done;
- }
- if (yang_parse_exit(&yy) < 0)
- goto done;
- if (yang_scan_exit(&yy) < 0)
- goto done;
+ if (yang_scan_init(&yy) < 0)
+ goto done;
+ if (yang_parse_init(&yy) < 0)
+ goto done;
+ if (clixon_yang_parseparse(&yy) != 0) { /* yacc returns 1 on error */
+ clicon_log(LOG_NOTICE, "Yang error: %s on line %d", name, yy.yy_linenum);
+ if (clicon_errno == 0)
+ clicon_err(OE_YANG, 0, "yang parser error with no error code (should not happen)");
+ yang_parse_exit(&yy);
+ yang_scan_exit(&yy);
+ goto done;
+ }
+ if (yang_parse_exit(&yy) < 0)
+ goto done;
+ if (yang_scan_exit(&yy) < 0)
+ goto done;
}
if ((ymod = yy.yy_module) == NULL){
- clicon_err(OE_YANG, 0, "No module in YANG %s", name);
- goto done;
+ clicon_err(OE_YANG, 0, "No module in YANG %s", name);
+ goto done;
}
/* Add filename for debugging and errors, see also ys_linenum on (each symbol?) */
if (yang_filename_set(ymod, name) < 0)
- goto done;
+ goto done;
done:
ystack_pop(&yy);
if (yy.yy_stack)
- free (yy.yy_stack);
+ free (yy.yy_stack);
return ymod; /* top-level (sub)module */
}
@@ -820,8 +820,8 @@ yang_parse_str(char *str,
*/
yang_stmt *
yang_parse_file(FILE *fp,
- const char *name,
- yang_stmt *yspec)
+ const char *name,
+ yang_stmt *yspec)
{
char *buf = NULL;
int i;
@@ -832,33 +832,33 @@ yang_parse_file(FILE *fp,
len = BUFLEN; /* any number is fine */
if ((buf = malloc(len)) == NULL){
- clicon_err(OE_XML, errno, "malloc");
- goto done;
+ clicon_err(OE_XML, errno, "malloc");
+ goto done;
}
memset(buf, 0, len);
i = 0; /* position in buf */
while (1){ /* read the whole file */
- if ((ret = fread(&c, 1, 1, fp)) < 0){
- clicon_err(OE_XML, errno, "read");
- break;
- }
- if (ret == 0)
- break; /* eof */
- if (i == len-1){
- if ((buf = realloc(buf, 2*len)) == NULL){
- clicon_err(OE_XML, errno, "realloc");
- goto done;
- }
- memset(buf+len, 0, len);
- len *= 2;
- }
- buf[i++] = (char)(c&0xff);
+ if ((ret = fread(&c, 1, 1, fp)) < 0){
+ clicon_err(OE_XML, errno, "read");
+ break;
+ }
+ if (ret == 0)
+ break; /* eof */
+ if (i == len-1){
+ if ((buf = realloc(buf, 2*len)) == NULL){
+ clicon_err(OE_XML, errno, "realloc");
+ goto done;
+ }
+ memset(buf+len, 0, len);
+ len *= 2;
+ }
+ buf[i++] = (char)(c&0xff);
} /* read a line */
if ((ymod = yang_parse_str(buf, name, yspec)) < 0)
- goto done;
+ goto done;
done:
if (buf != NULL)
- free(buf);
+ free(buf);
return ymod; /* top-level (sub)module */
}
@@ -869,8 +869,8 @@ yang_parse_file(FILE *fp,
*/
static int
filename2revision(const char *filename,
- char **basep,
- uint32_t *revp)
+ char **basep,
+ uint32_t *revp)
{
int retval = -1;
char *base = NULL;
@@ -878,25 +878,25 @@ filename2revision(const char *filename,
/* base = module name [+ @rev ] + .yang */
if ((base = strdup(filename)) == NULL){
- clicon_err(OE_UNIX, errno, "strdup");
- goto done;
+ clicon_err(OE_UNIX, errno, "strdup");
+ goto done;
}
clicon_debug(2, "%s %s", __FUNCTION__, base);
if ((p = rindex(base, '.')) != NULL) /* strip postfix .yang */
- *p = '\0';
+ *p = '\0';
if ((p = index(base, '@')) != NULL){ /* extract revision date */
- *p++ = '\0';
- if (revp && ys_parse_date_arg(p, revp) < 0)
- goto done;
+ *p++ = '\0';
+ if (revp && ys_parse_date_arg(p, revp) < 0)
+ goto done;
}
if (basep){
- *basep = base;
- base = NULL;
+ *basep = base;
+ base = NULL;
}
retval = 0;
done:
if (base)
- free(base);
+ free(base);
return retval;
}
@@ -913,10 +913,10 @@ filename2revision(const char *filename,
*/
static int
yang_parse_find_match(clicon_handle h,
- const char *module,
- const char *revision,
- uint32_t *revactual,
- cbuf *fbuf)
+ const char *module,
+ const char *revision,
+ uint32_t *revactual,
+ cbuf *fbuf)
{
int retval = -1;
cbuf *regex = NULL;
@@ -946,57 +946,57 @@ yang_parse_find_match(clicon_handle h,
xc = NULL;
while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL) {
- if (strcmp(xml_name(xc), "CLICON_YANG_MAIN_DIR") == 0){
- struct dirent *dp = NULL;
- int ndp;
+ if (strcmp(xml_name(xc), "CLICON_YANG_MAIN_DIR") == 0){
+ struct dirent *dp = NULL;
+ int ndp;
- dir = xml_body(xc);
- /* get all matching files in this directory */
- if ((ndp = clicon_file_dirent(dir,
- &dp,
- cbuf_get(regex),
- S_IFREG)) < 0)
- goto done;
- /* Entries are sorted, last entry should be most recent date
- */
- if (ndp != 0){
- cprintf(fbuf, "%s/%s", dir, dp[ndp-1].d_name);
- retval = 1;
- goto done;
- }
- if (dp)
- free(dp);
- }
+ dir = xml_body(xc);
+ /* get all matching files in this directory */
+ if ((ndp = clicon_file_dirent(dir,
+ &dp,
+ cbuf_get(regex),
+ S_IFREG)) < 0)
+ goto done;
+ /* Entries are sorted, last entry should be most recent date
+ */
+ if (ndp != 0){
+ cprintf(fbuf, "%s/%s", dir, dp[ndp-1].d_name);
+ retval = 1;
+ goto done;
+ }
+ if (dp)
+ free(dp);
+ }
else if (strcmp(xml_name(xc), "CLICON_YANG_DIR") == 0 &&
- (dir = xml_body(xc)) != NULL){
- /* get all matching files in this directory recursively */
- if ((cvv = cvec_new(0)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_new");
- goto done;
- }
- if (clicon_files_recursive(dir, cbuf_get(regex), cvv) < 0)
- goto done;
+ (dir = xml_body(xc)) != NULL){
+ /* get all matching files in this directory recursively */
+ if ((cvv = cvec_new(0)) == NULL){
+ clicon_err(OE_UNIX, errno, "cvec_new");
+ goto done;
+ }
+ if (clicon_files_recursive(dir, cbuf_get(regex), cvv) < 0)
+ goto done;
- /* Entries are not sorted and come in a vector: .
- * Find latest name and use path as return value
- */
- bestcv = NULL;
- while ((cv = cvec_each(cvv, cv)) != NULL){
- if (bestcv == NULL)
- bestcv = cv;
- else if (strcoll(cv_name_get(cv), cv_name_get(bestcv)) > 0)
- bestcv = cv;
- }
- if (bestcv){
- cprintf(fbuf, "%s", cv_string_get(bestcv)); /* file path */
- retval = 1; /* found */
- goto done;
- }
- if (cvv){
- cvec_free(cvv);
- cvv = NULL;
- }
- }
+ /* Entries are not sorted and come in a vector: .
+ * Find latest name and use path as return value
+ */
+ bestcv = NULL;
+ while ((cv = cvec_each(cvv, cv)) != NULL){
+ if (bestcv == NULL)
+ bestcv = cv;
+ else if (strcoll(cv_name_get(cv), cv_name_get(bestcv)) > 0)
+ bestcv = cv;
+ }
+ if (bestcv){
+ cprintf(fbuf, "%s", cv_string_get(bestcv)); /* file path */
+ retval = 1; /* found */
+ goto done;
+ }
+ if (cvv){
+ cvec_free(cvv);
+ cvv = NULL;
+ }
+ }
}
ok:
retval = 0;
@@ -1021,7 +1021,7 @@ done:
*/
yang_stmt *
yang_parse_filename(const char *filename,
- yang_stmt *yspec)
+ yang_stmt *yspec)
{
yang_stmt *ymod = NULL;
FILE *fp = NULL;
@@ -1029,18 +1029,18 @@ yang_parse_filename(const char *filename,
clicon_debug(1, "%s %s", __FUNCTION__, filename);
if (stat(filename, &st) < 0){
- clicon_err(OE_YANG, errno, "%s not found", filename);
- goto done;
+ clicon_err(OE_YANG, errno, "%s not found", filename);
+ goto done;
}
if ((fp = fopen(filename, "r")) == NULL){
- clicon_err(OE_YANG, errno, "fopen(%s)", filename);
- goto done;
+ clicon_err(OE_YANG, errno, "fopen(%s)", filename);
+ goto done;
}
if ((ymod = yang_parse_file(fp, filename, yspec)) < 0)
- goto done;
+ goto done;
done:
if (fp)
- fclose(fp);
+ fclose(fp);
return ymod; /* top-level (sub)module */
}
@@ -1059,10 +1059,10 @@ yang_parse_filename(const char *filename,
*/
static yang_stmt *
yang_parse_module(clicon_handle h,
- const char *module,
- const char *revision,
- yang_stmt *yspec,
- char *origname)
+ const char *module,
+ const char *revision,
+ yang_stmt *yspec,
+ char *origname)
{
cbuf *fbuf = NULL;
char *filename;
@@ -1074,60 +1074,60 @@ yang_parse_module(clicon_handle h,
cbuf *cb = NULL;
if ((fbuf = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
}
/* Match a yang file with or without revision in yang-dir list */
if ((nr = yang_parse_find_match(h, module, revision, &revf, fbuf)) < 0)
- goto done;
+ goto done;
if (nr == 0){
- if ((cb = cbuf_new()) == NULL){
- clicon_err(OE_UNIX, errno, "cbuf_new");
- goto done;
- }
- cprintf(cb, "%s", module);
- if (revision)
- cprintf(cb, "@%s", revision);
- if (origname)
- clicon_err(OE_YANG, ENOENT, "No yang files found matching \"%s\" in the list of CLICON_YANG_DIRs when loading %s.yang", cbuf_get(cb), origname);
- else
- clicon_err(OE_YANG, ENOENT, "No yang files found matching \"%s\" in the list of CLICON_YANG_DIRs", cbuf_get(cb));
- goto done;
+ if ((cb = cbuf_new()) == NULL){
+ clicon_err(OE_UNIX, errno, "cbuf_new");
+ goto done;
+ }
+ cprintf(cb, "%s", module);
+ if (revision)
+ cprintf(cb, "@%s", revision);
+ if (origname)
+ clicon_err(OE_YANG, ENOENT, "No yang files found matching \"%s\" in the list of CLICON_YANG_DIRs when loading %s.yang", cbuf_get(cb), origname);
+ else
+ clicon_err(OE_YANG, ENOENT, "No yang files found matching \"%s\" in the list of CLICON_YANG_DIRs", cbuf_get(cb));
+ goto done;
}
filename = cbuf_get(fbuf);
if ((ymod = yang_parse_filename(filename, yspec)) == NULL)
- goto done;
+ goto done;
/* Sanity check that requested module name matches loaded module
* If this does not match, the filename and containing module do not match
* RFC 7950 Sec 5.2
*/
if (strcmp(yang_argument_get(ymod), module) != 0){
- clicon_err(OE_YANG, EINVAL, "File %s contains yang module \"%s\" which does not match expected module %s",
- filename,
- yang_argument_get(ymod),
- module);
- ymod = NULL;
- goto done;
+ clicon_err(OE_YANG, EINVAL, "File %s contains yang module \"%s\" which does not match expected module %s",
+ filename,
+ yang_argument_get(ymod),
+ module);
+ ymod = NULL;
+ goto done;
}
/* Sanity check that requested module name matches loaded module
* If this does not match, the filename and containing module do not match
* RFC 7950 Sec 5.2
*/
if ((yrev = yang_find(ymod, Y_REVISION, NULL)) != NULL)
- revm = cv_uint32_get(yang_cv_get(yrev));
+ revm = cv_uint32_get(yang_cv_get(yrev));
if (filename2revision(filename, NULL, &revf) < 0)
- goto done;
+ goto done;
/* Sanity check that file revision does not match internal rev stmt */
if (revf && revm && revm != revf){
- clicon_err(OE_YANG, EINVAL, "Yang module file revision and in yang does not match: %s vs %u", filename, revm);
- ymod = NULL;
- goto done;
+ clicon_err(OE_YANG, EINVAL, "Yang module file revision and in yang does not match: %s vs %u", filename, revm);
+ ymod = NULL;
+ goto done;
}
done:
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
if (fbuf)
- cbuf_free(fbuf);
+ cbuf_free(fbuf);
return ymod; /* top-level (sub)module */
}
@@ -1144,8 +1144,8 @@ yang_parse_module(clicon_handle h,
*/
static int
yang_parse_recurse(clicon_handle h,
- yang_stmt *ymod,
- yang_stmt *ysp)
+ yang_stmt *ymod,
+ yang_stmt *ysp)
{
int retval = -1;
yang_stmt *yi = NULL; /* import */
@@ -1158,47 +1158,47 @@ yang_parse_recurse(clicon_handle h,
enum rfc_6020 keyw;
if (ys_real_module(ymod, &yrealmod) < 0)
- goto done;
+ goto done;
/* go through all import (modules) and include(submodules) of ysp */
while ((yi = yn_each(ymod, yi)) != NULL){
- keyw = yang_keyword_get(yi);
- if (keyw != Y_IMPORT && keyw != Y_INCLUDE)
- continue;
- /* common part */
- submodule = yang_argument_get(yi);
- /* Is there a specific revision (or just latest)? */
- if ((yrev = yang_find(yi, Y_REVISION_DATE, NULL)) != NULL)
- subrevision = yang_argument_get(yrev);
- else
- subrevision = NULL;
- /* if already loaded, ignore, else parse the file */
- if (yang_find(ysp,
- keyw==Y_IMPORT?Y_MODULE:Y_SUBMODULE,
- submodule) == NULL){
- /* recursive call */
- if ((subymod = yang_parse_module(h, submodule, subrevision, ysp, yang_argument_get(ymod))) == NULL)
- goto done;
- /* Sanity check: if submodule, its belongs-to statement shall point to the module */
- if (keyw == Y_INCLUDE){
- ybelongto = yang_find(subymod, Y_BELONGS_TO, NULL);
- if (ybelongto == NULL){
- clicon_err(OE_YANG, ENOENT, "Sub-module \"%s\" does not have a belongs-to statement", submodule); /* shouldnt happen */
- goto done;
- }
- if (strcmp(yang_argument_get(ybelongto), yang_argument_get(yrealmod)) != 0){
- clicon_err(OE_YANG, ENOENT, "Sub-module \"%s\" references module \"%s\" in its belongs-to statement but should reference \"%s\"",
- submodule,
- yang_argument_get(ybelongto),
- yang_argument_get(yrealmod));
- goto done;
- }
- }
- /* Go through its sub-modules recursively */
- if (yang_parse_recurse(h, subymod, ysp) < 0){
- ymod = NULL;
- goto done;
- }
- }
+ keyw = yang_keyword_get(yi);
+ if (keyw != Y_IMPORT && keyw != Y_INCLUDE)
+ continue;
+ /* common part */
+ submodule = yang_argument_get(yi);
+ /* Is there a specific revision (or just latest)? */
+ if ((yrev = yang_find(yi, Y_REVISION_DATE, NULL)) != NULL)
+ subrevision = yang_argument_get(yrev);
+ else
+ subrevision = NULL;
+ /* if already loaded, ignore, else parse the file */
+ if (yang_find(ysp,
+ keyw==Y_IMPORT?Y_MODULE:Y_SUBMODULE,
+ submodule) == NULL){
+ /* recursive call */
+ if ((subymod = yang_parse_module(h, submodule, subrevision, ysp, yang_argument_get(ymod))) == NULL)
+ goto done;
+ /* Sanity check: if submodule, its belongs-to statement shall point to the module */
+ if (keyw == Y_INCLUDE){
+ ybelongto = yang_find(subymod, Y_BELONGS_TO, NULL);
+ if (ybelongto == NULL){
+ clicon_err(OE_YANG, ENOENT, "Sub-module \"%s\" does not have a belongs-to statement", submodule); /* shouldnt happen */
+ goto done;
+ }
+ if (strcmp(yang_argument_get(ybelongto), yang_argument_get(yrealmod)) != 0){
+ clicon_err(OE_YANG, ENOENT, "Sub-module \"%s\" references module \"%s\" in its belongs-to statement but should reference \"%s\"",
+ submodule,
+ yang_argument_get(ybelongto),
+ yang_argument_get(yrealmod));
+ goto done;
+ }
+ }
+ /* Go through its sub-modules recursively */
+ if (yang_parse_recurse(h, subymod, ysp) < 0){
+ ymod = NULL;
+ goto done;
+ }
+ }
}
retval = 0;
done:
@@ -1212,7 +1212,7 @@ yang_parse_recurse(clicon_handle h,
*/
static int
ys_schemanode_check(yang_stmt *ys,
- void *dummy)
+ void *dummy)
{
int retval = -1;
yang_stmt *yres = NULL;
@@ -1229,43 +1229,43 @@ ys_schemanode_check(yang_stmt *ys,
keyword = yang_keyword_get(ys);
switch (yang_keyword_get(ys)){
case Y_AUGMENT:
- if (yang_keyword_get(yp) == Y_MODULE || /* Not top-level */
- yang_keyword_get(yp) == Y_SUBMODULE)
- break;
- /* fallthru */
+ if (yang_keyword_get(yp) == Y_MODULE || /* Not top-level */
+ yang_keyword_get(yp) == Y_SUBMODULE)
+ break;
+ /* fallthru */
case Y_REFINE:
- if (yang_desc_schema_nodeid(yp, arg, &yres) < 0)
- goto done;
- if (yres == NULL){
- clicon_err(OE_YANG, 0, "schemanode sanity check of %s %s",
- yang_key2str(keyword), arg);
- goto done;
- }
- break;
+ if (yang_desc_schema_nodeid(yp, arg, &yres) < 0)
+ goto done;
+ if (yres == NULL){
+ clicon_err(OE_YANG, 0, "schemanode sanity check of %s %s",
+ yang_key2str(keyword), arg);
+ goto done;
+ }
+ break;
case Y_UNIQUE:{
- /* Unique: Sec 7.8.3 It takes as an argument a string that contains a space-
- separated list of schema node identifiers */
- if ((vec = clicon_strsep(arg, " \t\n", &nvec)) == NULL)
- goto done;
- for (i=0; iys_stmt[i])) < 0)
- goto done;
+ if (yang_cardinality(h, yang_child_i(yspec, i), yang_argument_get(yspec->ys_stmt[i])) < 0)
+ goto done;
/* 3: Check features/if-features: check if enabled and remove disabled features */
for (i=modmin; i ym0/rev0 */
- rev0 = 0;
- if ((ym0 = yang_find(yspec, Y_MODULE, base)) != NULL ||
- (ym0 = yang_find(yspec, Y_SUBMODULE, base)) != NULL){
- yrev = yang_find(ym0, Y_REVISION, NULL);
- rev0 = cv_uint32_get(yang_cv_get(yrev));
- continue; /* skip if already added by specific file or module */
- }
- /* Create full filename */
- snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dp[i].d_name);
- if ((ym = yang_parse_filename(filename, yspec)) == NULL)
- goto done;
- revm = 0;
- if ((yrev = yang_find(ym, Y_REVISION, NULL)) != NULL)
- revm = cv_uint32_get(yang_cv_get(yrev));
- /* Sanity check that file revision does not match internal rev stmt */
- if (revf && revm && revm != revf){ /* XXX */
- clicon_err(OE_YANG, EINVAL, "Yang module file revision and in yang does not match: %s(%u) vs %u", filename, revf, revm);
- goto done;
- }
- /* If ym0 and ym exists, delete the yang with oldest revision
- * This is a failsafe in case anything else fails
- */
- if (revm && rev0){
- if (revm > rev0) /* Loaded module is older or eq -> remove ym */
- ym = ym0;
- for (j=0; jys_stmt[j] == ym)
- break;
- ys_prune(yspec, j);
- ys_free(ym);
- }
+ oldbase = base;
+ base = NULL;
+ revf = 0;
+ if (filename2revision(dp[i].d_name, &base, &revf) < 0)
+ goto done;
+ if (oldbase && strcmp(base, oldbase)) /* new yang file basename */
+ taken = 0;
+ if (revf == 0) /* No revision: a.yang - take that */
+ taken = 1;
+ else{ /* a@xxx.yang */
+ if (taken)
+ continue; /* skip if already taken */
+ /* Look forward: is there anyone else later? (assume sorted revision dates) */
+ if (i+1 < ndp){ /* not last in list */
+ char *nextbase = NULL; /* XXX suboptimal algorithm, could combione old/next/base */
+ if (filename2revision(dp[i+1].d_name, &nextbase, NULL) < 0)
+ goto done;
+ if (nextbase && strcmp(base, nextbase) == 0){
+ free(nextbase);
+ nextbase = NULL;
+ continue; /* same base: skip; */
+ }
+ if (nextbase)
+ free(nextbase);
+ }
+ taken = 1; /* last in line and not taken */
+ }
+ /* Here only a single file is reached(taken)
+ * Check if module already exists -> ym0/rev0 */
+ rev0 = 0;
+ if ((ym0 = yang_find(yspec, Y_MODULE, base)) != NULL ||
+ (ym0 = yang_find(yspec, Y_SUBMODULE, base)) != NULL){
+ yrev = yang_find(ym0, Y_REVISION, NULL);
+ rev0 = cv_uint32_get(yang_cv_get(yrev));
+ continue; /* skip if already added by specific file or module */
+ }
+ /* Create full filename */
+ snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dp[i].d_name);
+ if ((ym = yang_parse_filename(filename, yspec)) == NULL)
+ goto done;
+ revm = 0;
+ if ((yrev = yang_find(ym, Y_REVISION, NULL)) != NULL)
+ revm = cv_uint32_get(yang_cv_get(yrev));
+ /* Sanity check that file revision does not match internal rev stmt */
+ if (revf && revm && revm != revf){ /* XXX */
+ clicon_err(OE_YANG, EINVAL, "Yang module file revision and in yang does not match: %s(%u) vs %u", filename, revf, revm);
+ goto done;
+ }
+ /* If ym0 and ym exists, delete the yang with oldest revision
+ * This is a failsafe in case anything else fails
+ */
+ if (revm && rev0){
+ if (revm > rev0) /* Loaded module is older or eq -> remove ym */
+ ym = ym0;
+ for (j=0; jys_stmt[j] == ym)
+ break;
+ ys_prune(yspec, j);
+ ys_free(ym);
+ }
}
if (yang_parse_post(h, yspec, modmin) < 0)
- goto done;
+ goto done;
ok:
retval = 0;
done:
if (dp)
- free(dp);
+ free(dp);
if (base)
- free(base);
+ free(base);
if (oldbase)
- free(oldbase);
+ free(oldbase);
return retval;
}
@@ -1795,29 +1795,29 @@ yang_spec_load_dir(clicon_handle h,
*/
int
ys_parse_date_arg(char *datearg,
- uint32_t *dateint)
+ uint32_t *dateint)
{
int retval = -1;
int i;
uint32_t d = 0;
if (strlen(datearg) != 10 || datearg[4] != '-' || datearg[7] != '-'){
- clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
- goto done;
+ clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
+ goto done;
}
if ((i = cligen_tonum(4, datearg)) < 0){
- clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
- goto done;
+ clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
+ goto done;
}
d = i*10000; /* year */
if ((i = cligen_tonum(2, &datearg[5])) < 0){
- clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
- goto done;
+ clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
+ goto done;
}
d += i*100; /* month */
if ((i = cligen_tonum(2, &datearg[8])) < 0){
- clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
- goto done;
+ clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
+ goto done;
}
d += i; /* day */
*dateint = d;
@@ -1834,34 +1834,34 @@ ys_parse_date_arg(char *datearg,
*/
cg_var *
ys_parse(yang_stmt *ys,
- enum cv_type cvtype)
+ enum cv_type cvtype)
{
int cvret;
char *reason = NULL;
cg_var *cv = NULL;
if ((cv = yang_cv_get(ys)) != NULL){
- /* eg mandatory in uses is already set and then copied */
- cv_free(cv);
- yang_cv_set(ys, NULL);
+ /* eg mandatory in uses is already set and then copied */
+ cv_free(cv);
+ yang_cv_set(ys, NULL);
}
if ((cv = cv_new(cvtype)) == NULL){
- clicon_err(OE_YANG, errno, "cv_new");
- goto done;
+ clicon_err(OE_YANG, errno, "cv_new");
+ goto done;
}
if ((cvret = cv_parse1(yang_argument_get(ys), cv, &reason)) < 0){ /* error */
- clicon_err(OE_YANG, errno, "parsing cv");
- goto done;
+ clicon_err(OE_YANG, errno, "parsing cv");
+ goto done;
}
if (cvret == 0){ /* parsing failed */
- clicon_err(OE_YANG, errno, "Parsing CV: %s", reason);
- goto done;
+ clicon_err(OE_YANG, errno, "Parsing CV: %s", reason);
+ goto done;
}
yang_cv_set(ys, cv);
/* cvret == 1 means parsing is OK */
done:
if (reason)
- free(reason);
+ free(reason);
return yang_cv_get(ys);
}
@@ -1885,8 +1885,8 @@ ys_parse(yang_stmt *ys,
*/
int
ys_parse_sub(yang_stmt *ys,
- const char *filename,
- char *extra)
+ const char *filename,
+ char *extra)
{
int retval = -1;
uint8_t fd;
@@ -1905,127 +1905,127 @@ ys_parse_sub(yang_stmt *ys,
case Y_BASE:
case Y_TYPE:
case Y_USES:
- /* Invoke next level parser
- */
- if (yang_schema_nodeid_subparse(yang_argument_get(ys), YA_ID_REF, filename, yang_linenum_get(ys)) < 0)
- goto done;
- break;
+ /* Invoke next level parser
+ */
+ if (yang_schema_nodeid_subparse(yang_argument_get(ys), YA_ID_REF, filename, yang_linenum_get(ys)) < 0)
+ goto done;
+ break;
case Y_FRACTION_DIGITS:
- if (ys_parse(ys, CGV_UINT8) == NULL)
- goto done;
- if ((cv = yang_cv_get(ys)) == NULL){
- clicon_err(OE_YANG, ENOENT, "Unexpected NULL cv");
- goto done;
- }
- fd = cv_uint8_get(cv);
- if (fd < 1 || fd > 18){
- clicon_err(OE_YANG, errno, "%u: Out of range, should be [1:18]", fd);
- goto done;
- }
- break;
+ if (ys_parse(ys, CGV_UINT8) == NULL)
+ goto done;
+ if ((cv = yang_cv_get(ys)) == NULL){
+ clicon_err(OE_YANG, ENOENT, "Unexpected NULL cv");
+ goto done;
+ }
+ fd = cv_uint8_get(cv);
+ if (fd < 1 || fd > 18){
+ clicon_err(OE_YANG, errno, "%u: Out of range, should be [1:18]", fd);
+ goto done;
+ }
+ break;
case Y_MUST:
case Y_WHEN:
- if (xpath_parse(yang_argument_get(ys), NULL) < 0)
- goto done;
- break;
+ if (xpath_parse(yang_argument_get(ys), NULL) < 0)
+ goto done;
+ break;
case Y_REVISION:
case Y_REVISION_DATE: /* YYYY-MM-DD encoded as uint32 YYYYMMDD */
- if (ys_parse_date_arg(arg, &date) < 0)
- goto done;
- if ((cv = cv_new(CGV_UINT32)) == NULL){
- clicon_err(OE_YANG, errno, "cv_new");
- goto done;
- }
- yang_cv_set(ys, cv);
- cv_uint32_set(cv, date);
- break;
+ if (ys_parse_date_arg(arg, &date) < 0)
+ goto done;
+ if ((cv = cv_new(CGV_UINT32)) == NULL){
+ clicon_err(OE_YANG, errno, "cv_new");
+ goto done;
+ }
+ yang_cv_set(ys, cv);
+ cv_uint32_set(cv, date);
+ break;
case Y_STATUS: /* RFC7950 7.21.2: "current", "deprecated", or "obsolete". */
- if (strcmp(arg, "current") &&
- strcmp(arg, "deprecated") &&
- strcmp(arg, "obsolete")){
- clicon_err(OE_YANG, errno, "Invalid status: \"%s\", expected current, deprecated, or obsolete", arg);
- goto done;
+ if (strcmp(arg, "current") &&
+ strcmp(arg, "deprecated") &&
+ strcmp(arg, "obsolete")){
+ clicon_err(OE_YANG, errno, "Invalid status: \"%s\", expected current, deprecated, or obsolete", arg);
+ goto done;
- }
- break;
+ }
+ break;
case Y_MAX_ELEMENTS:
case Y_MIN_ELEMENTS:
- if ((cv = cv_new(CGV_UINT32)) == NULL){
- clicon_err(OE_YANG, errno, "cv_new");
- goto done;
- }
- yang_cv_set(ys, cv);
- if (keyword == Y_MAX_ELEMENTS &&
- strcmp(arg, "unbounded") == 0)
- cv_uint32_set(cv, 0); /* 0 means unbounded for max */
- else{
- if ((ret = parse_uint32(arg, &minmax, &reason)) < 0){
- clicon_err(OE_YANG, errno, "parse_uint32");
- goto done;
- }
- if (ret == 0){
- clicon_err(OE_YANG, EINVAL, "element-min/max parse error: %s", reason);
- if (reason)
- free(reason);
- goto done;
- }
- cv_uint32_set(cv, minmax);
- }
- break;
+ if ((cv = cv_new(CGV_UINT32)) == NULL){
+ clicon_err(OE_YANG, errno, "cv_new");
+ goto done;
+ }
+ yang_cv_set(ys, cv);
+ if (keyword == Y_MAX_ELEMENTS &&
+ strcmp(arg, "unbounded") == 0)
+ cv_uint32_set(cv, 0); /* 0 means unbounded for max */
+ else{
+ if ((ret = parse_uint32(arg, &minmax, &reason)) < 0){
+ clicon_err(OE_YANG, errno, "parse_uint32");
+ goto done;
+ }
+ if (ret == 0){
+ clicon_err(OE_YANG, EINVAL, "element-min/max parse error: %s", reason);
+ if (reason)
+ free(reason);
+ goto done;
+ }
+ cv_uint32_set(cv, minmax);
+ }
+ break;
case Y_MODIFIER:
- if (strcmp(yang_argument_get(ys), "invert-match")){
- clicon_err(OE_YANG, EINVAL, "modifier %s, expected invert-match", yang_argument_get(ys));
- goto done;
- }
- break;
+ if (strcmp(yang_argument_get(ys), "invert-match")){
+ clicon_err(OE_YANG, EINVAL, "modifier %s, expected invert-match", yang_argument_get(ys));
+ goto done;
+ }
+ break;
case Y_IF_FEATURE:
- /* Invoke next level parser on if-feature-expr string. Note do not send ys since
- * pass 1 is not yet resolved, only check syntax, actual feature check made in next pass
- * @see yang_features
- */
- if (yang_subparse(yang_argument_get(ys), ys, YA_IF_FEATURE, filename, yang_linenum_get(ys), NULL) < 0)
- goto done;
- break;
+ /* Invoke next level parser on if-feature-expr string. Note do not send ys since
+ * pass 1 is not yet resolved, only check syntax, actual feature check made in next pass
+ * @see yang_features
+ */
+ if (yang_subparse(yang_argument_get(ys), ys, YA_IF_FEATURE, filename, yang_linenum_get(ys), NULL) < 0)
+ goto done;
+ break;
case Y_AUGMENT: /* If parent is module/submodule: absolute-schema-nodeid
- * If parent is uses: descendant-schema-nodeid
- */
- if ((yp = yang_parent_get(ys)) &&
- yang_keyword_get(yp) != Y_USES){
- if (yang_schema_nodeid_subparse(yang_argument_get(ys), YA_ABS_SCHEMANODEID, filename, yang_linenum_get(ys)) < 0)
- goto done;
- break;
- }
- // fall through
+ * If parent is uses: descendant-schema-nodeid
+ */
+ if ((yp = yang_parent_get(ys)) &&
+ yang_keyword_get(yp) != Y_USES){
+ if (yang_schema_nodeid_subparse(yang_argument_get(ys), YA_ABS_SCHEMANODEID, filename, yang_linenum_get(ys)) < 0)
+ goto done;
+ break;
+ }
+ // fall through
case Y_REFINE:
- /* Invoke next level parser on refine-arg-str / descendant-schema-nodeid
- */
- if (yang_schema_nodeid_subparse(yang_argument_get(ys), YA_DESC_SCHEMANODEID, filename, yang_linenum_get(ys)) < 0)
- goto done;
- break;
+ /* Invoke next level parser on refine-arg-str / descendant-schema-nodeid
+ */
+ if (yang_schema_nodeid_subparse(yang_argument_get(ys), YA_DESC_SCHEMANODEID, filename, yang_linenum_get(ys)) < 0)
+ goto done;
+ break;
case Y_UNKNOWN:{ /* save (optional) argument in ys_cv */
- if (extra == NULL)
- break;
- if ((cv = cv_new(CGV_STRING)) == NULL){
- clicon_err(OE_YANG, errno, "cv_new");
- goto done;
- }
- yang_cv_set(ys, cv);
- if ((ret = cv_parse1(extra, cv, &reason)) < 0){ /* error */
- clicon_err(OE_YANG, errno, "parsing cv");
- goto done;
- }
- if (ret == 0){ /* parsing failed */
- clicon_err(OE_YANG, errno, "Parsing CV: %s", reason);
- goto done;
- }
- break;
+ if (extra == NULL)
+ break;
+ if ((cv = cv_new(CGV_STRING)) == NULL){
+ clicon_err(OE_YANG, errno, "cv_new");
+ goto done;
+ }
+ yang_cv_set(ys, cv);
+ if ((ret = cv_parse1(extra, cv, &reason)) < 0){ /* error */
+ clicon_err(OE_YANG, errno, "parsing cv");
+ goto done;
+ }
+ if (ret == 0){ /* parsing failed */
+ clicon_err(OE_YANG, errno, "Parsing CV: %s", reason);
+ goto done;
+ }
+ break;
}
default:
- break;
+ break;
}
retval = 0;
done:
if (extra)
- free(extra);
+ free(extra);
return retval;
}
diff --git a/lib/src/clixon_yang_schemanode_parse.h b/lib/src/clixon_yang_schemanode_parse.h
index 67c9945b..54768fc1 100644
--- a/lib/src/clixon_yang_schemanode_parse.h
+++ b/lib/src/clixon_yang_schemanode_parse.h
@@ -64,4 +64,4 @@ int clixon_yang_schemanode_parsel_linenr(void);
int clixon_yang_schemanode_parselex(void *);
int clixon_yang_schemanode_parseparse(void *);
-#endif /* _CLIXON_YANG_SCHEMANODE_PARSE_H_ */
+#endif /* _CLIXON_YANG_SCHEMANODE_PARSE_H_ */
diff --git a/lib/src/clixon_yang_schemanode_parse.y b/lib/src/clixon_yang_schemanode_parse.y
index 8f0dd9c6..d9c09e7d 100644
--- a/lib/src/clixon_yang_schemanode_parse.y
+++ b/lib/src/clixon_yang_schemanode_parse.y
@@ -101,16 +101,16 @@
void
clixon_yang_schemanode_parseerror(void *arg,
- char *s)
+ char *s)
{
clixon_yang_schemanode_yacc *ife = (clixon_yang_schemanode_yacc *)arg;
clicon_err_fn(NULL, 0, OE_YANG, 0, "yang_schemanode_parse: file:%s:%d \"%s\" %s: at or before: %s",
- ife->if_mainfile,
- ife->if_linenum,
- ife->if_parse_string,
- s,
- clixon_yang_schemanode_parsetext);
+ ife->if_mainfile,
+ ife->if_linenum,
+ ife->if_parse_string,
+ s,
+ clixon_yang_schemanode_parsetext);
return;
}
@@ -121,77 +121,77 @@ clixon_yang_schemanode_parseerror(void *arg,
/* See RFC 7950 Sec 14 refine-arg-str / usage-augment-arg-str */
top : descendant_schema_nodeid MY_EOF
{
- _PARSE_DEBUG("top->descendant-schema-nodeid");
- if (_IF->if_accept == YA_DESC_SCHEMANODEID){
- YYACCEPT;
- }
- else{
- _YYERROR("descendant-schema-nodeid unexpected");
- }
- }
+ _PARSE_DEBUG("top->descendant-schema-nodeid");
+ if (_IF->if_accept == YA_DESC_SCHEMANODEID){
+ YYACCEPT;
+ }
+ else{
+ _YYERROR("descendant-schema-nodeid unexpected");
+ }
+ }
| absolute_schema_nodeid MY_EOF
{
- _PARSE_DEBUG("top->absolute-schema-nodeid");
- if (_IF->if_accept == YA_ABS_SCHEMANODEID){
- YYACCEPT;
- }
- else{
- _YYERROR("absolute-schema-nodeid unexpected");
- }
- }
+ _PARSE_DEBUG("top->absolute-schema-nodeid");
+ if (_IF->if_accept == YA_ABS_SCHEMANODEID){
+ YYACCEPT;
+ }
+ else{
+ _YYERROR("absolute-schema-nodeid unexpected");
+ }
+ }
;
descendant_schema_nodeid
: node_identifier
{
- _PARSE_DEBUG("descendant-schema-nodeid->node-identifier");
- }
+ _PARSE_DEBUG("descendant-schema-nodeid->node-identifier");
+ }
| node_identifier absolute_schema_nodeid
- {
- _PARSE_DEBUG("descendant-schema-nodeid->absolute-schema-nodeid");
- }
+ {
+ _PARSE_DEBUG("descendant-schema-nodeid->absolute-schema-nodeid");
+ }
;
absolute_schema_nodeid
: absolute_schema_nodeid '/' node_identifier
{
- _PARSE_DEBUG("absolute-schema-nodeid->absolute-schema-nodeid '/' node-identifier");
- }
+ _PARSE_DEBUG("absolute-schema-nodeid->absolute-schema-nodeid '/' node-identifier");
+ }
| '/' node_identifier
- {
- _PARSE_DEBUG("absolute-schema-nodeid->'/' node-identifier");
- }
+ {
+ _PARSE_DEBUG("absolute-schema-nodeid->'/' node-identifier");
+ }
;
/* node-identifier = [prefix ":"] identifier */
node_identifier : identifier
- {
- _PARSE_DEBUG("node-identifier -> identifier");
- if (_IF->if_accept == YA_ID_REF){
- YYACCEPT;
- }
- }
+ {
+ _PARSE_DEBUG("node-identifier -> identifier");
+ if (_IF->if_accept == YA_ID_REF){
+ YYACCEPT;
+ }
+ }
| prefix ':' identifier
- {
- _PARSE_DEBUG("node_identifier -> prefix : identifier");
- if (_IF->if_accept == YA_ID_REF){
- YYACCEPT;
- }
- }
+ {
+ _PARSE_DEBUG("node_identifier -> prefix : identifier");
+ if (_IF->if_accept == YA_ID_REF){
+ YYACCEPT;
+ }
+ }
;
prefix : IDENTIFIER
- {
- _PARSE_DEBUG("prefix -> IDENTIFIER");
- free($1);
- }
+ {
+ _PARSE_DEBUG("prefix -> IDENTIFIER");
+ free($1);
+ }
;
identifier : IDENTIFIER
- {
- _PARSE_DEBUG("identifier -> IDENTIFIER");
- free($1);
- }
+ {
+ _PARSE_DEBUG("identifier -> IDENTIFIER");
+ free($1);
+ }
;
%%
diff --git a/lib/src/clixon_yang_sub_parse.c b/lib/src/clixon_yang_sub_parse.c
index 63418bde..8fa49a9e 100644
--- a/lib/src/clixon_yang_sub_parse.c
+++ b/lib/src/clixon_yang_sub_parse.c
@@ -70,11 +70,11 @@
*/
int
yang_subparse(char *str,
- yang_stmt *ys,
- enum yang_sub_parse_accept accept,
- const char *mainfile,
- int linenum,
- int *enabled)
+ yang_stmt *ys,
+ enum yang_sub_parse_accept accept,
+ const char *mainfile,
+ int linenum,
+ int *enabled)
{
int retval = -1;
clixon_yang_sub_parse_yacc ife = {0,};
@@ -83,18 +83,18 @@ yang_subparse(char *str,
ife.if_parse_string = str;
ife.if_linenum = linenum;
if (enabled)
- ife.if_ys = ys; /* Used as trigger to check if enabled */
+ ife.if_ys = ys; /* Used as trigger to check if enabled */
ife.if_accept = accept;
ife.if_mainfile = mainfile;
if (clixon_yang_sub_parsel_init(&ife) < 0)
- goto done;
+ goto done;
if (clixon_yang_sub_parseparse(&ife) != 0) { /* yacc returns 1 on error */
- if (clicon_errno == 0)
- clicon_err(OE_YANG, 0, "If-feature parser error with no error code (should not happen)");
- goto done;
+ if (clicon_errno == 0)
+ clicon_err(OE_YANG, 0, "If-feature parser error with no error code (should not happen)");
+ goto done;
}
if (enabled)
- *enabled = ife.if_enabled;
+ *enabled = ife.if_enabled;
retval = 0;
done:
clixon_yang_sub_parsel_exit(&ife);
@@ -113,9 +113,9 @@ yang_subparse(char *str,
*/
int
yang_schema_nodeid_subparse(char *str,
- enum yang_sub_parse_accept accept,
- const char *mainfile,
- int linenum)
+ enum yang_sub_parse_accept accept,
+ const char *mainfile,
+ int linenum)
{
int retval = -1;
clixon_yang_schemanode_yacc ife = {0,};
@@ -126,11 +126,11 @@ yang_schema_nodeid_subparse(char *str,
ife.if_mainfile = mainfile;
ife.if_accept = accept; /* accept absolute-schema-nodeid */
if (clixon_yang_schemanode_parsel_init(&ife) < 0)
- goto done;
+ goto done;
if (clixon_yang_schemanode_parseparse(&ife) != 0) { /* yacc returns 1 on error */
- if (clicon_errno == 0)
- clicon_err(OE_YANG, 0, "descendant-schema-nodeid parser error with no error code (should not happen)");
- goto done;
+ if (clicon_errno == 0)
+ clicon_err(OE_YANG, 0, "descendant-schema-nodeid parser error with no error code (should not happen)");
+ goto done;
}
retval = 0;
done:
diff --git a/lib/src/clixon_yang_sub_parse.h b/lib/src/clixon_yang_sub_parse.h
index e8c18ad9..c203ea51 100644
--- a/lib/src/clixon_yang_sub_parse.h
+++ b/lib/src/clixon_yang_sub_parse.h
@@ -76,4 +76,4 @@ int clixon_yang_sub_parseparse(void *);
int yang_subparse(char *str, yang_stmt *ys, enum yang_sub_parse_accept accept, const char *mainfile, int linenum, int *enabled);
int yang_schema_nodeid_subparse(char *str, enum yang_sub_parse_accept accept, const char *mainfile, int linenum);
-#endif /* _CLIXON_YANG_SUB_PARSER_H_ */
+#endif /* _CLIXON_YANG_SUB_PARSER_H_ */
diff --git a/lib/src/clixon_yang_sub_parse.y b/lib/src/clixon_yang_sub_parse.y
index 80d7ed1a..b0ecf29e 100644
--- a/lib/src/clixon_yang_sub_parse.y
+++ b/lib/src/clixon_yang_sub_parse.y
@@ -111,16 +111,16 @@
void
clixon_yang_sub_parseerror(void *arg,
- char *s)
+ char *s)
{
clixon_yang_sub_parse_yacc *ife = (clixon_yang_sub_parse_yacc *)arg;
clicon_err_fn(NULL, 0, OE_YANG, 0, "yang_sub_parse: file:%s:%d \"%s\" %s: at or before: %s",
- ife->if_mainfile,
- ife->if_linenum,
- ife->if_parse_string,
- s,
- clixon_yang_sub_parsetext);
+ ife->if_mainfile,
+ ife->if_linenum,
+ ife->if_parse_string,
+ s,
+ clixon_yang_sub_parsetext);
return;
}
@@ -130,7 +130,7 @@ clixon_yang_sub_parseerror(void *arg,
*/
static int
if_feature_check(clixon_yang_sub_parse_yacc *ife,
- char *str)
+ char *str)
{
int retval = -1;
char *prefix = NULL;
@@ -141,36 +141,36 @@ if_feature_check(clixon_yang_sub_parse_yacc *ife,
yang_stmt *ys;
if ((ys = ife->if_ys) == NULL)
- return 0;
+ return 0;
if (nodeid_split(str, &prefix, &feature) < 0)
- goto done;
+ goto done;
/* Specifically need to handle? strcmp(prefix, myprefix)) */
if (prefix == NULL)
- ymod = ys_module(ys);
+ ymod = ys_module(ys);
else
- ymod = yang_find_module_by_prefix(ys, prefix);
+ ymod = yang_find_module_by_prefix(ys, prefix);
if (ymod == NULL)
- goto done;
+ goto done;
/* Check if feature exists, and is set, otherwise remove */
if ((yfeat = yang_find(ymod, Y_FEATURE, feature)) == NULL){
- clicon_err(OE_YANG, EINVAL, "Yang module %s has IF_FEATURE %s, but no such FEATURE statement exists",
- ymod?yang_argument_get(ymod):"none",
- feature);
- goto done;
+ clicon_err(OE_YANG, EINVAL, "Yang module %s has IF_FEATURE %s, but no such FEATURE statement exists",
+ ymod?yang_argument_get(ymod):"none",
+ feature);
+ goto done;
}
/* Check if this feature is enabled or not
* Continue loop to catch unbound features and make verdict at end
*/
cv = yang_cv_get(yfeat);
if (cv == NULL || !cv_bool_get(cv)) /* disabled */
- retval = 0;
+ retval = 0;
else /* enabled */
- retval = 1;
+ retval = 1;
done:
if (prefix)
- free(prefix);
+ free(prefix);
if (feature)
- free(feature);
+ free(feature);
return retval;
}
@@ -181,84 +181,84 @@ if_feature_check(clixon_yang_sub_parse_yacc *ife,
/* See RFC 7950 Sec 14 if-feature-expr-str */
top : if_feature_expr MY_EOF
{
- _PARSE_DEBUG("top->if-feature-expr");
- _IF->if_enabled = $1;
- if (_IF->if_accept == YA_IF_FEATURE){
- YYACCEPT;
- }
- else{
- _YYERROR("Expected if-feature-expr");
- }
- }
+ _PARSE_DEBUG("top->if-feature-expr");
+ _IF->if_enabled = $1;
+ if (_IF->if_accept == YA_IF_FEATURE){
+ YYACCEPT;
+ }
+ else{
+ _YYERROR("Expected if-feature-expr");
+ }
+ }
;
if_feature_expr : if_feature_factor sep1 OR sep1 if_feature_expr
{
- _PARSE_DEBUG("if-feature-expr->if-feature-factor sep OR sep expr");
- $$ = $1 || $5;
- }
+ _PARSE_DEBUG("if-feature-expr->if-feature-factor sep OR sep expr");
+ $$ = $1 || $5;
+ }
| if_feature_factor sep1 AND sep1 if_feature_expr
- {
- _PARSE_DEBUG("if-feature-expr->if-feature-factor sep AND sep if-feature-expr");
- $$ = $1 && $5;
- }
+ {
+ _PARSE_DEBUG("if-feature-expr->if-feature-factor sep AND sep if-feature-expr");
+ $$ = $1 && $5;
+ }
| if_feature_factor
- {
- _PARSE_DEBUG("if-feature-expr->if-feature-factor");
- $$ = $1;
- }
+ {
+ _PARSE_DEBUG("if-feature-expr->if-feature-factor");
+ $$ = $1;
+ }
;
if_feature_factor : NOT sep1 if_feature_factor
{ _PARSE_DEBUG("if-feature-factor-> NOT sep if-feature-factor");
- $$ = !$3; }
+ $$ = !$3; }
| '(' optsep if_feature_expr optsep ')'
- { _PARSE_DEBUG("if-feature-factor-> ( optsep if-feature-expr optsep )");
- $$ = $3; }
+ { _PARSE_DEBUG("if-feature-factor-> ( optsep if-feature-expr optsep )");
+ $$ = $3; }
| identifier_ref {
- _PARSE_DEBUG("if-feature-factor-> identifier-ref");
- if (($$ = if_feature_check(_IF, $1)) < 0) {
- free($1);
- YYERROR;
- }
- free($1);
- }
+ _PARSE_DEBUG("if-feature-factor-> identifier-ref");
+ if (($$ = if_feature_check(_IF, $1)) < 0) {
+ free($1);
+ YYERROR;
+ }
+ free($1);
+ }
;
/* identifier-ref = [prefix ":"] identifier */
identifier_ref : identifier
- {
- // XXX memory leak?
- _PARSE_DEBUG("identifier-ref -> identifier");
- if (_IF->if_accept == YA_ID_REF){
- YYACCEPT;
- }
- $$=$1;
- }
+ {
+ // XXX memory leak?
+ _PARSE_DEBUG("identifier-ref -> identifier");
+ if (_IF->if_accept == YA_ID_REF){
+ YYACCEPT;
+ }
+ $$=$1;
+ }
| prefix ':' identifier
- {
- if (($$=clixon_string_del_join($1, ":", $3)) == NULL) _YYERROR("identifier_ref");
- free($3);
- if (_IF->if_accept == YA_ID_REF){
- YYACCEPT;
- }
- _PARSE_DEBUG("identifier-ref -> prefix : identifier");
- }
+ {
+ if (($$=clixon_string_del_join($1, ":", $3)) == NULL) _YYERROR("identifier_ref");
+ free($3);
+ if (_IF->if_accept == YA_ID_REF){
+ YYACCEPT;
+ }
+ _PARSE_DEBUG("identifier-ref -> prefix : identifier");
+ }
;
prefix : IDENTIFIER
- {
- _PARSE_DEBUG("prefix -> IDENTIFIER");
- $$=$1;
+ {
+ _PARSE_DEBUG("prefix -> IDENTIFIER");
+ $$=$1;
- }
+ }
;
identifier : IDENTIFIER
- {
- _PARSE_DEBUG("identifier -> IDENTIFIER");
- $$=$1;
- }
+ {
+ _PARSE_DEBUG("identifier -> IDENTIFIER");
+ $$=$1;
+ }
;
optsep : sep1 { _PARSE_DEBUG("optsep->sep"); }
diff --git a/lib/src/clixon_yang_type.c b/lib/src/clixon_yang_type.c
index 22cd0e84..60c596f2 100644
--- a/lib/src/clixon_yang_type.c
+++ b/lib/src/clixon_yang_type.c
@@ -166,7 +166,7 @@ static int
yang_builtin(char *type)
{
if (clicon_str2int_search(ytmap2, type, (sizeof(ytmap)/sizeof(map_str2int))-2) != -1)
- return 1;
+ return 1;
return 0;
}
@@ -182,8 +182,8 @@ yang_builtin(char *type)
*/
static int
compile_pattern2regexp(clicon_handle h,
- cvec *patterns,
- cvec *regexps)
+ cvec *patterns,
+ cvec *regexps)
{
int retval = -1;
cg_var *pcv; /* pattern cv */
@@ -194,26 +194,26 @@ compile_pattern2regexp(clicon_handle h,
pcv = NULL;
while ((pcv = cvec_each(patterns, pcv)) != NULL){
- pattern = cv_string_get(pcv);
- /* Compile yang pattern. handle necessary to select regex engine */
- if ((ret = regex_compile(h, pattern, &re)) < 0)
- goto done;
- if (ret == 0){
- clicon_err(OE_YANG, errno, "regexp compile fail: \"%s\"",
- pattern);
- goto done;
- break;
- }
- if ((rcv = cvec_add(regexps, CGV_VOID)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_add");
- goto done;
- }
- if (re != NULL)
- cv_void_set(rcv, re);
- re = NULL;
- /* invert pattern check */
- if (cv_flag(pcv, V_INVERT))
- cv_flag_set(rcv, V_INVERT);
+ pattern = cv_string_get(pcv);
+ /* Compile yang pattern. handle necessary to select regex engine */
+ if ((ret = regex_compile(h, pattern, &re)) < 0)
+ goto done;
+ if (ret == 0){
+ clicon_err(OE_YANG, errno, "regexp compile fail: \"%s\"",
+ pattern);
+ goto done;
+ break;
+ }
+ if ((rcv = cvec_add(regexps, CGV_VOID)) == NULL){
+ clicon_err(OE_UNIX, errno, "cvec_add");
+ goto done;
+ }
+ if (re != NULL)
+ cv_void_set(rcv, re);
+ re = NULL;
+ /* invert pattern check */
+ if (cv_flag(pcv, V_INVERT))
+ cv_flag_set(rcv, V_INVERT);
}
retval = 1;
done:
@@ -228,7 +228,7 @@ compile_pattern2regexp(clicon_handle h,
*/
int
ys_resolve_type(yang_stmt *ys,
- void *arg)
+ void *arg)
{
// clicon_handle h = (clicon_handle)arg;
int retval = -1;
@@ -239,8 +239,8 @@ ys_resolve_type(yang_stmt *ys,
yang_stmt *resolved = NULL;
if (yang_keyword_get(ys) != Y_TYPE){
- clicon_err(OE_YANG, EINVAL, "Expected Y_TYPE");
- goto done;
+ clicon_err(OE_YANG, EINVAL, "Expected Y_TYPE");
+ goto done;
}
if ((patterns = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
@@ -250,23 +250,23 @@ ys_resolve_type(yang_stmt *ys,
* Note that the resolved type could be ys itself.
*/
if (yang_type_resolve(yang_parent_get(ys), yang_parent_get(ys),
- ys, &resolved,
- &options, &cvv, patterns, NULL, &fraction) < 0)
- goto done;
+ ys, &resolved,
+ &options, &cvv, patterns, NULL, &fraction) < 0)
+ goto done;
if (resolved == NULL){
- clicon_err(OE_YANG, 0, "result-type should not be NULL");
- goto done;
+ clicon_err(OE_YANG, 0, "result-type should not be NULL");
+ goto done;
}
/* Cache the type resolving locally. Only place where this is done.
* Why not do it in yang_type_resolve? (compile regexps needs clicon_handle)
*/
if (yang_type_cache_set(ys, resolved, options, cvv,
- patterns, fraction) < 0)
- goto done;
+ patterns, fraction) < 0)
+ goto done;
retval = 0;
done:
if (patterns)
- cvec_free(patterns);
+ cvec_free(patterns);
return retval;
}
@@ -280,15 +280,15 @@ ys_resolve_type(yang_stmt *ys,
*/
int
yang2cv_type(char *ytype,
- enum cv_type *cv_type)
+ enum cv_type *cv_type)
{
int ret;
*cv_type = CGV_ERR;
/* built-in types */
if ((ret = clicon_str2int_search(ytmap2, ytype, (sizeof(ytmap)/sizeof(map_str2int))-2)) != -1){
- *cv_type = ret;
- return 0;
+ *cv_type = ret;
+ return 0;
}
return 0;
}
@@ -304,29 +304,29 @@ cv2yang_type(enum cv_type cv_type)
ytype = "empty";
/* built-in types */
if ((str = clicon_int2str(ytmap, cv_type)) != NULL)
- return (char*)str;
+ return (char*)str;
/* special derived types */
if (cv_type == CGV_IPV4ADDR) /* RFC6991 */
- return "ipv4-address";
+ return "ipv4-address";
if (cv_type == CGV_IPV6ADDR) /* RFC6991 */
- return "ipv6-address";
+ return "ipv6-address";
if (cv_type == CGV_IPV4PFX) /* RFC6991 */
- return "ipv4-prefix";
+ return "ipv4-prefix";
if (cv_type == CGV_IPV6PFX) /* RFC6991 */
- return "ipv6-prefix";
+ return "ipv6-prefix";
if (cv_type == CGV_TIME) /* RFC6991 */
- return "date-and-time";
+ return "date-and-time";
if (cv_type == CGV_MACADDR) /* RFC6991 */
- return "mac-address";
+ return "mac-address";
if (cv_type == CGV_UUID) /* RFC6991 */
- return "uuid";
+ return "uuid";
return ytype;
}
@@ -343,9 +343,9 @@ cv2yang_type(enum cv_type cv_type)
*/
int
clicon_type2cv(char *origtype,
- char *restype,
- yang_stmt *ys,
- enum cv_type *cvtype)
+ char *restype,
+ yang_stmt *ys,
+ enum cv_type *cvtype)
{
int retval = -1;
yang_stmt *ym;
@@ -353,24 +353,24 @@ clicon_type2cv(char *origtype,
*cvtype = CGV_ERR;
ym = ys_module(ys);
if (restype == NULL){
- /*
- * Not resolved, but we can use special cligen types, eg ipv4addr
- * Note this is a kludge or at least if we intend of using rfc types
- */
- yang2cv_type(origtype, cvtype);
- if (*cvtype == CGV_ERR){
- clicon_err(OE_YANG, 0, "%s:\"%s\": type not resolved",
- yang_argument_get(ym), origtype);
- goto done;
- }
+ /*
+ * Not resolved, but we can use special cligen types, eg ipv4addr
+ * Note this is a kludge or at least if we intend of using rfc types
+ */
+ yang2cv_type(origtype, cvtype);
+ if (*cvtype == CGV_ERR){
+ clicon_err(OE_YANG, 0, "%s:\"%s\": type not resolved",
+ yang_argument_get(ym), origtype);
+ goto done;
+ }
}
else {
- yang2cv_type(restype, cvtype);
- if (*cvtype == CGV_ERR){
- clicon_err(OE_YANG, 0, "%s: \"%s\" type not translated",
- yang_argument_get(ym), restype);
- goto done;
- }
+ yang2cv_type(restype, cvtype);
+ if (*cvtype == CGV_ERR){
+ clicon_err(OE_YANG, 0, "%s: \"%s\" type not translated",
+ yang_argument_get(ym), restype);
+ goto done;
+ }
}
retval = 0;
@@ -388,10 +388,10 @@ clicon_type2cv(char *origtype,
*/
static int
cv_validate_pattern(clicon_handle h,
- cvec *regexps,
- yang_stmt *yrestype,
- char *str,
- char **reason)
+ cvec *regexps,
+ yang_stmt *yrestype,
+ char *str,
+ char **reason)
{
int retval = -1;
cg_var *cvr;
@@ -400,18 +400,18 @@ cv_validate_pattern(clicon_handle h,
cvr = NULL; /* Loop over compiled regexps */
while ((cvr = cvec_each(regexps, cvr)) != NULL){
- re = cv_void_get(cvr);
- if ((ret = regex_exec(h, re, str?str:"")) < 0)
- goto done;
- if (cv_flag(cvr, V_INVERT))
- ret = !ret; /* swap 0 and 1 */
- if (ret == 0){
- if (reason)
- *reason = cligen_reason("regexp match fail: pattern does not match %s",
- str);
- goto fail;
- break;
- }
+ re = cv_void_get(cvr);
+ if ((ret = regex_exec(h, re, str?str:"")) < 0)
+ goto done;
+ if (cv_flag(cvr, V_INVERT))
+ ret = !ret; /* swap 0 and 1 */
+ if (ret == 0){
+ if (reason)
+ *reason = cligen_reason("regexp match fail: pattern does not match %s",
+ str);
+ goto fail;
+ break;
+ }
}
retval = 1; /* match */
done:
@@ -433,8 +433,8 @@ cv_validate_pattern(clicon_handle h,
*/
static int
outofrange(cg_var *cv0,
- cvec *cvv,
- char **reason)
+ cvec *cvv,
+ char **reason)
{
int retval = -1;
cbuf *cb = NULL;
@@ -443,7 +443,7 @@ outofrange(cg_var *cv0,
int i;
if ((cb = cbuf_new()) == NULL)
- goto done;
+ goto done;
cprintf(cb, "Number ");
cv2cbuf(cv0, cb);
cprintf(cb, " out of range: ");
@@ -451,28 +451,28 @@ outofrange(cg_var *cv0,
cv_validate1 */
i = 0;
while (i2)
- cprintf(cb, ", ");
- cv2cbuf(cv1, cb);
- cprintf(cb, " - ");
- cv2cbuf(cv2, cb);
+ cv1 = cvec_i(cvv, i++); /* Increment to check for max pair */
+ if (strcmp(cv_name_get(cv1),"range_min") != 0){
+ clicon_err(OE_YANG, EINVAL, "Internal error, expected range_min");
+ goto done;
+ }
+ if (i2)
+ cprintf(cb, ", ");
+ cv2cbuf(cv1, cb);
+ cprintf(cb, " - ");
+ cv2cbuf(cv2, cb);
}
if (reason && (*reason = strdup(cbuf_get(cb))) == NULL)
- goto done;
+ goto done;
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
retval = 0;
done:
return retval;
@@ -483,8 +483,8 @@ outofrange(cg_var *cv0,
*/
static int
outoflength(uint64_t u64,
- cvec *cvv,
- char **reason)
+ cvec *cvv,
+ char **reason)
{
int retval = -1;
cbuf *cb = NULL;
@@ -493,35 +493,35 @@ outoflength(uint64_t u64,
int i;
if ((cb = cbuf_new()) == NULL)
- goto done;
+ goto done;
cprintf(cb, "String length %" PRIu64 " out of range: ", u64);
/* Kludge: need to repeat the same loop as in the main function in
cv_validate1 */
i = 0;
while (i2)
- cprintf(cb, ", ");
- cv2cbuf(cv1, cb);
- cprintf(cb, " - ");
- cv2cbuf(cv2, cb);
+ cv1 = cvec_i(cvv, i++); /* Increment to check for max pair */
+ if (strcmp(cv_name_get(cv1),"range_min") != 0){
+ clicon_err(OE_YANG, EINVAL, "Internal error, expected range_min");
+ goto done;
+ }
+ if (i2)
+ cprintf(cb, ", ");
+ cv2cbuf(cv1, cb);
+ cprintf(cb, " - ");
+ cv2cbuf(cv2, cb);
}
if (reason && (*reason = strdup(cbuf_get(cb))) == NULL)
- goto done;
+ goto done;
if (cb)
- cbuf_free(cb);
+ cbuf_free(cb);
retval = 0;
done:
return retval;
@@ -543,14 +543,14 @@ outoflength(uint64_t u64,
*/
static int
cv_validate1(clicon_handle h,
- cg_var *cv,
- enum cv_type cvtype,
- int options,
- cvec *cvv,
- cvec *regexps,
- yang_stmt *yrestype,
- char *restype,
- char **reason)
+ cg_var *cv,
+ enum cv_type cvtype,
+ int options,
+ cvec *cvv,
+ cvec *regexps,
+ yang_stmt *yrestype,
+ char *restype,
+ char **reason)
{
int retval = 1; /* OK */
cg_var *cv1;
@@ -570,175 +570,175 @@ cv_validate1(clicon_handle h,
int rets;
if (reason && *reason){
- free(*reason);
- *reason = NULL;
+ free(*reason);
+ *reason = NULL;
}
/* check options first for length and range */
if ((options & YANG_OPTIONS_RANGE) != 0 ||
- (options & YANG_OPTIONS_LENGTH) != 0){
- i = 0;
- while (i , str is NULL.
- */
- if (restype){
- if (strcmp(restype, "enumeration") == 0){
- found = 0;
- yi = NULL;
- if (str != NULL) {
- // str = clixon_trim2(str, " \t\n"); /* May be misplaced, strip earlier? */
- while ((yi = yn_each(yrestype, yi)) != NULL){
- if (yang_keyword_get(yi) != Y_ENUM)
- continue;
- if (strcmp(yang_argument_get(yi), str) == 0){
- found++;
- break;
- }
- }
- }
- if (!found){
- if (reason)
- *reason = cligen_reason("'%s' does not match enumeration", str);
- goto fail;
- }
- }
- if (strcmp(restype, "bits") == 0 && str != NULL){
- /* The lexical representation of the bits type is a space-separated list
- * of the names of the bits that are set. A zero-length string thus
- * represents a value where no bits are set.
- */
- str = clixon_trim2(str, " \t\n"); /* May be misplaced, strip earlier? */
- nvec = 0;
- if ((vec = clicon_strsep(str, " \t", &nvec)) == NULL)
- goto done;
- for (i=0; i , str is NULL.
+ */
+ if (restype){
+ if (strcmp(restype, "enumeration") == 0){
+ found = 0;
+ yi = NULL;
+ if (str != NULL) {
+ // str = clixon_trim2(str, " \t\n"); /* May be misplaced, strip earlier? */
+ while ((yi = yn_each(yrestype, yi)) != NULL){
+ if (yang_keyword_get(yi) != Y_ENUM)
+ continue;
+ if (strcmp(yang_argument_get(yi), str) == 0){
+ found++;
+ break;
+ }
+ }
+ }
+ if (!found){
+ if (reason)
+ *reason = cligen_reason("'%s' does not match enumeration", str);
+ goto fail;
+ }
+ }
+ if (strcmp(restype, "bits") == 0 && str != NULL){
+ /* The lexical representation of the bits type is a space-separated list
+ * of the names of the bits that are set. A zero-length string thus
+ * represents a value where no bits are set.
+ */
+ str = clixon_trim2(str, " \t\n"); /* May be misplaced, strip earlier? */
+ nvec = 0;
+ if ((vec = clicon_strsep(str, " \t", &nvec)) == NULL)
+ goto done;
+ for (i=0; i cv but yang cant have that */
- if (cvtype == CGV_STRING && cv_type_get(ycv) == CGV_REST)
- ;
- else {
- clicon_err(OE_DB, 0, "Type mismatch data:%s != yang:%s",
- cv_type2str(cvtype), cv_type2str(cv_type_get(ycv)));
- goto done;
- }
+ /* special case: dbkey has rest syntax-> cv but yang cant have that */
+ if (cvtype == CGV_STRING && cv_type_get(ycv) == CGV_REST)
+ ;
+ else {
+ clicon_err(OE_DB, 0, "Type mismatch data:%s != yang:%s",
+ cv_type2str(cvtype), cv_type2str(cv_type_get(ycv)));
+ goto done;
+ }
}
/* Note restype can be NULL here for example with unresolved hardcoded uuid */
if (restype && strcmp(restype, "union") == 0){
- if (cvtype != CGV_REST){
- clicon_err(OE_YANG, 0, "union must be rest cv type but is %d", cvtype);
- goto done;
- }
- /* Instead of NULL, give an empty string to validate, this is to avoid cv_parse
- * errors and may actually be the wrong thing to do.
- */
- if ((val = cv_string_get(cv)) == NULL)
- val = "";
- if ((retval2 = ys_cv_validate_union(h, ys, reason, yrestype, origtype, val, ysub)) < 0)
- goto done;
- retval = retval2; /* invalid (0) with latest reason or valid 1 */
+ if (cvtype != CGV_REST){
+ clicon_err(OE_YANG, 0, "union must be rest cv type but is %d", cvtype);
+ goto done;
+ }
+ /* Instead of NULL, give an empty string to validate, this is to avoid cv_parse
+ * errors and may actually be the wrong thing to do.
+ */
+ if ((val = cv_string_get(cv)) == NULL)
+ val = "";
+ if ((retval2 = ys_cv_validate_union(h, ys, reason, yrestype, origtype, val, ysub)) < 0)
+ goto done;
+ retval = retval2; /* invalid (0) with latest reason or valid 1 */
}
else{
- /* The regexp cache may be invalidated, in that case re-compile
- * eg due to copying
- */
- if (cvec_len(patterns)!=0 && cvec_len(regexps)==0){
- yang_stmt *yt;
- if (compile_pattern2regexp(h, patterns, regexps) < 1)
- goto done;
- yt = yang_find(ys, Y_TYPE, NULL);
- if (yang_type_cache_regexp_set(yt,
- clicon_yang_regexp(h),
- regexps) < 0)
- goto done;
- }
- /* Leafref needs to resolve referred node for type information
- * From rfc7950 Sec 9.9:
- * The leafref built-in type is restricted to the value space of some
- * leaf or leaf-list node in the schema tree and optionally further
- * restricted by corresponding instance nodes in the data tree. The
- * "path" substatement (Section 9.9.2) is used to identify the referred
- * leaf or leaf-list node in the schema tree. The value space of the
- * referring node is the value space of the referred node.
- */
- if (restype && strcmp(restype,"leafref") == 0){
- if (cvtype != CGV_REST){
- clicon_err(OE_YANG, 0, "leafref must be rest cv type but is %d", cvtype);
- goto done;
- }
- /* Instead of NULL, give an empty string to validate, this is to avoid cv_parse
- * errors and may actually be the wrong thing to do.
- */
- if ((val = cv_string_get(cv)) == NULL)
- val = "";
- retval = ys_cv_validate_leafref(h, val, ys, yrestype, ysub, reason);
- goto done;
- }
- if ((retval = cv_validate1(h, cv, cvtype, options, cvv,
- regexps, yrestype, restype, reason)) < 0)
- goto done;
- if (ysub)
- *ysub = ys;
+ /* The regexp cache may be invalidated, in that case re-compile
+ * eg due to copying
+ */
+ if (cvec_len(patterns)!=0 && cvec_len(regexps)==0){
+ yang_stmt *yt;
+ if (compile_pattern2regexp(h, patterns, regexps) < 1)
+ goto done;
+ yt = yang_find(ys, Y_TYPE, NULL);
+ if (yang_type_cache_regexp_set(yt,
+ clicon_yang_regexp(h),
+ regexps) < 0)
+ goto done;
+ }
+ /* Leafref needs to resolve referred node for type information
+ * From rfc7950 Sec 9.9:
+ * The leafref built-in type is restricted to the value space of some
+ * leaf or leaf-list node in the schema tree and optionally further
+ * restricted by corresponding instance nodes in the data tree. The
+ * "path" substatement (Section 9.9.2) is used to identify the referred
+ * leaf or leaf-list node in the schema tree. The value space of the
+ * referring node is the value space of the referred node.
+ */
+ if (restype && strcmp(restype,"leafref") == 0){
+ if (cvtype != CGV_REST){
+ clicon_err(OE_YANG, 0, "leafref must be rest cv type but is %d", cvtype);
+ goto done;
+ }
+ /* Instead of NULL, give an empty string to validate, this is to avoid cv_parse
+ * errors and may actually be the wrong thing to do.
+ */
+ if ((val = cv_string_get(cv)) == NULL)
+ val = "";
+ retval = ys_cv_validate_leafref(h, val, ys, yrestype, ysub, reason);
+ goto done;
+ }
+ if ((retval = cv_validate1(h, cv, cvtype, options, cvv,
+ regexps, yrestype, restype, reason)) < 0)
+ goto done;
+ if (ysub)
+ *ysub = ys;
}
done:
if (origtype)
- free(origtype);
+ free(origtype);
if (regexps)
- cvec_free(regexps);
+ cvec_free(regexps);
if (patterns)
- cvec_free(patterns);
+ cvec_free(patterns);
if (cvt)
- cv_free(cvt);
+ cv_free(cvt);
return retval;
}
@@ -1105,7 +1105,7 @@ static inline int
ys_typedef(yang_stmt *ys)
{
return yang_keyword_get(ys) == Y_MODULE || yang_keyword_get(ys) == Y_SUBMODULE ||
- yang_keyword_get(ys) == Y_CONTAINER || yang_keyword_get(ys) == Y_LIST;
+ yang_keyword_get(ys) == Y_CONTAINER || yang_keyword_get(ys) == Y_LIST;
}
/* find next ys up which can contain a typedef */
@@ -1115,11 +1115,11 @@ ys_typedef_up(yang_stmt *ys)
yang_stmt *yn;
while (ys != NULL && !ys_typedef(ys)){
- yn = yang_parent_get(ys);
- /* Some extra stuff to ensure ys is a stmt */
- if (yn && yang_keyword_get(yn) == Y_SPEC)
- yn = NULL;
- ys = (yang_stmt*)yn;
+ yn = yang_parent_get(ys);
+ /* Some extra stuff to ensure ys is a stmt */
+ if (yn && yang_keyword_get(yn) == Y_SPEC)
+ yn = NULL;
+ ys = (yang_stmt*)yn;
}
/* Here it is either NULL or is a typedef-kind yang-stmt */
return (yang_stmt*)ys;
@@ -1136,7 +1136,7 @@ ys_typedef_up(yang_stmt *ys)
*/
yang_stmt *
yang_find_identity(yang_stmt *ys,
- char *identity)
+ char *identity)
{
char *id = NULL;
char *prefix = NULL;
@@ -1145,35 +1145,35 @@ yang_find_identity(yang_stmt *ys,
yang_stmt *yn;
if (nodeid_split(identity, &prefix, &id) < 0)
- goto done;
+ goto done;
/* No, now check if identityref is derived from base */
if (prefix){ /* Go to top and find import that matches */
- if ((ymodule = yang_find_module_by_prefix(ys, prefix)) == NULL)
- goto done;
- /* if ymodule is a sub-module, the identity may be found in a
- * sub-module of ymod */
- yid = yang_find(ymodule, Y_IDENTITY, id);
+ if ((ymodule = yang_find_module_by_prefix(ys, prefix)) == NULL)
+ goto done;
+ /* if ymodule is a sub-module, the identity may be found in a
+ * sub-module of ymod */
+ yid = yang_find(ymodule, Y_IDENTITY, id);
}
else{
- while (1){
- /* Check upwards in hierarchy for matching typedefs */
- if ((ys = ys_typedef_up(ys)) == NULL) /* If reach top */
- break;
- /* Here find identity */
- if ((yid = yang_find(ys, Y_IDENTITY, id)) != NULL)
- break;
- /* Did not find a matching typedef there, proceed to next level */
- yn = yang_parent_get(ys);
- if (yn && yang_keyword_get(yn) == Y_SPEC)
- yn = NULL;
- ys = (yang_stmt*)yn;
- }
+ while (1){
+ /* Check upwards in hierarchy for matching typedefs */
+ if ((ys = ys_typedef_up(ys)) == NULL) /* If reach top */
+ break;
+ /* Here find identity */
+ if ((yid = yang_find(ys, Y_IDENTITY, id)) != NULL)
+ break;
+ /* Did not find a matching typedef there, proceed to next level */
+ yn = yang_parent_get(ys);
+ if (yn && yang_keyword_get(yn) == Y_SPEC)
+ yn = NULL;
+ ys = (yang_stmt*)yn;
+ }
}
done:
if (id)
- free(id);
+ free(id);
if (prefix)
- free(prefix);
+ free(prefix);
return yid;
}
@@ -1189,8 +1189,8 @@ yang_find_identity(yang_stmt *ys,
*/
yang_stmt *
yang_find_identity_nsc(yang_stmt *yspec,
- char *identity,
- cvec *nsc)
+ char *identity,
+ cvec *nsc)
{
char *id = NULL;
char *prefix = NULL;
@@ -1199,19 +1199,19 @@ yang_find_identity_nsc(yang_stmt *yspec,
char *ns = NULL;
if (nodeid_split(identity, &prefix, &id) < 0)
- goto done;
+ goto done;
if ((ns = xml_nsctx_get(nsc, prefix)) == NULL)
- goto done;
+ goto done;
if ((ymodule = yang_find_module_by_namespace(yspec, ns)) == NULL)
- goto done;
+ goto done;
/* if ymodule is a sub-module, the identity may be found in a
* sub-module of ymod */
yid = yang_find(ymodule, Y_IDENTITY, id);
done:
if (id)
- free(id);
+ free(id);
if (prefix)
- free(prefix);
+ free(prefix);
return yid;
}
@@ -1230,10 +1230,10 @@ yang_find_identity_nsc(yang_stmt *yspec,
*/
static int
yang_type_resolve_restrictions(yang_stmt *ytype,
- int *options,
- cvec **cvv,
- cvec *regexps,
- uint8_t *fraction)
+ int *options,
+ cvec **cvv,
+ cvec *regexps,
+ uint8_t *fraction)
{
int retval = -1;
yang_stmt *ys;
@@ -1241,36 +1241,36 @@ yang_type_resolve_restrictions(yang_stmt *ytype,
char *pattern;
if (options && cvv &&
- (ys = yang_find(ytype, Y_RANGE, NULL)) != NULL){
- *cvv = yang_cvec_get(ys);
- *options |= YANG_OPTIONS_RANGE;
+ (ys = yang_find(ytype, Y_RANGE, NULL)) != NULL){
+ *cvv = yang_cvec_get(ys);
+ *options |= YANG_OPTIONS_RANGE;
}
if (options && cvv &&
- (ys = yang_find(ytype, Y_LENGTH, NULL)) != NULL){
- *cvv = yang_cvec_get(ys);
- *options |= YANG_OPTIONS_LENGTH;
+ (ys = yang_find(ytype, Y_LENGTH, NULL)) != NULL){
+ *cvv = yang_cvec_get(ys);
+ *options |= YANG_OPTIONS_LENGTH;
}
/* Find all patterns */
if (options && regexps){
- ys = NULL;
- while ((ys = yn_each(ytype, ys)) != NULL) {
- if (yang_keyword_get(ys) != Y_PATTERN)
- continue;
- if ((cv = cvec_add(regexps, CGV_STRING)) == NULL){
- clicon_err(OE_UNIX, errno, "cvec_add");
- goto done;
- }
- pattern = yang_argument_get(ys); /* clear text pattern */
- /* Check 1.1 invert pattern */
- if (yang_find(ys, Y_MODIFIER, "invert-match") != NULL)
- cv_flag_set(cv, V_INVERT);
- cv_string_set(cv, pattern);
- }
+ ys = NULL;
+ while ((ys = yn_each(ytype, ys)) != NULL) {
+ if (yang_keyword_get(ys) != Y_PATTERN)
+ continue;
+ if ((cv = cvec_add(regexps, CGV_STRING)) == NULL){
+ clicon_err(OE_UNIX, errno, "cvec_add");
+ goto done;
+ }
+ pattern = yang_argument_get(ys); /* clear text pattern */
+ /* Check 1.1 invert pattern */
+ if (yang_find(ys, Y_MODIFIER, "invert-match") != NULL)
+ cv_flag_set(cv, V_INVERT);
+ cv_string_set(cv, pattern);
+ }
}
if (options && fraction &&
- (ys = yang_find(ytype, Y_FRACTION_DIGITS, NULL)) != NULL){
- *fraction = cv_uint8_get(yang_cv_get(ys));
- *options |= YANG_OPTIONS_FRACTION_DIGITS;
+ (ys = yang_find(ytype, Y_FRACTION_DIGITS, NULL)) != NULL){
+ *fraction = cv_uint8_get(yang_cv_get(ys));
+ *options |= YANG_OPTIONS_FRACTION_DIGITS;
}
retval = 0;
done:
@@ -1302,14 +1302,14 @@ yang_type_resolve_restrictions(yang_stmt *ytype,
*/
int
yang_type_resolve(yang_stmt *yorig,
- yang_stmt *ys,
- yang_stmt *ytype,
- yang_stmt **yrestype,
- int *options,
- cvec **cvv,
- cvec *patterns,
- cvec *regexps,
- uint8_t *fraction)
+ yang_stmt *ys,
+ yang_stmt *ytype,
+ yang_stmt **yrestype,
+ int *options,
+ cvec **cvv,
+ cvec *patterns,
+ cvec *regexps,
+ uint8_t *fraction)
{
yang_stmt *rytypedef = NULL; /* Resolved typedef of ytype */
yang_stmt *rytype; /* Resolved type of ytype */
@@ -1321,94 +1321,94 @@ yang_type_resolve(yang_stmt *yorig,
int ret;
if (options)
- *options = 0x0;
+ *options = 0x0;
*yrestype = NULL; /* Initialization of resolved type that may not be necessary */
if (nodeid_split(yang_argument_get(ytype), &prefix, &type) < 0)
- goto done;
+ goto done;
/* Cache does not work for eg string length 32? */
#if 1
if ((ret = yang_type_cache_get(ytype, yrestype,
- options, cvv, patterns, NULL, regexps, fraction)) < 0)
- goto done;
+ options, cvv, patterns, NULL, regexps, fraction)) < 0)
+ goto done;
if (ret == 1)
- goto ok;
+ goto ok;
#else
if (ytype->ys_typecache != NULL){
- if (yang_type_cache_get(ytype, yrestype,
- options, cvv, patterns, NULL, regexps, fraction) < 0)
- goto done;
- goto ok;
+ if (yang_type_cache_get(ytype, yrestype,
+ options, cvv, patterns, NULL, regexps, fraction) < 0)
+ goto done;
+ goto ok;
}
#endif
/* Check if type is basic type. If so, return that */
if ((prefix == NULL && yang_builtin(type))){
- *yrestype = ytype;
- if (yang_type_resolve_restrictions(ytype, options, cvv, patterns, fraction) < 0)
- goto done;
- goto ok;
+ *yrestype = ytype;
+ if (yang_type_resolve_restrictions(ytype, options, cvv, patterns, fraction) < 0)
+ goto done;
+ goto ok;
}
/* Not basic type. Now check if prefix which means we look in other module */
if (prefix){ /* Go to top and find import that matches */
- if ((yrmod = yang_find_module_by_prefix(ytype, prefix)) == NULL){
- clicon_err(OE_DB, 0, "Type not resolved: \"%s:%s\" in module %s",
- prefix, type, yang_argument_get(ys_module(yorig)));
- goto done;
- }
- if ((rytypedef = yang_find(yrmod, Y_TYPEDEF, type)) == NULL)
- goto ok; /* unresolved */
- ys = rytypedef;
+ if ((yrmod = yang_find_module_by_prefix(ytype, prefix)) == NULL){
+ clicon_err(OE_DB, 0, "Type not resolved: \"%s:%s\" in module %s",
+ prefix, type, yang_argument_get(ys_module(yorig)));
+ goto done;
+ }
+ if ((rytypedef = yang_find(yrmod, Y_TYPEDEF, type)) == NULL)
+ goto ok; /* unresolved */
+ ys = rytypedef;
}
else
- while (1){
- /* Check upwards in hierarchy for matching typedefs */
- if ((ys = ys_typedef_up(ys)) == NULL){ /* If reach top */
- *yrestype = NULL;
- break;
- }
- /* Here find typedef */
- if ((rytypedef = yang_find(ys, Y_TYPEDEF, type)) != NULL)
- break;
- /* Did not find a matching typedef there, proceed to next level */
- yn = yang_parent_get(ys);
- if (yn && (yang_keyword_get(yn) == Y_SPEC))
- yn = NULL;
- ys = (yang_stmt*)yn;
- }
+ while (1){
+ /* Check upwards in hierarchy for matching typedefs */
+ if ((ys = ys_typedef_up(ys)) == NULL){ /* If reach top */
+ *yrestype = NULL;
+ break;
+ }
+ /* Here find typedef */
+ if ((rytypedef = yang_find(ys, Y_TYPEDEF, type)) != NULL)
+ break;
+ /* Did not find a matching typedef there, proceed to next level */
+ yn = yang_parent_get(ys);
+ if (yn && (yang_keyword_get(yn) == Y_SPEC))
+ yn = NULL;
+ ys = (yang_stmt*)yn;
+ }
if (rytypedef != NULL){ /* We have found a typedef */
- /* Find associated type statement */
- if ((rytype = yang_find(rytypedef, Y_TYPE, NULL)) == NULL){
- clicon_err(OE_DB, 0, "mandatory type object is not found");
- goto done;
- }
- /* recursively resolve this new type */
- if (yang_type_resolve(yorig, ys, rytype, yrestype,
- options, cvv,
- patterns, regexps,
- fraction) < 0)
- goto done;
- if (yrestype && *yrestype == NULL){
- clicon_err(OE_YANG, 0, "result-type should not be NULL");
- goto done;
- }
- /* appends patterns, overwrites others if any */
- if (yang_type_resolve_restrictions(ytype, options, cvv, patterns, fraction) < 0)
- goto done;
+ /* Find associated type statement */
+ if ((rytype = yang_find(rytypedef, Y_TYPE, NULL)) == NULL){
+ clicon_err(OE_DB, 0, "mandatory type object is not found");
+ goto done;
+ }
+ /* recursively resolve this new type */
+ if (yang_type_resolve(yorig, ys, rytype, yrestype,
+ options, cvv,
+ patterns, regexps,
+ fraction) < 0)
+ goto done;
+ if (yrestype && *yrestype == NULL){
+ clicon_err(OE_YANG, 0, "result-type should not be NULL");
+ goto done;
+ }
+ /* appends patterns, overwrites others if any */
+ if (yang_type_resolve_restrictions(ytype, options, cvv, patterns, fraction) < 0)
+ goto done;
}
ok:
retval = 0;
done:
#if 1
if (retval == 0 && yrestype != NULL && *yrestype == NULL){
- clicon_err(OE_YANG, 0, "No such type: \"%s\"", type);
- retval = -1;
+ clicon_err(OE_YANG, 0, "No such type: \"%s\"", type);
+ retval = -1;
}
#endif
if (prefix)
- free(prefix);
+ free(prefix);
if (type)
- free(type);
+ free(type);
return retval;
}
@@ -1454,13 +1454,13 @@ yang_type_resolve(yang_stmt *yorig,
*/
int
yang_type_get(yang_stmt *ys,
- char **origtype,
- yang_stmt **yrestype,
- int *options,
- cvec **cvv,
- cvec *patterns,
- cvec *regexps,
- uint8_t *fraction
+ char **origtype,
+ yang_stmt **yrestype,
+ int *options,
+ cvec **cvv,
+ cvec *patterns,
+ cvec *regexps,
+ uint8_t *fraction
)
{
int retval = -1;
@@ -1468,31 +1468,31 @@ yang_type_get(yang_stmt *ys,
char *type = NULL;
if (options)
- *options = 0x0;
+ *options = 0x0;
/* Find mandatory type */
if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL){
- clicon_err(OE_DB, ENOENT, "mandatory type object is not found");
- goto done;
+ clicon_err(OE_DB, ENOENT, "mandatory type object is not found");
+ goto done;
}
/* XXX: here we seem to have some problems if type is union */
if (nodeid_split(yang_argument_get(ytype), NULL, &type) < 0)
- goto done;
+ goto done;
if (origtype &&
- (*origtype = strdup(type)) == NULL){
- clicon_err(OE_XML, errno, "stdup");
- goto done;
+ (*origtype = strdup(type)) == NULL){
+ clicon_err(OE_XML, errno, "stdup");
+ goto done;
}
if (yang_type_resolve(ys, ys, ytype, yrestype,
- options, cvv, patterns, regexps, fraction) < 0)
- goto done;
+ options, cvv, patterns, regexps, fraction) < 0)
+ goto done;
if (yrestype && *yrestype == NULL){
- clicon_err(OE_YANG, 0, "result-type should not be NULL");
- goto done;
+ clicon_err(OE_YANG, 0, "result-type should not be NULL");
+ goto done;
}
retval = 0;
done:
if (type)
- free(type);
+ free(type);
return retval;
}
@@ -1510,12 +1510,12 @@ yang_type2cv(yang_stmt *ys)
/* Find type specification */
if (yang_type_get(ys, &origtype, &yrestype, NULL, NULL, NULL, NULL, NULL)
< 0)
- goto done;
+ goto done;
restype = yrestype?yang_argument_get(yrestype):NULL;
if (clicon_type2cv(origtype, restype, ys, &cvtype) < 0) /* This handles non-resolved also */
- goto done;
+ goto done;
done:
if (origtype)
- free(origtype);
+ free(origtype);
return cvtype;
}
diff --git a/test/all.sh b/test/all.sh
index 4580b734..e3da34b9 100755
--- a/test/all.sh
+++ b/test/all.sh
@@ -34,10 +34,10 @@ for test in $pattern; do
errcode=$?
endsuite
if [ $errcode -ne 0 ]; then
- allerr=1
- echo -e "\e[31mError in $test errcode=$errcode"
- echo -ne "\e[0m"
- exit $errcode
+ allerr=1
+ echo -e "\e[31mError in $test errcode=$errcode"
+ echo -ne "\e[0m"
+ exit $errcode
fi
done
if [ $allerr -eq 0 ]; then
diff --git a/test/example_social.sh b/test/example_social.sh
index 912f96f2..bdbe2e39 100755
--- a/test/example_social.sh
+++ b/test/example_social.sh
@@ -119,7 +119,7 @@ cat < $fexample
leaf-list following {
type leafref {
path "/members/member/member-id";
- require-instance false;
+ require-instance false;
}
description
"Other members this members is following.";
@@ -217,8 +217,8 @@ cat < $fexample
description
"Operational state members values.";
leaf-list numbers {
- description "config false extension";
- type int32;
+ description "config false extension";
+ type int32;
}
leaf joined {
type yang:date-and-time;
diff --git a/test/fuzz/http1/runfuzz.sh b/test/fuzz/http1/runfuzz.sh
index b3817864..9c6bef6d 100755
--- a/test/fuzz/http1/runfuzz.sh
+++ b/test/fuzz/http1/runfuzz.sh
@@ -37,9 +37,9 @@ cat < $cfg
file
default
- 0.0.0.0
- 8088
- false
+ 0.0.0.0
+ 8088
+ false
diff --git a/test/lib.sh b/test/lib.sh
index ac39a21d..983fff55 100755
--- a/test/lib.sh
+++ b/test/lib.sh
@@ -34,7 +34,7 @@
if [ -f ./config.sh ]; then
. ./config.sh
if [ $? -ne 0 ]; then
- return -1 # error
+ return -1 # error
fi
fi
@@ -98,6 +98,9 @@ DEFAULTNS="$DEFAULTONLY message-id=\"42\""
# Minimal hello message as a prelude to netconf rpcs
DEFAULTHELLO="urn:ietf:params:netconf:base:1.0 urn:ietf:params:netconf:base:1.1 ]]>]]>"
+# Minimal hello message that excludes 1.1 capability, in the case EOM style framing is needed
+HELLONO11="urn:ietf:params:netconf:base:1.0 ]]>]]>"
+
# XXX cannot get this to work for all combinations of nc/netcat fcgi/native
# But leave it here for debugging where netcat works properly
if [ -n "$(type netcat 2> /dev/null)" ]; then
@@ -127,11 +130,11 @@ fi
if [ ${HVER} = 2 ]; then
if ${HAVE_HTTP1}; then
- # This is if http/1 is enabled (unset proto=HTTP_2 in restconf_accept_client)
- CURLOPTS="${CURLOPTS} --http2"
+ # This is if http/1 is enabled (unset proto=HTTP_2 in restconf_accept_client)
+ CURLOPTS="${CURLOPTS} --http2"
else
- # This is if http/1 is disabled (set proto=HTTP_2 in restconf_accept_client)
- CURLOPTS="${CURLOPTS} --http2-prior-knowledge"
+ # This is if http/1 is disabled (set proto=HTTP_2 in restconf_accept_client)
+ CURLOPTS="${CURLOPTS} --http2-prior-knowledge"
fi
else
CURLOPTS="${CURLOPTS} --http1.1"
@@ -196,14 +199,14 @@ BUSER=clicon
if [ -f ./site.sh ]; then
. ./site.sh
if [ $? -ne 0 ]; then
- return -1 # skip
+ return -1 # skip
fi
# test skiplist.
for f in $SKIPLIST; do
- if [ "$testfile" = "$f" ]; then
- echo "...skipped (see site.sh)"
- return -1 # skip
- fi
+ if [ "$testfile" = "$f" ]; then
+ echo "...skipped (see site.sh)"
+ return -1 # skip
+ fi
done
fi
@@ -226,10 +229,10 @@ if $SNMPCHECK; then
snmptranslate="$(type -p snmptranslate) "
if [ "${ENABLE_NETSNMP}" == "yes" ]; then
- pgrep snmpd > /dev/null
+ pgrep snmpd > /dev/null
if [ $? != 0 ]; then
- echo -e "\e[31m\nenable-netsnmp set but snmpd not running, start with:"
- echo "systemctl start snmpd"
+ echo -e "\e[31m\nenable-netsnmp set but snmpd not running, start with:"
+ echo "systemctl start snmpd"
echo ""
echo "snmpd must be configured to use a Unix socket for agent communication"
echo "and have a rwcommunity configured, make sure the following lines are"
@@ -241,8 +244,8 @@ if $SNMPCHECK; then
echo ""
echo "If you don't rely on systemd you can configure the lines above"
echo "and start snmpd manually with 'snmpd -Lo -p /var/run/snmpd.pid'."
- echo -e "\e[0m"
- exit -1
+ echo -e "\e[0m"
+ exit -1
fi
fi
@@ -289,23 +292,23 @@ fi
# Sanity nginx running on systemd platforms
if $NGINXCHECK; then
if systemctl > /dev/null 2>&1 ; then
- # even if systemd exists, nginx may be started in other ways
- nginxactive=$(systemctl show nginx |grep ActiveState=active)
- if [ "${WITH_RESTCONF}" = "fcgi" ]; then
- if [ -z "$nginxactive" -a ! -f /var/run/nginx.pid ]; then
- echo -e "\e[31m\nwith-restconf=fcgi set but nginx not running, start with:"
- echo "systemctl start nginx"
- echo -e "\e[0m"
- exit -1
- fi
- else
- if [ -n "$nginxactive" -o -f /var/run/nginx.pid ]; then
- echo -e "\e[31m\nwith-restconf=fcgi not set but nginx running, stop with:"
- echo "systemctl stop nginx"
- echo -e "\e[0m"
- exit -1
- fi
- fi
+ # even if systemd exists, nginx may be started in other ways
+ nginxactive=$(systemctl show nginx |grep ActiveState=active)
+ if [ "${WITH_RESTCONF}" = "fcgi" ]; then
+ if [ -z "$nginxactive" -a ! -f /var/run/nginx.pid ]; then
+ echo -e "\e[31m\nwith-restconf=fcgi set but nginx not running, start with:"
+ echo "systemctl start nginx"
+ echo -e "\e[0m"
+ exit -1
+ fi
+ else
+ if [ -n "$nginxactive" -o -f /var/run/nginx.pid ]; then
+ echo -e "\e[31m\nwith-restconf=fcgi not set but nginx running, stop with:"
+ echo "systemctl stop nginx"
+ echo -e "\e[0m"
+ exit -1
+ fi
+ fi
fi # systemctl
fi
@@ -332,40 +335,40 @@ function restconf_config()
# Change this to fixed parameters
if [ $# -gt 2 ]; then
- myproto=$3
+ myproto=$3
else
- myproto=$RCPROTO
+ myproto=$RCPROTO
fi
if [ $# -gt 3 ]; then
- myhttpdata=$4
+ myhttpdata=$4
else
- myhttpdata=false
+ myhttpdata=false
fi
echo -n "clixon-restconf:fcgi "
if [ $myproto = http ]; then
- echo -n "true "
- if ${myhttpdata}; then
- echo -n "true "
- fi
- echo "$AUTH $PRETTY $DBG default 0.0.0.0 80 false "
+ echo -n "true "
+ if ${myhttpdata}; then
+ echo -n "true "
+ fi
+ echo "$AUTH $PRETTY $DBG default 0.0.0.0 80 false "
else
- certdir=$dir/certs
- if [ ! -f ${dir}/clixon-server-crt.pem ]; then
- certdir=$dir/certs
- test -d $certdir || mkdir $certdir
- srvcert=${certdir}/clixon-server-crt.pem
- srvkey=${certdir}/clixon-server-key.pem
- cacert=${certdir}/clixon-ca-crt.pem
- cakey=${certdir}/clixon-ca-key.pem
- cacerts $cakey $cacert
- servercerts $cakey $cacert $srvkey $srvcert
- fi
- echo -n "true "
- if ${myhttpdata}; then
- echo -n "true "
- fi
- echo "$AUTH $PRETTY ${certdir}/clixon-server-crt.pem ${certdir}/clixon-server-key.pem ${certdir}/clixon-ca-crt.pem $DBG default 0.0.0.0 443 true "
+ certdir=$dir/certs
+ if [ ! -f ${dir}/clixon-server-crt.pem ]; then
+ certdir=$dir/certs
+ test -d $certdir || mkdir $certdir
+ srvcert=${certdir}/clixon-server-crt.pem
+ srvkey=${certdir}/clixon-server-key.pem
+ cacert=${certdir}/clixon-ca-crt.pem
+ cakey=${certdir}/clixon-ca-key.pem
+ cacerts $cakey $cacert
+ servercerts $cakey $cacert $srvkey $srvcert
+ fi
+ echo -n "true "
+ if ${myhttpdata}; then
+ echo -n "true "
+ fi
+ echo "$AUTH $PRETTY ${certdir}/clixon-server-crt.pem ${certdir}/clixon-server-key.pem ${certdir}/clixon-ca-crt.pem $DBG default 0.0.0.0 443 true "
fi
}
@@ -454,19 +457,19 @@ function err1(){
# Test is previous test had valgrind errors if so quit
function checkvalgrind(){
if [ -f $valgrindfile ]; then
- res=$(cat $valgrindfile | grep -e "Invalid" |awk '{print $4}' | grep -v '^0$')
- if [ -n "$res" ]; then
- >&2 cat $valgrindfile
- sudo rm -f $valgrindfile
- exit -1
- fi
- res=$(cat $valgrindfile | grep -e "reachable" -e "lost:"|awk '{print $4}' | grep -v '^0$')
- if [ -n "$res" ]; then
- >&2 cat $valgrindfile
- sudo rm -f $valgrindfile
- exit -1
- fi
- sudo rm -f $valgrindfile
+ res=$(cat $valgrindfile | grep -e "Invalid" |awk '{print $4}' | grep -v '^0$')
+ if [ -n "$res" ]; then
+ >&2 cat $valgrindfile
+ sudo rm -f $valgrindfile
+ exit -1
+ fi
+ res=$(cat $valgrindfile | grep -e "reachable" -e "lost:"|awk '{print $4}' | grep -v '^0$')
+ if [ -n "$res" ]; then
+ >&2 cat $valgrindfile
+ sudo rm -f $valgrindfile
+ exit -1
+ fi
+ sudo rm -f $valgrindfile
fi
}
@@ -477,9 +480,9 @@ function chunked_equal()
echo "1:$1"
echo "2:$2"
if [ "$1" == "$2" ]; then
- return 0
+ return 0
else
- return 255
+ return 255
fi
}
@@ -503,18 +506,18 @@ function start_snmp(){
$clixon_snmp -f $cfg -D $DBG &
if [ $? -ne 0 ]; then
- err
+ err
fi
}
# Stop clixon_snmp and Valgrind if needed
function stop_snmp(){
if [ $valgrindtest -eq 4 ]; then
- pkill -f clixon_snmp
- sleep 1
- checkvalgrind
+ pkill -f clixon_snmp
+ sleep 1
+ checkvalgrind
else
- killall -q clixon_snmp
+ killall -q clixon_snmp
fi
rm -f ${clixon_snmp_pidfile}
}
@@ -523,25 +526,25 @@ function stop_snmp(){
# If valgrindtest == 2, start valgrind
function start_backend(){
if [ $valgrindtest -eq 2 ]; then
- # Start in background since daemon version creates two traces: parent,
- # child. If background then only the single relevant.
- sudo $clixon_backend -F -D $DBG $* &
+ # Start in background since daemon version creates two traces: parent,
+ # child. If background then only the single relevant.
+ sudo $clixon_backend -F -D $DBG $* &
else
- sudo $clixon_backend -D $DBG $*
+ sudo $clixon_backend -D $DBG $*
fi
if [ $? -ne 0 ]; then
- err
+ err
fi
}
function stop_backend(){
sudo clixon_backend -z $*
if [ $? -ne 0 ]; then
- err "kill backend"
+ err "kill backend"
fi
if [ $valgrindtest -eq 2 ]; then
- sleep 1
- checkvalgrind
+ sleep 1
+ checkvalgrind
fi
sudo pkill -f clixon_backend # extra ($BUSER?)
}
@@ -554,26 +557,27 @@ function wait_backend(){
# chunked_equal "$reply" "$freply"
let i=0;
while [[ $reply != *" ]]>]]>" | clixon_netconf -qef $cfg 2> /dev/null)
-# echo "reply:$reply"
- let i++;
-# echo "wait_backend $i"
- if [ $i -ge $DEMLOOP ]; then
- err "backend timeout $DEMWAIT seconds"
- fi
+# echo "sleep $DEMSLEEP"
+ sleep $DEMSLEEP
+ reply=$(echo " ]]>]]>" | clixon_netconf -qef $cfg 2> /dev/null)
+# echo "reply:$reply"
+ let i++;
+# echo "wait_backend $i"
+ if [ $i -ge $DEMLOOP ]; then
+ err "backend timeout $DEMWAIT seconds"
+ fi
done
}
# Start restconf daemon
# @see wait_restconf
function start_restconf(){
+ STTYSETTINGS=`stty -g`
# Start in background
echo "sudo -u $wwwstartuser -s $clixon_restconf $RCLOG -D $DBG $*"
sudo -u $wwwstartuser -s $clixon_restconf $RCLOG -D $DBG $* /dev/null &
if [ $? -ne 0 ]; then
- err1 "expected 0" "$?"
+ err1 "expected 0" "$?"
fi
}
@@ -590,8 +594,8 @@ function stop_restconf_pre(){
function stop_restconf(){
sudo pkill -f clixon_restconf
if [ $valgrindtest -eq 3 ]; then
- sleep 1
- checkvalgrind
+ sleep 1
+ checkvalgrind
fi
}
@@ -603,28 +607,30 @@ function stop_restconf(){
# 1: (optional) override RCPROTO with http or https
function wait_restconf(){
if [ $# = 1 ]; then
- myproto=$1
+ myproto=$1
else
- myproto=${RCPROTO}
+ myproto=${RCPROTO}
fi
# echo "curl $CURLOPTS -X GET $myproto://localhost/restconf"
hdr=$(curl $CURLOPTS -X GET $myproto://localhost/restconf 2> /dev/null)
# echo "hdr:\"$hdr\""
let i=0;
while [[ "$hdr" != *"200"* ]]; do
-# echo "wait_restconf $i"
- if [ $i -ge $DEMLOOP ]; then
- err1 "restconf timeout $DEMWAIT seconds"
- fi
- sleep $DEMSLEEP
-# echo "curl $CURLOPTS -X GET $myproto://localhost/restconf"
- hdr=$(curl $CURLOPTS -X GET $myproto://localhost/restconf 2> /dev/null)
-# echo "hdr:\"$hdr\""
- let i++;
+# echo "wait_restconf $i"
+ if [ $i -ge $DEMLOOP ]; then
+ err1 "restconf timeout $DEMWAIT seconds"
+ fi
+ sleep $DEMSLEEP
+# echo "curl $CURLOPTS -X GET $myproto://localhost/restconf"
+ hdr=$(curl $CURLOPTS -X GET $myproto://localhost/restconf 2> /dev/null)
+# echo "hdr:\"$hdr\""
+ let i++;
done
if [ $valgrindtest -eq 3 ]; then
- sleep 2 # some problems with valgrind
+ sleep 2 # some problems with valgrind
fi
+
+ stty $STTYSETTINGS
}
# Wait for restconf to stop
@@ -636,17 +642,17 @@ function wait_restconf_stopped(){
# echo "hdr:\"$hdr\""
let i=0;
while [[ $hdr = *"200 OK"* ]]; do
-# echo "wait_restconf_stopped $i"
- if [ $i -ge $DEMLOOP ]; then
- err1 "restconf timeout $DEMWAIT seconds"
- fi
- sleep $DEMSLEEP
- hdr=$(curl $CURLOPTS $* $RCPROTO://localhost/restconf 2> /dev/null)
-# echo "hdr:\"$hdr\""
- let i++;
+# echo "wait_restconf_stopped $i"
+ if [ $i -ge $DEMLOOP ]; then
+ err1 "restconf timeout $DEMWAIT seconds"
+ fi
+ sleep $DEMSLEEP
+ hdr=$(curl $CURLOPTS $* $RCPROTO://localhost/restconf 2> /dev/null)
+# echo "hdr:\"$hdr\""
+ let i++;
done
if [ $valgrindtest -eq 3 ]; then
- sleep 2 # some problems with valgrind
+ sleep 2 # some problems with valgrind
fi
}
@@ -655,11 +661,11 @@ function wait_snmp()
{
let i=0;
while [ ! -f ${clixon_snmp_pidfile} ]; do
- if [ $i -ge $DEMLOOP ]; then
- err1 "snmp timeout $DEMWAIT seconds"
- fi
- sleep $DEMSLEEP
- let i++;
+ if [ $i -ge $DEMLOOP ]; then
+ err1 "snmp timeout $DEMWAIT seconds"
+ fi
+ sleep $DEMSLEEP
+ let i++;
done
}
@@ -668,7 +674,7 @@ function wait_snmp()
function endtest()
{
if [ $valgrindtest -eq 1 ]; then
- checkvalgrind
+ checkvalgrind
fi
}
@@ -709,21 +715,21 @@ function expectpart(){
# echo "expect:\"$expect\""
if [ "$retval" -eq "$retval" 2> /dev/null ] ; then # single retval
if [ $r != $retval ]; then
- echo -e "\e[31m\nError ($r != $retval) in Test$testnr [$testname]:"
- echo -e "\e[0m:"
- exit -1
+ echo -e "\e[31m\nError ($r != $retval) in Test$testnr [$testname]:"
+ echo -e "\e[0m:"
+ exit -1
fi
else # List of retvals
found=0
for rv in $retval; do
- if [ $r == $rv ]; then
- found=1
- fi
+ if [ $r == $rv ]; then
+ found=1
+ fi
done
if [ $found -eq 0 ]; then
- echo -e "\e[31m\nError ($r != $retval) in Test$testnr [$testname]:"
- echo -e "\e[0m:"
- exit -1
+ echo -e "\e[31m\nError ($r != $retval) in Test$testnr [$testname]:"
+ echo -e "\e[0m:"
+ exit -1
fi
fi
if [ -z "$ret" -a -z "$expect" ]; then
@@ -736,22 +742,22 @@ function expectpart(){
let i=0;
for exp in "$@"; do
if [ $i -gt 1 ]; then
- if [ "$exp" == "--not--" ]; then
- positive=false;
- else
-# echo "echo \"$ret\" | grep --null -o \"$exp"\"
- match=$(echo "$ret" | grep --null -i -o "$exp") #-i ignore case XXX -EZo: -E cant handle {}
- r=$?
- if $positive; then
- if [ $r != 0 ]; then
- err "$exp" "$ret"
- fi
- else
- if [ $r == 0 ]; then
- err "not $exp" "$ret"
- fi
- fi
- fi
+ if [ "$exp" == "--not--" ]; then
+ positive=false;
+ else
+# echo "echo \"$ret\" | grep --null -o \"$exp"\"
+ match=$(echo "$ret" | grep --null -i -o "$exp") #-i ignore case XXX -EZo: -E cant handle {}
+ r=$?
+ if $positive; then
+ if [ $r != 0 ]; then
+ err "$exp" "$ret"
+ fi
+ else
+ if [ $r == 0 ]; then
+ err "not $exp" "$ret"
+ fi
+ fi
+ fi
fi
let i++;
done
@@ -780,7 +786,7 @@ function expecteof(){
ret=$($cmd 2> $errfile <"
if [ -z "$r" ]; then
- sleep 1
- continue
+ sleep 1
+ continue
fi
# Append $r to $ret
ret="$ret$r"
@@ -1068,38 +1074,38 @@ function expectwait(){
let ok=0
let fail=0
for exp in "$@"; do
- if [ $i -gt 4 ]; then
-# echo "i:$i"
-# echo "exp:$exp"
- if [ "$exp" == "--not--" ]; then
- positive=false;
- else
- match=$(echo "$ret" | grep --null -i -o "$exp")
-# match=$(echo "$ret" | grep -Eo "$exp");
- r=$?
- if $positive; then
- if [ $r != 0 ]; then
-# echo "fail: $exp"
- let fail++
- break
- fi
- else
- if [ $r == 0 ]; then
-# echo "fail: $exp"
- let fail++
- break
- fi
- fi
- fi
- fi
- let i++;
+ if [ $i -gt 4 ]; then
+# echo "i:$i"
+# echo "exp:$exp"
+ if [ "$exp" == "--not--" ]; then
+ positive=false;
+ else
+ match=$(echo "$ret" | grep --null -i -o "$exp")
+# match=$(echo "$ret" | grep -Eo "$exp");
+ r=$?
+ if $positive; then
+ if [ $r != 0 ]; then
+# echo "fail: $exp"
+ let fail++
+ break
+ fi
+ else
+ if [ $r == 0 ]; then
+# echo "fail: $exp"
+ let fail++
+ break
+ fi
+ fi
+ fi
+ fi
+ let i++;
done # for exp
# echo "fail:$fail"
if [ $fail -eq 0 ]; then
-# echo ok
- echo ok > $dir/expectwaitresult
- # break
- exit 0
+# echo ok
+ echo ok > $dir/expectwaitresult
+ # break
+ exit 0
fi
done
# cat $dir/expectwaitresult
@@ -1120,23 +1126,23 @@ function expectmatch(){
# echo "expret:$expret"
# echo "expect:$expect"
if [ $r != $expret ]; then
- echo -e "\e[31m\nError ($r != $retval) in Test$testnr [$testname]:"
- echo -e "\e[0m:"
- exit -1
+ echo -e "\e[31m\nError ($r != $retval) in Test$testnr [$testname]:"
+ echo -e "\e[0m:"
+ exit -1
fi
if [ -z "$ret" -a -z "$expect" ]; then
- echo > /dev/null
+ echo > /dev/null
else
- match=$(echo "$ret" | grep -Eo "$expect")
- if [ -z "$match" ]; then
- err "$expect" "$ret"
- fi
- if [ -n "$expect2" ]; then
- match=`echo "$ret" | grep --null -Eo "$expect2"`
- if [ -z "$match" ]; then
- err $expect "$ret"
- fi
- fi
+ match=$(echo "$ret" | grep -Eo "$expect")
+ if [ -z "$match" ]; then
+ err "$expect" "$ret"
+ fi
+ if [ -n "$expect2" ]; then
+ match=`echo "$ret" | grep --null -Eo "$expect2"`
+ if [ -z "$match" ]; then
+ err $expect "$ret"
+ fi
+ fi
fi
}
@@ -1148,8 +1154,8 @@ function expectmatch(){
function cacerts()
{
if [ $# -ne 2 ]; then
- echo "cacerts function: Expected: cakey cacert"
- exit 1
+ echo "cacerts function: Expected: cakey cacert"
+ exit 1
fi
local cakey=$1
local cacert=$2
@@ -1209,8 +1215,8 @@ EOF
function servercerts()
{
if [ $# -ne 4 ]; then
- echo "servercerts function: Expected: cakey cacert srvkey srvcert"
- exit 1
+ echo "servercerts function: Expected: cakey cacert srvkey srvcert"
+ exit 1
fi
cakey=$1
cacert=$2
diff --git a/test/long.sh b/test/long.sh
index 98a91513..073e1cfc 100755
--- a/test/long.sh
+++ b/test/long.sh
@@ -70,7 +70,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
@@ -131,7 +131,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/mem.sh b/test/mem.sh
index d5a63fd9..a21c5ab8 100755
--- a/test/mem.sh
+++ b/test/mem.sh
@@ -20,69 +20,69 @@ function memonce(){
clixon_restconf=
clixon_snmp=
case "$what" in
- 'cli')
- valgrindtest=1
- : ${DEMWAIT:=5} # valgrind backend needs some time to get up
- clixon_cli="/usr/bin/valgrind --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_cli"
- ;;
- 'netconf')
- valgrindtest=1
- : ${DEMWAIT:=5} # valgrind backend needs some time to get up
- clixon_netconf="/usr/bin/valgrind --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_netconf"
- ;;
- 'backend')
- valgrindtest=2 # This means backend valgrind test
- : ${DEMWAIT:=10} # valgrind backend needs some time to get up
- # trace-children=no for test_restconf_rpc.sh
- clixon_backend="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --log-file=$valgrindfile clixon_backend"
- ;;
- 'restconf')
- valgrindtest=3 # This means restconf valgrind test
- sudo chmod 660 $valgrindfile
- sudo chown www-data $valgrindfile
- : ${DEMWAIT:=15} # valgrind backend needs some time to get up
- clixon_restconf="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_restconf"
-
- ;;
- 'snmp')
- valgrindtest=4 # This means snmp valgrind test
+ 'cli')
+ valgrindtest=1
+ : ${DEMWAIT:=5} # valgrind backend needs some time to get up
+ clixon_cli="/usr/bin/valgrind --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_cli"
+ ;;
+ 'netconf')
+ valgrindtest=1
+ : ${DEMWAIT:=5} # valgrind backend needs some time to get up
+ clixon_netconf="/usr/bin/valgrind --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_netconf"
+ ;;
+ 'backend')
+ valgrindtest=2 # This means backend valgrind test
+ : ${DEMWAIT:=10} # valgrind backend needs some time to get up
+ # trace-children=no for test_restconf_rpc.sh
+ clixon_backend="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --log-file=$valgrindfile clixon_backend"
+ ;;
+ 'restconf')
+ valgrindtest=3 # This means restconf valgrind test
sudo chmod 660 $valgrindfile
- : ${DEMWAIT:=15} # valgrind snmp needs some time to get up
- clixon_snmp="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_snmp"
- ;;
+ sudo chown www-data $valgrindfile
+ : ${DEMWAIT:=15} # valgrind backend needs some time to get up
+ clixon_restconf="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_restconf"
- *)
- echo "usage: $0 cli|netconf|restconf|backend|snmp" # valgrind memleak checks
- rm -f $valgrindfile
- exit -1
- ;;
+ ;;
+ 'snmp')
+ valgrindtest=4 # This means snmp valgrind test
+ sudo chmod 660 $valgrindfile
+ : ${DEMWAIT:=15} # valgrind snmp needs some time to get up
+ clixon_snmp="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_snmp"
+ ;;
+
+ *)
+ echo "usage: $0 cli|netconf|restconf|backend|snmp" # valgrind memleak checks
+ rm -f $valgrindfile
+ exit -1
+ ;;
esac
memerr=0
for test in $pattern; do
- # Can happen if no pattern, eg pattern=foo but "foo" does not exist
- if [ ! -f $test ]; then
- echo -e "\e[31mNo such file: $test"
- echo -ne "\e[0m"
- exit -1
- fi
- if [ $testnr != 0 ]; then echo; fi
- perfnr=1000 # Limit performance tests
- testfile=$test
- . ./$test
- errcode=$?
- endsuite
- if [ $errcode -ne 0 ]; then
- memerr=1
- echo -e "\e[31mError in $test errcode=$errcode"
- echo -ne "\e[0m"
- exit $errcode
- fi
+ # Can happen if no pattern, eg pattern=foo but "foo" does not exist
+ if [ ! -f $test ]; then
+ echo -e "\e[31mNo such file: $test"
+ echo -ne "\e[0m"
+ exit -1
+ fi
+ if [ $testnr != 0 ]; then echo; fi
+ perfnr=1000 # Limit performance tests
+ testfile=$test
+ . ./$test
+ errcode=$?
+ endsuite
+ if [ $errcode -ne 0 ]; then
+ memerr=1
+ echo -e "\e[31mError in $test errcode=$errcode"
+ echo -ne "\e[0m"
+ exit $errcode
+ fi
done
if [ $valgrindtest -eq 1 ]; then
- checkvalgrind
- sudo rm -f $valgrindfile
+ checkvalgrind
+ sudo rm -f $valgrindfile
fi
}
@@ -93,8 +93,8 @@ function println(){
length=$(echo "$str" | wc -c)
let i=1
while [ $i -lt $length ]; do
- echo -n "="
- let i++
+ echo -n "="
+ let i++
done
echo
}
@@ -108,10 +108,10 @@ fi
# First run sanity
for c in $cmds; do
if [ $c != cli -a $c != netconf -a $c != restconf -a $c != backend -a $c != snmp ]; then
- echo "c:$c"
- echo "usage: $0 [cli|netconf|restconf|backend|snmp]+"
- echo " with no args run all"
- exit -1
+ echo "c:$c"
+ echo "usage: $0 [cli|netconf|restconf|backend|snmp]+"
+ echo " with no args run all"
+ exit -1
fi
done
diff --git a/test/plot_perf.sh b/test/plot_perf.sh
index fcd7f901..18869404 100755
--- a/test/plot_perf.sh
+++ b/test/plot_perf.sh
@@ -90,20 +90,20 @@ EOF
# argument:
function genfile(){
if [ $2 = netconf ]; then
- echo -n "replace " > $fxml
- for (( i=0; i<$1; i++ )); do
- echo -n "$i $i " >> $fxml
- done
- echo " ]]>]]>" >> $fxml
+ echo -n "replace " > $fxml
+ for (( i=0; i<$1; i++ )); do
+ echo -n "$i $i " >> $fxml
+ done
+ echo " ]]>]]>" >> $fxml
else # restconf
- echo -n '{"scaling:x":{"y":[' > $fjson
- for (( i=0; i<$1; i++ )); do
- if [ $i -ne 0 ]; then
- echo -n ',' >> $fjson
- fi
- echo -n "{\"a\":$i,\"b\":\"$i\"}" >> $fjson
- done
- echo ']}}' >> $fjson
+ echo -n '{"scaling:x":{"y":[' > $fjson
+ for (( i=0; i<$1; i++ )); do
+ if [ $i -ne 0 ]; then
+ echo -n ',' >> $fjson
+ fi
+ echo -n "{\"a\":$i,\"b\":\"$i\"}" >> $fjson
+ done
+ echo ']}}' >> $fjson
fi
}
@@ -121,40 +121,40 @@ function runnet(){
file=$resdir/$op-netconf-$reqs-$arch
echo -n "$nr " >> $file
case $op in
- put)
- if [ $reqs = 0 ]; then # Write all in one go
- genfile $nr netconf;
- { time -p cat $fxml | $clixon_netconf -qf $cfg -y $fyang ; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
- else # reqs != 0
- { time -p for (( i=0; i<$reqs; i++ )); do
- rnd=$(( ( RANDOM % $nr ) ));
- echo "$rnd $rnd ]]>]]>";
+ put)
+ if [ $reqs = 0 ]; then # Write all in one go
+ genfile $nr netconf;
+ { time -p cat $fxml | $clixon_netconf -qf $cfg -y $fyang ; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
+ else # reqs != 0
+ { time -p for (( i=0; i<$reqs; i++ )); do
+ rnd=$(( ( RANDOM % $nr ) ));
+ echo "$rnd $rnd ]]>]]>";
done | $clixon_netconf -qf $cfg -y $fyang > /dev/null; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
- fi
- ;;
- get)
- if [ $reqs = 0 ]; then # Read all in one go
- { time -p echo " ]]>]]>" | $clixon_netconf -qf $cfg -y $fyang > /dev/null ; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
- else # reqs != 0
- { time -p for (( i=0; i<$reqs; i++ )); do
- rnd=$(( ( RANDOM % $nr ) ))
- echo "$rnd $rnd ]]>]]>"
- done | $clixon_netconf -qf $cfg -y $fyang > /dev/null; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
- fi
- ;;
- delete)
- { time -p for (( i=0; i<$reqs; i++ )); do
- rnd=$(( ( RANDOM % $nr ) ))
- echo "$rnd $rnd ]]>]]>"
+ fi
+ ;;
+ get)
+ if [ $reqs = 0 ]; then # Read all in one go
+ { time -p echo " ]]>]]>" | $clixon_netconf -qf $cfg -y $fyang > /dev/null ; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
+ else # reqs != 0
+ { time -p for (( i=0; i<$reqs; i++ )); do
+ rnd=$(( ( RANDOM % $nr ) ))
+ echo "$rnd $rnd ]]>]]>"
+ done | $clixon_netconf -qf $cfg -y $fyang > /dev/null; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
+ fi
+ ;;
+ delete)
+ { time -p for (( i=0; i<$reqs; i++ )); do
+ rnd=$(( ( RANDOM % $nr ) ))
+ echo "$rnd $rnd ]]>]]>"
done | $clixon_netconf -qf $cfg -y $fyang; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
- ;;
- commit)
- { time -p echo " ]]>]]>" | $clixon_netconf -qf $cfg -y $fyang > /dev/null ; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
- ;;
- *)
- err "Operation not supported" "$op"
- exit
- ;;
+ ;;
+ commit)
+ { time -p echo " ]]>]]>" | $clixon_netconf -qf $cfg -y $fyang > /dev/null ; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
+ ;;
+ *)
+ err "Operation not supported" "$op"
+ exit
+ ;;
esac
}
@@ -172,39 +172,39 @@ function runrest(){
file=$resdir/$op-restconf-$reqs-$arch
echo -n "$nr " >> $file
case $op in
- put)
- if [ $reqs = 0 ]; then # Write all in one go
- genfile $nr restconf
- # restconf @- means from stdin
- { time -p curl $CURLOPTS -X PUT -d @$fjson http://localhost/restconf/data/scaling:x ; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
- else # Small requests
- { time -p for (( i=0; i<$reqs; i++ )); do
- rnd=$(( ( RANDOM % $nr ) ));
- curl $CURLOPTS -X PUT http://localhost/restconf/data/scaling:x/y=$rnd -d "{\"scaling:y\":{\"a\":$rnd,\"b\":\"$rnd\"}}"
+ put)
+ if [ $reqs = 0 ]; then # Write all in one go
+ genfile $nr restconf
+ # restconf @- means from stdin
+ { time -p curl $CURLOPTS -X PUT -d @$fjson http://localhost/restconf/data/scaling:x ; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
+ else # Small requests
+ { time -p for (( i=0; i<$reqs; i++ )); do
+ rnd=$(( ( RANDOM % $nr ) ));
+ curl $CURLOPTS -X PUT http://localhost/restconf/data/scaling:x/y=$rnd -d "{\"scaling:y\":{\"a\":$rnd,\"b\":\"$rnd\"}}"
done ; } 2>&1 | awk '/real/ {print $2}' | tr , .>> $file
- #
- fi
- ;;
- get)
- if [ $reqs = 0 ]; then # Read all in one go
- { time -p curl $CURLOPTS -X GET http://localhost/restconf/data/scaling:x > /dev/null; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
- else # Small requests
- { time -p for (( i=0; i<$reqs; i++ )); do
- rnd=$(( ( RANDOM % $nr ) ));
- curl $CURLOPTS -X GET http://localhost/restconf/data/scaling:x/y=$rnd
+ #
+ fi
+ ;;
+ get)
+ if [ $reqs = 0 ]; then # Read all in one go
+ { time -p curl $CURLOPTS -X GET http://localhost/restconf/data/scaling:x > /dev/null; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $file
+ else # Small requests
+ { time -p for (( i=0; i<$reqs; i++ )); do
+ rnd=$(( ( RANDOM % $nr ) ));
+ curl $CURLOPTS -X GET http://localhost/restconf/data/scaling:x/y=$rnd
done ; } 2>&1 | awk '/real/ {print $2}' | tr , .>> $file
- fi
- ;;
- delete)
- { time -p for (( i=0; i<$reqs; i++ )); do
- rnd=$(( ( RANDOM % $nr ) ));
- curl $CURLOPTS -X GET http://localhost/restconf/data/scaling:x/y=$rnd
+ fi
+ ;;
+ delete)
+ { time -p for (( i=0; i<$reqs; i++ )); do
+ rnd=$(( ( RANDOM % $nr ) ));
+ curl $CURLOPTS -X GET http://localhost/restconf/data/scaling:x/y=$rnd
done ; } 2>&1 | awk '/real/ {print $2}' | tr , .>> $file
- ;;
- *)
- err "Operation not supported" "$op"
- exit
- ;;
+ ;;
+ *)
+ err "Operation not supported" "$op"
+ exit
+ ;;
esac
}
@@ -246,26 +246,26 @@ function plot(){
run=$8
if [ $# -ne 8 ]; then
- exit "plot should be called with 8 arguments, got $#"
+ exit "plot should be called with 8 arguments, got $#"
fi
# reset file
new "Create file $resdir/$op-$proto-$reqs-$arch"
echo -n "" > $resdir/$op-$proto-$reqs-$arch
for (( n=$from; n<=$to; n=$n+$step )); do
- reset
- if [ $can = n ]; then
- load $n
- if [ $run = n ]; then
- commit
- fi
- fi
- new "$op-$proto-$reqs-$arch $n"
- if [ $proto = netconf ]; then
- runnet $op $n $reqs
- else
- runrest $op $n $reqs
- fi
+ reset
+ if [ $can = n ]; then
+ load $n
+ if [ $run = n ]; then
+ commit
+ fi
+ fi
+ new "$op-$proto-$reqs-$arch $n"
+ if [ $proto = netconf ]; then
+ runnet $op $n $reqs
+ else
+ runrest $op $n $reqs
+ fi
done
echo # newline
}
@@ -281,7 +281,7 @@ function startup(){
mode=startup
if [ $# -ne 3 ]; then
- exit "plot should be called with 3 arguments, got $#"
+ exit "plot should be called with 3 arguments, got $#"
fi
# gnuplot file
@@ -294,17 +294,17 @@ function startup(){
sudo touch $dbfile
sudo chmod 666 $dbfile
for (( n=$from; n<=$to; n=$n+$step )); do
- new "startup-$arch $n"
- new "Generate $n entries to $dbfile"
- echo -n "" > $dbfile
- for (( i=0; i<$n; i++ )); do
- echo -n "$i $i " >> $dbfile
- done
- echo " " >> $dbfile
+ new "startup-$arch $n"
+ new "Generate $n entries to $dbfile"
+ echo -n "" > $dbfile
+ for (( i=0; i<$n; i++ )); do
+ echo -n "$i $i " >> $dbfile
+ done
+ echo " " >> $dbfile
- new "Startup backend once -s $mode -f $cfg -y $fyang"
- echo -n "$n " >> $gfile
- { time -p sudo $clixon_backend -F1 -D $DBG -s $mode -f $cfg -y $fyang 2> /dev/null; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $gfile
+ new "Startup backend once -s $mode -f $cfg -y $fyang"
+ echo -n "$n " >> $gfile
+ { time -p sudo $clixon_backend -F1 -D $DBG -s $mode -f $cfg -y $fyang 2> /dev/null; } 2>&1 | awk '/real/ {print $2}' | tr , . >> $gfile
done
echo # newline
@@ -318,13 +318,13 @@ if $run; then
new "test params: -f $cfg -y $fyang"
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -zf $cfg -y $fyang
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s init -f $cfg -y $fyang"
- start_backend -s init -f $cfg -y $fyang
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg -y $fyang
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s init -f $cfg -y $fyang"
+ start_backend -s init -f $cfg -y $fyang
fi
new "kill old restconf daemon"
@@ -343,14 +343,14 @@ if $run; then
# Put all tests
for proto in netconf restconf; do
- new "$proto put all entries to candidate (restconf:running)"
- plot put $proto $step $step $to 0 0 0 # all candidate 0 running 0
+ new "$proto put all entries to candidate (restconf:running)"
+ plot put $proto $step $step $to 0 0 0 # all candidate 0 running 0
done
# Get all tests
for proto in netconf restconf; do
- new "$proto get all entries from running"
- plot get $proto $step $step $to 0 n n # start w full datastore
+ new "$proto get all entries from running"
+ plot get $proto $step $step $to 0 n n # start w full datastore
done
# Netconf commit all
@@ -360,28 +360,28 @@ if $run; then
# Transactions get/put/delete
reqs=$reqs0
for proto in netconf restconf; do
- new "$proto get $reqs from full database"
- plot get $proto $step $step $to $reqs n n
+ new "$proto get $reqs from full database"
+ plot get $proto $step $step $to $reqs n n
- new "$proto put $reqs to full database(replace / alter values)"
- plot put $proto $step $step $to $reqs n n
+ new "$proto put $reqs to full database(replace / alter values)"
+ plot put $proto $step $step $to $reqs n n
- new "$proto delete $reqs from full database(replace / alter values)"
- plot delete $proto $step $step $to $reqs n n
+ new "$proto delete $reqs from full database(replace / alter values)"
+ plot delete $proto $step $step $to $reqs n n
done
new "Kill restconf daemon"
stop_restconf
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=`pgrep -u root -f clixon_backend`
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=`pgrep -u root -f clixon_backend`
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
fi # if run
diff --git a/test/sum.sh b/test/sum.sh
index 4d84c11e..bf273ff0 100755
--- a/test/sum.sh
+++ b/test/sum.sh
@@ -15,7 +15,7 @@
dir=/var/tmp/$0
if $detail; then
if [ ! -d $dir ]; then
- mkdir $dir
+ mkdir $dir
fi
fi
@@ -40,18 +40,18 @@ let sumerr=0 # error counter
for testfile in $pattern; do # For lib.sh the variable must be called testfile
echo "Running $testfile"
if $detail; then
- ./$testfile > $dir/err.log 2>&1
+ ./$testfile > $dir/err.log 2>&1
else
- ./$testfile > /dev/null 2>&1
+ ./$testfile > /dev/null 2>&1
fi
errcode=$?
if [ $errcode -ne 0 ]; then
let sumerr++
- echo -e "\e[31mError in $testfile errcode=$errcode"
- echo -ne "\e[0m"
- if $detail; then
- detail=false; # Just once for now, print at end
- fi
+ echo -e "\e[31mError in $testfile errcode=$errcode"
+ echo -ne "\e[0m"
+ if $detail; then
+ detail=false; # Just once for now, print at end
+ fi
fi
done
if [ $sumerr -eq 0 ]; then
@@ -59,10 +59,10 @@ if [ $sumerr -eq 0 ]; then
else
echo -e "\e[31m"
if [ -f $dir/err.log ]; then
- echo "Detailed output of first error:"
- echo -ne "\e[0m"
- cat $dir/err.log
- echo
+ echo "Detailed output of first error:"
+ echo -ne "\e[0m"
+ cat $dir/err.log
+ echo
fi
echo -e "\e[31m${sumerr} Errors"
echo -ne "\e[0m"
diff --git a/test/test_api.sh b/test/test_api.sh
index 69a03b26..917eef34 100755
--- a/test/test_api.sh
+++ b/test/test_api.sh
@@ -81,7 +81,7 @@ module example-api{
}
}
rpc trigger {
- description "trigger an action in the backend";
+ description "trigger an action in the backend";
}
}
EOF
@@ -107,10 +107,10 @@ cat< $cfile
static int
trigger_rpc(clicon_handle h, /* Clicon handle */
- cxobj *xe, /* Request: */
- cbuf *cbret, /* Reply eg ... */
- void *arg, /* client_entry */
- void *regarg) /* Argument given at register */
+ cxobj *xe, /* Request: */
+ cbuf *cbret, /* Reply eg ... */
+ void *arg, /* client_entry */
+ void *regarg) /* Argument given at register */
{
int retval = -1;
cxobj *xret = NULL;
@@ -152,11 +152,11 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
val = NULL;
/* Add key/value vector */
if ((cvk = cvec_new(0)) == NULL){
- clicon_err(OE_YANG, errno, "cvec_new");
- goto done;
+ clicon_err(OE_YANG, errno, "cvec_new");
+ goto done;
}
if ((cv = cvec_add(cvk, CGV_STRING)) == NULL)
- goto done;
+ goto done;
cv_name_set(cv, "k");
cv_string_set(cv, "5");
if ((xv = clixon_xvec_new()) == NULL)
@@ -175,7 +175,7 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
if (cvk)
- cvec_free(cvk);
+ cvec_free(cvk);
if (xret)
xml_free(xret);
if (xv)
@@ -202,11 +202,11 @@ clixon_plugin_init(clicon_handle h)
/* From example.yang (clicon) */
if (rpc_callback_register(h, trigger_rpc,
- NULL,
- "urn:example:api",
- "trigger"/* Xml tag when callback is made */
- ) < 0)
- return NULL;
+ NULL,
+ "urn:example:api",
+ "trigger"/* Xml tag when callback is made */
+ ) < 0)
+ return NULL;
return &api;
}
@@ -222,13 +222,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend"
start_backend -s init -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -264,7 +264,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_api_path.sh b/test/test_api_path.sh
index c9b9c1e3..996eb3a5 100755
--- a/test/test_api_path.sh
+++ b/test/test_api_path.sh
@@ -243,7 +243,7 @@ echo -n '' > $xml6
for (( i=0; i<$nr; i++ )); do
echo -n "b$i b$i foo$i " >> $xml6
for (( j=0; j<3; j++ )); do
- echo -n "a$j a$j foo$j " >> $xml6
+ echo -n "a$j a$j foo$j " >> $xml6
done
echo -n " " >> $xml6
done
diff --git a/test/test_augment.sh b/test/test_augment.sh
index 93b4cd01..13b5f798 100755
--- a/test/test_augment.sh
+++ b/test/test_augment.sh
@@ -138,7 +138,7 @@ module example-augment {
when 'derived-from-or-self(if:type, "mymod:some-new-iftype")';
container ospf { /* moved from test_restconf_err (two-level augment) */
leaf reference-bandwidth {
- type uint32;
+ type uint32;
}
}
leaf mandatory-leaf {
@@ -161,7 +161,7 @@ module example-augment {
default 80;
}
refine ip {
- description "double refine triggered mem error";
+ description "double refine triggered mem error";
}
}
uses localgroup {
@@ -174,7 +174,7 @@ module example-augment {
/* augment choice */
augment "/if:target" {
case datastore {
- leaf two{
+ leaf two{
type uint32;
}
}
@@ -188,13 +188,13 @@ module example-augment {
/* augment a list */
augment "/if:interfaces" {
list ports{
- key id;
- leaf id {
+ key id;
+ leaf id {
type int32;
- }
- leaf str {
+ }
+ leaf str {
type string;
- }
+ }
}
}
}
@@ -207,7 +207,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -337,7 +337,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_augment_default.sh b/test/test_augment_default.sh
index b1b33bb7..ea6edb77 100755
--- a/test/test_augment_default.sh
+++ b/test/test_augment_default.sh
@@ -53,9 +53,9 @@ module augment {
leaf name{
type string;
}
- leaf enable {
- type boolean;
- default true;
+ leaf enable {
+ type boolean;
+ default true;
}
}
}
@@ -79,7 +79,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg"
start_backend -s startup -f $cfg
@@ -108,7 +108,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_augment_state.sh b/test/test_augment_state.sh
index 582b71a6..db982650 100755
--- a/test/test_augment_state.sh
+++ b/test/test_augment_state.sh
@@ -44,11 +44,11 @@ module example-lib {
description "Global base default state";
type string;
default "gbds";
- }
+ }
leaf gbos{
description "Global base optional state";
type string;
- }
+ }
container nopres{
description "This should be removed";
}
@@ -57,18 +57,18 @@ module example-lib {
list parameter{
key name;
leaf name{
- type string;
+ type string;
}
container param-state {
config false;
leaf lbds{
- description "Local base default state";
- type string;
- default "lbds";
+ description "Local base default state";
+ type string;
+ default "lbds";
}
leaf lbos{
- description "Local base optional state";
- type string;
+ description "Local base optional state";
+ type string;
}
}
}
@@ -92,11 +92,11 @@ module example-augment {
description "Global augmented default state";
type string;
default "gads";
- }
+ }
leaf gaos{
description "Global augmented optional state";
type string;
- }
+ }
}
/* Augments state in config in-line */
augment "/lib:base-config/lib:parameter/lib:param-state" {
@@ -104,11 +104,11 @@ module example-augment {
description "Local augmented default state";
type string;
default "lads";
- }
+ }
leaf laos{
description "Local augmented optional state";
type string;
- }
+ }
}
}
EOF
@@ -124,9 +124,9 @@ function testrun()
new "get config"
if [ -z "$config" ]; then
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "^ $"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "^ $"
else
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "^$config $"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "^$config $"
fi
new "get state"
@@ -139,12 +139,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -sS $fstate"
start_backend -s init -f $cfg -- -sS $fstate
fi
-new "waiting"
+
+new "wait backend"
wait_backend
#-----------------------------
@@ -252,7 +253,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_augment_trans.sh b/test/test_augment_trans.sh
index a0aa53d2..3ec18e61 100755
--- a/test/test_augment_trans.sh
+++ b/test/test_augment_trans.sh
@@ -48,7 +48,7 @@ module example-lib {
list parameter{
key name;
leaf name{
- type string;
+ type string;
}
}
}
@@ -69,7 +69,7 @@ module example-augment1 {
augment "/lib:base-config/lib:parameter" {
container aug1{
description "Local augmented optional";
- }
+ }
}
}
EOF
@@ -93,7 +93,7 @@ module example-augment2 {
leaf aug2{
description "Local augmented optional";
type string;
- }
+ }
}
}
EOF
@@ -104,12 +104,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
-new "waiting"
+
+new "wait backend"
wait_backend
new "get-config empty"
@@ -129,7 +130,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_autocli_editmode.sh b/test/test_autocli_editmode.sh
index 0d88373f..25027887 100755
--- a/test/test_autocli_editmode.sh
+++ b/test/test_autocli_editmode.sh
@@ -45,20 +45,20 @@ module clixon-example {
prefix ex;
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
- leaf stat{
- description "Inline state data for example application";
- config false;
- type int32;
- }
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
+ leaf stat{
+ description "Inline state data for example application";
+ config false;
+ type int32;
+ }
+ }
}
}
EOF
@@ -81,11 +81,11 @@ commit("Commit the changes"), cli_commit();
quit("Quit"), cli_quit();
show("Show a particular state of the system"){
configuration("Show configuration"), cli_show_auto_mode("candidate", "text", true, false);{
- xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", false, false);
- cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", false, false, "report-all", "set ");
- netconf("Show configuration as netconf edit-config operation"), cli_show_auto_mode("candidate", "netconf", false, false);
- text("Show configuration as text"), cli_show_auto_mode("candidate", "text", false, false);
- json("Show configuration as JSON"), cli_show_auto_mode("candidate", "json", false, false);
+ xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", false, false);
+ cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", false, false, "report-all", "set ");
+ netconf("Show configuration as netconf edit-config operation"), cli_show_auto_mode("candidate", "netconf", false, false);
+ text("Show configuration as text"), cli_show_auto_mode("candidate", "text", false, false);
+ json("Show configuration as JSON"), cli_show_auto_mode("candidate", "json", false, false);
}
state("Show configuration and state"), cli_show_auto_mode("running", "xml", false, true);
}
@@ -117,7 +117,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg -- -sS $fstate"
start_backend -s startup -f $cfg -- -sS $fstate
@@ -325,7 +325,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_autocli_extension.sh b/test/test_autocli_extension.sh
index 86b2e511..c92b9ded 100755
--- a/test/test_autocli_extension.sh
+++ b/test/test_autocli_extension.sh
@@ -87,10 +87,10 @@ module example {
}
list index{
key i;
- leaf i{
- type string;
- }
- leaf iv{
+ leaf i{
+ type string;
+ }
+ leaf iv{
type string;
}
}
@@ -170,7 +170,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -208,10 +208,10 @@ module example {
}
list index{
key i;
- leaf i{
- type string;
- }
- leaf iv{
+ leaf i{
+ type string;
+ }
+ leaf iv{
type string;
}
}
@@ -241,10 +241,10 @@ module example {
}
list index{
key i;
- leaf i{
- type string;
- }
- leaf iv{
+ leaf i{
+ type string;
+ }
+ leaf iv{
type string;
}
}
@@ -336,10 +336,10 @@ module example-augment {
}
list index{
key i;
- leaf i{
- type string;
- }
- leaf iv{
+ leaf i{
+ type string;
+ }
+ leaf iv{
type string;
}
}
@@ -355,7 +355,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_autocli_listkey_compress.sh b/test/test_autocli_listkey_compress.sh
index 65f2c816..892882e8 100755
--- a/test/test_autocli_listkey_compress.sh
+++ b/test/test_autocli_listkey_compress.sh
@@ -66,26 +66,26 @@ module $APPNAME {
type string;
}
container config {
- leaf enabled {
- type boolean;
- default false;
- description "Whether the interface is enabled or not.";
- }
+ leaf enabled {
+ type boolean;
+ default false;
+ description "Whether the interface is enabled or not.";
+ }
}
container state {
- config false;
- leaf oper-status {
- type enumeration {
- enum UP {
- value 1;
- description "Ready to pass packets.";
- }
- enum DOWN {
- value 2;
- description "The interface does not pass any packets.";
- }
- }
- }
+ config false;
+ leaf oper-status {
+ type enumeration {
+ enum UP {
+ value 1;
+ description "Ready to pass packets.";
+ }
+ enum DOWN {
+ value 2;
+ description "The interface does not pass any packets.";
+ }
+ }
+ }
}
}
}
@@ -105,26 +105,26 @@ module ${APPNAME}2 {
type string;
}
container config {
- leaf enabled {
- type boolean;
- default false;
- description "Whether the interface is enabled or not.";
- }
+ leaf enabled {
+ type boolean;
+ default false;
+ description "Whether the interface is enabled or not.";
+ }
}
container state {
- config false;
- leaf oper-status {
- type enumeration {
- enum UP {
- value 1;
- description "Ready to pass packets.";
- }
- enum DOWN {
- value 2;
- description "The interface does not pass any packets.";
- }
- }
- }
+ config false;
+ leaf oper-status {
+ type enumeration {
+ enum UP {
+ value 1;
+ description "Ready to pass packets.";
+ }
+ enum DOWN {
+ value 2;
+ description "The interface does not pass any packets.";
+ }
+ }
+ }
}
}
}
@@ -176,29 +176,29 @@ COMPRESS=$(cat <
compress
compress
- container
- list
+ container
+ list
EOF
)
else
- COMPRESS=""
+ COMPRESS=""
fi
if $openconfig; then
OCOMPRESS=$(cat <
openconfig compress
- compress
- container
- config
-
-
- oc-ext:openconfig-version
+ compress
+ container
+ config
+
+
+ oc-ext:openconfig-version
"
EOF
)
else
- OCOMPRESS=""
+ OCOMPRESS=""
fi
cat < $cfg
@@ -239,7 +239,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -sS $fstate"
start_backend -s init -f $cfg -- -sS $fstate
@@ -258,14 +258,14 @@ function testrun()
compress=$2
if [ $listkw = kw-all ]; then
- name=" name"
+ name=" name"
else
- name=
+ name=
fi
if $compress; then
- table=
+ table=
else
- table=" table"
+ table=" table"
fi
new "set a"
@@ -392,7 +392,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_autocli_show.sh b/test/test_autocli_show.sh
index fa85aca6..709c7e81 100755
--- a/test/test_autocli_show.sh
+++ b/test/test_autocli_show.sh
@@ -47,18 +47,18 @@ module clixon-example {
prefix ex;
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
- leaf-list array1{
- type string;
+ list parameter{
+ key name;
+ leaf name{
+ type string;
}
- }
+ leaf value{
+ type string;
+ }
+ leaf-list array1{
+ type string;
+ }
+ }
}
}
EOF
@@ -101,7 +101,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -220,7 +220,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_autocli_spec.sh b/test/test_autocli_spec.sh
index 6a1ae8e5..2e0591ab 100755
--- a/test/test_autocli_spec.sh
+++ b/test/test_autocli_spec.sh
@@ -22,20 +22,20 @@ module clixon-example {
prefix ex;
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
- leaf stat{
- description "Inline state data for example application";
- config false;
- type int32;
- }
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
+ leaf stat{
+ description "Inline state data for example application";
+ config false;
+ type int32;
+ }
+ }
}
}
EOF
@@ -47,20 +47,20 @@ module clixon-example2 {
prefix ex2;
/* Alt config data */
container table2{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
- leaf stat{
- description "Inline state data for example application";
- config false;
- type int32;
- }
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
+ leaf stat{
+ description "Inline state data for example application";
+ config false;
+ type int32;
+ }
+ }
}
}
EOF
@@ -80,11 +80,11 @@ commit("Commit the changes"), cli_commit();
quit("Quit"), cli_quit();
show("Show a particular state of the system"){
configuration("Show configuration"), cli_show_auto_mode("candidate", "text", true, false);{
- xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", false, false);
- cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", false, false, "report-all", "set ");
- netconf("Show configuration as netconf edit-config operation"), cli_show_auto_mode("candidate", "netconf", false, false);
- text("Show configuration as text"), cli_show_auto_mode("candidate", "text", false, false);
- json("Show configuration as JSON"), cli_show_auto_mode("candidate", "json", false, false);
+ xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", false, false);
+ cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", false, false, "report-all", "set ");
+ netconf("Show configuration as netconf edit-config operation"), cli_show_auto_mode("candidate", "netconf", false, false);
+ text("Show configuration as text"), cli_show_auto_mode("candidate", "text", false, false);
+ json("Show configuration as JSON"), cli_show_auto_mode("candidate", "json", false, false);
}
state("Show configuration and state"), cli_show_auto_mode("running", "xml", false, true);
}
@@ -146,7 +146,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg -- -sS $fstate"
start_backend -s startup -f $cfg -- -sS $fstate
@@ -207,7 +207,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_autocli_strict_expand.sh b/test/test_autocli_strict_expand.sh
index 4337f566..8307c280 100755
--- a/test/test_autocli_strict_expand.sh
+++ b/test/test_autocli_strict_expand.sh
@@ -99,7 +99,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -148,7 +148,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_autocli_sub.sh b/test/test_autocli_sub.sh
index 2b090828..6fb62d31 100755
--- a/test/test_autocli_sub.sh
+++ b/test/test_autocli_sub.sh
@@ -56,10 +56,10 @@ module $APPNAME {
}
list index{
key i;
- leaf i{
- type string;
- }
- leaf iv{
+ leaf i{
+ type string;
+ }
+ leaf iv{
type string;
}
}
@@ -118,7 +118,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg"
start_backend -s startup -f $cfg
@@ -157,7 +157,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_autocli_treeref.sh b/test/test_autocli_treeref.sh
index dc4d1cc2..675e6082 100755
--- a/test/test_autocli_treeref.sh
+++ b/test/test_autocli_treeref.sh
@@ -127,7 +127,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -sS $fstate"
start_backend -s init -f $cfg -- -sS $fstate
@@ -204,7 +204,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_c++.sh b/test/test_c++.sh
index d00521b5..b3ddeb90 100755
--- a/test/test_c++.sh
+++ b/test/test_c++.sh
@@ -19,7 +19,7 @@ cat < $cfg
$cfg
${YANG_INSTALLDIR}
- $fyang
+ $fyang
$dir/backend
/usr/local/lib/$APPNAME/clispec
/usr/local/lib/$APPNAME/cli
@@ -36,32 +36,32 @@ module clixon-example{
namespace "urn:example:clixon";
prefix ex;
rpc example {
- description "Some example input/output for testing RFC7950 7.14.
+ description "Some example input/output for testing RFC7950 7.14.
RPC simply echoes the input for debugging.";
- input {
- leaf x {
- description
- "If a leaf in the input tree has a 'mandatory' statement with
+ input {
+ leaf x {
+ description
+ "If a leaf in the input tree has a 'mandatory' statement with
the value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- mandatory true;
- }
- leaf y {
- description
+ type string;
+ mandatory true;
+ }
+ leaf y {
+ description
"If a leaf in the input tree has a 'mandatory' statement with the
value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- default "42";
- }
- }
- output {
- leaf x {
- type string;
- }
- leaf y {
- type string;
- }
- }
+ type string;
+ default "42";
+ }
+ }
+ output {
+ leaf x {
+ type string;
+ }
+ leaf y {
+ type string;
+ }
+ }
}
}
EOF
@@ -122,10 +122,10 @@ static netconf_test api(clixon_plugin_init, plugin_start, plugin_exit);
/*! Local example netconf rpc callback
*/
int example_rpc(clicon_handle h,
- cxobj *xe,
- cbuf *cbret,
- void *arg,
- void *regarg)
+ cxobj *xe,
+ cbuf *cbret,
+ void *arg,
+ void *regarg)
{
int retval = -1;
cxobj *x = NULL;
@@ -134,12 +134,12 @@ int example_rpc(clicon_handle h,
/* get namespace from rpc name, return back in each output parameter */
if ((ns = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL)
{
- clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
- goto done;
+ clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
+ goto done;
}
cprintf(cbret, "", NETCONF_BASE_NAMESPACE);
if (!xml_child_nr_type(xe, CX_ELMNT))
- cprintf(cbret, " ");
+ cprintf(cbret, " ");
else{
while ((x = xml_child_each(xe, x, CX_ELMNT)) != NULL) {
if (xmlns_set(x, NULL, ns) < 0)
@@ -165,7 +165,7 @@ clixon_plugin_api* clixon_plugin_init(clicon_handle h)
clicon_debug(1, "%s netconf", __FUNCTION__);
/* Register local netconf rpc client (note not backend rpc client) */
if (rpc_callback_register(h, example_rpc, NULL, "urn:example:clixon", "example") < 0)
- return NULL;
+ return NULL;
return api.get_api();
}
@@ -180,7 +180,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
diff --git a/test/test_choice.sh b/test/test_choice.sh
index d96665e4..1fe4b9bf 100755
--- a/test/test_choice.sh
+++ b/test/test_choice.sh
@@ -111,16 +111,16 @@ module system{
presence true;
choice name {
container udp {
- leaf udp1{
- type string;
+ leaf udp1{
+ type string;
}
- leaf udp2{
- type string;
+ leaf udp2{
+ type string;
}
}
container tcp {
- leaf tcp1{
- type string;
+ leaf tcp1{
+ type string;
}
}
}
@@ -131,27 +131,27 @@ module system{
choice name {
case a {
leaf a1 {
- type string;
+ type string;
}
leaf a2 {
- mandatory true;
- type string;
+ mandatory true;
+ type string;
}
}
case b {
leaf b1 {
- type string;
+ type string;
}
}
case c {
- leaf c1 {
- mandatory true;
- type string;
+ leaf c1 {
+ mandatory true;
+ type string;
}
- choice c2 {
- case cc1 {
- leaf ccc1 {
- type string;
+ choice c2 {
+ case cc1 {
+ leaf ccc1 {
+ type string;
}
}
}
@@ -166,14 +166,14 @@ module system{
choice c {
case c1 {
leaf c1 {
- mandatory true;
- type string;
- }
- choice c1c {
- case c1c1 {
- leaf c1c1l {
+ mandatory true;
+ type string;
+ }
+ choice c1c {
+ case c1c1 {
+ leaf c1c1l {
type string;
- }
+ }
}
}
}
@@ -201,8 +201,8 @@ discard("Discard edits (rollback 0)"), discard_changes();
show("Show a particular state of the system"){
configuration("Show configuration"), cli_show_auto_mode("candidate", "text", true, false);{
- cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", true, false, "report-all", "set ");
- xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", true, false, NULL);
+ cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", true, false, "report-all", "set ");
+ xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", true, false, NULL);
}
}
EOF
@@ -213,7 +213,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -479,7 +479,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_choice_recursive.sh b/test/test_choice_recursive.sh
index f012ed7b..9fd25133 100755
--- a/test/test_choice_recursive.sh
+++ b/test/test_choice_recursive.sh
@@ -37,43 +37,43 @@ module system{
namespace "urn:example:config";
prefix ex;
container c {
- choice top{
- case topA {
- choice A{
- mandatory true;
- case A1{
- leaf A1x{
- type string;
- }
+ choice top{
+ case topA {
+ choice A{
+ mandatory true;
+ case A1{
+ leaf A1x{
+ type string;
+ }
}
- case A2{
- leaf A2x{
- type string;
- }
+ case A2{
+ leaf A2x{
+ type string;
+ }
}
- }
- leaf Ay{
- type string;
- }
- }
- case topB{
- choice B{
- case B1{
- leaf B1x{
- type string;
- }
- }
- case B2{
- leaf B2x{
- type string;
- }
- }
- }
- leaf By{
- type string;
- }
- }
- }
+ }
+ leaf Ay{
+ type string;
+ }
+ }
+ case topB{
+ choice B{
+ case B1{
+ leaf B1x{
+ type string;
+ }
+ }
+ case B2{
+ leaf B2x{
+ type string;
+ }
+ }
+ }
+ leaf By{
+ type string;
+ }
+ }
+ }
}
}
EOF
@@ -106,7 +106,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -167,7 +167,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_cli.sh b/test/test_cli.sh
index fd25c37e..35f87b5d 100755
--- a/test/test_cli.sh
+++ b/test/test_cli.sh
@@ -45,60 +45,60 @@ module clixon-example {
namespace "urn:example:clixon";
prefix ex;
import ietf-interfaces {
- prefix if;
+ prefix if;
}
import ietf-ip {
- prefix ip;
+ prefix ip;
}
import iana-if-type {
- prefix ianaift;
+ prefix ianaift;
}
import clixon-autocli{
- prefix autocli;
+ prefix autocli;
}
/* Example interface type for tests, local callbacks, etc */
identity eth {
- base if:interface-type;
+ base if:interface-type;
}
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
+ }
}
rpc example {
- description "Some example input/output for testing RFC7950 7.14.
+ description "Some example input/output for testing RFC7950 7.14.
RPC simply echoes the input for debugging.";
- input {
- leaf x {
- description
- "If a leaf in the input tree has a 'mandatory' statement with
+ input {
+ leaf x {
+ description
+ "If a leaf in the input tree has a 'mandatory' statement with
the value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- mandatory true;
- }
- leaf y {
- description
- "If a leaf in the input tree has a 'mandatory' statement with the
+ type string;
+ mandatory true;
+ }
+ leaf y {
+ description
+ "If a leaf in the input tree has a 'mandatory' statement with the
value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- default "42";
- }
- }
- output {
- leaf x {
- type string;
- }
- leaf y {
- type string;
- }
- }
+ type string;
+ default "42";
+ }
+ }
+ output {
+ leaf x {
+ type string;
+ }
+ leaf y {
+ type string;
+ }
+ }
}
}
EOF
@@ -120,23 +120,23 @@ quit("Quit"), cli_quit();
shell("System command") , cli_start_shell("bash");
copy("Copy and create a new object"){
interface("Copy interface"){
- (|("name of interface to copy from")) to("Copy to interface") ("Name of interface to copy to"), cli_copy_config("candidate","//interface[%s='%s']","urn:ietf:params:xml:ns:yang:ietf-interfaces","name","name","toname");
+ (|("name of interface to copy from")) to("Copy to interface") ("Name of interface to copy to"), cli_copy_config("candidate","//interface[%s='%s']","urn:ietf:params:xml:ns:yang:ietf-interfaces","name","name","toname");
}
}
discard("Discard edits (rollback 0)"), discard_changes();
debug("Debugging parts of the system"){
- cli("Set cli debug") ("Set debug level (0..n)"), cli_debug_cli();
+ cli("Set cli debug") ("Set debug level (0..n)"), cli_debug_cli();
}
show("Show a particular state of the system"){
xpath("Show configuration") ("XPATH expression") ("Namespace"), show_conf_xpath("candidate");
compare("Compare candidate and running databases"), compare_dbs((int32)0);{
- xml("Show comparison in xml"), compare_dbs((int32)0);
- text("Show comparison in text"), compare_dbs((int32)1);
+ xml("Show comparison in xml"), compare_dbs((int32)0);
+ text("Show comparison in text"), compare_dbs((int32)1);
}
configuration("Show configuration"), cli_show_auto_mode("candidate", "text", true, false);{
- cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", true, false, "report-all", "set ");
- xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", true, false);
- text("Show configuration as TEXT"), cli_show_auto_mode("candidate", "text", true, false);
+ cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", true, false, "report-all", "set ");
+ xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", true, false);
+ text("Show configuration as TEXT"), cli_show_auto_mode("candidate", "text", true, false);
}
}
save("Save candidate configuration to XML file") ("Filename (local filename)"), save_config_file("candidate","filename", "xml"){
@@ -146,10 +146,10 @@ save("Save candidate configuration to XML file") ("Filename (lo
text("Save configuration as TEXT"), save_config_file("candidate","filename", "text");
}
load("Load configuration from XML file") ("Filename (local filename)"),load_config_file("filename", "replace");{
- cli("Replace candidate with file containing CLI commands"), load_config_file("filename", "replace", "cli");
- xml("Replace candidate with file containing XML"), load_config_file("filename", "replace", "xml");
- json("Replace candidate with file containing JSON"), load_config_file("filename", "replace", "json");
- text("Replace candidate with file containing TEXT"), load_config_file("filename", "replace", "text");
+ cli("Replace candidate with file containing CLI commands"), load_config_file("filename", "replace", "cli");
+ xml("Replace candidate with file containing XML"), load_config_file("filename", "replace", "xml");
+ json("Replace candidate with file containing JSON"), load_config_file("filename", "replace", "json");
+ text("Replace candidate with file containing TEXT"), load_config_file("filename", "replace", "text");
}
rpc("example rpc") ("routing instance"), example_client_rpc("");
@@ -167,7 +167,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -272,7 +272,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_cli_apipath.sh b/test/test_cli_apipath.sh
index 2f9100db..f0564147 100755
--- a/test/test_cli_apipath.sh
+++ b/test/test_cli_apipath.sh
@@ -83,7 +83,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -117,7 +117,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_cli_duplicates.sh b/test/test_cli_duplicates.sh
index 485d542a..311d0830 100755
--- a/test/test_cli_duplicates.sh
+++ b/test/test_cli_duplicates.sh
@@ -26,37 +26,37 @@ module example {
prefix ex;
typedef uniontype {
type union {
- type enumeration {
+ type enumeration {
enum u1;
enum u2;
}
- type string;
+ type string;
}
}
/* Generic config data */
container tableleaf{
- list parleaf{
- description "leaf is union type";
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type uniontype;
- }
- }
+ list parleaf{
+ description "leaf is union type";
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type uniontype;
+ }
+ }
}
container tablekey{
- list parkey{
- description "key is union type";
- key name;
- leaf name{
- type uniontype;
- }
- leaf value{
- type string;
- }
- }
+ list parkey{
+ description "key is union type";
+ key name;
+ leaf name{
+ type uniontype;
+ }
+ leaf value{
+ type string;
+ }
+ }
}
}
EOF
@@ -115,7 +115,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -169,7 +169,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_cli_expand.sh b/test/test_cli_expand.sh
index 592ff32a..7f5ef1ee 100755
--- a/test/test_cli_expand.sh
+++ b/test/test_cli_expand.sh
@@ -22,7 +22,7 @@ cat < $cfg
$cfg
${YANG_INSTALLDIR}
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/backend
$clidir
/usr/local/lib/$APPNAME/cli
@@ -39,7 +39,7 @@ module clixon-example{
namespace "urn:example:clixon";
prefix ex;
list list1{
- key "key1";
+ key "key1";
leaf key1{
type string;
}
@@ -47,7 +47,7 @@ module clixon-example{
key "key2";
leaf key2{
type string;
- }
+ }
}
}
}
@@ -82,7 +82,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -111,7 +111,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_cli_history.sh b/test/test_cli_history.sh
index 5e95bd7a..f82cdaf2 100755
--- a/test/test_cli_history.sh
+++ b/test/test_cli_history.sh
@@ -18,7 +18,7 @@ cat < $cfg
$cfg
${YANG_INSTALLDIR}
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/backend
/usr/local/lib/$APPNAME/clispec
/usr/local/lib/$APPNAME/cli
@@ -49,7 +49,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -135,7 +135,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_cli_leafref.sh b/test/test_cli_leafref.sh
index 487ef084..c791a20a 100755
--- a/test/test_cli_leafref.sh
+++ b/test/test_cli_leafref.sh
@@ -59,87 +59,87 @@ module example-leafref{
}
/* Basic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type uint32;
- }
- leaf value{
- type string;
- }
+ list parameter{
+ key name;
+ leaf name{
+ type uint32;
+ }
+ leaf value{
+ type string;
+ }
}
}
/* first level leafref */
container leafrefs {
description "Leafref relative path, no require-instance";
- list leafref{
- key name;
- leaf name {
- type leafref{
+ list leafref{
+ key name;
+ leaf name {
+ type leafref{
path "../../../table/parameter/name";
- require-instance false;
+ require-instance false;
}
}
}
}
- /* first level leafref absolute */
+ /* first level leafref absolute */
container leafrefsabs {
description "Leafref absolute path, no require-instance";
- list leafref{
- key name;
- leaf name {
- type leafref{
+ list leafref{
+ key name;
+ leaf name {
+ type leafref{
path "/table/parameter/name";
- require-instance false;
+ require-instance false;
}
}
}
}
- /* first level leafref require-instance */
+ /* first level leafref require-instance */
container leafrefsreqinst {
description "Leafref absolute path, require-instance true";
- list leafref{
- key name;
- leaf name {
- type leafref{
+ list leafref{
+ key name;
+ leaf name {
+ type leafref{
path "/table/parameter/name";
- require-instance true;
+ require-instance true;
}
}
}
}
/* first level identityrefs */
container identityrefs {
- list identityref{
- description "Identityref base";
- key name;
- leaf name {
- type identityref{
- base "ex:crypto-alg";
+ list identityref{
+ description "Identityref base";
+ key name;
+ leaf name {
+ type identityref{
+ base "ex:crypto-alg";
}
}
}
}
/* second level leafref */
container leafrefs2 {
- list leafref{
- key name;
- leaf name {
- type leafref{
+ list leafref{
+ key name;
+ leaf name {
+ type leafref{
path "../../../leafrefs/leafref/name";
- require-instance false;
+ require-instance false;
}
}
}
}
/* second level identityref */
container identityrefs2 {
- list identityref{
- key name;
- leaf name {
- type leafref{
+ list identityref{
+ key name;
+ leaf name {
+ type leafref{
path "../../../identityrefs/identityref/name";
- require-instance false;
+ require-instance false;
}
}
}
@@ -196,7 +196,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg"
start_backend -s startup -f $cfg
@@ -296,7 +296,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_cli_multikey.sh b/test/test_cli_multikey.sh
index 5078a1c3..59396fcb 100755
--- a/test/test_cli_multikey.sh
+++ b/test/test_cli_multikey.sh
@@ -39,30 +39,30 @@ module $APPNAME{
container ex {
list x{
key "a b" ;
- leaf a {
- type string;
- }
- leaf b {
- type enumeration{
- enum v1;
- enum v2;
- enum v3;
- }
- }
+ leaf a {
+ type string;
+ }
+ leaf b {
+ type enumeration{
+ enum v1;
+ enum v2;
+ enum v3;
+ }
+ }
}
list y{
key "a b" ;
ordered-by user;
- leaf a {
- type string;
- }
- leaf b {
- type enumeration{
- enum v1;
- enum v2;
- enum v3;
- }
- }
+ leaf a {
+ type string;
+ }
+ leaf b {
+ type enumeration{
+ enum v1;
+ enum v2;
+ enum v3;
+ }
+ }
}
}
}
@@ -73,7 +73,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -130,7 +130,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_cli_rest.sh b/test/test_cli_rest.sh
index 8cb951a8..ea8266b3 100755
--- a/test/test_cli_rest.sh
+++ b/test/test_cli_rest.sh
@@ -21,7 +21,7 @@ cat < $cfg
$cfg
${YANG_INSTALLDIR}
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/backend
$clidir
/usr/local/lib/$APPNAME/cli
@@ -59,7 +59,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -100,7 +100,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_cli_submodes.sh b/test/test_cli_submodes.sh
index 430d4340..46164cac 100755
--- a/test/test_cli_submodes.sh
+++ b/test/test_cli_submodes.sh
@@ -26,7 +26,7 @@ cat < $cfg
$cfg
${YANG_INSTALLDIR}
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/backend
$clidir
/usr/local/lib/$APPNAME/cli
@@ -81,7 +81,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -119,7 +119,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_cli_translate.sh b/test/test_cli_translate.sh
index b8262023..a44abdda 100755
--- a/test/test_cli_translate.sh
+++ b/test/test_cli_translate.sh
@@ -39,14 +39,14 @@ module clixon-example{
prefix ex;
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
}
}
}
@@ -74,7 +74,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -94,7 +94,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_cli_union.sh b/test/test_cli_union.sh
index 88694abf..fc8be923 100755
--- a/test/test_cli_union.sh
+++ b/test/test_cli_union.sh
@@ -22,37 +22,37 @@ module example {
prefix ex;
typedef uniontype {
type union {
- type enumeration {
+ type enumeration {
enum u1;
enum u2;
}
- type string;
+ type string;
}
}
/* Generic config data */
container tableleaf{
- list parleaf{
- description "leaf is union type";
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type uniontype;
- }
- }
+ list parleaf{
+ description "leaf is union type";
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type uniontype;
+ }
+ }
}
container tablekey{
- list parkey{
- description "key is union type";
- key name;
- leaf name{
- type uniontype;
- }
- leaf value{
- type string;
- }
- }
+ list parkey{
+ description "key is union type";
+ key name;
+ leaf name{
+ type uniontype;
+ }
+ leaf value{
+ type string;
+ }
+ }
}
}
EOF
@@ -103,7 +103,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -155,7 +155,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_cli_varonly.sh b/test/test_cli_varonly.sh
index b4d27d70..84a064d0 100755
--- a/test/test_cli_varonly.sh
+++ b/test/test_cli_varonly.sh
@@ -39,15 +39,15 @@ module example {
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
+ }
}
}
EOF
@@ -57,7 +57,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -89,7 +89,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_client.sh b/test/test_client.sh
index eb7efb32..1a7dc794 100755
--- a/test/test_client.sh
+++ b/test/test_client.sh
@@ -52,21 +52,21 @@ module clixon-client {
namespace "urn:example:clixon-client";
prefix exc;
description
- "Clixon client example yang";
+ "Clixon client example yang";
revision 2021-01-14 {
description "Added table/paramater/value as the primary data example";
}
/* Generic config data */
container table{
list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type uint32;
- }
- }
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type uint32;
+ }
+ }
}
}
EOF
@@ -111,7 +111,7 @@ main(int argc,
done:
clixon_client_disconnect(ch);
clixon_client_terminate(h);
- printf("done\n"); /* for test output */
+ printf("done\n"); /* for test output */
return retval;
}
EOF
@@ -132,13 +132,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend"
start_backend -s init -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -174,7 +174,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_confirmed_commit.sh b/test/test_confirmed_commit.sh
new file mode 100755
index 00000000..a7def9b0
--- /dev/null
+++ b/test/test_confirmed_commit.sh
@@ -0,0 +1,475 @@
+#!/usr/bin/env bash
+# Netconf confirm commit capability
+# See RFC 6241 Section 8.4 and RFC 8040 Section 1.4
+# TODO:
+# - privileges drop
+# - lock check
+
+# Magic line must be first in script (see README.md)
+s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
+
+APPNAME=example
+
+cfg=$dir/conf_yang.xml
+tmp=$dir/tmp.x
+fyang=$dir/clixon-example.yang
+
+# Backend user for priv drop, otherwise root
+USER=${BUSER}
+
+# Define default restconfig config: RESTCONFIG
+RESTCONFIG=$(restconf_config none false)
+
+cat < $cfg
+
+ ietf-netconf:confirmed-commit
+ clixon-restconf:allow-auth-none
+ $cfg
+ ${YANG_INSTALLDIR}
+ $fyang
+ /usr/local/lib/$APPNAME/clispec
+ /usr/local/lib/$APPNAME/cli
+ $APPNAME
+ $dir/$APPNAME.sock
+ /usr/local/var/$APPNAME/$APPNAME.pidfile
+ /usr/local/var/$APPNAME
+ $USER
+ drop_perm
+ $RESTCONFIG
+
+EOF
+
+cat < $fyang
+module clixon-example{
+ yang-version 1.1;
+ namespace "urn:example:clixon";
+ prefix ex;
+
+ /* Generic config data */
+ container table{
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ }
+ }
+}
+EOF
+
+function data() {
+ if [[ "$1" == "" ]]
+ then
+ echo " "
+ else
+ echo "$1 "
+ fi
+}
+
+# Pipe stdin to command and also do chunked framing (netconf 1.1)
+# Arguments:
+# - Command
+# - expected command return value (0 if OK)
+# - stdin input1 This is NOT encoded, eg preamble/hello
+# - stdin input2 This gets chunked encoding
+# - expect1 stdout outcome, can be partial and contain regexps
+# - expect2 stdout outcome This gets chunked encoding, must be complete netconf message
+# Use this if you want regex eg ^foo$
+
+function rpc() {
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$1 " "" "$2 "
+}
+
+function commit() {
+ new "commit $1"
+ if [[ "$1" == "" ]]
+ then
+ rpc " " " "
+ else
+ rpc "$1 " " "
+ fi
+}
+
+function edit_config() {
+ TARGET="$1"
+ CONFIG="$2"
+ new "edit-config $1 $2"
+ rpc "<$TARGET/> $CONFIG " " "
+}
+
+function assert_config_equals() {
+ TARGET="$1"
+ EXPECTED="$2"
+# new "get-config: $TARGET"
+ rpc "<$TARGET/> " "$(data "$EXPECTED")"
+}
+
+# delete all
+function reset() {
+ rpc "none " " "
+ commit
+ assert_config_equals "candidate" ""
+ assert_config_equals "running" ""
+}
+
+CANDIDATE_PATH="/usr/local/var/$APPNAME/candidate_db"
+RUNNING_PATH="/usr/local/var/$APPNAME/running_db"
+ROLLBACK_PATH="/usr/local/var/$APPNAME/rollback_db"
+FAILSAFE_PATH="/usr/local/var/$APPNAME/failsafe_db"
+
+
+CONFIGB=""
+CONFIGC=""
+CONFIGCONLY="eth1 " # restcpnf
+CONFIGBPLUSC=""
+FAILSAFE_CFG=""
+
+new "test params: -f $cfg"
+
+# Bring your own backend
+if [ $BE -ne 0 ]; then
+ # kill old backend (if any)
+ new "kill old backend"
+ stop_backend -f $cfg
+
+ new "start backend -s init -f $cfg"
+ start_backend -s init -f $cfg
+fi
+
+new "wait backend"
+wait_backend
+
+new "Hello check confirm-commit capability"
+expecteof "$clixon_netconf -f $cfg" 0 "urn:ietf:params:netconf:base:1.1 ]]>]]>" "urn:ietf:params:netconf:capability:confirmed-commit:1.1 " '^$'
+
+################################################################################
+new "netconf ephemeral confirmed-commit rolls back after disconnect"
+reset
+edit_config "candidate" "$CONFIGB"
+assert_config_equals "candidate" "$CONFIGB"
+commit "30 "
+assert_config_equals "running" ""
+
+################################################################################
+
+new "netconf persistent confirmed-commit"
+reset
+edit_config "candidate" "$CONFIGB"
+commit "a "
+assert_config_equals "running" "$CONFIGB"
+edit_config "candidate" "$CONFIGC"
+commit "ab a "
+assert_config_equals "running" "$CONFIGBPLUSC"
+
+################################################################################
+
+new "netconf cancel-commit with invalid persist-id"
+rpc "abc " "application invalid-value error a confirmed-commit with the given persist-id was not found "
+
+################################################################################
+
+new "netconf cancel-commit with valid persist-id"
+rpc "ab " " "
+
+################################################################################
+
+new "netconf persistent confirmed-commit with timeout"
+reset
+edit_config "candidate" "$CONFIGB"
+commit "2 abcd "
+assert_config_equals "running" "$CONFIGB"
+sleep 2
+assert_config_equals "running" ""
+
+################################################################################
+
+new "netconf persistent confirmed-commit with reset timeout"
+reset
+edit_config "candidate" "$CONFIGB"
+commit "abcde 5 "
+assert_config_equals "running" "$CONFIGB"
+edit_config "candidate" "$CONFIGC"
+commit "abcde abcdef 10 "
+# prove the new timeout is active by sleeping longer than first timeout. get config, assert == B+C
+sleep 6
+assert_config_equals "running" "$CONFIGBPLUSC"
+# now sleep long enough for rollback to happen; get config, assert == A
+sleep 5
+assert_config_equals "running" ""
+
+################################################################################
+
+new "netconf persistent confirming-commit to epehemeral confirmed-commit should rollback"
+reset
+edit_config "candidate" "$CONFIGB"
+commit "10 "
+assert_config_equals "running" "$CONFIGB"
+commit " "
+assert_config_equals "running" ""
+
+################################################################################
+
+new "netconf confirming-commit for persistent confirmed-commit with empty persist value"
+reset
+edit_config "candidate" "$CONFIGB"
+commit "10 "
+assert_config_equals "running" "$CONFIGB"
+commit " "
+assert_config_equals "running" "$CONFIGB"
+
+################################################################################
+# TODO reconsider logic around presence/absence of rollback_db as a signal as dropping permissions may impact ability
+# to unlink and/or create that file. see clixon_datastore.c#xmldb_delete() and backend_startup.c#startup_mode_startup()
+
+new "backend loads rollback if present at startup"
+reset
+edit_config "candidate" "$CONFIGB"
+commit ""
+edit_config "candidate" "$CONFIGC"
+commit "abcdefg "
+assert_config_equals "running" "$CONFIGBPLUSC"
+
+new "kill old backend"
+stop_backend -f $cfg # kill backend and restart
+
+new "Check $ROLLBACK_PATH"
+[ -f "$ROLLBACK_PATH" ] || err "rollback_db doesn't exist!" # assert rollback_db exists
+
+new "start backend -s running -f $cfg"
+start_backend -s running -f $cfg
+
+new "wait backend"
+wait_backend
+
+assert_config_equals "running" "$CONFIGB"
+
+new "Check $ROLLBACK_PATH removed"
+[ -f "ROLLBACK_PATH" ] && err "rollback_db still exists!" # assert rollback_db doesn't exist
+
+new "kill old backend"
+stop_backend -f $cfg
+
+new "start backend -s init -f $cfg"
+start_backend -s init -f $cfg
+
+################################################################################
+new "backend loads failsafe at startup if rollback present but cannot be loaded"
+
+new "wait backend"
+wait_backend
+
+reset
+
+sudo tee "$FAILSAFE_PATH" > /dev/null << EOF # create a failsafe database
+$FAILSAFE_CFG
+EOF
+edit_config "candidate" "$CONFIGC"
+
+commit "foobar "
+
+assert_config_equals "running" "$CONFIGC"
+
+new "kill old backend"
+stop_backend -f $cfg # kill the backend
+
+sudo rm $ROLLBACK_PATH # modify rollback_db so it won't commit successfully
+
+sudo tee "$ROLLBACK_PATH" > /dev/null << EOF
+
+
+
+
+
+EOF
+
+new "start backend -s running -f $cfg"
+start_backend -s running -f $cfg
+
+new "wait backend"
+wait_backend
+
+assert_config_equals "running" "$FAILSAFE_CFG"
+
+new "kill old backend"
+stop_backend -f $cfg
+
+new "start backend -s init -f $cfg"
+start_backend -s init -f $cfg -lf/tmp/clixon.log -D1
+
+new "wait backend"
+wait_backend
+
+################################################################################
+
+new "ephemeral confirmed-commit survives unrelated ephemeral session disconnect"
+reset
+edit_config "candidate" "$CONFIGB"
+assert_config_equals "candidate" "$CONFIGB"
+# start a new ephemeral confirmed commit, but keep the confirmed-commit session alive (need to put it in the background)
+# use HELLONO11 which uses older EOM framing
+sleep 60 | cat <(echo "$HELLONO1160 ]]>]]>") -| $clixon_netconf -qf $cfg >> /dev/null &
+PIDS=($(jobs -l % | cut -c 6- | awk '{print $1}'))
+assert_config_equals "running" "$CONFIGB" # assert config twice to prove it surives disconnect
+assert_config_equals "running" "$CONFIGB" # of ephemeral sessions
+
+new "soft kill ${PIDS[0]}"
+kill ${PIDS[0]} # kill the while loop above to close STDIN on 1st
+
+################################################################################
+
+new "cli ephemeral confirmed-commit rolls back after disconnect"
+reset
+
+tmppipe=$(mktemp -u)
+mkfifo -m 600 "$tmppipe"
+
+cat << EOF | clixon_cli -f $cfg >> /dev/null &
+set table parameter eth0
+commit confirmed 60
+shell echo >> $tmppipe
+shell cat $tmppipe
+quit
+EOF
+
+cat $tmppipe >> /dev/null
+assert_config_equals "running" "$CONFIGB"
+echo >> $tmppipe
+sleep 1
+assert_config_equals "running" ""
+rm $tmppipe
+
+################################################################################
+
+new "cli persistent confirmed-commit"
+reset
+
+cat << EOF | clixon_cli -f $cfg >> /dev/null
+set table parameter eth0
+commit confirmed persist a
+quit
+EOF
+
+assert_config_equals "running" "$CONFIGB"
+
+cat << EOF | clixon_cli -f $cfg >> /dev/null
+set table parameter eth1
+commit persist-id a confirmed persist ab
+quit
+EOF
+assert_config_equals "running" "$CONFIGBPLUSC"
+
+################################################################################
+
+new "cli cancel-commit with invalid persist-id"
+expectpart "$($clixon_cli -lo -1 -f $cfg commit persist-id abc cancel)" 255 "a confirmed-commit with the given persist-id was not found"
+
+################################################################################
+
+new "cli cancel-commit with valid persist-id"
+expectpart "$($clixon_cli -lo -1 -f $cfg commit persist-id ab cancel)" 0 "^$"
+assert_config_equals "running" ""
+
+################################################################################
+
+new "cli cancel-commit with no confirmed-commit in progress"
+expectpart "$($clixon_cli -lo -1 -f $cfg commit persist-id ab cancel)" 255 "no confirmed-commit is in progress"
+
+################################################################################
+
+new "cli persistent confirmed-commit with timeout"
+reset
+cat << EOF | clixon_cli -f $cfg >> /dev/null
+set table parameter eth0
+commit confirmed persist abcd 2
+EOF
+assert_config_equals "running" "$CONFIGB"
+sleep 2
+assert_config_equals "running" ""
+
+################################################################################
+
+new "cli persistent confirmed-commit with reset timeout"
+reset
+cat << EOF | clixon_cli -f $cfg >> /dev/null
+set table parameter eth0
+commit confirmed persist abcd 5
+EOF
+
+assert_config_equals "running" "$CONFIGB"
+cat << EOF | clixon_cli -f $cfg >> /dev/null
+set table parameter eth1
+commit persist-id abcd confirmed persist abcdef 10
+EOF
+
+sleep 6
+assert_config_equals "running" "$CONFIGBPLUSC"
+# now sleep long enough for rollback to happen; get config, assert == A
+sleep 5
+assert_config_equals "running" ""
+
+# TODO test restconf receives "409 conflict" when there is a persistent confirmed-commit active
+# TODO test restconf causes confirming-commit for ephemeral confirmed-commit
+if [ $RC -ne 0 ]; then
+ new "kill old restconf daemon"
+ stop_restconf_pre
+
+ new "start restconf daemon"
+ start_restconf -f $cfg
+fi
+
+new "wait restconf"
+wait_restconf
+
+new "restconf as confirmed commit"
+reset
+edit_config "candidate" "$CONFIGB"
+assert_config_equals "candidate" "$CONFIGB"
+# use HELLONO11 which uses older EOM framing
+sleep 60 | cat <(echo "$HELLONO1160 ]]>]]> ]]>]]>") -| $clixon_netconf -qf $cfg >> /dev/null &
+PIDS=($(jobs -l % | cut -c 6- | awk '{print $1}'))
+assert_config_equals "running" "$CONFIGB" # assert config twice to prove it surives disconnect
+
+new "restconf POST"
+expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" -d "$CONFIGCONLY" $RCPROTO://localhost/restconf/data/clixon-example:table)" 0 "HTTP/$HVER 201" "location:"
+
+assert_config_equals "running" "$CONFIGBPLUSC"
+
+new "soft kill ${PIDS[0]}"
+kill ${PIDS[0]} # kill the while loop above to close STDIN on 1st
+
+assert_config_equals "running" "$CONFIGBPLUSC"
+
+################################################################################
+
+new "restconf persistid expect fail"
+reset
+edit_config "candidate" "$CONFIGB"
+commit "a "
+assert_config_equals "running" "$CONFIGB"
+
+new "restconf POST"
+expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" -d "$CONFIGCONLY" $RCPROTO://localhost/restconf/data/clixon-example:table)" 0 # "HTTP/$HVER 409"
+
+assert_config_equals "running" "$CONFIGB"
+
+if [ $RC -ne 0 ]; then
+ new "Kill restconf daemon"
+ stop_restconf
+fi
+
+if [ $BE -ne 0 ]; then
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u ${USER} -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
+fi
+
+# Set by restconf_config
+unset RESTCONFIG
+
+new "endtest"
+endtest
diff --git a/test/test_copy_config.sh b/test/test_copy_config.sh
index 87640215..f8b6e9b1 100755
--- a/test/test_copy_config.sh
+++ b/test/test_copy_config.sh
@@ -107,7 +107,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
@@ -227,7 +227,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_datastore_format.sh b/test/test_datastore_format.sh
index 2d6dca62..eae29819 100755
--- a/test/test_datastore_format.sh
+++ b/test/test_datastore_format.sh
@@ -49,18 +49,18 @@ module clixon-example {
prefix ex;
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
- leaf-list array1{
- type string;
+ list parameter{
+ key name;
+ leaf name{
+ type string;
}
- }
+ leaf value{
+ type string;
+ }
+ leaf-list array1{
+ type string;
+ }
+ }
}
}
EOF
@@ -75,8 +75,8 @@ module clixon-augment {
}
augment "/ex:table/ex:parameter" {
leaf-list array2{
- type string;
- }
+ type string;
+ }
}
}
EOF
@@ -100,13 +100,13 @@ discard("Discard edits (rollback 0)"), discard_changes();
show("Show a particular state of the system"){
xpath("Show configuration") ("XPATH expression") ("Namespace"), show_conf_xpath("candidate");
compare("Compare candidate and running databases"), compare_dbs((int32)0);{
- xml("Show comparison in xml"), compare_dbs((int32)0);
- text("Show comparison in text"), compare_dbs((int32)1);
+ xml("Show comparison in xml"), compare_dbs((int32)0);
+ text("Show comparison in text"), compare_dbs((int32)1);
}
configuration("Show configuration"), cli_show_auto_mode("candidate", "text", true, false);{
- cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", true, false, "report-all", "set ");
- xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", true, false);
- text("Show configuration as TEXT"), cli_show_auto_mode("candidate", "text", true, false);
+ cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", true, false, "report-all", "set ");
+ xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", true, false);
+ text("Show configuration as TEXT"), cli_show_auto_mode("candidate", "text", true, false);
}
}
save("Save candidate configuration to XML file") ("Filename (local filename)"), save_config_file("candidate","filename", "xml"){
@@ -116,10 +116,10 @@ save("Save candidate configuration to XML file") ("Filename (lo
text("Save configuration as TEXT"), save_config_file("candidate","filename", "text");
}
load("Load configuration from XML file") ("Filename (local filename)"),load_config_file("filename", "replace");{
- cli("Replace candidate with file containing CLI commands"), load_config_file("filename", "replace", "cli");
- xml("Replace candidate with file containing XML"), load_config_file("filename", "replace", "xml");
- json("Replace candidate with file containing JSON"), load_config_file("filename", "replace", "json");
- text("Replace candidate with file containing TEXT"), load_config_file("filename", "replace", "text");
+ cli("Replace candidate with file containing CLI commands"), load_config_file("filename", "replace", "cli");
+ xml("Replace candidate with file containing XML"), load_config_file("filename", "replace", "xml");
+ json("Replace candidate with file containing JSON"), load_config_file("filename", "replace", "json");
+ text("Replace candidate with file containing TEXT"), load_config_file("filename", "replace", "text");
}
EOF
@@ -129,7 +129,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -162,8 +162,8 @@ for format in cli text xml json; do
expectpart "$($clixon_cli -1 -f $cfg -l o load $formatdir/config.$format $format)" 0 "^$"
if [ $format != json ]; then # XXX JSON identity problem
- new "cli check compare $format"
- expectpart "$($clixon_cli -1 -f $cfg -l o show compare xml)" 0 "^$" --not-- "i" # interface?
+ new "cli check compare $format"
+ expectpart "$($clixon_cli -1 -f $cfg -l o show compare xml)" 0 "^$" --not-- "i" # interface?
fi
done
@@ -173,7 +173,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_datastore_repair.sh b/test/test_datastore_repair.sh
index 9e6b91e0..0e3e6278 100755
--- a/test/test_datastore_repair.sh
+++ b/test/test_datastore_repair.sh
@@ -85,14 +85,14 @@ function testrun(){
new "test params: -f $cfg -- -U" # -U : upgrade
# Bring your own backend
if [ $BE -ne 0 ]; then
- # kill old backend (if any)
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s startup -f $cfg -- -U"
- start_backend -s startup -f $cfg -- -U
+ # kill old backend (if any)
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s startup -f $cfg -- -U"
+ start_backend -s startup -f $cfg -- -U
fi
new "wait backend"
@@ -102,14 +102,14 @@ function testrun(){
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "$AFTER "
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
} # end testrun
diff --git a/test/test_db.sh b/test/test_db.sh
index c64e0789..a2e0a833 100755
--- a/test/test_db.sh
+++ b/test/test_db.sh
@@ -40,18 +40,18 @@ module clixon-example{
prefix ex;
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
- container two{
- leaf a{
- type string;
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
+ container two{
+ leaf a{
+ type string;
+ }
}
}
}
@@ -95,13 +95,13 @@ function testrun()
pretty=$2
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -z -f $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s init -f $cfg -o CLICON_XMLDB_FORMAT=$format -o CLICON_XMLDB_PRETTY=$pretty"
- start_backend -s init -f $cfg -o CLICON_XMLDB_FORMAT=$format -o CLICON_XMLDB_PRETTY=$pretty
+ new "kill old backend"
+ sudo clixon_backend -z -f $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s init -f $cfg -o CLICON_XMLDB_FORMAT=$format -o CLICON_XMLDB_PRETTY=$pretty"
+ start_backend -s init -f $cfg -o CLICON_XMLDB_FORMAT=$format -o CLICON_XMLDB_PRETTY=$pretty
fi
new "wait backend"
@@ -117,12 +117,12 @@ function testrun()
# permission kludges
sudo chmod 666 $dir/candidate_db
if [ "$format" = xml ]; then
- if [ "$pretty" = false ]; then
- cat < $dir/expect
+ if [ "$pretty" = false ]; then
+ cat < $dir/expect
<${DATASTORE_TOP}>${DATASTORE_TOP}>
EOF
- else
- cat < $dir/expect
+ else
+ cat < $dir/expect
<${DATASTORE_TOP}>
@@ -132,14 +132,14 @@ EOF
${DATASTORE_TOP}>
EOF
- fi
+ fi
else
- if [ "$pretty" = false ]; then
- cat < $dir/expect
+ if [ "$pretty" = false ]; then
+ cat < $dir/expect
{"$DATASTORE_TOP":{"clixon-example:table":{"parameter":[{"name":"a","value":"42"}]}}}
EOF
- else
- cat < $dir/expect
+ else
+ cat < $dir/expect
{
"${DATASTORE_TOP}": {
"clixon-example:table": {
@@ -153,13 +153,13 @@ EOF
}
}
EOF
- fi
+ fi
fi
# -w ignore white space
ret=$(diff -w $dir/candidate_db $dir/expect)
if [ $? -ne 0 ]; then
- err "$(cat $dir/expect)" "$(cat $dir/candidate_db)"
+ err "$(cat $dir/expect)" "$(cat $dir/candidate_db)"
fi
new "save config file"
@@ -175,14 +175,14 @@ EOF
expectpart "$($clixon_cli -1 -f $cfg show config)" 0 "^$"
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
@@ -190,8 +190,8 @@ new "test params: -f $cfg"
for format in xml json; do
for pretty in false true; do
- new "test db $format pretty=$pretty"
- testrun xml false
+ new "test db $format pretty=$pretty"
+ testrun xml false
done
done
@@ -200,7 +200,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -o CLICON_XMLDB_FORMAT=$format -o CLICON_XMLDB_PRETTY=$pretty"
start_backend -s init -f $cfg -o CLICON_XMLDB_FORMAT=$format -o CLICON_XMLDB_PRETTY=$pretty
@@ -237,8 +237,8 @@ cat < $dir/myconfig
a
42
- 1
- 2
+ 1
+ 2
${DATASTORE_TOP}>
@@ -256,7 +256,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_debug.sh b/test/test_debug.sh
index d1fe80ad..42dc17a0 100755
--- a/test/test_debug.sh
+++ b/test/test_debug.sh
@@ -38,15 +38,15 @@ module example{
prefix ex;
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
+ }
}
}
EOF
@@ -57,7 +57,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
new "start backend -s init -f $cfg"
@@ -104,7 +104,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err1 "backend pid !=0" 0
+ err1 "backend pid !=0" 0
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_feature.sh b/test/test_feature.sh
index accdb743..92221390 100755
--- a/test/test_feature.sh
+++ b/test/test_feature.sh
@@ -50,7 +50,7 @@ module example{
namespace "urn:example:clixon";
prefix ex;
import ietf-routing {
- prefix rt;
+ prefix rt;
}
feature A{
description "This test feature is enabled";
@@ -119,13 +119,13 @@ module example{
}
leaf m9{
if-feature "(A or B "
- + "or B1) and A1";
+ + "or B1) and A1";
description "Enabled";
type "string";
}
leaf m10{
if-feature "(A and A1 "
- + "and B1) or not A";
+ + "and B1) or not A";
description "Disabled";
type "string";
}
@@ -155,14 +155,14 @@ function testrun()
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
if $enabled; then
- new "netconf set extra element under $node (expect fail)"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<$node xmlns=\"urn:example:clixon\"> $node> " "" "application unknown-element kallekaka error Failed to find YANG spec of XML node: kallekaka with parent: $node in namespace: urn:example:clixon "
+ new "netconf set extra element under $node (expect fail)"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<$node xmlns=\"urn:example:clixon\"> $node> " "" "application unknown-element kallekaka error Failed to find YANG spec of XML node: kallekaka with parent: $node in namespace: urn:example:clixon "
else
- new "netconf set extra element under $node"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<$node xmlns=\"urn:example:clixon\"> $node> " "" " "
+ new "netconf set extra element under $node"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<$node xmlns=\"urn:example:clixon\"> $node> " "" " "
- new "netconf validate $node"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+ new "netconf validate $node"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
fi
new "netconf discard-changes"
@@ -174,7 +174,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
@@ -296,7 +296,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -324,7 +324,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg: feature missing expected fail"
diff --git a/test/test_feature_startup.sh b/test/test_feature_startup.sh
index 5956c63d..ea38e293 100755
--- a/test/test_feature_startup.sh
+++ b/test/test_feature_startup.sh
@@ -65,7 +65,7 @@ testrun()
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg"
@@ -88,7 +88,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_helloworld.sh b/test/test_helloworld.sh
index c635d864..69cce32b 100755
--- a/test/test_helloworld.sh
+++ b/test/test_helloworld.sh
@@ -23,7 +23,7 @@ cat < $cfg
$cfg
clixon-restconf:allow-auth-none
${YANG_INSTALLDIR}
- $fyang
+ $fyang
$clispec
hello
$dir/hello.sock
@@ -43,9 +43,9 @@ cat < $cfg
file
default
- 0.0.0.0
- 80
- false
+ 0.0.0.0
+ 80
+ false
@@ -65,13 +65,13 @@ module clixon-hello {
namespace "urn:example:hello";
prefix he;
revision 2019-04-17 {
- description
- "Clixon hello world example";
+ description
+ "Clixon hello world example";
}
container hello{
- container world{
- presence true;
- }
+ container world{
+ presence true;
+ }
}
}
EOF
@@ -101,7 +101,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -184,7 +184,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_http_data.sh b/test/test_http_data.sh
index 58309359..6a0a7329 100755
--- a/test/test_http_data.sh
+++ b/test/test_http_data.sh
@@ -130,13 +130,13 @@ function testrun()
RESTCONFIG=$(restconf_config none false $proto $enable)
if true; then
- # Proper test setup
- datapath=/data
- wdir=$dir/www
+ # Proper test setup
+ datapath=/data
+ wdir=$dir/www
else
- # Experiments with local host
- datapath=/
- wdir=/var/www/html
+ # Experiments with local host
+ datapath=/
+ wdir=/var/www/html
fi
# Clixon config
cat < $cfg
@@ -165,26 +165,26 @@ EOF
new "test params: -f $cfg"
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- sudo pkill -f clixon_backend # to be sure
-
- new "start backend -s init -f $cfg"
- start_backend -s init -f $cfg
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ sudo pkill -f clixon_backend # to be sure
+
+ new "start backend -s init -f $cfg"
+ start_backend -s init -f $cfg
fi
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
- new "kill old restconf daemon"
- stop_restconf_pre
+ new "kill old restconf daemon"
+ stop_restconf_pre
- new "start restconf daemon"
- start_restconf -f $cfg
+ new "start restconf daemon"
+ start_restconf -f $cfg
fi
new "wait restconf"
@@ -193,95 +193,95 @@ EOF
# echo "curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/index.html"
if ! $enable; then
- # XXX or bad request?
- new "WWW get html, not enabled, expect not found"
-# echo "curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/index.html"
- expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/index.html)" 0 "HTTP/$HVER 404"
+ # XXX or bad request?
+ new "WWW get html, not enabled, expect not found"
+# echo "curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/index.html"
+ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/index.html)" 0 "HTTP/$HVER 404"
else
- new "WWW get root expect 404 without body"
- expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/)" 0 "HTTP/$HVER 404" --not-- "Content-Type"
-
- new "WWW get index.html"
- expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/index.html)" 0 "HTTP/$HVER 200" "Content-Type: text/html" "Welcome to Clixon! "
-
- new "WWW get dir -> expect index.html"
- expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data)" 0 "HTTP/$HVER 200" "Content-Type: text/html" "Welcome to Clixon! "
+ new "WWW get root expect 404 without body"
+ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/)" 0 "HTTP/$HVER 404" --not-- "Content-Type"
+
+ new "WWW get index.html"
+ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/index.html)" 0 "HTTP/$HVER 200" "Content-Type: text/html" "Welcome to Clixon! "
+
+ new "WWW get dir -> expect index.html"
+ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data)" 0 "HTTP/$HVER 200" "Content-Type: text/html" "Welcome to Clixon! "
- # remove index
- mv $dir/www/data/index.html $dir/www/data/tmp.index.html
+ # remove index
+ mv $dir/www/data/index.html $dir/www/data/tmp.index.html
- new "WWW get dir -> no indirection expect 404"
- expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data)" 0 "HTTP/$HVER 404" "Content-Type: text/html" "404 Not Found "
+ new "WWW get dir -> no indirection expect 404"
+ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data)" 0 "HTTP/$HVER 404" "Content-Type: text/html" "404 Not Found "
- # move index back
- mv $dir/www/data/tmp.index.html $dir/www/data/index.html
-
- new "WWW get css"
- expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/example.css)" 0 "HTTP/$HVER 200" "Content-Type: text/css" "display: inline;" --not-- "Content-Type: text/html"
+ # move index back
+ mv $dir/www/data/tmp.index.html $dir/www/data/index.html
+
+ new "WWW get css"
+ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/example.css)" 0 "HTTP/$HVER 200" "Content-Type: text/css" "display: inline;" --not-- "Content-Type: text/html"
- new "WWW head"
- expectpart "$(curl $CURLOPTS --head -H 'Accept: text/html' $proto://localhost/data/index.html)" 0 "HTTP/$HVER 200" "Content-Type: text/html" --not-- "Welcome to Clixon! "
+ new "WWW head"
+ expectpart "$(curl $CURLOPTS --head -H 'Accept: text/html' $proto://localhost/data/index.html)" 0 "HTTP/$HVER 200" "Content-Type: text/html" --not-- "Welcome to Clixon! "
- new "WWW options"
- expectpart "$(curl $CURLOPTS -X OPTIONS $proto://localhost/data/index.html)" 0 "HTTP/$HVER 200" "allow: OPTIONS,HEAD,GET"
+ new "WWW options"
+ expectpart "$(curl $CURLOPTS -X OPTIONS $proto://localhost/data/index.html)" 0 "HTTP/$HVER 200" "allow: OPTIONS,HEAD,GET"
- # Remove -i option for binary transfer
- CURLOPTS2=$(echo $CURLOPTS | sed 's/i//')
- new "WWW binary bitmap"
- curl $CURLOPTS2 -X GET $proto://localhost/data/clixon.png -o $dir/foo.png
- cmp $dir/foo.png $dir/www/data/clixon.png
- if [ $? -ne 0 ]; then
- err1 "$dir/foo.png $dir/www/data/example.css should be equal" "Not equal"
- fi
+ # Remove -i option for binary transfer
+ CURLOPTS2=$(echo $CURLOPTS | sed 's/i//')
+ new "WWW binary bitmap"
+ curl $CURLOPTS2 -X GET $proto://localhost/data/clixon.png -o $dir/foo.png
+ cmp $dir/foo.png $dir/www/data/clixon.png
+ if [ $? -ne 0 ]; then
+ err1 "$dir/foo.png $dir/www/data/example.css should be equal" "Not equal"
+ fi
- # negative errors
- new "WWW get http not found"
- expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/notfound.html)" 0 "HTTP/$HVER 404" "Content-Type: text/html" "404 Not Found "
+ # negative errors
+ new "WWW get http not found"
+ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/notfound.html)" 0 "HTTP/$HVER 404" "Content-Type: text/html" "404 Not Found "
- new "WWW get http soft link"
- expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/inside.html)" 0 "HTTP/$HVER 403" "Content-Type: text/html" "403 Forbidden " --not-- "Dont access this "
-
- # Two cases where the privileges test is not run:
- # 1) Docker in alpine for some reason
- # 2) Restconf run explicitly as root (eg coverage)
- if [ ! -f /.dockerenv ] ; then
+ new "WWW get http soft link"
+ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/inside.html)" 0 "HTTP/$HVER 403" "Content-Type: text/html" "403 Forbidden " --not-- "Dont access this "
+
+ # Two cases where the privileges test is not run:
+ # 1) Docker in alpine for some reason
+ # 2) Restconf run explicitly as root (eg coverage)
+ if [ ! -f /.dockerenv ] ; then
if [[ "$clixon_restconf" != *"-r"* ]]; then
- new "WWW get http not read access"
- expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/noread.html)" 0 "HTTP/$HVER 403" "Content-Type: text/html" "403 Forbidden "
+ new "WWW get http not read access"
+ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/noread.html)" 0 "HTTP/$HVER 403" "Content-Type: text/html" "403 Forbidden "
fi
- fi
+ fi
- # Try .. Cannot get .. in path to work in curl (it seems to remove it)
- if [ "$proto" = http -a -n "$netcat" ]; then
- new "WWW get outside using .. netcat"
- expectpart "$(${netcat} 127.0.0.1 80 <405 Method Not Allowed"
+ new "WWW post not allowed"
+ expectpart "$(curl $CURLOPTS -X POST -H 'Accept: text/html' -H "Content-Type: application/yang-data+json" -d '{"ietf-interfaces:interfaces":{"interface":{"name":"eth/0/0","type":"clixon-example:eth","enabled":true}}}' $proto://localhost/data/notfound.html)" 0 "HTTP/$HVER 405" "Content-Type: text/html" "405 Method Not Allowed "
fi
if [ $RC -ne 0 ]; then
- new "Kill restconf daemon"
- stop_restconf
+ new "Kill restconf daemon"
+ stop_restconf
fi
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
@@ -299,8 +299,8 @@ fi
for proto in $protos; do
for enable in true false; do # false
- new "http-data proto:$proto enabled:$enable"
- testrun $proto $enable
+ new "http-data proto:$proto enabled:$enable"
+ testrun $proto $enable
done
done
diff --git a/test/test_identity.sh b/test/test_identity.sh
index 7e07e2ab..bf6134ce 100755
--- a/test/test_identity.sh
+++ b/test/test_identity.sh
@@ -134,7 +134,7 @@ module example-my-crypto {
type string;
}
leaf type {
- type acl-type;
+ type acl-type;
}
}
}
@@ -191,13 +191,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -395,7 +395,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_insert.sh b/test/test_insert.sh
index 462de6af..b0dec0e3 100755
--- a/test/test_insert.sh
+++ b/test/test_insert.sh
@@ -37,10 +37,10 @@ module example {
revision 2019-01-13;
container c{
list a{
- key x;
- leaf x{
- type int32;
- }
+ key x;
+ leaf x{
+ type int32;
+ }
}
}
}
@@ -62,13 +62,13 @@ function testrun(){
r0=$($clixon_util_xml_mod -y $fyang -x "$xi" -b "$x0" -p $xp $OPTS)
# If both are null something is amiss
if [ -z "$r0" -a -z "$rs" ]; then
- err "length of retval is zero"
+ err "length of retval is zero"
fi
# echo "rs:$rs"
# echo "r0:$r0"
# Check they are equal
if [[ "$r0" != "$rs" ]]; then
- err "$rs" "$r0"
+ err "$rs" "$r0"
fi
}
@@ -178,10 +178,10 @@ module example {
}
}
list d{
- key x;
- leaf x{
- type int32;
- }
+ key x;
+ leaf x{
+ type int32;
+ }
ordered-by user;
}
leaf-list e{
diff --git a/test/test_install.sh b/test/test_install.sh
index 0ec82824..80bb8a35 100755
--- a/test/test_install.sh
+++ b/test/test_install.sh
@@ -39,13 +39,13 @@ new "Check installed files libclixon${SUFFIX}"
# This is a problem on some platforms that dont have /usr/local/ in LD_LIBRARY_PATH
if [ ! ${LIBOPT} $dir/usr/local/lib/libclixon${SUFFIX} ]; then
if [ ! ${LIBOPT} $dir/usr/lib/libclixon${SUFFIX} ]; then
- err $dir/usr/local/lib/libclixon${SUFFIX}
+ err $dir/usr/local/lib/libclixon${SUFFIX}
fi
fi
new "Check installed files libclixon_backend${SUFFIX}"
if [ ! ${LIBOPT} $dir/usr/local/lib/libclixon_backend${SUFFIX} ]; then
if [ ! ${LIBOPT} $dir/usr/lib/libclixon_backend${SUFFIX} ]; then
- err $dir/usr/local/lib/libclixon_backend${SUFFIX}
+ err $dir/usr/local/lib/libclixon_backend${SUFFIX}
fi
fi
diff --git a/test/test_instance_id.sh b/test/test_instance_id.sh
index 9e6bbf38..9859becf 100755
--- a/test/test_instance_id.sh
+++ b/test/test_instance_id.sh
@@ -282,7 +282,7 @@ echo -n '' > $xml6
for (( i=0; i<$nr; i++ )); do
echo -n "b$i b$i foo$i " >> $xml6
for (( j=0; j<3; j++ )); do
- echo -n "a$j a$j foo$j " >> $xml6
+ echo -n "a$j a$j foo$j " >> $xml6
done
echo -n " " >> $xml6
done
diff --git a/test/test_json_list.sh b/test/test_json_list.sh
index f2af66e3..2aa3763e 100755
--- a/test/test_json_list.sh
+++ b/test/test_json_list.sh
@@ -18,12 +18,12 @@ module json{
}
list l2{
key name;
- leaf name{
- type int32;
- }
- leaf value{
- type string;
- }
+ leaf name{
+ type int32;
+ }
+ leaf value{
+ type string;
+ }
}
leaf extra{
type string;
diff --git a/test/test_leaf_default.sh b/test/test_leaf_default.sh
index 745c5e1c..e205ee3b 100755
--- a/test/test_leaf_default.sh
+++ b/test/test_leaf_default.sh
@@ -45,12 +45,12 @@ module example{
namespace "urn:example:clixon";
prefix ex;
leaf r1 {
- description "Top level leaf";
+ description "Top level leaf";
type uint32;
default 11; /* should be set */
}
leaf r2 {
- description "Top level leaf";
+ description "Top level leaf";
type uint32;
default 22; /* should be set on startup */
}
@@ -69,13 +69,13 @@ module example{
/* Extra rules to check when condition */
leaf npleaf{
when "../s3 = '99'";
- type uint32;
+ type uint32;
default 98;
}
container npcont{
when "../s3 = '99'";
leaf npext{
- type uint32;
+ type uint32;
default 99;
}
}
@@ -88,8 +88,8 @@ module example{
default 44;
}
container np45{
- description "No presence container";
- leaf s5 {
+ description "No presence container";
+ leaf s5 {
type uint32;
default 45;
}
@@ -97,22 +97,22 @@ module example{
}
container xs-config {
description "Typical contruct where a list element has a default leaf";
- list x {
- key "name";
- leaf name {
- type string;
- }
- container y {
- leaf inside {
- type boolean;
- default false;
- }
+ list x {
+ key "name";
+ leaf name {
+ type string;
}
- leaf outside {
- type boolean;
- default false;
- }
- }
+ container y {
+ leaf inside {
+ type boolean;
+ default false;
+ }
+ }
+ leaf outside {
+ type boolean;
+ default false;
+ }
+ }
}
}
EOF
@@ -126,7 +126,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -168,7 +168,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -187,7 +187,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg"
start_backend -s startup -f $cfg
@@ -210,7 +210,7 @@ moreret=$(diff $dir/running_db <(echo "<${DATASTORE_TOP}>
${DATASTORE_TOP}>"))
if [ $? -ne 0 ]; then
err "<${DATASTORE_TOP}>$SXML${DATASTORE_TOP}>" "$moreret"
-fi
+fi
new "Change default value r2"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "88 " "" " "
@@ -226,14 +226,14 @@ moreret=$(diff $dir/running_db <(echo "<${DATASTORE_TOP}>
${DATASTORE_TOP}>"))
if [ $? -ne 0 ]; then
err "<${DATASTORE_TOP}>$SXML88 ${DATASTORE_TOP}>" "$moreret"
-fi
+fi
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
fi
@@ -248,7 +248,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg"
start_backend -s startup -f $cfg
@@ -265,7 +265,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
fi
@@ -280,7 +280,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg"
start_backend -s startup -f $cfg
@@ -297,7 +297,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
fi
diff --git a/test/test_leafref.sh b/test/test_leafref.sh
index 7e1070e5..b0229a70 100755
--- a/test/test_leafref.sh
+++ b/test/test_leafref.sh
@@ -31,29 +31,29 @@ module example{
namespace "urn:example:clixon";
prefix ex;
import ietf-interfaces {
- prefix if;
+ prefix if;
}
import ietf-ip {
prefix ip;
}
identity eth {
- base if:interface-type;
+ base if:interface-type;
}
identity lo {
- base if:interface-type;
+ base if:interface-type;
}
container default-address {
leaf absname {
description "Absolute references existing interfaces in if module";
type leafref {
path "/if:interfaces/if:interface/if:name";
- require-instance true;
+ require-instance true;
}
}
leaf relname {
type leafref {
path "../../if:interfaces/if:interface/if:name";
- require-instance true;
+ require-instance true;
}
}
leaf address {
@@ -61,14 +61,14 @@ module example{
type leafref {
path "../../if:interfaces/if:interface[if:name = current()/../relname]"
+ "/ip:ipv4/ip:address/ip:ip";
- require-instance true;
+ require-instance true;
}
}
leaf wrong {
description "References leading nowhere in yang";
type leafref {
path "/ip:interfaces/ip:interface/ip:name";
- require-instance true;
+ require-instance true;
}
}
}
@@ -80,7 +80,7 @@ module example{
leaf template{
type leafref{
path "/sender/name";
- require-instance true;
+ require-instance true;
}
}
}
@@ -123,7 +123,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -197,7 +197,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_leafref_augment.sh b/test/test_leafref_augment.sh
index 9afae28a..6feca4d6 100755
--- a/test/test_leafref_augment.sh
+++ b/test/test_leafref_augment.sh
@@ -56,34 +56,34 @@ module leafref{
namespace "urn:example:example";
prefix example;
typedef sender-ref {
- description "For testing leafref across augment and grouping";
- type leafref {
- path "/ex:sender/ex:name";
- require-instance true;
- }
+ description "For testing leafref across augment and grouping";
+ type leafref {
+ path "/ex:sender/ex:name";
+ require-instance true;
+ }
}
typedef sender-ref-local {
- description "For testing leafref local";
- type leafref {
- path "/example:sender/example:name";
- require-instance true;
- }
+ description "For testing leafref local";
+ type leafref {
+ path "/example:sender/example:name";
+ require-instance true;
+ }
}
list sender{
key name;
leaf name{
type string;
}
- container stub{
- description "Here is where augmentation is done";
+ container stub{
+ description "Here is where augmentation is done";
}
leaf ref{
description "top-level ref (wrong prefix)";
- type sender-ref;
+ type sender-ref;
}
leaf ref-local{
description "top-level ref (right prefix)";
- type sender-ref-local;
+ type sender-ref-local;
}
}
}
@@ -96,7 +96,7 @@ module augment{
prefix aug;
import leafref {
description "Note different from canonical (leafref module own prefix is 'example'";
- prefix "ex";
+ prefix "ex";
}
grouping attributes {
container track{
@@ -112,19 +112,19 @@ module augment{
description "reference using path inline in data (not typedef)";
key name;
leaf name{
- type leafref {
- path "/ex:sender/ex:name";
- require-instance true;
- }
+ type leafref {
+ path "/ex:sender/ex:name";
+ require-instance true;
+ }
}
}
}
}
augment "/ex:sender/ex:stub" {
- description "Main leafref/sender stub.";
+ description "Main leafref/sender stub.";
container extra{
- presence "ensuring it is there";
- uses attributes;
+ presence "ensuring it is there";
+ uses attributes;
}
}
}
@@ -137,7 +137,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -251,7 +251,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_leafref_state.sh b/test/test_leafref_state.sh
index c7e9d0c1..5c5f8c12 100755
--- a/test/test_leafref_state.sh
+++ b/test/test_leafref_state.sh
@@ -62,9 +62,9 @@ module leafref{
config false;
key ref;
leaf ref{
- type leafref {
- path "/ex:sender-config/ex:name";
- }
+ type leafref {
+ path "/ex:sender-config/ex:name";
+ }
}
}
}
@@ -88,10 +88,10 @@ module leafref{
config false;
key ref;
leaf ref{
- type leafref {
- path "/ex:sender-config/ex:name";
- require-instance false;
- }
+ type leafref {
+ path "/ex:sender-config/ex:name";
+ require-instance false;
+ }
}
}
}
@@ -111,7 +111,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -sS $fstate"
start_backend -s init -f $cfg -- -sS $fstate
@@ -214,7 +214,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -227,7 +227,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -o CLICON_VALIDATE_STATE_XML=false -- -sS $fstate"
start_backend -s init -f $cfg -o CLICON_YANG_MAIN_FILE=$fyangno -- -sS $fstate
@@ -269,7 +269,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -282,7 +282,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -o CLICON_VALIDATE_STATE_XML=false -- -sS $fstate"
start_backend -s init -f $cfg -o CLICON_VALIDATE_STATE_XML=false -- -sS $fstate
@@ -324,7 +324,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_leafref_union.sh b/test/test_leafref_union.sh
index c2f2c6f7..22325e30 100755
--- a/test/test_leafref_union.sh
+++ b/test/test_leafref_union.sh
@@ -74,10 +74,10 @@ module example{
description "idref union";
type union {
type identityref {
- base crypto;
+ base crypto;
}
type identityref {
- base airplane;
+ base airplane;
}
}
}
@@ -85,7 +85,7 @@ module example{
description "Union mix of idref and leafref";
type union {
type identityref {
- base crypto;
+ base crypto;
}
type leafref {
path "../x";
@@ -103,7 +103,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -174,7 +174,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_leafref_uses_augment.sh b/test/test_leafref_uses_augment.sh
index bc11b24f..9101a1a4 100755
--- a/test/test_leafref_uses_augment.sh
+++ b/test/test_leafref_uses_augment.sh
@@ -108,13 +108,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
new "cli set t1-con t1-con t1-a 123"
@@ -155,7 +155,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_minmax.sh b/test/test_minmax.sh
index 387a0f38..01356210 100755
--- a/test/test_minmax.sh
+++ b/test/test_minmax.sh
@@ -106,12 +106,12 @@ module $APPNAME{
}
container b2c {
leaf-list b2ll{
- min-elements 1;
- type string;
+ min-elements 1;
+ type string;
}
}
leaf-list b3ll{
- type string;
+ type string;
}
}
}
@@ -124,7 +124,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
# start new backend
@@ -295,7 +295,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_nacm.sh b/test/test_nacm.sh
index 963a5cd0..869d4645 100755
--- a/test/test_nacm.sh
+++ b/test/test_nacm.sh
@@ -45,7 +45,7 @@ module nacm-example{
namespace "urn:example:nacm";
prefix nex;
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
leaf x{
type int32;
@@ -117,13 +117,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -192,7 +192,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_nacm_credentials.sh b/test/test_nacm_credentials.sh
index 937adc69..45f6ccf4 100755
--- a/test/test_nacm_credentials.sh
+++ b/test/test_nacm_credentials.sh
@@ -27,7 +27,7 @@ module nacm-example{
namespace "urn:example:nacm";
prefix nex;
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
leaf x{
type int32;
@@ -126,16 +126,16 @@ EOF
new "test params: -f $cfg"
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s init -f $cfg"
- start_backend -s init -f $cfg
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s init -f $cfg"
+ start_backend -s init -f $cfg
fi
- new "waiting"
+ new "wait backend"
wait_backend
# First push in nacm rules via regular means
@@ -150,23 +150,23 @@ EOF
# raw socket test
if [ -n "$username" ]; then
- XML=" "
+ XML=" "
else
- XML=" "
+ XML=" "
fi
new "get-config mode:$mode user:$username $family $precmd"
expecteof_netconf "$precmd $clixon_util_socket -a $family -s $sock -D $DBG" 0 "" "$XML" "$ex"
if [ $BE -ne 0 ]; then # Bring your own backend
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
} # testrun
diff --git a/test/test_nacm_datanode.sh b/test/test_nacm_datanode.sh
index 4ff4d6e8..5e5e066d 100755
--- a/test/test_nacm_datanode.sh
+++ b/test/test_nacm_datanode.sh
@@ -76,10 +76,10 @@ module nacm-example{
namespace "http://example.com/ns/netconf";
prefix ex;
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
import itf {
- prefix acme;
+ prefix acme;
}
container acme-netconf{
container config-parameters{
@@ -220,13 +220,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -324,7 +324,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_nacm_datanode_paths.sh b/test/test_nacm_datanode_paths.sh
index f64f0595..1947f3bf 100755
--- a/test/test_nacm_datanode_paths.sh
+++ b/test/test_nacm_datanode_paths.sh
@@ -94,13 +94,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg"
start_backend -s startup -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -160,7 +160,7 @@ if [ $BE -ne 0 ]; then # Bring your own backend
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_nacm_datanode_read.sh b/test/test_nacm_datanode_read.sh
index 002e672c..5131b6e4 100755
--- a/test/test_nacm_datanode_read.sh
+++ b/test/test_nacm_datanode_read.sh
@@ -206,9 +206,9 @@ function testrun(){
new "get table"
if $test3; then
- expectpart "$(curl -u wilma:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/nacm-example:table?depth=1)" 0 "HTTP/$HVER 200" '{"nacm-example:table":{}}'
+ expectpart "$(curl -u wilma:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/nacm-example:table?depth=1)" 0 "HTTP/$HVER 200" '{"nacm-example:table":{}}'
else
- expectpart "$(curl -u wilma:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/nacm-example:table?depth=1)" 0 "HTTP/$HVER 404" '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"invalid-value","error-severity":"error","error-message":"Instance does not exist"}}}'
+ expectpart "$(curl -u wilma:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/nacm-example:table?depth=1)" 0 "HTTP/$HVER 404" '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"invalid-value","error-severity":"error","error-message":"Instance does not exist"}}}'
fi
new "get parameter"
if $test4; then
@@ -225,13 +225,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -291,7 +291,7 @@ if [ $BE -ne 0 ]; then # Bring your own backend
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_nacm_datanode_write.sh b/test/test_nacm_datanode_write.sh
index be66222b..50228097 100755
--- a/test/test_nacm_datanode_write.sh
+++ b/test/test_nacm_datanode_write.sh
@@ -188,29 +188,29 @@ function testrun(){
if $testu; then
expectpart "$(curl -u wilma:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" $RCPROTO://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b -d '{"nacm-example:parameter":[{"name":"b","value":"92"}]}')" 0 "HTTP/$HVER 204"
else
- expectpart "$(curl -u wilma:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" $RCPROTO://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b -d '{"nacm-example:parameter":[{"name":"b","value":"92"}]}')" 0 "HTTP/$HVER 403"
- # '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"access denied"}}}'
+ expectpart "$(curl -u wilma:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" $RCPROTO://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b -d '{"nacm-example:parameter":[{"name":"b","value":"92"}]}')" 0 "HTTP/$HVER 403"
+ # '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"access denied"}}}'
fi
new "delete object b"
if $testd; then
expectpart "$(curl -u wilma:bar $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b)" 0 "HTTP/$HVER 204"
else # XXX can vara olika
- ret=$(curl -u wilma:bar $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b)
- r=$?
- if [ $r != 0 ]; then
- err "retval: $r" "0"
- fi
- match1=$(echo "$ret" | grep --null -o "HTTP/$HVER 403")
- r1=$?
- match2=$(echo "$ret" | grep --null -o "HTTP/$HVER 409")
- r2=$?
- if [ $r1 != 0 -a $r2 != 0 ]; then
- err "\"HTTP/$HVER 403\" or \"HTTP/$HVER 409\"" "$ret"
- fi
- # Ensure delete
- new "ensure delete object b"
- expectpart "$(curl -u andy:bar $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b)" 0 "HTTP/$HVER" # ignore error
+ ret=$(curl -u wilma:bar $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b)
+ r=$?
+ if [ $r != 0 ]; then
+ err "retval: $r" "0"
+ fi
+ match1=$(echo "$ret" | grep --null -o "HTTP/$HVER 403")
+ r1=$?
+ match2=$(echo "$ret" | grep --null -o "HTTP/$HVER 409")
+ r2=$?
+ if [ $r1 != 0 -a $r2 != 0 ]; then
+ err "\"HTTP/$HVER 403\" or \"HTTP/$HVER 409\"" "$ret"
+ fi
+ # Ensure delete
+ new "ensure delete object b"
+ expectpart "$(curl -u andy:bar $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b)" 0 "HTTP/$HVER" # ignore error
fi
} # testrun
@@ -221,13 +221,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -289,7 +289,7 @@ if [ $BE -ne 0 ]; then # Bring your own backend
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_nacm_default.sh b/test/test_nacm_default.sh
index d8caef00..220ad6a4 100755
--- a/test/test_nacm_default.sh
+++ b/test/test_nacm_default.sh
@@ -44,7 +44,7 @@ module nacm-example{
namespace "urn:example:nacm";
prefix nex;
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
leaf x{
type int32;
@@ -74,13 +74,13 @@ function testrun(){
db=$8
NACM=$(cat <
- ${enablenacm}
- ${readdefault}
- ${writedefault}
- ${execdefault}
- true
-
+
+ ${enablenacm}
+ ${readdefault}
+ ${writedefault}
+ ${execdefault}
+ true
+
EOF
)
# Initial data
@@ -88,28 +88,28 @@ EOF
# Use startup or set values with POST (below)
if [ $db = startup ]; then
- sudo echo "<${DATASTORE_TOP}>$NACM$XML${DATASTORE_TOP}>" > $dir/startup_db
+ sudo echo "<${DATASTORE_TOP}>$NACM$XML${DATASTORE_TOP}>" > $dir/startup_db
fi
if [ $BE -ne 0 ]; then # Bring your own backend
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s $db -f $cfg"
- start_backend -s $db -f $cfg
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s $db -f $cfg"
+ start_backend -s $db -f $cfg
fi
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then # Bring your own restconf
- new "kill old restconf daemon"
- stop_restconf_pre
+ new "kill old restconf daemon"
+ stop_restconf_pre
- new "start restconf daemon"
- start_restconf -f $cfg
+ new "start restconf daemon"
+ start_restconf -f $cfg
fi
new "wait restconf"
@@ -118,27 +118,27 @@ EOF
# Use POST (instead of startup)
# Note this only works because CLICON_NACM_DISABLED_ON_EMPTY is true
if [ $db = init ]; then
- # Must set NACM first
- new "Set NACM using PATCH"
- expectpart "$(curl -u guest:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+xml" -d "$NACM$XML " $RCPROTO://localhost/restconf/data)" 0 "HTTP/$HVER 201"
+ # Must set NACM first
+ new "Set NACM using PATCH"
+ expectpart "$(curl -u guest:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+xml" -d "$NACM$XML " $RCPROTO://localhost/restconf/data)" 0 "HTTP/$HVER 201"
-# new "Set Initial data using POST"
-# expectpart "$(curl -u guest:bar $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" -d "$XML" $RCPROTO://localhost/restconf/data)" 0 "HTTP/$HVER 201"
-
+# new "Set Initial data using POST"
+# expectpart "$(curl -u guest:bar $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" -d "$XML" $RCPROTO://localhost/restconf/data)" 0 "HTTP/$HVER 201"
+
fi
#----------- First get
case "$ret1" in
- 0) ret='{"nacm-example:x":42}'
- status="HTTP/$HVER 200"
- ;;
- 1) ret='{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"default deny"}}}'
- status="HTTP/$HVER 403"
- ;;
- 2) ret='{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"invalid-value","error-severity":"error","error-message":"Instance does not exist"}}}'
- status="HTTP/$HVER 404"
- ;;
+ 0) ret='{"nacm-example:x":42}'
+ status="HTTP/$HVER 200"
+ ;;
+ 1) ret='{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"default deny"}}}'
+ status="HTTP/$HVER 403"
+ ;;
+ 2) ret='{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"invalid-value","error-severity":"error","error-message":"Instance does not exist"}}}'
+ status="HTTP/$HVER 404"
+ ;;
esac
new "get startup 42"
@@ -146,30 +146,30 @@ EOF
#----------- Then edit
case "$ret2" in
- 0) ret=''
- status="HTTP/$HVER 204"
- ;;
- 1) ret='{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"default deny"}}}'
- status="HTTP/$HVER 403"
- ;;
+ 0) ret=''
+ status="HTTP/$HVER 204"
+ ;;
+ 1) ret='{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"default deny"}}}'
+ status="HTTP/$HVER 403"
+ ;;
esac
new "edit new 99"
expectpart "$(curl -u guest:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" -d '{"nacm-example:x": 99}' $RCPROTO://localhost/restconf/data/nacm-example:x)" 0 "$status" "$ret"
#----------- Then second get
case "$ret3" in
- 0) ret='{"nacm-example:x":99}'
- status="HTTP/$HVER 200"
- ;;
- 1) ret='{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"default deny"}}}'
- status="HTTP/$HVER 403"
+ 0) ret='{"nacm-example:x":99}'
+ status="HTTP/$HVER 200"
;;
- 2) ret='{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"invalid-value","error-severity":"error","error-message":"Instance does not exist"}}}'
- status="HTTP/$HVER 404"
- ;;
- 3) ret='{"nacm-example:x":42}'
- status="HTTP/$HVER 200"
- ;;
+ 1) ret='{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"default deny"}}}'
+ status="HTTP/$HVER 403"
+ ;;
+ 2) ret='{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"invalid-value","error-severity":"error","error-message":"Instance does not exist"}}}'
+ status="HTTP/$HVER 404"
+ ;;
+ 3) ret='{"nacm-example:x":42}'
+ status="HTTP/$HVER 200"
+ ;;
esac
new "get 99"
@@ -178,19 +178,19 @@ EOF
sleep $DEMSLEEP
if [ $RC -ne 0 ]; then # Bring your own restconf
- new "Kill restconf daemon"
- stop_restconf
+ new "Kill restconf daemon"
+ stop_restconf
fi
if [ $BE -ne 0 ]; then # Bring your own backend
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
} # testrun
diff --git a/test/test_nacm_ext.sh b/test/test_nacm_ext.sh
index 470b8a2f..14c781f4 100755
--- a/test/test_nacm_ext.sh
+++ b/test/test_nacm_ext.sh
@@ -48,28 +48,28 @@ module nacm-example{
namespace "urn:example:nacm";
prefix nacm;
import clixon-example {
- prefix ex;
+ prefix ex;
}
container authentication {
presence "To keep this from auto-expanding";
description "Example code for enabling www basic auth and some example
users";
leaf basic_auth{
- description "Basic user / password authentication as in HTTP basic auth";
- type boolean;
- default true;
+ description "Basic user / password authentication as in HTTP basic auth";
+ type boolean;
+ default true;
}
list auth {
- description "user / password entries. Valid if basic_auth=true";
- key user;
- leaf user{
- description "User name";
- type string;
- }
- leaf password{
- description "Password";
- type string;
- }
+ description "user / password entries. Valid if basic_auth=true";
+ key user;
+ leaf user{
+ description "User name";
+ type string;
+ }
+ leaf password{
+ description "Password";
+ type string;
+ }
}
}
leaf x{
@@ -93,31 +93,31 @@ module clixon-example{
}
}
rpc example {
- description "Some example input/output for testing RFC7950 7.14.
+ description "Some example input/output for testing RFC7950 7.14.
RPC simply echoes the input for debugging.";
- input {
- leaf x {
- description
- "If a leaf in the input tree has a 'mandatory' statement with
+ input {
+ leaf x {
+ description
+ "If a leaf in the input tree has a 'mandatory' statement with
the value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- mandatory true;
- }
- leaf y {
- description
+ type string;
+ mandatory true;
+ }
+ leaf y {
+ description
"If a leaf in the input tree has a 'mandatory' statement with the
value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- default "42";
- }
+ type string;
+ default "42";
+ }
}
output {
- leaf x {
- type string;
- }
- leaf y {
- type string;
- }
+ leaf x {
+ type string;
+ }
+ leaf y {
+ type string;
+ }
}
}
}
@@ -183,7 +183,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend -zf $cfg "
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sleep 1
new "start backend -s init -f $cfg -- -s"
@@ -191,7 +191,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg -- -s
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -266,7 +266,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_nacm_module_read.sh b/test/test_nacm_module_read.sh
index 334f4a8f..4b37a13e 100755
--- a/test/test_nacm_module_read.sh
+++ b/test/test_nacm_module_read.sh
@@ -48,10 +48,10 @@ module nacm-example{
namespace "urn:example:nacm";
prefix nex;
import clixon-example {
- prefix ex;
+ prefix ex;
}
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
leaf x{
type int32;
@@ -66,14 +66,14 @@ module clixon-example{
namespace "urn:example:clixon";
prefix ex;
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
}
}
/* State data (not config) for the example application*/
@@ -85,31 +85,31 @@ module clixon-example{
}
}
rpc example {
- description "Some example input/output for testing RFC7950 7.14.
+ description "Some example input/output for testing RFC7950 7.14.
RPC simply echoes the input for debugging.";
- input {
- leaf x {
- description
- "If a leaf in the input tree has a 'mandatory' statement with
+ input {
+ leaf x {
+ description
+ "If a leaf in the input tree has a 'mandatory' statement with
the value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- mandatory true;
- }
- leaf y {
- description
+ type string;
+ mandatory true;
+ }
+ leaf y {
+ description
"If a leaf in the input tree has a 'mandatory' statement with the
value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- default "42";
- }
+ type string;
+ default "42";
+ }
}
output {
- leaf x {
- type string;
- }
- leaf y {
- type string;
- }
+ leaf x {
+ type string;
+ }
+ leaf y {
+ type string;
+ }
}
}
}
@@ -178,13 +178,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -s"
start_backend -s init -f $cfg -- -s
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -318,7 +318,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_nacm_module_write.sh b/test/test_nacm_module_write.sh
index 3fb8832a..bd8d51d0 100755
--- a/test/test_nacm_module_write.sh
+++ b/test/test_nacm_module_write.sh
@@ -61,10 +61,10 @@ module nacm-example{
namespace "urn:example:nacm";
prefix nex;
import clixon-example {
- prefix ex;
+ prefix ex;
}
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
leaf x{
type int32;
@@ -90,14 +90,14 @@ module clixon-example{
namespace "urn:example:clixon";
prefix ex;
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
}
}
/* State data (not config) for the example application*/
@@ -169,7 +169,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -293,7 +293,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_nacm_protocol.sh b/test/test_nacm_protocol.sh
index f37d911f..3fbe5fc9 100755
--- a/test/test_nacm_protocol.sh
+++ b/test/test_nacm_protocol.sh
@@ -64,7 +64,7 @@ module nacm-example{
namespace "urn:example:nacm";
prefix nex;
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
leaf x{
type int32;
@@ -138,14 +138,14 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -228,7 +228,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_nacm_recovery.sh b/test/test_nacm_recovery.sh
index c8c242ba..b5274618 100755
--- a/test/test_nacm_recovery.sh
+++ b/test/test_nacm_recovery.sh
@@ -29,7 +29,7 @@ module nacm-example{
namespace "urn:example:nacm";
prefix nex;
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
leaf x{
type int32;
@@ -61,9 +61,9 @@ function testrun()
putp=$6
if [ "$realuser" = "root" ]; then
- prefix="sudo "
+ prefix="sudo "
else
- prefix=""
+ prefix=""
fi
cat < $cfg
@@ -87,62 +87,62 @@ cat < $cfg
EOF
if [ $BE -ne 0 ]; then
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s init -f $cfg"
- start_backend -s init -f $cfg
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s init -f $cfg"
+ start_backend -s init -f $cfg
fi
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
- new "kill old restconf daemon"
- stop_restconf_pre
+ new "kill old restconf daemon"
+ stop_restconf_pre
- new "start restconf daemon"
- start_restconf -f $cfg
+ new "start restconf daemon"
+ start_restconf -f $cfg
fi
new "wait restconf"
wait_restconf
if $getp; then
- # default is read allowed so this should always succeed.
- new "get startup default ok"
- expecteof_netconf "$prefix$clixon_netconf -qf $cfg -U $pseudo" 0 "$DEFAULTHELLO" " " "" "$DEFAULT "
- # This would normally not work except in recovery situations
+ # default is read allowed so this should always succeed.
+ new "get startup default ok"
+ expecteof_netconf "$prefix$clixon_netconf -qf $cfg -U $pseudo" 0 "$DEFAULTHELLO" " " "" "$DEFAULT "
+ # This would normally not work except in recovery situations
else
- new "get startup not ok"
- expecteof_netconf "$prefix$clixon_netconf -qf $cfg -U $pseudo" 0 "$DEFAULTHELLO" " " "" "application access-denied error User $realuser credential not matching NACM user $pseudo "
+ new "get startup not ok"
+ expecteof_netconf "$prefix$clixon_netconf -qf $cfg -U $pseudo" 0 "$DEFAULTHELLO" " " "" "application access-denied error User $realuser credential not matching NACM user $pseudo "
fi
-
+
if $putp; then
- new "put, expect ok"
- expecteof_netconf "$prefix$clixon_netconf -qf $cfg -U $pseudo" 0 "$DEFAULTHELLO" "$RULES " "" " "
+ new "put, expect ok"
+ expecteof_netconf "$prefix$clixon_netconf -qf $cfg -U $pseudo" 0 "$DEFAULTHELLO" "$RULES " "" " "
- new "get rules ok"
- expecteof_netconf "$prefix$clixon_netconf -qf $cfg -U $pseudo" 0 "$DEFAULTHELLO" " " "" "$RULES "
+ new "get rules ok"
+ expecteof_netconf "$prefix$clixon_netconf -qf $cfg -U $pseudo" 0 "$DEFAULTHELLO" " " "" "$RULES "
else
- new "put, expect fail"
- expecteof_netconf "$prefix$clixon_netconf -qf $cfg -U $pseudo" 0 "$DEFAULTHELLO" "$RULES " "application access-denied error " "" # default deny "
+ new "put, expect fail"
+ expecteof_netconf "$prefix$clixon_netconf -qf $cfg -U $pseudo" 0 "$DEFAULTHELLO" "$RULES " "application access-denied error " "" # default deny "
fi
if [ $RC -ne 0 ]; then
- new "Kill restconf daemon"
- stop_restconf
+ new "Kill restconf daemon"
+ stop_restconf
fi
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
diff --git a/test/test_netconf.sh b/test/test_netconf.sh
index 7c2c2f10..bb57fd3f 100755
--- a/test/test_netconf.sh
+++ b/test/test_netconf.sh
@@ -19,11 +19,12 @@ cat < $cfg
$cfg
ietf-netconf:startup
+ ietf-netconf:confirmed-commit
42
$dir
${YANG_INSTALLDIR}
$IETFRFC
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/clispec
/usr/local/lib/$APPNAME/backend
example_backend.so$
@@ -44,90 +45,90 @@ module clixon-example{
namespace "urn:example:clixon";
prefix ex;
import ietf-interfaces {
- prefix if;
+ prefix if;
}
import ietf-ip {
- prefix ip;
+ prefix ip;
}
/* Example interface type for tests, local callbacks, etc */
identity eth {
- base if:interface-type;
+ base if:interface-type;
}
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ }
}
/* State data (not config) for the example application*/
container state {
- config false;
- description "state data for the example application (must be here for example get operation)";
- leaf-list op {
+ config false;
+ description "state data for the example application (must be here for example get operation)";
+ leaf-list op {
type string;
- }
+ }
}
augment "/if:interfaces/if:interface" {
- container my-status {
- config false;
- description "For testing augment+state";
- leaf int {
- type int32;
- }
- leaf str {
- type string;
- }
- }
+ container my-status {
+ config false;
+ description "For testing augment+state";
+ leaf int {
+ type int32;
+ }
+ leaf str {
+ type string;
+ }
+ }
}
rpc client-rpc {
- description "Example local client-side RPC that is processed by the
+ description "Example local client-side RPC that is processed by the
the netconf/restconf and not sent to the backend.
This is a clixon implementation detail: some rpc:s
are better processed by the client for API or perf reasons";
- input {
- leaf x {
- type string;
- }
- }
- output {
- leaf x {
- type string;
- }
- }
+ input {
+ leaf x {
+ type string;
+ }
+ }
+ output {
+ leaf x {
+ type string;
+ }
+ }
}
rpc empty {
- description "Smallest possible RPC with no input or output sections";
+ description "Smallest possible RPC with no input or output sections";
}
rpc example {
- description "Some example input/output for testing RFC7950 7.14.
+ description "Some example input/output for testing RFC7950 7.14.
RPC simply echoes the input for debugging.";
- input {
- leaf x {
- description
- "If a leaf in the input tree has a 'mandatory' statement with
+ input {
+ leaf x {
+ description
+ "If a leaf in the input tree has a 'mandatory' statement with
the value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- mandatory true;
- }
- leaf y {
- description
- "If a leaf in the input tree has a 'mandatory' statement with the
+ type string;
+ mandatory true;
+ }
+ leaf y {
+ description
+ "If a leaf in the input tree has a 'mandatory' statement with the
value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- default "42";
- }
- }
- output {
- leaf x {
- type string;
- }
- leaf y {
- type string;
- }
- }
+ type string;
+ default "42";
+ }
+ }
+ output {
+ leaf x {
+ type string;
+ }
+ leaf y {
+ type string;
+ }
+ }
}
}
@@ -140,7 +141,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -s"
start_backend -s init -f $cfg -- -s
@@ -356,6 +357,30 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "
new "kill-session using prefix xx"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "44 " "" " "
+new "asynchronous lock running"
+sleep 60 | cat <(echo "$HELLONO11 ]]>]]>") -| $clixon_netconf -qf $cfg >> /dev/null &
+
+PIDS=($(jobs -l % | cut -c 6- | awk '{print $1}'))
+
+new "try commit should fail"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "protocol in-use error Operation failed, lock is already held "
+
+new "soft kill ${PIDS[0]}"
+kill ${PIDS[0]} # kill the while loop above to close STDIN on 1st
+
+new "asynchronous confirmed commit"
+sleep 60 | cat <(echo "$HELLONO1160 ]]>]]>") -| $clixon_netconf -qf $cfg >> /dev/null &
+PIDS=($(jobs -l % | cut -c 6- | awk '{print $1}'))
+
+new "try lock should fail"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "protocol lock-denied [0-9]* error Operation failed, another session has an ongoing confirmed commit "
+
+new "soft kill ${PIDS[0]}"
+kill ${PIDS[0]} # kill the while loop above to close STDIN on 1st
+
+new "netconf discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
# modify candidate, then lock, should fail.
new "netconf edit config"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
@@ -414,7 +439,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_netconf_filter.sh b/test/test_netconf_filter.sh
index 05346d1b..71cf0683 100755
--- a/test/test_netconf_filter.sh
+++ b/test/test_netconf_filter.sh
@@ -50,13 +50,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
new "Add two entries"
@@ -118,7 +118,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_netconf_framing.sh b/test/test_netconf_framing.sh
index ddec9ad2..24eee756 100755
--- a/test/test_netconf_framing.sh
+++ b/test/test_netconf_framing.sh
@@ -18,7 +18,7 @@ cat < $cfg
ietf-netconf:startup
42
${YANG_INSTALLDIR}
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/clispec
/usr/local/lib/$APPNAME/backend
example_backend.so$
@@ -42,13 +42,13 @@ module clixon-example{
/* Generic config data */
container table{
list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
}
}
}
@@ -61,7 +61,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -s"
start_backend -s init -f $cfg -- -s
@@ -102,7 +102,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_netconf_hello.sh b/test/test_netconf_hello.sh
index 93e81177..545eba4b 100755
--- a/test/test_netconf_hello.sh
+++ b/test/test_netconf_hello.sh
@@ -21,7 +21,7 @@ cat < $cfg
ietf-netconf:startup
42
${YANG_INSTALLDIR}
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/clispec
/usr/local/lib/$APPNAME/backend
example_backend.so$
@@ -52,7 +52,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -s"
start_backend -s init -f $cfg -- -s
@@ -106,7 +106,15 @@ new "Netconf snd hello with prefix"
expecteof "$clixon_netconf -qef $cfg" 0 "urn:ietf:params:netconf:base:1.1 ]]>]]>" '^$'
new "netconf snd + rcv hello"
-expecteof "$clixon_netconf -f $cfg" 0 "urn:ietf:params:netconf:base:1.1 ]]>]]>" "^urn:ietf:params:netconf:base:1.1 urn:ietf:params:netconf:base:1.0 urn:ietf:params:netconf:capability:yang-library:1.0?revision=2019-01-04&module-set-id=42 urn:ietf:params:netconf:capability:candidate:1.0 urn:ietf:params:netconf:capability:validate:1.1 urn:ietf:params:netconf:capability:startup:1.0 urn:ietf:params:netconf:capability:xpath:1.0 urn:ietf:params:netconf:capability:notification:1.0 urn:ietf:params:netconf:capability:with-defaults:1.0?basic-mode=explicit&also-supported=report-all,trim,report-all-tagged [0-9]* ]]>]]>$" '^$'
+expecteof "$clixon_netconf -f $cfg" 0 "urn:ietf:params:netconf:base:1.1 ]]>]]>" "^urn:ietf:params:netconf:base:1.1 urn:ietf:params:netconf:base:1.0
+urn:ietf:params:netconf:capability:yang-library:1.0?revision=2019-01-04&module-set-id=42
+urn:ietf:params:netconf:capability:candidate:1.0
+urn:ietf:params:netconf:capability:validate:1.1
+urn:ietf:params:netconf:capability:xpath:1.0
+urn:ietf:params:netconf:capability:notification:1.0
+urn:ietf:params:netconf:capability:startup:1.0
+urn:ietf:params:netconf:capability:with-defaults:1.0?basic-mode=explicit&also-supported=report-all,trim,report-all-tagged
+[0-9]* ]]>]]>$" '^$'
# Actually non-standard to reply on wrong hello with rpc-error, but may be useful
new "Netconf snd hello with extra element"
@@ -124,7 +132,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_netconf_notifications.sh b/test/test_netconf_notifications.sh
index 84c4c61c..3cda86cf 100755
--- a/test/test_netconf_notifications.sh
+++ b/test/test_netconf_notifications.sh
@@ -95,13 +95,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -n"
start_backend -s init -f $cfg -- -n # create example notification stream
fi
-new "waiting"
+new "wait backend"
wait_backend
#
@@ -139,7 +139,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_netconf_ssh_callhome.sh b/test/test_netconf_ssh_callhome.sh
index 32a05415..9d916a0b 100755
--- a/test/test_netconf_ssh_callhome.sh
+++ b/test/test_netconf_ssh_callhome.sh
@@ -39,7 +39,7 @@ cat < $cfg
$cfg
42
${YANG_INSTALLDIR}
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/clispec
/usr/local/lib/$APPNAME/backend
example_backend.so$
@@ -97,7 +97,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -134,7 +134,7 @@ EOF
new "Start Listener client"
echo "ssh -s -F $sshcfg -v -i $key -o ProxyUseFdpass=yes -o ProxyCommand=\"clixon_netconf_ssh_callhome_client -a 127.0.0.1\" . netconf"
#-F $sshcfg
-expectpart "$(ssh -s -F $sshcfg -v -i $key -o ProxyUseFdpass=yes -o ProxyCommand="${clixon_netconf_ssh_callhome_client} -a 127.0.0.1" . netconf < $rpccmd)" 0 "urn:ietf:params:netconf:base:1.1 urn:ietf:params:netconf:base:1.0 urn:ietf:params:netconf:capability:yang-library:1.0?revision=2019-01-04&module-set-id=42 urn:ietf:params:netconf:capability:candidate:1.0 urn:ietf:params:netconf:capability:validate:1.1 urn:ietf:params:netconf:capability:startup:1.0 urn:ietf:params:netconf:capability:xpath:1.0 urn:ietf:params:netconf:capability:notification:1.0 urn:ietf:params:netconf:capability:with-defaults:1.0?basic-mode=explicit&also-supported=report-all,trim,report-all-tagged 2 " " "
+expectpart "$(ssh -s -F $sshcfg -v -i $key -o ProxyUseFdpass=yes -o ProxyCommand="${clixon_netconf_ssh_callhome_client} -a 127.0.0.1" . netconf < $rpccmd)" 0 "urn:ietf:params:netconf:base:1.1 urn:ietf:params:netconf:base:1.0 urn:ietf:params:netconf:capability:yang-library:1.0?revision=2019-01-04&module-set-id=42 urn:ietf:params:netconf:capability:candidate:1.0 urn:ietf:params:netconf:capability:validate:1.1 urn:ietf:params:netconf:capability:xpath:1.0 urn:ietf:params:netconf:capability:with-defaults:1.0?basic-mode=explicit&also-supported=report-all,trim,report-all-tagged urn:ietf:params:netconf:capability:notification:1.0 2 " " "
# Wait
wait
@@ -144,7 +144,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_netconf_whitespace.sh b/test/test_netconf_whitespace.sh
index 76793223..b4fe2843 100755
--- a/test/test_netconf_whitespace.sh
+++ b/test/test_netconf_whitespace.sh
@@ -50,7 +50,7 @@ module whitespace{
type string;
}
container b{
- presence true;
+ presence true;
}
}
}
@@ -67,13 +67,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg -s startup
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg"
start_backend -s startup -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
new "get startup"
@@ -143,7 +143,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_openconfig.sh b/test/test_openconfig.sh
index 4b6f7ee8..3eb8f397 100755
--- a/test/test_openconfig.sh
+++ b/test/test_openconfig.sh
@@ -37,28 +37,28 @@ for f in $files; do
let m=0; # Nr of modules
let s=0; # Nr of modules
if [ -n "$(head -15 $f|grep '^[ ]*module')" ]; then
- let m++;
- let ms++;
+ let m++;
+ let ms++;
elif [ -n "$(head -15 $f|grep '^[ ]*submodule')" ]; then
- let s++;
- let ss++;
+ let s++;
+ let ss++;
else
- echo "No module or submodule found $f"
- exit
+ echo "No module or submodule found $f"
+ exit
fi
if [ $m -eq 1 -a $s -eq 1 ]; then
- echo "Double match $f"
- exit
+ echo "Double match $f"
+ exit
fi
done
new "Openconfig test: $clixon_cli -1f $cfg show version ($m modules)"
for f in $files; do
if [ -n "$(head -1 $f|grep '^module')" ]; then
- modname=$(basename $f | awk -F "." '{print $1}')
- # Generate autocli for these modules
- AUTOCLI=$(autocli_config $modname kw-nokey false)
-
+ modname=$(basename $f | awk -F "." '{print $1}')
+ # Generate autocli for these modules
+ AUTOCLI=$(autocli_config $modname kw-nokey false)
+
cat < $cfg
$cfg
@@ -76,8 +76,8 @@ cat < $cfg
EOF
- new "$clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_FILE=$f show version"
- expectpart "$($clixon_cli -D $DBG -1f $cfg -y $f show version)" 0 "${CLIXON_VERSION}"
+ new "$clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_FILE=$f show version"
+ expectpart "$($clixon_cli -D $DBG -1f $cfg -y $f show version)" 0 "${CLIXON_VERSION}"
fi
done
diff --git a/test/test_openconfig_interfaces.sh b/test/test_openconfig_interfaces.sh
index c15d1eed..9daaa50e 100755
--- a/test/test_openconfig_interfaces.sh
+++ b/test/test_openconfig_interfaces.sh
@@ -30,7 +30,7 @@ cat < $cfg
${YANG_INSTALLDIR}
$IETFRFC
$OCDIR
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/clispec
/usr/local/lib/$APPNAME/cli
$APPNAME
@@ -89,7 +89,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -111,18 +111,18 @@ expectpart "$($clixon_cli -1 -f $cfg show conf xml)" 0 "^ complete: e"
-#expectpart "$(echo "set interfaces interface " | $clixon_cli -f $cfg)" 0 "interface e"
+#expectpart "$(echo "set interfaces interface " | $clixon_cli -f $cfg)" 0 "interface e"
# XXX See https://github.com/clicon/clixon/issues/218
#new "cli set interfaces interface e complete: not ethernet"
-#expectpart "$(echo "set interfaces interface e " | $clixon_cli -f $cfg)" 0 config hold-time subinterfaces --not-- ethernet
+#expectpart "$(echo "set interfaces interface e " | $clixon_cli -f $cfg)" 0 config hold-time subinterfaces --not-- ethernet
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -173,7 +173,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -192,7 +192,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_openconfig_network_instance.sh b/test/test_openconfig_network_instance.sh
index e09694f4..8ff11489 100755
--- a/test/test_openconfig_network_instance.sh
+++ b/test/test_openconfig_network_instance.sh
@@ -27,7 +27,7 @@ cat < $cfg
${YANG_INSTALLDIR}
$IETFRFC
$OCDIR
- $fyang
+ $fyang
$dir
/usr/local/lib/$APPNAME/cli
$APPNAME
@@ -112,7 +112,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -140,7 +140,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_order.sh b/test/test_order.sh
index 71bb12ff..362e7d91 100755
--- a/test/test_order.sh
+++ b/test/test_order.sh
@@ -202,7 +202,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend"
start_backend -s running -f $cfg -- -s
@@ -304,14 +304,14 @@ expecteof_netconf "$clixon_netconf -qef $cfg" 0 "$DEFAULTHELLO" "
+ type=$s$t
+ new "put leaf-list $type (10,2,1)"
+ expecteof_netconf "$clixon_netconf -qef $cfg" 0 "$DEFAULTHELLO" "
10 2 1
" "" " "
- new "check leaf-list $type order (1,2,10)"
- expecteof_netconf "$clixon_netconf -qef $cfg" 0 "$DEFAULTHELLO" " " "" "1 2 10 "
+ new "check leaf-list $type order (1,2,10)"
+ expecteof_netconf "$clixon_netconf -qef $cfg" 0 "$DEFAULTHELLO" " " "" "1 2 10 "
done
done
@@ -449,7 +449,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_pagination_config.sh b/test/test_pagination_config.sh
index 0234de5c..0c33b605 100755
--- a/test/test_pagination_config.sh
+++ b/test/test_pagination_config.sh
@@ -147,7 +147,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -170,7 +170,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_pagination_draft.sh b/test/test_pagination_draft.sh
index e612bfd3..ba18114a 100755
--- a/test/test_pagination_draft.sh
+++ b/test/test_pagination_draft.sh
@@ -168,7 +168,7 @@ cat< $fstate
alice
2020-07-08T12:38:32Z
- admin
+ admin
2021-04-01T02:51:11Z
@@ -176,7 +176,7 @@ cat< $fstate
bob
2020-08-14T03:30:00Z
- standard
+ standard
2020-08-14T03:34:30Z
@@ -184,7 +184,7 @@ cat< $fstate
eric
2020-09-17T19:38:32Z
- pro
+ pro
2020-09-17T18:02:04Z
@@ -192,7 +192,7 @@ cat< $fstate
lin
2020-07-09T12:38:32Z
- standard
+ standard
2021-04-01T02:51:11Z
@@ -200,7 +200,7 @@ cat< $fstate
joe
2020-10-08T12:38:32Z
- pro
+ pro
2021-04-01T02:51:11Z
@@ -279,73 +279,73 @@ function testlimit()
let i=0
for li in $list; do
- if [ $i = 0 ]; then
- # Note: if REMAINING is enabled:
- # if [ $limit == 0 ]; then
- if true; then
- el="$li "
- el2="$li "
- else
- el="$li "
- el2="$li "
- jsonmeta=",\"@example-social:uint8-numbers\":\[{\"ietf-list-pagination:remaining\":$remaining}\]"
- fi
- jsonlist="$li"
- else
- el="$li "
- el2="$li " jsonlist="$jsonlist,$li"
- fi
- xmllist="$xmllist$el"
- xmllist2="$xmllist2$el2"
- let i++
+ if [ $i = 0 ]; then
+ # Note: if REMAINING is enabled:
+ # if [ $limit == 0 ]; then
+ if true; then
+ el="$li "
+ el2="$li "
+ else
+ el="$li "
+ el2="$li "
+ jsonmeta=",\"@example-social:uint8-numbers\":\[{\"ietf-list-pagination:remaining\":$remaining}\]"
+ fi
+ jsonlist="$li"
+ else
+ el="$li "
+ el2="$li " jsonlist="$jsonlist,$li"
+ fi
+ xmllist="$xmllist$el"
+ xmllist2="$xmllist2$el2"
+ let i++
done
jsonstr=""
if [ $limit -eq 0 ]; then
- limitxmlstr=""
+ limitxmlstr=""
else
- limitxmlstr="$limit "
- jsonstr="?limit=$limit"
+ limitxmlstr="$limit "
+ jsonstr="?limit=$limit"
fi
if [ $offset -eq 0 ]; then
- offsetxmlstr=""
+ offsetxmlstr=""
else
- offsetxmlstr="$offset "
- if [ -z "$jsonstr" ]; then
- jsonstr="?offset=$offset"
- else
- jsonstr="${jsonstr}&offset=$offset"
- fi
+ offsetxmlstr="$offset "
+ if [ -z "$jsonstr" ]; then
+ jsonstr="?offset=$offset"
+ else
+ jsonstr="${jsonstr}&offset=$offset"
+ fi
fi
if [ -z "$list" ]; then
- reply=" "
+ reply=" "
else
- reply="alice $xmllist "
+ reply="alice $xmllist "
fi
new "limit=$limit offset=$offset NETCONF get-config"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$limitxmlstr$offsetxmlstr " "" "$reply"
if [ -z "$list" ]; then
- reply=" "
+ reply=" "
else
- reply="alice $xmllist "
+ reply="alice $xmllist "
fi
new "limit=$limit offset=$offset NETCONF get"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$limitxmlstr$offsetxmlstr " "" "$reply"
if [ -z "$list" ]; then
- reply=""
+ reply=""
else
- reply="$xmllist2 "
+ reply="$xmllist2 "
fi
new "limit=$limit offset=$offset Parameter RESTCONF xml"
expectpart "$(curl $CURLOPTS -X GET -H "Accept: application/yang-data+xml-list" $RCPROTO://localhost/restconf/data/example-social:members/member=alice/favorites/uint8-numbers${jsonstr})" 0 "HTTP/$HVER 200" "Content-Type: application/yang-data+xml-list" "$reply"
if [ -z "$list" ]; then
- # reply="{\"xml-list\":{}}"
- reply="{}"
+ # reply="{\"xml-list\":{}}"
+ reply="{}"
else
- reply="{\"example-social:uint8-numbers\":\[$jsonlist\]}"
+ reply="{\"example-social:uint8-numbers\":\[$jsonlist\]}"
fi
new "limit=$limit offset=$offset Parameter RESTCONF json"
expectpart "$(curl $CURLOPTS -X GET -H "Accept: application/yang-data+json" $RCPROTO://localhost/restconf/data/example-social:members/member=alice/favorites/uint8-numbers${jsonstr})" 0 "HTTP/$HVER 200" "Content-Type: application/yang-data+json" "$reply" --not-- "xml-list"
@@ -357,7 +357,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -420,7 +420,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_pagination_state.sh b/test/test_pagination_state.sh
index eac96699..f11debd6 100755
--- a/test/test_pagination_state.sh
+++ b/test/test_pagination_state.sh
@@ -101,15 +101,15 @@ function testrun_start()
new "test params: -f $cfg -s init -- -siS $fstate -x $xpath"
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- sudo pkill -f clixon_backend # to be sure
-
- new "start backend -s init -f $cfg -- -siS $fstate -x $xpath"
- start_backend -s init -f $cfg -- -siS $fstate -x $xpath
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ sudo pkill -f clixon_backend # to be sure
+
+ new "start backend -s init -f $cfg -- -siS $fstate -x $xpath"
+ start_backend -s init -f $cfg -- -siS $fstate -x $xpath
fi
new "wait backend"
@@ -119,14 +119,14 @@ function testrun_start()
function testrun_stop()
{
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
@@ -166,7 +166,7 @@ if [ -n "$(type expect 2> /dev/null)" ]; then
new "CLI scroll test using expect"
expect ./test_pagination_expect.exp "$cfg" "$xpath" bob3 bob4
if [ $? -ne 0 ]; then
- err1 "Failed: CLI show paginate state scroll using expect"
+ err1 "Failed: CLI show paginate state scroll using expect"
fi
testrun_stop
diff --git a/test/test_pattern.sh b/test/test_pattern.sh
index 4da1fa40..084eeb87 100755
--- a/test/test_pattern.sh
+++ b/test/test_pattern.sh
@@ -356,13 +356,13 @@ module pattern{
leaf p45 {
description "Recognizing a CDATA pattern";
type string {
- pattern "";
+ pattern "";
}
}
leaf p46 {
description "opencoinfig types/openconfig-inet-types.yang ipv4-address";
type string {
- pattern '^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|' +
+ pattern '^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|' +
'25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4]' +
'[0-9]|25[0-5])$';
}
@@ -403,13 +403,13 @@ function testrun(){
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<$leaf>$str$leaf> " "" " "
if $mat; then
- new "netconf validate expected match"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+ new "netconf validate expected match"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
else
- new "netconf validate expected fail"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "application bad-element $leaf error " ""
- new "netconf discard-changes"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "^ "
+ new "netconf validate expected fail"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "application bad-element $leaf error " ""
+ new "netconf discard-changes"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "^ "
fi
}
@@ -419,7 +419,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -824,7 +824,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_perf_cli.sh b/test/test_perf_cli.sh
index a0fd852a..ddc3b84e 100755
--- a/test/test_perf_cli.sh
+++ b/test/test_perf_cli.sh
@@ -76,14 +76,14 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -s"
start_backend -s init -f $cfg -- -s
fi
-new "waiting"
+new "wait backend"
wait_backend
new "generate config with $perfnr list entries"
@@ -154,7 +154,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_perf_mem.sh b/test/test_perf_mem.sh
index e6dd1ec2..25a7f642 100755
--- a/test/test_perf_mem.sh
+++ b/test/test_perf_mem.sh
@@ -69,23 +69,23 @@ function testrun(){
new "test params: -f $cfg"
if [ $BE -ne 0 ]; then
- new "generate config with $nr list entries"
- echo -n "<${DATASTORE_TOP}>" > $dir/startup_db
- for (( i=0; i<$nr; i++ )); do
- echo -n "$i $i " >> $dir/startup_db
- done
- echo " ${DATASTORE_TOP}>" >> $dir/startup_db
+ new "generate config with $nr list entries"
+ echo -n "<${DATASTORE_TOP}>" > $dir/startup_db
+ for (( i=0; i<$nr; i++ )); do
+ echo -n "$i $i " >> $dir/startup_db
+ done
+ echo " ${DATASTORE_TOP}>" >> $dir/startup_db
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s startup -f $cfg"
- start_backend -s startup -f $cfg
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s startup -f $cfg"
+ start_backend -s startup -f $cfg
fi
- new "waiting"
+ new "wait backend"
wait_backend
pid=$(cat $pidfile)
@@ -97,7 +97,7 @@ function testrun(){
err0=$(echo "$res" | $clixon_util_xpath -p "/rpc-reply/rpc-error")
err=${err0#"nodeset:"}
if [ -n "$err" ]; then
- err1 "" "$err"
+ err1 "" "$err"
fi
objects=$(echo "$res" | $clixon_util_xpath -p "/rpc-reply/global/xmlnr" | awk -F ">" '{print $2}' | awk -F "<" '{print $1}')
@@ -106,42 +106,42 @@ function testrun(){
#
if [ -f /proc/$pid/statm ]; then # This only works on Linux
-# cat /proc/$pid/statm
- echo -n " /proc/$pid/statm: "
- cat /proc/$pid/statm|awk '{print $1*4/1000 "M"}'
+# cat /proc/$pid/statm
+ echo -n " /proc/$pid/statm: "
+ cat /proc/$pid/statm|awk '{print $1*4/1000 "M"}'
fi
for db in running candidate startup; do
- echo "$db"
- resdb0=$(echo "$res" | $clixon_util_xpath -p "/rpc-reply/datastore[name=\"$db\"]")
- resdb=${resdb0#"nodeset:0:"}
- if [ "$resdb0" = "$resdb" ]; then
- err1 "nodeset:0:" "$resdb0"
- fi
- echo -n " objects: "
- echo $resdb | $clixon_util_xpath -p "datastore/nr" | awk -F ">" '{print $2}' | awk -F "<" '{print $1}'
- echo -n " mem: "
- echo $resdb | $clixon_util_xpath -p "datastore/size" | awk -F ">" '{print $2}' | awk -F "<" '{print $1}' | awk '{print $1/1000000 "M"}'
+ echo "$db"
+ resdb0=$(echo "$res" | $clixon_util_xpath -p "/rpc-reply/datastore[name=\"$db\"]")
+ resdb=${resdb0#"nodeset:0:"}
+ if [ "$resdb0" = "$resdb" ]; then
+ err1 "nodeset:0:" "$resdb0"
+ fi
+ echo -n " objects: "
+ echo $resdb | $clixon_util_xpath -p "datastore/nr" | awk -F ">" '{print $2}' | awk -F "<" '{print $1}'
+ echo -n " mem: "
+ echo $resdb | $clixon_util_xpath -p "datastore/size" | awk -F ">" '{print $2}' | awk -F "<" '{print $1}' | awk '{print $1/1000000 "M"}'
done
for mod in clixon-config; do
- echo "$mod"
- resmod0=$(echo "$res" | $clixon_util_xpath -p "/rpc-reply/module[name=\"$mod\"]")
- resmod=${resmod0#"nodeset:0:"}
- echo -n " objects: "
- echo $resmod | $clixon_util_xpath -p "module/nr" | awk -F ">" '{print $2}' | awk -F "<" '{print $1}'
- echo -n " mem: "
- echo $resmod | $clixon_util_xpath -p "module/size" | awk -F ">" '{print $2}' | awk -F "<" '{print $1}' | awk '{print $1/1000000 "M"}'
+ echo "$mod"
+ resmod0=$(echo "$res" | $clixon_util_xpath -p "/rpc-reply/module[name=\"$mod\"]")
+ resmod=${resmod0#"nodeset:0:"}
+ echo -n " objects: "
+ echo $resmod | $clixon_util_xpath -p "module/nr" | awk -F ">" '{print $2}' | awk -F "<" '{print $1}'
+ echo -n " mem: "
+ echo $resmod | $clixon_util_xpath -p "module/size" | awk -F ">" '{print $2}' | awk -F "<" '{print $1}' | awk '{print $1/1000000 "M"}'
done
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
- new "Zap backend"
- stop_backend -f $cfg
+ new "Zap backend"
+ stop_backend -f $cfg
fi
}
diff --git a/test/test_perf_netconf.sh b/test/test_perf_netconf.sh
index 7beb12b9..0e9493e1 100755
--- a/test/test_perf_netconf.sh
+++ b/test/test_perf_netconf.sh
@@ -80,14 +80,14 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -s"
start_backend -s init -f $cfg -- -s
fi
-new "waiting"
+new "wait backend"
wait_backend
# Check this later with committed data
@@ -135,7 +135,7 @@ echo "$(chunked_framing "$rpc")" >> $ftest
ret=$(diff $ftest $foutput)
if [ $? -ne 0 ]; then
err1 "Matching running-db with $fconfigonly"
-fi
+fi
# Now commit it again from candidate (validation takes time when
# comparing to existing)
@@ -234,7 +234,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_perf_restconf.sh b/test/test_perf_restconf.sh
index a1140eb0..e6416eb9 100755
--- a/test/test_perf_restconf.sh
+++ b/test/test_perf_restconf.sh
@@ -96,7 +96,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
# sudo pkill clixon_backend # extra
@@ -106,7 +106,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg -- -s
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -158,7 +158,7 @@ ret=$(diff -i $ftest $foutput)
if [ $? -ne 0 ]; then
echo "diff -i $ftest $foutput"
err1 "Matching running-db with $fdataxml"
-fi
+fi
# RESTCONF get
new "restconf get $perfreq small config 1 key index"
@@ -235,7 +235,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_perf_restconf_ssl.sh b/test/test_perf_restconf_ssl.sh
index 0e230fd9..7beb0b39 100755
--- a/test/test_perf_restconf_ssl.sh
+++ b/test/test_perf_restconf_ssl.sh
@@ -112,7 +112,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
# sudo pkill clixon_backend # extra
@@ -122,7 +122,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg -- -s
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -172,7 +172,7 @@ ret=$(diff -i $ftest $foutput)
if [ $? -ne 0 ]; then
echo "diff -i $ftest $foutput"
err1 "Matching running-db with $fdataxml"
-fi
+fi
# RESTCONF get
new "restconf get $perfreq small config 1 key index"
@@ -249,7 +249,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_perf_startup.sh b/test/test_perf_startup.sh
index 9c713d40..cd1487c7 100755
--- a/test/test_perf_startup.sh
+++ b/test/test_perf_startup.sh
@@ -74,7 +74,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg -y $fyang
if [ $? -ne 0 ]; then
- err
+ err
fi
fi
@@ -105,10 +105,10 @@ cat< $sxpp
EOF
for (( i=0; i<$perfnr; i++ )); do
- echo " " >> $sxpp
- echo " $i " >> $sxpp
- echo " $i " >> $sxpp
- echo " " >> $sxpp
+ echo " " >> $sxpp
+ echo " $i " >> $sxpp
+ echo " $i " >> $sxpp
+ echo " " >> $sxpp
done
cat<> $sxpp
@@ -123,9 +123,9 @@ new "generate pretty-printed json startup config ($sj) with $perfnr entries"
echo -n '{"config": {"scaling:x":{"y":[' > $sj
for (( i=0; i<$perfnr; i++ )); do
if [ $i -ne 0 ]; then
- echo -n ",{\"a\":$i,\"b\":$i}" >> $sj
+ echo -n ",{\"a\":$i,\"b\":$i}" >> $sj
else
- echo -n "{\"a\":$i,\"b\":$i}" >> $sj
+ echo -n "{\"a\":$i,\"b\":$i}" >> $sj
fi
done
@@ -139,13 +139,13 @@ sdb=$dir/${mode}_db
for variant in prefix plain pretty; do
case $variant in
plain)
- f=$sx
+ f=$sx
;;
- pretty)
- f=$sxpp
+ pretty)
+ f=$sxpp
;;
- prefix)
- f=$sxpre
+ prefix)
+ f=$sxpre
;;
esac
diff --git a/test/test_perf_state.sh b/test/test_perf_state.sh
index d9d3b459..77462f45 100755
--- a/test/test_perf_state.sh
+++ b/test/test_perf_state.sh
@@ -102,7 +102,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -sS $fstate"
@@ -211,7 +211,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_perf_state_only.sh b/test/test_perf_state_only.sh
index 2145bf0a..98b76258 100755
--- a/test/test_perf_state_only.sh
+++ b/test/test_perf_state_only.sh
@@ -102,7 +102,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -sS $fstate"
@@ -194,7 +194,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_privileges.sh b/test/test_privileges.sh
index 17c5af0e..bae5ba2a 100755
--- a/test/test_privileges.sh
+++ b/test/test_privileges.sh
@@ -26,7 +26,7 @@ cat < $cfg
$cfg
${YANG_INSTALLDIR}
- $fyang
+ $fyang
$dir/$APPNAME.sock
/var/tmp/$APPNAME.pidfile
$dir
@@ -68,7 +68,7 @@ function testrun(){
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
# Kill all backends regardless of user or pid files (we mess with them in this test)
sudo pkill -f clixon_backend
@@ -78,42 +78,42 @@ function testrun(){
new "start backend -f $cfg -s init -D $DBG -o CLICON_BACKEND_PRIVILEGES=$priv_mode -o CLICON_BACKEND_USER=$beuser"
sudo -u $startuser $clixon_backend -f $cfg -s init -D $DBG -o CLICON_BACKEND_PRIVILEGES=$priv_mode -o CLICON_BACKEND_USER=$beuser
if [ $? -ne 0 ]; then
- err
+ err
fi
sleep 1 # wait for backend to exit
pid=$(pgrep -f clixon_backend)
if [ $? -ne 0 ]; then
- if [ $expecterr -eq 1 ]; then
- return 0
- fi
- err
+ if [ $expecterr -eq 1 ]; then
+ return 0
+ fi
+ err
fi
new "Number of clixon_backend processes"
c=$(pgrep -c -f clixon_backend)
if [ $c -ne 1 ]; then
- err 1 $c
+ err 1 $c
fi
- new "waiting"
+ new "wait backend"
wait_backend
if [ $expecterr -eq 1 ]; then
- err "Expected error"
+ err "Expected error"
fi
# Get uid now, and compare with expected user (tail to skip hdr)
u=$(ps -p $pid -u | tail -1 | awk '{print $1}')
if [ $u != $expectuser ]; then
- err "$expectuser but user is $u"
+ err "$expectuser but user is $u"
fi
new "Kill backend"
# Check if premature kill
pid=$(pgrep -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_refine.sh b/test/test_refine.sh
index 5e4db71c..b31a6690 100755
--- a/test/test_refine.sh
+++ b/test/test_refine.sh
@@ -42,20 +42,20 @@ module clixon-example {
mandatory true;
case local {
container local-definition {
- presence true;
- leaf dummy1{
+ presence true;
+ leaf dummy1{
type string;
- default "foo1";
- }
+ default "foo1";
+ }
}
}
case keystore {
container keystore-reference {
- presence true;
- leaf dummy2{
+ presence true;
+ leaf dummy2{
type string;
- default "bar1";
- }
+ default "bar1";
+ }
}
}
}
@@ -64,11 +64,11 @@ module clixon-example {
description "See ietf-tls-server@2022-05-24.yang";
uses ex:mygrouping{
refine "mykeystore/local/local-definition/dummy1" {
- default "foo2";
+ default "foo2";
}
refine "mykeystore/keystore/keystore-reference"
+ "/dummy2" {
- default "bar2";
+ default "bar2";
}
}
}
@@ -83,7 +83,7 @@ if [ $BE -ne 0 ]; then
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -109,7 +109,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf.sh b/test/test_restconf.sh
index c6e71925..d006a8e6 100755
--- a/test/test_restconf.sh
+++ b/test/test_restconf.sh
@@ -119,135 +119,135 @@ module clixon-example {
namespace "urn:example:clixon";
prefix ex;
import ietf-interfaces {
- /* is in yang/optional which means clixon must be installed using --opt-yang-installdir */
- prefix if;
+ /* is in yang/optional which means clixon must be installed using --opt-yang-installdir */
+ prefix if;
}
import ietf-ip {
- prefix ip;
+ prefix ip;
}
import iana-if-type {
- prefix ianaift;
+ prefix ianaift;
}
import ietf-datastores {
- prefix ds;
+ prefix ds;
}
import clixon-autocli{
- prefix autocli;
+ prefix autocli;
}
description
- "Clixon example used as a part of the Clixon test suite.
+ "Clixon example used as a part of the Clixon test suite.
It can be used as a basis for making new Clixon applications.
Note, may change without updating revision, just for testing current master.
";
/* Example interface type for tests, local callbacks, etc */
identity eth {
- base if:interface-type;
+ base if:interface-type;
}
identity loopback {
- base if:interface-type;
+ base if:interface-type;
}
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
- leaf hidden{
- type string;
- autocli:hide;
- }
- leaf stat{
- description "Inline state data for example application";
- config false;
- type int32;
- }
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
+ leaf hidden{
+ type string;
+ autocli:hide;
+ }
+ leaf stat{
+ description "Inline state data for example application";
+ config false;
+ type int32;
+ }
+ }
}
/* State data (not config) for the example application*/
container state {
- config false;
- description "state data for the example application (must be here for example get operation)";
- leaf-list op {
+ config false;
+ description "state data for the example application (must be here for example get operation)";
+ leaf-list op {
type string;
- }
+ }
}
augment "/if:interfaces/if:interface" {
- container my-status {
- config false;
- description "For testing augment+state";
- leaf int {
- type int32;
- }
- leaf str {
- type string;
- }
- }
+ container my-status {
+ config false;
+ description "For testing augment+state";
+ leaf int {
+ type int32;
+ }
+ leaf str {
+ type string;
+ }
+ }
}
/* yang extension implemented by the example backend code. */
extension e4 {
- description
- "The first child of the ex:e4 (unknown) statement is inserted into
- the module as a regular data statement. This means that 'uses bar;'
- in the ex:e4 statement below is a valid data node";
- argument arg;
+ description
+ "The first child of the ex:e4 (unknown) statement is inserted into
+ the module as a regular data statement. This means that 'uses bar;'
+ in the ex:e4 statement below is a valid data node";
+ argument arg;
}
grouping bar {
- leaf bar{
- type string;
- }
+ leaf bar{
+ type string;
+ }
}
ex:e4 arg1{
- uses bar;
+ uses bar;
}
rpc client-rpc {
- description "Example local client-side RPC that is processed by the
+ description "Example local client-side RPC that is processed by the
the netconf/restconf and not sent to the backend.
This is a clixon implementation detail: some rpc:s
are better processed by the client for API or perf reasons";
- input {
- leaf x {
- type string;
- }
- }
- output {
- leaf x {
- type string;
- }
- }
+ input {
+ leaf x {
+ type string;
+ }
+ }
+ output {
+ leaf x {
+ type string;
+ }
+ }
}
rpc empty {
- description "Smallest possible RPC with no input or output sections";
+ description "Smallest possible RPC with no input or output sections";
}
rpc example {
- description "Some example input/output for testing RFC7950 7.14.
+ description "Some example input/output for testing RFC7950 7.14.
RPC simply echoes the input for debugging.";
- input {
- leaf x {
- description
- "If a leaf in the input tree has a 'mandatory' statement with
+ input {
+ leaf x {
+ description
+ "If a leaf in the input tree has a 'mandatory' statement with
the value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- mandatory true;
- }
- leaf y {
- description
- "If a leaf in the input tree has a 'mandatory' statement with the
+ type string;
+ mandatory true;
+ }
+ leaf y {
+ description
+ "If a leaf in the input tree has a 'mandatory' statement with the
value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- default "42";
- }
- }
- output {
- leaf x {
- type string;
- }
- leaf y {
- type string;
- }
+ type string;
+ default "42";
+ }
+ }
+ output {
+ leaf x {
+ type string;
+ }
+ leaf y {
+ type string;
+ }
}
}
}
@@ -267,15 +267,15 @@ function testrun()
new "test params: -f $cfg -- -s"
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- sudo pkill -f clixon_backend # to be sure
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ sudo pkill -f clixon_backend # to be sure
- new "start backend -s init -f $cfg -- -s"
- start_backend -s init -f $cfg -- -s
+ new "start backend -s init -f $cfg -- -s"
+ start_backend -s init -f $cfg -- -s
fi
new "wait backend"
@@ -288,160 +288,160 @@ function testrun()
expecteof_netconf "$clixon_netconf -qef $cfg" 0 "$DEFAULTHELLO" " " "" " "
if [ $RC -ne 0 ]; then
- new "kill old restconf daemon"
- stop_restconf_pre
+ new "kill old restconf daemon"
+ stop_restconf_pre
- new "start restconf daemon"
- # inline of start_restconf, cant make quotes to work
- echo "sudo -u $wwwstartuser -s $clixon_restconf $RCLOG -D $DBG -f $cfg -R $RESTCONFIG1"
- sudo -u $wwwstartuser -s $clixon_restconf $RCLOG -D $DBG -f $cfg -R "$RESTCONFIG1" /dev/null &
- if [ $? -ne 0 ]; then
- err1 "expected 0" "$?"
- fi
+ new "start restconf daemon"
+ # inline of start_restconf, cant make quotes to work
+ echo "sudo -u $wwwstartuser -s $clixon_restconf $RCLOG -D $DBG -f $cfg -R $RESTCONFIG1"
+ sudo -u $wwwstartuser -s $clixon_restconf $RCLOG -D $DBG -f $cfg -R "$RESTCONFIG1" /dev/null &
+ if [ $? -ne 0 ]; then
+ err1 "expected 0" "$?"
+ fi
fi
#------------------------------------------------------- HTTP/1 + HTTP/2
if [ ${HAVE_LIBNGHTTP2} = true -a ${HAVE_HTTP1} = true ]; then
- if [ $proto = http ]; then # No plain http/2
- HVER=1.1
- else
- HVER=2
- fi
- new "wait restconf"
- wait_restconf
+ if [ $proto = http ]; then # No plain http/2
+ HVER=1.1
+ else
+ HVER=2
+ fi
+ new "wait restconf"
+ wait_restconf
- new "restconf root discovery. RFC 8040 3.1 (xml+xrd)"
- echo "curl $CURLOPTS -X GET $proto://$addr/.well-known/host-meta"
- expectpart "$(curl $CURLOPTS -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/$HVER 200" "" " " " "
+ new "restconf root discovery. RFC 8040 3.1 (xml+xrd)"
+ echo "curl $CURLOPTS -X GET $proto://$addr/.well-known/host-meta"
+ expectpart "$(curl $CURLOPTS -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/$HVER 200" "" " " " "
- echo "fcgi or native+http/1 or native+http/1+http/2"
- if [ "${WITH_RESTCONF}" = "native" ]; then # XXX does not work with nginx
- new "restconf GET http/1.0 - returns 1.0"
- expectpart "$(curl $CURLOPTS --http1.0 -X GET $proto://$addr/.well-known/host-meta)" 0 'HTTP/1.0 200 OK' "" " " " "
- fi
- new "restconf GET http/1.1"
- expectpart "$(curl $CURLOPTS --http1.1 -X GET $proto://$addr/.well-known/host-meta)" 0 'HTTP/1.1 200 OK' "" " " " "
+ echo "fcgi or native+http/1 or native+http/1+http/2"
+ if [ "${WITH_RESTCONF}" = "native" ]; then # XXX does not work with nginx
+ new "restconf GET http/1.0 - returns 1.0"
+ expectpart "$(curl $CURLOPTS --http1.0 -X GET $proto://$addr/.well-known/host-meta)" 0 'HTTP/1.0 200 OK' "" " " " "
+ fi
+ new "restconf GET http/1.1"
+ expectpart "$(curl $CURLOPTS --http1.1 -X GET $proto://$addr/.well-known/host-meta)" 0 'HTTP/1.1 200 OK' "" " " " "
- new "restconf GET http/2 switch protocol"
- if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
- expectpart "$(curl $CURLOPTS --http2 -X GET $proto://$addr/.well-known/host-meta)" 0 "" "HTTP/1.1 200" "" " " " "
- else
- expectpart "$(curl $CURLOPTS --http2 -X GET $proto://$addr/.well-known/host-meta)" 0 "" "HTTP/2 200" "" " " " " # Only if https: HTTP/1.1 101 Switching Protocols
- fi
+ new "restconf GET http/2 switch protocol"
+ if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
+ expectpart "$(curl $CURLOPTS --http2 -X GET $proto://$addr/.well-known/host-meta)" 0 "" "HTTP/1.1 200" "" " " " "
+ else
+ expectpart "$(curl $CURLOPTS --http2 -X GET $proto://$addr/.well-known/host-meta)" 0 "" "HTTP/2 200" "" " " " " # Only if https: HTTP/1.1 101 Switching Protocols
+ fi
- # http2-prior knowledge
- if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
- new "restconf GET http/2 prior-knowledge (http)"
- expectpart "$(curl $CURLOPTS --http2-prior-knowledge -X GET $proto://$addr/.well-known/host-meta 2>&1)" "16 52 55" # "Error in the HTTP2 framing layer" "Connection reset by peer"
- else
- new "restconf GET https/2 prior-knowledge"
- expectpart "$(curl $CURLOPTS --http2-prior-knowledge -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/$HVER 200" "" " " " "
- fi
-
- # Wrong protocol http when https or vice versa
- if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
- new "Wrong proto=https on http port, expect err 35 wrong version number"
- expectpart "$(curl $CURLOPTS -X GET https://$addr:80/.well-known/host-meta 2>&1)" 35 #"wrong version number" # dependent on curl version
- else # see (1) http to https port in restconf_main_native.c
- new "Wrong proto=http on https port, expect bad request http1+2"
-# expectpart "$(curl $CURLOPTS -X GET http://$addr:443/.well-known/host-meta 2>&1)" 56 "Connection reset by peer"
- expectpart "$(curl $CURLOPTS -X GET http://$addr:443/.well-known/host-meta)" 0 "HTTP/" "400"
+ # http2-prior knowledge
+ if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
+ new "restconf GET http/2 prior-knowledge (http)"
+ expectpart "$(curl $CURLOPTS --http2-prior-knowledge -X GET $proto://$addr/.well-known/host-meta 2>&1)" "16 52 55" # "Error in the HTTP2 framing layer" "Connection reset by peer"
+ else
+ new "restconf GET https/2 prior-knowledge"
+ expectpart "$(curl $CURLOPTS --http2-prior-knowledge -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/$HVER 200" "" " " " "
+ fi
+
+ # Wrong protocol http when https or vice versa
+ if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
+ new "Wrong proto=https on http port, expect err 35 wrong version number"
+ expectpart "$(curl $CURLOPTS -X GET https://$addr:80/.well-known/host-meta 2>&1)" 35 #"wrong version number" # dependent on curl version
+ else # see (1) http to https port in restconf_main_native.c
+ new "Wrong proto=http on https port, expect bad request http1+2"
+# expectpart "$(curl $CURLOPTS -X GET http://$addr:443/.well-known/host-meta 2>&1)" 56 "Connection reset by peer"
+ expectpart "$(curl $CURLOPTS -X GET http://$addr:443/.well-known/host-meta)" 0 "HTTP/" "400"
- fi
-
+ fi
+
#------------------------------------------------------- HTTP/2 ONLY
elif [ ${HAVE_LIBNGHTTP2} = true -a ${HAVE_HTTP1} = false ]; then
- HVER=2
-
- new "wait restconf"
- wait_restconf
+ HVER=2
+
+ new "wait restconf"
+ wait_restconf
- new "restconf root discovery. RFC 8040 3.1 (xml+xrd)"
- echo "curl $CURLOPTS -X GET $proto://$addr/.well-known/host-meta"
- expectpart "$(curl $CURLOPTS -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/$HVER 200" "" " " " "
+ new "restconf root discovery. RFC 8040 3.1 (xml+xrd)"
+ echo "curl $CURLOPTS -X GET $proto://$addr/.well-known/host-meta"
+ expectpart "$(curl $CURLOPTS -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/$HVER 200" "" " " " "
- echo "native + http/2 only"
- # Important here is robustness of restconf daemon, not a meaningful reply
- if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
- # http protocol mismatch can just close the socket if assumed its http/2
- # everything else would guess it is http/1 which is really wrong here
- # The tr statement replaces null char to get rid of annoying message:
- # ./test_restconf.sh: line 180: warning: command substitution: ignored null byte in input
- new "restconf GET http/1.0 - close"
- expectpart "$(curl $CURLOPTS --http1.0 -X GET $proto://$addr/.well-known/host-meta | tr '\0' '\n')" 0 "" --not-- 'HTTP'
- else
- new "restconf GET https/1.0 - close"
- expectpart "$(curl $CURLOPTS --http1.0 -X GET $proto://$addr/.well-known/host-meta)" "52 56" "" --not-- 'HTTP'
+ echo "native + http/2 only"
+ # Important here is robustness of restconf daemon, not a meaningful reply
+ if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
+ # http protocol mismatch can just close the socket if assumed its http/2
+ # everything else would guess it is http/1 which is really wrong here
+ # The tr statement replaces null char to get rid of annoying message:
+ # ./test_restconf.sh: line 180: warning: command substitution: ignored null byte in input
+ new "restconf GET http/1.0 - close"
+ expectpart "$(curl $CURLOPTS --http1.0 -X GET $proto://$addr/.well-known/host-meta | tr '\0' '\n')" 0 "" --not-- 'HTTP'
+ else
+ new "restconf GET https/1.0 - close"
+ expectpart "$(curl $CURLOPTS --http1.0 -X GET $proto://$addr/.well-known/host-meta)" "52 56" "" --not-- 'HTTP'
- fi
+ fi
- if [ $proto = http ]; then
- new "restconf GET http/1.1 - close"
- expectpart "$(curl $CURLOPTS --http1.1 -X GET $proto://$addr/.well-known/host-meta | tr '\0' '\n')" 0 --not-- 'HTTP'
- else
- new "restconf GET https/1.1 - close"
- expectpart "$(curl $CURLOPTS --http1.1 -X GET $proto://$addr/.well-known/host-meta)" "52 56" --not-- 'HTTP'
- fi
-
- if [ $proto = http ]; then
- new "restconf GET http/2 switch protocol"
- expectpart "$(curl $CURLOPTS --http2 -X GET $proto://$addr/.well-known/host-meta | tr '\0' '\n')" 0 --not-- 'HTTP'
- else
- new "restconf GET https/2 alpn protocol"
- expectpart "$(curl $CURLOPTS --http2 -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/$HVER 200" "" " " " "
- fi
+ if [ $proto = http ]; then
+ new "restconf GET http/1.1 - close"
+ expectpart "$(curl $CURLOPTS --http1.1 -X GET $proto://$addr/.well-known/host-meta | tr '\0' '\n')" 0 --not-- 'HTTP'
+ else
+ new "restconf GET https/1.1 - close"
+ expectpart "$(curl $CURLOPTS --http1.1 -X GET $proto://$addr/.well-known/host-meta)" "52 56" --not-- 'HTTP'
+ fi
+
+ if [ $proto = http ]; then
+ new "restconf GET http/2 switch protocol"
+ expectpart "$(curl $CURLOPTS --http2 -X GET $proto://$addr/.well-known/host-meta | tr '\0' '\n')" 0 --not-- 'HTTP'
+ else
+ new "restconf GET https/2 alpn protocol"
+ expectpart "$(curl $CURLOPTS --http2 -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/$HVER 200" "" " " " "
+ fi
- # Wrong protocol http when https or vice versa
- if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
- new "Wrong proto=https on http port, expect err 35 wrong version number"
- expectpart "$(curl $CURLOPTS -X GET https://$addr:80/.well-known/host-meta 2>&1)" 35 #"wrong version number" # dependent on curl version
- else # see (1) http to https port in restconf_main_native.c
- new "Wrong proto=http on https port, expect bad request http2-only"
- expectpart "$(curl $CURLOPTS -X GET http://$addr:443/.well-known/host-meta)" "16 52 55 56" --not-- 'HTTP'
- fi
+ # Wrong protocol http when https or vice versa
+ if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
+ new "Wrong proto=https on http port, expect err 35 wrong version number"
+ expectpart "$(curl $CURLOPTS -X GET https://$addr:80/.well-known/host-meta 2>&1)" 35 #"wrong version number" # dependent on curl version
+ else # see (1) http to https port in restconf_main_native.c
+ new "Wrong proto=http on https port, expect bad request http2-only"
+ expectpart "$(curl $CURLOPTS -X GET http://$addr:443/.well-known/host-meta)" "16 52 55 56" --not-- 'HTTP'
+ fi
else #------------------------------------------------------- HTTP/1 only
- HVER=1.1
+ HVER=1.1
- new "wait restconf"
- wait_restconf
+ new "wait restconf"
+ wait_restconf
- new "restconf root discovery. RFC 8040 3.1 (xml+xrd)"
- echo "curl $CURLOPTS -X GET $proto://$addr/.well-known/host-meta"
- expectpart "$(curl $CURLOPTS -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/$HVER 200" "" " " " "
+ new "restconf root discovery. RFC 8040 3.1 (xml+xrd)"
+ echo "curl $CURLOPTS -X GET $proto://$addr/.well-known/host-meta"
+ expectpart "$(curl $CURLOPTS -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/$HVER 200" "" " " " "
- echo "fcgi or native+http/1 or native+http/1+http/2"
- if [ "${WITH_RESTCONF}" = "native" ]; then # XXX does not work with nginx
- new "restconf GET http/1.0 - returns 1.0"
- expectpart "$(curl $CURLOPTS --http1.0 -X GET $proto://$addr/.well-known/host-meta)" 0 'HTTP/1.0 200 OK' "" " " " "
- fi
- new "restconf GET http/1.1"
- expectpart "$(curl $CURLOPTS --http1.1 -X GET $proto://$addr/.well-known/host-meta)" 0 'HTTP/1.1 200 OK' "" " " " "
+ echo "fcgi or native+http/1 or native+http/1+http/2"
+ if [ "${WITH_RESTCONF}" = "native" ]; then # XXX does not work with nginx
+ new "restconf GET http/1.0 - returns 1.0"
+ expectpart "$(curl $CURLOPTS --http1.0 -X GET $proto://$addr/.well-known/host-meta)" 0 'HTTP/1.0 200 OK' "" " " " "
+ fi
+ new "restconf GET http/1.1"
+ expectpart "$(curl $CURLOPTS --http1.1 -X GET $proto://$addr/.well-known/host-meta)" 0 'HTTP/1.1 200 OK' "" " " " "
- # http/1 only Try http/2 - go back to http/1.1
- new "restconf GET http/2 switch protocol"
- expectpart "$(curl $CURLOPTS --http2 -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/1.1 200 OK" "" " " " "
-
- # http2-prior knowledge
- if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
- new "restconf GET http/2 prior-knowledge (http)"
- expectpart "$(curl $CURLOPTS --http2-prior-knowledge -X GET $proto://$addr/.well-known/host-meta 2>&1)" "16 52 55" # "Error in the HTTP2 framing layer" "Connection reset by peer"
- else
- new "restconf GET https/2 prior-knowledge"
- expectpart "$(curl $CURLOPTS --http2-prior-knowledge -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/$HVER 200" "" " " " "
- fi
-
- # Wrong protocol http when https or vice versa
- if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
- new "Wrong proto=https on http port, expect err 35 wrong version number"
- expectpart "$(curl $CURLOPTS -X GET https://$addr:80/.well-known/host-meta 2>&1)" 35 #"wrong version number" # dependent on curl version
- else # see (1) http to https port in restconf_main_native.c
- new "Wrong proto=http on https port, expect bad request http/1 only"
-# expectpart "$(curl $CURLOPTS -X GET http://$addr:443/.well-known/host-meta 2>&1)" 56 "Connection reset by peer"
- expectpart "$(curl $CURLOPTS -X GET http://$addr:443/.well-known/host-meta)" 0 "HTTP/" "400"
- fi
+ # http/1 only Try http/2 - go back to http/1.1
+ new "restconf GET http/2 switch protocol"
+ expectpart "$(curl $CURLOPTS --http2 -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/1.1 200 OK" "" " " " "
+
+ # http2-prior knowledge
+ if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
+ new "restconf GET http/2 prior-knowledge (http)"
+ expectpart "$(curl $CURLOPTS --http2-prior-knowledge -X GET $proto://$addr/.well-known/host-meta 2>&1)" "16 52 55" # "Error in the HTTP2 framing layer" "Connection reset by peer"
+ else
+ new "restconf GET https/2 prior-knowledge"
+ expectpart "$(curl $CURLOPTS --http2-prior-knowledge -X GET $proto://$addr/.well-known/host-meta)" 0 "HTTP/$HVER 200" "" " " " "
+ fi
+
+ # Wrong protocol http when https or vice versa
+ if [ $proto = http ]; then # see (2) https to http port in restconf_main_native.c
+ new "Wrong proto=https on http port, expect err 35 wrong version number"
+ expectpart "$(curl $CURLOPTS -X GET https://$addr:80/.well-known/host-meta 2>&1)" 35 #"wrong version number" # dependent on curl version
+ else # see (1) http to https port in restconf_main_native.c
+ new "Wrong proto=http on https port, expect bad request http/1 only"
+# expectpart "$(curl $CURLOPTS -X GET http://$addr:443/.well-known/host-meta 2>&1)" 56 "Connection reset by peer"
+ expectpart "$(curl $CURLOPTS -X GET http://$addr:443/.well-known/host-meta)" 0 "HTTP/" "400"
+ fi
fi # HTTP/2
# Exact match
@@ -461,7 +461,7 @@ function testrun()
expect=' '
match=`echo $ret | grep --null -Eo "$expect"`
if [ -z "$match" ]; then
- err "$expect" "$ret"
+ err "$expect" "$ret"
fi
new "restconf get restconf/yang-library-version. RFC8040 3.3.3"
@@ -472,7 +472,7 @@ function testrun()
expect="2019-01-04 "
match=`echo $ret | grep --null -Eo "$expect"`
if [ -z "$match" ]; then
- err "$expect" "$ret"
+ err "$expect" "$ret"
fi
new "restconf schema resource, RFC 8040 sec 3.7 according to RFC 8525 (explicit resource)"
@@ -520,7 +520,7 @@ function testrun()
expect='41 42 43 '
match=`echo $ret | grep --null -Eo "$expect"`
if [ -z "$match" ]; then
- err "$expect" "$ret"
+ err "$expect" "$ret"
fi
new "restconf get data type json"
@@ -532,7 +532,7 @@ function testrun()
expect='42 '
match=`echo $ret | grep --null -Eo "$expect"`
if [ -z "$match" ]; then
- err "$expect" "$ret"
+ err "$expect" "$ret"
fi
new "restconf get state operation type json"
@@ -544,7 +544,7 @@ function testrun()
expect='42 '
match=`echo $ret | grep --null -Eo "$expect"`
if [ -z "$match" ]; then
- err "$expect" "$ret"
+ err "$expect" "$ret"
fi
new "restconf GET datastore"
@@ -616,8 +616,8 @@ function testrun()
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" -d '{"clixon-example:input":{"x":42}}' $proto://$addr/restconf/operations/clixon-example:example)" 0 "HTTP/$HVER 200" '{"clixon-example:output":{"x":"42","y":"42"}}'
if ! $YANG_UNKNOWN_ANYDATA ; then
- new "restconf rpc using POST json wrong"
- expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" -d '{"clixon-example:input":{"wrongelement":"ipv4"}}' $proto://$addr/restconf/operations/clixon-example:example)" 0 "HTTP/$HVER 400" '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"unknown-element","error-info":{"bad-element":"wrongelement"},"error-severity":"error","error-message":"Failed to find YANG spec of XML node: wrongelement with parent: example in namespace: urn:example:clixon"}}}'
+ new "restconf rpc using POST json wrong"
+ expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" -d '{"clixon-example:input":{"wrongelement":"ipv4"}}' $proto://$addr/restconf/operations/clixon-example:example)" 0 "HTTP/$HVER 400" '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"unknown-element","error-info":{"bad-element":"wrongelement"},"error-severity":"error","error-message":"Failed to find YANG spec of XML node: wrongelement with parent: example in namespace: urn:example:clixon"}}}'
fi
new "restconf rpc non-existing rpc without namespace"
@@ -637,7 +637,7 @@ function testrun()
expect='42 42 '
match=`echo $ret | grep --null -Eo "$expect"`
if [ -z "$match" ]; then
- err "$expect" "$ret"
+ err "$expect" "$ret"
fi
new "restconf rpc using wrong prefix"
@@ -648,7 +648,7 @@ function testrun()
expect='example '
match=`echo $ret | grep --null -Eo "$expect"`
if [ -z "$match" ]; then
- err "$expect" "$ret"
+ err "$expect" "$ret"
fi
new "restconf Add subtree without key (expected error)"
@@ -658,19 +658,19 @@ function testrun()
expectpart "$(curl $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" -d '{"ietf-interfaces:interface":{"name":"eth/0/0","type":"clixon-example:eth","enabled":true}}' $proto://$addr/restconf/data/ietf-interfaces:interfaces/interface=a,b)" 0 "HTTP/$HVER 400" '{"ietf-restconf:errors":{"error":{"error-type":"rpc","error-tag":"malformed-message","error-severity":"error","error-message":"List key interface length mismatch"}}}'
if [ $RC -ne 0 ]; then
- new "Kill restconf daemon"
- stop_restconf
+ new "Kill restconf daemon"
+ stop_restconf
fi
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
@@ -688,11 +688,11 @@ fi
for proto in $protos; do
addrs="127.0.0.1"
if $IPv6 ; then
- addrs="$addrs \[::1\]"
+ addrs="$addrs \[::1\]"
fi
for addr in $addrs; do
- new "restconf test: proto:$proto addr:$addr HVER:$HVER"
- testrun $proto $addr
+ new "restconf test: proto:$proto addr:$addr HVER:$HVER"
+ testrun $proto $addr
done
done
diff --git a/test/test_restconf_basic_auth.sh b/test/test_restconf_basic_auth.sh
index 6c386447..0b6a75dd 100755
--- a/test/test_restconf_basic_auth.sh
+++ b/test/test_restconf_basic_auth.sh
@@ -68,12 +68,12 @@ module myexample{
namespace "urn:example:auth";
prefix ex;
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
container top {
leaf anonymous{
type string;
- }
+ }
leaf wilma {
type string;
}
@@ -121,7 +121,7 @@ cat < $dir/startup_db
/ex:top/ex:anonymous
permit
-
+
data-limited
limited
@@ -204,11 +204,11 @@ function testrun()
EOF
if [ $RC -ne 0 ]; then
- new "kill old restconf daemon"
- stop_restconf_pre
+ new "kill old restconf daemon"
+ stop_restconf_pre
- new "start restconf daemon"
- start_restconf -f $cfg
+ new "start restconf daemon"
+ start_restconf -f $cfg
fi
new "wait restconf"
@@ -218,8 +218,8 @@ EOF
expectpart "$(curl $CURLOPTS $user -X GET $RCPROTO://localhost/restconf/data/myexample:top)" 0 $expectcode "$expectmsg"
if [ $RC -ne 0 ]; then
- new "Kill restconf daemon"
- stop_restconf
+ new "Kill restconf daemon"
+ stop_restconf
fi
}
@@ -227,7 +227,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -281,7 +281,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_callhome.sh b/test/test_restconf_callhome.sh
index fa4d2fd1..1821a7dd 100755
--- a/test/test_restconf_callhome.sh
+++ b/test/test_restconf_callhome.sh
@@ -63,7 +63,7 @@ cat < $cfg
$cfg
ietf-netconf:startup
${YANG_INSTALLDIR}
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/backend
example_backend.so$
/usr/local/lib/$APPNAME/cli
@@ -85,14 +85,14 @@ cat < $cfg
callhome persistent
default
-
-
-
-
-
- 1
-
-
+
+
+
+
+
+ 1
+
+
127.0.0.1
4336
true
@@ -100,23 +100,23 @@ cat < $cfg
callhome periodic
default
-
-
-
- ${PERIOD_S}
- ${IDLE_TIMEOUT_S}
-
-
-
- 3
-
-
+
+
+
+ ${PERIOD_S}
+ ${IDLE_TIMEOUT_S}
+
+
+
+ 3
+
+
127.0.0.1
8336
true
- listen
+ listen
default
0.0.0.0
443
@@ -163,11 +163,11 @@ module clixon-example{
container table{
list parameter{
key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
}
}
}
@@ -220,11 +220,11 @@ commit("Commit the changes"), cli_commit();
quit("Quit"), cli_quit();
show("Show a particular state of the system"){
configuration("Show configuration"), cli_show_auto_mode("candidate", "text", true, false);{
- xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", true, false);
- cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", false, false, "report-all", "set ");
- netconf("Show configuration as netconf edit-config operation"), cli_show_auto_mode("candidate", "netconf", false, false);
- text("Show configuration as text"), cli_show_auto_mode("candidate", "text", false, false);
- json("Show configuration as JSON"), cli_show_auto_mode("candidate", "json", false, false);
+ xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", true, false);
+ cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", false, false, "report-all", "set ");
+ netconf("Show configuration as netconf edit-config operation"), cli_show_auto_mode("candidate", "netconf", false, false);
+ text("Show configuration as text"), cli_show_auto_mode("candidate", "text", false, false);
+ json("Show configuration as JSON"), cli_show_auto_mode("candidate", "json", false, false);
}
state("Show configuration and state"), cli_show_auto_mode("running", "xml", false, true);
}
@@ -282,7 +282,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg"
@@ -373,7 +373,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_continue.sh b/test/test_restconf_continue.sh
index 83b47445..24c5c2b2 100755
--- a/test/test_restconf_continue.sh
+++ b/test/test_restconf_continue.sh
@@ -53,9 +53,9 @@ module example{
key name;
leaf name{
type string;
- }
- leaf value{
- type string;
+ }
+ leaf value{
+ type string;
}
}
}
@@ -68,7 +68,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -98,7 +98,7 @@ echo -n '{"example:table":{"parameter":[' > $fjson
nr=1000
for (( i=0; i<$nr; i++ )); do
if [ $i -ne 0 ]; then
- echo -n ",
+ echo -n ",
" >> $fjson
fi
echo -n "{\"name\":\"A$i\",\"value\":\"$i\"}" >> $fjson
@@ -124,7 +124,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_err.sh b/test/test_restconf_err.sh
index 923f50d0..3241f765 100755
--- a/test/test_restconf_err.sh
+++ b/test/test_restconf_err.sh
@@ -81,17 +81,17 @@ module augment{
prefix aug;
description "Used as a base for augment";
container route-config {
- description
- "Root container for routing models";
- container dynamic {
- }
+ description
+ "Root container for routing models";
+ container dynamic {
+ }
}
container route-state {
- description
- "Root container for routing models";
- config "false";
- container dynamic {
- }
+ description
+ "Root container for routing models";
+ config "false";
+ container dynamic {
+ }
}
}
EOF
@@ -103,7 +103,7 @@ module example{
prefix ex;
import augment {
description "Just for augment";
- prefix "aug";
+ prefix "aug";
}
list a {
@@ -130,7 +130,7 @@ module example{
augment "/aug:route-config/aug:dynamic" {
container ospf {
leaf reference-bandwidth {
- type uint32;
+ type uint32;
}
}
}
@@ -139,23 +139,23 @@ module example{
description "Just for generating a invalid XML";
list parameter{
key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
}
}
container table{
list parameter{
key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
}
}
}
@@ -183,7 +183,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
new "start backend -s init -f $cfg -- -sS $fstate -v /table/parameter[name=\"4242\"]"
@@ -330,7 +330,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_http_upgrade.sh b/test/test_restconf_http_upgrade.sh
index 20bafc9d..66393e19 100755
--- a/test/test_restconf_http_upgrade.sh
+++ b/test/test_restconf_http_upgrade.sh
@@ -61,128 +61,128 @@ function testrun()
new "test params: -f $cfg -- -s"
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- sudo pkill -f clixon_backend # to be sure
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ sudo pkill -f clixon_backend # to be sure
- new "start backend -s init -f $cfg"
- start_backend -s init -f $cfg
+ new "start backend -s init -f $cfg"
+ start_backend -s init -f $cfg
fi
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
- new "kill old restconf daemon"
- stop_restconf_pre
+ new "kill old restconf daemon"
+ stop_restconf_pre
- new "start restconf daemon -o CLICON_RESTCONF_HTTP2_PLAIN=${h2enable}"
- start_restconf -f $cfg -o CLICON_RESTCONF_HTTP2_PLAIN=${h2enable}
+ new "start restconf daemon -o CLICON_RESTCONF_HTTP2_PLAIN=${h2enable}"
+ start_restconf -f $cfg -o CLICON_RESTCONF_HTTP2_PLAIN=${h2enable}
fi
if [ ${HAVE_LIBNGHTTP2} = false -a ${HAVE_HTTP1} = true ]; then # http/1 only
- new "wait restconf"
- wait_restconf
+ new "wait restconf"
+ wait_restconf
- # http/1-only always stays on http/1 in http/1 + http/2 mode
- new "restconf http1.1 no upgrade (h2:$h2enable)"
- echo "curl -Ssik --http1.1 -X GET http://localhost/.well-known/host-meta"
- expectpart "$(curl -Ssik --http1.1 -X GET http://localhost/.well-known/host-meta)" 0 "HTTP/1.1 200" "" " " " " --not-- "HTTP/2"
-
- # http/1->http/2 switched if h2enable, otherwise it stays in http/1
- new "restconf upgrade http1->http2 (h2:$h2enable)"
- echo "curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta"
- # stay on http/1
- expectpart "$(curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta)" 0 "HTTP/1.1 200" "" " " " " --not-- "HTTP/2"
+ # http/1-only always stays on http/1 in http/1 + http/2 mode
+ new "restconf http1.1 no upgrade (h2:$h2enable)"
+ echo "curl -Ssik --http1.1 -X GET http://localhost/.well-known/host-meta"
+ expectpart "$(curl -Ssik --http1.1 -X GET http://localhost/.well-known/host-meta)" 0 "HTTP/1.1 200" "" " " " " --not-- "HTTP/2"
+
+ # http/1->http/2 switched if h2enable, otherwise it stays in http/1
+ new "restconf upgrade http1->http2 (h2:$h2enable)"
+ echo "curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta"
+ # stay on http/1
+ expectpart "$(curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta)" 0 "HTTP/1.1 200" "" " " " " --not-- "HTTP/2"
- # http/2-only is always an error in http/1 + http/2 mode
- new "restconf http2 prior-knowledge (h2:$h2enable)"
- echo "curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta"
- expectpart "$(curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta 2>&1)" "16 52 55"
+ # http/2-only is always an error in http/1 + http/2 mode
+ new "restconf http2 prior-knowledge (h2:$h2enable)"
+ echo "curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta"
+ expectpart "$(curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta 2>&1)" "16 52 55"
elif [ ${HAVE_LIBNGHTTP2} = true -a ${HAVE_HTTP1} = false ]; then # http/2 only
- sleep 2 # Cannot do wait restconf
-
- # http/1-only always stays on http/1 in http/1 + http/2 mode
- new "restconf http1.1 no upgrade (h2:$h2enable)"
- echo "curl -Ssik --http1.1 -X GET http://localhost/.well-known/host-meta"
- # XXX cannot use expectpart due to null in pipe
- curl -Ssik --http1.1 -X GET http://localhost/.well-known/host-meta
- if [ $? == 0 ]; then
- err "NULL" "sucess"
- fi
+ sleep 2 # Cannot do wait restconf
+
+ # http/1-only always stays on http/1 in http/1 + http/2 mode
+ new "restconf http1.1 no upgrade (h2:$h2enable)"
+ echo "curl -Ssik --http1.1 -X GET http://localhost/.well-known/host-meta"
+ # XXX cannot use expectpart due to null in pipe
+ curl -Ssik --http1.1 -X GET http://localhost/.well-known/host-meta
+ if [ $? == 0 ]; then
+ err "NULL" "sucess"
+ fi
- # http/1->http/2 switched if h2enable, otherwise it stays in http/1
- new "restconf upgrade http1->http2 (h2:$h2enable)"
- echo "curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta"
- # stay on http/1
- curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta
- if [ $? == 0 ]; then
- err "NULL" "sucess"
- fi
+ # http/1->http/2 switched if h2enable, otherwise it stays in http/1
+ new "restconf upgrade http1->http2 (h2:$h2enable)"
+ echo "curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta"
+ # stay on http/1
+ curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta
+ if [ $? == 0 ]; then
+ err "NULL" "sucess"
+ fi
- # http/2-only is always an error in http/1 + http/2 mode
- new "restconf http2 prior-knowledge (h2:$h2enable)"
- echo "curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta"
- if $h2enable; then
- new "wait restconf"
- wait_restconf
+ # http/2-only is always an error in http/1 + http/2 mode
+ new "restconf http2 prior-knowledge (h2:$h2enable)"
+ echo "curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta"
+ if $h2enable; then
+ new "wait restconf"
+ wait_restconf
- expectpart "$(curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta 2>&1)" 0 "HTTP/2 200" "" " " " " --not-- "HTTP/1.1"
+ expectpart "$(curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta 2>&1)" 0 "HTTP/2 200" "" " " " " --not-- "HTTP/1.1"
- else
- expectpart "$(curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta 2>&1)" 0 "HTTP/2 405"
- fi
+ else
+ expectpart "$(curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta 2>&1)" 0 "HTTP/2 405"
+ fi
elif [ ${HAVE_LIBNGHTTP2} = true -a ${HAVE_HTTP1} = true ]; then # http/1 + http/2
- new "wait restconf"
- wait_restconf
-
- # http/1-only always stays on http/1 in http/1 + http/2 mode
- new "restconf http1.1 no upgrade (h2:$h2enable)"
- echo "curl -Ssik --http1.1 -X GET http://localhost/.well-known/host-meta"
- expectpart "$(curl -Ssik --http1.1 -X GET http://localhost/.well-known/host-meta)" 0 "HTTP/1.1 200" "" " " " " --not-- "HTTP/2"
-
- # http/1->http/2 switched if h2enable, otherwise it stays in http/1
- new "restconf upgrade http1->http2 (h2:$h2enable)"
- echo "curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta"
- if $h2enable; then
- # switch to http/2
- expectpart "$(curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta)" 0 "HTTP/2 200" "" " " " " "HTTP/1.1 101 Switching" "HTTP/2 200" --not-- "HTTP/1.1 200"
- else
- # stay on http/1
- expectpart "$(curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta)" 0 "HTTP/1.1 200" "" " " " " --not-- "HTTP/2"
- fi
+ new "wait restconf"
+ wait_restconf
+
+ # http/1-only always stays on http/1 in http/1 + http/2 mode
+ new "restconf http1.1 no upgrade (h2:$h2enable)"
+ echo "curl -Ssik --http1.1 -X GET http://localhost/.well-known/host-meta"
+ expectpart "$(curl -Ssik --http1.1 -X GET http://localhost/.well-known/host-meta)" 0 "HTTP/1.1 200" "" " " " " --not-- "HTTP/2"
+
+ # http/1->http/2 switched if h2enable, otherwise it stays in http/1
+ new "restconf upgrade http1->http2 (h2:$h2enable)"
+ echo "curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta"
+ if $h2enable; then
+ # switch to http/2
+ expectpart "$(curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta)" 0 "HTTP/2 200" "" " " " " "HTTP/1.1 101 Switching" "HTTP/2 200" --not-- "HTTP/1.1 200"
+ else
+ # stay on http/1
+ expectpart "$(curl -Ssik --http2 -X GET http://localhost/.well-known/host-meta)" 0 "HTTP/1.1 200" "" " " " " --not-- "HTTP/2"
+ fi
- # http/2-only is always an error in http/1 + http/2 mode
- new "restconf http2 prior-knowledge (h2:$h2enable)"
- echo "curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta"
- expectpart "$(curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta 2>&1)" "16 52 55"
+ # http/2-only is always an error in http/1 + http/2 mode
+ new "restconf http2 prior-knowledge (h2:$h2enable)"
+ echo "curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta"
+ expectpart "$(curl -Ssik --http2-prior-knowledge -X GET http://localhost/.well-known/host-meta 2>&1)" "16 52 55"
fi
if [ $RC -ne 0 ]; then
- new "Kill restconf daemon"
- stop_restconf
+ new "Kill restconf daemon"
+ stop_restconf
fi
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
diff --git a/test/test_restconf_internal.sh b/test/test_restconf_internal.sh
index 3c44ec1f..c81ec7b1 100755
--- a/test/test_restconf_internal.sh
+++ b/test/test_restconf_internal.sh
@@ -91,7 +91,7 @@ EOF
function rpcstatus()
{
if [ $# -ne 2 ]; then
- err1 "rpcstatus: # arguments: 2" "$#"
+ err1 "rpcstatus: # arguments: 2" "$#"
fi
active=$1
status=$2
@@ -107,23 +107,23 @@ EOF
expect="[0-9]* "
match=$(echo "$retx" | grep --null -Go "$expect")
if [ -z "$match" ]; then
- pid=0
+ pid=0
else
- pid=$(echo "$match" | awk -F'[<>]' '{print $3}')
+ pid=$(echo "$match" | awk -F'[<>]' '{print $3}')
fi
if [ -z "$pid" ]; then
- err "No pid return value" "$retx"
+ err "No pid return value" "$retx"
fi
if $active; then
- expect="^$active Clixon RESTCONF process /.*/clixon_restconf -f $cfg -D [0-9] .* $status 20[0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9]*Z $pid $"
+ expect="^$active Clixon RESTCONF process /.*/clixon_restconf -f $cfg -D [0-9] .* $status 20[0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9]*Z $pid $"
else
- # inactive, no startime or pid
- expect="^$active Clixon RESTCONF process /.*/clixon_restconf -f $cfg -D [0-9] .* $status $"
+ # inactive, no startime or pid
+ expect="^$active Clixon RESTCONF process /.*/clixon_restconf -f $cfg -D [0-9] .* $status $"
fi
match=$(echo "$retx" | grep --null -Go "$expect")
if [ -z "$match" ]; then
- err "$expect" "$retx"
+ err "$expect" "$retx"
fi
}
@@ -159,9 +159,9 @@ cat< $startupdb
$LOGDST
default
- 0.0.0.0
- 80
- false
+ 0.0.0.0
+ 80
+ false
${DATASTORE_TOP}>
@@ -175,7 +175,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg"
@@ -316,7 +316,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -331,7 +331,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s none -f $cfg"
start_backend -s none -f $cfg
@@ -354,7 +354,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -375,9 +375,9 @@ cat< $startupdb
$LOGDST
default
- 0.0.0.0
- 80
- false
+ 0.0.0.0
+ 80
+ false
${DATASTORE_TOP}>
@@ -392,7 +392,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s startup -f $cfg"
start_backend -s startup -f $cfg
@@ -483,7 +483,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_internal_usecases.sh b/test/test_restconf_internal_usecases.sh
index c7c94392..8e21622c 100755
--- a/test/test_restconf_internal_usecases.sh
+++ b/test/test_restconf_internal_usecases.sh
@@ -106,7 +106,7 @@ EOF
function rpcstatus()
{
if [ $# -ne 2 ]; then
- err1 "rpcstatus: # arguments: 2" "$#"
+ err1 "rpcstatus: # arguments: 2" "$#"
fi
active=$1
status=$2
@@ -122,23 +122,23 @@ EOF
expect="[0-9]* "
match=$(echo "$retx" | grep --null -Go "$expect")
if [ -z "$match" ]; then
- pid=0
+ pid=0
else
- pid=$(echo "$match" | awk -F'[<>]' '{print $3}')
+ pid=$(echo "$match" | awk -F'[<>]' '{print $3}')
fi
if [ -z "$pid" ]; then
- err "No pid return value" "$retx"
+ err "No pid return value" "$retx"
fi
if $active; then
- expect="^$active Clixon RESTCONF process /.*/clixon_restconf -f $cfg -D [0-9] .* $status 20[0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9]*Z $pid $"
+ expect="^$active Clixon RESTCONF process /.*/clixon_restconf -f $cfg -D [0-9] .* $status 20[0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9]*Z $pid $"
else
- # inactive, no startime or pid
- expect="^$active Clixon RESTCONF process /.*/clixon_restconf -f $cfg -D [0-9] .* $status $"
+ # inactive, no startime or pid
+ expect="^$active Clixon RESTCONF process /.*/clixon_restconf -f $cfg -D [0-9] .* $status $"
fi
match=$(echo "$retx" | grep --null -Go "$expect")
if [ -z "$match" ]; then
- err "$expect" "$retx"
+ err "$expect" "$retx"
fi
}
@@ -160,7 +160,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -227,7 +227,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -244,7 +244,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
@@ -288,7 +288,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -315,7 +315,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
@@ -386,7 +386,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -409,7 +409,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
@@ -459,7 +459,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_jukebox.sh b/test/test_restconf_jukebox.sh
index 49613960..d596002b 100755
--- a/test/test_restconf_jukebox.sh
+++ b/test/test_restconf_jukebox.sh
@@ -72,7 +72,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
new "start backend -s init -f $cfg -- -s"
@@ -263,7 +263,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_listkey.sh b/test/test_restconf_listkey.sh
index 9ab440a7..3d3031e5 100755
--- a/test/test_restconf_listkey.sh
+++ b/test/test_restconf_listkey.sh
@@ -74,7 +74,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -221,7 +221,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_netns.sh b/test/test_restconf_netns.sh
index d74dcda4..0387c71d 100755
--- a/test/test_restconf_netns.sh
+++ b/test/test_restconf_netns.sh
@@ -102,7 +102,7 @@ cat < $cfg
ietf-netconf:startup
clixon-restconf:allow-auth-none
${YANG_INSTALLDIR}
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/clispec
/usr/local/lib/$APPNAME/backend
example_backend.so$
@@ -123,14 +123,14 @@ module clixon-example{
prefix ex;
/* Generic config data */
container table{
- list parameter{
- key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
+ list parameter{
+ key name;
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
}
}
}
@@ -180,7 +180,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -241,7 +241,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -283,7 +283,7 @@ cat < $cfg
ietf-netconf:startup
clixon-restconf:allow-auth-none
${YANG_INSTALLDIR}
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/clispec
/usr/local/lib/$APPNAME/backend
example_backend.so$
@@ -307,7 +307,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
@@ -341,7 +341,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_nmap.sh b/test/test_restconf_nmap.sh
index 3e2a1147..3f8ac4c7 100755
--- a/test/test_restconf_nmap.sh
+++ b/test/test_restconf_nmap.sh
@@ -107,7 +107,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -128,7 +128,7 @@ if [ $RC -ne 0 ]; then
echo "sudo -u $wwwstartuser -s $clixon_restconf $RCLOG -D $DBG -f $cfg"
sudo -u $wwwstartuser -s $clixon_restconf $RCLOG -D $DBG -f $cfg &
if [ $? -ne 0 ]; then
- err1 "expected 0" "$?"
+ err1 "expected 0" "$?"
fi
fi
@@ -142,7 +142,7 @@ result=$(nmap --script ssl-ccs-injection -p 443 127.0.0.1)
# echo "result:$result"
while [[ "$result" = *"No reply from server"* ]]; do
if [ $i -ge 10 ]; then
- err "ssl-ccs-injection"
+ err "ssl-ccs-injection"
fi
sleep 1
let i++;
@@ -194,7 +194,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_notifications.sh b/test/test_restconf_notifications.sh
index b7e671ec..9ca06510 100755
--- a/test/test_restconf_notifications.sh
+++ b/test/test_restconf_notifications.sh
@@ -143,13 +143,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -n"
start_backend -s init -f $cfg -- -n # create example notification stream
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -311,7 +311,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_op.sh b/test/test_restconf_op.sh
index ea832fad..6c90d286 100755
--- a/test/test_restconf_op.sh
+++ b/test/test_restconf_op.sh
@@ -78,7 +78,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -251,7 +251,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_plain_patch.sh b/test/test_restconf_plain_patch.sh
index 5d628022..14c89b8d 100755
--- a/test/test_restconf_plain_patch.sh
+++ b/test/test_restconf_plain_patch.sh
@@ -84,7 +84,7 @@ cat < $dir/example-system.yang
namespace "http://example.com/ns/example-system";
prefix "ex";
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
container system {
leaf enable-jukebox-streaming {
@@ -105,7 +105,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -168,7 +168,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -182,7 +182,7 @@ wait_backend
if [ $RC -ne 0 ]; then
new "kill old restconf daemon"
stop_restconf_pre
-
+
new "start restconf daemon"
start_restconf -f $cfg
fi
@@ -274,7 +274,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_ssl_certs.sh b/test/test_restconf_ssl_certs.sh
index 076f4144..a2e4257e 100755
--- a/test/test_restconf_ssl_certs.sh
+++ b/test/test_restconf_ssl_certs.sh
@@ -54,7 +54,7 @@ module example{
namespace "urn:example:example";
prefix ex;
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
leaf x{
type int32;
@@ -104,7 +104,7 @@ if $genkeys; then
# create client certs
for name in $users $x1users; do
- cat< $dir/$name.cnf
+ cat< $dir/$name.cnf
[req]
prompt = no
distinguished_name = dn
@@ -115,25 +115,25 @@ O = Clixon
L = Stockholm
C = SE
EOF
- # Create client key
- openssl genpkey -algorithm RSA -out "$certdir/$name.key" || err "Generate client key"
+ # Create client key
+ openssl genpkey -algorithm RSA -out "$certdir/$name.key" || err "Generate client key"
- # Generate CSR (signing request)
- openssl req -new -config $dir/$name.cnf -key $certdir/$name.key -out $certdir/$name.csr
+ # Generate CSR (signing request)
+ openssl req -new -config $dir/$name.cnf -key $certdir/$name.key -out $certdir/$name.csr
- # Sign by CA
- openssl x509 -req -extfile $dir/$name.cnf -days 1 -passin "pass:password" -in $certdir/$name.csr -CA $cacert -CAkey $cakey -CAcreateserial -out $certdir/$name.crt || err "Generate signing client cert"
+ # Sign by CA
+ openssl x509 -req -extfile $dir/$name.cnf -days 1 -passin "pass:password" -in $certdir/$name.csr -CA $cacert -CAkey $cakey -CAcreateserial -out $certdir/$name.crt || err "Generate signing client cert"
done # client key
# invalid (days = 0)
for name in $x1users; do
- openssl x509 -req -extfile $dir/$name.cnf -days 0 -passin "pass:password" -in $certdir/$name.csr -CA $cacert -CAkey $cakey -CAcreateserial -out $certdir/$name.crt || err "Generate signing client cert"
+ openssl x509 -req -extfile $dir/$name.cnf -days 0 -passin "pass:password" -in $certdir/$name.csr -CA $cacert -CAkey $cakey -CAcreateserial -out $certdir/$name.crt || err "Generate signing client cert"
done # invalid
# create client certs with md5 -- too weak ca
for name in $x3users; do
- cat< $dir/$name.cnf
+ cat< $dir/$name.cnf
[req]
prompt = no
distinguished_name = dn
@@ -144,20 +144,20 @@ O = Clixon
L = Stockholm
C = SE
EOF
- # Create client key
- openssl genpkey -algorithm RSA -out "$certdir/$name.key" || err "Generate client key"
+ # Create client key
+ openssl genpkey -algorithm RSA -out "$certdir/$name.key" || err "Generate client key"
- # Generate CSR (signing request)
- openssl req -new -config $dir/$name.cnf -key $certdir/$name.key -out $certdir/$name.csr
+ # Generate CSR (signing request)
+ openssl req -new -config $dir/$name.cnf -key $certdir/$name.key -out $certdir/$name.csr
- # Sign by CA
- openssl x509 -req -extfile $dir/$name.cnf -days 1 -passin "pass:password" -in $certdir/$name.csr -CA $cacert -CAkey $cakey -CAcreateserial -md5 -out $certdir/$name.crt || err "Generate signing client cert"
+ # Sign by CA
+ openssl x509 -req -extfile $dir/$name.cnf -days 1 -passin "pass:password" -in $certdir/$name.csr -CA $cacert -CAkey $cakey -CAcreateserial -md5 -out $certdir/$name.crt || err "Generate signing client cert"
done # too weak ca
if false; then # XXX: How do you generate an "invalid" cert?
# create client certs from invalid CA
for name in $x2users; do
- cat< $dir/$name.cnf
+ cat< $dir/$name.cnf
[req]
prompt = no
distinguished_name = dn
@@ -168,14 +168,14 @@ O = Clixon
L = Stockholm
C = SE
EOF
- # Create client key
- openssl genpkey -algorithm RSA -out "$certdir/$name.key" || err "Generate client key"
+ # Create client key
+ openssl genpkey -algorithm RSA -out "$certdir/$name.key" || err "Generate client key"
- # Generate CSR (signing request)
- openssl req -new -config $dir/$name.cnf -key $certdir/$name.key -out $certdir/$name.csr
+ # Generate CSR (signing request)
+ openssl req -new -config $dir/$name.cnf -key $certdir/$name.key -out $certdir/$name.csr
- # Sign by CA
- openssl x509 -req -extfile $dir/$name.cnf -days 1 -passin "pass:password" -in $certdir/$name.csr -CA $xcacert -CAkey $xcakey -CAcreateserial -out $certdir/$name.crt
+ # Sign by CA
+ openssl x509 -req -extfile $dir/$name.cnf -days 1 -passin "pass:password" -in $certdir/$name.csr -CA $xcacert -CAkey $xcakey -CAcreateserial -out $certdir/$name.crt
done # invalid ca
fi # XXX
@@ -229,26 +229,26 @@ function testrun()
${DATASTORE_TOP}>
EOF
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- sudo pkill -f clixon_backend # to be sure
-
- new "start backend -s startup -f $cfg"
- start_backend -s startup -f $cfg
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ sudo pkill -f clixon_backend # to be sure
+
+ new "start backend -s startup -f $cfg"
+ start_backend -s startup -f $cfg
fi
new "wait for backend"
wait_backend
if [ $RC -ne 0 ]; then
- new "kill old restconf daemon"
- stop_restconf_pre
+ new "kill old restconf daemon"
+ stop_restconf_pre
- new "start restconf daemon"
- start_restconf -f $cfg
+ new "start restconf daemon"
+ start_restconf -f $cfg
fi
# Note, the root resource is accessed by wait_restconf to detect liveness.
@@ -288,7 +288,7 @@ EOF
expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/example:x 2>&1)" 0 "HTTP/$HVER 401"
# Unsure if clixon should fail early with SSL_VERIFY_FAIL_IF_NO_PEER_CERT, instead now fail later in
# code
-# expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/example:x 2>&1)" 0 "HTTP/$HVER 400"
+# expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/example:x 2>&1)" 0 "HTTP/$HVER 400"
new "limited invalid cert"
expectpart "$(curl $CURLOPTS --key $certdir/limited.key --cert $certdir/limited.crt -X GET $RCPROTO://localhost/restconf/data/example:x 2>&1)" 0 "HTTP/$HVER 400" "\"error-message\": \"HTTP cert verification failed: certificate has expired"
@@ -327,18 +327,18 @@ EOF
expectpart "$(curl $CURLOPTS --key $certdir/andy.key --cert $certdir/andy.crt -X GET $RCPROTO://localhost/restconf/data/example:x)" 0 "HTTP/$HVER 200" '{"example:x":42}'
if [ $RC -ne 0 ]; then
- new "Kill restconf daemon"
- stop_restconf
+ new "Kill restconf daemon"
+ stop_restconf
fi
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
diff --git a/test/test_restconf_startup.sh b/test/test_restconf_startup.sh
index efc42c0d..13baa444 100755
--- a/test/test_restconf_startup.sh
+++ b/test/test_restconf_startup.sh
@@ -57,24 +57,24 @@ function testrun(){
new "test params: -f $cfg -y $fyang $option"
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s init -f $cfg -y $fyang $option"
- start_backend -s init -f $cfg -y $fyang $option
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s init -f $cfg -y $fyang $option"
+ start_backend -s init -f $cfg -y $fyang $option
fi
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
- new "kill old restconf daemon"
- stop_restconf_pre
+ new "kill old restconf daemon"
+ stop_restconf_pre
- new "start restconf daemon"
- start_restconf -f $cfg -y $fyang $option
+ new "start restconf daemon"
+ start_restconf -f $cfg -y $fyang $option
fi
new "wait restconf"
@@ -93,19 +93,19 @@ function testrun(){
expectpart "$(curl $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data/example:x/y=42)" 0 "HTTP/$HVER 204"
if [ $RC -ne 0 ]; then
- new "Kill restconf daemon"
- stop_restconf
+ new "Kill restconf daemon"
+ stop_restconf
fi
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
diff --git a/test/test_restconf_yang_patch_json.sh b/test/test_restconf_yang_patch_json.sh
index 1fc762ef..fd417fe4 100755
--- a/test/test_restconf_yang_patch_json.sh
+++ b/test/test_restconf_yang_patch_json.sh
@@ -95,11 +95,11 @@ cat < $dir/example-system.yang
prefix ianaift;
}
import ietf-interfaces {
- /* is in yang/optional which means clixon must be installed using --opt-yang-installdir */
- prefix if;
+ /* is in yang/optional which means clixon must be installed using --opt-yang-installdir */
+ prefix if;
}
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
container system {
leaf enable-jukebox-streaming {
@@ -120,7 +120,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -321,7 +321,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_restconf_yang_patch_xml.sh b/test/test_restconf_yang_patch_xml.sh
index 0b362d70..8e263b35 100755
--- a/test/test_restconf_yang_patch_xml.sh
+++ b/test/test_restconf_yang_patch_xml.sh
@@ -93,7 +93,7 @@ cat < $dir/example-system.yang
namespace "http://example.com/ns/example-system";
prefix "ex";
import ietf-netconf-acm {
- prefix nacm;
+ prefix nacm;
}
container system {
leaf enable-jukebox-streaming {
@@ -120,7 +120,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
sudo pkill -f clixon_backend # to be sure
@@ -297,7 +297,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_rpc.sh b/test/test_rpc.sh
index ab7dd0a4..c34034d0 100755
--- a/test/test_rpc.sh
+++ b/test/test_rpc.sh
@@ -23,7 +23,7 @@ cat < $cfg
$cfg
clixon-restconf:allow-auth-none
${YANG_INSTALLDIR}
- $fyang
+ $fyang
/usr/local/lib/$APPNAME/backend
/usr/local/lib/$APPNAME/clispec
/usr/local/lib/$APPNAME/cli
@@ -42,69 +42,69 @@ module clixon-example{
prefix ex;
rpc empty {
- description "Smallest possible RPC with no input or output sections";
+ description "Smallest possible RPC with no input or output sections";
}
rpc optional {
- description "Small RPC with optional input and output";
- input {
- leaf x {
- type string;
- }
- }
- output {
- leaf x {
- type string;
- }
- }
+ description "Small RPC with optional input and output";
+ input {
+ leaf x {
+ type string;
+ }
+ }
+ output {
+ leaf x {
+ type string;
+ }
+ }
}
rpc example {
- description "Some example input/output for testing RFC7950 7.14.
+ description "Some example input/output for testing RFC7950 7.14.
RPC simply echoes the input for debugging.";
- input {
- leaf x {
- description
- "If a leaf in the input tree has a 'mandatory' statement with
+ input {
+ leaf x {
+ description
+ "If a leaf in the input tree has a 'mandatory' statement with
the value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- mandatory true;
- }
- leaf y {
- description
+ type string;
+ mandatory true;
+ }
+ leaf y {
+ description
"If a leaf in the input tree has a 'mandatory' statement with the
value 'true', the leaf MUST be present in an RPC invocation.";
- type string;
- default "42";
- }
- leaf-list z {
- description
- "If a leaf-list in the input tree has one or more default
+ type string;
+ default "42";
+ }
+ leaf-list z {
+ description
+ "If a leaf-list in the input tree has one or more default
values, the server MUST use these values (XXX not supported)";
- type string;
- }
+ type string;
+ }
- leaf w {
- description
- "If any node has a 'when' statement that would evaluate to
+ leaf w {
+ description
+ "If any node has a 'when' statement that would evaluate to
'false',then this node MUST NOT be present in the input tree.
(XXX not supported)";
- type string;
- }
- list u0 {
- description "list without key";
- leaf uk{
- type string;
- }
- }
- list u1 {
- description "list with key";
- key uk;
- leaf uk{
- type string;
- }
- leaf val{
- type string;
- }
- }
+ type string;
+ }
+ list u0 {
+ description "list without key";
+ leaf uk{
+ type string;
+ }
+ }
+ list u1 {
+ description "list with key";
+ key uk;
+ leaf uk{
+ type string;
+ }
+ leaf val{
+ type string;
+ }
+ }
choice par1 {
leaf a1{
type string;
@@ -128,35 +128,35 @@ module clixon-example{
}
}
}
- }
- output {
- leaf x {
- type string;
- }
- leaf y {
- type string;
- }
- leaf z {
- type string;
- }
- leaf w {
- type string;
- }
+ }
+ output {
+ leaf x {
+ type string;
+ }
+ leaf y {
+ type string;
+ }
+ leaf z {
+ type string;
+ }
+ leaf w {
+ type string;
+ }
- list u0 {
- leaf uk{
- type string;
- }
- }
- list u1 {
- key uk;
- leaf uk{
- type string;
- }
- leaf val{
- type string;
- }
- }
+ list u0 {
+ leaf uk{
+ type string;
+ }
+ }
+ list u1 {
+ key uk;
+ leaf uk{
+ type string;
+ }
+ leaf val{
+ type string;
+ }
+ }
choice par1 {
leaf a1{
type string;
@@ -180,7 +180,7 @@ module clixon-example{
}
}
}
- }
+ }
}
}
EOF
@@ -190,13 +190,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
@@ -335,7 +335,7 @@ for expect in "mandatory
new "expect:$expect"
match=`echo $ret | grep --null -Eo "$expect"`
if [ -z "$match" ]; then
- err "$expect" "$ret"
+ err "$expect" "$ret"
fi
done
@@ -370,7 +370,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_search_index.sh b/test/test_search_index.sh
index d8265eff..246cf41d 100755
--- a/test/test_search_index.sh
+++ b/test/test_search_index.sh
@@ -50,7 +50,7 @@ module moda{
leaf i{
description "explicit index variable";
type int32;
- cc:search_index;
+ cc:search_index;
}
leaf j{
description "non-index variable";
diff --git a/test/test_snmp_entity.sh b/test/test_snmp_entity.sh
index 7ebd7273..ad9639c4 100755
--- a/test/test_snmp_entity.sh
+++ b/test/test_snmp_entity.sh
@@ -122,12 +122,12 @@ function testinit(){
wait_backend
if [ $SN -ne 0 ]; then
- # Kill old clixon_snmp, if any
- new "Terminating any old clixon_snmp processes"
- sudo killall -q clixon_snmp
+ # Kill old clixon_snmp, if any
+ new "Terminating any old clixon_snmp processes"
+ sudo killall -q clixon_snmp
- new "Starting clixon_snmp"
- start_snmp $cfg &
+ new "Starting clixon_snmp"
+ start_snmp $cfg &
fi
new "wait snmp"
@@ -136,6 +136,17 @@ function testinit(){
function testexit(){
stop_snmp
+
+ if [ $BE -ne 0 ]; then
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
+ fi
}
ENTITY_OID=".1.3.6.1.2.1.47.1.1.1"
diff --git a/test/test_snmp_get.sh b/test/test_snmp_get.sh
index bb1a38d5..e82ccb30 100755
--- a/test/test_snmp_get.sh
+++ b/test/test_snmp_get.sh
@@ -132,6 +132,16 @@ function testinit(){
function testexit(){
stop_snmp
+ if [ $BE -ne 0 ]; then
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
+ fi
}
new "SNMP tests"
@@ -280,6 +290,9 @@ expectpart "$($snmpget $OID19)" 0 "$OID19 = Hex-STRING: 74 65 73 74 00"
new "Test SNMP getnext netSnmpHostName"
expectpart "$($snmpgetnext $OID19)" 0 "$OID20 = INTEGER: 1"
+new "Negative test: Try to set object"
+expectpart "$($snmpset $OID1 i 4 2> /dev/null)" 2 "^$"
+
new "Cleaning up"
testexit
diff --git a/test/test_snmp_ifmib.sh b/test/test_snmp_ifmib.sh
index 98ba9890..1e2251cc 100755
--- a/test/test_snmp_ifmib.sh
+++ b/test/test_snmp_ifmib.sh
@@ -165,28 +165,28 @@ EOF
function testinit(){
new "test params: -f $cfg -- -sS $fstate"
if [ $BE -ne 0 ]; then
- # Kill old backend and start a new one
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
+ # Kill old backend and start a new one
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
err "Failed to start backend"
- fi
- sudo pkill -f clixon_backend
+ fi
+ sudo pkill -f clixon_backend
- new "Starting backend"
- start_backend -s init -f $cfg -- -sS $fstate
+ new "Starting backend"
+ start_backend -s init -f $cfg -- -sS $fstate
fi
new "wait backend"
wait_backend
if [ $SN -ne 0 ]; then
- # Kill old clixon_snmp, if any
- new "Terminating any old clixon_snmp processes"
- sudo killall -q clixon_snmp
+ # Kill old clixon_snmp, if any
+ new "Terminating any old clixon_snmp processes"
+ sudo killall -q clixon_snmp
- new "Starting clixon_snmp"
- start_snmp $cfg &
+ new "Starting clixon_snmp"
+ start_snmp $cfg &
fi
new "wait snmp"
@@ -195,13 +195,21 @@ function testinit(){
function testexit(){
stop_snmp
+ if [ $BE -ne 0 ]; then
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
+ fi
}
-
new "SNMP tests"
testinit
-
# IF-MIB::interfaces
MIB=".1.3.6.1.2.1"
for (( i=1; i<23; i++ )); do
@@ -370,8 +378,8 @@ expectpart "$($snmptable IF-MIB::ifTable)" 0 "Test 2" "1400" "1000" "11:22:33:44
new "Walk the walk..."
expectpart "$($snmpwalk IF-MIB::ifTable)" 0 "IF-MIB::ifIndex.1 = INTEGER: 1" \
"IF-MIB::ifIndex.2 = INTEGER: 2" \
- "IF-MIB::ifDescr.1 = STRING: Test." \
- "IF-MIB::ifDescr.2 = STRING: Test 2." \
+ "IF-MIB::ifDescr.1 = STRING: Test" \
+ "IF-MIB::ifDescr.2 = STRING: Test 2" \
"IF-MIB::ifType.1 = INTEGER: ethernetCsmacd(6)" \
"IF-MIB::ifType.2 = INTEGER: ethernetCsmacd(6)" \
"IF-MIB::ifMtu.1 = INTEGER: 1500" \
diff --git a/test/test_snmp_rowstatus.sh b/test/test_snmp_rowstatus.sh
index e92776d5..7a3995b3 100755
--- a/test/test_snmp_rowstatus.sh
+++ b/test/test_snmp_rowstatus.sh
@@ -206,6 +206,16 @@ function testrun_removeRows()
function testexit()
{
stop_snmp
+ if [ $BE -ne 0 ]; then
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
+ fi
}
new "SNMP tests"
diff --git a/test/test_snmp_set.sh b/test/test_snmp_set.sh
index f57ff676..d2de145b 100755
--- a/test/test_snmp_set.sh
+++ b/test/test_snmp_set.sh
@@ -2,6 +2,7 @@
# snmpset. This requires deviation of MIB-YANG to make write operations
# Get default value, set new value via SNMP and check it, set new value via NETCONF and check
# Selected types from CLIXON/IF-MIB/ENTITY mib
+# Also an incomplete commit failed test
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
@@ -33,6 +34,7 @@ cat < $cfg
$fyang
$dir/$APPNAME.sock
/var/tmp/$APPNAME.pidfile
+ /usr/local/lib/$APPNAME/backend
$dir
unix:$SOCK
CLIXON-TYPES-MIB
@@ -95,18 +97,18 @@ cat < $dir/startup_db
-
-
+
+
9
9
-
+
1
aa:bb:cc:dd:ee:ff
-
+
${DATASTORE_TOP}>
EOF
@@ -116,29 +118,29 @@ function testinit(){
new "test params: -f $cfg"
if [ $BE -ne 0 ]; then
- # Kill old backend and start a new one
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err "Failed to start backend"
- fi
+ # Kill old backend and start a new one
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err "Failed to start backend"
+ fi
- sudo pkill -f clixon_backend
+ sudo pkill -f clixon_backend
- new "Starting backend"
- start_backend -s startup -f $cfg
+ new "Starting backend"
+ start_backend -s startup -f $cfg
fi
new "wait backend"
wait_backend
-
+
if [ $SN -ne 0 ]; then
- # Kill old clixon_snmp, if any
- new "Terminating any old clixon_snmp processes"
- sudo killall -q clixon_snmp
+ # Kill old clixon_snmp, if any
+ new "Terminating any old clixon_snmp processes"
+ sudo killall -q clixon_snmp
- new "Starting clixon_snmp"
- start_snmp $cfg &
+ new "Starting clixon_snmp"
+ start_snmp $cfg &
fi
new "wait snmp"
@@ -170,39 +172,40 @@ function testrun()
"STRING")
set_type="s"
;;
- "HEX STRING")
+ "HEX STRING")
set_type="x"
;;
"TIMETICKS")
set_type="t"
;;
- "IPADDRESS")
+ "IPADDRESS")
set_type="a"
;;
- "OBJID")
+ "OBJID")
set_type="o"
;;
- "BITS")
+ "BITS")
set_type="b"
;;
- *)
- set_type="s"
- ;;
+ *)
+ set_type="s"
+ ;;
esac
new "Set $name via SNMP"
if [ $type == "STRING" ]; then
- echo "$snmpset $oid $set_type $value"
- expectpart "$($snmpset $oid $set_type $value)" 0 "$type:" "$value"
+ echo "$snmpset $oid $set_type $value"
+ expectpart "$($snmpset $oid $set_type $value)" 0 "$type:" "$value"
else
- echo "$snmpset $oid $set_type $value"
- expectpart "$($snmpset $oid $set_type $value)" 0 "$type: $value2"
+ echo "$snmpset $oid $set_type $value2"
+ expectpart "$($snmpset $oid $set_type $value)" 0 "$type: $value2"
fi
+
new "Check $name via SNMP"
if [ "$type" == "STRING" ]; then
- expectpart "$($snmpget $oid)" 0 "$type:" "$value"
+ expectpart "$($snmpget $oid)" 0 "$type:" "$value"
else
- expectpart "$($snmpget $oid)" 0 "$type: $value2"
+ expectpart "$($snmpget $oid)" 0 "$type: $value2"
fi
new "Check $name via CLI"
@@ -211,6 +214,17 @@ function testrun()
function testexit(){
stop_snmp
+
+ if [ $BE -ne 0 ]; then
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
+ fi
}
new "SNMP tests"
@@ -225,7 +239,8 @@ testrun clixonExampleSleeper INTEGER -1 -1 -1 ${MIB}.1.2
testrun clixonExampleString STRING foobar foobar foobar ${MIB}.1.3
testrun ifPromiscuousMode INTEGER 1 1 true ${MIB}.1.10 # boolean
testrun ifIpAddr IPADDRESS 1.2.3.4 1.2.3.4 1.2.3.4 ${MIB}.1.13 # InetAddress
-testrun ifPhysAddress STRING ff:ee:dd:cc:bb:aa ff:ee:dd:cc:bb:aa ff:ee:dd:cc:bb:aa ${IFMIB}.2.2.1.6.1
+# XXX It was supposed to test writing hardware address type, but it is also read-only
+#testrun ifPhysAddress STRING ff:ee:dd:cc:bb:aa ff:ee:dd:cc:bb:aa ff:ee:dd:cc:bb:aa ${IFMIB}.2.2.1.6.1
# Inline testrun for rowstatus complicated logic
name=ifStackStatus
@@ -241,6 +256,28 @@ expectpart "$($snmpget $oid)" 0 "$type: active(1)"
new "Check $name via CLI"
expectpart "$($clixon_cli -1 -f $cfg show config xml)" 0 "<$name>active$name>"
+# restart backend with synthetic validation failure
+# Incomplete commit failed test: the commit fails by logging but this is not actually checked
+if [ $BE -ne 0 ]; then
+ # Kill old backend and start a new one
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err "Failed to start backend"
+ fi
+
+ sudo pkill -f clixon_backend
+
+ new "Starting backend"
+ start_backend -s startup -f $cfg -- -V CLIXON-TYPES-MIB/clixonExampleScalars/clixonExampleInteger
+fi
+
+new "wait backend"
+wait_backend
+
+new "set value with error"
+expectpart "$($snmpset ${MIB}.1.1 i 4321 2>&1)" 2 "commitFailed"
+
new "Cleaning up"
testexit
diff --git a/test/test_snmp_system.sh b/test/test_snmp_system.sh
index 922dbaf6..98bd59f3 100755
--- a/test/test_snmp_system.sh
+++ b/test/test_snmp_system.sh
@@ -107,12 +107,14 @@ function testinit(){
wait_backend
if [ $SN -ne 0 ]; then
- # Kill old clixon_snmp, if any
- new "Terminating any old clixon_snmp processes"
- sudo killall -q clixon_snmp
+ # Kill old clixon_snmp, if any
+ new "Terminating any old clixon_snmp processes"
+ sudo killall -q clixon_snmp
+
+ new "Starting clixon_snmp"
+ # XXX augmented objects seem to be registered twice: error: duplicate registration: MIB modules snmpSetSerialNo and AgentX subagent 52, session 0x562087a70e20, subsession 0x562087a820c0 (oid .1.3.6.1.6.3.1.1.6.1).
- new "Starting clixon_snmp"
- start_snmp $cfg &
+ start_snmp $cfg &
fi
new "wait snmp"
@@ -121,6 +123,16 @@ function testinit(){
function testexit(){
stop_snmp
+ if [ $BE -ne 0 ]; then
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
+ fi
}
new "SNMP tests"
@@ -217,19 +229,19 @@ expectpart "$($snmptable $OID_ORTABLE)" 0 ".*Entry 2 description.*" "IF-MIB::ifT
expectpart "$($snmptable $NAME_ORTABLE)" 0 ".*Entry 1 description.*" "IP-MIB::ip" "1:7:10:33.44"
expectpart "$($snmptable $NAME_ORTABLE)" 0 ".*Entry 2 description.*" "IF-MIB::ifTable" "129:20:58:31.11"
-new "Walk the tabbles..."
-expectpart "$($snmpwalkstr system)" 0 "SNMPv2-MIB::sysDescr = STRING: System description." \
+new "Walk the tables..."
+expectpart "$($snmpwalkstr system)" 0 "SNMPv2-MIB::sysDescr = STRING: System description" \
"SNMPv2-MIB::sysUpTime = Timeticks: (11223344) 1 day, 7:10:33.44" \
- "SNMPv2-MIB::sysContact = STRING: clixon@clicon.com." \
- "SNMPv2-MIB::sysName = STRING: Test." \
- "SNMPv2-MIB::sysLocation = STRING: Clixon HQ." \
+ "SNMPv2-MIB::sysContact = STRING: clixon@clicon.com" \
+ "SNMPv2-MIB::sysName = STRING: Test" \
+ "SNMPv2-MIB::sysLocation = STRING: Clixon HQ" \
"SNMPv2-MIB::sysServices = INTEGER: 72" \
"SNMPv2-MIB::sysORIndex.1 = INTEGER: 1" \
"SNMPv2-MIB::sysORIndex.2 = INTEGER: 2" \
"SNMPv2-MIB::sysORID.1 = OID: IP-MIB::ip" \
"SNMPv2-MIB::sysORID.2 = OID: IF-MIB::ifTable" \
- "SNMPv2-MIB::sysORDescr.1 = STRING: Entry 1 description." \
- "SNMPv2-MIB::sysORDescr.2 = STRING: Entry 2 description." \
+ "SNMPv2-MIB::sysORDescr.1 = STRING: Entry 1 description" \
+ "SNMPv2-MIB::sysORDescr.2 = STRING: Entry 2 description" \
"SNMPv2-MIB::sysORUpTime.1 = Timeticks: (11223344) 1 day, 7:10:33.44" \
"SNMPv2-MIB::sysORUpTime.2 = Timeticks: (1122111111) 129 days, 20:58:31.11"
diff --git a/test/test_sock.sh b/test/test_sock.sh
index 0a604c3b..d2feadd5 100755
--- a/test/test_sock.sh
+++ b/test/test_sock.sh
@@ -40,7 +40,7 @@ cat < $cfg
$cfg
*:*
${YANG_INSTALLDIR}
- $fyang
+ $fyang
$family
4535
$sock
@@ -56,13 +56,13 @@ EOF
new "test params: -f $cfg"
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s init -f $cfg"
- start_backend -s init -f $cfg
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s init -f $cfg"
+ start_backend -s init -f $cfg
fi
new "wait backend"
@@ -78,14 +78,14 @@ EOF
expecteof "$clixon_util_socket -a $family -s $sock -D $DBG" 0 " " "4 "
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
diff --git a/test/test_startup.sh b/test/test_startup.sh
index a90e5198..39f694ff 100755
--- a/test/test_startup.sh
+++ b/test/test_startup.sh
@@ -115,20 +115,20 @@ function testrun(){
echo "<${DATASTORE_TOP}>$edb${DATASTORE_TOP}>" > $dir/extra_db
if [ $BE -ne 0 ]; then # Bring your own backend
- # kill old backend (if any)
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
+ # kill old backend (if any)
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
new "start backend -f $cfg -s $mode -c $dir/extra_db"
- start_backend -s $mode -f $cfg -c $dir/extra_db
+ start_backend -s $mode -f $cfg -c $dir/extra_db
- new "waiting"
- wait_backend
+ new "wait backend"
+ wait_backend
else
- new "Restart backend as eg follows: -Ff $cfg -s $mode -c $dir/extra_db # $BETIMEOUT s"
- sleep $BETIMEOUT
+ new "Restart backend as eg follows: -Ff $cfg -s $mode -c $dir/extra_db # $BETIMEOUT s"
+ sleep $BETIMEOUT
fi
new "Startup test for $mode mode, check running"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "$exprun "
@@ -143,7 +143,7 @@ function testrun(){
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -167,13 +167,13 @@ function testfail(){
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -f $cfg -s $mode -c $dir/extra_db"
ret=$(start_backend -1 -s $mode -f $cfg -c $dir/extra_db 2> /dev/null)
r=$?
if [ $r -ne 255 ]; then
- err "Unexpected retval" $r
+ err "Unexpected retval" $r
fi
# permission kludges
sudo chmod 666 $dir/running_db
@@ -181,18 +181,18 @@ function testfail(){
new "Checking running unchanged"
ret=$(diff $dir/running_db <(echo "<${DATASTORE_TOP}>$rdb${DATASTORE_TOP}>"))
if [ $? -ne 0 ]; then
- err "<${DATASTORE_TOP}>$rdb${DATASTORE_TOP}>" "$ret"
- fi
+ err "<${DATASTORE_TOP}>$rdb${DATASTORE_TOP}>" "$ret"
+ fi
new "Checking startup unchanged"
ret=$(diff $dir/startup_db <(echo "<${DATASTORE_TOP}>$sdb${DATASTORE_TOP}>"))
if [ $? -ne 0 ]; then
- err "<${DATASTORE_TOP}>$sdb${DATASTORE_TOP}>" "$ret"
+ err "<${DATASTORE_TOP}>$sdb${DATASTORE_TOP}>" "$ret"
fi
new "Checking extra unchanged"
ret=$(diff $dir/extra_db <(echo "<${DATASTORE_TOP}>$edb${DATASTORE_TOP}>"))
if [ $? -ne 0 ]; then
- err "<${DATASTORE_TOP}>$edb${DATASTORE_TOP}>" "$ret"
+ err "<${DATASTORE_TOP}>$edb${DATASTORE_TOP}>" "$ret"
fi
}
diff --git a/test/test_submodule.sh b/test/test_submodule.sh
index 674960c3..e6328b39 100755
--- a/test/test_submodule.sh
+++ b/test/test_submodule.sh
@@ -183,7 +183,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -278,7 +278,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_transaction.sh b/test/test_transaction.sh
index fc83e622..34d11292 100755
--- a/test/test_transaction.sh
+++ b/test/test_transaction.sh
@@ -122,23 +122,23 @@ function checklog(){
echo "grep \"transaction_log $s line:$l0\" $flog"
t=$(grep -n "transaction_log $s" $flog)
if [ -z "$t" ]; then
- echo -e "\e[31m\nError in Test$testnr [$testname]:"
- if [ $# -gt 0 ]; then
- echo "Not found \"$s\" on line $l0"
- echo
- fi
- echo -e "\e[0m"
- exit -1
+ echo -e "\e[31m\nError in Test$testnr [$testname]:"
+ if [ $# -gt 0 ]; then
+ echo "Not found \"$s\" on line $l0"
+ echo
+ fi
+ echo -e "\e[0m"
+ exit -1
fi
l1=$(echo "$t" | awk -F ":" '{print $1}')
if [ $l1 -ne $l0 ]; then
- echo -e "\e[31m\nError in Test$testnr [$testname]:"
- if [ $# -gt 0 ]; then
- echo "Expected match on line $l0, found on $l1"
- echo
- fi
- echo -e "\e[0m"
- exit -1
+ echo -e "\e[31m\nError in Test$testnr [$testname]:"
+ if [ $# -gt 0 ]; then
+ echo "Expected match on line $l0, found on $l1"
+ echo
+ fi
+ echo -e "\e[0m"
+ exit -1
fi
}
@@ -149,7 +149,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -l f$flog -- -t -v \"/x/y[a='$errnr']\""
start_backend -s init -f $cfg -l f$flog -- -t -v "/x/y[a='$errnr']" # -t means transaction logging
@@ -451,7 +451,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_transaction_restart.sh b/test/test_transaction_restart.sh
index e5e5e208..3f646e5f 100755
--- a/test/test_transaction_restart.sh
+++ b/test/test_transaction_restart.sh
@@ -26,12 +26,12 @@ module trans{
container table{
list parameter{
key name;
- leaf name{
- type string;
- }
- leaf value{
- type string;
- }
+ leaf name{
+ type string;
+ }
+ leaf value{
+ type string;
+ }
}
}
}
@@ -66,23 +66,23 @@ function checklog(){
t=$(grep -n "transaction_log $s" $flog)
if [ -z "$t" ]; then
- echo -e "\e[31m\nError in Test$testnr [$testname]:"
- if [ $# -gt 0 ]; then
- echo "Not found in log"
- echo
- fi
- echo -e "\e[0m"
- exit -1
+ echo -e "\e[31m\nError in Test$testnr [$testname]:"
+ if [ $# -gt 0 ]; then
+ echo "Not found in log"
+ echo
+ fi
+ echo -e "\e[0m"
+ exit -1
fi
l1=$(echo "$t" | awk -F ":" '{print $1}')
if [ $l1 -ne $l0 ]; then
- echo -e "\e[31m\nError in Test$testnr [$testname]:"
- if [ $# -gt 0 ]; then
- echo "Expected match on line $l0, found on $l1"
- echo
- fi
- echo -e "\e[0m"
- exit -1
+ echo -e "\e[31m\nError in Test$testnr [$testname]:"
+ if [ $# -gt 0 ]; then
+ echo "Expected match on line $l0, found on $l1"
+ echo
+ fi
+ echo -e "\e[0m"
+ exit -1
fi
}
@@ -93,7 +93,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -l f$flog -- -t /foo"
start_backend -s init -f $cfg -l f$flog -- -t /foo # -t means transaction logging (foo is dummy)
@@ -136,7 +136,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_type.sh b/test/test_type.sh
index aaaf697d..2a495639 100755
--- a/test/test_type.sh
+++ b/test/test_type.sh
@@ -165,10 +165,10 @@ module example{
}
typedef mybits {
description "Test adding several bits";
- type bits {
- bit create;
- bit read;
- bit write;
+ type bits {
+ bit create;
+ bit read;
+ bit write;
}
}
leaf mbits{
@@ -235,13 +235,13 @@ function testrun(){
EOF
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s init -f $cfg"
- start_backend -s init -f $cfg
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s init -f $cfg"
+ start_backend -s init -f $cfg
fi
new "wait backend"
@@ -657,14 +657,14 @@ EOF
expectpart "$($clixon_cli -1f $cfg -l o set bool wrong)" 255 "'wrong' is not a boolean value"
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
diff --git a/test/test_type_range.sh b/test/test_type_range.sh
index 35a7b3e8..9d8e94d3 100755
--- a/test/test_type_range.sh
+++ b/test/test_type_range.sh
@@ -222,10 +222,10 @@ function testrange(){
post=$4
if [ $t = "string" ]; then # special case for string type error msg
- len=$(echo -n "$eval" | wc -c | awk '{print $1}'; )
- errmsg="String length $len out of range: 1$post - 10$post, 14$post - 20$post"
+ len=$(echo -n "$eval" | wc -c | awk '{print $1}'; )
+ errmsg="String length $len out of range: 1$post - 10$post, 14$post - 20$post"
else
- errmsg="Number $eval$post out of range: 1$post - 10$post, 14$post - 20$post"
+ errmsg="Number $eval$post out of range: 1$post - 10$post, 14$post - 20$post"
fi
new "generated cli set $t leaf invalid"
@@ -271,7 +271,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -322,7 +322,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_union.sh b/test/test_union.sh
index f6d3cf20..f49de56a 100755
--- a/test/test_union.sh
+++ b/test/test_union.sh
@@ -81,7 +81,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -104,7 +104,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_unique.sh b/test/test_unique.sh
index 176f061f..3450e99a 100755
--- a/test/test_unique.sh
+++ b/test/test_unique.sh
@@ -84,7 +84,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
# start new backend
@@ -212,7 +212,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_unique_descendant.sh b/test/test_unique_descendant.sh
index b82ef446..33c1e1f3 100755
--- a/test/test_unique_descendant.sh
+++ b/test/test_unique_descendant.sh
@@ -57,7 +57,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
# start new backend
@@ -110,7 +110,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_upgrade_auto.sh b/test/test_upgrade_auto.sh
index 69543002..ddaa3480 100755
--- a/test/test_upgrade_auto.sh
+++ b/test/test_upgrade_auto.sh
@@ -29,33 +29,33 @@ module example-a{
organization "foo.";
contact "fo@example.com";
description
- "foo.";
+ "foo.";
revision 2017-12-01 {
- description "Initial revision.";
+ description "Initial revision.";
}
container system {
- leaf a {
- type string;
- description "no change";
- }
- leaf b {
- type string;
- description "rename tag";
- }
- leaf x {
- type string;
- description "delete";
- }
- leaf host-name {
- type uint32;
- description "modify type";
- }
- leaf z {
- description "move to alt";
- type string;
- }
+ leaf a {
+ type string;
+ description "no change";
+ }
+ leaf b {
+ type string;
+ description "rename tag";
+ }
+ leaf x {
+ type string;
+ description "delete";
+ }
+ leaf host-name {
+ type uint32;
+ description "modify type";
+ }
+ leaf z {
+ description "move to alt";
+ type string;
+ }
}
container alt {
}
@@ -71,37 +71,37 @@ module example-a {
organization "foo.";
contact "fo@example.com";
description
- "foo.";
+ "foo.";
revision 2017-12-20 {
- description "Create y, delete x, replace host-name, move z";
+ description "Create y, delete x, replace host-name, move z";
}
revision 2017-12-01 {
- description "Initial revision.";
+ description "Initial revision.";
}
container system {
- leaf a {
- type string;
- description "no change";
- }
- leaf c {
- type string;
- description "rename tag";
- }
- leaf host-name {
- type string;
- description "replace";
- }
- leaf y {
- type string;
- description "create";
- }
+ leaf a {
+ type string;
+ description "no change";
+ }
+ leaf c {
+ type string;
+ description "rename tag";
+ }
+ leaf host-name {
+ type string;
+ description "replace";
+ }
+ leaf y {
+ type string;
+ description "create";
+ }
}
container alt {
- leaf z {
- description "move to alt";
- type string;
- }
+ leaf z {
+ description "move to alt";
+ type string;
+ }
}
}
EOF
@@ -116,10 +116,10 @@ module example-b {
organization "foo.";
contact "fo@example.com";
description
- "foo.";
+ "foo.";
revision 2017-12-20 {
- description "Remove all";
+ description "Remove all";
}
}
EOF
@@ -252,13 +252,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s $mode -f $cfg"
start_backend -s $mode -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
new "Check running db content"
@@ -269,7 +269,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_upgrade_checkold.sh b/test/test_upgrade_checkold.sh
index 197e6f4e..3da12564 100755
--- a/test/test_upgrade_checkold.sh
+++ b/test/test_upgrade_checkold.sh
@@ -102,46 +102,46 @@ module A{
}
EOF
else
- rm -f $fyang1
+ rm -f $fyang1
fi
for modstate in true false; do
- if $modstate; then
- modstatestr="default 42 A 2016-01-01 urn:example:a "
-# modstatestr="42 A 2016-01-01 urn:example:a "
- else
- modstatestr=""
- fi
- for xml in true false; do
- if $xml; then
- xmltag="old"
- expectxml="Failed to find YANG spec of XML node: $xmltag with parent: config in namespace: urn:example:a "
- if $oldyang; then
- if $modstate; then
- expectxml=""
- fi
- elif $modstate; then
- expectxml="Internal error: No yang files found matching \"A@2016-01-01\" in the list of CLICON_YANG_DIRs "
- fi
- else # xml false
- xmltag="wrong"
- expectxml="Failed to find YANG spec of XML node: $xmltag with parent: config in namespace: urn:example:a "
- if ! $oldyang; then
- if $modstate; then
- expectxml="Internal error: No yang files found matching \"A@2016-01-01\" in the list of CLICON_YANG_DIRs "
- fi
- fi
- fi
- cat < $dir/startup_db
- <${DATASTORE_TOP}>
- $modstatestr
- <$xmltag xmlns="urn:example:a"/>
- ${DATASTORE_TOP}>
+ if $modstate; then
+ modstatestr="default 42 A 2016-01-01 urn:example:a "
+# modstatestr="42 A 2016-01-01 urn:example:a "
+ else
+ modstatestr=""
+ fi
+ for xml in true false; do
+ if $xml; then
+ xmltag="old"
+ expectxml="Failed to find YANG spec of XML node: $xmltag with parent: config in namespace: urn:example:a "
+ if $oldyang; then
+ if $modstate; then
+ expectxml=""
+ fi
+ elif $modstate; then
+ expectxml="Internal error: No yang files found matching \"A@2016-01-01\" in the list of CLICON_YANG_DIRs "
+ fi
+ else # xml false
+ xmltag="wrong"
+ expectxml="Failed to find YANG spec of XML node: $xmltag with parent: config in namespace: urn:example:a "
+ if ! $oldyang; then
+ if $modstate; then
+ expectxml="Internal error: No yang files found matching \"A@2016-01-01\" in the list of CLICON_YANG_DIRs "
+ fi
+ fi
+ fi
+ cat < $dir/startup_db
+ <${DATASTORE_TOP}>
+ $modstatestr
+ <$xmltag xmlns="urn:example:a"/>
+ ${DATASTORE_TOP}>
EOF
- # Here is actual call
- new "$j. checkold:$checkold oldyang:$oldyang modstate:$modstate xmlok:$xml"
- testrun "$checkold" "$expectxml"
- let j++
- done
+ # Here is actual call
+ new "$j. checkold:$checkold oldyang:$oldyang modstate:$modstate xmlok:$xml"
+ testrun "$checkold" "$expectxml"
+ let j++
+ done
done
done
done
diff --git a/test/test_upgrade_failsafe.sh b/test/test_upgrade_failsafe.sh
index e70c6616..8aa98a5a 100755
--- a/test/test_upgrade_failsafe.sh
+++ b/test/test_upgrade_failsafe.sh
@@ -275,16 +275,16 @@ runtest(){
new "test params: -f $cfg"
# Bring your own backend
if [ $BE -ne 0 ]; then
- # kill old backend (if any)
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s $mode -f $cfg -o \"CLICON_XMLDB_MODSTATE=$modstate\""
- start_backend -s $mode -f $cfg -o "CLICON_XMLDB_MODSTATE=$modstate"
+ # kill old backend (if any)
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s $mode -f $cfg -o \"CLICON_XMLDB_MODSTATE=$modstate\""
+ start_backend -s $mode -f $cfg -o "CLICON_XMLDB_MODSTATE=$modstate"
-# new "Restart backend as eg follows: -Ff $cfg -s $mode -o \"CLICON_XMLDB_MODSTATE=$modstate\" ($BETIMEOUT s)"
+# new "Restart backend as eg follows: -Ff $cfg -s $mode -o \"CLICON_XMLDB_MODSTATE=$modstate\" ($BETIMEOUT s)"
fi
new "wait backend"
@@ -295,19 +295,19 @@ runtest(){
# If given check startup db XML
if [ -n "$expstart" ]; then
- new "Check startup db content"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "$expstart "
+ new "Check startup db content"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "$expstart "
fi
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
diff --git a/test/test_upgrade_interfaces.sh b/test/test_upgrade_interfaces.sh
index 58aa5d4c..d65ce20d 100755
--- a/test/test_upgrade_interfaces.sh
+++ b/test/test_upgrade_interfaces.sh
@@ -60,70 +60,70 @@ module interfaces{
prefix "if";
import ietf-yang-types {
- prefix yang;
+ prefix yang;
}
revision 2014-05-08 {
- description
- "Initial revision.";
- reference
- "RFC 7223: A YANG Data Model for Interface Management";
+ description
+ "Initial revision.";
+ reference
+ "RFC 7223: A YANG Data Model for Interface Management";
}
feature if-mib {
- description
- "This feature indicates that the device implements
+ description
+ "This feature indicates that the device implements
the IF-MIB.";
- reference
- "RFC 2863: The Interfaces Group MIB";
+ reference
+ "RFC 2863: The Interfaces Group MIB";
}
container interfaces {
- description
- "Interface configuration parameters.";
+ description
+ "Interface configuration parameters.";
- list interface {
- key "name";
- leaf name {
- type string;
- }
- leaf description {
- type string;
- }
- leaf type {
- type string;
- mandatory true;
- }
- leaf link-up-down-trap-enable {
- if-feature if-mib;
- type enumeration {
- enum enabled;
- enum disabled;
- }
- }
- }
+ list interface {
+ key "name";
+ leaf name {
+ type string;
+ }
+ leaf description {
+ type string;
+ }
+ leaf type {
+ type string;
+ mandatory true;
+ }
+ leaf link-up-down-trap-enable {
+ if-feature if-mib;
+ type enumeration {
+ enum enabled;
+ enum disabled;
+ }
+ }
+ }
}
container interfaces-state {
- list interface {
- key "name";
- leaf name {
- type string;
- }
- leaf admin-status {
- if-feature if-mib;
- type enumeration {
- enum up;
- enum down;
- enum testing;
- }
- mandatory true;
- }
- container statistics {
- leaf in-octets {
- type yang:counter64;
- }
- leaf in-unicast-pkts {
- type yang:counter64;
- }
- }
- }
+ list interface {
+ key "name";
+ leaf name {
+ type string;
+ }
+ leaf admin-status {
+ if-feature if-mib;
+ type enumeration {
+ enum up;
+ enum down;
+ enum testing;
+ }
+ mandatory true;
+ }
+ container statistics {
+ leaf in-octets {
+ type yang:counter64;
+ }
+ leaf in-unicast-pkts {
+ type yang:counter64;
+ }
+ }
+ }
}
}
EOF
@@ -135,7 +135,7 @@ module interfaces{
prefix "if";
import ietf-yang-types {
- prefix yang;
+ prefix yang;
}
revision 2018-02-20 {
description
@@ -144,64 +144,64 @@ module interfaces{
"RFC 8343: A YANG Data Model for Interface Management";
}
revision 2014-05-08 {
- description
- "Initial revision.";
- reference
- "RFC 7223: A YANG Data Model for Interface Management";
+ description
+ "Initial revision.";
+ reference
+ "RFC 7223: A YANG Data Model for Interface Management";
}
feature if-mib {
- description
- "This feature indicates that the device implements
+ description
+ "This feature indicates that the device implements
the IF-MIB.";
- reference
- "RFC 2863: The Interfaces Group MIB";
+ reference
+ "RFC 2863: The Interfaces Group MIB";
}
container interfaces {
- description
- "Interface configuration parameters.";
+ description
+ "Interface configuration parameters.";
- list interface {
- key "name";
- leaf name {
- type string;
- }
- container docs{
- description "Original description is wrapped and renamed";
- leaf descr {
- type string;
- }
+ list interface {
+ key "name";
+ leaf name {
+ type string;
}
- leaf type {
- type string;
- mandatory true;
- }
- leaf link-up-down-trap-enable {
- if-feature if-mib;
- type enumeration {
- enum enabled;
- enum disabled;
- }
- }
- leaf admin-status {
- if-feature if-mib;
- type enumeration {
- enum up;
- enum down;
- enum testing;
- }
- mandatory true;
- }
- container statistics {
- leaf in-octets {
- type decimal64{
+ container docs{
+ description "Original description is wrapped and renamed";
+ leaf descr {
+ type string;
+ }
+ }
+ leaf type {
+ type string;
+ mandatory true;
+ }
+ leaf link-up-down-trap-enable {
+ if-feature if-mib;
+ type enumeration {
+ enum enabled;
+ enum disabled;
+ }
+ }
+ leaf admin-status {
+ if-feature if-mib;
+ type enumeration {
+ enum up;
+ enum down;
+ enum testing;
+ }
+ mandatory true;
+ }
+ container statistics {
+ leaf in-octets {
+ type decimal64{
fraction-digits 3;
}
- }
- leaf in-unicast-pkts {
- type yang:counter64;
- }
- }
- }
+ }
+ leaf in-unicast-pkts {
+ type yang:counter64;
+ }
+ }
+ }
}
}
EOF
@@ -261,31 +261,31 @@ function testrun(){
new "test params: -s startup -f $cfg -- -u"
# Bring your own backend
if [ $BE -ne 0 ]; then
- # kill old backend (if any)
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s startup -f $cfg -- -u"
- start_backend -s startup -f $cfg -- -u
+ # kill old backend (if any)
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s startup -f $cfg -- -u"
+ start_backend -s startup -f $cfg -- -u
fi
- new "waiting"
+ new "wait backend"
wait_backend
new "Check running db content"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "$runxml "
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
diff --git a/test/test_upgrade_interfaces_rfc7895.sh b/test/test_upgrade_interfaces_rfc7895.sh
index 49b72302..42cea8c8 100755
--- a/test/test_upgrade_interfaces_rfc7895.sh
+++ b/test/test_upgrade_interfaces_rfc7895.sh
@@ -60,70 +60,70 @@ module interfaces{
prefix "if";
import ietf-yang-types {
- prefix yang;
+ prefix yang;
}
revision 2014-05-08 {
- description
- "Initial revision.";
- reference
- "RFC 7223: A YANG Data Model for Interface Management";
+ description
+ "Initial revision.";
+ reference
+ "RFC 7223: A YANG Data Model for Interface Management";
}
feature if-mib {
- description
- "This feature indicates that the device implements
+ description
+ "This feature indicates that the device implements
the IF-MIB.";
- reference
- "RFC 2863: The Interfaces Group MIB";
+ reference
+ "RFC 2863: The Interfaces Group MIB";
}
container interfaces {
- description
- "Interface configuration parameters.";
+ description
+ "Interface configuration parameters.";
- list interface {
- key "name";
- leaf name {
- type string;
- }
- leaf description {
- type string;
- }
- leaf type {
- type string;
- mandatory true;
- }
- leaf link-up-down-trap-enable {
- if-feature if-mib;
- type enumeration {
- enum enabled;
- enum disabled;
- }
- }
- }
+ list interface {
+ key "name";
+ leaf name {
+ type string;
+ }
+ leaf description {
+ type string;
+ }
+ leaf type {
+ type string;
+ mandatory true;
+ }
+ leaf link-up-down-trap-enable {
+ if-feature if-mib;
+ type enumeration {
+ enum enabled;
+ enum disabled;
+ }
+ }
+ }
}
container interfaces-state {
- list interface {
- key "name";
- leaf name {
- type string;
- }
- leaf admin-status {
- if-feature if-mib;
- type enumeration {
- enum up;
- enum down;
- enum testing;
- }
- mandatory true;
- }
- container statistics {
- leaf in-octets {
- type yang:counter64;
- }
- leaf in-unicast-pkts {
- type yang:counter64;
- }
- }
- }
+ list interface {
+ key "name";
+ leaf name {
+ type string;
+ }
+ leaf admin-status {
+ if-feature if-mib;
+ type enumeration {
+ enum up;
+ enum down;
+ enum testing;
+ }
+ mandatory true;
+ }
+ container statistics {
+ leaf in-octets {
+ type yang:counter64;
+ }
+ leaf in-unicast-pkts {
+ type yang:counter64;
+ }
+ }
+ }
}
}
EOF
@@ -135,7 +135,7 @@ module interfaces{
prefix "if";
import ietf-yang-types {
- prefix yang;
+ prefix yang;
}
revision 2018-02-20 {
description
@@ -144,64 +144,64 @@ module interfaces{
"RFC 8343: A YANG Data Model for Interface Management";
}
revision 2014-05-08 {
- description
- "Initial revision.";
- reference
- "RFC 7223: A YANG Data Model for Interface Management";
+ description
+ "Initial revision.";
+ reference
+ "RFC 7223: A YANG Data Model for Interface Management";
}
feature if-mib {
- description
- "This feature indicates that the device implements
+ description
+ "This feature indicates that the device implements
the IF-MIB.";
- reference
- "RFC 2863: The Interfaces Group MIB";
+ reference
+ "RFC 2863: The Interfaces Group MIB";
}
container interfaces {
- description
- "Interface configuration parameters.";
+ description
+ "Interface configuration parameters.";
- list interface {
- key "name";
- leaf name {
- type string;
- }
- container docs{
- description "Original description is wrapped and renamed";
- leaf descr {
- type string;
- }
+ list interface {
+ key "name";
+ leaf name {
+ type string;
}
- leaf type {
- type string;
- mandatory true;
- }
- leaf link-up-down-trap-enable {
- if-feature if-mib;
- type enumeration {
- enum enabled;
- enum disabled;
- }
- }
- leaf admin-status {
- if-feature if-mib;
- type enumeration {
- enum up;
- enum down;
- enum testing;
- }
- mandatory true;
- }
- container statistics {
- leaf in-octets {
- type decimal64{
+ container docs{
+ description "Original description is wrapped and renamed";
+ leaf descr {
+ type string;
+ }
+ }
+ leaf type {
+ type string;
+ mandatory true;
+ }
+ leaf link-up-down-trap-enable {
+ if-feature if-mib;
+ type enumeration {
+ enum enabled;
+ enum disabled;
+ }
+ }
+ leaf admin-status {
+ if-feature if-mib;
+ type enumeration {
+ enum up;
+ enum down;
+ enum testing;
+ }
+ mandatory true;
+ }
+ container statistics {
+ leaf in-octets {
+ type decimal64{
fraction-digits 3;
}
- }
- leaf in-unicast-pkts {
- type yang:counter64;
- }
- }
- }
+ }
+ leaf in-unicast-pkts {
+ type yang:counter64;
+ }
+ }
+ }
}
}
EOF
@@ -258,31 +258,31 @@ function testrun(){
new "test params: -s startup -f $cfg -- -u"
# Bring your own backend
if [ $BE -ne 0 ]; then
- # kill old backend (if any)
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s startup -f $cfg -- -u"
- start_backend -s startup -f $cfg -- -u
+ # kill old backend (if any)
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s startup -f $cfg -- -u"
+ start_backend -s startup -f $cfg -- -u
fi
- new "waiting"
+ new "wait backend"
wait_backend
new "Check running db content"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "$runxml "
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
diff --git a/test/test_upgrade_module.sh b/test/test_upgrade_module.sh
index 19f970a0..26574a67 100755
--- a/test/test_upgrade_module.sh
+++ b/test/test_upgrade_module.sh
@@ -169,23 +169,23 @@ function checklog(){
new "Check $s in log on line $l0"
t=$(grep -n "$s" $log)
if [ -z "$t" ]; then
- echo -e "\e[31m\nError in Test$testnr [$testname]:"
- if [ $# -gt 0 ]; then
- echo "Not found in log"
- echo
- fi
- echo -e "\e[0m"
- exit -1
+ echo -e "\e[31m\nError in Test$testnr [$testname]:"
+ if [ $# -gt 0 ]; then
+ echo "Not found in log"
+ echo
+ fi
+ echo -e "\e[0m"
+ exit -1
fi
l1=$(echo "$t" | awk -F ":" '{print $1}')
if [ $l1 -ne $l0 ]; then
- echo -e "\e[31m\nError in Test$testnr [$testname]:"
- if [ $# -gt 0 ]; then
- echo "Expected match on line $l0, found on $l1"
- echo
- fi
- echo -e "\e[0m"
- exit -1
+ echo -e "\e[31m\nError in Test$testnr [$testname]:"
+ if [ $# -gt 0 ]; then
+ echo "Expected match on line $l0, found on $l1"
+ echo
+ fi
+ echo -e "\e[0m"
+ exit -1
fi
}
@@ -198,13 +198,13 @@ function checknolog(){
t=$(grep -n "$s" $log)
# echo "t:$t"
if [ -n "$t" ]; then
- echo -e "\e[31m\nError in Test$testnr [$testname]:"
- if [ $# -gt 0 ]; then
- echo "$s found in log"
- echo
- fi
- echo -e "\e[0m"
- exit -1
+ echo -e "\e[31m\nError in Test$testnr [$testname]:"
+ if [ $# -gt 0 ]; then
+ echo "$s found in log"
+ echo
+ fi
+ echo -e "\e[0m"
+ exit -1
fi
}
@@ -224,34 +224,34 @@ function testrun(){
new "test params: -f $cfg"
# Bring your own backend
if [ $BE -ne 0 ]; then
- # kill old backend (if any)
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s startup -f $cfg -l f$log -- -u"
- start_backend -s startup -f $cfg -l f$log -- -u
+ # kill old backend (if any)
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s startup -f $cfg -l f$log -- -u"
+ start_backend -s startup -f $cfg -l f$log -- -u
fi
new "wait backend"
wait_backend
if $flag; then
- checklog "$match" $line
+ checklog "$match" $line
else
- checknolog "$match"
+ checknolog "$match"
fi
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
diff --git a/test/test_upgrade_quit.sh b/test/test_upgrade_quit.sh
index 178e1dbd..ed4165f8 100755
--- a/test/test_upgrade_quit.sh
+++ b/test/test_upgrade_quit.sh
@@ -47,80 +47,80 @@ module interfaces{
prefix "if";
import ietf-yang-types {
- prefix yang;
+ prefix yang;
}
revision 2014-05-08 {
- description
- "Initial revision.";
- reference
- "RFC 7223: A YANG Data Model for Interface Management";
+ description
+ "Initial revision.";
+ reference
+ "RFC 7223: A YANG Data Model for Interface Management";
}
feature if-mib {
- description
- "This feature indicates that the device implements
+ description
+ "This feature indicates that the device implements
the IF-MIB.";
- reference
- "RFC 2863: The Interfaces Group MIB";
+ reference
+ "RFC 2863: The Interfaces Group MIB";
}
leaf foo{
description "Should not appear";
- type string;
- default "bar";
+ type string;
+ default "bar";
}
container interfaces {
- description
- "Interface configuration parameters.";
+ description
+ "Interface configuration parameters.";
- list interface {
- key "name";
- leaf name {
- type string;
- }
- leaf description {
- type string;
- }
+ list interface {
+ key "name";
+ leaf name {
+ type string;
+ }
+ leaf description {
+ type string;
+ }
leaf foo{
description "Should not appear";
type string;
- default "bar";
+ default "bar";
}
- leaf type {
- type string;
- mandatory true;
- }
- leaf link-up-down-trap-enable {
- if-feature if-mib;
- type enumeration {
- enum enabled;
- enum disabled;
- }
- }
- }
+ leaf type {
+ type string;
+ mandatory true;
+ }
+ leaf link-up-down-trap-enable {
+ if-feature if-mib;
+ type enumeration {
+ enum enabled;
+ enum disabled;
+ }
+ }
+ }
}
container interfaces-state {
- list interface {
- key "name";
- leaf name {
- type string;
- }
- leaf admin-status {
- if-feature if-mib;
- type enumeration {
- enum up;
- enum down;
- enum testing;
- }
- mandatory true;
- }
- container statistics {
- leaf in-octets {
- type yang:counter64;
- }
- leaf in-unicast-pkts {
- type yang:counter64;
- }
- }
- }
+ list interface {
+ key "name";
+ leaf name {
+ type string;
+ }
+ leaf admin-status {
+ if-feature if-mib;
+ type enumeration {
+ enum up;
+ enum down;
+ enum testing;
+ }
+ mandatory true;
+ }
+ container statistics {
+ leaf in-octets {
+ type yang:counter64;
+ }
+ leaf in-unicast-pkts {
+ type yang:counter64;
+ }
+ }
+ }
}
}
@@ -133,7 +133,7 @@ module interfaces{
prefix "if";
import ietf-yang-types {
- prefix yang;
+ prefix yang;
}
revision 2018-02-20 {
description
@@ -142,74 +142,74 @@ module interfaces{
"RFC 8343: A YANG Data Model for Interface Management";
}
revision 2014-05-08 {
- description
- "Initial revision.";
- reference
- "RFC 7223: A YANG Data Model for Interface Management";
+ description
+ "Initial revision.";
+ reference
+ "RFC 7223: A YANG Data Model for Interface Management";
}
feature if-mib {
- description
- "This feature indicates that the device implements
+ description
+ "This feature indicates that the device implements
the IF-MIB.";
- reference
- "RFC 2863: The Interfaces Group MIB";
+ reference
+ "RFC 2863: The Interfaces Group MIB";
}
leaf foo{
description "Should not appear";
- type string;
- default "fie";
+ type string;
+ default "fie";
}
container interfaces {
- description
- "Interface configuration parameters.";
+ description
+ "Interface configuration parameters.";
- list interface {
- key "name";
- leaf name {
- type string;
- }
+ list interface {
+ key "name";
+ leaf name {
+ type string;
+ }
leaf foo{
description "Should not appear";
type string;
- default "bar";
+ default "bar";
}
- container docs{
+ container docs{
description "Original description is wrapped and renamed";
- leaf descr {
- type string;
- }
+ leaf descr {
+ type string;
+ }
}
- leaf type {
- type string;
- mandatory true;
- }
- leaf link-up-down-trap-enable {
- if-feature if-mib;
- type enumeration {
- enum enabled;
- enum disabled;
- }
- }
- leaf admin-status {
- if-feature if-mib;
- type enumeration {
- enum up;
- enum down;
- enum testing;
- }
- mandatory true;
- }
- container statistics {
- leaf in-octets {
- type decimal64{
+ leaf type {
+ type string;
+ mandatory true;
+ }
+ leaf link-up-down-trap-enable {
+ if-feature if-mib;
+ type enumeration {
+ enum enabled;
+ enum disabled;
+ }
+ }
+ leaf admin-status {
+ if-feature if-mib;
+ type enumeration {
+ enum up;
+ enum down;
+ enum testing;
+ }
+ mandatory true;
+ }
+ container statistics {
+ leaf in-octets {
+ type decimal64{
fraction-digits 3;
}
- }
- leaf in-unicast-pkts {
- type yang:counter64;
- }
- }
- }
+ }
+ leaf in-unicast-pkts {
+ type yang:counter64;
+ }
+ }
+ }
}
}
EOF
diff --git a/test/test_upgrade_repair.sh b/test/test_upgrade_repair.sh
index e83297ad..3d5c208b 100755
--- a/test/test_upgrade_repair.sh
+++ b/test/test_upgrade_repair.sh
@@ -111,13 +111,13 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s $mode -f $cfg"
start_backend -s $mode -f $cfg
fi
-new "waiting"
+new "wait backend"
wait_backend
new "Check running db content is failsafe"
@@ -147,7 +147,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_upgrade_simple.sh b/test/test_upgrade_simple.sh
index d8682b0f..650d2a99 100755
--- a/test/test_upgrade_simple.sh
+++ b/test/test_upgrade_simple.sh
@@ -37,13 +37,13 @@ module $APPNAME {
namespace "urn:example:simple";
prefix he;
revision 2019-04-17 {
- description
- "Clixon hello world example";
+ description
+ "Clixon hello world example";
}
container hello{
- container world{
- presence true;
- }
+ container world{
+ presence true;
+ }
}
}
EOF
@@ -55,7 +55,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -78,7 +78,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -91,17 +91,17 @@ module $APPNAME {
namespace "urn:example:simple";
prefix he;
revision 2020-01-01 {
- description
- "Test new revision";
+ description
+ "Test new revision";
}
revision 2019-04-17 {
- description
- "Clixon hello world example";
+ description
+ "Clixon hello world example";
}
container hello{
- container world{
- presence true;
- }
+ container world{
+ presence true;
+ }
}
}
EOF
@@ -111,11 +111,11 @@ EOF
if [ $BE -ne 0 ]; then
new "start backend -s running -f $cfg"
start_backend -s running -f $cfg
-
- new "waiting"
- wait_backend
fi
+new "wait backend"
+wait_backend
+
new "netconf get config"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
@@ -124,7 +124,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_when_mandatory.sh b/test/test_when_mandatory.sh
new file mode 100755
index 00000000..71a69dbd
--- /dev/null
+++ b/test/test_when_mandatory.sh
@@ -0,0 +1,309 @@
+#!/usr/bin/env bash
+# Yang when conditional and mandatory
+# Testing of validation phase.
+# Variants:
+# - One level and two levels of non-presence containers
+# - when-condition true and false
+# - empty vs extra leaf in non-presence container
+# - mandatory leaf present or not
+
+# Magic line must be first in script (see README.md)
+s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
+
+APPNAME=example
+
+cfg=$dir/conf_yang.xml
+fyang=$dir/test.yang
+
+cat < $cfg
+
+ $cfg
+ ${YANG_INSTALLDIR}
+ $fyang
+ /usr/local/lib/$APPNAME/clispec
+ /usr/local/lib/$APPNAME/cli
+ $APPNAME
+ /usr/local/var/$APPNAME/$APPNAME.sock
+ /usr/local/var/$APPNAME/$APPNAME.pidfile
+ /usr/local/var/$APPNAME
+
+EOF
+
+cat < $fyang
+module $APPNAME{
+ yang-version 1.1;
+ namespace "urn:example:clixon";
+ prefix ex;
+ identity routing-protocol {
+ description
+ "Base identity from which routing protocol identities are
+ derived.";
+ }
+ identity direct {
+ base routing-protocol;
+ description
+ "Routing pseudo-protocol which provides routes to directly
+ connected networks.";
+ }
+ identity static {
+ base routing-protocol;
+ description
+ "Static routing pseudo-protocol.";
+ }
+ list x {
+ key "type";
+ leaf type {
+ type identityref {
+ base routing-protocol;
+ }
+ }
+ container y {
+ when "../type='static'" {
+ description
+ "This container is only valid for the 'static'
+ routing protocol.";
+ }
+ leaf name{
+ type string;
+ mandatory true;
+ }
+ leaf extra{
+ type string;
+ }
+ }
+ }
+ list x2 {
+ key "type";
+ leaf type {
+ type identityref {
+ base routing-protocol;
+ }
+ }
+ container y2 {
+ when "../type='static'" {
+ description
+ "This container is only valid for the 'static'
+ routing protocol.";
+ }
+ container y3 {
+ leaf name{
+ type string;
+ mandatory true;
+ }
+ leaf extra{
+ type string;
+ }
+ }
+ }
+ }
+ list x3 {
+ key "type";
+ leaf type {
+ type identityref {
+ base routing-protocol;
+ }
+ }
+ container y2 {
+ container y3 {
+ when "../../type='static'" {
+ description
+ "This container is only valid for the 'static'
+ routing protocol.";
+ }
+ leaf name{
+ type string;
+ mandatory true;
+ }
+ leaf extra{
+ type string;
+ }
+ }
+ }
+ }
+}
+EOF
+
+new "test params: -f $cfg"
+
+if [ $BE -ne 0 ]; then
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s init -f $cfg"
+ start_backend -s init -f $cfg
+fi
+
+new "wait backend"
+wait_backend
+
+new "First: have mandatory leaf under an empty when-conditioned ccntainer"
+
+new "when false + no name"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "direct " "" " "
+
+new "validate ok"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when: discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when true + no name"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static " "" " "
+
+new "validate fail"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "application missing-element y error Mandatory variable of x in module example "
+
+new "when true + name"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static a " "" " "
+
+new "validate ok"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when: discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "Second: have mandatory leaf under a non-empty when-conditioned ccntainer"
+
+new "when false + no name + extra"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "direct b " "" " "
+
+new "validate fail extra"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "application operation-failed error Failed WHEN condition of y in module example (WHEN xpath is ../type='static') "
+
+new "when: discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when true + no name + extra"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static b " "" " "
+
+new "validate fail"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "application missing-element name error Mandatory variable of y in module example "
+
+new "when true + name"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static a b " "" " "
+
+new "validate ok"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when: discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "Third: have mandatory leaf under two empty when-conditioned ccntainer"
+new "when false + no name"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "direct " "" " "
+
+new "validate ok"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when: discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when true + no name"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static " "" " "
+
+new "validate fail"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "application missing-element y2 error Mandatory variable of x2 in module example "
+
+new "when true + name"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static a " "" " "
+
+new "validate ok"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when: discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "Fourth: have mandatory leaf under two non-empty when-conditioned ccntainer"
+
+new "when false + no name + extra"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "direct b " "" " "
+
+new "validate fail extra"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "application operation-failed error Failed WHEN condition of y2 in module example (WHEN xpath is ../type='static') "
+
+new "when: discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when true + no name + extra"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static b " "" " "
+
+new "validate fail"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "application missing-element name error Mandatory variable of y3 in module example "
+
+new "when true + name"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static a b " "" " "
+
+new "validate ok"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when: discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "Fifth: have mandatory leaf under one empty and one when-conditioned ccntainer"
+new "when false + no name"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "direct " "" " "
+
+new "validate ok"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when: discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when true + no name"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static " "" " "
+
+new "validate fail"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "application missing-element y2 error Mandatory variable of x3 in module example "
+
+new "when true + name"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static a " "" " "
+
+new "validate ok"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when: discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "Sixth: have mandatory leaf under one non-empty and one when-conditioned ccntainer"
+
+new "when false + no name + extra"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "direct b " "" " "
+
+new "validate fail extra"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "application operation-failed error Failed WHEN condition of y3 in module example (WHEN xpath is ../../type='static') "
+
+new "when: discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when true + no name + extra"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static b " "" " "
+
+new "validate fail"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "application missing-element name error Mandatory variable of y3 in module example "
+
+new "when true + name"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static a b " "" " "
+
+new "validate ok"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+new "when: discard-changes"
+expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+
+if [ $BE -ne 0 ]; then
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
+fi
+
+rm -rf $dir
+
+new "endtest"
+endtest
diff --git a/test/test_when_must.sh b/test/test_when_must.sh
index 942a3111..61944819 100755
--- a/test/test_when_must.sh
+++ b/test/test_when_must.sh
@@ -94,7 +94,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -144,7 +144,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_with_default.sh b/test/test_with_default.sh
index 6df7836d..423db538 100755
--- a/test/test_with_default.sh
+++ b/test/test_with_default.sh
@@ -69,7 +69,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -105,7 +105,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_xml.sh b/test/test_xml.sh
index bdf3bfa4..61d917bc 100755
--- a/test/test_xml.sh
+++ b/test/test_xml.sh
@@ -174,7 +174,7 @@ expecteof "$clixon_util_xml -o" 0 ' ' ' '
new "prolog element misc*"
expecteof "$clixon_util_xml -o" 0 ' ' ' '
-
+
# We allow it as an internal necessity for parsing of xml fragments
#new "double element error"
#expecteof "$clixon_util_xml" 255 ' ' ''
diff --git a/test/test_xml_trees.sh b/test/test_xml_trees.sh
index 5334f54a..4176de40 100755
--- a/test/test_xml_trees.sh
+++ b/test/test_xml_trees.sh
@@ -39,10 +39,10 @@ module example {
type int32;
}
list a{
- key x;
- leaf x{
- type int32;
- }
+ key x;
+ leaf x{
+ type int32;
+ }
}
}
}
diff --git a/test/test_xml_validate.sh b/test/test_xml_validate.sh
index f39b9758..d7dc4166 100755
--- a/test/test_xml_validate.sh
+++ b/test/test_xml_validate.sh
@@ -19,8 +19,8 @@ module example {
revision 2019-01-13;
container a{
container b{
- leaf c {
- type string;
+ leaf c {
+ type string;
}
}
}
diff --git a/test/test_xpath_functions.sh b/test/test_xpath_functions.sh
index 2721383a..8c2953dd 100755
--- a/test/test_xpath_functions.sh
+++ b/test/test_xpath_functions.sh
@@ -61,16 +61,16 @@ module $APPNAME{
list mylist{ /* contains */
key id;
leaf id {
- type string;
- }
- leaf site {
- /* If the XPath expression is defined in a substatement to a data
- * node that represents configuration, the accessible tree is the
- * data in the datastore where the context node exists.
- * The "when" statement makes its parent data definition statement conditional.
- */
- when "contains(../../class,'foo') or contains(../../class,'bar')";
- type int32;
+ type string;
+ }
+ leaf site {
+ /* If the XPath expression is defined in a substatement to a data
+ * node that represents configuration, the accessible tree is the
+ * data in the datastore where the context node exists.
+ * The "when" statement makes its parent data definition statement conditional.
+ */
+ when "contains(../../class,'foo') or contains(../../class,'bar')";
+ type int32;
}
}
}
@@ -87,9 +87,9 @@ module $APPNAME{
leaf flags {
description "See RFC 7950 Sec 10.6.1";
type bits{
- bit UP;
- bit PROMISCUOUS;
- bit DISABLED;
+ bit UP;
+ bit PROMISCUOUS;
+ bit DISABLED;
}
}
}
@@ -97,13 +97,13 @@ module $APPNAME{
when 'derived-from(type, "ex:ethernet")';
leaf mtu {
type uint32;
- }
+ }
}
augment "/ex:interface" {
when 'derived-from-or-self(type, "ex:ethernet")';
leaf crc {
type uint32;
- }
+ }
}
/* Example derved from yangmodels ietf-mpls-ldp.yang */
container mustnot{
@@ -114,7 +114,7 @@ module $APPNAME{
}
container mycont{
must "not (../../ex:mustlist[ex:name!=current()/../ex:name])" {
- description
+ description
"Only one list instance is allowed.";
}
leaf foo{
@@ -129,8 +129,8 @@ module $APPNAME{
container system {
container ntp {
presence
- "Enables the NTP client unless the 'enabled' leaf
- (which defaults to 'true') is set to 'false'";
+ "Enables the NTP client unless the 'enabled' leaf
+ (which defaults to 'true') is set to 'false'";
}
}
container ntp {
@@ -143,7 +143,7 @@ module $APPNAME{
from the 'ntp/associations' list.";
leaf port {
type int16;
- }
+ }
}
}
EOF
@@ -154,7 +154,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -246,7 +246,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_yang.sh b/test/test_yang.sh
index 6116be9a..cf994241 100755
--- a/test/test_yang.sh
+++ b/test/test_yang.sh
@@ -35,7 +35,7 @@ module $APPNAME{
namespace "urn:example:clixon";
include example-types;
revision 2020-12-01 {
- description "Added table/parameter/value as the primary data example";
+ description "Added table/parameter/value as the primary data example";
}
extension c-define {
description "Example from RFC 6020";
@@ -158,7 +158,7 @@ show("Show a particular state of the system"){
xpath("Show configuration") ("XPATH expression") ("Namespace"), show_conf_xpath("candidate");
yang("Show yang specs"), show_yang(); {
example("Show example yang spec"), show_yang("example");
- }
+ }
}
EOF
@@ -168,7 +168,7 @@ if [ "$BE" -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf "$cfg"
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f "$cfg"
@@ -308,7 +308,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f "$cfg"
diff --git a/test/test_yang_action.sh b/test/test_yang_action.sh
index aabc8713..ea7ec402 100755
--- a/test/test_yang_action.sh
+++ b/test/test_yang_action.sh
@@ -63,7 +63,7 @@ if [ $BE -ne 0 ]; then # Bring your own backend
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg -- -a /sfarm:server/sfarm:reset"
start_backend -s init -f $cfg -- -a /sfarm:server/sfarm:reset
@@ -82,7 +82,7 @@ if [ $BE -ne 0 ]; then # Bring your own backend
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_yang_anydata.sh b/test/test_yang_anydata.sh
index c232c424..53ecbdae 100755
--- a/test/test_yang_anydata.sh
+++ b/test/test_yang_anydata.sh
@@ -52,12 +52,12 @@ module any{
anydata u4;
}
rpc myrpc {
- input {
- anydata u7;
- }
- output {
- anydata u8;
- }
+ input {
+ anydata u7;
+ }
+ output {
+ anydata u8;
+ }
}
}
EOF
@@ -112,21 +112,21 @@ function testrun()
unknown=$2
if $unknown; then # treat unknown as anydata or not
- if $startup; then # If startup
- XML="$XMLA$XMLU"
- else
- XML="$XMLA"
- unknownreply="application unknown-element u3 error Failed to find YANG spec of XML node: u3 with parent: b in namespace: urn:example:unknown "
- fi
+ if $startup; then # If startup
+ XML="$XMLA$XMLU"
+ else
+ XML="$XMLA"
+ unknownreply="application unknown-element u3 error Failed to find YANG spec of XML node: u3 with parent: b in namespace: urn:example:unknown "
+ fi
else
- XML="$XMLA"
- unknownreply="application unknown-element u3 error Failed to find YANG spec of XML node: u3 with parent: b in namespace: urn:example:unknown "
+ XML="$XMLA"
+ unknownreply="application unknown-element u3 error Failed to find YANG spec of XML node: u3 with parent: b in namespace: urn:example:unknown "
fi
if $startup; then # get config from startup
- F="ietf-netconf:startup "
+ F="ietf-netconf:startup "
else
- F=""
+ F=""
fi
cat < $cfg
@@ -152,9 +152,9 @@ function testrun()
EOF
if $startup; then
- # Only positive startup test, ie dont add XMLU if unknown not treated as anyxml
- # and check for errors
- cat < $dir/startup_db
+ # Only positive startup test, ie dont add XMLU if unknown not treated as anyxml
+ # and check for errors
+ cat < $dir/startup_db
<${DATASTORE_TOP}>
$XML
${DATASTORE_TOP}>
@@ -162,42 +162,42 @@ EOF
fi
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -zf $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- if $startup; then
- new "start backend -s startup -f $cfg -- -sS $fstate"
- start_backend -s startup -f $cfg -- -sS $fstate
- else
- new "start backend -s init -f $cfg -- -sS $fstate"
- start_backend -s init -f $cfg -- -sS $fstate
- fi
+ new "kill old backend"
+ sudo clixon_backend -zf $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ if $startup; then
+ new "start backend -s startup -f $cfg -- -sS $fstate"
+ start_backend -s startup -f $cfg -- -sS $fstate
+ else
+ new "start backend -s init -f $cfg -- -sS $fstate"
+ start_backend -s init -f $cfg -- -sS $fstate
+ fi
fi
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then
- new "kill old restconf daemon"
- stop_restconf_pre
+ new "kill old restconf daemon"
+ stop_restconf_pre
- new "start restconf daemon"
- start_restconf -f $cfg
+ new "start restconf daemon"
+ start_restconf -f $cfg
fi
new "wait restconf"
wait_restconf
if ! $startup; then # If not startup, add xml using netconf
- new "Put anydata"
- expecteof_netconf "$clixon_netconf -qf $cfg -D $DBG" 0 "$DEFAULTHELLO" "$XMLA " "" " "
+ new "Put anydata"
+ expecteof_netconf "$clixon_netconf -qf $cfg -D $DBG" 0 "$DEFAULTHELLO" "$XMLA " "" " "
- new "Put unknown"
- expecteof_netconf "$clixon_netconf -qf $cfg -D $DBG" 0 "$DEFAULTHELLO" "$XMLU " "$unknownreply"
+ new "Put unknown"
+ expecteof_netconf "$clixon_netconf -qf $cfg -D $DBG" 0 "$DEFAULTHELLO" "$XMLU " "$unknownreply"
- new "commit"
- expecteof_netconf "$clixon_netconf -qf $cfg -D $DBG" 0 "$DEFAULTHELLO" " " "" " "
+ new "commit"
+ expecteof_netconf "$clixon_netconf -qf $cfg -D $DBG" 0 "$DEFAULTHELLO" " " "" " "
fi
new "Get candidate"
@@ -231,7 +231,7 @@ EOF
new "Get state (negative test)"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "error-message>Failed to find YANG spec of XML node: u5 with parent: sb in namespace: urn:example:unknown. Internal error, state callback returned invalid XML from plugin: example_backend" ""
- new "restconf get state(negative)"
+ new "restconf get state(negative)"
expectpart "$(curl $CURLOPTS -X GET -H "Accept: application/yang-data+xml" $RCPROTO://localhost/restconf/data?content=nonconfig)" 0 "HTTP/$HVER 412" "operation-failed u5 "
# RPC:s take "not-supported" as OK: syntax OK and according to mdeol, just not implemented in
@@ -247,20 +247,20 @@ EOF
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "88 " "unknown-element " ""
if [ $RC -ne 0 ]; then
- new "Kill restconf daemon"
- stop_restconf
+ new "Kill restconf daemon"
+ stop_restconf
fi
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
- sudo pkill -u root -f clixon_backend
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
+ sudo pkill -u root -f clixon_backend
fi
}
diff --git a/test/test_yang_bind.sh b/test/test_yang_bind.sh
index 140dfa0d..9f3b5198 100755
--- a/test/test_yang_bind.sh
+++ b/test/test_yang_bind.sh
@@ -53,8 +53,8 @@ module match{
description "Note same as parent to catch false positives 2a/2b";
key k;
leaf k{
- type uint32;
- }
+ type uint32;
+ }
}
anyxml any;
}
diff --git a/test/test_yang_default.sh b/test/test_yang_default.sh
index 85fb2f8e..2416a282 100755
--- a/test/test_yang_default.sh
+++ b/test/test_yang_default.sh
@@ -47,8 +47,8 @@ module example-default {
}
container a{
leaf d0 {
- description "container default";
- type int32;
+ description "container default";
+ type int32;
default 88;
}
list b {
@@ -57,12 +57,12 @@ module example-default {
type string;
}
leaf d1 {
- description "direct default";
- type string;
+ description "direct default";
+ type string;
default "foo";
}
leaf d2 { /* <-- ys */
- description "default in type";
+ description "default in type";
type def;
}
}
@@ -81,7 +81,7 @@ if [ $BE -ne 0 ]; then # Bring your own backend
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s $db -f $cfg"
start_backend -s $db -f $cfg
@@ -148,7 +148,7 @@ if [ $BE -ne 0 ]; then # Bring your own backend
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_yang_deviation.sh b/test/test_yang_deviation.sh
index e8023989..e911a845 100755
--- a/test/test_yang_deviation.sh
+++ b/test/test_yang_deviation.sh
@@ -38,10 +38,10 @@ module example-base{
grouping system-top {
container system {
must "daytime or time"; /* deviate delete removes this */
- leaf daytime{ /* deviate not-supported removes this */
+ leaf daytime{ /* deviate not-supported removes this */
type string;
}
- leaf time{
+ leaf time{
type string;
}
list name-server {
@@ -58,7 +58,7 @@ module example-base{
}
leaf type {
type string;
- /* deviate add adds "default admin" here */
+ /* deviate add adds "default admin" here */
}
}
}
@@ -82,13 +82,13 @@ function testrun()
new "test params: -f $cfg"
if [ "$BE" -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -zf "$cfg"
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s init -f $cfg"
- start_backend -s init -f "$cfg"
+ new "kill old backend"
+ sudo clixon_backend -zf "$cfg"
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s init -f $cfg"
+ start_backend -s init -f "$cfg"
fi
new "wait backend"
@@ -98,11 +98,11 @@ function testrun()
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "bob " "" " "
if $mustdate; then # fail since there is neither date or daytime (delete rule)
- new "netconf validate expect error"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "application operation-failed error Failed MUST xpath 'daytime or time' of 'system' in module example-base "
+ new "netconf validate expect error"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "application operation-failed error Failed MUST xpath 'daytime or time' of 'system' in module example-base "
else
- new "netconf validate ok"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+ new "netconf validate ok"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
fi
new "Add time"
@@ -112,44 +112,44 @@ function testrun()
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
if $daytime; then # not-supported rule
- new "Add example-base daytime - supported"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "Sept17 " "" " "
+ new "Add example-base daytime - supported"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "Sept17 " "" " "
else # Not supported
- new "Add example-base daytime - expect error not supported"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "Sept17 " "" "application unknown-element daytime error Failed to find YANG spec of XML node: daytime with parent: system in namespace: urn:example:base "
+ new "Add example-base daytime - expect error not supported"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "Sept17 " "" "application unknown-element daytime error Failed to find YANG spec of XML node: daytime with parent: system in namespace: urn:example:base "
fi # daytime supported
new "netconf commit"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
-
+
if $admindefault; then # add rule
- new "Get type admin expected"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "bob admin "
+ new "Get type admin expected"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "bob admin "
else
- new "Get type none expected"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+ new "Get type none expected"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
fi
# Add 2 name-servers
new "Add two name-servers"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "aa bb " "" " "
if $maxel1; then # add two and check if it fails
- new "netconf validate 2 element fail"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "protocol operation-failed too-many-elements error /system/name-server "
+ new "netconf validate 2 element fail"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" "protocol operation-failed too-many-elements error /system/name-server "
else
- new "netconf validate 2 elements ok"
- expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
+ new "netconf validate 2 elements ok"
+ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
fi
if [ "$BE" -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f "$cfg"
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f "$cfg"
fi
} # testrun
diff --git a/test/test_yang_extension.sh b/test/test_yang_extension.sh
index 54114038..01a83cda 100755
--- a/test/test_yang_extension.sh
+++ b/test/test_yang_extension.sh
@@ -107,7 +107,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -131,7 +131,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_yang_load.sh b/test/test_yang_load.sh
index 83a480c6..a7f51c98 100755
--- a/test/test_yang_load.sh
+++ b/test/test_yang_load.sh
@@ -77,7 +77,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -100,7 +100,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -147,7 +147,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -190,7 +190,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
stop_backend -f $cfg
sudo pkill -u root -f clixon_backend
@@ -233,7 +233,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -276,7 +276,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
@@ -321,7 +321,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -366,7 +366,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
@@ -411,7 +411,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_yang_models_ietf.sh b/test/test_yang_models_ietf.sh
index 32e8805a..e1752c36 100755
--- a/test/test_yang_models_ietf.sh
+++ b/test/test_yang_models_ietf.sh
@@ -44,12 +44,12 @@ EOF
files=$(find ${YANG_STANDARD_DIR}/ietf/RFC -type f -name "*.yang")
for f in $files; do
if [ -n "$(head -1 $f|grep '^module')" ]; then
- # Mask old revision
- if [ $f = ${YANG_STANDARD_DIR}/ietf/RFC/ietf-yang-types@2010-09-24.yang ]; then
- continue;
- fi
- new "$clixon_cli -D $DBG -1f $cfg -y $f show version"
- expectpart "$($clixon_cli -D $DBG -1f $cfg -y $f show version)" 0 "${CLIXON_VERSION}"
+ # Mask old revision
+ if [ $f = ${YANG_STANDARD_DIR}/ietf/RFC/ietf-yang-types@2010-09-24.yang ]; then
+ continue;
+ fi
+ new "$clixon_cli -D $DBG -1f $cfg -y $f show version"
+ expectpart "$($clixon_cli -D $DBG -1f $cfg -y $f show version)" 0 "${CLIXON_VERSION}"
fi
done
diff --git a/test/test_yang_namespace.sh b/test/test_yang_namespace.sh
index 3ee7f496..605e5156 100755
--- a/test/test_yang_namespace.sh
+++ b/test/test_yang_namespace.sh
@@ -65,7 +65,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
@@ -137,7 +137,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_yang_wdcc.sh b/test/test_yang_wdcc.sh
index 1eaaceea..1b388eb1 100755
--- a/test/test_yang_wdcc.sh
+++ b/test/test_yang_wdcc.sh
@@ -89,21 +89,21 @@ show("Show a particular state of the system"){
xml("Show configuration and state as XML")
default("With-default mode"){
report-all @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all");
- trim @datamodelshow, cli_show_auto("candidate", "xml", false, false, "trim");
- explicit @datamodelshow, cli_show_auto("candidate", "xml", false, false, "explicit");
- report-all-tagged @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged");
- report-all-tagged-default @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged-default");
- report-all-tagged-strip @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged-strip");
+ trim @datamodelshow, cli_show_auto("candidate", "xml", false, false, "trim");
+ explicit @datamodelshow, cli_show_auto("candidate", "xml", false, false, "explicit");
+ report-all-tagged @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged");
+ report-all-tagged-default @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged-default");
+ report-all-tagged-strip @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged-strip");
}
state("Show configuration and state")
xml("Show configuration and state as XML")
default("With-default mode"){
- report-all @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all");
- trim @datamodelshow, cli_show_auto("running", "xml", false, true, "trim");
- explicit @datamodelshow, cli_show_auto("running", "xml", false, true, "explicit");
- report-all-tagged @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged");
- report-all-tagged-default @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged-default");
- report-all-tagged-strip @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged-strip");
+ report-all @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all");
+ trim @datamodelshow, cli_show_auto("running", "xml", false, true, "trim");
+ explicit @datamodelshow, cli_show_auto("running", "xml", false, true, "explicit");
+ report-all-tagged @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged");
+ report-all-tagged-default @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged-default");
+ report-all-tagged-strip @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged-strip");
}
}
EOF
@@ -123,7 +123,7 @@ if [ $BE -ne 0 ]; then # Bring your own backend
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s $db -f $cfg"
start_backend -s $db -f $cfg
@@ -241,7 +241,7 @@ if [ $BE -ne 0 ]; then # Bring your own backend
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_yang_when.sh b/test/test_yang_when.sh
index 69f02260..b759e2bf 100755
--- a/test/test_yang_when.sh
+++ b/test/test_yang_when.sh
@@ -72,13 +72,13 @@ function testrun()
{
new "test params: -f $cfg"
if [ $BE -ne 0 ]; then
- new "kill old backend"
- sudo clixon_backend -z -f $cfg
- if [ $? -ne 0 ]; then
- err
- fi
- new "start backend -s init -f $cfg"
- start_backend -s init -f $cfg
+ new "kill old backend"
+ sudo clixon_backend -z -f $cfg
+ if [ $? -ne 0 ]; then
+ err
+ fi
+ new "start backend -s init -f $cfg"
+ start_backend -s init -f $cfg
fi
new "wait backend"
wait_backend
@@ -126,14 +126,14 @@ function testrun()
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " " "" " "
if [ $BE -ne 0 ]; then
- new "Kill backend"
- # Check if premature kill
- pid=$(pgrep -u root -f clixon_backend)
- if [ -z "$pid" ]; then
- err "backend already dead"
- fi
- # kill backend
- stop_backend -f $cfg
+ new "Kill backend"
+ # Check if premature kill
+ pid=$(pgrep -u root -f clixon_backend)
+ if [ -z "$pid" ]; then
+ err "backend already dead"
+ fi
+ # kill backend
+ stop_backend -f $cfg
fi
}
@@ -261,7 +261,7 @@ if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
@@ -296,7 +296,7 @@ if [ $BE -ne 0 ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/test_yang_with_defaults.sh b/test/test_yang_with_defaults.sh
index b65eef15..99cbb025 100755
--- a/test/test_yang_with_defaults.sh
+++ b/test/test_yang_with_defaults.sh
@@ -98,20 +98,20 @@ module example {
}
}
container cedv {
- description
- "Container for test with explicit default value - EDV";
- leaf edv {
- type string;
- default "edv";
- }
+ description
+ "Container for test with explicit default value - EDV";
+ leaf edv {
+ type string;
+ default "edv";
+ }
}
container cdv {
- description
- "Container for test with default value - DV";
- leaf dv {
- type string;
- default "dv";
- }
+ description
+ "Container for test with default value - DV";
+ leaf dv {
+ type string;
+ default "dv";
+ }
}
}
}
@@ -133,21 +133,21 @@ show("Show a particular state of the system"){
xml("Show configuration and state as XML")
default("With-default mode"){
report-all @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all");
- trim @datamodelshow, cli_show_auto("candidate", "xml", false, false, "trim");
- explicit @datamodelshow, cli_show_auto("candidate", "xml", false, false, "explicit");
- report-all-tagged @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged");
- report-all-tagged-default @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged-default");
- report-all-tagged-strip @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged-strip");
+ trim @datamodelshow, cli_show_auto("candidate", "xml", false, false, "trim");
+ explicit @datamodelshow, cli_show_auto("candidate", "xml", false, false, "explicit");
+ report-all-tagged @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged");
+ report-all-tagged-default @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged-default");
+ report-all-tagged-strip @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged-strip");
}
state("Show configuration and state")
xml("Show configuration and state as XML")
default("With-default mode"){
- report-all @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all");
- trim @datamodelshow, cli_show_auto("running", "xml", false, true, "trim");
- explicit @datamodelshow, cli_show_auto("running", "xml", false, true, "explicit");
- report-all-tagged @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged");
- report-all-tagged-default @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged-default");
- report-all-tagged-strip @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged-strip");
+ report-all @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all");
+ trim @datamodelshow, cli_show_auto("running", "xml", false, true, "trim");
+ explicit @datamodelshow, cli_show_auto("running", "xml", false, true, "explicit");
+ report-all-tagged @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged");
+ report-all-tagged-default @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged-default");
+ report-all-tagged-strip @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged-strip");
}
}
EOF
@@ -180,7 +180,7 @@ if [ $BE -ne 0 ]; then # Bring your own backend
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
- err
+ err
fi
new "start backend -s $db -f $cfg -- -sS $fstate"
start_backend -s $db -f $cfg -- -sS $fstate
@@ -639,7 +639,7 @@ if [ $BE -ne 0 ]; then # Bring your own backend
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
- err "backend already dead"
+ err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
diff --git a/test/vagrant/clixon.sh b/test/vagrant/clixon.sh
index 54a869ba..1fd8ac70 100755
--- a/test/vagrant/clixon.sh
+++ b/test/vagrant/clixon.sh
@@ -19,7 +19,7 @@ if [ ! $(id -u clicon) ]; then
elif [ $release = "alpine" ]; then
sudo adduser -D -H clicon
sudo adduser $wwwuser clicon
- else
+ else
sudo useradd -M -U clicon;
sudo usermod -a -G clicon vagrant; # start clixon tests as this users
sudo usermod -a -G clicon $wwwuser;
@@ -29,7 +29,7 @@ fi
# Fcgi restconf requires /www-data directory for fcgi socket
if [ ${with_restconf} = fcgi ]; then
if [ ! -d /www-data ]; then
- sudo mkdir /www-data
+ sudo mkdir /www-data
fi
sudo chown $wwwuser /www-data
sudo chgrp $wwwuser /www-data
diff --git a/test/vagrant/mem.sh b/test/vagrant/mem.sh
index 106e1d8b..c2767b8f 100755
--- a/test/vagrant/mem.sh
+++ b/test/vagrant/mem.sh
@@ -13,7 +13,7 @@ for pid in $pids; do
# echo "ps -o rss,vsize,cmd -h -p $pid"
line=$(ps -o rss,vsize,cmd -h -p $pid)
if [ -z "$line" ]; then
- continue;
+ continue;
fi
rss=$(echo "$line"| awk '{print $1}')
let rss=rss/1000
diff --git a/test/vagrant/nginx.sh b/test/vagrant/nginx.sh
index 71078d1f..18dc933c 100755
--- a/test/vagrant/nginx.sh
+++ b/test/vagrant/nginx.sh
@@ -50,18 +50,18 @@ http {
listen 80 default_server;
listen localhost:80 default_server;
listen [::]:80 default_server;
- server_name localhost;
- server_name _;
+ server_name localhost;
+ server_name _;
#:well-known is in root, otherwise restconf would be ok
- location / {
- fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
- include fastcgi_params;
+ location / {
+ fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
+ include fastcgi_params;
}
- location /streams {
- fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
- include fastcgi_params;
- proxy_http_version 1.1;
- proxy_set_header Connection "";
+ location /streams {
+ fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
+ include fastcgi_params;
+ proxy_http_version 1.1;
+ proxy_set_header Connection "";
}
}
}
@@ -74,20 +74,20 @@ cat<<'EOF' > $dir/startnginx.sh
if [ $# -ne 0 -a $# -ne 1 ]; then
echo "usage: $0 ["]
exit
- fi
+ fi
prefix=$1
# start nginx
sudo cp nginx.conf $prefix/etc/nginx/
if [ -d /etc/rc.conf ]; then # freebsd
if [ ! $(grep nginx_enable /etc/rc.conf) ]; then
- sudo sh -c ' echo 'nginx_enable="YES"' >> /etc/rc.conf'
- fi
+ sudo sh -c ' echo 'nginx_enable="YES"' >> /etc/rc.conf'
+ fi
sudo /usr/local/etc/rc.d/nginx restart
- else
- sudo pkill nginx
+ else
+ sudo pkill nginx
nginxbin=$(sudo which nginx)
- sudo $nginxbin -c $prefix/etc/nginx/nginx.conf
+ sudo $nginxbin -c $prefix/etc/nginx/nginx.conf
fi
EOF
diff --git a/test/vagrant/vagrant.sh b/test/vagrant/vagrant.sh
index 3f5c5f53..42933cd9 100755
--- a/test/vagrant/vagrant.sh
+++ b/test/vagrant/vagrant.sh
@@ -29,18 +29,18 @@ linuxrelease()
box=$1
release="unknown"
for r in freebsd openbsd opensuse ubuntu centos coreos alpine debian arch gentoo fedora rhel; do
- # -i ignore case
- if [ -n "$(echo "$box" | grep -io "$r")" ]; then
- release=$r
- break
- fi
+ # -i ignore case
+ if [ -n "$(echo "$box" | grep -io "$r")" ]; then
+ release=$r
+ break
+ fi
done
# Special cases
if [ "$release" = "unknown" ]; then
- if [ -n "$(echo "$box" | grep -io "bionic")" ]; then
- release=ubuntu
- break;
- fi
+ if [ -n "$(echo "$box" | grep -io "bionic")" ]; then
+ release=ubuntu
+ break;
+ fi
fi
echo "$release"
}
@@ -112,148 +112,148 @@ system=$($sshcmd uname) # we use the release "hack" instead
buildfcgi=false
case $release in
openbsd)
- # packages for building
- $sshcmd sudo pkg install -y git gmake bash
- # cligen
- $sshcmd sudo pkg install -y bison flex
- # Add restconf user
- if [ ! $($sshcmd id -u $wwwuser) ]; then
- $sshcmd sudo pw useradd $wwwuser -d /nonexistent -s /usr/sbin/nologin
- fi
- case ${with_restconf} in
- fcgi)
- $sshcmd sudo pkg install -y fcgi-devkit nginx
- ;;
- native)
- ;;
- esac
+ # packages for building
+ $sshcmd sudo pkg install -y git gmake bash
+ # cligen
+ $sshcmd sudo pkg install -y bison flex
+ # Add restconf user
+ if [ ! $($sshcmd id -u $wwwuser) ]; then
+ $sshcmd sudo pw useradd $wwwuser -d /nonexistent -s /usr/sbin/nologin
+ fi
+ case ${with_restconf} in
+ fcgi)
+ $sshcmd sudo pkg install -y fcgi-devkit nginx
+ ;;
+ native)
+ ;;
+ esac
;;
freebsd)
- # packages for building
- $sshcmd sudo pkg install -y git gmake bash
- # cligen
- $sshcmd sudo pkg install -y bison flex
- # Add restconf user
- if [ ! $($sshcmd id -u $wwwuser) ]; then
- $sshcmd sudo pw useradd $wwwuser -d /nonexistent -s /usr/sbin/nologin
- fi
- case ${with_restconf} in
- fcgi)
- $sshcmd sudo pkg install -y fcgi-devkit nginx
- ;;
- native)
- ;;
- esac
- ;;
+ # packages for building
+ $sshcmd sudo pkg install -y git gmake bash
+ # cligen
+ $sshcmd sudo pkg install -y bison flex
+ # Add restconf user
+ if [ ! $($sshcmd id -u $wwwuser) ]; then
+ $sshcmd sudo pw useradd $wwwuser -d /nonexistent -s /usr/sbin/nologin
+ fi
+ case ${with_restconf} in
+ fcgi)
+ $sshcmd sudo pkg install -y fcgi-devkit nginx
+ ;;
+ native)
+ ;;
+ esac
+ ;;
centos)
# enable ipv6
$sshcmd sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
- # add restconf user: $wwwuser
- if [ ! $($sshcmd id -u $wwwuser) ]; then
- $sshcmd sudo useradd -M $wwwuser
- fi
- # packages for building
- $sshcmd sudo yum install -y git make
- # cligen
- $sshcmd sudo yum install -y bison flex
- # clixon utilities
- $sshcmd sudo yum install -y time libcurl-devel gcc-c++
- # restconf
- case ${with_restconf} in
- fcgi)
- buildfcgi=true # build fcgi from source
- $sshcmd sudo yum install -y epel-release
- # $sshcmd sudo yum update
- $sshcmd sudo yum install -y nginx
- ;;
- native)
- $sshcmd sudo yum install -y openssl
- $sshcmd sudo yum install -y openssl-devel
- $sshcmd sudo yum-config-manager --enable powertools
- $sshcmd sudo yum install -y libnghttp2-devel
- ;;
- esac
- ;;
+ # add restconf user: $wwwuser
+ if [ ! $($sshcmd id -u $wwwuser) ]; then
+ $sshcmd sudo useradd -M $wwwuser
+ fi
+ # packages for building
+ $sshcmd sudo yum install -y git make
+ # cligen
+ $sshcmd sudo yum install -y bison flex
+ # clixon utilities
+ $sshcmd sudo yum install -y time libcurl-devel gcc-c++
+ # restconf
+ case ${with_restconf} in
+ fcgi)
+ buildfcgi=true # build fcgi from source
+ $sshcmd sudo yum install -y epel-release
+ # $sshcmd sudo yum update
+ $sshcmd sudo yum install -y nginx
+ ;;
+ native)
+ $sshcmd sudo yum install -y openssl
+ $sshcmd sudo yum install -y openssl-devel
+ $sshcmd sudo yum-config-manager --enable powertools
+ $sshcmd sudo yum install -y libnghttp2-devel
+ ;;
+ esac
+ ;;
opensuse) # opensuse42
- # restconf user: $wwwuser
- if [ ! $($sshcmd id -u $wwwuser) ]; then
- $sshcmd sudo useradd -M -U $wwwuser
- fi
- # packages for building
- $sshcmd sudo zypper install -y git
- # cligen
- $sshcmd sudo zypper install -y bison flex
- # clixon utilities
- $sshcmd sudo zypper install -y libcurl-devel gcc-c++
- # restconf
- case ${with_restconf} in
- fcgi)
- $sshcmd sudo zypper install -y nginx
- buildfcgi=true # build fcgi from source
- ;;
- native)
- ;;
- esac
- ;;
+ # restconf user: $wwwuser
+ if [ ! $($sshcmd id -u $wwwuser) ]; then
+ $sshcmd sudo useradd -M -U $wwwuser
+ fi
+ # packages for building
+ $sshcmd sudo zypper install -y git
+ # cligen
+ $sshcmd sudo zypper install -y bison flex
+ # clixon utilities
+ $sshcmd sudo zypper install -y libcurl-devel gcc-c++
+ # restconf
+ case ${with_restconf} in
+ fcgi)
+ $sshcmd sudo zypper install -y nginx
+ buildfcgi=true # build fcgi from source
+ ;;
+ native)
+ ;;
+ esac
+ ;;
ubuntu) # ubuntu/apt based
# enable ipv6
$sshcmd sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
- $sshcmd sudo apt-get update --fix-missing
- $sshcmd sudo apt install -y git
- # restconf user: $wwwuser
- if [ ! $($sshcmd id -u $wwwuser) ]; then
- $sshcmd sudo useradd -M $wwwuser
- fi
- # cligen
- $sshcmd sudo apt install -y bison flex make
- # clixon utilities
- $sshcmd sudo apt install -y libcurl4-openssl-dev
- $sshcmd sudo apt install -y g++
- # restconf
- case ${with_restconf} in
- fcgi)
- buildfcgi=true # some ubuntu dont have fcgi-dev
- $sshcmd sudo apt install -y nginx
- ;;
- native)
- $sshcmd sudo apt install -y libssl-dev
- $sshcmd sudo apt install -y libnghttp2-dev # nghttp2
- ;;
- esac
- ;;
+ $sshcmd sudo apt-get update --fix-missing
+ $sshcmd sudo apt install -y git
+ # restconf user: $wwwuser
+ if [ ! $($sshcmd id -u $wwwuser) ]; then
+ $sshcmd sudo useradd -M $wwwuser
+ fi
+ # cligen
+ $sshcmd sudo apt install -y bison flex make
+ # clixon utilities
+ $sshcmd sudo apt install -y libcurl4-openssl-dev
+ $sshcmd sudo apt install -y g++
+ # restconf
+ case ${with_restconf} in
+ fcgi)
+ buildfcgi=true # some ubuntu dont have fcgi-dev
+ $sshcmd sudo apt install -y nginx
+ ;;
+ native)
+ $sshcmd sudo apt install -y libssl-dev
+ $sshcmd sudo apt install -y libnghttp2-dev # nghttp2
+ ;;
+ esac
+ ;;
alpine)
- if [ ! $($sshcmd id -u $wwwuser) ]; then
+ if [ ! $($sshcmd id -u $wwwuser) ]; then
$sshcmd sudo adduser -D -H $wwwuser
- fi
- $sshcmd sudo apk add --update git make build-base gcc flex bison curl-dev g++
- # restconf
- case ${with_restconf} in
- fcgi)
- $sshcmd sudo apk add --update nginx fcgi-dev
- ;;
- native)
- ;;
- esac
- ;;
+ fi
+ $sshcmd sudo apk add --update git make build-base gcc flex bison curl-dev g++
+ # restconf
+ case ${with_restconf} in
+ fcgi)
+ $sshcmd sudo apk add --update nginx fcgi-dev
+ ;;
+ native)
+ ;;
+ esac
+ ;;
arch)
- $sshcmd sudo useradd -M $wwwuser
- useradd -m -G additional_groups -s login_shell username
- $sshcmd sudo pacman -Syu --noconfirm git
- # cligen
- $sshcmd sudo pacman -Syu --noconfirm bison flex make
- # restconf
- case ${with_restconf} in
- fcgi)
- $sshcmd sudo pacman -Syu --noconfirm nginx fcgi
- ;;
- native)
- ;;
- esac
- ;;
+ $sshcmd sudo useradd -M $wwwuser
+ useradd -m -G additional_groups -s login_shell username
+ $sshcmd sudo pacman -Syu --noconfirm git
+ # cligen
+ $sshcmd sudo pacman -Syu --noconfirm bison flex make
+ # restconf
+ case ${with_restconf} in
+ fcgi)
+ $sshcmd sudo pacman -Syu --noconfirm nginx fcgi
+ ;;
+ native)
+ ;;
+ esac
+ ;;
*)
- echo "Unknown release: $release"
- ;;
+ echo "Unknown release: $release"
+ ;;
esac
# Some platforms dont have fcgi, build the source (should all?)
@@ -266,11 +266,11 @@ fi
case ${with_restconf} in
fcgi)
- # Hide all complex nginx config in sub-script
- . ./nginx.sh $dir $idfile $port $wwwuser
- ;;
+ # Hide all complex nginx config in sub-script
+ . ./nginx.sh $dir $idfile $port $wwwuser
+ ;;
native)
- ;;
+ ;;
esac
# Setup cligen and clixon
diff --git a/test/valgrind-clixon.supp b/test/valgrind-clixon.supp
index 80d26160..8be3dc21 100644
--- a/test/valgrind-clixon.supp
+++ b/test/valgrind-clixon.supp
@@ -42,3 +42,12 @@
fun:*
fun:OS_LibInit
}
+{
+ supp7
+ Memcheck:Leak
+ match-leak-kinds: reachable
+ fun:*
+ fun:*
+ fun:*
+ fun:_dl_map_object
+}
\ No newline at end of file
diff --git a/util/clixon_netconf_ssh_callhome.c b/util/clixon_netconf_ssh_callhome.c
index 9dd0c2d4..78cafb22 100644
--- a/util/clixon_netconf_ssh_callhome.c
+++ b/util/clixon_netconf_ssh_callhome.c
@@ -84,20 +84,20 @@ sudo clixon_netconf_ssh_callhome -a 127.0.0.1 -c /var/tmp/./test_netconf_ssh_cal
static int
callhome_connect(struct sockaddr *sa,
- size_t sa_len,
- int *sp)
+ size_t sa_len,
+ int *sp)
{
int retval = -1;
int s;
if ((s = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
- perror("socket");
- goto done;
+ perror("socket");
+ goto done;
}
if (connect(s, sa, sa_len) < 0){
- perror("connect");
- close(s);
- goto done;
+ perror("connect");
+ close(s);
+ goto done;
}
*sp = s;
retval = 0;
@@ -108,31 +108,31 @@ callhome_connect(struct sockaddr *sa,
/* @see clixon_inet2sin */
static int
inet2sin(const char *addrtype,
- const char *addrstr,
- uint16_t port,
- struct sockaddr *sa,
- size_t *sa_len)
+ const char *addrstr,
+ uint16_t port,
+ struct sockaddr *sa,
+ size_t *sa_len)
{
struct sockaddr_in6 *sin6;
struct sockaddr_in *sin;
if (strcmp(addrtype, "inet:ipv6-address") == 0) {
- sin6 = (struct sockaddr_in6 *)sa;
+ sin6 = (struct sockaddr_in6 *)sa;
*sa_len = sizeof(struct sockaddr_in6);
sin6->sin6_port = htons(port);
sin6->sin6_family = AF_INET6;
inet_pton(AF_INET6, addrstr, &sin6->sin6_addr);
}
else if (strcmp(addrtype, "inet:ipv4-address") == 0) {
- sin = (struct sockaddr_in *)sa;
+ sin = (struct sockaddr_in *)sa;
*sa_len = sizeof(struct sockaddr_in);
sin->sin_family = AF_INET;
sin->sin_port = htons(port);
sin->sin_addr.s_addr = inet_addr(addrstr);
}
else{
- fprintf(stderr, "Unexpected addrtype: %s\n", addrtype);
- return -1;
+ fprintf(stderr, "Unexpected addrtype: %s\n", addrtype);
+ return -1;
}
return 0;
}
@@ -140,10 +140,10 @@ inet2sin(const char *addrtype,
static int
ssh_server_exec(int s,
- char *sshdbin,
- char *sshdconfigfile,
- char *clixonconfigfile,
- int dbg)
+ char *sshdbin,
+ char *sshdconfigfile,
+ char *clixonconfigfile,
+ int dbg)
{
int retval = -1;
char **argv = NULL;
@@ -154,39 +154,39 @@ ssh_server_exec(int s,
const char *formatstr = "Subsystem netconf /usr/local/bin/clixon_netconf -f %s";
if (s < 0){
- errno = EINVAL;
- perror("socket s");
- goto done;
+ errno = EINVAL;
+ perror("socket s");
+ goto done;
}
if (sshdbin == NULL){
- errno = EINVAL;
- perror("sshdbin");
- goto done;
+ errno = EINVAL;
+ perror("sshdbin");
+ goto done;
}
if (sshdconfigfile == NULL){
- errno = EINVAL;
- perror("sshdconfigfile");
- goto done;
+ errno = EINVAL;
+ perror("sshdconfigfile");
+ goto done;
}
if (clixonconfigfile == NULL){
- errno = EINVAL;
- perror("clixonconfigfile");
- goto done;
+ errno = EINVAL;
+ perror("clixonconfigfile");
+ goto done;
}
/* Construct subsystem string */
len = strlen(formatstr)+strlen(clixonconfigfile)+1;
if ((optstr = malloc(len)) == NULL){
- perror("malloc");
- goto done;
+ perror("malloc");
+ goto done;
}
snprintf(optstr, len, formatstr, clixonconfigfile);
nr = 9; /* See below */
if (dbg)
- nr++;
+ nr++;
if ((argv = calloc(nr, sizeof(char *))) == NULL){
- perror("calloc");
- goto done;
+ perror("calloc");
+ goto done;
}
i = 0;
@@ -195,7 +195,7 @@ ssh_server_exec(int s,
argv[i++] = "-i"; /* Specifies that sshd is being run from inetd(8) */
argv[i++] = "-D"; /* Foreground ? */
if (dbg)
- argv[i++] = "-d"; /* Debug mode */
+ argv[i++] = "-d"; /* Debug mode */
argv[i++] = "-e"; /* write debug logs to stderr */
argv[i++] = "-o"; /* option */
argv[i++] = optstr;
@@ -204,22 +204,22 @@ ssh_server_exec(int s,
argv[i++] = NULL;
assert(i==nr);
if (setreuid(0, 0) < 0){
- perror("setreuid");
- goto done;
+ perror("setreuid");
+ goto done;
}
close(0);
close(1);
if (dup2(s, STDIN_FILENO) < 0){
- perror("dup2");
- return -1;
+ perror("dup2");
+ return -1;
}
if (dup2(s, STDOUT_FILENO) < 0){
- perror("dup2");
- return -1;
+ perror("dup2");
+ return -1;
}
if (execv(argv[0], argv) < 0) {
- perror("execv");
- exit(1);
+ perror("execv");
+ exit(1);
}
/* Should reach here */
retval = 0;
@@ -231,17 +231,17 @@ static int
usage(char *argv0)
{
fprintf(stderr, "usage:%s [options]\n"
- "where options are\n"
+ "where options are\n"
"\t-h \tHelp\n"
- "\t-D \tDebug\n"
- "\t-f ipv4|ipv6 \tSocket address family(inet:ipv4-address default)\n"
- "\t-a \tIP address (eg 1.2.3.4) - mandatory\n"
- "\t-p \tPort (default 4334)\n"
- "\t-c \tClixon config file - (default /usr/local/etc/clixon.xml)\n"
- "\t-C \tSSHD config file - (default /dev/null)\n"
- "\t-s \tPath to sshd binary, default %s\n"
- ,
- argv0, SSHDBIN_DEFAULT);
+ "\t-D \tDebug\n"
+ "\t-f ipv4|ipv6 \tSocket address family(inet:ipv4-address default)\n"
+ "\t-a \tIP address (eg 1.2.3.4) - mandatory\n"
+ "\t-p \tPort (default 4334)\n"
+ "\t-c \tClixon config file - (default /usr/local/etc/clixon.xml)\n"
+ "\t-C \tSSHD config file - (default /dev/null)\n"
+ "\t-s \tPath to sshd binary, default %s\n"
+ ,
+ argv0, SSHDBIN_DEFAULT);
exit(0);
}
@@ -266,55 +266,55 @@ main(int argc,
optind = 1;
opterr = 0;
while ((c = getopt(argc, argv, UTIL_OPTS)) != -1)
- switch (c) {
- case 'h':
- usage(argv[0]);
- break;
- case 'D':
- dbg++;
- break;
- case 'f':
- family = optarg;
- break;
- case 'a':
- addr = optarg;
- break;
- case 'p':
- port = atoi(optarg);
- break;
- case 'C':
- sshdconfigfile = optarg;
- break;
- case 'c':
- clixonconfigfile = optarg;
- break;
- case 's':
- sshdbin = optarg;
- break;
- default:
- usage(argv[0]);
- break;
- }
+ switch (c) {
+ case 'h':
+ usage(argv[0]);
+ break;
+ case 'D':
+ dbg++;
+ break;
+ case 'f':
+ family = optarg;
+ break;
+ case 'a':
+ addr = optarg;
+ break;
+ case 'p':
+ port = atoi(optarg);
+ break;
+ case 'C':
+ sshdconfigfile = optarg;
+ break;
+ case 'c':
+ clixonconfigfile = optarg;
+ break;
+ case 's':
+ sshdbin = optarg;
+ break;
+ default:
+ usage(argv[0]);
+ break;
+ }
if (port == 0){
- fprintf(stderr, "-p is invalid\n");
- usage(argv[0]);
- goto done;
+ fprintf(stderr, "-p is invalid\n");
+ usage(argv[0]);
+ goto done;
}
if (addr == NULL){
- fprintf(stderr, "-a is NULL\n");
- usage(argv[0]);
- goto done;
+ fprintf(stderr, "-a is NULL\n");
+ usage(argv[0]);
+ goto done;
}
if (inet2sin(family, addr, port, sa, &sa_len) < 0)
- goto done;
+ goto done;
if (callhome_connect(sa, sa_len, &s) < 0)
- goto done;
+ goto done;
/* For some reason this sshd returns -1 which is unclear why */
if (ssh_server_exec(s, sshdbin, sshdconfigfile, clixonconfigfile, dbg) < 0)
- goto done;
+ goto done;
/* Should not reach here */
if (s >= 0)
- close(s);
+ close(s);
retval = 0;
done:
return retval;
diff --git a/util/clixon_netconf_ssh_callhome_client.c b/util/clixon_netconf_ssh_callhome_client.c
index 6875b7da..816bf9af 100644
--- a/util/clixon_netconf_ssh_callhome_client.c
+++ b/util/clixon_netconf_ssh_callhome_client.c
@@ -93,8 +93,8 @@ fdpass(int nfd)
{
struct msghdr mh;
union {
- struct cmsghdr hdr;
- char buf[CMSG_SPACE(sizeof(int))];
+ struct cmsghdr hdr;
+ char buf[CMSG_SPACE(sizeof(int))];
} cmsgbuf;
struct cmsghdr *cmsg;
struct iovec iov;
@@ -104,8 +104,8 @@ fdpass(int nfd)
/* Avoid obvious stupidity */
if (isatty(STDOUT_FILENO)){
- perror("Cannot pass file descriptor to tty");
- return -1;
+ perror("Cannot pass file descriptor to tty");
+ return -1;
}
memset(&mh, 0, sizeof(mh));
memset(&cmsgbuf, 0, sizeof(cmsgbuf));
@@ -128,25 +128,25 @@ fdpass(int nfd)
pfd.fd = STDOUT_FILENO;
pfd.events = POLLOUT;
for (;;) {
- r = sendmsg(STDOUT_FILENO, &mh, 0);
- if (r == -1) {
- if (errno == EAGAIN || errno == EINTR) {
- if (poll(&pfd, 1, -1) == -1){
- perror("poll");
- return -1;
- }
- continue;
- }
- perror("sendmsg");
- return -1;
- } else if (r != 1){
- perror("sendmsg: unexpected return value");
- return -1;
- }
- else
- break;
+ r = sendmsg(STDOUT_FILENO, &mh, 0);
+ if (r == -1) {
+ if (errno == EAGAIN || errno == EINTR) {
+ if (poll(&pfd, 1, -1) == -1){
+ perror("poll");
+ return -1;
+ }
+ continue;
+ }
+ perror("sendmsg");
+ return -1;
+ } else if (r != 1){
+ perror("sendmsg: unexpected return value");
+ return -1;
+ }
+ else
+ break;
}
- // exit(0);
+ // exit(0);
return 0;
}
@@ -158,52 +158,52 @@ fdpass(int nfd)
*/
int
callhome_bind(struct sockaddr *sa,
- size_t sin_len,
- int backlog,
- int *sock)
+ size_t sin_len,
+ int backlog,
+ int *sock)
{
int retval = -1;
int s = -1;
int on = 1;
if (sock == NULL){
- errno = EINVAL;
- perror("sock");
- goto done;
+ errno = EINVAL;
+ perror("sock");
+ goto done;
}
/* create inet socket */
if ((s = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
- perror("socket");
- goto done;
+ perror("socket");
+ goto done;
}
if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)) == -1) {
- perror("setsockopt SO_KEEPALIVE");
- goto done;
+ perror("setsockopt SO_KEEPALIVE");
+ goto done;
}
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) == -1) {
- perror("setsockopt SO_REUSEADDR");
- goto done;
+ perror("setsockopt SO_REUSEADDR");
+ goto done;
}
/* only bind ipv6, otherwise it may bind to ipv4 as well which is strange but seems default */
if (sa->sa_family == AF_INET6 &&
- setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) {
- perror("setsockopt IPPROTO_IPV6");
- goto done;
+ setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) {
+ perror("setsockopt IPPROTO_IPV6");
+ goto done;
}
if (bind(s, sa, sin_len) == -1) {
- perror("bind");
- goto done;
+ perror("bind");
+ goto done;
}
if (listen(s, backlog) < 0){
- perror("listen");
- goto done;
+ perror("listen");
+ goto done;
}
if (sock)
- *sock = s;
+ *sock = s;
retval = 0;
done:
if (retval != 0 && s != -1)
- close(s);
+ close(s);
return retval;
}
@@ -211,14 +211,14 @@ static int
usage(char *argv0)
{
fprintf(stderr, "usage:%s [options]\n"
- "where options are\n"
+ "where options are\n"
"\t-h \tHelp\n"
- "\t-D \tDebug\n"
- "\t-f ipv4|ipv6 \tSocket address family(ipv4 default)\n"
- "\t-a \tIP address (eg 1.2.3.4) - mandatory\n"
- "\t-p \tPort (default 4334)\n"
- ,
- argv0);
+ "\t-D \tDebug\n"
+ "\t-f ipv4|ipv6 \tSocket address family(ipv4 default)\n"
+ "\t-a \tIP address (eg 1.2.3.4) - mandatory\n"
+ "\t-p \tPort (default 4334)\n"
+ ,
+ argv0);
exit(0);
}
@@ -244,42 +244,42 @@ main(int argc,
optind = 1;
opterr = 0;
while ((c = getopt(argc, argv, UTIL_OPTS)) != -1)
- switch (c) {
- case 'h':
- usage(argv[0]);
- break;
- case 'D':
- dbg++; /* not used */
- break;
- case 'f':
- family = optarg;
- break;
- case 'a':
- addr = optarg;
- break;
- case 'p':
- port = atoi(optarg);
- break;
- default:
- usage(argv[0]);
- break;
- }
+ switch (c) {
+ case 'h':
+ usage(argv[0]);
+ break;
+ case 'D':
+ dbg++; /* not used */
+ break;
+ case 'f':
+ family = optarg;
+ break;
+ case 'a':
+ addr = optarg;
+ break;
+ case 'p':
+ port = atoi(optarg);
+ break;
+ default:
+ usage(argv[0]);
+ break;
+ }
if (port == 0){
- fprintf(stderr, "-p is invalid\n");
- usage(argv[0]);
- goto done;
+ fprintf(stderr, "-p is invalid\n");
+ usage(argv[0]);
+ goto done;
}
if (addr == NULL){
- fprintf(stderr, "-a is NULL\n");
- usage(argv[0]);
- goto done;
+ fprintf(stderr, "-a is NULL\n");
+ usage(argv[0]);
+ goto done;
}
if (strcmp(family, "ipv6") == 0){
sin_len = sizeof(struct sockaddr_in6);
sin6.sin6_port = htons(port);
sin6.sin6_family = AF_INET6;
inet_pton(AF_INET6, addr, &sin6.sin6_addr);
- sa = (struct sockaddr *)&sin6;
+ sa = (struct sockaddr *)&sin6;
}
else if (strcmp(family, "ipv4") == 0){
sin_len = sizeof(struct sockaddr_in);
@@ -289,21 +289,21 @@ main(int argc,
sa = (struct sockaddr *)&sin;
}
else{
- fprintf(stderr, "-f <%s> is invalid family\n", family);
- goto done;
+ fprintf(stderr, "-f <%s> is invalid family\n", family);
+ goto done;
}
/* Bind port */
if (callhome_bind(sa, sin_len, 1, &ss) < 0)
- goto done;
+ goto done;
/* Wait until connect */
len = sizeof(from);
if ((s = accept(ss, &from, &len)) < 0){
- perror("accept");
- goto done;
+ perror("accept");
+ goto done;
}
/* s Pass the first connected socket using sendmsg(2) to stdout and exit. */
if (fdpass(s) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
diff --git a/util/clixon_restconf_callhome_client.c b/util/clixon_restconf_callhome_client.c
index e942769c..b4062522 100644
--- a/util/clixon_restconf_callhome_client.c
+++ b/util/clixon_restconf_callhome_client.c
@@ -143,52 +143,52 @@ static FILE *_event_f = NULL; /* set to stdout in main */
*/
int
callhome_bind(struct sockaddr *sa,
- size_t sin_len,
- int backlog,
- int *sock)
+ size_t sin_len,
+ int backlog,
+ int *sock)
{
int retval = -1;
int s = -1;
int on = 1;
if (sock == NULL){
- errno = EINVAL;
- perror("sock");
- goto done;
+ errno = EINVAL;
+ perror("sock");
+ goto done;
}
/* create inet socket */
if ((s = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
- perror("socket");
- goto done;
+ perror("socket");
+ goto done;
}
if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)) == -1) {
- perror("setsockopt SO_KEEPALIVE");
- goto done;
+ perror("setsockopt SO_KEEPALIVE");
+ goto done;
}
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) == -1) {
- perror("setsockopt SO_REUSEADDR");
- goto done;
+ perror("setsockopt SO_REUSEADDR");
+ goto done;
}
/* only bind ipv6, otherwise it may bind to ipv4 as well which is strange but seems default */
if (sa->sa_family == AF_INET6 &&
- setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) {
- perror("setsockopt IPPROTO_IPV6");
- goto done;
+ setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) {
+ perror("setsockopt IPPROTO_IPV6");
+ goto done;
}
if (bind(s, sa, sin_len) == -1) {
- perror("bind");
- goto done;
+ perror("bind");
+ goto done;
}
if (listen(s, backlog) < 0){
- perror("listen");
- goto done;
+ perror("listen");
+ goto done;
}
if (sock)
- *sock = s;
+ *sock = s;
retval = 0;
done:
if (retval != 0 && s != -1)
- close(s);
+ close(s);
return retval;
}
@@ -198,8 +198,8 @@ callhome_bind(struct sockaddr *sa,
*/
static int
read_data_file(FILE *fe,
- char **bufp,
- size_t *lenp)
+ char **bufp,
+ size_t *lenp)
{
int retval = -1;
char *buf = NULL;
@@ -209,21 +209,21 @@ read_data_file(FILE *fe,
int ret;
if ((buf = malloc(buflen)) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(buf, 0, buflen);
/* Start file form beginning */
rewind(fe);
while (1){
- if ((ret = fread(&ch, 1, 1, fe)) < 0){
- clicon_err(OE_JSON, errno, "fread");
- goto done;
- }
- if (ret == 0)
- break;
- buf[len++] = ch;
- // XXX No realloc, can overflow
+ if ((ret = fread(&ch, 1, 1, fe)) < 0){
+ clicon_err(OE_JSON, errno, "fread");
+ goto done;
+ }
+ if (ret == 0)
+ break;
+ buf[len++] = ch;
+ // XXX No realloc, can overflow
}
*bufp = buf;
*lenp = len;
@@ -236,7 +236,7 @@ read_data_file(FILE *fe,
*/
static int
tls_write_file(FILE *fp,
- SSL *ssl)
+ SSL *ssl)
{
int retval = -1;
char *buf = NULL;
@@ -246,15 +246,15 @@ tls_write_file(FILE *fp,
clicon_debug(1, "%s", __FUNCTION__);
if (read_data_file(fp, &buf, &len) < 0)
- goto done;
+ goto done;
if ((ret = SSL_write(ssl, buf, len)) < 1){
- sslerr = SSL_get_error(ssl, ret);
- clicon_debug(1, "%s SSL_write() n:%d errno:%d sslerr:%d", __FUNCTION__, ret, errno, sslerr);
+ sslerr = SSL_get_error(ssl, ret);
+ clicon_debug(1, "%s SSL_write() n:%d errno:%d sslerr:%d", __FUNCTION__, ret, errno, sslerr);
}
retval = 0;
done:
if (buf)
- free(buf);
+ free(buf);
return retval;
}
@@ -265,7 +265,7 @@ tls_write_file(FILE *fp,
*/
static int
tls_server_reply_cb(int s,
- void *arg)
+ void *arg)
{
int retval = -1;
tls_session_data *sd = (tls_session_data *)arg;
@@ -276,73 +276,73 @@ tls_server_reply_cb(int s,
struct timeval now;
struct timeval td;
static int seq = 0; // from start
-
+
// clicon_debug(1, "%s", __FUNCTION__);
ssl = sd->sd_ssl;
/* get reply & decrypt */
if ((n = SSL_read(ssl, buf, sizeof(buf))) < 0){
- clicon_err(OE_XML, errno, "SSL_read");
- goto done;
+ clicon_err(OE_XML, errno, "SSL_read");
+ goto done;
}
clicon_debug(1, "%s n:%d", __FUNCTION__, n);
gettimeofday(&now, NULL);
timersub(&now, &sd->sd_t0, &td); /* from start of connection */
if (n == 0){ /* Server closed socket */
- SSL_free(ssl);
- clixon_event_unreg_fd(s, tls_server_reply_cb);
- if (_event_trace)
- fprintf(_event_f, "Close: %d remote at t=%lu\n", _n_accepts, td.tv_sec);
- close(s);
- free(sd);
- if (_accepts == 0)
- ;
- else if (_accepts == 1){
- clixon_exit_set(1); /* XXX more elaborate logic: 1) continue request, 2) close and accept new */
- fprintf(_event_f, "Exit: %s remote\n", __FUNCTION__);
- }
- else
- _accepts--;
- goto ok;
+ SSL_free(ssl);
+ clixon_event_unreg_fd(s, tls_server_reply_cb);
+ if (_event_trace)
+ fprintf(_event_f, "Close: %d remote at t=%lu\n", _n_accepts, td.tv_sec);
+ close(s);
+ free(sd);
+ if (_accepts == 0)
+ ;
+ else if (_accepts == 1){
+ clixon_exit_set(1); /* XXX more elaborate logic: 1) continue request, 2) close and accept new */
+ fprintf(_event_f, "Exit: %s remote\n", __FUNCTION__);
+ }
+ else
+ _accepts--;
+ goto ok;
}
seq++;
buf[n] = 0;
if (_event_trace){
- fprintf(_event_f, "Reply: %d t=%lu\n", seq, td.tv_sec);
- if (_event_trace > 1)
- fprintf(_event_f, "%s\n", buf);
+ fprintf(_event_f, "Reply: %d t=%lu\n", seq, td.tv_sec);
+ if (_event_trace > 1)
+ fprintf(_event_f, "%s\n", buf);
}
/* See if we should send more requests on this socket */
if (sd->sd_t0.tv_sec + _data_timeout_s > now.tv_sec){
- /* Send another packet */
- usleep(100000); /* XXX This is a blocking timeout */
- /* Write HTTP request on socket */
- if (tls_write_file(_input_file, sd->sd_ssl) < 0)
- goto done;
-
+ /* Send another packet */
+ usleep(100000); /* XXX This is a blocking timeout */
+ /* Write HTTP request on socket */
+ if (tls_write_file(_input_file, sd->sd_ssl) < 0)
+ goto done;
+
}
else if (!_idle){
- clicon_debug(1, "%s idle", __FUNCTION__);
- SSL_shutdown(ssl);
- SSL_free(ssl);
- clixon_event_unreg_fd(s, tls_server_reply_cb);
- if (_event_trace)
- fprintf(_event_f, "Close: %d local at t=%lu\n", _n_accepts, td.tv_sec);
- close(s);
- if (_accepts == 0)
- ;
- else if (_accepts == 1){
- clixon_exit_set(1); /* XXX more elaborate logic: 1) continue request, 2) close and accept new */
- fprintf(_event_f, "Exit: %s idle\n", __FUNCTION__);
- }
- else
- _accepts--;
- free(sd);
+ clicon_debug(1, "%s idle", __FUNCTION__);
+ SSL_shutdown(ssl);
+ SSL_free(ssl);
+ clixon_event_unreg_fd(s, tls_server_reply_cb);
+ if (_event_trace)
+ fprintf(_event_f, "Close: %d local at t=%lu\n", _n_accepts, td.tv_sec);
+ close(s);
+ if (_accepts == 0)
+ ;
+ else if (_accepts == 1){
+ clixon_exit_set(1); /* XXX more elaborate logic: 1) continue request, 2) close and accept new */
+ fprintf(_event_f, "Exit: %s idle\n", __FUNCTION__);
+ }
+ else
+ _accepts--;
+ free(sd);
}
ok:
retval = 0;
done:
if (expbuf)
- free(expbuf);
+ free(expbuf);
clicon_debug(1, "%s ret:%d", __FUNCTION__, retval);
return retval;
}
@@ -351,8 +351,8 @@ tls_server_reply_cb(int s,
*/
static int
tls_ssl_init_connect(SSL_CTX *ctx,
- int s,
- SSL **sslp)
+ int s,
+ SSL **sslp)
{
int retval = -1;
SSL *ssl = NULL;
@@ -363,7 +363,7 @@ tls_ssl_init_connect(SSL_CTX *ctx,
/* create new SSL connection state */
if ((ssl = SSL_new(ctx)) == NULL){
- clicon_err(OE_SSL, 0, "SSL_new.");
+ clicon_err(OE_SSL, 0, "SSL_new.");
goto done;
}
SSL_set_fd(ssl, s); /* attach the socket descriptor */
@@ -372,8 +372,8 @@ tls_ssl_init_connect(SSL_CTX *ctx,
protos[0] = 8;
strncpy((char*)&protos[1], "http/1.1", 9);
if ((retval = SSL_set_alpn_protos(ssl, protos, 9)) != 0){
- clicon_err(OE_SSL, retval, "SSL_set_alpn_protos.");
- goto done;
+ clicon_err(OE_SSL, retval, "SSL_set_alpn_protos.");
+ goto done;
}
#if 0
SSL_get0_next_proto_negotiated(conn_.tls.ssl, &next_proto, &next_proto_len);
@@ -384,31 +384,31 @@ tls_ssl_init_connect(SSL_CTX *ctx,
TLSEXT_TYPE_application_layer_protocol_negotiation
int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos,
unsigned int protos_len);
- see
+ see
https://www.openssl.org/docs/man3.0/man3/SSL_CTX_set_alpn_select_cb.html
*/
if ((ret = SSL_connect(ssl)) < 1){
- sslerr = SSL_get_error(ssl, ret);
- clicon_debug(1, "%s SSL_read() n:%d errno:%d sslerr:%d", __FUNCTION__, ret, errno, sslerr);
+ sslerr = SSL_get_error(ssl, ret);
+ clicon_debug(1, "%s SSL_read() n:%d errno:%d sslerr:%d", __FUNCTION__, ret, errno, sslerr);
- switch (sslerr){
- case SSL_ERROR_SSL: /* 1 */
- goto done;
- break;
- default:
- clicon_err(OE_XML, errno, "SSL_connect");
- goto done;
- break;
- }
+ switch (sslerr){
+ case SSL_ERROR_SSL: /* 1 */
+ goto done;
+ break;
+ default:
+ clicon_err(OE_XML, errno, "SSL_connect");
+ goto done;
+ break;
+ }
}
/* check certificate verification result */
verify = SSL_get_verify_result(ssl);
switch (verify) {
case X509_V_OK:
- break;
+ break;
default:
- clicon_err(OE_SSL, errno, "verify problems: %d", verify);
- goto done;
+ clicon_err(OE_SSL, errno, "verify problems: %d", verify);
+ goto done;
}
*sslp = ssl;
retval = 0;
@@ -418,7 +418,7 @@ tls_ssl_init_connect(SSL_CTX *ctx,
static int
tls_timeout_cb(int fd,
- void *arg)
+ void *arg)
{
fprintf(_event_f, "Exit: %s\n", __FUNCTION__);
exit(200);
@@ -441,10 +441,10 @@ tls_client_timeout(void *arg)
t1.tv_sec = _accept_timeout_s;
timeradd(&now, &t1, &t);
if (clixon_event_reg_timeout(t,
- tls_timeout_cb,
- arg,
- "tls client timeout") < 0)
- goto done;
+ tls_timeout_cb,
+ arg,
+ "tls client timeout") < 0)
+ goto done;
retval = 0;
done:
return retval;
@@ -454,7 +454,7 @@ tls_client_timeout(void *arg)
*/
static int
tls_server_accept_cb(int ss,
- void *arg)
+ void *arg)
{
int retval = -1;
tls_accept_handle *ta = (tls_accept_handle *)arg;
@@ -468,16 +468,16 @@ tls_server_accept_cb(int ss,
clicon_debug(1, "%s", __FUNCTION__);
len = sizeof(from);
if ((s = accept(ss, &from, &len)) < 0){
- perror("accept");
- goto done;
+ perror("accept");
+ goto done;
}
clicon_debug(1, "accepted");
if (tls_ssl_init_connect(ta->ta_ctx, s, &ssl) < 0)
- goto done;
+ goto done;
clicon_debug(1, "connected");
if ((sd = malloc(sizeof(*sd))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(sd, 0, sizeof(*sd));
sd->sd_s = s;
@@ -486,17 +486,17 @@ tls_server_accept_cb(int ss,
timersub(&sd->sd_t0, &ta->ta_t0, &td); /* from start of connection */
_n_accepts++;
if (_event_trace)
- fprintf(_event_f, "Accept: %d at t=%lu\n", _n_accepts, td.tv_sec);
+ fprintf(_event_f, "Accept: %d at t=%lu\n", _n_accepts, td.tv_sec);
/* Always write one HTTP request on socket, maybe more if _data_timeout_s > 0 */
if (tls_write_file(_input_file, ssl) < 0)
- goto done;
+ goto done;
/* register callback for reply */
if (clixon_event_reg_fd(s, tls_server_reply_cb, sd, "tls server reply") < 0)
- goto done;
+ goto done;
/* Unregister old + register new timeout */
if (tls_client_timeout(ta) < 0)
- goto done;
+ goto done;
retval = 0;
done:
return retval;
@@ -507,11 +507,11 @@ tls_server_accept_cb(int ss,
*/
static int
tls_proto_select_cb(SSL *s,
- unsigned char **out,
- unsigned char *outlen,
- const unsigned char *in,
- unsigned int inlen,
- void *arg)
+ unsigned char **out,
+ unsigned char *outlen,
+ const unsigned char *in,
+ unsigned int inlen,
+ void *arg)
{
clicon_debug(1, "%s", __FUNCTION__);
return 0;
@@ -524,36 +524,36 @@ tls_proto_select_cb(SSL *s,
*/
static int
tls_auth_verify_callback(int preverify_ok,
- X509_STORE_CTX *x509_ctx)
+ X509_STORE_CTX *x509_ctx)
{
return 1; /* success */
}
static SSL_CTX *
tls_ctx_init(const char *cert_path,
- const char *key_path,
- const char *ca_cert_path)
+ const char *key_path,
+ const char *ca_cert_path)
{
SSL_CTX *ctx = NULL;
if ((ctx = SSL_CTX_new(TLS_client_method())) == NULL) {
- clicon_err(OE_SSL, 0, "SSL_CTX_new");
- goto done;
+ clicon_err(OE_SSL, 0, "SSL_CTX_new");
+ goto done;
}
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, tls_auth_verify_callback);
/* get peer certificate
nc_client_tls_update_opts */
if (SSL_CTX_use_certificate_file(ctx, cert_path, SSL_FILETYPE_PEM) != 1) {
- clicon_err(OE_SSL, 0, "SSL_CTX_use_certificate_file");
- goto done;
+ clicon_err(OE_SSL, 0, "SSL_CTX_use_certificate_file");
+ goto done;
}
if (SSL_CTX_use_PrivateKey_file(ctx, key_path, SSL_FILETYPE_PEM) != 1) {
- clicon_err(OE_SSL, 0, "SSL_CTX_use_PrivateKey_file");
- goto done;
+ clicon_err(OE_SSL, 0, "SSL_CTX_use_PrivateKey_file");
+ goto done;
}
if (SSL_CTX_load_verify_locations(ctx, ca_cert_path, NULL) != 1) {
- clicon_err(OE_SSL, 0, "SSL_CTX_load_verify_locations");
- goto done;
+ clicon_err(OE_SSL, 0, "SSL_CTX_load_verify_locations");
+ goto done;
}
(void)SSL_CTX_set_next_proto_select_cb(ctx, tls_proto_select_cb, NULL);
return ctx;
@@ -565,25 +565,25 @@ static int
usage(char *argv0)
{
fprintf(stderr, "usage:%s [options]\n"
- "where options are\n"
+ "where options are\n"
"\t-h \t\tHelp\n"
- "\t-D \tDebug\n"
- "\t-f \tHTTP input file (overrides stdin)\n"
- "\t-F ipv4|ipv6 \tSocket address family(ipv4 default)\n"
- "\t-a \tIP address (eg 1.2.3.4) - mandatory\n"
- "\t-p \tPort (default %d)\n"
- "\t-c \tcert\n"
- "\t-C \tcacert\n"
- "\t-k \tkey\n"
- "\t-n \tQuit after this many incoming connections, 0 means no limit. Default: 1\n"
- "\t-t \tTimeout in seconds after each accept, if fired just exit. Default: %ds\n"
- "\t-d \tTimeout of data requests on a connection in seconds after each accept, if fired either close or keep idle (see -i). Default: 0s\n"
- "\t-i \tIdle after receiving last reply. Otherwise close directly after receiving last reply\n"
- "\t-e \tEvent trace on stdout, 1: terse, 2: full\n"
- ,
- argv0,
- RESTCONF_CH_TLS,
- _accept_timeout_s);
+ "\t-D \tDebug\n"
+ "\t-f \tHTTP input file (overrides stdin)\n"
+ "\t-F ipv4|ipv6 \tSocket address family(ipv4 default)\n"
+ "\t-a \tIP address (eg 1.2.3.4) - mandatory\n"
+ "\t-p \tPort (default %d)\n"
+ "\t-c \tcert\n"
+ "\t-C \tcacert\n"
+ "\t-k \tkey\n"
+ "\t-n \tQuit after this many incoming connections, 0 means no limit. Default: 1\n"
+ "\t-t \tTimeout in seconds after each accept, if fired just exit. Default: %ds\n"
+ "\t-d \tTimeout of data requests on a connection in seconds after each accept, if fired either close or keep idle (see -i). Default: 0s\n"
+ "\t-i \tIdle after receiving last reply. Otherwise close directly after receiving last reply\n"
+ "\t-e \tEvent trace on stdout, 1: terse, 2: full\n"
+ ,
+ argv0,
+ RESTCONF_CH_TLS,
+ _accept_timeout_s);
exit(0);
}
@@ -613,130 +613,130 @@ main(int argc,
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
if ((h = clicon_handle_init()) == NULL)
- goto done;
+ goto done;
while ((c = getopt(argc, argv, UTIL_TLS_OPTS)) != -1)
- switch (c) {
- case 'h':
- usage(argv[0]);
- break;
- case 'D':
- if (sscanf(optarg, "%d", &dbg) != 1)
- usage(argv[0]);
- break;
- case 'f':
- if (optarg == NULL || *optarg == '-')
- usage(argv[0]);
- input_filename = optarg;
- break;
- case 'F':
- family = optarg;
- break;
- case 'a':
- addr = optarg;
- break;
- case 'p':
- if (sscanf(optarg, "%hu", &port) != 1)
- usage(argv[0]);
- break;
- case 'c':
- if (optarg == NULL || *optarg == '-')
- usage(argv[0]);
- cert_path = optarg;
- break;
- case 'C':
- if (optarg == NULL || *optarg == '-')
- usage(argv[0]);
- ca_cert_path = optarg;
- break;
- case 'k':
- if (optarg == NULL || *optarg == '-')
- usage(argv[0]);
- key_path = optarg;
- break;
- case 'n':
- if (optarg == NULL || *optarg == '-')
- usage(argv[0]);
- _accepts = atoi(optarg);
- break;
- case 'i': /* keep open, do not close after first reply */
- _idle = 1;
- break;
- case 't': /* accept timeout */
- if (optarg == NULL || *optarg == '-')
- usage(argv[0]);
- _accept_timeout_s = atoi(optarg);
- break;
- case 'd': /* data timeout */
- if (optarg == NULL || *optarg == '-')
- usage(argv[0]);
- _data_timeout_s = atoi(optarg);
- break;
- case 'e': /* Event trace */
- if (optarg == NULL || *optarg == '-')
- usage(argv[0]);
- _event_trace = atoi(optarg);
- _event_f = stdout;
- break;
- default:
- usage(argv[0]);
- break;
- }
+ switch (c) {
+ case 'h':
+ usage(argv[0]);
+ break;
+ case 'D':
+ if (sscanf(optarg, "%d", &dbg) != 1)
+ usage(argv[0]);
+ break;
+ case 'f':
+ if (optarg == NULL || *optarg == '-')
+ usage(argv[0]);
+ input_filename = optarg;
+ break;
+ case 'F':
+ family = optarg;
+ break;
+ case 'a':
+ addr = optarg;
+ break;
+ case 'p':
+ if (sscanf(optarg, "%hu", &port) != 1)
+ usage(argv[0]);
+ break;
+ case 'c':
+ if (optarg == NULL || *optarg == '-')
+ usage(argv[0]);
+ cert_path = optarg;
+ break;
+ case 'C':
+ if (optarg == NULL || *optarg == '-')
+ usage(argv[0]);
+ ca_cert_path = optarg;
+ break;
+ case 'k':
+ if (optarg == NULL || *optarg == '-')
+ usage(argv[0]);
+ key_path = optarg;
+ break;
+ case 'n':
+ if (optarg == NULL || *optarg == '-')
+ usage(argv[0]);
+ _accepts = atoi(optarg);
+ break;
+ case 'i': /* keep open, do not close after first reply */
+ _idle = 1;
+ break;
+ case 't': /* accept timeout */
+ if (optarg == NULL || *optarg == '-')
+ usage(argv[0]);
+ _accept_timeout_s = atoi(optarg);
+ break;
+ case 'd': /* data timeout */
+ if (optarg == NULL || *optarg == '-')
+ usage(argv[0]);
+ _data_timeout_s = atoi(optarg);
+ break;
+ case 'e': /* Event trace */
+ if (optarg == NULL || *optarg == '-')
+ usage(argv[0]);
+ _event_trace = atoi(optarg);
+ _event_f = stdout;
+ break;
+ default:
+ usage(argv[0]);
+ break;
+ }
if (cert_path == NULL || key_path == NULL || ca_cert_path == NULL){
- fprintf(stderr, "-c and -k -C are mandatory\n");
- usage(argv[0]);
+ fprintf(stderr, "-c and -k -C are mandatory\n");
+ usage(argv[0]);
}
clicon_debug_init(dbg, NULL);
if (input_filename){
- if ((_input_file = fopen(input_filename, "r")) == NULL){
- clicon_err(OE_YANG, errno, "open(%s)", input_filename);
- goto done;
- }
+ if ((_input_file = fopen(input_filename, "r")) == NULL){
+ clicon_err(OE_YANG, errno, "open(%s)", input_filename);
+ goto done;
+ }
}
if ((ctx = tls_ctx_init(cert_path, key_path, ca_cert_path)) == NULL)
- goto done;
+ goto done;
if (port == 0){
- fprintf(stderr, "-p is invalid\n");
- usage(argv[0]);
- goto done;
+ fprintf(stderr, "-p is invalid\n");
+ usage(argv[0]);
+ goto done;
}
if (addr == NULL){
- fprintf(stderr, "-a is NULL\n");
- usage(argv[0]);
- goto done;
+ fprintf(stderr, "-a is NULL\n");
+ usage(argv[0]);
+ goto done;
}
if (clixon_inet2sin(family, addr, port, sa, &sa_len) < 0)
- goto done;
+ goto done;
/* Bind port */
if (callhome_bind(sa, sa_len, 1, &ss) < 0)
- goto done;
+ goto done;
clicon_debug(1, "callhome_bind %s:%hu", addr, port);
if ((ta = malloc(sizeof(*ta))) == NULL){
- clicon_err(OE_UNIX, errno, "malloc");
- goto done;
+ clicon_err(OE_UNIX, errno, "malloc");
+ goto done;
}
memset(ta, 0, sizeof(*ta));
ta->ta_ctx = ctx;
ta->ta_ss = ss;
gettimeofday(&ta->ta_t0, NULL);
if (clixon_event_reg_fd(ss, tls_server_accept_cb, ta, "tls server accept") < 0)
- goto done;
+ goto done;
if (tls_client_timeout(ta) < 0)
- goto done;
+ goto done;
if (clixon_event_loop(h) < 0)
- goto done;
+ goto done;
retval = 0;
done:
if (ss != -1)
- clixon_event_unreg_fd(ss, tls_server_accept_cb);
+ clixon_event_unreg_fd(ss, tls_server_accept_cb);
if (ta)
- free(ta);
+ free(ta);
if (fp)
- fclose(fp);
+ fclose(fp);
if (ss != -1)
- close(ss);
+ close(ss);
if (ctx)
- SSL_CTX_free(ctx); /* release context */
+ SSL_CTX_free(ctx); /* release context */
clicon_handle_exit(h); /* frees h and options (and streams) */
clixon_err_exit();
clicon_debug(1, "clixon_restconf_callhome_client pid:%u done", getpid());
diff --git a/util/clixon_util_datastore.c b/util/clixon_util_datastore.c
index cd1b6e0a..5402437b 100644
--- a/util/clixon_util_datastore.c
+++ b/util/clixon_util_datastore.c
@@ -74,30 +74,30 @@ static void
usage(char *argv0)
{
fprintf(stderr, "usage:%s * []\n"
- "where options are\n"
- "\t-h\t\tHelp\n"
- "\t-D\t\tDebug\n"
- "\t-d \t\tDatabase name. Default: running. Alt: candidate,startup\n"
- "\t-b \tDatabase directory. Mandatory\n"
- "\t-f \tDatabase format: xml or json\n"
- "\t-x \tXML file. Alternative to put argument\n"
- "\t-y \tYang file. Mandatory\n"
- "\t-Y \tYang dirs (can be several)\n"
- "and command is either:\n"
- "\tget []\n"
- "\tmget []\n"
- "\tput (merge|replace|create|delete|remove) []\n"
- "\tcopy \n"
- "\tlock \n"
- "\tunlock\n"
- "\tunlock_all \n"
- "\tislocked\n"
- "\texists\n"
- "\tdelete\n"
- "\tinit\n"
- ,
- argv0
- );
+ "where options are\n"
+ "\t-h\t\tHelp\n"
+ "\t-D\t\tDebug\n"
+ "\t-d \t\tDatabase name. Default: running. Alt: candidate,startup\n"
+ "\t-b \tDatabase directory. Mandatory\n"
+ "\t-f \tDatabase format: xml or json\n"
+ "\t-x \tXML file. Alternative to put argument\n"
+ "\t-y \tYang file. Mandatory\n"
+ "\t-Y