Skip to content

Commit 1f6ac6d

Browse files
author
roman
committed
context UPDATE add static plugins only flag
1 parent 6a54fb7 commit 1f6ac6d

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

src/context.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ ly_ctx_new(const char *search_dir, uint32_t options, struct ly_ctx **new_ctx)
279279
struct ly_in *in = NULL;
280280
LY_ERR rc = LY_SUCCESS;
281281
struct lys_glob_unres unres = {0};
282-
ly_bool builtin_plugins_only;
282+
ly_bool builtin_plugins_only, static_plugins_only;
283283

284284
LY_CHECK_ARG_RET(NULL, new_ctx, LY_EINVAL);
285285

@@ -291,7 +291,8 @@ ly_ctx_new(const char *search_dir, uint32_t options, struct ly_ctx **new_ctx)
291291

292292
/* plugins */
293293
builtin_plugins_only = (options & LY_CTX_BUILTIN_PLUGINS_ONLY) ? 1 : 0;
294-
LY_CHECK_ERR_GOTO(lyplg_init(builtin_plugins_only), LOGINT(NULL); rc = LY_EINT, cleanup);
294+
static_plugins_only = (options & LY_CTX_STATIC_PLUGINS_ONLY) ? 1 : 0;
295+
LY_CHECK_ERR_GOTO(lyplg_init(builtin_plugins_only, static_plugins_only), LOGINT(NULL); rc = LY_EINT, cleanup);
295296

296297
/* ctx data */
297298
ctx_data = ly_ctx_data_add(ctx);
@@ -628,6 +629,13 @@ ly_ctx_set_options(struct ly_ctx *ctx, uint32_t option)
628629
return LY_EINVAL;
629630
}
630631

632+
if (!(ctx->opts & LY_CTX_STATIC_PLUGINS_ONLY) && (option & LY_CTX_STATIC_PLUGINS_ONLY)) {
633+
LOGERR(ctx, LY_EINVAL,
634+
"Invalid argument %s (LY_CTX_STATIC_PLUGINS_ONLY can be set only when creating a new context) (%s()).",
635+
"option", __func__);
636+
return LY_EINVAL;
637+
}
638+
631639
if (!(ctx->opts & LY_CTX_LEAFREF_LINKING) && (option & LY_CTX_LEAFREF_LINKING)) {
632640
ctx_data = ly_ctx_data_get(ctx);
633641
ctx_data->leafref_links_ht = lyht_new(1, sizeof(struct lyd_leafref_links_rec), ly_ctx_ht_leafref_links_equal_cb, NULL, 1);
@@ -1392,7 +1400,7 @@ ly_ctx_compiled_print(const struct ly_ctx *ctx, void *mem, void **mem_end)
13921400

13931401
LY_CHECK_ARG_RET(ctx, ctx, mem, LY_EINVAL);
13941402

1395-
if (ctx->plugins_types.count || ctx->plugins_extensions.count) {
1403+
if (ctx->plugins_types.count || ctx->plugins_extensions.count || !(ctx->opts & LY_CTX_STATIC_PLUGINS_ONLY)) {
13961404
LOGERR(ctx, LY_EINVAL, "Printing context with dynamic type or extension plugins is not supported.");
13971405
return LY_EINVAL;
13981406
}
@@ -1430,6 +1438,7 @@ ly_ctx_new_printed(const void *mem, struct ly_ctx **ctx)
14301438
{
14311439
LY_ERR rc = LY_SUCCESS;
14321440
struct ly_ctx_data *ctx_data = NULL;
1441+
ly_bool builtin_plugins_only, static_plugins_only;
14331442

14341443
LY_CHECK_ARG_RET(NULL, mem, ctx, LY_EINVAL);
14351444

@@ -1438,6 +1447,11 @@ ly_ctx_new_printed(const void *mem, struct ly_ctx **ctx)
14381447
/* ctx data */
14391448
ctx_data = ly_ctx_data_add(*ctx);
14401449

1450+
/* plugins */
1451+
builtin_plugins_only = ((*ctx)->opts & LY_CTX_BUILTIN_PLUGINS_ONLY) ? 1 : 0;
1452+
static_plugins_only = 1;
1453+
LY_CHECK_ERR_GOTO(lyplg_init(builtin_plugins_only, static_plugins_only), LOGINT(NULL); rc = LY_EINT, cleanup);
1454+
14411455
/* data dictionary */
14421456
ctx_data->data_dict = malloc(sizeof *ctx_data->data_dict);
14431457
LY_CHECK_ERR_GOTO(!ctx_data->data_dict, rc = LY_EMEM, cleanup);

src/context.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ struct ly_ctx;
209209
invalid data needs to be stored in YANG node values. */
210210
#define LY_CTX_LYB_HASHES 0x1000 /**< Generate hashes for all the schema nodes. Required when using LYB data parse
211211
or print. */
212+
#define LY_CTX_STATIC_PLUGINS_ONLY 0x2000 /**< By default, external plugins from directories the path to which is obtained
213+
from the `LIBYANG_TYPES_PLUGINS_DIR` and `LIBYANG_EXTENSIONS_PLUGINS_DIR` environmental variables
214+
are loaded. This option prevents loading of all external plugins and only
215+
the static (built-in) plugins are loaded.
212216
213217
/* 0x80000000 reserved for internal use */
214218

src/plugins.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ plugins_insert_dir(enum LYPLG type)
526526
#endif
527527

528528
LY_ERR
529-
lyplg_init(ly_bool builtin_type_plugins_only)
529+
lyplg_init(ly_bool builtin_type_plugins_only, ly_bool static_plugins_only)
530530
{
531531
LY_ERR ret;
532532

@@ -587,11 +587,13 @@ lyplg_init(ly_bool builtin_type_plugins_only)
587587
}
588588

589589
#ifndef STATIC
590-
/* external types */
591-
LY_CHECK_GOTO(ret = plugins_insert_dir(LYPLG_TYPE), error);
590+
if (!static_plugins_only) {
591+
/* external types */
592+
LY_CHECK_GOTO(ret = plugins_insert_dir(LYPLG_TYPE), error);
592593

593-
/* external extensions */
594-
LY_CHECK_GOTO(ret = plugins_insert_dir(LYPLG_EXTENSION), error);
594+
/* external extensions */
595+
LY_CHECK_GOTO(ret = plugins_insert_dir(LYPLG_EXTENSION), error);
596+
}
595597
#endif
596598

597599
/* initiation done, wake-up possibly waiting threads creating another contexts */

src/plugins_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@
4949
* Covers both the types and extensions plugins.
5050
*
5151
* @param[in] builtin_type_plugins_only Whether to load only built-in YANG type plugins and no included extension plugins.
52+
* @param[in] static_plugins_only Whether to load only static plugins, meaning no external directories with plugins.
5253
* @return LY_SUCCESS in case of success
5354
* @return LY_EINT in case of internal error
5455
* @return LY_EMEM in case of memory allocation failure.
5556
*/
56-
LY_ERR lyplg_init(ly_bool builtin_type_plugins_only);
57+
LY_ERR lyplg_init(ly_bool builtin_type_plugins_only, ly_bool static_plugins_only);
5758

5859
/**
5960
* @brief Remove (unload) all the plugins currently available.

0 commit comments

Comments
 (0)