@@ -167,6 +167,12 @@ lysc_get_type_plugin(uintptr_t plugin_id)
167167 return lysc_get_plugin (plugin_id , LYPLG_TYPE , & plugins_types );
168168}
169169
170+ LIBYANG_API_DEF struct lyplg_ext *
171+ lysc_get_ext_plugin (uintptr_t plugin_id )
172+ {
173+ return lysc_get_plugin (plugin_id , LYPLG_EXTENSION , & plugins_extensions );
174+ }
175+
170176/**
171177 * @brief Iterate over list of loaded plugins of the given @p type.
172178 *
@@ -255,40 +261,34 @@ lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char
255261 }
256262}
257263
258- struct lyplg_type *
259- lyplg_type_plugin_find (const struct ly_ctx * ctx , const char * module , const char * revision , const char * name )
264+ uintptr_t
265+ lyplg_ext_plugin_find (const struct ly_ctx * ctx , const char * module , const char * revision , const char * name )
260266{
261- struct lyplg_type_record * record = NULL ;
267+ struct lyplg_ext_record * record = NULL ;
268+ uint32_t record_idx = 0 ;
262269
263270 if (ctx ) {
264271 /* try to find context specific plugin */
265- record = lyplg_record_find (ctx , LYPLG_TYPE , module , revision , name , NULL );
272+ record = lyplg_record_find (ctx , LYPLG_EXTENSION , module , revision , name , & record_idx );
266273 }
267274
268275 if (!record ) {
269276 /* try to find shared plugin */
270- record = lyplg_record_find (NULL , LYPLG_TYPE , module , revision , name , NULL );
271- }
272-
273- return record ? & record -> plugin : NULL ;
274- }
275-
276- struct lyplg_ext *
277- lyplg_ext_plugin_find (const struct ly_ctx * ctx , const char * module , const char * revision , const char * name )
278- {
279- struct lyplg_ext_record * record = NULL ;
280-
281- if (ctx ) {
282- /* try to find context specific plugin */
283- record = lyplg_record_find (ctx , LYPLG_EXTENSION , module , revision , name , NULL );
277+ record = lyplg_record_find (NULL , LYPLG_EXTENSION , module , revision , name , & record_idx );
284278 }
285279
286280 if (!record ) {
287- /* try to find shared plugin */
288- record = lyplg_record_find ( NULL , LYPLG_EXTENSION , module , revision , name , NULL ) ;
281+ /* not found */
282+ return 0 ;
289283 }
290284
291- return record ? & record -> plugin : NULL ;
285+ if (!strncmp (record -> plugin .id , "ly2 - " , 6 )) {
286+ /* internal plugin, return an index with an offset of +1 in order to keep 0 as an invalid index (a NULL ptr) */
287+ return record_idx + 1 ;
288+ } else {
289+ /* external plugin, return the pointer */
290+ return (uintptr_t )& record -> plugin ;
291+ }
292292}
293293
294294/**
0 commit comments