Skip to content

Commit

Permalink
ngx-rtmp-kmp: prefer proxy_protocol address (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
erankor authored Sep 3, 2023
1 parent 9a8fb64 commit 6f81220
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 9 additions & 6 deletions nginx-rtmp-kmp-module/src/ngx_rtmp_kmp_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ static size_t
ngx_rtmp_kmp_connect_rtmp_json_get_size(ngx_rtmp_kmp_connect_t *obj,
ngx_rtmp_session_t *s)
{
size_t result;
size_t result;
ngx_rtmp_kmp_ctx_t *ctx;

ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_kmp_module);
result =
sizeof("{\"app\":\"") - 1 + ngx_json_str_get_size(&obj->app) +
sizeof("\",\"flashver\":\"") - 1 +
Expand All @@ -25,9 +27,8 @@ ngx_rtmp_kmp_connect_rtmp_json_get_size(ngx_rtmp_kmp_connect_t *obj,
sizeof("\",\"tc_url\":\"") - 1 + ngx_json_str_get_size(&obj->tc_url) +
sizeof("\",\"page_url\":\"") - 1 +
ngx_json_str_get_size(&obj->page_url) +
sizeof("\",\"addr\":\"") - 1 + s->connection->addr_text.len +
ngx_escape_json(NULL, s->connection->addr_text.data,
s->connection->addr_text.len) +
sizeof("\",\"addr\":\"") - 1 +
ngx_json_str_get_size(&ctx->remote_addr) +
sizeof("\",\"connection\":") - 1 + NGX_INT_T_LEN +
sizeof("}") - 1;

Expand All @@ -39,6 +40,9 @@ static u_char *
ngx_rtmp_kmp_connect_rtmp_json_write(u_char *p, ngx_rtmp_kmp_connect_t *obj,
ngx_rtmp_session_t *s)
{
ngx_rtmp_kmp_ctx_t *ctx;

ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_kmp_module);
p = ngx_copy_fix(p, "{\"app\":\"");
p = ngx_json_str_write(p, &obj->app);
p = ngx_copy_fix(p, "\",\"flashver\":\"");
Expand All @@ -50,8 +54,7 @@ ngx_rtmp_kmp_connect_rtmp_json_write(u_char *p, ngx_rtmp_kmp_connect_t *obj,
p = ngx_copy_fix(p, "\",\"page_url\":\"");
p = ngx_json_str_write(p, &obj->page_url);
p = ngx_copy_fix(p, "\",\"addr\":\"");
p = (u_char *) ngx_escape_json(p, s->connection->addr_text.data,
s->connection->addr_text.len);
p = ngx_json_str_write(p, &ctx->remote_addr);
p = ngx_copy_fix(p, "\",\"connection\":");
p = ngx_sprintf(p, "%uA", (ngx_atomic_uint_t) s->connection->number);
*p++ = '}';
Expand Down
4 changes: 3 additions & 1 deletion nginx-rtmp-kmp-module/src/ngx_rtmp_kmp_json.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

out ngx_rtmp_kmp_connect_rtmp_json ngx_rtmp_kmp_connect_t ngx_rtmp_session_t *s
- %var ngx_rtmp_kmp_ctx_t *ctx
- %code ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_kmp_module);
app %jV
flashver %jV
swf_url %jV
tc_url %jV
page_url %jV
addr %V s->connection->addr_text
addr %jV ctx->remote_addr
connection %uA s->connection->number

out ngx_rtmp_kmp_connect_json ngx_rtmp_kmp_connect_t ngx_rtmp_session_t *s
Expand Down

0 comments on commit 6f81220

Please sign in to comment.