context UPDATE context module hashing function
diff --git a/src/context.c b/src/context.c
index 47e63d4..54c2fc5 100644
--- a/src/context.c
+++ b/src/context.c
@@ -657,6 +657,25 @@
return ctx->change_count;
}
+LIBYANG_API_DEF uint32_t
+ly_ctx_get_modules_hash(const struct ly_ctx *ctx)
+{
+ const struct lys_module *mod;
+ uint32_t i = ly_ctx_internal_modules_count(ctx), hash = 0;
+
+ LY_CHECK_ARG_RET(ctx, ctx, 0);
+
+ while ((mod = ly_ctx_get_module_iter(ctx, &i))) {
+ hash = dict_hash_multi(hash, mod->name, strlen(mod->name));
+ if (mod->revision) {
+ hash = dict_hash_multi(hash, mod->revision, strlen(mod->revision));
+ }
+ }
+
+ hash = dict_hash_multi(hash, NULL, 0);
+ return hash;
+}
+
LIBYANG_API_DEF ly_module_imp_clb
ly_ctx_get_module_imp_clb(const struct ly_ctx *ctx, void **user_data)
{
diff --git a/src/context.h b/src/context.h
index 331a89f..ec5ac3b 100644
--- a/src/context.h
+++ b/src/context.h
@@ -370,6 +370,15 @@
LIBYANG_API_DECL uint16_t ly_ctx_get_change_count(const struct ly_ctx *ctx);
/**
+ * @brief Get the hash of all the modules in the context with their revision. Since order of the modules is significant,
+ * even when 2 contexts have the same modules but loaded in a different order, the hash will differ.
+ *
+ * @param[in] ctx Context to be examined.
+ * @return Context modules hash.
+ */
+LIBYANG_API_DECL uint32_t ly_ctx_get_modules_hash(const struct ly_ctx *ctx);
+
+/**
* @brief Callback for freeing returned module data in #ly_module_imp_clb.
*
* @param[in] module_data Data to free.
@@ -630,7 +639,8 @@
* If the data identifier can be limited to the existence and changes of this context, the following
* last 2 parameters can be used:
*
- * "%u" as @p content_id_format and ::ly_ctx_get_change_count() as its parameter.
+ * "%u" as @p content_id_format and ::ly_ctx_get_change_count() as its parameter;
+ * "%u" as @p content_id_format and ::ly_ctx_get_modules_hash() as its parameter.
*
* @param[in] ctx Context with the modules.
* @param[out] root Generated yang-library data.