@@ -16,23 +16,23 @@ index 3caabe2..6361a23 100644
16
16
$(INSTALL) lib/ngx/ssl/*.lua $(DESTDIR)$(LUA_LIB_DIR)/ngx/ssl/
17
17
18
18
diff --git lib/resty/core.lua lib/resty/core.lua
19
- index 5472230..d6e6869 100644
19
+ index 5472230..7d3ab16 100644
20
20
--- lib/resty/core.lua
21
21
+++ lib/resty/core.lua
22
- @@ -20,6 +20,7 @@ if subsystem == 'http' then
23
- require "resty.core.phase"
24
- require "resty.core.ndk"
25
- require "resty.core.socket"
26
- + require "resty.core.socket.tcp"
22
+ @@ -23,6 +23,7 @@ if subsystem == 'http' then
27
23
end
28
-
29
-
24
+
25
+
26
+ + require "resty.core.socket.tcp"
27
+ require "resty.core.misc"
28
+ require "resty.core.ctx"
29
+
30
30
diff --git lib/resty/core/socket/tcp.lua lib/resty/core/socket/tcp.lua
31
31
new file mode 100644
32
- index 0000000..30302f0
32
+ index 0000000..4b59adb
33
33
--- /dev/null
34
34
+++ lib/resty/core/socket/tcp.lua
35
- @@ -0,0 +1,236 @@
35
+ @@ -0,0 +1,273 @@
36
36
+ -- Copyright (C) by OpenResty Inc.
37
37
+
38
38
+
@@ -59,9 +59,15 @@ index 0000000..30302f0
59
59
+ local select = select
60
60
+ local co_yield = coroutine._yield
61
61
+ local io_open = io.open
62
+ + local subsystem = ngx.config.subsystem
63
+ +
62
64
+
65
+ + local ngx_lua_ffi_socket_tcp_tlshandshake
66
+ + local ngx_lua_ffi_socket_tcp_get_tlshandshake_result
67
+ + local ngx_lua_ffi_tls_free_session
63
68
+
64
- + ffi.cdef[[
69
+ + if subsystem == 'http' then
70
+ + ffi.cdef[[
65
71
+ typedef struct ngx_http_lua_socket_tcp_upstream_s
66
72
+ ngx_http_lua_socket_tcp_upstream_t;
67
73
+
@@ -77,6 +83,37 @@ index 0000000..30302f0
77
83
+ void ngx_http_lua_ffi_tls_free_session(void *sess);
78
84
+ ]]
79
85
+
86
+ + ngx_lua_ffi_socket_tcp_tlshandshake =
87
+ + C.ngx_http_lua_ffi_socket_tcp_tlshandshake
88
+ + ngx_lua_ffi_socket_tcp_get_tlshandshake_result =
89
+ + C.ngx_http_lua_ffi_socket_tcp_get_tlshandshake_result
90
+ + ngx_lua_ffi_tls_free_session = C.ngx_http_lua_ffi_tls_free_session
91
+ +
92
+ + elseif subsystem == 'stream' then
93
+ + ffi.cdef[[
94
+ + typedef struct ngx_stream_lua_socket_tcp_upstream_s
95
+ + ngx_stream_lua_socket_tcp_upstream_t;
96
+ +
97
+ + int ngx_stream_lua_ffi_socket_tcp_tlshandshake(ngx_stream_lua_request_t *r,
98
+ + ngx_stream_lua_socket_tcp_upstream_t *u, void *sess,
99
+ + int enable_session_reuse, ngx_str_t *server_name, int verify,
100
+ + int ocsp_status_req, void *chain, void *pkey, char **errmsg);
101
+ +
102
+ + int ngx_stream_lua_ffi_socket_tcp_get_tlshandshake_result(
103
+ + ngx_stream_lua_request_t *r,
104
+ + ngx_stream_lua_socket_tcp_upstream_t *u, void **sess, char **errmsg,
105
+ + int *openssl_error_code);
106
+ +
107
+ + void ngx_stream_lua_ffi_tls_free_session(void *sess);
108
+ + ]]
109
+ +
110
+ + ngx_lua_ffi_socket_tcp_tlshandshake =
111
+ + C.ngx_stream_lua_ffi_socket_tcp_tlshandshake
112
+ + ngx_lua_ffi_socket_tcp_get_tlshandshake_result =
113
+ + C.ngx_stream_lua_ffi_socket_tcp_get_tlshandshake_result
114
+ + ngx_lua_ffi_tls_free_session = C.ngx_stream_lua_ffi_tls_free_session
115
+ + end
116
+ +
80
117
+
81
118
+ local SOCKET_CTX_INDEX = 1
82
119
+
@@ -175,7 +212,7 @@ index 0000000..30302f0
175
212
+
176
213
+ local u = self[SOCKET_CTX_INDEX]
177
214
+
178
- + local rc = C.ngx_http_lua_ffi_socket_tcp_tlshandshake (r, u,
215
+ + local rc = ngx_lua_ffi_socket_tcp_tlshandshake (r, u,
179
216
+ session_ptr[0],
180
217
+ reused_session ~= false,
181
218
+ server_name_str,
@@ -205,7 +242,7 @@ index 0000000..30302f0
205
242
+ return true
206
243
+ end
207
244
+
208
- + rc = C.ngx_http_lua_ffi_socket_tcp_get_tlshandshake_result (r, u,
245
+ + rc = ngx_lua_ffi_socket_tcp_get_tlshandshake_result (r, u,
209
246
+ session_ptr, errmsg, openssl_error_code)
210
247
+
211
248
+ assert(rc == FFI_OK)
@@ -214,14 +251,14 @@ index 0000000..30302f0
214
251
+ return nil
215
252
+ end
216
253
+
217
- + return ffi_gc(session_ptr[0], C.ngx_http_lua_ffi_tls_free_session )
254
+ + return ffi_gc(session_ptr[0], ngx_lua_ffi_tls_free_session )
218
255
+ end
219
256
+
220
257
+ assert(rc == FFI_AGAIN)
221
258
+
222
259
+ co_yield()
223
260
+
224
- + rc = C.ngx_http_lua_ffi_socket_tcp_get_tlshandshake_result (r, u,
261
+ + rc = ngx_lua_ffi_socket_tcp_get_tlshandshake_result (r, u,
225
262
+ session_ptr, errmsg, openssl_error_code)
226
263
+ end
227
264
+ end
0 commit comments