From 3497601b6b691dec86c697a9955dd06a137501e3 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Sat, 1 Aug 2015 04:50:38 +0300 Subject: [PATCH] Upsate: - fix memory allocation for URL string - fix code pass in AMF --- ngx_rtmp_notify_module.c | 18 +++++++++++++++--- ngx_rtmp_send.c | 36 +++++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/ngx_rtmp_notify_module.c b/ngx_rtmp_notify_module.c index 2dddf3d..25975d6 100644 --- a/ngx_rtmp_notify_module.c +++ b/ngx_rtmp_notify_module.c @@ -1059,10 +1059,22 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, if (nacf->send_redirect) { // Send 302 redirect and go next - ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: send 302 redirect for stream '%s' to new location '%*s'", v->name, rc, name); - ngx_rtmp_send_redirect_status("Publish here", name); + local_name.data = ngx_palloc(s->connection->pool, rc); + local_name.len = rc; + *ngx_cpymem(local_name.data, name, rc) = 0; + + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, + "notify: check redirect to location: '%s'", local_name.data); + + ngx_rtmp_send_redirect_status(s, "Publish here", local_name); + + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, + "notify: release location memory"); + + ngx_pfree(s->connection->pool, local_name.data); goto next; @@ -1072,7 +1084,7 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, ngx_rtmp_notify_set_name(v->name, NGX_RTMP_MAX_NAME, name, (size_t) rc); } - ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: push '%s' to '%*s'", v->name, rc, name); local_name.data = v->name; diff --git a/ngx_rtmp_send.c b/ngx_rtmp_send.c index 25db6ed..f5011fb 100644 --- a/ngx_rtmp_send.c +++ b/ngx_rtmp_send.c @@ -491,7 +491,7 @@ ngx_rtmp_create_status(ngx_rtmp_session_t *s, char *code, char* level, NULL, 0 }, { NGX_RTMP_AMF_OBJECT, - ngx_null_string, + ngx_string("info"), out_inf, sizeof(out_inf) }, }; @@ -597,16 +597,24 @@ ngx_rtmp_send_play_status(ngx_rtmp_session_t *s, char *code, char* level, // ----------- Based on Adobe FMS 3 application.redirectConnection description --------- // ngx_chain_t * -ngx_rtmp_create_redirect_status(ngx_rtmp_session_t *s, char *desc, char *to_url) +ngx_rtmp_create_redirect_status(ngx_rtmp_session_t *s, char *desc, ngx_str_t to_url) { ngx_rtmp_header_t h; static double trans; + static double dcode; - static ngx_rtmp_amf_elt_t out_inf_ex[] = { + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, + "create redirect status: got data"); + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, + "create redirect status: status code='%s' level='%s' " + "ex.code=%ui ex.redirect='%s'", + "NetConnection.Connect.Rejected", "Error", 302, to_url.data); - { NGX_RTMP_AMF_STRING, + static ngx_rtmp_amf_elt_t out_inf_ex_data[] = { + + { NGX_RTMP_AMF_NUMBER, ngx_string("code"), - NULL, 0 }, + &dcode, 0 }, { NGX_RTMP_AMF_STRING, ngx_string("redirect"), @@ -629,8 +637,8 @@ ngx_rtmp_create_redirect_status(ngx_rtmp_session_t *s, char *desc, char *to_url) { NGX_RTMP_AMF_OBJECT, ngx_string("ex"), - out_inf_ex, - sizeof(out_inf_ex) }, + out_inf_ex_data, + sizeof(out_inf_ex_data) }, }; static ngx_rtmp_amf_elt_t out_elts[] = { @@ -648,21 +656,19 @@ ngx_rtmp_create_redirect_status(ngx_rtmp_session_t *s, char *desc, char *to_url) NULL, 0 }, { NGX_RTMP_AMF_OBJECT, - ngx_null_string, + ngx_string("info"), out_inf, sizeof(out_inf) }, }; - ngx_log_debug4(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "create: status code='%s' level='%s' " - "ex.code='%s' ex.redirect='%s'", - "NetConnection.Connect.Rejected", "Error", "302", to_url); + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, + "create redirect status: set structure data"); out_inf[0].data = "NetConnection.Connect.Rejected"; out_inf[1].data = "Error"; out_inf[2].data = desc; - out_inf_ex[0].data = "302"; - out_inf_ex[1].data = to_url; + dcode = 302; + out_inf_ex_data[1].data = to_url.data; memset(&h, 0, sizeof(h)); @@ -677,7 +683,7 @@ ngx_rtmp_create_redirect_status(ngx_rtmp_session_t *s, char *desc, char *to_url) ngx_int_t ngx_rtmp_send_redirect_status(ngx_rtmp_session_t *s, - char *desc, char *to_url) + char *desc, ngx_str_t to_url) { return ngx_rtmp_send_shared_packet(s, ngx_rtmp_create_redirect_status(s, desc, to_url));