From c39589c5ea2f5bf154b7b5a81e30e65213294b99 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Mon, 10 Aug 2015 22:36:43 +0300 Subject: [PATCH 1/2] 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; } From f0c9b595bc56e4c69748cd71cabc1169f41d7760 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Thu, 17 Sep 2015 12:57:33 +0300 Subject: [PATCH 2/2] Fix missing vars in func calls --- ngx_rtmp_notify_module.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ngx_rtmp_notify_module.c b/ngx_rtmp_notify_module.c index 279ea07..befab4a 100644 --- a/ngx_rtmp_notify_module.c +++ b/ngx_rtmp_notify_module.c @@ -1021,7 +1021,7 @@ ngx_rtmp_notify_connect_handle(ngx_rtmp_session_t *s, 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", + ngx_rtmp_send_status(s, "NetConnection.Connect.Rejected", "error", "Cennection denyed by notify event handler and callback return code"); // Something by rtmpdump lib @@ -1154,7 +1154,7 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, 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", + ngx_rtmp_send_status(s, "NetConnection.Connect.Rejected", "error", "Publishing denyed by notify event handler and callback return code"); ngx_rtmp_notify_clear_flag(s, NGX_RTMP_NOTIFY_PUBLISHING); @@ -1275,7 +1275,7 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, void *arg, ngx_chain_t *in) { ngx_rtmp_play_t *v = arg; - ngx_int_t rc; + ngx_int_t rc, send; ngx_str_t local_name; ngx_rtmp_relay_target_t target; ngx_url_t *u; @@ -1300,7 +1300,7 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, 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", + ngx_rtmp_send_status(s, "NetConnection.Connect.Rejected", "error", "Playing denyed by notify event handler and callback return code"); ngx_rtmp_notify_clear_flag(s, NGX_RTMP_NOTIFY_PLAYING);