From c47be2e727d1bb3e2e3aa415ec96be2a5f8a45b7 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Sun, 14 Jun 2009 08:51:43 +0000 Subject: [PATCH] GSoC: Documentation #2 --- libs/lucid-http/luasrc/lucid/http.lua | 3 + .../luasrc/lucid/http/DirectoryPublisher.lua | 3 + .../luasrc/lucid/http/LuciWebPublisher.lua | 4 ++ .../luasrc/lucid/http/Redirector.lua | 4 +- .../luasrc/lucid/http/handler/catchall.lua | 18 +++++ .../luasrc/lucid/http/handler/file.lua | 23 ++++++- .../luasrc/lucid/http/handler/luci.lua | 16 +++++ libs/lucid-http/luasrc/lucid/http/server.lua | 66 +++++++++++++++--- libs/lucid-rpc/luasrc/lucid/rpc.lua | 4 +- libs/lucid-rpc/luasrc/lucid/rpc/ruci.lua | 19 +++++ libs/lucid-rpc/luasrc/lucid/rpc/server.lua | 69 +++++++++++++++++-- libs/lucid-rpc/luasrc/lucid/rpc/system.lua | 17 ++++- 12 files changed, 229 insertions(+), 17 deletions(-) diff --git a/libs/lucid-http/luasrc/lucid/http.lua b/libs/lucid-http/luasrc/lucid/http.lua index 32ba5791d..931967c56 100644 --- a/libs/lucid-http/luasrc/lucid/http.lua +++ b/libs/lucid-http/luasrc/lucid/http.lua @@ -17,6 +17,9 @@ local srv = require "luci.lucid.http.server" module "luci.lucid.http" +--- Prepare the HTTP-daemon and its associated publishers. +-- @param publisher Table of publishers +-- @return factory callback or nil, error message function factory(publisher) local server = srv.Server() for _, r in ipairs(publisher) do diff --git a/libs/lucid-http/luasrc/lucid/http/DirectoryPublisher.lua b/libs/lucid-http/luasrc/lucid/http/DirectoryPublisher.lua index f471781a9..b57b5586a 100644 --- a/libs/lucid-http/luasrc/lucid/http/DirectoryPublisher.lua +++ b/libs/lucid-http/luasrc/lucid/http/DirectoryPublisher.lua @@ -18,6 +18,9 @@ local srv = require "luci.lucid.http.server" module "luci.lucid.http.DirectoryPublisher" +--- Prepare a directory publisher and assign it to a given Virtual Host. +-- @param server HTTP daemon object +-- @param config publisher configuration function factory(server, config) config.domain = config.domain or "" local vhost = server:get_vhosts()[config.domain] diff --git a/libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua b/libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua index 0d0648967..f72b94f41 100644 --- a/libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua +++ b/libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua @@ -18,6 +18,10 @@ local srv = require "luci.lucid.http.server" module "luci.lucid.http.LuciWebPublisher" + +--- Prepare a LuCI web publisher and assign it to a given Virtual Host. +-- @param server HTTP daemon object +-- @param config publisher configuration function factory(server, config) pcall(function() require "luci.dispatcher" diff --git a/libs/lucid-http/luasrc/lucid/http/Redirector.lua b/libs/lucid-http/luasrc/lucid/http/Redirector.lua index c0af90b00..73561af2d 100644 --- a/libs/lucid-http/luasrc/lucid/http/Redirector.lua +++ b/libs/lucid-http/luasrc/lucid/http/Redirector.lua @@ -17,7 +17,9 @@ local srv = require "luci.lucid.http.server" module "luci.lucid.http.Redirector" - +--- Prepare a redirector publisher and assign it to a given Virtual Host. +-- @param server HTTP daemon object +-- @param config publisher configuration function factory(server, config) config.domain = config.domain or "" local vhost = server:get_vhosts()[config.domain] diff --git a/libs/lucid-http/luasrc/lucid/http/handler/catchall.lua b/libs/lucid-http/luasrc/lucid/http/handler/catchall.lua index 3b2c2b0a0..30af84ba2 100644 --- a/libs/lucid-http/luasrc/lucid/http/handler/catchall.lua +++ b/libs/lucid-http/luasrc/lucid/http/handler/catchall.lua @@ -15,8 +15,15 @@ local srv = require "luci.lucid.http.server" local proto = require "luci.http.protocol" local util = require "luci.util" +--- Catchall Handler +-- @cstyle instance module "luci.lucid.http.handler.catchall" +--- Create a Redirect handler. +-- @param name Name +-- @param target Redirect Target +-- @class function +-- @return Redirect handler object Redirect = util.class(srv.Handler) function Redirect.__init__(self, name, target) @@ -24,6 +31,9 @@ function Redirect.__init__(self, name, target) self.target = target end +--- Handle a GET request. +-- @param request Request object +-- @return status code, header table, response source function Redirect.handle_GET(self, request) local target = self.target local protocol = request.env.HTTPS and "https://" or "http://" @@ -46,8 +56,16 @@ function Redirect.handle_GET(self, request) return 302, { Location = target } end +--- Handle a POST request. +-- @class function +-- @param request Request object +-- @return status code, header table, response source Redirect.handle_POST = Redirect.handle_GET +--- Handle a HEAD request. +-- @class function +-- @param request Request object +-- @return status code, header table, response source function Redirect.handle_HEAD(self, request) local stat, head = self:handle_GET(request) return stat, head diff --git a/libs/lucid-http/luasrc/lucid/http/handler/file.lua b/libs/lucid-http/luasrc/lucid/http/handler/file.lua index d08e47025..8f7bf8b8a 100644 --- a/libs/lucid-http/luasrc/lucid/http/handler/file.lua +++ b/libs/lucid-http/luasrc/lucid/http/handler/file.lua @@ -28,8 +28,16 @@ local date = require "luci.http.protocol.date" local mime = require "luci.http.protocol.mime" local cond = require "luci.http.protocol.conditionals" +--- File system handler +-- @cstyle instance module "luci.lucid.http.handler.file" +--- Create a simple file system handler. +-- @class function +-- @param name Name +-- @param docroot Physical Document Root +-- @param options Options +-- @return Simple file system handler object Simple = util.class(srv.Handler) function Simple.__init__(self, name, docroot, options) @@ -42,6 +50,10 @@ function Simple.__init__(self, name, docroot, options) self.error404 = options.error404 end +--- Parse a range request. +-- @param request Request object +-- @param size File size +-- @return offset, length, range header or boolean status function Simple.parse_range(self, request, size) if not request.headers.Range then return true @@ -75,6 +87,9 @@ function Simple.parse_range(self, request, size) return from, (1 + to - from), range end +--- Translate path and return file information. +-- @param uri Request URI +-- @return physical file path, file information function Simple.getfile(self, uri) if not self.realdocroot then self.realdocroot = fs.realpath(self.docroot) @@ -86,6 +101,9 @@ function Simple.getfile(self, uri) return file, fs.stat(file) end +--- Handle a GET request. +-- @param request Request object +-- @return status code, header table, response source function Simple.handle_GET(self, request) local file, stat = self:getfile(prot.urldecode(request.env.PATH_INFO, true)) @@ -190,7 +208,7 @@ function Simple.handle_GET(self, request) 'p { margin:0 }' .. '\n

Index of %s/