1 --[==========================================================================[
2 httpd.lua: VLC Lua interface HTTPd module
3 --[==========================================================================[
4 Copyright (C) 2007 the VideoLAN team
7 Authors: Antoine Cellerier <dionoea at videolan dot org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 --]==========================================================================]
24 --[==========================================================================[
25 --]==========================================================================]
27 module("httpd",package.seeall)
29 local function generic_metatable(methods,destructor)
31 __index = function(this,key)
32 if methods and methods[key] then
34 elseif key == "private" then
37 return rawget(this,key)
40 __newindex = function(this,key,value)
41 if key == "private" or (methods and methods[key]) then
44 rawset(this,key,value)
49 destructor(rawget(this,"private"))
52 --__metatable = "None of your business.",
56 local handler_metatable = generic_metatable({},vlc.httpd.handler_delete)
57 local file_metatable = generic_metatable({},vlc.httpd.file_delete)
58 local redirect_metatable = generic_metatable({},vlc.httpd.redirect_delete)
60 local host_methods = {
61 handler_new = function(this,...)
62 return setmetatable({private=vlc.httpd.handler_new(rawget(this,"private"),...),parent=this},handler_metatable)
64 file_new = function(this,...)
65 return setmetatable({private=vlc.httpd.file_new(rawget(this,"private"),...),parent=this},file_metatable)
67 redirect_new = function(this,...)
68 return setmetatable({private=vlc.httpd.redirect_new(rawget(this,"private"),...),parent=this},redirect_metatable)
71 local host_metatable = generic_metatable(host_methods,vlc.httpd.host_delete)
74 return setmetatable({private=vlc.httpd.host_new(...)},host_metatable)