[vlc-devel] [PATCH] lua HTTPd: inform user that password has not been set
Rafaël Carré
funman at videolan.org
Tue May 14 09:50:02 CEST 2013
---
Suggestion for HTML message welcome.
TODO: allocate the answer once and cache it for further requests?
modules/lua/libs/httpd.c | 29 +++++++++++++++++++++++++++++
share/lua/intf/http.lua | 1 -
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/modules/lua/libs/httpd.c b/modules/lua/libs/httpd.c
index 28f3abd..ff6ffb8 100644
--- a/modules/lua/libs/httpd.c
+++ b/modules/lua/libs/httpd.c
@@ -61,6 +61,14 @@ static const luaL_Reg vlclua_httpd_reg[] = {
{ NULL, NULL }
};
+static const char no_password[] = N_("<?xml version=\"1.0\" encoding=\"ascii\" ?>\n"
+"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
+"<html><title>VLC media player</title>\n"
+"<head>Password for Web interface has not been set.<br>\n"
+"Please use --http-password, or set a password in <br>\n"
+"Preferences > All > Main interfaces > Lua > Lua HTTP > Password.\n"
+"<!-- VLC_PASSWORD_NOT_SET ></html>\n");
+
static int vlclua_httpd_tls_host_new( lua_State *L )
{
vlc_object_t *p_this = vlclua_get_this( L );
@@ -97,6 +105,7 @@ static int vlclua_httpd_host_delete( lua_State *L )
struct httpd_handler_sys_t
{
lua_State *L;
+ bool password;
int ref;
};
@@ -138,6 +147,17 @@ static int vlclua_httpd_handler_callback(
}
/* function data outdata */
*pp_data = vlclua_todata( L, -1, pi_data );
+ if (!p_sys->password)
+ {
+ free(*pp_data);
+ size_t s = strlen(_(no_password));
+ if (asprintf((char**)pp_data, "Status: 403\n"
+ "Content-Length: %zu\n"
+ "Content-Type: text/html\n\n%s", s, _(no_password)) < 0)
+ *pi_data = 0;
+ else
+ *pi_data = strlen((char*)*pp_data);
+ }
lua_pop( L, 1 );
/* function data */
return VLC_SUCCESS;
@@ -159,6 +179,7 @@ static int vlclua_httpd_handler_new( lua_State * L )
return luaL_error( L, "Failed to allocate private buffer." );
p_sys->L = lua_newthread( L );
p_sys->ref = luaL_ref( L, LUA_REGISTRYINDEX ); /* pops the object too */
+ p_sys->password = psz_password && *psz_password;
/* use lua_xmove to move the lua callback function and data to
* the callback's stack. */
lua_xmove( L, p_sys->L, 2 );
@@ -200,6 +221,7 @@ struct httpd_file_sys_t
{
lua_State *L;
int ref;
+ bool password;
};
static int vlclua_httpd_file_callback(
@@ -228,6 +250,12 @@ static int vlclua_httpd_file_callback(
}
/* function data outdata */
*pp_data = vlclua_todata( L, -1, pi_data );
+ if (!p_sys->password)
+ {
+ free(*pp_data);
+ *pp_data = (uint8_t*)strdup(_(no_password));
+ *pi_data = strlen((char*)*pp_data);
+ }
lua_pop( L, 1 );
/* function data */
return VLC_SUCCESS;
@@ -248,6 +276,7 @@ static int vlclua_httpd_file_new( lua_State *L )
if( !p_sys )
return luaL_error( L, "Failed to allocate private buffer." );
p_sys->L = lua_newthread( L );
+ p_sys->password = psz_password && *psz_password;
p_sys->ref = luaL_ref( L, LUA_REGISTRYINDEX ); /* pops the object too */
lua_xmove( L, p_sys->L, 2 );
httpd_file_t *p_file = httpd_FileNew( *pp_host, psz_url, psz_mime,
diff --git a/share/lua/intf/http.lua b/share/lua/intf/http.lua
index f428a7f..9a7926c 100644
--- a/share/lua/intf/http.lua
+++ b/share/lua/intf/http.lua
@@ -320,7 +320,6 @@ if config.host then
end
password = vlc.var.inherit(nil,"http-password")
-assert(password ~= "", "password not defined")
h = vlc.httpd()
load_dir( http_dir )
--
1.8.1.2
More information about the vlc-devel
mailing list