X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=share%2Flua%2Fintf%2Fhttp.lua;h=1ff7fe7a31d532a7518c395eeded3b59cc9c6e94;hb=deb69f94c57f7124522d8c47b1b5ed77cb1f967e;hp=2c2cd1bbe037da4b248d311765147f086da91a8b;hpb=d8b6a43aa36771282a71a5983f813cd5f2c48471;p=vlc diff --git a/share/lua/intf/http.lua b/share/lua/intf/http.lua index 2c2cd1bbe0..1ff7fe7a31 100644 --- a/share/lua/intf/http.lua +++ b/share/lua/intf/http.lua @@ -24,18 +24,16 @@ --[==========================================================================[ 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 = "" @@ -69,14 +67,17 @@ function process_raw(filename) 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 @@ -101,7 +102,7 @@ function callback_error(path,url,msg) ]] end -function dirlisting(url,listing) +function dirlisting(url,listing,acl_) local list = {} for _,f in ipairs(listing) do if not string.match(f,"^%.") then @@ -119,7 +120,7 @@ function dirlisting(url,listing) ]] 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) @@ -148,42 +149,57 @@ 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 @@ -209,29 +225,27 @@ local mimes = { 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 @@ -249,10 +263,7 @@ local function load_dir(dir,root,parent_acl) 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 @@ -263,10 +274,10 @@ local function load_dir(dir,root,parent_acl) 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