Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If proxy protocol is used take the remote addr from there. #173

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions nginx-rtmp-kmp-module/src/ngx_rtmp_kmp_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ 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(&obj->addr) +
sizeof("\",\"connection\":") - 1 + NGX_INT_T_LEN +
sizeof("}") - 1;

Expand All @@ -50,8 +48,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, &obj->addr);
p = ngx_copy_fix(p, "\",\"connection\":");
p = ngx_sprintf(p, "%uA", (ngx_atomic_uint_t) s->connection->number);
*p++ = '}';
Expand Down
8 changes: 6 additions & 2 deletions nginx-rtmp-kmp-module/src/ngx_rtmp_kmp_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef struct {
ngx_json_str_t swf_url;
ngx_json_str_t tc_url;
ngx_json_str_t page_url;
ngx_json_str_t addr;
} ngx_rtmp_kmp_connect_t;

#include "ngx_rtmp_kmp_json.h"
Expand Down Expand Up @@ -357,14 +358,17 @@ ngx_rtmp_kmp_get_publish_info(ngx_rtmp_kmp_publish_t *kp,

static void
ngx_rtmp_kmp_get_connect_info(ngx_rtmp_kmp_connect_t *kc,
ngx_rtmp_connect_t *v)
ngx_rtmp_connect_t *v, ngx_connection_t *c)
{
ngx_json_str_from_c(kc->app, v->app);
ngx_json_str_from_c(kc->args, v->args);
ngx_json_str_from_c(kc->flashver, v->flashver);
ngx_json_str_from_c(kc->swf_url, v->swf_url);
ngx_json_str_from_c(kc->tc_url, v->tc_url);
ngx_json_str_from_c(kc->page_url, v->page_url);
kc->addr.s.data = (c->proxy_protocol != NULL && c->proxy_protocol->src_addr.len > 0) ? c->proxy_protocol->src_addr.data : c->addr_text.data;
kc->addr.s.len = (c->proxy_protocol != NULL && c->proxy_protocol->src_addr.len > 0) ? c->proxy_protocol->src_addr.len : c->addr_text.len;
ngx_json_str_set_escape(&kc->addr);
}


Expand Down Expand Up @@ -546,7 +550,7 @@ ngx_rtmp_kmp_connect_create(void *arg, ngx_pool_t *pool, ngx_chain_t **body)

s = ctx->s;

ngx_rtmp_kmp_get_connect_info(&connect, &ctx->connect);
ngx_rtmp_kmp_get_connect_info(&connect, &ctx->connect, s->connection);

size = ngx_rtmp_kmp_connect_json_get_size(&connect, s);

Expand Down
Loading