Skip to content

Commit 2fe1849

Browse files
feature: add ffi functions ngx_stream_lua_ffi_socket_tcp_get_ssl_pointer() and ngx_stream_lua_ffi_socket_tcp_get_ssl_ctx().
1 parent c7b161f commit 2fe1849

File tree

1 file changed

+89
-2
lines changed

1 file changed

+89
-2
lines changed

src/ngx_stream_lua_socket_tcp.c

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,8 @@ ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
374374
lua_pushcfunction(L, ngx_stream_lua_socket_tcp_sslhandshake);
375375
lua_setfield(L, -2, "sslhandshake");
376376

377-
lua_pushcfunction(L, ngx_stream_lua_socket_tcp_get_ssl_session);
377+
lua_pushcfunction(L, ngx_stream_lua_socket_tcp_get_ssl_session);
378378
lua_setfield(L, -2, "getsslsession");
379-
380379
#endif
381380

382381
lua_pushcfunction(L, ngx_stream_lua_socket_tcp_receive);
@@ -1663,6 +1662,94 @@ ngx_stream_lua_socket_conn_error_retval_handler(ngx_stream_lua_request_t *r,
16631662

16641663

16651664
#if (NGX_STREAM_SSL)
1665+
int
1666+
ngx_stream_lua_ffi_socket_tcp_get_ssl_pointer(
1667+
ngx_stream_lua_request_t *r,
1668+
ngx_stream_lua_socket_tcp_upstream_t *u,
1669+
void **pssl, char **errmsg)
1670+
{
1671+
ngx_connection_t *c;
1672+
1673+
*pssl = NULL;
1674+
if (r == NULL) {
1675+
*errmsg = "no request";
1676+
return NGX_ERROR;
1677+
}
1678+
1679+
ngx_log_debug0(NGX_LOG_DEBUG_STREAM, r->connection->log, 0,
1680+
"stream lua tcp socket getsslpointer");
1681+
1682+
if (u == NULL
1683+
|| u->peer.connection == NULL
1684+
|| u->read_closed
1685+
|| u->write_closed)
1686+
{
1687+
*errmsg = "closed";
1688+
return NGX_ERROR;
1689+
}
1690+
1691+
if (u->request != r) {
1692+
*errmsg = "bad request";
1693+
return NGX_ERROR;
1694+
}
1695+
1696+
c = u->peer.connection;
1697+
if (c == NULL || c->ssl == NULL || c->ssl->connection == NULL) {
1698+
*errmsg = "no ssl connection";
1699+
return NGX_ERROR;
1700+
}
1701+
1702+
*pssl = c->ssl->connection;
1703+
1704+
return NGX_OK;
1705+
}
1706+
1707+
1708+
int
1709+
ngx_stream_lua_ffi_socket_tcp_get_ssl_ctx(
1710+
ngx_stream_lua_request_t *r,
1711+
ngx_stream_lua_socket_tcp_upstream_t *u,
1712+
void **pctx, char **errmsg)
1713+
{
1714+
ngx_connection_t *c;
1715+
1716+
*pctx = NULL;
1717+
if (r == NULL) {
1718+
*errmsg = "no request";
1719+
return NGX_ERROR;
1720+
}
1721+
1722+
ngx_log_debug0(NGX_LOG_DEBUG_STREAM, r->connection->log, 0,
1723+
"stream lua tcp socket getsslpointer");
1724+
1725+
if (u == NULL
1726+
|| u->peer.connection == NULL
1727+
|| u->read_closed
1728+
|| u->write_closed)
1729+
{
1730+
*errmsg = "closed";
1731+
return NGX_ERROR;
1732+
}
1733+
1734+
if (u->request != r) {
1735+
*errmsg = "bad request";
1736+
return NGX_ERROR;
1737+
}
1738+
1739+
c = u->peer.connection;
1740+
if (c == NULL || c->ssl == NULL || c->ssl->session_ctx == NULL) {
1741+
*errmsg = "no ssl connection";
1742+
return NGX_ERROR;
1743+
}
1744+
1745+
*pctx = c->ssl->session_ctx;
1746+
1747+
return NGX_OK;
1748+
}
1749+
1750+
1751+
1752+
16661753
static int
16671754
ngx_stream_lua_socket_tcp_get_ssl_session(lua_State *L)
16681755
{

0 commit comments

Comments
 (0)