webmcp
view framework/env/request/set_allowed_json_request_slots.lua @ 31:1cd9e69b85cb
add execute.load_chunk(args)
load_chunk loads the content of a lua file and returns the code.
It can construct the path name easily so you can put helper code in
seperate files for DRYness.
load_chunk loads the content of a lua file and returns the code.
It can construct the path name easily so you can put helper code in
seperate files for DRYness.
| author | Daniel Poelzleithner <poelzi@poelzi.org> |
|---|---|
| date | Tue Oct 05 02:34:04 2010 +0200 (2010-10-05) |
| parents | 944642a3e488 |
| children |
line source
1 --[[--
2 request.set_allowed_json_request_slots(
3 slot_idents -- list of names of slots which can be requested in JSON format
4 )
6 This function enables JSON requests. The given list of names of slots selects, which slots may be requestd in JSON format (without layout).
8 --]]--
10 function request.set_allowed_json_request_slots(slot_idents)
11 if cgi then -- do nothing, when being in interactive mode
12 local hash = {}
13 for idx, slot_ident in ipairs(slot_idents) do
14 hash[slot_ident] = true
15 end
16 if cgi.params["_webmcp_json_slots[]"] then
17 for idx, slot_ident in ipairs(cgi.params["_webmcp_json_slots[]"]) do
18 if not hash[slot_ident] then
19 error('Requesting slot "' .. slot_ident .. '" is forbidden.')
20 end
21 end
22 end
23 request._json_requests_allowed = true
24 end
25 end
