luci-0.9: merge r5154-r5161
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 29 Jul 2009 03:53:16 +0000 (03:53 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 29 Jul 2009 03:53:16 +0000 (03:53 +0000)
libs/core/luasrc/store.lua [new file with mode: 0644]
libs/core/luasrc/util.lua
libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua
libs/lucid-http/luasrc/lucid/http/server.lua
libs/lucid/hostfiles/etc/config/lucid
libs/lucid/luasrc/lucid.lua
libs/lucid/root/etc/config/lucid
libs/nixio/lua/nixio/util.lua
modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua

diff --git a/libs/core/luasrc/store.lua b/libs/core/luasrc/store.lua
new file mode 100644 (file)
index 0000000..c33ef07
--- /dev/null
@@ -0,0 +1,16 @@
+--[[
+
+LuCI - Lua Development Framework
+(c) 2009 Steven Barth <steven@midlink.org>
+(c) 2009 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+]]--
+
+local util = require "luci.util"
+module("luci.store", util.threadlocal)
\ No newline at end of file
index a3ba432..9747a44 100644 (file)
@@ -114,19 +114,16 @@ end
 -- Scope manipulation routines
 --
 
---- Create a new or get an already existing thread local store associated with
--- the current active coroutine. A thread local store is private a table object
--- whose values can't be accessed from outside of the running coroutine.
--- @return     Table value representing the corresponding thread local store
-function threadlocal()
-       local tbl = {}
+local tl_meta = {
+       __mode = "k",
 
-       local function get(self, key)
-               local t = rawget(self, coxpt[coroutine.running()] or coroutine.running() or 0)
+       __index = function(self, key)
+               local t = rawget(self, coxpt[coroutine.running()]
+                or coroutine.running() or 0)
                return t and t[key]
-       end
+       end,
 
-       local function set(self, key, value)
+       __newindex = function(self, key, value)
                local c = coxpt[coroutine.running()] or coroutine.running() or 0
                if not rawget(self, c) then
                        rawset(self, c, { [key] = value })
@@ -134,10 +131,14 @@ function threadlocal()
                        rawget(self, c)[key] = value
                end
        end
+}
 
-       setmetatable(tbl, {__index = get, __newindex = set, __mode = "k"})
-
-       return tbl
+--- Create a new or get an already existing thread local store associated with
+-- the current active coroutine. A thread local store is private a table object
+-- whose values can't be accessed from outside of the running coroutine.
+-- @return     Table value representing the corresponding thread local store
+function threadlocal(tbl)
+       return setmetatable(tbl or {}, tl_meta)
 end
 
 
index 0d06489..cd33caf 100644 (file)
@@ -52,11 +52,18 @@ function factory(server, config)
                end
        end
 
+       local mypath
        if type(config.virtual) == "table" then
                for _, v in ipairs(config.virtual) do
+                       mypath = mypath or v
                        vhost:set_handler(v, handler)
                end
        else
+               mypath = config.virtual
                vhost:set_handler(config.virtual, handler)
        end
+
+       if config.home then
+               vhost.default = mypath
+       end
 end
\ No newline at end of file
index 24eb042..53531a5 100644 (file)
@@ -173,6 +173,10 @@ function VHost.process(self, request, ...)
        -- Call URI part
        request.env.PATH_INFO = uri
        
+       if self.default and uri == "/" then
+               return 302, {Location = self.default}
+       end
+
        for k, h in pairs(self.handlers) do
                if #k > hlen then
                        if uri == k or (uri:sub(1, #k) == k and uri:byte(#k+1) == sc) then
@@ -365,8 +369,8 @@ function Server.process(self, client, env)
                set_memory_limit(env.config.memlimit)
        end
 
-       client:setsockopt("socket", "rcvtimeo", 5)
-       client:setsockopt("socket", "sndtimeo", 5)
+       client:setsockopt("socket", "rcvtimeo", 60)
+       client:setsockopt("socket", "sndtimeo", 60)
        
        repeat
                -- parse headers
index 934faa1..22b7efa 100644 (file)
@@ -19,6 +19,7 @@ config LuciWebPublisher luciweb
        option physical ''
        list virtual /luci
        option domain ''
+       option home 1
        list exec ':lo'
        list exec ':br-lan'
        list exec 'root'
@@ -71,4 +72,3 @@ config 'Redirector' 'splashredir'
         option 'virtual' '/'
         option 'physical' ':80/luci/splash'
 
-       
\ No newline at end of file
index d743269..4feb159 100644 (file)
@@ -60,6 +60,12 @@ function start()
        run()
 end
 
+--- Returns the PID of the currently active LuCId process.
+function running()
+       local pid = tonumber(state:get(UCINAME, "main", "pid"))
+       return pid and nixio.kill(pid, 0) and pid
+end
+
 --- Stops any running LuCId superprocess. 
 function stop()
        local pid = tonumber(state:get(UCINAME, "main", "pid"))
index c5a3f3d..07c32c1 100644 (file)
@@ -15,6 +15,7 @@ config DirectoryPublisher webroot
 config LuciWebPublisher luciweb
        option name 'LuCI Webapplication'
        option physical ''
+       option home 1
        list virtual /luci
        list virtual /cgi-bin/luci
        option domain ''
index 401ec61..4090048 100644 (file)
@@ -14,8 +14,8 @@ $Id$
 
 local table = require "table"
 local nixio = require "nixio"
-local getmetatable, assert, pairs, type, tostring =
-       getmetatable, assert, pairs, type, tostring
+local getmetatable, assert, pairs, type = getmetatable, assert, pairs, type
+local tostring = tostring
 
 module "nixio.util"
 
index 2192697..2363c8c 100644 (file)
@@ -27,11 +27,12 @@ f:field(DummyValue, "_memtotal", translate("m_i_memory")).value =
 string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
        tonumber(memtotal) / 1024,
        100 * memcached / memtotal,
-       tostring(translate("mem_cached"), "")),
+       tostring(translate("mem_cached", "")),
        100 * membuffers / memtotal,
        tostring(translate("mem_buffered", "")),
        100 * memfree / memtotal,
        tostring(translate("mem_free", ""))
+)
 
 f:field(DummyValue, "_systime", translate("m_i_systemtime")).value =
 os.date("%c")