Skip to content

Commit

Permalink
server UPDATE libyang v3 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed Feb 27, 2024
1 parent f2a956d commit 4a76359
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 40 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ endif()
set(NP2SRV_VERSION 2.2.16)

# libyang required version
set(LIBYANG_DEP_VERSION 2.1.146)
set(LIBYANG_DEP_SOVERSION 2.46.1)
set(LIBYANG_DEP_SOVERSION_MAJOR 2)
set(LIBYANG_DEP_VERSION 2.2.0)
set(LIBYANG_DEP_SOVERSION 3.0.0)
set(LIBYANG_DEP_SOVERSION_MAJOR 3)

# libnetconf2 required version
set(LIBNETCONF2_DEP_VERSION 3.0.10)
Expand Down
24 changes: 12 additions & 12 deletions cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
int done;
extern struct nc_session *session;

void
static void
lnc2_print_clb(const struct nc_session *UNUSED(session), NC_VERB_LEVEL level, const char *msg)
{
int was_rawmode = 0;
Expand Down Expand Up @@ -73,8 +73,8 @@ lnc2_print_clb(const struct nc_session *UNUSED(session), NC_VERB_LEVEL level, co
}
}

void
ly_print_clb(LY_LOG_LEVEL level, const char *msg, const char *path)
static void
ly_print_clb(LY_LOG_LEVEL level, const char *msg, const char *data_path, const char *schema_path, uint64_t UNUSED(line))
{
int was_rawmode = 0;

Expand All @@ -86,29 +86,29 @@ ly_print_clb(LY_LOG_LEVEL level, const char *msg, const char *path)

switch (level) {
case LY_LLERR:
if (path) {
fprintf(stderr, "ly ERROR: %s (%s)\n", msg, path);
if (data_path || schema_path) {
fprintf(stderr, "ly ERROR: %s (%s)\n", msg, data_path ? data_path : schema_path);
} else {
fprintf(stderr, "ly ERROR: %s\n", msg);
}
break;
case LY_LLWRN:
if (path) {
fprintf(stderr, "ly WARNING: %s (%s)\n", msg, path);
if (data_path || schema_path) {
fprintf(stderr, "ly WARNING: %s (%s)\n", msg, data_path ? data_path : schema_path);
} else {
fprintf(stderr, "ly WARNING: %s\n", msg);
}
break;
case LY_LLVRB:
if (path) {
fprintf(stderr, "ly VERBOSE: %s (%s)\n", msg, path);
if (data_path || schema_path) {
fprintf(stderr, "ly VERBOSE: %s (%s)\n", msg, data_path ? data_path : schema_path);
} else {
fprintf(stderr, "ly VERBOSE: %s\n", msg);
}
break;
case LY_LLDBG:
if (path) {
fprintf(stderr, "ly DEBUG: %s (%s)\n", msg, path);
if (data_path || schema_path) {
fprintf(stderr, "ly DEBUG: %s (%s)\n", msg, data_path ? data_path : schema_path);
} else {
fprintf(stderr, "ly DEBUG: %s\n", msg);
}
Expand Down Expand Up @@ -139,7 +139,7 @@ main(void)
sigaction(SIGPIPE, &action, NULL);

nc_set_print_clb_session(lnc2_print_clb);
ly_set_log_clb(ly_print_clb, 1);
ly_set_log_clb(ly_print_clb);
linenoiseSetCompletionCallback(complete_cmd);
linenoiseHistoryDataFree(free);

Expand Down
8 changes: 4 additions & 4 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ op_parse_url(const char *url, int validate, int *rc, sr_session_ctx_t *ev_sess)
/* load the whole config element */
if (lyd_parse_data_mem(ly_ctx, url_data, LYD_XML, LYD_PARSE_OPAQ | LYD_PARSE_ONLY | LYD_PARSE_NO_STATE, 0, &config)) {
*rc = SR_ERR_LY;
sr_session_set_error_message(ev_sess, ly_errmsg(ly_ctx));
sr_session_set_error_message(ev_sess, ly_err_last(ly_ctx)->msg);
goto cleanup;
}

Expand All @@ -700,7 +700,7 @@ op_parse_url(const char *url, int validate, int *rc, sr_session_ctx_t *ev_sess)
/* separate validation if requested */
if (lyd_validate_all(&data, NULL, LYD_VALIDATE_NO_STATE, NULL)) {
*rc = SR_ERR_LY;
sr_session_set_error_message(ev_sess, ly_errmsg(ly_ctx));
sr_session_set_error_message(ev_sess, ly_err_last(ly_ctx)->msg);
goto cleanup;
}
}
Expand Down Expand Up @@ -732,7 +732,7 @@ op_export_url(const char *url, struct lyd_node *data, uint32_t print_options, in
/* print the config as expected by the other end */
if (lyd_new_opaq2(NULL, ly_ctx, "config", NULL, NULL, "urn:ietf:params:xml:ns:netconf:base:1.0", &config)) {
*rc = SR_ERR_LY;
sr_session_set_error_message(ev_sess, ly_errmsg(ly_ctx));
sr_session_set_error_message(ev_sess, ly_err_last(ly_ctx)->msg);
ret = -1;
goto cleanup;
}
Expand Down Expand Up @@ -829,7 +829,7 @@ op_parse_config(struct lyd_node_any *config, uint32_t parse_options, int *rc, sr
}
if (lyrc) {
*rc = SR_ERR_LY;
sr_session_set_error_message(ev_sess, ly_errmsg(ly_ctx));
sr_session_set_error_message(ev_sess, ly_err_last(ly_ctx)->msg);
}

return root;
Expand Down
9 changes: 2 additions & 7 deletions src/err_netconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,8 @@ np_err_sr2nc_edit(sr_session_ctx_t *ev_sess, const sr_session_ctx_t *err_sess)
err = &err_info->err[0];

/* get path */
if ((ptr = strstr(err->message, "Data location \""))) {
ptr += 15;
}
if (!ptr) {
if ((ptr = strstr(err->message, "Schema location \""))) {
ptr += 17;
}
if ((ptr = strstr(err->message, "(path \""))) {
ptr += 7;
}
if (ptr) {
path = strndup(ptr, strchr(ptr, '\"') - ptr);
Expand Down
6 changes: 3 additions & 3 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ np2log_cb_nc2(const struct nc_session *session, NC_VERB_LEVEL level, const char
* @brief printer callback for libyang
*/
void
np2log_cb_ly(LY_LOG_LEVEL level, const char *msg, const char *path)
np2log_cb_ly(LY_LOG_LEVEL level, const char *msg, const char *data_path, const char *schema_path, uint64_t UNUSED(line))
{
int priority;

Expand All @@ -149,8 +149,8 @@ np2log_cb_ly(LY_LOG_LEVEL level, const char *msg, const char *path)
return;
}

if (path) {
np2log(priority, "LY", "%s (%s)", msg, path);
if (data_path || schema_path) {
np2log(priority, "LY", "%s (path \"%s\")", msg, data_path ? data_path : schema_path);
} else {
np2log(priority, "LY", "%s", msg);
}
Expand Down
2 changes: 1 addition & 1 deletion src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void np2log_cb_nc2(const struct nc_session *session, NC_VERB_LEVEL level, const
/**
* @brief printer callback for libyang
*/
void np2log_cb_ly(LY_LOG_LEVEL level, const char *msg, const char *path);
void np2log_cb_ly(LY_LOG_LEVEL level, const char *msg, const char *data_path, const char *schema_path, uint64_t line);

/**
* @brief printer callback for sysrepo
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ main(int argc, char *argv[])

/* set printer callbacks for the used libraries and set proper log levels */
nc_set_print_clb_session(np2log_cb_nc2); /* libnetconf2 */
ly_set_log_clb(np2log_cb_ly, 1); /* libyang */
ly_set_log_clb(np2log_cb_ly); /* libyang */
sr_log_set_cb(np2log_cb_sr); /* sysrepo, log level is checked by callback */

/* initiate NETCONF server */
Expand Down
4 changes: 2 additions & 2 deletions src/netconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ np2srv_get_rpc_data(sr_session_ctx_t *session, const char *xp_filter, sr_session
}

/* now filter only the requested data from the created running data + state data */
if (lyd_find_xpath3(NULL, base_data, xp_filter, NULL, &set)) {
if (lyd_find_xpath3(NULL, base_data, xp_filter, LY_VALUE_JSON, NULL, NULL, &set)) {
rc = SR_ERR_LY;
goto cleanup;
}
Expand Down Expand Up @@ -198,7 +198,7 @@ np2srv_rpc_get_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id), const char
}

/* add output */
if (lyd_new_any(output, NULL, "data", data_get, 1, LYD_ANYDATA_DATATREE, 1, &node)) {
if (lyd_new_any(output, NULL, "data", data_get, LYD_ANYDATA_DATATREE, LYD_NEW_ANY_USE_VALUE | LYD_NEW_VAL_OUTPUT, &node)) {
rc = SR_ERR_LY;
goto cleanup;
}
Expand Down
2 changes: 1 addition & 1 deletion src/netconf_confirmed_commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ ncc_get_running_backup(const struct ly_ctx *ctx, const char *path, struct lyd_no
int ret = SR_ERR_OK;

if (lyd_parse_data_path(ctx, path, LYD_JSON, LYD_PARSE_ORDERED | LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, node)) {
ERR("Failed parsing confirmed commit backup of running for file \"%s\" (%s).", path, ly_errmsg(ctx));
ERR("Failed parsing confirmed commit backup of running for file \"%s\" (%s).", path, ly_err_last(ctx)->msg);
ret = SR_ERR_LY;
goto cleanup;
}
Expand Down
2 changes: 1 addition & 1 deletion src/netconf_monitoring.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ np2srv_rpc_getschema_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id), cons
}

/* add output */
if (lyd_new_any(output, NULL, "data", model_data, 1, LYD_ANYDATA_STRING, 1, NULL)) {
if (lyd_new_any(output, NULL, "data", model_data, LYD_ANYDATA_STRING, LYD_NEW_ANY_USE_VALUE | LYD_NEW_VAL_OUTPUT, NULL)) {
rc = SR_ERR_LY;
goto cleanup;
}
Expand Down
2 changes: 1 addition & 1 deletion src/netconf_nmda.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ np2srv_rpc_getdata_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id), const
ly_set_free(nodeset, NULL);

/* add output */
if (lyd_new_any(output, NULL, "data", data, 1, LYD_ANYDATA_DATATREE, 1, NULL)) {
if (lyd_new_any(output, NULL, "data", data, LYD_ANYDATA_DATATREE, LYD_NEW_ANY_USE_VALUE | LYD_NEW_VAL_OUTPUT, NULL)) {
rc = SR_ERR_LY;
goto cleanup;
}
Expand Down
6 changes: 3 additions & 3 deletions src/netconf_subscribed_notifications.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ sub_ntf_error_ly(sr_session_ctx_t *ev_sess, const struct ly_ctx *ly_ctx)
{
const char *msg;

msg = ly_errmsg(ly_ctx);
msg = ly_err_last(ly_ctx)->msg;

ERR("%s", msg);
sr_session_set_error_message(ev_sess, "%s", msg);
Expand Down Expand Up @@ -747,7 +747,7 @@ sub_ntf_append_params_filter(sr_session_ctx_t *ev_sess, struct lyd_node *parent,
} else if (sub->subtree_filter) {
/* stream-subtree-filter */
any = (struct lyd_node_any *)sub->subtree_filter;
if (lyd_new_any(parent, NULL, "stream-subtree-filter", any->value.tree, 0, any->value_type, 0, NULL)) {
if (lyd_new_any(parent, NULL, "stream-subtree-filter", any->value.tree, any->value_type, 0, NULL)) {
rc = sub_ntf_error_ly(ev_sess, LYD_CTX(parent));
goto cleanup;
}
Expand All @@ -768,7 +768,7 @@ sub_ntf_append_params_filter(sr_session_ctx_t *ev_sess, struct lyd_node *parent,
} else if (sub->subtree_filter) {
/* datastore-subtree-filter */
any = (struct lyd_node_any *)sub->subtree_filter;
if (lyd_new_any(parent, yp_mod, "datastore-subtree-filter", any->value.tree, 0, any->value_type, 0, NULL)) {
if (lyd_new_any(parent, yp_mod, "datastore-subtree-filter", any->value.tree, any->value_type, 0, NULL)) {
rc = sub_ntf_error_ly(ev_sess, LYD_CTX(parent));
goto cleanup;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ test_unknown_element(void **state)
" <error-type>application</error-type>\n"
" <error-tag>unknown-element</error-tag>\n"
" <error-severity>error</error-severity>\n"
" <error-message xml:lang=\"en\">Node \"numero\" not found in the \"errors\" module. (Path \"/\".)</error-message>\n"
" <error-message xml:lang=\"en\">Node \"numero\" not found in the \"errors\" module. (path \"/\")</error-message>\n"
" <error-info>\n"
" <bad-element>numero</bad-element>\n"
" </error-info>\n"
Expand Down

0 comments on commit 4a76359

Please sign in to comment.