From c39589c5ea2f5bf154b7b5a81e30e65213294b99 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Mon, 10 Aug 2015 22:36:43 +0300 Subject: [PATCH] Add first version of 4xx HTTP code handlers for nitify submodule --- ngx_rtmp_notify_module.c | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/ngx_rtmp_notify_module.c b/ngx_rtmp_notify_module.c index b519716..279ea07 100644 --- a/ngx_rtmp_notify_module.c +++ b/ngx_rtmp_notify_module.c @@ -860,6 +860,8 @@ ngx_rtmp_notify_parse_http_retcode(ngx_rtmp_session_t *s, return NGX_OK; case (u_char) '3': return NGX_AGAIN; + case (u_char) '4': + return NGX_DECLINED; default: return NGX_ERROR; } @@ -1005,10 +1007,31 @@ ngx_rtmp_notify_connect_handle(ngx_rtmp_session_t *s, static ngx_str_t location = ngx_string("location"); rc = ngx_rtmp_notify_parse_http_retcode(s, in); + + /* HTTP 5xx or unknown/unsupprted */ + if (rc == NGX_ERROR) { return NGX_ERROR; } + /* HTTP 4xx */ + + if (rc == NGX_DECLINED) { + + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, + "notify: connection denyed by callback return code 4xx"); + + ngx_rtmp_send_status("NetConnection.Connect.Rejected", "error", + "Cennection denyed by notify event handler and callback return code"); + + // Something by rtmpdump lib + send = ngx_rtmp_send_close_method(s, "close"); + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, + "notify: connect send(e) close method = '%ui'", send == NGX_OK); + + return NGX_ERROR; + } + if (rc != NGX_AGAIN) { goto next; } @@ -1116,11 +1139,34 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, static ngx_str_t location = ngx_string("location"); rc = ngx_rtmp_notify_parse_http_retcode(s, in); + + /* HTTP 5xx or unknown/unsupprted */ + if (rc == NGX_ERROR) { ngx_rtmp_notify_clear_flag(s, NGX_RTMP_NOTIFY_PUBLISHING); return NGX_ERROR; } + /* HTTP 4xx */ + + if (rc == NGX_DECLINED) { + + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, + "notify: publishing denyed by callback return code 4xx"); + + ngx_rtmp_send_status("NetConnection.Connect.Rejected", "error", + "Publishing denyed by notify event handler and callback return code"); + + ngx_rtmp_notify_clear_flag(s, NGX_RTMP_NOTIFY_PUBLISHING); + + // Something by rtmpdump lib + send = ngx_rtmp_send_close_method(s, "close"); + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, + "notify: connect send(e) close method = '%ui'", send == NGX_OK); + + return NGX_ERROR; + } + if (rc != NGX_AGAIN) { goto next; } @@ -1239,11 +1285,34 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, static ngx_str_t location = ngx_string("location"); rc = ngx_rtmp_notify_parse_http_retcode(s, in); + + /* HTTP 5xx or unknown/unsupprted */ + if (rc == NGX_ERROR) { ngx_rtmp_notify_clear_flag(s, NGX_RTMP_NOTIFY_PLAYING); return NGX_ERROR; } + /* HTTP 4xx */ + + if (rc == NGX_DECLINED) { + + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, + "notify: playing denyed by callback return code 4xx"); + + ngx_rtmp_send_status("NetConnection.Connect.Rejected", "error", + "Playing denyed by notify event handler and callback return code"); + + ngx_rtmp_notify_clear_flag(s, NGX_RTMP_NOTIFY_PLAYING); + + // Something by rtmpdump lib + send = ngx_rtmp_send_close_method(s, "close"); + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, + "notify: connect send(e) close method = '%ui'", send == NGX_OK); + + return NGX_ERROR; + } + if (rc != NGX_AGAIN) { goto next; }