Skip to content

Commit

Permalink
update to 1.5.11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Apr 15, 2014
1 parent 2f7d508 commit 7b50651
Show file tree
Hide file tree
Showing 34 changed files with 4,485 additions and 309 deletions.
24 changes: 21 additions & 3 deletions heroku-openresty-dev-1.rockspec
Expand Up @@ -19,11 +19,11 @@ build = {
type = "command",
install_command = [[
LIB_DIR=`cd $(PREFIX)/../../../../; pwd`
cp luajit/lib/libluajit-5.1.so.2.0.2 "$LIB_DIR"
cp luajit/lib/libluajit-5.1.so.2.1.0 "$LIB_DIR"
(
cd "$LIB_DIR"
ln -s libluajit-5.1.so.2.0.2 libluajit-5.1.so.2
ln -s libluajit-5.1.so.2.0.2 libluajit-5.1.so
ln -s libluajit-5.1.so.2.1.0 libluajit-5.1.so.2
ln -s libluajit-5.1.so.2.1.0 libluajit-5.1.so
)
]],
install = {
Expand All @@ -40,7 +40,21 @@ build = {
},
lua = {
["resty.aes"] = "lualib/resty/aes.lua",
["resty.core"] = "lualib/resty/core.lua",
["resty.core.base"] = "lualib/resty/core/base.lua",
["resty.core.base64"] = "lualib/resty/core/base64.lua",
["resty.core.ctx"] = "lualib/resty/core/ctx.lua",
["resty.core.exit"] = "lualib/resty/core/exit.lua",
["resty.core.hash"] = "lualib/resty/core/hash.lua",
["resty.core.misc"] = "lualib/resty/core/misc.lua",
["resty.core.regex"] = "lualib/resty/core/regex.lua",
["resty.core.request"] = "lualib/resty/core/request.lua",
["resty.core.response"] = "lualib/resty/core/response.lua",
["resty.core.shdict"] = "lualib/resty/core/shdict.lua",
["resty.core.uri"] = "lualib/resty/core/uri.lua",
["resty.core.var"] = "lualib/resty/core/var.lua",
["resty.dns.resolver"] = "lualib/resty/dns/resolver.lua",
["resty.lock"] = "lualib/resty/lock.lua",
["resty.md5"] = "lualib/resty/md5.lua",
["resty.memcached"] = "lualib/resty/memcached.lua",
["resty.mysql"] = "lualib/resty/mysql.lua",
Expand All @@ -54,6 +68,10 @@ build = {
["resty.sha512"] = "lualib/resty/sha512.lua",
["resty.string"] = "lualib/resty/string.lua",
["resty.upload"] = "lualib/resty/upload.lua",
["resty.upstream.healthcheck"] = "lualib/resty/upstream/healthcheck.lua",
["resty.websocket.client"] = "lualib/resty/websocket/client.lua",
["resty.websocket.protocol"] = "lualib/resty/websocket/protocol.lua",
["resty.websocket.server"] = "lualib/resty/websocket/server.lua",
},
}
}
Binary file removed luajit/lib/libluajit-5.1.so.2.0.2
Binary file not shown.
Binary file added luajit/lib/libluajit-5.1.so.2.1.0
Binary file not shown.
Binary file modified lualib/cjson.so
Binary file not shown.
Binary file modified lualib/rds/parser.so
Binary file not shown.
Binary file modified lualib/redis/parser.so
Binary file not shown.
22 changes: 22 additions & 0 deletions lualib/resty/core.lua
@@ -0,0 +1,22 @@
-- Copyright (C) 2013 Yichun Zhang (agentzh)


require "resty.core.uri"
require "resty.core.hash"
require "resty.core.base64"
require "resty.core.regex"
require "resty.core.exit"
require "resty.core.shdict"
require "resty.core.var"
require "resty.core.ctx"
require "resty.core.misc"
require "resty.core.request"
require "resty.core.response"


local base = require "resty.core.base"


return {
version = base.version
}
181 changes: 181 additions & 0 deletions lualib/resty/core/base.lua
@@ -0,0 +1,181 @@
-- Copyright (C) 2013 Yichun Zhang (agentzh)


local ffi = require 'ffi'
local ffi_new = ffi.new
local error = error
local setmetatable = setmetatable
local floor = math.floor
local ceil = math.ceil


local str_buf_size = 4096
local str_buf
local size_ptr
local FREE_LIST_REF = 0


if not ngx.config
or not ngx.config.ngx_lua_version
or ngx.config.ngx_lua_version < 9006
then
error("ngx_lua 0.9.6+ required")
end


if string.find(jit.version, " 2.0") then
ngx.log(ngx.WARN, "use of lua-resty-core with LuaJIT 2.0 is "
.. "not recommended; use LuaJIT 2.1+ instead")
end


local ok, new_tab = pcall(require, "table.new")
if not ok then
new_tab = function (narr, nrec) return {} end
end


local ok, clear_tab = pcall(require, "table.clear")
if not ok then
clear_tab = function (tab)
for k, _ in pairs(tab) do
tab[k] = nil
end
end
end


-- XXX for now LuaJIT 2.1 cannot compile require()
-- so we make the fast code path Lua only in our own
-- wrapper so that most of the require() calls in hot
-- Lua code paths can be JIT compiled.
do
local orig_require = require
local pkg_loaded = package.loaded
local function my_require(name)
local mod = pkg_loaded[name]
if mod then
return mod
end
return orig_require(name)
end
getfenv(0).require = my_require
end


if not pcall(ffi.typeof, "ngx_str_t") then
ffi.cdef[[
typedef struct {
size_t len;
const unsigned char *data;
} ngx_str_t;

struct ngx_http_request_s;
typedef struct ngx_http_request_s ngx_http_request_t;
]]
end


if not pcall(ffi.typeof, "ngx_http_lua_ffi_str_t") then
ffi.cdef[[
typedef struct {
int len;
const unsigned char *data;
} ngx_http_lua_ffi_str_t;
]]
end


local c_buf_type = ffi.typeof("char[?]")


local _M = new_tab(0, 15)


_M.version = "0.0.5"
_M.new_tab = new_tab
_M.clear_tab = clear_tab


local errmsg


function _M.get_errmsg_ptr()
if not errmsg then
errmsg = ffi_new("char *[1]")
end
return errmsg
end


if not ngx then
return error("no existing ngx. table found")
end


function _M.set_string_buf_size(size)
if size <= 0 then
return
end
if str_buf then
str_buf = nil
end
str_buf_size = ceil(size)
end


function _M.get_string_buf_size()
return str_buf_size
end


function _M.get_size_ptr()
if not size_ptr then
size_ptr = ffi_new("size_t[1]")
end

return size_ptr
end


function _M.get_string_buf(size)
-- ngx.log(ngx.ERR, "str buf size: ", str_buf_size)
if size > str_buf_size then
return ffi_new(c_buf_type, size)
end

if not str_buf then
str_buf = ffi_new(c_buf_type, str_buf_size)
end

return str_buf
end


function _M.ref_in_table(tb, key)
if key == nil then
return -1
end
local ref = tb[FREE_LIST_REF]
if ref and ref ~= 0 then
tb[FREE_LIST_REF] = tb[ref]

else
ref = #tb + 1
end
tb[ref] = key

-- print("ref key_id returned ", ref)
return ref
end


_M.FFI_OK = 0
_M.FFI_NO_REQ_CTX = -100
_M.FFI_BAD_CONTEXT = -101
_M.FFI_ERROR = -1
_M.FFI_DONE = -4
_M.FFI_DECLINED = -5


return _M
78 changes: 78 additions & 0 deletions lualib/resty/core/base64.lua
@@ -0,0 +1,78 @@
-- Copyright (C) 2013 Yichun Zhang (agentzh)


local ffi = require 'ffi'
local base = require "resty.core.base"

local ffi_string = ffi.string
local ffi_new = ffi.new
local C = ffi.C
local setmetatable = setmetatable
local ngx = ngx
local type = type
local tostring = tostring
local error = error
local get_string_buf = base.get_string_buf
local get_size_ptr = base.get_size_ptr
local floor = math.floor
local print = print
local tonumber = tonumber


ffi.cdef[[
size_t ngx_http_lua_ffi_encode_base64(const unsigned char *src,
size_t len, unsigned char *dst);

int ngx_http_lua_ffi_decode_base64(const unsigned char *src,
size_t len, unsigned char *dst,
size_t *dlen);
]]


local function base64_encoded_length(len)
return floor((len + 2) / 3) * 4
end


ngx.encode_base64 = function (s)
if type(s) ~= 'string' then
if not s then
s = ''
else
s = tostring(s)
end
end
local slen = #s
local dlen = base64_encoded_length(slen)
-- print("dlen: ", tonumber(dlen))
local dst = get_string_buf(dlen)
dlen = C.ngx_http_lua_ffi_encode_base64(s, slen, dst)
return ffi_string(dst, dlen)
end


local function base64_decoded_length(len)
return floor((len + 3) / 4) * 3
end


ngx.decode_base64 = function (s)
if type(s) ~= 'string' then
return error("string argument only")
end
local slen = #s
local dlen = base64_decoded_length(slen)
-- print("dlen: ", tonumber(dlen))
local dst = get_string_buf(dlen)
local pdlen = get_size_ptr()
local ok = C.ngx_http_lua_ffi_decode_base64(s, slen, dst, pdlen)
if ok == 0 then
return nil
end
return ffi_string(dst, pdlen[0])
end


return {
version = base.version
}

0 comments on commit 7b50651

Please sign in to comment.