Skip to content

Commit ce8ff27

Browse files
author
Tuure Vartiainen
committed
Merge branch 'upstream/master' into ssl-psk
2 parents 576e606 + db56858 commit ce8ff27

File tree

15 files changed

+550
-17
lines changed

15 files changed

+550
-17
lines changed

.luacheckrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
std = 'ngx_lua'
2+
globals = { 'ngx' }
23
unused_args = false
34
read_globals = {
45
"coroutine._yield"

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@ env:
3737
- LD_LIBRARY_PATH=$LUAJIT_LIB:$LD_LIBRARY_PATH
3838
- TEST_NGINX_SLEEP=0.005
3939
- TEST_NGINX_RANDOMIZE=1
40+
- LUACHECK_VER=0.21.1
4041
matrix:
41-
- NGINX_VERSION=1.9.15
4242
- NGINX_VERSION=1.11.2
43+
- NGINX_VERSION=1.13.5
4344

4445
before_install:
45-
- sudo luarocks install luacheck
46+
- sudo luarocks install luacheck $LUACHECK_VER
4647
- luacheck -q .
4748
- '! grep -n -P ''(?<=.{80}).+'' --color `find . -name ''*.lua''` || (echo "ERROR: Found Lua source lines exceeding 80 columns." > /dev/stderr; exit 1)'
4849
- '! grep -n -P ''\t+'' --color `find . -name ''*.lua''` || (echo "ERROR: Cannot use tabs." > /dev/stderr; exit 1)'
49-
- sudo cpanm --notest Test::Nginx > build.log 2>&1 || (cat build.log && exit 1)
50+
- sudo cpanm --notest Test::Nginx IPC::Run > build.log 2>&1 || (cat build.log && exit 1)
5051

5152
install:
5253
- if [ ! -d download-cache ]; then mkdir download-cache; fi

README.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ of this library in the particular OpenResty release you are using. Otherwise you
9191
into serious comaptibility issues.
9292

9393
* LuaJIT 2.1 (for now, it is the v2.1 git branch in the official luajit-2.0 git repository: http://luajit.org/download.html )
94-
* [ngx_lua](https://github.com/openresty/lua-nginx-module) v0.10.9 or later.
94+
* [ngx_lua](https://github.com/openresty/lua-nginx-module) v0.10.11 or later.
9595
* [lua-resty-lrucache](https://github.com/openresty/lua-resty-lrucache)
9696

9797
[Back to TOC](#table-of-contents)
@@ -149,6 +149,8 @@ API Implemented
149149
* [ngx.shared.DICT.safe_add](https://github.com/openresty/lua-nginx-module#ngxshareddictsafe_add)
150150
* [ngx.shared.DICT.replace](https://github.com/openresty/lua-nginx-module#ngxshareddictreplace)
151151
* [ngx.shared.DICT.delete](https://github.com/openresty/lua-nginx-module#ngxshareddictdelete)
152+
* [ngx.shared.DICT.ttl](https://github.com/openresty/lua-nginx-module#ngxshareddictttl)
153+
* [ngx.shared.DICT.expire](https://github.com/openresty/lua-nginx-module#ngxshareddictexpire)
152154
* [ngx.shared.DICT.flush_all](https://github.com/openresty/lua-nginx-module#ngxshareddictflush_all)
153155

154156
[Back to TOC](#table-of-contents)

dist.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ lib_dir=lib
77
doc_dir=lib
88
repo_link=https://github.com/openresty/lua-resty-core
99
main_module=lib/resty/core/base.lua
10-
requires = luajit >= 2.1.0, nginx >= 1.11.2, ngx_http_lua = 0.10.8, openresty/lua-resty-lrucache >= 0.06
10+
requires = luajit >= 2.1.0, nginx >= 1.11.2, ngx_http_lua = 0.10.9, openresty/lua-resty-lrucache >= 0.06

lib/ngx/balancer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ get_last_failure
138138
**context:** *balancer_by_lua&#42;*
139139

140140
Retrieves the failure details about the previous failed attempt (if any) when the `next_upstream` retrying
141-
mechanism is in action. When there was indeed a failed previous attempt, it returned a string descrbing
141+
mechanism is in action. When there was indeed a failed previous attempt, it returned a string describing
142142
that attempt's state name, as well as an integer describing the status code of that attempt.
143143

144144
Possible state names are as follows:

lib/ngx/ssl.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ Sets the SSL certificate chain opaque pointer returned by the
371371

372372
Returns `true` on success, or a `nil` value and a string describing the error otherwise.
373373

374+
Note that this `set_cert` function will run slightly faster, in terms of CPU cycles wasted, than the
375+
[set_der_cert](#set_der_cert) variant, since the first function uses opaque cdata pointers
376+
which do not require any additional conversion needed to be performed by the SSL library during the SSL handshake.
377+
374378
This function was first added in version `0.1.7`.
375379

376380
[Back to TOC](#table-of-contents)
@@ -386,6 +390,10 @@ Sets the SSL private key opaque pointer returned by the
386390

387391
Returns `true` on success, or a `nil` value and a string describing the error otherwise.
388392

393+
Note that this `set_priv_key` function will run slightly faster, in terms of CPU cycles wasted, than the
394+
[set_der_priv_key](#set_der_priv_key) variant, since the first function uses opaque cdata pointers
395+
which do not require any additional conversion needed to be performed by the SSL library during the SSL handshake.
396+
389397
This function was first added in version `0.1.7`.
390398

391399
[Back to TOC](#table-of-contents)

lib/resty/core/base.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ local FREE_LIST_REF = 0
1515

1616
if not ngx.config
1717
or not ngx.config.ngx_lua_version
18-
or ngx.config.ngx_lua_version < 10009
18+
or ngx.config.ngx_lua_version < 10011
1919
then
20-
error("ngx_lua 0.10.9+ required")
20+
error("ngx_lua 0.10.11+ required")
2121
end
2222

2323

@@ -96,7 +96,7 @@ local c_buf_type = ffi.typeof("char[?]")
9696
local _M = new_tab(0, 16)
9797

9898

99-
_M.version = "0.1.12"
99+
_M.version = "0.1.13"
100100
_M.new_tab = new_tab
101101
_M.clear_tab = clear_tab
102102

lib/resty/core/shdict.lua

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ local type = type
1717
local error = error
1818
local ngx_shared = ngx.shared
1919
local getmetatable = getmetatable
20+
local FFI_ERROR = base.FFI_ERROR
21+
local FFI_DECLINED = base.FFI_DECLINED
2022

2123

2224
ffi.cdef[[
@@ -36,6 +38,12 @@ ffi.cdef[[
3638
int *forcible);
3739

3840
int ngx_http_lua_ffi_shdict_flush_all(void *zone);
41+
42+
int ngx_http_lua_ffi_shdict_get_ttl(void *zone,
43+
const unsigned char *key, size_t key_len);
44+
45+
int ngx_http_lua_ffi_shdict_set_expire(void *zone,
46+
const unsigned char *key, size_t key_len, int exptime);
3947
]]
4048

4149

@@ -387,6 +395,81 @@ local function shdict_flush_all(zone)
387395
end
388396

389397

398+
local function shdict_ttl(zone, key)
399+
zone = check_zone(zone)
400+
401+
if key == nil then
402+
return nil, "nil key"
403+
end
404+
405+
if type(key) ~= "string" then
406+
key = tostring(key)
407+
end
408+
409+
local key_len = #key
410+
if key_len == 0 then
411+
return nil, "empty key"
412+
end
413+
414+
if key_len > 65535 then
415+
return nil, "key too long"
416+
end
417+
418+
local rc = C.ngx_http_lua_ffi_shdict_get_ttl(zone, key, key_len)
419+
420+
if rc == FFI_ERROR then
421+
return nil, "bad zone"
422+
end
423+
424+
if rc == FFI_DECLINED then
425+
return nil, "not found"
426+
end
427+
428+
return tonumber(rc) / 1000
429+
end
430+
431+
432+
local function shdict_expire(zone, key, exptime)
433+
zone = check_zone(zone)
434+
435+
if not exptime then
436+
error('bad "exptime" argument', 2)
437+
end
438+
439+
if key == nil then
440+
return nil, "nil key"
441+
end
442+
443+
if type(key) ~= "string" then
444+
key = tostring(key)
445+
end
446+
447+
local key_len = #key
448+
if key_len == 0 then
449+
return nil, "empty key"
450+
end
451+
452+
if key_len > 65535 then
453+
return nil, "key too long"
454+
end
455+
456+
local rc = C.ngx_http_lua_ffi_shdict_set_expire(zone, key, key_len,
457+
exptime * 1000)
458+
459+
if rc == FFI_ERROR then
460+
return nil, "bad zone"
461+
end
462+
463+
if rc == FFI_DECLINED then
464+
return nil, "not found"
465+
end
466+
467+
-- NGINX_OK/FFI_OK
468+
469+
return true
470+
end
471+
472+
390473
if ngx_shared then
391474
local _, dict = next(ngx_shared, nil)
392475
if dict then
@@ -404,6 +487,8 @@ if ngx_shared then
404487
mt.replace = shdict_replace
405488
mt.delete = shdict_delete
406489
mt.flush_all = shdict_flush_all
490+
mt.ttl = shdict_ttl
491+
mt.expire = shdict_expire
407492
end
408493
end
409494
end

t/balancer.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ qr/\[error] .*? upstream prematurely closed connection while reading response he
707707
708708
709709
=== TEST 16: https (keepalive)
710-
--- skip_nginx: 4: < 1.7.5
710+
--- skip_nginx: 5: < 1.7.5
711711
--- http_config
712712
lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;";
713713

t/ocsp.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim:set ft=ts=4 sw=4 et fdm=marker:
1+
# vim:set ft= ts=4 sw=4 et fdm=marker:
22

33
use Test::Nginx::Socket::Lua;
44
use Cwd qw(cwd);

0 commit comments

Comments
 (0)