type plugins CHANGE rename ly_get_prefix() and ly_resolve_prefix()
Since both the functions can be used publicly only in type plugins just
passing parameters provided by the callbacks, it is necessary to
simplify their description and improve namimng.
This change hides ly_get_prefix() and ly_resolve_prefix() into an
internal API for internal use in libyang2. It also introduces new
ly_type_print_get_prefix() and ly_type_store_resolve_prefix() functions
as a replacement for the hidden functions (they are simple wrappers
around the internal functions).
diff --git a/src/plugins_types.c b/src/plugins_types.c
index 4c4e814..166f736 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -87,7 +87,7 @@
return ly_ctx_get_module_implemented2(ctx, prefix, prefix_len);
}
-API const struct lys_module *
+const struct lys_module *
ly_resolve_prefix(const struct ly_ctx *ctx, const char *prefix, size_t prefix_len, LY_PREFIX_FORMAT format, void *prefix_data)
{
const struct lys_module *mod = NULL;
@@ -112,6 +112,13 @@
return mod;
}
+API const struct lys_module *
+ly_type_store_resolve_prefix(const struct ly_ctx *ctx, const char *prefix, size_t prefix_len,
+ LY_PREFIX_FORMAT format, void *prefix_data)
+{
+ return ly_resolve_prefix(ctx, prefix, prefix_len, format, prefix_data);
+}
+
/**
* @brief Find module in import prefixes.
*/
@@ -178,7 +185,7 @@
return mod->name;
}
-API const char *
+const char *
ly_get_prefix(const struct lys_module *mod, LY_PREFIX_FORMAT format, void *prefix_data)
{
const char *prefix = NULL;
@@ -201,6 +208,12 @@
return prefix;
}
+API const char *
+ly_type_print_get_prefix(const struct lys_module *mod, LY_PREFIX_FORMAT format, void *prefix_data)
+{
+ return ly_get_prefix(mod, format, prefix_data);
+}
+
/**
* @brief Generic comparison callback checking the canonical value.
*
@@ -1395,7 +1408,7 @@
}
if (prefix_len) {
- mod = ly_resolve_prefix(ctx, prefix, prefix_len, format, prefix_data);
+ mod = ly_type_store_resolve_prefix(ctx, prefix, prefix_len, format, prefix_data);
} else {
switch (format) {
case LY_PREF_SCHEMA:
@@ -1500,7 +1513,7 @@
char *result = NULL;
*dynamic = 1;
- if (asprintf(&result, "%s:%s", ly_get_prefix(value->ident->module, format, prefix_data), value->ident->name) == -1) {
+ if (asprintf(&result, "%s:%s", ly_type_print_get_prefix(value->ident->module, format, prefix_data), value->ident->name) == -1) {
return NULL;
} else {
return result;
@@ -1711,7 +1724,7 @@
if ((format == LY_PREF_XML) || (format == LY_PREF_SCHEMA)) {
/* everything is prefixed */
LY_ARRAY_FOR(value->target, u) {
- ly_strcat(&result, "/%s:%s", ly_get_prefix(value->target[u].node->module, format, prefix_data),
+ ly_strcat(&result, "/%s:%s", ly_type_print_get_prefix(value->target[u].node->module, format, prefix_data),
value->target[u].node->name);
LY_ARRAY_FOR(value->target[u].predicates, v) {
struct ly_path_predicate *pred = &value->target[u].predicates[v];
@@ -1731,7 +1744,7 @@
if (strchr(value, quot)) {
quot = '"';
}
- ly_strcat(&result, "[%s:%s=%c%s%c]", ly_get_prefix(pred->key->module, format, prefix_data),
+ ly_strcat(&result, "[%s:%s=%c%s%c]", ly_type_print_get_prefix(pred->key->module, format, prefix_data),
pred->key->name, quot, value, quot);
if (d) {
free((char *)value);
@@ -1761,7 +1774,7 @@
LY_ARRAY_FOR(value->target, u) {
if (mod != value->target[u].node->module) {
mod = value->target[u].node->module;
- ly_strcat(&result, "/%s:%s", ly_get_prefix(mod, format, prefix_data), value->target[u].node->name);
+ ly_strcat(&result, "/%s:%s", ly_type_print_get_prefix(mod, format, prefix_data), value->target[u].node->name);
} else {
ly_strcat(&result, "/%s", value->target[u].node->name);
}
@@ -2179,9 +2192,9 @@
size_t len = stop - start;
/* do we already have the prefix? */
- mod = ly_resolve_prefix(ctx, start, len, *format_p, *prefix_data_p);
+ mod = ly_type_store_resolve_prefix(ctx, start, len, *format_p, *prefix_data_p);
if (!mod) {
- mod = ly_resolve_prefix(ctx, start, len, format, prefix_data);
+ mod = ly_type_store_resolve_prefix(ctx, start, len, format, prefix_data);
if (mod) {
if (*format_p == LY_PREF_XML) {
/* store a new prefix - namespace pair */
diff --git a/src/plugins_types.h b/src/plugins_types.h
index 11e35e6..fa7d118 100644
--- a/src/plugins_types.h
+++ b/src/plugins_types.h
@@ -107,35 +107,31 @@
/**
* @brief Resolve format-specific prefixes to modules.
*
+ * Use only in implementations of ::ly_type_store_clb which provide all the necessary parameters for this function.
+ *
* @param[in] ctx libyang context.
- * @param[in] prefix Prefix to resolve.
+ * @param[in] prefix Prefix to resolve - identified beginning of a prefix in ::ly_type_store_clb's value parameter.
* @param[in] prefix_len Length of @p prefix.
- * @param[in] format Format of the prefix.
- * @param[in] prefix_data Format-specific data:
- * LY_PREF_SCHEMA - const struct lysp_module * (module used for resolving prefixes from imports)
- * LY_PREF_SCHEMA_RESOLVED - struct lyd_value_prefix * (sized array of pairs: prefix - module)
- * LY_PREF_XML - const struct ly_set * (set with defined namespaces stored as ::lyxml_ns)
- * LY_PREF_JSON - NULL
+ * @param[in] format Format of the prefix (::ly_type_store_clb's format parameter).
+ * @param[in] prefix_data Format-specific data (::ly_type_store_clb's prefix_data parameter).
* @return Resolved prefix module,
* @return NULL otherwise.
*/
-const struct lys_module *ly_resolve_prefix(const struct ly_ctx *ctx, const char *prefix, size_t prefix_len,
+const struct lys_module *ly_type_store_resolve_prefix(const struct ly_ctx *ctx, const char *prefix, size_t prefix_len,
LY_PREFIX_FORMAT format, void *prefix_data);
/**
* @brief Get format-specific prefix for a module.
*
- * @param[in] mod Module whose prefix to get.
- * @param[in] format Format of the prefix.
- * @param[in] prefix_data Format-specific data:
- * LY_PREF_SCHEMA - const struct lysp_module * (module used for resolving imports to prefixes)
- * LY_PREF_SCHEMA_RESOLVED - struct lyd_value_prefix * (sized array of pairs: prefix - module)
- * LY_PREF_XML - struct ly_set * (set of all returned modules as ::struct lys_module)
- * LY_PREF_JSON - NULL
- * @return Module prefix to print.
+ * Use only in implementations of ::ly_type_print_clb which provide all the necessary parameters for this function.
+ *
+ * @param[in] mod Module whose prefix to get - the module somehow connected with the value to print.
+ * @param[in] format Format of the prefix (::ly_type_print_clb's format parameter).
+ * @param[in] prefix_data Format-specific data (::ly_type_print_clb's prefix_data parameter).
+ * @return Module's prefix to print.
* @return NULL on error.
*/
-const char *ly_get_prefix(const struct lys_module *mod, LY_PREFIX_FORMAT format, void *prefix_data);
+const char *ly_type_print_get_prefix(const struct lys_module *mod, LY_PREFIX_FORMAT format, void *prefix_data);
/**
* @brief Collect any possible used prefixes in a string into a sized array of pairs of prefixes and modules.
diff --git a/src/tree_schema_internal.h b/src/tree_schema_internal.h
index 4bcd71a..67d9e48 100644
--- a/src/tree_schema_internal.h
+++ b/src/tree_schema_internal.h
@@ -670,4 +670,41 @@
*/
ly_bool lysc_is_output(const struct lysc_node *schema);
+/**
+ * @brief Get format-specific prefix for a module.
+ *
+ * For type plugins available as ::ly_type_print_get_prefix().
+ *
+ * @param[in] mod Module whose prefix to get.
+ * @param[in] format Format of the prefix.
+ * @param[in] prefix_data Format-specific data:
+ * LY_PREF_SCHEMA - const struct lysp_module * (module used for resolving imports to prefixes)
+ * LY_PREF_SCHEMA_RESOLVED - struct lyd_value_prefix * (sized array of pairs: prefix - module)
+ * LY_PREF_XML - struct ly_set * (set of all returned modules as ::struct lys_module)
+ * LY_PREF_JSON - NULL
+ * @return Module prefix to print.
+ * @return NULL on error.
+ */
+const char *ly_get_prefix(const struct lys_module *mod, LY_PREFIX_FORMAT format, void *prefix_data);
+
+/**
+ * @brief Resolve format-specific prefixes to modules.
+ *
+ * For type plugins available as ::ly_type_store_resolve_prefix().
+ *
+ * @param[in] ctx libyang context.
+ * @param[in] prefix Prefix to resolve.
+ * @param[in] prefix_len Length of @p prefix.
+ * @param[in] format Format of the prefix.
+ * @param[in] prefix_data Format-specific data:
+ * LY_PREF_SCHEMA - const struct lysp_module * (module used for resolving prefixes from imports)
+ * LY_PREF_SCHEMA_RESOLVED - struct lyd_value_prefix * (sized array of pairs: prefix - module)
+ * LY_PREF_XML - const struct ly_set * (set with defined namespaces stored as ::lyxml_ns)
+ * LY_PREF_JSON - NULL
+ * @return Resolved prefix module,
+ * @return NULL otherwise.
+ */
+const struct lys_module *ly_resolve_prefix(const struct ly_ctx *ctx, const char *prefix, size_t prefix_len,
+ LY_PREFIX_FORMAT format, void *prefix_data);
+
#endif /* LY_TREE_SCHEMA_INTERNAL_H_ */