@@ -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 );
0 commit comments