Skip to content
This repository

A way to kill session #39

Closed
tumurzakov opened this Issue August 08, 2012 · 1 comment

2 participants

tumurzakov Roman Arutyunyan
tumurzakov

I needed a way to kill selected session.

I did it with following way:
I will allow connections to rtmp stream only with argument like
rtmp://[ip]/[app]/[stream]?ABCD
where ABCD is session hash, also i show this hash in stat page

If request to stat page consist argument that match sessions hash i will kill this session.

ngx_rtmp.h

typedef struct {
...
ngx_str_t               hash;
...
} ngx_rtmp_session_t;

ngx_rtmp_cmd_module.c

static ngx_int_t
ngx_rtmp_cmd_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
{
...
    if (ngx_strlen(v->args) > 0) {
        s->hash.len = ngx_strlen(v->args);
        s->hash.data = ngx_palloc(s->connection->pool, s->hash.len);
        ngx_memcpy(s->hash.data, v->args, s->hash.len);
    }
...
}

ngx_rtmp_stat_module.c

static void
ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
        ngx_rtmp_live_app_conf_t *lacf)
{
...
            for (ctx = stream->ctx; ctx; ctx = ctx->next, ++nclients) {
                s = ctx->session;
                if (slcf->stat & NGX_RTMP_STAT_CLIENTS) {
                    if (r->args.len && s->hash.len && r->args.len == s->hash.len) {
                        if (ngx_strncmp(s->hash.data, r->args.data, s->hash.len) == 0) {
                            ngx_rtmp_finalize_session(s);
                            continue;
                        }
                    }
                    ...
                    if (s->hash.len) {
                        NGX_RTMP_STAT_L("<hash>");
                        NGX_RTMP_STAT_ES(&s->hash);
                        NGX_RTMP_STAT_L("</hash>");
                    }

...
}

it is not better way to do this, but it works for me.
Can you look at this code and say is there any mistakes that could cause memory leaks?

Roman Arutyunyan
Owner

I've added new feature which can solve your probem
http://rarut.wordpress.com/2012/10/23/rtmp-client-dropper/

Roman Arutyunyan arut closed this November 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.