--[==========================================================================[
Configuration options:
* host: A host to listen on.
- * dir: Directory to use a the http interface's root.
+ * dir: Directory to use as the http interface's root.
* no_error_detail: If set, do not print the Lua error message when generating
a page fails.
* no_index: If set, don't build directory indexes
--]==========================================================================]
-require "httpd"
-require "acl"
require "common"
-vlc.msg.err("Lua HTTP interface")
+vlc.msg.info("Lua HTTP interface")
open_tag = "<?vlc"
close_tag = "?>"
return assert(loadstring(code,filename))
end
function process(filename)
- vlc.msg.dbg("Loading `"..filename.."'")
- local mtime = 0 -- vlc.fd.stat(filename).modification_time
+ local mtime = 0 -- vlc.net.stat(filename).modification_time
local func = false -- process_raw(filename)
return function(...)
- local new_mtime = vlc.fd.stat(filename).modification_time
+ local new_mtime = vlc.net.stat(filename).modification_time
if new_mtime ~= mtime then
-- Re-read the file if it changed
- vlc.msg.dbg("Reloading `"..filename.."'")
+ if mtime == 0 then
+ vlc.msg.dbg("Loading `"..filename.."'")
+ else
+ vlc.msg.dbg("Reloading `"..filename.."'")
+ end
func = process_raw(filename)
mtime = new_mtime
end
</html>]]
end
-function dirlisting(url,listing)
+function dirlisting(url,listing,acl_)
local list = {}
for _,f in ipairs(listing) do
if not string.match(f,"^%.") then
</body>
</html>]]
end
- return h:file_new(url,"text/html",nil,nil,nil,callback,nil)
+ return h:file(url,"text/html",nil,nil,acl_,callback,nil)
end
function file(h,path,url,acl_,mime)
end
return table.concat(page)
end
- return h:file_new(url or path,mime,nil,nil,acl_,callback,nil)
+ return h:file(url or path,mime,nil,nil,acl_,callback,nil)
end
function rawfile(h,path,url,acl_)
local filename = path
- vlc.msg.dbg("Loading `"..filename.."'")
- local mtime = 0 -- vlc.fd.stat(filename).modification_time
+ local mtime = 0 -- vlc.net.stat(filename).modification_time
local page = false -- io.open(filename):read("*a")
local callback = function(data,request)
- local new_mtime = vlc.fd.stat(filename).modification_time
+ local new_mtime = vlc.net.stat(filename).modification_time
if mtime ~= new_mtime then
-- Re-read the file if it changed
- vlc.msg.dbg("Reloading `"..filename.."'")
+ if mtime == 0 then
+ vlc.msg.dbg("Loading `"..filename.."'")
+ else
+ vlc.msg.dbg("Reloading `"..filename.."'")
+ end
page = io.open(filename):read("*a")
mtime = new_mtime
end
return page
end
- return h:file_new(url or path,nil,nil,nil,acl_,callback,nil)
+ return h:file(url or path,nil,nil,nil,acl_,callback,nil)
end
function parse_url_request(request)
if not request then return {} end
t = {}
for k,v in string.gmatch(request,"([^=&]+)=?([^=&]*)") do
- local k_ = vlc.decode_uri(k)
- local v_ = vlc.decode_uri(v)
- t[k_]=v_
+ local k_ = vlc.strings.decode_uri(k)
+ local v_ = vlc.strings.decode_uri(v)
+ if t[k_] ~= nil then
+ local t2
+ if type(t[k_]) ~= "table" then
+ t2 = {}
+ table.insert(t2,t[k_])
+ t[k_] = t2
+ else
+ t2 = t[k_]
+ end
+ table.insert(t2,v_)
+ else
+ t[k_] = v_
+ end
end
return t
end
local function find_datadir(name)
- local list = vlc.datadir_list(name)
+ local list = vlc.misc.datadir_list(name)
for _, l in ipairs(list) do
- local s = vlc.fd.stat(l)
+ local s = vlc.net.stat(l)
if s then
return l
end
html = "text/html",
xml = "text/xml",
js = "text/javascript",
+ css = "text/css",
png = "image/png",
ico = "image/x-icon",
}
local function load_dir(dir,root,parent_acl)
local root = root or "/"
local has_index = false
- if string.match(dir,"/old") then
- return
- end
local my_acl = parent_acl
do
local af = dir.."/.hosts"
- local s = vlc.fd.stat(af)
+ local s = vlc.net.stat(af)
if s and s.type == "file" then
-- We found an acl
- my_acl = acl.new(false)
+ my_acl = vlc.acl(false)
my_acl:load_file(af)
end
end
- local d = vlc.fd.opendir(dir)
+ local d = vlc.net.opendir(dir)
for _,f in ipairs(d) do
if not string.match(f,"^%.") then
- local s = vlc.fd.stat(dir.."/"..f)
+ local s = vlc.net.stat(dir.."/"..f)
if s.type == "file" then
local url
if f == "index.html" then
table.insert(files,rawfile(h,dir.."/"..f,url,my_acl and my_acl.private))
end
elseif s.type == "dir" then
- if f == "dialogs" then -- FIXME
- else
- load_dir(dir.."/"..f,root..f.."/",my_acl)
- end
+ load_dir(dir.."/"..f,root..f.."/",my_acl)
end
end
end
end
local u = vlc.net.url_parse( config.host or "localhost:8080" )
-h = httpd.new(u.host,u.port)
+h = vlc.httpd(u.host,u.port)
load_dir( http_dir )
-while not die do die = vlc.lock_and_wait() end -- everything happens in callbacks
+while not die do die = vlc.misc.lock_and_wait() end -- everything happens in callbacks
-- FIXME: We shouldn't need to do this ourselves.
for i=1,#files do