diff options
| author | Martin Winter <mwinter@opensourcerouting.org> | 2024-05-08 12:48:03 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-08 12:48:03 +0200 | 
| commit | 8e2b2caf6592b587749777f00778bf48fa164ed5 (patch) | |
| tree | 2f4f56138328a6e66bff959e07fba04cfe091ca5 /lib/yang.c | |
| parent | 190f8baa7b898511c6757aede6ac0a8acbb9d2a3 (diff) | |
| parent | 9fd31367b42aa13983eca97958efc658f3bdbb19 (diff) | |
Merge pull request #15608 from vjardin/libyang3
libyang3 - fondation step 1
Diffstat (limited to 'lib/yang.c')
| -rw-r--r-- | lib/yang.c | 54 | 
1 files changed, 45 insertions, 9 deletions
diff --git a/lib/yang.c b/lib/yang.c index 06d29bb9c4..702fcf436d 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -11,6 +11,7 @@  #include "lib_errors.h"  #include "yang.h"  #include "yang_translator.h" +#include <libyang/version.h>  #include "northbound.h"  #include "frrstr.h" @@ -19,6 +20,17 @@  DEFINE_MTYPE_STATIC(LIB, YANG_MODULE, "YANG module");  DEFINE_MTYPE_STATIC(LIB, YANG_DATA, "YANG data structure"); +/* Safe to remove after libyang 2.2.8 */ +#if (LY_VERSION_MAJOR < 3) +#define yang_lyd_find_xpath3(ctx_node, tree, xpath, format, prefix_data, vars, \ +			     set)                                              \ +	lyd_find_xpath3(ctx_node, tree, xpath, vars, set) +#else +#define yang_lyd_find_xpath3(ctx_node, tree, xpath, format, prefix_data, vars, \ +			     set)                                              \ +	lyd_find_xpath3(ctx_node, tree, xpath, LY_VALUE_JSON, NULL, vars, set) +#endif +  /* libyang container. */  struct ly_ctx *ly_native_ctx; @@ -712,7 +724,12 @@ struct yang_data *yang_data_list_find(const struct list *list,  }  /* Make libyang log its errors using FRR logging infrastructure. */ -static void ly_log_cb(LY_LOG_LEVEL level, const char *msg, const char *path) +static void ly_zlog_cb(LY_LOG_LEVEL level, const char *msg, const char *data_path +#if !(LY_VERSION_MAJOR < 3) +		       , +		       const char *schema_path, uint64_t line +#endif +)  {  	int priority = LOG_ERR; @@ -729,8 +746,14 @@ static void ly_log_cb(LY_LOG_LEVEL level, const char *msg, const char *path)  		break;  	} -	if (path) -		zlog(priority, "libyang: %s (%s)", msg, path); +	if (data_path) +		zlog(priority, "libyang: %s (%s)", msg, data_path); +#if !(LY_VERSION_MAJOR < 3) +	else if (schema_path) +		zlog(priority, "libyang %s (%s)\n", msg, schema_path); +	else if (line) +		zlog(priority, "libyang %s (line %" PRIu64 ")\n", msg, line); +#endif  	else  		zlog(priority, "libyang: %s", msg);  } @@ -757,7 +780,8 @@ LY_ERR yang_parse_notification(const char *xpath, LYD_FORMAT format,  		return err;  	} -	err = lyd_find_xpath3(NULL, tree, xpath, NULL, &set); +	err = yang_lyd_find_xpath3(NULL, tree, xpath, LY_VALUE_JSON, NULL, NULL, +				   &set);  	if (err) {  		zlog_err("Failed to parse notification: %s", ly_last_errmsg());  		lyd_free_all(tree); @@ -907,23 +931,29 @@ char *yang_convert_lyd_format(const char *data, size_t data_len,  const char *yang_print_errors(struct ly_ctx *ly_ctx, char *buf, size_t buf_len)  { -	struct ly_err_item *ei; +	const struct ly_err_item *ei;  	ei = ly_err_first(ly_ctx);  	if (!ei)  		return "";  	strlcpy(buf, "YANG error(s):\n", buf_len); +#if (LY_VERSION_MAJOR < 3) +#define data_path path +#else +#define data_path data_path +#endif  	for (; ei; ei = ei->next) { -		if (ei->path) { +		if (ei->data_path) {  			strlcat(buf, " Path: ", buf_len); -			strlcat(buf, ei->path, buf_len); +			strlcat(buf, ei->data_path, buf_len);  			strlcat(buf, "\n", buf_len);  		}  		strlcat(buf, " Error: ", buf_len);  		strlcat(buf, ei->msg, buf_len);  		strlcat(buf, "\n", buf_len);  	} +#undef data_path  	ly_err_clean(ly_ctx, NULL); @@ -975,7 +1005,12 @@ struct ly_ctx *yang_ctx_new_setup(bool embedded_modules, bool explicit_compile)  void yang_init(bool embedded_modules, bool defer_compile)  {  	/* Initialize libyang global parameters that affect all containers. */ -	ly_set_log_clb(ly_log_cb, 1); +	ly_set_log_clb(ly_zlog_cb +#if (LY_VERSION_MAJOR < 3) +		       , +		       1 +#endif +	);  	ly_log_options(LY_LOLOG | LY_LOSTORE);  	/* Initialize libyang container for native models. */ @@ -1313,7 +1348,8 @@ LY_ERR yang_lyd_trim_xpath(struct lyd_node **root, const char *xpath)  	*root = lyd_first_sibling(*root); -	err = lyd_find_xpath3(NULL, *root, xpath, NULL, &set); +	err = yang_lyd_find_xpath3(NULL, *root, xpath, LY_VALUE_JSON, NULL, +				   NULL, &set);  	if (err) {  		flog_err_sys(EC_LIB_LIBYANG,  			     "cannot obtain specific result for xpath \"%s\": %s",  | 
