* Rewrote Luci to be coroutine-safe allowing the use of non-forking webservers
[project/luci.git] / libs / sgi-webuci / luasrc / sgi / webuci.lua
1 --[[
2 LuCI - SGI-Module for Webuci
3
4 Description:
5 Server Gateway Interface for Webuci
6
7 FileId:
8 $Id: webuci.lua 2027 2008-05-07 21:16:35Z Cyrus $
9
10 License:
11 Copyright 2008 Steven Barth <steven@midlink.org>
12
13 Licensed under the Apache License, Version 2.0 (the "License");
14 you may not use this file except in compliance with the License.
15 You may obtain a copy of the License at 
16
17         http://www.apache.org/licenses/LICENSE-2.0 
18
19 Unless required by applicable law or agreed to in writing, software
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
24
25 ]]--
26 module("luci.sgi.webuci", package.seeall)
27 require("luci.http")
28 require("luci.util")
29 require("luci.dispatcher")
30
31 function run(env, vars)
32         local r = luci.http.Request()
33         r.env = env
34         r.request = vars
35         
36         local x = coroutine.create(luci.dispatcher.httpdispatch)
37         
38         while coroutine.status(x) ~= "dead" do
39                 local res, id, data1, data2 = coroutine.resume(x, r)
40
41                 if not res then
42                         print(env.SERVER_PROTOCOL .. " 500 Internal Server Error")
43                         print("Content-Type: text/plain\n")
44                         print(id)
45                         break;
46                 end
47                 
48                 if id == 1 then
49                         io.write(env.SERVER_PROTOCOL .. " " .. tostring(data1) .. " " .. data2 .. "\n")
50                 elseif id == 2 then
51                         io.write(data1 .. ": " .. data2 .. "\n")
52                 elseif id == 3 then
53                         io.write("\n")
54                 elseif id == 4 then
55                         io.write(data1)
56                 end
57                 
58         end
59 end