# include "config.h"
#endif
-#include <vlc_common.h>
-#include <vlc_input.h>
-#include <vlc_meta.h>
-#include <vlc_demux.h>
-#include <vlc_art_finder.h>
-#include <vlc_url.h>
-#include <vlc_strings.h>
-#include <vlc_stream.h>
-
#include "vlc.h"
#include "libs.h"
luaopen_variables( L );
luaopen_object( L );
luaopen_xml( L );
- luaopen_md5( L );
luaopen_input_item( L, p_item );
- if( vlclua_add_modules_path( p_this, L, psz_filename ) )
+ if( vlclua_add_modules_path( L, psz_filename ) )
{
msg_Warn( p_this, "Error while setting the module search path for %s",
psz_filename );
* Run a lua entry point function
*****************************************************************************/
static int run( vlc_object_t *p_this, const char * psz_filename,
- lua_State * L, const char *luafunction )
+ lua_State * L, const char *luafunction,
+ const luabatch_context_t *p_context )
{
/* Ugly hack to delete previous versions of the fetchart()
* functions. */
lua_setglobal( L, luafunction );
/* Load and run the script(s) */
- if( luaL_dofile( L, psz_filename ) )
+ if( vlclua_dofile( p_this, L, psz_filename ) )
{
msg_Warn( p_this, "Error loading script %s: %s", psz_filename,
lua_tostring( L, lua_gettop( L ) ) );
goto error;
}
+
+ meta_fetcher_scope_t e_scope = FETCHER_SCOPE_NETWORK; /* default to restricted one */
+ lua_getglobal( L, "descriptor" );
+ if( lua_isfunction( L, lua_gettop( L ) ) && !lua_pcall( L, 0, 1, 0 ) )
+ {
+ lua_getfield( L, -1, "scope" );
+ char *psz_scope = luaL_strdupornull( L, -1 );
+ if ( psz_scope && !strcmp( psz_scope, "local" ) )
+ e_scope = FETCHER_SCOPE_LOCAL;
+ free( psz_scope );
+ lua_pop( L, 1 );
+ }
+ lua_pop( L, 1 );
+
+ if ( p_context && p_context->pf_validator && !p_context->pf_validator( p_context, e_scope ) )
+ {
+ msg_Dbg( p_this, "skipping script (unmatched scope) %s", psz_filename );
+ goto error;
+ }
+
lua_getglobal( L, luafunction );
if( !lua_isfunction( L, lua_gettop( L ) ) )
* Called through lua_scripts_batch_execute to call 'fetch_art' on the script
* pointed by psz_filename.
*****************************************************************************/
-static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
- void * user_data )
+static bool validate_scope( const luabatch_context_t *p_context, meta_fetcher_scope_t e_scope )
{
- input_item_t * p_item = user_data;
+ if ( p_context->e_scope == FETCHER_SCOPE_ANY )
+ return true;
+ else
+ return ( p_context->e_scope == e_scope );
+}
- lua_State *L = init( p_this, p_item, psz_filename );
+static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
+ const luabatch_context_t *p_context )
+{
+ lua_State *L = init( p_this, p_context->p_item, psz_filename );
if( !L )
return VLC_EGENERIC;
- int i_ret = run(p_this, psz_filename, L, "fetch_art");
+ int i_ret = run(p_this, psz_filename, L, "fetch_art", p_context);
if(i_ret != VLC_SUCCESS)
{
lua_close( L );
if( psz_value && *psz_value != 0 )
{
lua_Dbg( p_this, "setting arturl: %s", psz_value );
- input_item_SetArtURL ( p_item, psz_value );
+ input_item_SetArtURL ( p_context->p_item, psz_value );
lua_close( L );
return VLC_SUCCESS;
}
* pointed by psz_filename.
*****************************************************************************/
static int read_meta( vlc_object_t *p_this, const char * psz_filename,
- void * user_data )
+ const luabatch_context_t *p_context )
{
- input_item_t * p_item = user_data;
- lua_State *L = init( p_this, p_item, psz_filename );
+ /* FIXME: merge with finder */
+ demux_meta_t *p_demux_meta = (demux_meta_t *)p_this;
+ VLC_UNUSED( p_context );
+
+ lua_State *L = init( p_this, p_demux_meta->p_item, psz_filename );
if( !L )
return VLC_EGENERIC;
- int i_ret = run(p_this, psz_filename, L, "read_meta");
+ int i_ret = run(p_this, psz_filename, L, "read_meta", NULL);
lua_close( L );
- // Continue even if an error occured: all "meta reader" are always run.
+ // Continue even if an error occurred: all "meta reader" are always run.
return i_ret == VLC_SUCCESS ? VLC_EGENERIC : i_ret;
}
* pointed by psz_filename.
*****************************************************************************/
static int fetch_meta( vlc_object_t *p_this, const char * psz_filename,
- void * user_data )
+ const luabatch_context_t *p_context )
{
- input_item_t * p_item = user_data;
- lua_State *L = init( p_this, p_item, psz_filename );
+ lua_State *L = init( p_this, p_context->p_item, psz_filename );
if( !L )
return VLC_EGENERIC;
- int ret = run(p_this, psz_filename, L, "fetch_meta");
+ int ret = run(p_this, psz_filename, L, "fetch_meta", p_context);
lua_close( L );
return ret;
* Read meta.
*****************************************************************************/
-int ReadMeta( vlc_object_t *p_this )
+int ReadMeta( demux_meta_t *p_this )
{
- demux_meta_t *p_demux_meta = (demux_meta_t *)p_this;
- input_item_t *p_item = p_demux_meta->p_item;
-
- return vlclua_scripts_batch_execute( p_this, "meta"DIR_SEP"reader",
- &read_meta, p_item );
+ return vlclua_scripts_batch_execute( VLC_OBJECT(p_this), "meta"DIR_SEP"reader",
+ (void*) &read_meta, NULL );
}
* Read meta.
*****************************************************************************/
-int FetchMeta( vlc_object_t *p_this )
+int FetchMeta( meta_fetcher_t *p_finder )
{
- demux_meta_t *p_demux_meta = (demux_meta_t *)p_this;
- input_item_t *p_item = p_demux_meta->p_item;
+ luabatch_context_t context = { p_finder->p_item, p_finder->e_scope, validate_scope };
- return vlclua_scripts_batch_execute( p_this, "meta"DIR_SEP"fetcher",
- &fetch_meta, p_item );
+ return vlclua_scripts_batch_execute( VLC_OBJECT(p_finder), "meta"DIR_SEP"fetcher",
+ &fetch_meta, (void*)&context );
}
/*****************************************************************************
* Module entry point for art.
*****************************************************************************/
-int FindArt( vlc_object_t *p_this )
+int FindArt( meta_fetcher_t *p_finder )
{
- art_finder_t *p_finder = (art_finder_t *)p_this;
- input_item_t *p_item = p_finder->p_item;
+ luabatch_context_t context = { p_finder->p_item, p_finder->e_scope, validate_scope };
- return vlclua_scripts_batch_execute( p_this, "meta"DIR_SEP"art",
- &fetch_art, p_item );
+ return vlclua_scripts_batch_execute( VLC_OBJECT(p_finder), "meta"DIR_SEP"art",
+ &fetch_art, (void*)&context );
}