Changeset 3000
- Timestamp:
- 08/29/08 13:27:54 (5 years ago)
- Location:
- ff-luci/trunk/modules/rpc/luasrc
- Files:
-
- 2 modified
-
controller/rpc.lua (modified) (2 diffs)
-
jsonrpc.lua (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ff-luci/trunk/modules/rpc/luasrc/controller/rpc.lua
r2956 r3000 17 17 local pairs = pairs 18 18 local print = print 19 local pcall = pcall 20 local table = table 19 21 20 22 module "luci.controller.rpc" … … 87 89 function rpc_fs() 88 90 local util = require "luci.util" 89 local fs = util.clone(require "luci.fs") 91 local io = require "io" 92 local fs2 = util.clone(require "luci.fs") 90 93 local jsonrpc = require "luci.jsonrpc" 91 94 local http = require "luci.http" 92 95 local ltn12 = require "luci.ltn12" 93 94 function fs.readfile(filename) 95 if not pcall(require, "mime") then 96 97 function fs2.readfile(filename) 98 local stat, mime = pcall(require, "mime") 99 if not stat then 96 100 error("Base64 support not available. Please install LuaSocket.") 97 101 end 98 99 return ltn12.source.chain(ltn12.source.file(filename), mime.encode("base64")) 102 103 local fp = io.open(filename) 104 if not fp then 105 return nil 106 end 107 108 local output = {} 109 local sink = ltn12.sink.table(output) 110 local source = ltn12.source.chain(ltn12.source.file(fp), mime.encode("base64")) 111 return ltn12.pump.all(source, sink) and table.concat(output) 100 112 end 101 113 102 function fs.writefile(filename, data) 103 if not pcall(require, "mime") then 114 function fs2.writefile(filename, data) 115 local stat, mime = pcall(require, "mime") 116 if not stat then 104 117 error("Base64 support not available. Please install LuaSocket.") 105 118 end 106 107 local sink = ltn12.sink.chain(mime.decode("base64"), ltn12.sink.file(filename)) 108 return ltn12.pump.all(ltn12.source.string(data), sink) 119 120 local file = io.open(filename, "w") 121 local sink = file and ltn12.sink.chain(mime.decode("base64"), ltn12.sink.file(file)) 122 return sink and ltn12.pump.all(ltn12.source.string(data), sink) or false 109 123 end 110 124 111 125 http.prepare_content("application/json") 112 ltn12.pump.all(jsonrpc.handle(fs , http.source()), http.write)126 ltn12.pump.all(jsonrpc.handle(fs2, http.source()), http.write) 113 127 end 114 128 -
ff-luci/trunk/modules/rpc/luasrc/jsonrpc.lua
r2956 r3000 45 45 if type(json.method) == "string" 46 46 and (not json.params or type(json.params) == "table") then 47 if tbl[json.method] then 47 local method = resolve(tbl, json.method) 48 if method then 48 49 response = reply(json.jsonrpc, json.id, 49 proxy( resolve(tbl, json.method), unpack(json.params or {})))50 proxy(method, unpack(json.params or {}))) 50 51 else 51 52 response = reply(json.jsonrpc, json.id,
