context FEATURE function ly_ctx_get_module_iter()
diff --git a/src/context.c b/src/context.c
index 066f662..c177faa 100644
--- a/src/context.c
+++ b/src/context.c
@@ -387,6 +387,21 @@
return result;
}
+API const struct lys_module *
+ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *idx)
+{
+ if (!ctx || !idx) {
+ ly_errno = LY_EINVAL;
+ return NULL;
+ }
+
+ if (*idx >= (unsigned)ctx->models.used) {
+ return NULL;
+ }
+
+ return ctx->models.list[(*idx)++];
+}
+
API const char **
ly_ctx_get_submodule_names(const struct ly_ctx *ctx, const char *module_name)
{
diff --git a/src/libyang.h b/src/libyang.h
index f9b570e..110398e 100644
--- a/src/libyang.h
+++ b/src/libyang.h
@@ -106,6 +106,7 @@
* Alternatively, the ly_ctx_info() function can be used to get complex information about the schemas in the context
* in the form of data tree defined by
* <a href="https://tools.ietf.org/html/draft-ietf-netconf-yang-library-04">ietf-yang-library</a> schema.
+ * Also, if all the modules need to be iterated over, it can be done effectively using ly_ctx_get_module_iter().
*
* Modules held by a context cannot be removed one after one. The only way how to \em change modules in the
* context is to create a new context and remove the old one. To remove a context, there is ly_ctx_destroy()
@@ -125,6 +126,7 @@
* - ly_ctx_load_module()
* - ly_ctx_info()
* - ly_ctx_get_module_names()
+ * - ly_ctx_get_module_iter()
* - ly_ctx_get_module()
* - ly_ctx_get_module_by_ns()
* - ly_ctx_get_submodule_names()
@@ -622,6 +624,15 @@
const char **ly_ctx_get_module_names(const struct ly_ctx *ctx);
/**
+ * @brief Iterate over all modules in a context.
+ *
+ * @param[in] ctx Context with the modules.
+ * @param[in,out] idx Index of the next module to be returned. Value of 0 starts from the beginning.
+ * @return Next context module, NULL if the last was already returned.
+ */
+const struct lys_module *ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *idx);
+
+/**
* @brief Get the names of the loaded submodules of the specified module.
*
* @param[in] ctx Context with the modules.