]> git.sesse.net Git - vlc/blob - share/luaintf/modules/httpd.lua
Revert 4ce6c3f34b0807c7ee8db8739bdbdb9773d42f56. Fixes drag and drop on my system...
[vlc] / share / luaintf / modules / httpd.lua
1 --[==========================================================================[
2  httpd.lua: VLC Lua interface HTTPd module
3 --[==========================================================================[
4  Copyright (C) 2007 the VideoLAN team
5  $Id$
6
7  Authors: Antoine Cellerier <dionoea at videolan dot org>
8
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.
13
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.
18
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 --]==========================================================================]
23
24 --[==========================================================================[
25 --]==========================================================================]
26
27 module("httpd",package.seeall)
28
29 local function generic_metatable(methods,destructor)
30     return {
31         __index = function(this,key)
32             if methods and methods[key] then
33                 return methods[key]
34             elseif key == "private" then
35                 error("Forbidden")
36             else
37                 return rawget(this,key)
38             end
39         end,
40         __newindex = function(this,key,value)
41             if key == "private" or (methods and methods[key]) then
42                 error("Forbidden")
43             else
44                 rawset(this,key,value)
45             end
46         end,
47         __gc = function(this)
48             if destructor then
49                 destructor(rawget(this,"private"))
50             end
51         end,
52         --__metatable = "None of your business.",
53     }
54 end
55
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)
59
60 local host_methods = {
61     handler_new = function(this,...)
62         return setmetatable({private=vlc.httpd.handler_new(rawget(this,"private"),...),parent=this},handler_metatable)
63     end,
64     file_new = function(this,...)
65         return setmetatable({private=vlc.httpd.file_new(rawget(this,"private"),...),parent=this},file_metatable)
66     end,
67     redirect_new = function(this,...)
68         return setmetatable({private=vlc.httpd.redirect_new(rawget(this,"private"),...),parent=this},redirect_metatable)
69     end,
70 }
71 local host_metatable = generic_metatable(host_methods,vlc.httpd.host_delete)
72
73 function new( ... )
74     return setmetatable({private=vlc.httpd.host_new(...)},host_metatable)
75 end