summaryrefslogtreecommitdiff
path: root/lib/northbound.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/northbound.c')
-rw-r--r--lib/northbound.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/lib/northbound.c b/lib/northbound.c
index 48b8499bfc..29e843a84e 100644
--- a/lib/northbound.c
+++ b/lib/northbound.c
@@ -680,8 +680,12 @@ int nb_candidate_commit_prepare(struct nb_context *context,
RB_INIT(nb_config_cbs, &changes);
nb_config_diff(running_config, candidate, &changes);
- if (RB_EMPTY(nb_config_cbs, &changes))
+ if (RB_EMPTY(nb_config_cbs, &changes)) {
+ snprintf(
+ errmsg, errmsg_len,
+ "No changes to apply were found during preparation phase");
return NB_ERR_NO_CHANGES;
+ }
if (nb_candidate_validate_code(context, candidate, &changes, errmsg,
errmsg_len)
@@ -707,23 +711,21 @@ int nb_candidate_commit_prepare(struct nb_context *context,
errmsg_len);
}
-void nb_candidate_commit_abort(struct nb_transaction *transaction)
+void nb_candidate_commit_abort(struct nb_transaction *transaction, char *errmsg,
+ size_t errmsg_len)
{
- char errmsg[BUFSIZ] = {0};
-
(void)nb_transaction_process(NB_EV_ABORT, transaction, errmsg,
- sizeof(errmsg));
+ errmsg_len);
nb_transaction_free(transaction);
}
void nb_candidate_commit_apply(struct nb_transaction *transaction,
- bool save_transaction, uint32_t *transaction_id)
+ bool save_transaction, uint32_t *transaction_id,
+ char *errmsg, size_t errmsg_len)
{
- char errmsg[BUFSIZ] = {0};
-
(void)nb_transaction_process(NB_EV_APPLY, transaction, errmsg,
- sizeof(errmsg));
- nb_transaction_apply_finish(transaction, errmsg, sizeof(errmsg));
+ errmsg_len);
+ nb_transaction_apply_finish(transaction, errmsg, errmsg_len);
/* Replace running by candidate. */
transaction->config->version++;
@@ -754,9 +756,9 @@ int nb_candidate_commit(struct nb_context *context, struct nb_config *candidate,
*/
if (ret == NB_OK)
nb_candidate_commit_apply(transaction, save_transaction,
- transaction_id);
+ transaction_id, errmsg, errmsg_len);
else if (transaction != NULL)
- nb_candidate_commit_abort(transaction);
+ nb_candidate_commit_abort(transaction, errmsg, errmsg_len);
return ret;
}
@@ -2046,18 +2048,21 @@ void *nb_running_unset_entry(const struct lyd_node *dnode)
return entry;
}
-void *nb_running_get_entry(const struct lyd_node *dnode, const char *xpath,
- bool abort_if_not_found)
+static void *nb_running_get_entry_worker(const struct lyd_node *dnode,
+ const char *xpath,
+ bool abort_if_not_found,
+ bool rec_search)
{
const struct lyd_node *orig_dnode = dnode;
char xpath_buf[XPATH_MAXLEN];
+ bool rec_flag = true;
assert(dnode || xpath);
if (!dnode)
dnode = yang_dnode_get(running_config->dnode, xpath);
- while (dnode) {
+ while (rec_flag && dnode) {
struct nb_config_entry *config, s;
yang_dnode_get_path(dnode, s.xpath, sizeof(s.xpath));
@@ -2065,6 +2070,8 @@ void *nb_running_get_entry(const struct lyd_node *dnode, const char *xpath,
if (config)
return config->entry;
+ rec_flag = rec_search;
+
dnode = dnode->parent;
}
@@ -2078,6 +2085,20 @@ void *nb_running_get_entry(const struct lyd_node *dnode, const char *xpath,
abort();
}
+void *nb_running_get_entry(const struct lyd_node *dnode, const char *xpath,
+ bool abort_if_not_found)
+{
+ return nb_running_get_entry_worker(dnode, xpath, abort_if_not_found,
+ true);
+}
+
+void *nb_running_get_entry_non_rec(const struct lyd_node *dnode,
+ const char *xpath, bool abort_if_not_found)
+{
+ return nb_running_get_entry_worker(dnode, xpath, abort_if_not_found,
+ false);
+}
+
/* Logging functions. */
const char *nb_event_name(enum nb_event event)
{