server session CHANGE libyang error API changes
diff --git a/src/messages_server.c b/src/messages_server.c
index 9962af1..25a6eaa 100644
--- a/src/messages_server.c
+++ b/src/messages_server.c
@@ -361,7 +361,7 @@
}
API struct nc_server_error *
-nc_err_libyang(void)
+nc_err_libyang(struct ly_ctx *ctx)
{
struct nc_server_error *e;
struct lyxml_elem *elem;
@@ -373,15 +373,15 @@
/* LY_SUCCESS */
return NULL;
} else if (ly_errno == LY_EVALID) {
- switch (ly_vecode) {
+ switch (ly_vecode(ctx)) {
/* RFC 6020 section 13 errors */
case LYVE_NOUNIQ:
e = nc_err(NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
nc_err_set_app_tag(e, "data-not-unique");
- nc_err_set_path(e, ly_errpath());
+ nc_err_set_path(e, ly_errpath(ctx));
/* parse the message and get all the information we need */
- str = ly_errmsg();
+ str = ly_errmsg(ctx);
uniqi = strchr(str, '"');
uniqi++;
uniqj = strchr(uniqi, '"');
@@ -431,17 +431,17 @@
case LYVE_NOMAX:
e = nc_err(NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
nc_err_set_app_tag(e, "too-many-elements");
- nc_err_set_path(e, ly_errpath());
+ nc_err_set_path(e, ly_errpath(ctx));
break;
case LYVE_NOMIN:
e = nc_err(NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
nc_err_set_app_tag(e, "too-few-elements");
- nc_err_set_path(e, ly_errpath());
+ nc_err_set_path(e, ly_errpath(ctx));
break;
case LYVE_NOMUST:
e = nc_err(NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
- if (ly_errapptag()[0]) {
- nc_err_set_app_tag(e, ly_errapptag());
+ if (ly_errapptag(ctx)) {
+ nc_err_set_app_tag(e, ly_errapptag(ctx));
} else {
nc_err_set_app_tag(e, "must-violation");
}
@@ -450,14 +450,14 @@
case LYVE_NOLEAFREF:
e = nc_err(NC_ERR_DATA_MISSING);
nc_err_set_app_tag(e, "instance-required");
- nc_err_set_path(e, ly_errpath());
+ nc_err_set_path(e, ly_errpath(ctx));
break;
case LYVE_NOMANDCHOICE:
e = nc_err(NC_ERR_DATA_MISSING);
nc_err_set_app_tag(e, "missing-choice");
- nc_err_set_path(e, ly_errpath());
+ nc_err_set_path(e, ly_errpath(ctx));
- str = ly_errmsg();
+ str = ly_errmsg(ctx);
stri = strchr(str, '"');
stri++;
strj = strchr(stri, '"');
@@ -467,26 +467,26 @@
}
break;
case LYVE_INELEM:
- str = ly_errpath();
+ str = ly_errpath(ctx);
if (!strcmp(str, "/")) {
e = nc_err(NC_ERR_OP_NOT_SUPPORTED, NC_ERR_TYPE_APP);
/* keep default message */
return e;
} else {
- e = nc_err(NC_ERR_UNKNOWN_ELEM, NC_ERR_TYPE_PROT, ly_errpath());
+ e = nc_err(NC_ERR_UNKNOWN_ELEM, NC_ERR_TYPE_PROT, ly_errpath(ctx));
}
break;
case LYVE_MISSELEM:
case LYVE_INORDER:
- e = nc_err(NC_ERR_MISSING_ELEM, NC_ERR_TYPE_PROT, ly_errpath());
+ e = nc_err(NC_ERR_MISSING_ELEM, NC_ERR_TYPE_PROT, ly_errpath(ctx));
break;
case LYVE_INVAL:
- e = nc_err(NC_ERR_BAD_ELEM, NC_ERR_TYPE_PROT, ly_errpath());
+ e = nc_err(NC_ERR_BAD_ELEM, NC_ERR_TYPE_PROT, ly_errpath(ctx));
break;
case LYVE_INATTR:
case LYVE_MISSATTR:
case LYVE_INMETA:
- str = ly_errmsg();
+ str = ly_errmsg(ctx);
stri = strchr(str, '"');
stri++;
if (!strncmp(stri, "<none>:", 7)) {
@@ -495,12 +495,12 @@
strj = strchr(stri, '"');
strj--;
attr = strndup(stri, (strj - stri) + 1);
- if (ly_vecode == LYVE_INATTR) {
- e = nc_err(NC_ERR_UNKNOWN_ATTR, NC_ERR_TYPE_PROT, attr, ly_errpath());
- } else if (ly_vecode == LYVE_MISSATTR) {
- e = nc_err(NC_ERR_MISSING_ATTR, NC_ERR_TYPE_PROT, attr, ly_errpath());
+ if (ly_vecode(ctx) == LYVE_INATTR) {
+ e = nc_err(NC_ERR_UNKNOWN_ATTR, NC_ERR_TYPE_PROT, attr, ly_errpath(ctx));
+ } else if (ly_vecode(ctx) == LYVE_MISSATTR) {
+ e = nc_err(NC_ERR_MISSING_ATTR, NC_ERR_TYPE_PROT, attr, ly_errpath(ctx));
} else { /* LYVE_INMETA */
- e = nc_err(NC_ERR_BAD_ATTR, NC_ERR_TYPE_PROT, attr, ly_errpath());
+ e = nc_err(NC_ERR_BAD_ATTR, NC_ERR_TYPE_PROT, attr, ly_errpath(ctx));
}
free(attr);
break;
@@ -508,8 +508,8 @@
case LYVE_NOWHEN:
e = nc_err(NC_ERR_INVALID_VALUE, NC_ERR_TYPE_PROT);
/* LYVE_NOCONSTR (length, range, pattern) can have a specific error-app-tag */
- if (ly_errapptag()[0]) {
- nc_err_set_app_tag(e, ly_errapptag());
+ if (ly_errapptag(ctx)) {
+ nc_err_set_app_tag(e, ly_errapptag(ctx));
}
break;
default:
@@ -520,7 +520,7 @@
/* non-validation (internal) error */
e = nc_err(NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
}
- nc_err_set_msg(e, ly_errmsg(), "en");
+ nc_err_set_msg(e, ly_errmsg(ctx), "en");
return e;
}
diff --git a/src/messages_server.h b/src/messages_server.h
index 151e50c..9d9d9c2 100644
--- a/src/messages_server.h
+++ b/src/messages_server.h
@@ -169,9 +169,10 @@
* The function should be used immediately when a libyang function fails to generate
* NETCONF error structure based on internal libyang error information (ly_errno, ly_errmsg, ...)
*
+ * @param[in] ctx Libyang context to read the error from.
* @return Server error structure, NULL on error.
*/
-struct nc_server_error *nc_err_libyang(void);
+struct nc_server_error *nc_err_libyang(struct ly_ctx *ctx);
/**
* @brief Get the \<error-type\> of a server error.
diff --git a/src/session_server.c b/src/session_server.c
index 5d376d7..67b1198 100644
--- a/src/session_server.c
+++ b/src/session_server.c
@@ -1031,7 +1031,7 @@
LYD_OPT_RPC | LYD_OPT_DESTRUCT | LYD_OPT_NOEXTDEPS | LYD_OPT_STRICT, NULL);
if (!(*rpc)->tree) {
/* parsing RPC failed */
- reply = nc_server_reply_err(nc_err_libyang());
+ reply = nc_server_reply_err(nc_err_libyang(server_opts.ctx));
ret = nc_write_msg(session, NC_MSG_REPLY, xml, reply);
nc_server_reply_free(reply);
if (ret == -1) {