|
@@ -96,19 +96,13 @@ static int srp_compl_or_help(kcontext_t *context, bool_t help)
|
|
|
{
|
|
|
faux_argv_t *args = NULL;
|
|
|
pline_t *pline = NULL;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
const char *entry_name = NULL;
|
|
|
faux_argv_t *cur_path = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn))
|
|
|
- return -1;
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
entry_name = kentry_name(kcontext_candidate_entry(context));
|
|
@@ -118,8 +112,6 @@ static int srp_compl_or_help(kcontext_t *context, bool_t help)
|
|
|
pline_print_completions(pline, help);
|
|
|
pline_free(pline);
|
|
|
|
|
|
- sr_disconnect(conn);
|
|
|
-
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -160,7 +152,6 @@ static int srp_check_type(kcontext_t *context,
|
|
|
int ret = -1;
|
|
|
faux_argv_t *args = NULL;
|
|
|
pline_t *pline = NULL;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
const char *entry_name = NULL;
|
|
|
const char *value = NULL;
|
|
@@ -169,13 +160,7 @@ static int srp_check_type(kcontext_t *context,
|
|
|
faux_argv_t *cur_path = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
-
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn))
|
|
|
- return -1;
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
entry_name = kentry_name(kcontext_candidate_entry(context));
|
|
@@ -201,7 +186,6 @@ static int srp_check_type(kcontext_t *context,
|
|
|
ret = 0;
|
|
|
err:
|
|
|
pline_free(pline);
|
|
|
- sr_disconnect(conn);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -265,7 +249,6 @@ int srp_PLINE_INSERT_TO(kcontext_t *context)
|
|
|
int ret = -1;
|
|
|
faux_argv_t *args = NULL;
|
|
|
pline_t *pline = NULL;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
const char *value = NULL;
|
|
|
pexpr_t *expr = NULL;
|
|
@@ -273,13 +256,7 @@ int srp_PLINE_INSERT_TO(kcontext_t *context)
|
|
|
faux_argv_t *cur_path = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
-
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn))
|
|
|
- return -1;
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
value = kcontext_candidate_value(context);
|
|
@@ -300,7 +277,6 @@ int srp_PLINE_INSERT_TO(kcontext_t *context)
|
|
|
ret = 0;
|
|
|
err:
|
|
|
pline_free(pline);
|
|
|
- sr_disconnect(conn);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -310,18 +286,11 @@ static int srp_compl_or_help_insert_to(kcontext_t *context, bool_t help)
|
|
|
{
|
|
|
faux_argv_t *args = NULL;
|
|
|
pline_t *pline = NULL;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
faux_argv_t *cur_path = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
-
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn))
|
|
|
- return -1;
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
args = assemble_insert_to(sess, kcontext_parent_pargv(context),
|
|
@@ -331,8 +300,6 @@ static int srp_compl_or_help_insert_to(kcontext_t *context, bool_t help)
|
|
|
pline_print_completions(pline, help);
|
|
|
pline_free(pline);
|
|
|
|
|
|
- sr_disconnect(conn);
|
|
|
-
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -354,7 +321,6 @@ int srp_set(kcontext_t *context)
|
|
|
int ret = 0;
|
|
|
faux_argv_t *args = NULL;
|
|
|
pline_t *pline = NULL;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
faux_list_node_t *iter = NULL;
|
|
|
pexpr_t *expr = NULL;
|
|
@@ -362,16 +328,7 @@ int srp_set(kcontext_t *context)
|
|
|
faux_argv_t *cur_path = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
-
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't connect to data store\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
args = param2argv(cur_path, kcontext_pargv(context), "path");
|
|
@@ -416,7 +373,6 @@ int srp_set(kcontext_t *context)
|
|
|
|
|
|
cleanup:
|
|
|
pline_free(pline);
|
|
|
- sr_disconnect(conn);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -427,22 +383,12 @@ int srp_del(kcontext_t *context)
|
|
|
int ret = -1;
|
|
|
faux_argv_t *args = NULL;
|
|
|
pline_t *pline = NULL;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
pexpr_t *expr = NULL;
|
|
|
faux_argv_t *cur_path = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
-
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't connect to data store\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
args = param2argv(cur_path, kcontext_pargv(context), "path");
|
|
@@ -479,7 +425,6 @@ int srp_del(kcontext_t *context)
|
|
|
ret = 0;
|
|
|
err:
|
|
|
pline_free(pline);
|
|
|
- sr_disconnect(conn);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -490,22 +435,12 @@ int srp_edit(kcontext_t *context)
|
|
|
int ret = -1;
|
|
|
faux_argv_t *args = NULL;
|
|
|
pline_t *pline = NULL;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
pexpr_t *expr = NULL;
|
|
|
faux_argv_t *cur_path = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
-
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't connect to data store\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
args = param2argv(cur_path, kcontext_pargv(context), "path");
|
|
@@ -546,7 +481,6 @@ err:
|
|
|
if (ret < 0)
|
|
|
faux_argv_free(args);
|
|
|
pline_free(pline);
|
|
|
- sr_disconnect(conn);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -564,27 +498,17 @@ int srp_top(kcontext_t *context)
|
|
|
|
|
|
int srp_up(kcontext_t *context)
|
|
|
{
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
faux_argv_t *cur_path = NULL;
|
|
|
faux_argv_node_t *iter = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
if (!cur_path)
|
|
|
return -1; // It's top level and can't level up
|
|
|
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't connect to data store\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
// Remove last arguments one by one and wait for legal edit-like pline
|
|
|
while (faux_argv_len(cur_path) > 0) {
|
|
|
pline_t *pline = NULL;
|
|
@@ -617,8 +541,6 @@ int srp_up(kcontext_t *context)
|
|
|
if (faux_argv_len(cur_path) == 0)
|
|
|
srp_udata_set_path(context, NULL);
|
|
|
|
|
|
- sr_disconnect(conn);
|
|
|
-
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -628,7 +550,6 @@ int srp_insert(kcontext_t *context)
|
|
|
int ret = -1;
|
|
|
pline_t *pline = NULL;
|
|
|
pline_t *pline_to = NULL;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
pexpr_t *expr = NULL;
|
|
|
pexpr_t *expr_to = NULL;
|
|
@@ -641,16 +562,7 @@ int srp_insert(kcontext_t *context)
|
|
|
const char *leaflist_value = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
-
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't connect to data store\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
pargv = kcontext_pargv(context);
|
|
@@ -736,7 +648,6 @@ int srp_insert(kcontext_t *context)
|
|
|
err:
|
|
|
pline_free(pline);
|
|
|
pline_free(pline_to);
|
|
|
- sr_disconnect(conn);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -745,20 +656,10 @@ err:
|
|
|
int srp_verify(kcontext_t *context)
|
|
|
{
|
|
|
int ret = -1;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
-
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't connect to data store\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
// Validate candidate config
|
|
|
if (sr_validate(sess, NULL, 0) != SR_ERR_OK) {
|
|
@@ -768,7 +669,6 @@ int srp_verify(kcontext_t *context)
|
|
|
|
|
|
ret = 0;
|
|
|
err:
|
|
|
- sr_disconnect(conn);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -777,20 +677,10 @@ err:
|
|
|
int srp_commit(kcontext_t *context)
|
|
|
{
|
|
|
int ret = -1;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
-
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't connect to data store\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
// Copy candidate to running-config
|
|
|
if (sr_session_switch_ds(sess, SR_DS_RUNNING)) {
|
|
@@ -814,7 +704,7 @@ int srp_commit(kcontext_t *context)
|
|
|
|
|
|
ret = 0;
|
|
|
err:
|
|
|
- sr_disconnect(conn);
|
|
|
+ sr_session_switch_ds(sess, SRP_REPO_EDIT);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -823,20 +713,10 @@ err:
|
|
|
int srp_reset(kcontext_t *context)
|
|
|
{
|
|
|
int ret = -1;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
-
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't connect to data store\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
// Copy running-config to candidate config
|
|
|
if (sr_copy_config(sess, NULL, SR_DS_RUNNING, 0) != SR_ERR_OK) {
|
|
@@ -846,7 +726,6 @@ int srp_reset(kcontext_t *context)
|
|
|
|
|
|
ret = 0;
|
|
|
err:
|
|
|
- sr_disconnect(conn);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -857,7 +736,6 @@ int srp_show_xml(kcontext_t *context)
|
|
|
int ret = -1;
|
|
|
faux_argv_t *args = NULL;
|
|
|
pline_t *pline = NULL;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
pexpr_t *expr = NULL;
|
|
|
faux_argv_t *cur_path = NULL;
|
|
@@ -865,16 +743,7 @@ int srp_show_xml(kcontext_t *context)
|
|
|
struct ly_out *out = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
-
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't connect to data store\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
args = param2argv(cur_path, kcontext_pargv(context), "path");
|
|
@@ -901,6 +770,8 @@ int srp_show_xml(kcontext_t *context)
|
|
|
srp_error(sess, ERRORMSG "Can't get specified subtree\n");
|
|
|
goto err;
|
|
|
}
|
|
|
+ if (!data) // Not found
|
|
|
+ goto err;
|
|
|
|
|
|
ly_out_new_file(stdout, &out);
|
|
|
lyd_print_tree(out, data->tree, LYD_XML, 0);
|
|
@@ -920,7 +791,6 @@ int srp_show_xml(kcontext_t *context)
|
|
|
ret = 0;
|
|
|
err:
|
|
|
pline_free(pline);
|
|
|
- sr_disconnect(conn);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -939,7 +809,8 @@ static int show(kcontext_t *context, sr_datastore_t ds)
|
|
|
assert(context);
|
|
|
|
|
|
sess = srp_udata_sr_sess(context);
|
|
|
- sr_session_switch_ds(sess, ds);
|
|
|
+ if (ds != SRP_REPO_EDIT)
|
|
|
+ sr_session_switch_ds(sess, ds);
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
|
|
|
if (kpargv_find(kcontext_pargv(context), "path") || cur_path) {
|
|
@@ -977,6 +848,8 @@ static int show(kcontext_t *context, sr_datastore_t ds)
|
|
|
ret = 0;
|
|
|
err:
|
|
|
pline_free(pline);
|
|
|
+ if (ds != SRP_REPO_EDIT)
|
|
|
+ sr_session_switch_ds(sess, SRP_REPO_EDIT);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -990,21 +863,12 @@ int srp_show(kcontext_t *context)
|
|
|
|
|
|
int srp_show_running(kcontext_t *context)
|
|
|
{
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't connect to data store\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SR_DS_RUNNING, &sess)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ assert(context);
|
|
|
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
show_xpath(sess, NULL, srp_udata_opts(context));
|
|
|
- sr_disconnect(conn);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -1015,7 +879,6 @@ int srp_deactivate(kcontext_t *context)
|
|
|
int ret = -1;
|
|
|
faux_argv_t *args = NULL;
|
|
|
pline_t *pline = NULL;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
pexpr_t *expr = NULL;
|
|
|
faux_argv_t *cur_path = NULL;
|
|
@@ -1023,15 +886,7 @@ int srp_deactivate(kcontext_t *context)
|
|
|
|
|
|
assert(context);
|
|
|
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't connect to data store\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
args = param2argv(cur_path, kcontext_pargv(context), "path");
|
|
@@ -1058,6 +913,8 @@ int srp_deactivate(kcontext_t *context)
|
|
|
srp_error(sess, ERRORMSG "Can't get specified subtree\n");
|
|
|
goto err;
|
|
|
}
|
|
|
+ if (!data) // Not found
|
|
|
+ goto err;
|
|
|
if (lyd_new_meta(LYD_CTX(data->tree), data->tree, NULL,
|
|
|
"junos-configuration-metadata:active", "false", 0, NULL)) {
|
|
|
fprintf(stderr, ERRORMSG "Can't deactivate\n");
|
|
@@ -1079,6 +936,8 @@ int srp_deactivate(kcontext_t *context)
|
|
|
srp_error(sess, ERRORMSG "Can't get specified subtree\n");
|
|
|
goto err;
|
|
|
}
|
|
|
+ if (!data) // Not found
|
|
|
+ goto err;
|
|
|
|
|
|
struct ly_out *out = NULL;
|
|
|
ly_out_new_file(stdout, &out);
|
|
@@ -1090,7 +949,6 @@ int srp_deactivate(kcontext_t *context)
|
|
|
ret = 0;
|
|
|
err:
|
|
|
pline_free(pline);
|
|
|
- sr_disconnect(conn);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -1100,9 +958,7 @@ int srp_diff(kcontext_t *context)
|
|
|
{
|
|
|
int ret = -1;
|
|
|
pline_t *pline = NULL;
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
- sr_session_ctx_t *sess1 = NULL;
|
|
|
- sr_session_ctx_t *sess2 = NULL;
|
|
|
+ sr_session_ctx_t *sess = NULL;
|
|
|
sr_data_t *data1 = NULL;
|
|
|
sr_data_t *data2 = NULL;
|
|
|
faux_argv_t *cur_path = NULL;
|
|
@@ -1110,21 +966,7 @@ int srp_diff(kcontext_t *context)
|
|
|
struct lyd_node *diff = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
-
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't connect to data store\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SR_DS_RUNNING, &sess1)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (sr_session_start(conn, SRP_REPO_EDIT, &sess2)) {
|
|
|
- fprintf(stderr, ERRORMSG "Can't start data store session\n");
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
|
|
|
cur_path = (faux_argv_t *)srp_udata_path(context);
|
|
|
|
|
@@ -1133,7 +975,7 @@ int srp_diff(kcontext_t *context)
|
|
|
pexpr_t *expr = NULL;
|
|
|
|
|
|
args = param2argv(cur_path, kcontext_pargv(context), "path");
|
|
|
- pline = pline_parse(sess2, args, srp_udata_opts(context));
|
|
|
+ pline = pline_parse(sess, args, srp_udata_opts(context));
|
|
|
faux_argv_free(args);
|
|
|
|
|
|
if (pline->invalid) {
|
|
@@ -1164,17 +1006,22 @@ int srp_diff(kcontext_t *context)
|
|
|
if (!xpath)
|
|
|
xpath = "/*";
|
|
|
|
|
|
- if (sr_get_data(sess1, xpath, 0, 0, 0, &data1) != SR_ERR_OK) {
|
|
|
- srp_error(sess1, ERRORMSG "Can't get specified subtree\n");
|
|
|
+ if (sr_get_data(sess, xpath, 0, 0, 0, &data2) != SR_ERR_OK) {
|
|
|
+ srp_error(sess, ERRORMSG "Can't get specified subtree\n");
|
|
|
goto err;
|
|
|
}
|
|
|
- if (sr_get_data(sess2, xpath, 0, 0, 0, &data2) != SR_ERR_OK) {
|
|
|
- srp_error(sess2, ERRORMSG "Can't get specified subtree\n");
|
|
|
+
|
|
|
+ // Running config
|
|
|
+ sr_session_switch_ds(sess, SR_DS_RUNNING);
|
|
|
+
|
|
|
+ if (sr_get_data(sess, xpath, 0, 0, 0, &data1) != SR_ERR_OK) {
|
|
|
+ srp_error(sess, ERRORMSG "Can't get specified subtree\n");
|
|
|
goto err;
|
|
|
}
|
|
|
|
|
|
- if (lyd_diff_siblings(data1->tree, data2->tree, 0, &diff) != LY_SUCCESS) {
|
|
|
- srp_error(sess2, ERRORMSG "Can't generate diff\n");
|
|
|
+ if (lyd_diff_siblings(data1 ? data1->tree : NULL, data2 ? data2->tree : NULL,
|
|
|
+ 0, &diff) != LY_SUCCESS) {
|
|
|
+ srp_error(sess, ERRORMSG "Can't generate diff\n");
|
|
|
goto err;
|
|
|
}
|
|
|
|
|
@@ -1189,7 +1036,7 @@ err:
|
|
|
sr_release_data(data2);
|
|
|
|
|
|
pline_free(pline);
|
|
|
- sr_disconnect(conn);
|
|
|
+ sr_session_switch_ds(sess, SRP_REPO_EDIT);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -1197,7 +1044,6 @@ err:
|
|
|
|
|
|
static int srp_compl_xpath(kcontext_t *context, const sr_datastore_t datastore)
|
|
|
{
|
|
|
- sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
sr_val_t *vals = NULL;
|
|
|
size_t val_num = 0;
|
|
@@ -1209,12 +1055,9 @@ static int srp_compl_xpath(kcontext_t *context, const sr_datastore_t datastore)
|
|
|
if (faux_str_is_empty(script))
|
|
|
return -1;
|
|
|
|
|
|
- if (sr_connect(SR_CONN_DEFAULT, &conn))
|
|
|
- return -1;
|
|
|
- if (sr_session_start(conn, datastore, &sess)) {
|
|
|
- sr_disconnect(conn);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ sess = srp_udata_sr_sess(context);
|
|
|
+ if (datastore != SRP_REPO_EDIT)
|
|
|
+ sr_session_switch_ds(sess, datastore);
|
|
|
|
|
|
sr_get_items(sess, script, 0, 0, &vals, &val_num);
|
|
|
for (i = 0; i < val_num; i++) {
|
|
@@ -1226,7 +1069,8 @@ static int srp_compl_xpath(kcontext_t *context, const sr_datastore_t datastore)
|
|
|
}
|
|
|
sr_free_values(vals, val_num);
|
|
|
|
|
|
- sr_disconnect(conn);
|
|
|
+ if (datastore != SRP_REPO_EDIT)
|
|
|
+ sr_session_switch_ds(sess, SRP_REPO_EDIT);
|
|
|
|
|
|
return 0;
|
|
|
}
|