@@ -38,13 +38,18 @@ if subsystem == 'http' then
38
38
39
39
int ngx_http_lua_ffi_ssl_set_protocols (ngx_http_request_t * r ,
40
40
int protocols , char ** err );
41
+ int ngx_http_lua_ffi_ssl_get_client_hello_ext_present (ngx_http_request_t * r ,
42
+ int ** extensions , size_t * extensions_len , char ** err );
41
43
]]
42
44
43
45
ngx_lua_ffi_ssl_get_client_hello_server_name =
44
46
C .ngx_http_lua_ffi_ssl_get_client_hello_server_name
45
47
ngx_lua_ffi_ssl_get_client_hello_ext =
46
48
C .ngx_http_lua_ffi_ssl_get_client_hello_ext
47
49
ngx_lua_ffi_ssl_set_protocols = C .ngx_http_lua_ffi_ssl_set_protocols
50
+ ngx_lua_ffi_ssl_get_client_hello_ext_present =
51
+ C .ngx_http_lua_ffi_ssl_get_client_hello_ext_present
52
+
48
53
49
54
elseif subsystem == ' stream' then
50
55
ffi .cdef [[
@@ -102,6 +107,39 @@ function _M.get_client_hello_server_name()
102
107
return nil , ffi_str (errmsg [0 ])
103
108
end
104
109
110
+ -- return ext, err
111
+ function _M .get_client_hello_ext_present ()
112
+ local r = get_request ()
113
+ if not r then
114
+ error (" no request found" )
115
+ end
116
+
117
+ if ngx_phase () ~= " ssl_client_hello" then
118
+ error (" API disabled in the current context" )
119
+ end
120
+
121
+ local sizep = get_size_ptr ()
122
+ local intp = ffi .new (" int*[1]" ) -- array of len 1 of int pointers
123
+
124
+ local rc = ngx_lua_ffi_ssl_get_client_hello_ext_present (r , intp , sizep , errmsg )
125
+ if rc == FFI_OK then -- Convert C array to Lua table
126
+ local result = {}
127
+ local array = intp [0 ] -- This is now a pointer to the first integer
128
+ local size = tonumber (sizep [0 ])
129
+ for i = 0 ,size - 1 ,1 do
130
+ table_insert (result , array [i ])
131
+ end
132
+
133
+ return result , size
134
+ end
135
+
136
+ -- NGX_DECLINED: no extension
137
+ if rc == - 5 then
138
+ return nil
139
+ end
140
+
141
+ return nil , ffi_str (errmsg [0 ])
142
+ end
105
143
106
144
-- return ext, err
107
145
function _M .get_client_hello_ext (ext_type )
0 commit comments