From 98d02febe28980387d35a3b0598e99b6ff6e101a Mon Sep 17 00:00:00 2001 From: Loic Baron Date: Fri, 10 Jun 2022 12:18:04 +0100 Subject: [PATCH 1/5] fix: add https for notify url --- ngx_rtmp_notify_module.c | 1286 ++++++++++++++++++++------------------ 1 file changed, 678 insertions(+), 608 deletions(-) diff --git a/ngx_rtmp_notify_module.c b/ngx_rtmp_notify_module.c index dd65e4991..3de37b602 100644 --- a/ngx_rtmp_notify_module.c +++ b/ngx_rtmp_notify_module.c @@ -3,7 +3,6 @@ * Copyright (C) Roman Arutyunyan */ - #include #include #include @@ -13,41 +12,37 @@ #include "ngx_rtmp_record_module.h" #include "ngx_rtmp_relay_module.h" - -static ngx_rtmp_connect_pt next_connect; -static ngx_rtmp_disconnect_pt next_disconnect; -static ngx_rtmp_publish_pt next_publish; -static ngx_rtmp_play_pt next_play; -static ngx_rtmp_close_stream_pt next_close_stream; -static ngx_rtmp_record_done_pt next_record_done; - +static ngx_rtmp_connect_pt next_connect; +static ngx_rtmp_disconnect_pt next_disconnect; +static ngx_rtmp_publish_pt next_publish; +static ngx_rtmp_play_pt next_play; +static ngx_rtmp_close_stream_pt next_close_stream; +static ngx_rtmp_record_done_pt next_record_done; static char *ngx_rtmp_notify_on_srv_event(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_rtmp_notify_on_app_event(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_rtmp_notify_method(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static ngx_int_t ngx_rtmp_notify_postconfiguration(ngx_conf_t *cf); -static void * ngx_rtmp_notify_create_app_conf(ngx_conf_t *cf); -static char * ngx_rtmp_notify_merge_app_conf(ngx_conf_t *cf, - void *parent, void *child); +static void *ngx_rtmp_notify_create_app_conf(ngx_conf_t *cf); +static char *ngx_rtmp_notify_merge_app_conf(ngx_conf_t *cf, + void *parent, void *child); static void *ngx_rtmp_notify_create_srv_conf(ngx_conf_t *cf); static char *ngx_rtmp_notify_merge_srv_conf(ngx_conf_t *cf, void *parent, - void *child); + void *child); static ngx_int_t ngx_rtmp_notify_done(ngx_rtmp_session_t *s, char *cbname, - ngx_uint_t url_idx); - - -ngx_str_t ngx_rtmp_notify_urlencoded = - ngx_string("application/x-www-form-urlencoded"); - + ngx_uint_t url_idx); -#define NGX_RTMP_NOTIFY_PUBLISHING 0x01 -#define NGX_RTMP_NOTIFY_PLAYING 0x02 +ngx_str_t ngx_rtmp_notify_urlencoded = + ngx_string("application/x-www-form-urlencoded"); +#define NGX_RTMP_NOTIFY_PUBLISHING 0x01 +#define NGX_RTMP_NOTIFY_PLAYING 0x02 -enum { +enum +{ NGX_RTMP_NOTIFY_PLAY, NGX_RTMP_NOTIFY_PUBLISH, NGX_RTMP_NOTIFY_PLAY_DONE, @@ -58,183 +53,179 @@ enum { NGX_RTMP_NOTIFY_APP_MAX }; - -enum { +enum +{ NGX_RTMP_NOTIFY_CONNECT, NGX_RTMP_NOTIFY_DISCONNECT, NGX_RTMP_NOTIFY_SRV_MAX }; - -typedef struct { - ngx_url_t *url[NGX_RTMP_NOTIFY_APP_MAX]; - ngx_flag_t active; - ngx_uint_t method; - ngx_msec_t update_timeout; - ngx_flag_t update_strict; - ngx_flag_t relay_redirect; +typedef struct +{ + ngx_url_t *url[NGX_RTMP_NOTIFY_APP_MAX]; + ngx_flag_t active; + ngx_uint_t method; + ngx_msec_t update_timeout; + ngx_flag_t update_strict; + ngx_flag_t relay_redirect; } ngx_rtmp_notify_app_conf_t; - -typedef struct { - ngx_url_t *url[NGX_RTMP_NOTIFY_SRV_MAX]; - ngx_uint_t method; +typedef struct +{ + ngx_url_t *url[NGX_RTMP_NOTIFY_SRV_MAX]; + ngx_uint_t method; } ngx_rtmp_notify_srv_conf_t; - -typedef struct { - ngx_uint_t flags; - u_char name[NGX_RTMP_MAX_NAME]; - u_char args[NGX_RTMP_MAX_ARGS]; - ngx_event_t update_evt; - time_t start; +typedef struct +{ + ngx_uint_t flags; + u_char name[NGX_RTMP_MAX_NAME]; + u_char args[NGX_RTMP_MAX_ARGS]; + ngx_event_t update_evt; + time_t start; } ngx_rtmp_notify_ctx_t; - -typedef struct { - u_char *cbname; - ngx_uint_t url_idx; +typedef struct +{ + u_char *cbname; + ngx_uint_t url_idx; } ngx_rtmp_notify_done_t; - -static ngx_command_t ngx_rtmp_notify_commands[] = { - - { ngx_string("on_connect"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_CONF_TAKE1, - ngx_rtmp_notify_on_srv_event, - NGX_RTMP_SRV_CONF_OFFSET, - 0, - NULL }, - - { ngx_string("on_disconnect"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_CONF_TAKE1, - ngx_rtmp_notify_on_srv_event, - NGX_RTMP_SRV_CONF_OFFSET, - 0, - NULL }, - - { ngx_string("on_publish"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL }, - - { ngx_string("on_play"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL }, - - { ngx_string("on_publish_done"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL }, - - { ngx_string("on_play_done"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL }, - - { ngx_string("on_done"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL }, - - { ngx_string("on_record_done"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_RTMP_REC_CONF| - NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL }, - - { ngx_string("on_update"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL }, - - { ngx_string("notify_method"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, - ngx_rtmp_notify_method, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL }, - - { ngx_string("notify_update_timeout"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, - ngx_conf_set_msec_slot, - NGX_RTMP_APP_CONF_OFFSET, - offsetof(ngx_rtmp_notify_app_conf_t, update_timeout), - NULL }, - - { ngx_string("notify_update_strict"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, - ngx_conf_set_flag_slot, - NGX_RTMP_APP_CONF_OFFSET, - offsetof(ngx_rtmp_notify_app_conf_t, update_strict), - NULL }, - - { ngx_string("notify_relay_redirect"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, - ngx_conf_set_flag_slot, - NGX_RTMP_APP_CONF_OFFSET, - offsetof(ngx_rtmp_notify_app_conf_t, relay_redirect), - NULL }, - - ngx_null_command +static ngx_command_t ngx_rtmp_notify_commands[] = { + + {ngx_string("on_connect"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_CONF_TAKE1, + ngx_rtmp_notify_on_srv_event, + NGX_RTMP_SRV_CONF_OFFSET, + 0, + NULL}, + + {ngx_string("on_disconnect"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_CONF_TAKE1, + ngx_rtmp_notify_on_srv_event, + NGX_RTMP_SRV_CONF_OFFSET, + 0, + NULL}, + + {ngx_string("on_publish"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL}, + + {ngx_string("on_play"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL}, + + {ngx_string("on_publish_done"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL}, + + {ngx_string("on_play_done"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL}, + + {ngx_string("on_done"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL}, + + {ngx_string("on_record_done"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_RTMP_REC_CONF | + NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL}, + + {ngx_string("on_update"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL}, + + {ngx_string("notify_method"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, + ngx_rtmp_notify_method, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL}, + + {ngx_string("notify_update_timeout"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, + ngx_conf_set_msec_slot, + NGX_RTMP_APP_CONF_OFFSET, + offsetof(ngx_rtmp_notify_app_conf_t, update_timeout), + NULL}, + + {ngx_string("notify_update_strict"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, + ngx_conf_set_flag_slot, + NGX_RTMP_APP_CONF_OFFSET, + offsetof(ngx_rtmp_notify_app_conf_t, update_strict), + NULL}, + + {ngx_string("notify_relay_redirect"), + NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, + ngx_conf_set_flag_slot, + NGX_RTMP_APP_CONF_OFFSET, + offsetof(ngx_rtmp_notify_app_conf_t, relay_redirect), + NULL}, + + ngx_null_command}; + +static ngx_rtmp_module_t ngx_rtmp_notify_module_ctx = { + NULL, /* preconfiguration */ + ngx_rtmp_notify_postconfiguration, /* postconfiguration */ + NULL, /* create main configuration */ + NULL, /* init main configuration */ + ngx_rtmp_notify_create_srv_conf, /* create server configuration */ + ngx_rtmp_notify_merge_srv_conf, /* merge server configuration */ + ngx_rtmp_notify_create_app_conf, /* create app configuration */ + ngx_rtmp_notify_merge_app_conf /* merge app configuration */ }; - -static ngx_rtmp_module_t ngx_rtmp_notify_module_ctx = { - NULL, /* preconfiguration */ - ngx_rtmp_notify_postconfiguration, /* postconfiguration */ - NULL, /* create main configuration */ - NULL, /* init main configuration */ - ngx_rtmp_notify_create_srv_conf, /* create server configuration */ - ngx_rtmp_notify_merge_srv_conf, /* merge server configuration */ - ngx_rtmp_notify_create_app_conf, /* create app configuration */ - ngx_rtmp_notify_merge_app_conf /* merge app configuration */ -}; - - -ngx_module_t ngx_rtmp_notify_module = { +ngx_module_t ngx_rtmp_notify_module = { NGX_MODULE_V1, - &ngx_rtmp_notify_module_ctx, /* module context */ - ngx_rtmp_notify_commands, /* module directives */ - NGX_RTMP_MODULE, /* module type */ - NULL, /* init master */ - NULL, /* init module */ - NULL, /* init process */ - NULL, /* init thread */ - NULL, /* exit thread */ - NULL, /* exit process */ - NULL, /* exit master */ - NGX_MODULE_V1_PADDING -}; - + &ngx_rtmp_notify_module_ctx, /* module context */ + ngx_rtmp_notify_commands, /* module directives */ + NGX_RTMP_MODULE, /* module type */ + NULL, /* init master */ + NULL, /* init module */ + NULL, /* init process */ + NULL, /* init thread */ + NULL, /* exit thread */ + NULL, /* exit process */ + NULL, /* exit master */ + NGX_MODULE_V1_PADDING}; static void * ngx_rtmp_notify_create_app_conf(ngx_conf_t *cf) { - ngx_rtmp_notify_app_conf_t *nacf; - ngx_uint_t n; + ngx_rtmp_notify_app_conf_t *nacf; + ngx_uint_t n; nacf = ngx_pcalloc(cf->pool, sizeof(ngx_rtmp_notify_app_conf_t)); - if (nacf == NULL) { + if (nacf == NULL) + { return NULL; } - for (n = 0; n < NGX_RTMP_NOTIFY_APP_MAX; ++n) { + for (n = 0; n < NGX_RTMP_NOTIFY_APP_MAX; ++n) + { nacf->url[n] = NGX_CONF_UNSET_PTR; } @@ -246,22 +237,24 @@ ngx_rtmp_notify_create_app_conf(ngx_conf_t *cf) return nacf; } - static char * ngx_rtmp_notify_merge_app_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_rtmp_notify_app_conf_t *prev = parent; ngx_rtmp_notify_app_conf_t *conf = child; - ngx_uint_t n; + ngx_uint_t n; - for (n = 0; n < NGX_RTMP_NOTIFY_APP_MAX; ++n) { + for (n = 0; n < NGX_RTMP_NOTIFY_APP_MAX; ++n) + { ngx_conf_merge_ptr_value(conf->url[n], prev->url[n], NULL); - if (conf->url[n]) { + if (conf->url[n]) + { conf->active = 1; } } - if (conf->active) { + if (conf->active) + { prev->active = 1; } @@ -275,19 +268,20 @@ ngx_rtmp_notify_merge_app_conf(ngx_conf_t *cf, void *parent, void *child) return NGX_CONF_OK; } - static void * ngx_rtmp_notify_create_srv_conf(ngx_conf_t *cf) { - ngx_rtmp_notify_srv_conf_t *nscf; - ngx_uint_t n; + ngx_rtmp_notify_srv_conf_t *nscf; + ngx_uint_t n; nscf = ngx_pcalloc(cf->pool, sizeof(ngx_rtmp_notify_srv_conf_t)); - if (nscf == NULL) { + if (nscf == NULL) + { return NULL; } - for (n = 0; n < NGX_RTMP_NOTIFY_SRV_MAX; ++n) { + for (n = 0; n < NGX_RTMP_NOTIFY_SRV_MAX; ++n) + { nscf->url[n] = NGX_CONF_UNSET_PTR; } @@ -296,15 +290,15 @@ ngx_rtmp_notify_create_srv_conf(ngx_conf_t *cf) return nscf; } - static char * ngx_rtmp_notify_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_rtmp_notify_srv_conf_t *prev = parent; ngx_rtmp_notify_srv_conf_t *conf = child; - ngx_uint_t n; + ngx_uint_t n; - for (n = 0; n < NGX_RTMP_NOTIFY_SRV_MAX; ++n) { + for (n = 0; n < NGX_RTMP_NOTIFY_SRV_MAX; ++n) + { ngx_conf_merge_ptr_value(conf->url[n], prev->url[n], NULL); } @@ -314,21 +308,21 @@ ngx_rtmp_notify_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) return NGX_CONF_OK; } - static ngx_chain_t * ngx_rtmp_notify_create_request(ngx_rtmp_session_t *s, ngx_pool_t *pool, - ngx_uint_t url_idx, ngx_chain_t *args) + ngx_uint_t url_idx, ngx_chain_t *args) { ngx_rtmp_notify_app_conf_t *nacf; - ngx_chain_t *al, *bl, *cl; - ngx_url_t *url; + ngx_chain_t *al, *bl, *cl; + ngx_url_t *url; nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); url = nacf->url[url_idx]; al = ngx_rtmp_netcall_http_format_session(s, pool); - if (al == NULL) { + if (al == NULL) + { return NULL; } @@ -336,7 +330,8 @@ ngx_rtmp_notify_create_request(ngx_rtmp_session_t *s, ngx_pool_t *pool, bl = NULL; - if (nacf->method == NGX_RTMP_NETCALL_HTTP_POST) { + if (nacf->method == NGX_RTMP_NETCALL_HTTP_POST) + { cl = al; al = bl; bl = cl; @@ -347,25 +342,25 @@ ngx_rtmp_notify_create_request(ngx_rtmp_session_t *s, ngx_pool_t *pool, &ngx_rtmp_notify_urlencoded); } - static ngx_chain_t * ngx_rtmp_notify_connect_create(ngx_rtmp_session_t *s, void *arg, - ngx_pool_t *pool) + ngx_pool_t *pool) { - ngx_rtmp_connect_t *v = arg; + ngx_rtmp_connect_t *v = arg; - ngx_rtmp_notify_srv_conf_t *nscf; - ngx_url_t *url; - ngx_chain_t *al, *bl; - ngx_buf_t *b; - ngx_str_t *addr_text; - size_t app_len, args_len, flashver_len, - swf_url_len, tc_url_len, page_url_len; + ngx_rtmp_notify_srv_conf_t *nscf; + ngx_url_t *url; + ngx_chain_t *al, *bl; + ngx_buf_t *b; + ngx_str_t *addr_text; + size_t app_len, args_len, flashver_len, + swf_url_len, tc_url_len, page_url_len; nscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_notify_module); al = ngx_alloc_chain_link(pool); - if (al == NULL) { + if (al == NULL) + { return NULL; } @@ -383,68 +378,70 @@ ngx_rtmp_notify_connect_create(ngx_rtmp_session_t *s, void *arg, addr_text = &s->connection->addr_text; b = ngx_create_temp_buf(pool, - sizeof("call=connect") - 1 + - sizeof("&app=") - 1 + app_len * 3 + - sizeof("&flashver=") - 1 + flashver_len * 3 + - sizeof("&swfurl=") - 1 + swf_url_len * 3 + - sizeof("&tcurl=") - 1 + tc_url_len * 3 + - sizeof("&pageurl=") - 1 + page_url_len * 3 + - sizeof("&addr=") - 1 + addr_text->len * 3 + - sizeof("&epoch=") - 1 + NGX_INT32_LEN + - 1 + args_len - ); - - if (b == NULL) { + sizeof("call=connect") - 1 + + sizeof("&app=") - 1 + app_len * 3 + + sizeof("&flashver=") - 1 + flashver_len * 3 + + sizeof("&swfurl=") - 1 + swf_url_len * 3 + + sizeof("&tcurl=") - 1 + tc_url_len * 3 + + sizeof("&pageurl=") - 1 + page_url_len * 3 + + sizeof("&addr=") - 1 + addr_text->len * 3 + + sizeof("&epoch=") - 1 + NGX_INT32_LEN + + 1 + args_len); + + if (b == NULL) + { return NULL; } al->buf = b; al->next = NULL; - b->last = ngx_cpymem(b->last, (u_char*) "app=", sizeof("app=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, v->app, app_len, + b->last = ngx_cpymem(b->last, (u_char *)"app=", sizeof("app=") - 1); + b->last = (u_char *)ngx_escape_uri(b->last, v->app, app_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char*) "&flashver=", + b->last = ngx_cpymem(b->last, (u_char *)"&flashver=", sizeof("&flashver=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, v->flashver, flashver_len, + b->last = (u_char *)ngx_escape_uri(b->last, v->flashver, flashver_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char*) "&swfurl=", + b->last = ngx_cpymem(b->last, (u_char *)"&swfurl=", sizeof("&swfurl=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, v->swf_url, swf_url_len, + b->last = (u_char *)ngx_escape_uri(b->last, v->swf_url, swf_url_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char*) "&tcurl=", + b->last = ngx_cpymem(b->last, (u_char *)"&tcurl=", sizeof("&tcurl=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, v->tc_url, tc_url_len, + b->last = (u_char *)ngx_escape_uri(b->last, v->tc_url, tc_url_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char*) "&pageurl=", + b->last = ngx_cpymem(b->last, (u_char *)"&pageurl=", sizeof("&pageurl=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, v->page_url, page_url_len, + b->last = (u_char *)ngx_escape_uri(b->last, v->page_url, page_url_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char*) "&addr=", sizeof("&addr=") -1); - b->last = (u_char*) ngx_escape_uri(b->last, addr_text->data, + b->last = ngx_cpymem(b->last, (u_char *)"&addr=", sizeof("&addr=") - 1); + b->last = (u_char *)ngx_escape_uri(b->last, addr_text->data, addr_text->len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char*) "&epoch=", sizeof("&epoch=") -1); - b->last = ngx_sprintf(b->last, "%uD", (uint32_t) s->epoch); + b->last = ngx_cpymem(b->last, (u_char *)"&epoch=", sizeof("&epoch=") - 1); + b->last = ngx_sprintf(b->last, "%uD", (uint32_t)s->epoch); - b->last = ngx_cpymem(b->last, (u_char*) "&call=connect", + b->last = ngx_cpymem(b->last, (u_char *)"&call=connect", sizeof("&call=connect") - 1); - if (args_len) { + if (args_len) + { *b->last++ = '&'; - b->last = (u_char *) ngx_cpymem(b->last, v->args, args_len); + b->last = (u_char *)ngx_cpymem(b->last, v->args, args_len); } url = nscf->url[NGX_RTMP_NOTIFY_CONNECT]; bl = NULL; - if (nscf->method == NGX_RTMP_NETCALL_HTTP_POST) { + if (nscf->method == NGX_RTMP_NETCALL_HTTP_POST) + { bl = al; al = NULL; } @@ -454,50 +451,53 @@ ngx_rtmp_notify_connect_create(ngx_rtmp_session_t *s, void *arg, &ngx_rtmp_notify_urlencoded); } - static ngx_chain_t * ngx_rtmp_notify_disconnect_create(ngx_rtmp_session_t *s, void *arg, - ngx_pool_t *pool) + ngx_pool_t *pool) { - ngx_rtmp_notify_srv_conf_t *nscf; - ngx_url_t *url; - ngx_chain_t *al, *bl, *pl; - ngx_buf_t *b; + ngx_rtmp_notify_srv_conf_t *nscf; + ngx_url_t *url; + ngx_chain_t *al, *bl, *pl; + ngx_buf_t *b; nscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_notify_module); pl = ngx_alloc_chain_link(pool); - if (pl == NULL) { + if (pl == NULL) + { return NULL; } b = ngx_create_temp_buf(pool, sizeof("&call=disconnect") + - sizeof("&app=") + s->app.len * 3 + - 1 + s->args.len); - if (b == NULL) { + sizeof("&app=") + s->app.len * 3 + + 1 + s->args.len); + if (b == NULL) + { return NULL; } pl->buf = b; pl->next = NULL; - b->last = ngx_cpymem(b->last, (u_char*) "&call=disconnect", + b->last = ngx_cpymem(b->last, (u_char *)"&call=disconnect", sizeof("&call=disconnect") - 1); - b->last = ngx_cpymem(b->last, (u_char*) "&app=", sizeof("&app=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, s->app.data, s->app.len, + b->last = ngx_cpymem(b->last, (u_char *)"&app=", sizeof("&app=") - 1); + b->last = (u_char *)ngx_escape_uri(b->last, s->app.data, s->app.len, NGX_ESCAPE_ARGS); - if (s->args.len) { + if (s->args.len) + { *b->last++ = '&'; - b->last = (u_char *) ngx_cpymem(b->last, s->args.data, s->args.len); + b->last = (u_char *)ngx_cpymem(b->last, s->args.data, s->args.len); } url = nscf->url[NGX_RTMP_NOTIFY_DISCONNECT]; al = ngx_rtmp_netcall_http_format_session(s, pool); - if (al == NULL) { + if (al == NULL) + { return NULL; } @@ -505,7 +505,8 @@ ngx_rtmp_notify_disconnect_create(ngx_rtmp_session_t *s, void *arg, bl = NULL; - if (nscf->method == NGX_RTMP_NETCALL_HTTP_POST) { + if (nscf->method == NGX_RTMP_NETCALL_HTTP_POST) + { bl = al; al = NULL; } @@ -515,19 +516,19 @@ ngx_rtmp_notify_disconnect_create(ngx_rtmp_session_t *s, void *arg, &ngx_rtmp_notify_urlencoded); } - static ngx_chain_t * ngx_rtmp_notify_publish_create(ngx_rtmp_session_t *s, void *arg, - ngx_pool_t *pool) + ngx_pool_t *pool) { - ngx_rtmp_publish_t *v = arg; + ngx_rtmp_publish_t *v = arg; - ngx_chain_t *pl; - ngx_buf_t *b; - size_t name_len, type_len, args_len; + ngx_chain_t *pl; + ngx_buf_t *b; + size_t name_len, type_len, args_len; pl = ngx_alloc_chain_link(pool); - if (pl == NULL) { + if (pl == NULL) + { return NULL; } @@ -537,48 +538,50 @@ ngx_rtmp_notify_publish_create(ngx_rtmp_session_t *s, void *arg, b = ngx_create_temp_buf(pool, sizeof("&call=publish") + - sizeof("&name=") + name_len * 3 + - sizeof("&type=") + type_len * 3 + - 1 + args_len); - if (b == NULL) { + sizeof("&name=") + name_len * 3 + + sizeof("&type=") + type_len * 3 + + 1 + args_len); + if (b == NULL) + { return NULL; } pl->buf = b; pl->next = NULL; - b->last = ngx_cpymem(b->last, (u_char*) "&call=publish", + b->last = ngx_cpymem(b->last, (u_char *)"&call=publish", sizeof("&call=publish") - 1); - b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, v->name, name_len, + b->last = ngx_cpymem(b->last, (u_char *)"&name=", sizeof("&name=") - 1); + b->last = (u_char *)ngx_escape_uri(b->last, v->name, name_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char*) "&type=", sizeof("&type=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, v->type, type_len, + b->last = ngx_cpymem(b->last, (u_char *)"&type=", sizeof("&type=") - 1); + b->last = (u_char *)ngx_escape_uri(b->last, v->type, type_len, NGX_ESCAPE_ARGS); - if (args_len) { + if (args_len) + { *b->last++ = '&'; - b->last = (u_char *) ngx_cpymem(b->last, v->args, args_len); + b->last = (u_char *)ngx_cpymem(b->last, v->args, args_len); } return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_PUBLISH, pl); } - static ngx_chain_t * ngx_rtmp_notify_play_create(ngx_rtmp_session_t *s, void *arg, - ngx_pool_t *pool) + ngx_pool_t *pool) { - ngx_rtmp_play_t *v = arg; + ngx_rtmp_play_t *v = arg; - ngx_chain_t *pl; - ngx_buf_t *b; - size_t name_len, args_len; + ngx_chain_t *pl; + ngx_buf_t *b; + size_t name_len, args_len; pl = ngx_alloc_chain_link(pool); - if (pl == NULL) { + if (pl == NULL) + { return NULL; } @@ -587,52 +590,54 @@ ngx_rtmp_notify_play_create(ngx_rtmp_session_t *s, void *arg, b = ngx_create_temp_buf(pool, sizeof("&call=play") + - sizeof("&name=") + name_len * 3 + - sizeof("&start=&duration=&reset=") + - NGX_INT32_LEN * 3 + 1 + args_len); - if (b == NULL) { + sizeof("&name=") + name_len * 3 + + sizeof("&start=&duration=&reset=") + + NGX_INT32_LEN * 3 + 1 + args_len); + if (b == NULL) + { return NULL; } pl->buf = b; pl->next = NULL; - b->last = ngx_cpymem(b->last, (u_char*) "&call=play", + b->last = ngx_cpymem(b->last, (u_char *)"&call=play", sizeof("&call=play") - 1); - b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, v->name, name_len, + b->last = ngx_cpymem(b->last, (u_char *)"&name=", sizeof("&name=") - 1); + b->last = (u_char *)ngx_escape_uri(b->last, v->name, name_len, NGX_ESCAPE_ARGS); b->last = ngx_snprintf(b->last, b->end - b->last, "&start=%uD&duration=%uD&reset=%d", - (uint32_t) v->start, (uint32_t) v->duration, + (uint32_t)v->start, (uint32_t)v->duration, v->reset & 1); - if (args_len) { + if (args_len) + { *b->last++ = '&'; - b->last = (u_char *) ngx_cpymem(b->last, v->args, args_len); + b->last = (u_char *)ngx_cpymem(b->last, v->args, args_len); } return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_PLAY, pl); } - static ngx_chain_t * ngx_rtmp_notify_done_create(ngx_rtmp_session_t *s, void *arg, - ngx_pool_t *pool) + ngx_pool_t *pool) { - ngx_rtmp_notify_done_t *ds = arg; + ngx_rtmp_notify_done_t *ds = arg; - ngx_chain_t *pl; - ngx_buf_t *b; - size_t cbname_len, name_len, args_len; - ngx_rtmp_notify_ctx_t *ctx; + ngx_chain_t *pl; + ngx_buf_t *b; + size_t cbname_len, name_len, args_len; + ngx_rtmp_notify_ctx_t *ctx; ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module); pl = ngx_alloc_chain_link(pool); - if (pl == NULL) { + if (pl == NULL) + { return NULL; } @@ -642,55 +647,63 @@ ngx_rtmp_notify_done_create(ngx_rtmp_session_t *s, void *arg, b = ngx_create_temp_buf(pool, sizeof("&call=") + cbname_len + - sizeof("&name=") + name_len * 3 + - 1 + args_len); - if (b == NULL) { + sizeof("&name=") + name_len * 3 + + 1 + args_len); + if (b == NULL) + { return NULL; } pl->buf = b; pl->next = NULL; - b->last = ngx_cpymem(b->last, (u_char*) "&call=", sizeof("&call=") - 1); + b->last = ngx_cpymem(b->last, (u_char *)"&call=", sizeof("&call=") - 1); b->last = ngx_cpymem(b->last, ds->cbname, cbname_len); - if (name_len) { - b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, ctx->name, name_len, + if (name_len) + { + b->last = ngx_cpymem(b->last, (u_char *)"&name=", sizeof("&name=") - 1); + b->last = (u_char *)ngx_escape_uri(b->last, ctx->name, name_len, NGX_ESCAPE_ARGS); } - if (args_len) { + if (args_len) + { *b->last++ = '&'; - b->last = (u_char *) ngx_cpymem(b->last, ctx->args, args_len); + b->last = (u_char *)ngx_cpymem(b->last, ctx->args, args_len); } return ngx_rtmp_notify_create_request(s, pool, ds->url_idx, pl); } - static ngx_chain_t * ngx_rtmp_notify_update_create(ngx_rtmp_session_t *s, void *arg, - ngx_pool_t *pool) + ngx_pool_t *pool) { - ngx_chain_t *pl; - ngx_buf_t *b; - size_t name_len, args_len; - ngx_rtmp_notify_ctx_t *ctx; - ngx_str_t sfx; + ngx_chain_t *pl; + ngx_buf_t *b; + size_t name_len, args_len; + ngx_rtmp_notify_ctx_t *ctx; + ngx_str_t sfx; ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module); pl = ngx_alloc_chain_link(pool); - if (pl == NULL) { + if (pl == NULL) + { return NULL; } - if (ctx->flags & NGX_RTMP_NOTIFY_PUBLISHING) { + if (ctx->flags & NGX_RTMP_NOTIFY_PUBLISHING) + { ngx_str_set(&sfx, "_publish"); - } else if (ctx->flags & NGX_RTMP_NOTIFY_PLAYING) { + } + else if (ctx->flags & NGX_RTMP_NOTIFY_PLAYING) + { ngx_str_set(&sfx, "_play"); - } else { + } + else + { ngx_str_null(&sfx); } @@ -699,134 +712,142 @@ ngx_rtmp_notify_update_create(ngx_rtmp_session_t *s, void *arg, b = ngx_create_temp_buf(pool, sizeof("&call=update") + sfx.len + - sizeof("&time=") + NGX_TIME_T_LEN + - sizeof("×tamp=") + NGX_INT32_LEN + - sizeof("&name=") + name_len * 3 + - 1 + args_len); - if (b == NULL) { + sizeof("&time=") + NGX_TIME_T_LEN + + sizeof("×tamp=") + NGX_INT32_LEN + + sizeof("&name=") + name_len * 3 + + 1 + args_len); + if (b == NULL) + { return NULL; } pl->buf = b; pl->next = NULL; - b->last = ngx_cpymem(b->last, (u_char*) "&call=update", + b->last = ngx_cpymem(b->last, (u_char *)"&call=update", sizeof("&call=update") - 1); b->last = ngx_cpymem(b->last, sfx.data, sfx.len); - b->last = ngx_cpymem(b->last, (u_char *) "&time=", + b->last = ngx_cpymem(b->last, (u_char *)"&time=", sizeof("&time=") - 1); b->last = ngx_sprintf(b->last, "%T", ngx_cached_time->sec - ctx->start); - b->last = ngx_cpymem(b->last, (u_char *) "×tamp=", + b->last = ngx_cpymem(b->last, (u_char *)"×tamp=", sizeof("×tamp=") - 1); b->last = ngx_sprintf(b->last, "%D", s->current_time); - if (name_len) { - b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, ctx->name, name_len, + if (name_len) + { + b->last = ngx_cpymem(b->last, (u_char *)"&name=", sizeof("&name=") - 1); + b->last = (u_char *)ngx_escape_uri(b->last, ctx->name, name_len, NGX_ESCAPE_ARGS); } - if (args_len) { + if (args_len) + { *b->last++ = '&'; - b->last = (u_char *) ngx_cpymem(b->last, ctx->args, args_len); + b->last = (u_char *)ngx_cpymem(b->last, ctx->args, args_len); } return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_UPDATE, pl); } - static ngx_chain_t * ngx_rtmp_notify_record_done_create(ngx_rtmp_session_t *s, void *arg, ngx_pool_t *pool) { - ngx_rtmp_record_done_t *v = arg; + ngx_rtmp_record_done_t *v = arg; - ngx_rtmp_notify_ctx_t *ctx; - ngx_chain_t *pl; - ngx_buf_t *b; - size_t name_len, args_len; + ngx_rtmp_notify_ctx_t *ctx; + ngx_chain_t *pl; + ngx_buf_t *b; + size_t name_len, args_len; ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module); pl = ngx_alloc_chain_link(pool); - if (pl == NULL) { + if (pl == NULL) + { return NULL; } - name_len = ngx_strlen(ctx->name); - args_len = ngx_strlen(ctx->args); + name_len = ngx_strlen(ctx->name); + args_len = ngx_strlen(ctx->args); b = ngx_create_temp_buf(pool, sizeof("&call=record_done") + - sizeof("&recorder=") + v->recorder.len + - sizeof("&name=") + name_len * 3 + - sizeof("&path=") + v->path.len * 3 + - 1 + args_len); - if (b == NULL) { + sizeof("&recorder=") + v->recorder.len + + sizeof("&name=") + name_len * 3 + + sizeof("&path=") + v->path.len * 3 + + 1 + args_len); + if (b == NULL) + { return NULL; } pl->buf = b; pl->next = NULL; - b->last = ngx_cpymem(b->last, (u_char*) "&call=record_done", + b->last = ngx_cpymem(b->last, (u_char *)"&call=record_done", sizeof("&call=record_done") - 1); - b->last = ngx_cpymem(b->last, (u_char *) "&recorder=", + b->last = ngx_cpymem(b->last, (u_char *)"&recorder=", sizeof("&recorder=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, v->recorder.data, + b->last = (u_char *)ngx_escape_uri(b->last, v->recorder.data, v->recorder.len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, ctx->name, name_len, + b->last = ngx_cpymem(b->last, (u_char *)"&name=", sizeof("&name=") - 1); + b->last = (u_char *)ngx_escape_uri(b->last, ctx->name, name_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char*) "&path=", sizeof("&path=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, v->path.data, v->path.len, + b->last = ngx_cpymem(b->last, (u_char *)"&path=", sizeof("&path=") - 1); + b->last = (u_char *)ngx_escape_uri(b->last, v->path.data, v->path.len, NGX_ESCAPE_ARGS); - if (args_len) { + if (args_len) + { *b->last++ = '&'; - b->last = (u_char *) ngx_cpymem(b->last, ctx->args, args_len); + b->last = (u_char *)ngx_cpymem(b->last, ctx->args, args_len); } return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_RECORD_DONE, pl); } - static ngx_int_t ngx_rtmp_notify_parse_http_retcode(ngx_rtmp_session_t *s, - ngx_chain_t *in) + ngx_chain_t *in) { - ngx_buf_t *b; - ngx_int_t n; - u_char c; + ngx_buf_t *b; + ngx_int_t n; + u_char c; /* find 10th character */ n = 9; - while (in) { + while (in) + { b = in->buf; - if (b->last - b->pos > n) { + if (b->last - b->pos > n) + { c = b->pos[n]; - if (c >= (u_char)'0' && c <= (u_char)'9') { + if (c >= (u_char)'0' && c <= (u_char)'9') + { ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "notify: HTTP retcode: %dxx", (int)(c - '0')); - switch (c) { - case (u_char) '2': - return NGX_OK; - case (u_char) '3': - return NGX_AGAIN; - default: - return NGX_ERROR; + "notify: HTTP retcode: %dxx", (int)(c - '0')); + switch (c) + { + case (u_char)'2': + return NGX_OK; + case (u_char)'3': + return NGX_AGAIN; + default: + return NGX_ERROR; } } ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, - "notify: invalid HTTP retcode: %d..", (int)c); + "notify: invalid HTTP retcode: %d..", (int)c); return NGX_ERROR; } @@ -835,7 +856,7 @@ ngx_rtmp_notify_parse_http_retcode(ngx_rtmp_session_t *s, } ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, - "notify: empty or broken HTTP response"); + "notify: empty or broken HTTP response"); /* * not enough data; @@ -845,17 +866,17 @@ ngx_rtmp_notify_parse_http_retcode(ngx_rtmp_session_t *s, return NGX_ERROR; } - static ngx_int_t ngx_rtmp_notify_parse_http_header(ngx_rtmp_session_t *s, - ngx_chain_t *in, ngx_str_t *name, u_char *data, size_t len) + ngx_chain_t *in, ngx_str_t *name, u_char *data, size_t len) { - ngx_buf_t *b; - ngx_int_t matched; - u_char *p, c; - ngx_uint_t n; + ngx_buf_t *b; + ngx_int_t matched; + u_char *p, c; + ngx_uint_t n; - enum { + enum + { parse_name, parse_space, parse_value, @@ -865,74 +886,85 @@ ngx_rtmp_notify_parse_http_header(ngx_rtmp_session_t *s, n = 0; matched = 0; - while (in) { + while (in) + { b = in->buf; - for (p = b->pos; p != b->last; ++p) { + for (p = b->pos; p != b->last; ++p) + { c = *p; - if (c == '\r') { + if (c == '\r') + { continue; } - switch (state) { - case parse_value_newline: - if (c == ' ' || c == '\t') { - state = parse_space; - break; - } + switch (state) + { + case parse_value_newline: + if (c == ' ' || c == '\t') + { + state = parse_space; + break; + } - if (matched) { - return n; - } + if (matched) + { + return n; + } - if (c == '\n') { - return NGX_OK; - } + if (c == '\n') + { + return NGX_OK; + } + + n = 0; + state = parse_name; + /* fall through */ + case parse_name: + switch (c) + { + case ':': + matched = (n == name->len); n = 0; - state = parse_name; - /* fall through */ - - case parse_name: - switch (c) { - case ':': - matched = (n == name->len); - n = 0; - state = parse_space; - break; - case '\n': - n = 0; - break; - default: - if (n < name->len && - ngx_tolower(c) == ngx_tolower(name->data[n])) - { - ++n; - break; - } - n = name->len + 1; - } + state = parse_space; break; - - case parse_space: - if (c == ' ' || c == '\t') { - break; - } - state = parse_value; - /* fall through */ - - case parse_value: - if (c == '\n') { - state = parse_value_newline; + case '\n': + n = 0; + break; + default: + if (n < name->len && + ngx_tolower(c) == ngx_tolower(name->data[n])) + { + ++n; break; } + n = name->len + 1; + } + break; - if (matched && n + 1 < len) { - data[n++] = c; - } + case parse_space: + if (c == ' ' || c == '\t') + { + break; + } + state = parse_value; + /* fall through */ + case parse_value: + if (c == '\n') + { + state = parse_value_newline; break; + } + + if (matched && n + 1 < len) + { + data[n++] = c; + } + + break; } } @@ -942,40 +974,41 @@ ngx_rtmp_notify_parse_http_header(ngx_rtmp_session_t *s, return NGX_OK; } - static void ngx_rtmp_notify_clear_flag(ngx_rtmp_session_t *s, ngx_uint_t flag) { - ngx_rtmp_notify_ctx_t *ctx; + ngx_rtmp_notify_ctx_t *ctx; ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module); ctx->flags &= ~flag; } - static ngx_int_t ngx_rtmp_notify_connect_handle(ngx_rtmp_session_t *s, - void *arg, ngx_chain_t *in) + void *arg, ngx_chain_t *in) { ngx_rtmp_connect_t *v = arg; - ngx_int_t rc; - u_char app[NGX_RTMP_MAX_NAME]; + ngx_int_t rc; + u_char app[NGX_RTMP_MAX_NAME]; - static ngx_str_t location = ngx_string("location"); + static ngx_str_t location = ngx_string("location"); rc = ngx_rtmp_notify_parse_http_retcode(s, in); - if (rc == NGX_ERROR) { + if (rc == NGX_ERROR) + { return NGX_ERROR; } - if (rc == NGX_AGAIN) { + if (rc == NGX_AGAIN) + { ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, "notify: connect redirect received"); rc = ngx_rtmp_notify_parse_http_header(s, in, &location, app, sizeof(app) - 1); - if (rc > 0) { + if (rc > 0) + { *ngx_cpymem(v->app, app, rc) = 0; ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: connect redirect to '%s'", v->app); @@ -985,13 +1018,12 @@ ngx_rtmp_notify_connect_handle(ngx_rtmp_session_t *s, return next_connect(s, v); } - static void ngx_rtmp_notify_set_name(u_char *dst, size_t dst_len, u_char *src, - size_t src_len) + size_t src_len) { - u_char result[16], *p; - ngx_md5_t md5; + u_char result[16], *p; + ngx_md5_t md5; ngx_md5_init(&md5); ngx_md5_update(&md5, src, src_len); @@ -1001,28 +1033,29 @@ ngx_rtmp_notify_set_name(u_char *dst, size_t dst_len, u_char *src, *p = '\0'; } - static ngx_int_t ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, - void *arg, ngx_chain_t *in) + void *arg, ngx_chain_t *in) { - ngx_rtmp_publish_t *v = arg; - ngx_int_t rc; - ngx_str_t local_name; - ngx_rtmp_relay_target_t target; - ngx_url_t *u; + ngx_rtmp_publish_t *v = arg; + ngx_int_t rc; + ngx_str_t local_name; + ngx_rtmp_relay_target_t target; + ngx_url_t *u; ngx_rtmp_notify_app_conf_t *nacf; - u_char name[NGX_RTMP_MAX_NAME]; + u_char name[NGX_RTMP_MAX_NAME]; - static ngx_str_t location = ngx_string("location"); + static ngx_str_t location = ngx_string("location"); rc = ngx_rtmp_notify_parse_http_retcode(s, in); - if (rc == NGX_ERROR) { + if (rc == NGX_ERROR) + { ngx_rtmp_notify_clear_flag(s, NGX_RTMP_NOTIFY_PUBLISHING); return NGX_ERROR; } - if (rc != NGX_AGAIN) { + if (rc != NGX_AGAIN) + { goto next; } @@ -1033,11 +1066,13 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, rc = ngx_rtmp_notify_parse_http_header(s, in, &location, name, sizeof(name) - 1); - if (rc <= 0) { + if (rc <= 0) + { goto next; } - if (ngx_strncasecmp(name, (u_char *) "rtmp://", 7)) { + if (ngx_strncasecmp(name, (u_char *)"rtmp://", 7)) + { *ngx_cpymem(v->name, name, rc) = 0; ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: publish redirect to '%s'", v->name); @@ -1047,8 +1082,9 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, /* push */ nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (nacf->relay_redirect) { - ngx_rtmp_notify_set_name(v->name, NGX_RTMP_MAX_NAME, name, (size_t) rc); + if (nacf->relay_redirect) + { + 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, @@ -1067,7 +1103,8 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, u->uri_part = 1; u->no_resolve = 1; /* want ip here */ - if (ngx_parse_url(s->connection->pool, u) != NGX_OK) { + if (ngx_parse_url(s->connection->pool, u) != NGX_OK) + { ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: push failed '%V'", &local_name); return NGX_ERROR; @@ -1080,28 +1117,29 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, return next_publish(s, v); } - static ngx_int_t ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, - void *arg, ngx_chain_t *in) + void *arg, ngx_chain_t *in) { - ngx_rtmp_play_t *v = arg; - ngx_int_t rc; - ngx_str_t local_name; - ngx_rtmp_relay_target_t target; - ngx_url_t *u; + ngx_rtmp_play_t *v = arg; + ngx_int_t rc; + ngx_str_t local_name; + ngx_rtmp_relay_target_t target; + ngx_url_t *u; ngx_rtmp_notify_app_conf_t *nacf; - u_char name[NGX_RTMP_MAX_NAME]; + u_char name[NGX_RTMP_MAX_NAME]; - static ngx_str_t location = ngx_string("location"); + static ngx_str_t location = ngx_string("location"); rc = ngx_rtmp_notify_parse_http_retcode(s, in); - if (rc == NGX_ERROR) { + if (rc == NGX_ERROR) + { ngx_rtmp_notify_clear_flag(s, NGX_RTMP_NOTIFY_PLAYING); return NGX_ERROR; } - if (rc != NGX_AGAIN) { + if (rc != NGX_AGAIN) + { goto next; } @@ -1112,11 +1150,13 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, rc = ngx_rtmp_notify_parse_http_header(s, in, &location, name, sizeof(name) - 1); - if (rc <= 0) { + if (rc <= 0) + { goto next; } - if (ngx_strncasecmp(name, (u_char *) "rtmp://", 7)) { + if (ngx_strncasecmp(name, (u_char *)"rtmp://", 7)) + { *ngx_cpymem(v->name, name, rc) = 0; ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: play redirect to '%s'", v->name); @@ -1126,8 +1166,9 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, /* pull */ nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (nacf->relay_redirect) { - ngx_rtmp_notify_set_name(v->name, NGX_RTMP_MAX_NAME, name, (size_t) rc); + if (nacf->relay_redirect) + { + ngx_rtmp_notify_set_name(v->name, NGX_RTMP_MAX_NAME, name, (size_t)rc); } ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, @@ -1146,7 +1187,8 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, u->uri_part = 1; u->no_resolve = 1; /* want ip here */ - if (ngx_parse_url(s->connection->pool, u) != NGX_OK) { + if (ngx_parse_url(s->connection->pool, u) != NGX_OK) + { ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: pull failed '%V'", &local_name); return NGX_ERROR; @@ -1159,21 +1201,20 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, return next_play(s, v); } - static ngx_int_t ngx_rtmp_notify_update_handle(ngx_rtmp_session_t *s, - void *arg, ngx_chain_t *in) + void *arg, ngx_chain_t *in) { ngx_rtmp_notify_app_conf_t *nacf; - ngx_rtmp_notify_ctx_t *ctx; - ngx_int_t rc; + ngx_rtmp_notify_ctx_t *ctx; + ngx_int_t rc; nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); rc = ngx_rtmp_notify_parse_http_retcode(s, in); if ((!nacf->update_strict && rc == NGX_ERROR) || - (nacf->update_strict && rc != NGX_OK)) + (nacf->update_strict && rc != NGX_OK)) { ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: update failed"); @@ -1192,15 +1233,14 @@ ngx_rtmp_notify_update_handle(ngx_rtmp_session_t *s, return NGX_OK; } - static void ngx_rtmp_notify_update(ngx_event_t *e) { - ngx_connection_t *c; - ngx_rtmp_session_t *s; + ngx_connection_t *c; + ngx_rtmp_session_t *s; ngx_rtmp_notify_app_conf_t *nacf; - ngx_rtmp_netcall_init_t ci; - ngx_url_t *url; + ngx_rtmp_netcall_init_t ci; + ngx_url_t *url; c = e->data; s = c->data; @@ -1218,7 +1258,8 @@ ngx_rtmp_notify_update(ngx_event_t *e) ci.create = ngx_rtmp_notify_update_create; ci.handle = ngx_rtmp_notify_update_handle; - if (ngx_rtmp_netcall_create(s, &ci) == NGX_OK) { + if (ngx_rtmp_netcall_create(s, &ci) == NGX_OK) + { return; } @@ -1227,26 +1268,28 @@ ngx_rtmp_notify_update(ngx_event_t *e) ngx_rtmp_notify_update_handle(s, NULL, NULL); } - static void ngx_rtmp_notify_init(ngx_rtmp_session_t *s, - u_char name[NGX_RTMP_MAX_NAME], u_char args[NGX_RTMP_MAX_ARGS], - ngx_uint_t flags) + u_char name[NGX_RTMP_MAX_NAME], u_char args[NGX_RTMP_MAX_ARGS], + ngx_uint_t flags) { - ngx_rtmp_notify_ctx_t *ctx; - ngx_rtmp_notify_app_conf_t *nacf; - ngx_event_t *e; + ngx_rtmp_notify_ctx_t *ctx; + ngx_rtmp_notify_app_conf_t *nacf; + ngx_event_t *e; nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (!nacf->active) { + if (!nacf->active) + { return; } ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module); - if (ctx == NULL) { + if (ctx == NULL) + { ctx = ngx_pcalloc(s->connection->pool, sizeof(ngx_rtmp_notify_ctx_t)); - if (ctx == NULL) { + if (ctx == NULL) + { return; } @@ -1264,7 +1307,8 @@ ngx_rtmp_notify_init(ngx_rtmp_session_t *s, return; } - if (ctx->update_evt.timer_set) { + if (ctx->update_evt.timer_set) + { return; } @@ -1283,22 +1327,23 @@ ngx_rtmp_notify_init(ngx_rtmp_session_t *s, nacf->update_timeout); } - static ngx_int_t ngx_rtmp_notify_connect(ngx_rtmp_session_t *s, ngx_rtmp_connect_t *v) { - ngx_rtmp_notify_srv_conf_t *nscf; - ngx_rtmp_netcall_init_t ci; - ngx_url_t *url; + ngx_rtmp_notify_srv_conf_t *nscf; + ngx_rtmp_netcall_init_t ci; + ngx_url_t *url; - if (s->auto_pushed || s->relay) { + if (s->auto_pushed || s->relay) + { goto next; } nscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_notify_module); url = nscf->url[NGX_RTMP_NOTIFY_CONNECT]; - if (url == NULL) { + if (url == NULL) + { goto next; } @@ -1319,22 +1364,23 @@ ngx_rtmp_notify_connect(ngx_rtmp_session_t *s, ngx_rtmp_connect_t *v) return next_connect(s, v); } - static ngx_int_t ngx_rtmp_notify_disconnect(ngx_rtmp_session_t *s) { - ngx_rtmp_notify_srv_conf_t *nscf; - ngx_rtmp_netcall_init_t ci; - ngx_url_t *url; + ngx_rtmp_notify_srv_conf_t *nscf; + ngx_rtmp_netcall_init_t ci; + ngx_url_t *url; - if (s->auto_pushed || s->relay) { + if (s->auto_pushed || s->relay) + { goto next; } nscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_notify_module); url = nscf->url[NGX_RTMP_NOTIFY_DISCONNECT]; - if (url == NULL) { + if (url == NULL) + { goto next; } @@ -1352,20 +1398,21 @@ ngx_rtmp_notify_disconnect(ngx_rtmp_session_t *s) return next_disconnect(s); } - static ngx_int_t ngx_rtmp_notify_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v) { - ngx_rtmp_notify_app_conf_t *nacf; - ngx_rtmp_netcall_init_t ci; - ngx_url_t *url; + ngx_rtmp_notify_app_conf_t *nacf; + ngx_rtmp_netcall_init_t ci; + ngx_url_t *url; - if (s->auto_pushed) { + if (s->auto_pushed) + { goto next; } nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (nacf == NULL) { + if (nacf == NULL) + { goto next; } @@ -1373,7 +1420,8 @@ ngx_rtmp_notify_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v) ngx_rtmp_notify_init(s, v->name, v->args, NGX_RTMP_NOTIFY_PUBLISHING); - if (url == NULL) { + if (url == NULL) + { goto next; } @@ -1394,20 +1442,21 @@ ngx_rtmp_notify_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v) return next_publish(s, v); } - static ngx_int_t ngx_rtmp_notify_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v) { - ngx_rtmp_notify_app_conf_t *nacf; - ngx_rtmp_netcall_init_t ci; - ngx_url_t *url; + ngx_rtmp_notify_app_conf_t *nacf; + ngx_rtmp_netcall_init_t ci; + ngx_url_t *url; - if (s->auto_pushed) { + if (s->auto_pushed) + { goto next; } nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (nacf == NULL) { + if (nacf == NULL) + { goto next; } @@ -1415,7 +1464,8 @@ ngx_rtmp_notify_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v) ngx_rtmp_notify_init(s, v->name, v->args, NGX_RTMP_NOTIFY_PLAYING); - if (url == NULL) { + if (url == NULL) + { goto next; } @@ -1436,43 +1486,49 @@ ngx_rtmp_notify_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v) return next_play(s, v); } - static ngx_int_t ngx_rtmp_notify_close_stream(ngx_rtmp_session_t *s, ngx_rtmp_close_stream_t *v) { - ngx_rtmp_notify_ctx_t *ctx; - ngx_rtmp_notify_app_conf_t *nacf; + ngx_rtmp_notify_ctx_t *ctx; + ngx_rtmp_notify_app_conf_t *nacf; - if (s->auto_pushed) { + if (s->auto_pushed) + { goto next; } ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module); - if (ctx == NULL) { + if (ctx == NULL) + { goto next; } nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (nacf == NULL) { + if (nacf == NULL) + { goto next; } - if (ctx->flags & NGX_RTMP_NOTIFY_PUBLISHING) { + if (ctx->flags & NGX_RTMP_NOTIFY_PUBLISHING) + { ngx_rtmp_notify_done(s, "publish_done", NGX_RTMP_NOTIFY_PUBLISH_DONE); } - if (ctx->flags & NGX_RTMP_NOTIFY_PLAYING) { + if (ctx->flags & NGX_RTMP_NOTIFY_PLAYING) + { ngx_rtmp_notify_done(s, "play_done", NGX_RTMP_NOTIFY_PLAY_DONE); } - if (ctx->flags) { + if (ctx->flags) + { ngx_rtmp_notify_done(s, "done", NGX_RTMP_NOTIFY_DONE); } - if (ctx->update_evt.timer_set) { + if (ctx->update_evt.timer_set) + { ngx_del_timer(&ctx->update_evt); } @@ -1482,19 +1538,20 @@ ngx_rtmp_notify_close_stream(ngx_rtmp_session_t *s, return next_close_stream(s, v); } - static ngx_int_t ngx_rtmp_notify_record_done(ngx_rtmp_session_t *s, ngx_rtmp_record_done_t *v) { - ngx_rtmp_netcall_init_t ci; - ngx_rtmp_notify_app_conf_t *nacf; + ngx_rtmp_netcall_init_t ci; + ngx_rtmp_notify_app_conf_t *nacf; - if (s->auto_pushed) { + if (s->auto_pushed) + { goto next; } nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (nacf == NULL || nacf->url[NGX_RTMP_NOTIFY_RECORD_DONE] == NULL) { + if (nacf == NULL || nacf->url[NGX_RTMP_NOTIFY_RECORD_DONE] == NULL) + { goto next; } @@ -1505,9 +1562,9 @@ ngx_rtmp_notify_record_done(ngx_rtmp_session_t *s, ngx_rtmp_record_done_t *v) ngx_memzero(&ci, sizeof(ci)); - ci.url = nacf->url[NGX_RTMP_NOTIFY_RECORD_DONE]; + ci.url = nacf->url[NGX_RTMP_NOTIFY_RECORD_DONE]; ci.create = ngx_rtmp_notify_record_done_create; - ci.arg = v; + ci.arg = v; ngx_rtmp_netcall_create(s, &ci); @@ -1515,26 +1572,26 @@ ngx_rtmp_notify_record_done(ngx_rtmp_session_t *s, ngx_rtmp_record_done_t *v) return next_record_done(s, v); } - static ngx_int_t ngx_rtmp_notify_done(ngx_rtmp_session_t *s, char *cbname, ngx_uint_t url_idx) { - ngx_rtmp_netcall_init_t ci; - ngx_rtmp_notify_done_t ds; - ngx_rtmp_notify_app_conf_t *nacf; - ngx_url_t *url; + ngx_rtmp_netcall_init_t ci; + ngx_rtmp_notify_done_t ds; + ngx_rtmp_notify_app_conf_t *nacf; + ngx_url_t *url; nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); url = nacf->url[url_idx]; - if (url == NULL) { + if (url == NULL) + { return NGX_OK; } ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: %s '%V'", cbname, &url->url); - ds.cbname = (u_char *) cbname; + ds.cbname = (u_char *)cbname; ds.url_idx = url_idx; ngx_memzero(&ci, sizeof(ci)); @@ -1546,33 +1603,42 @@ ngx_rtmp_notify_done(ngx_rtmp_session_t *s, char *cbname, ngx_uint_t url_idx) return ngx_rtmp_netcall_create(s, &ci); } - static ngx_url_t * ngx_rtmp_notify_parse_url(ngx_conf_t *cf, ngx_str_t *url) { - ngx_url_t *u; - size_t add; + ngx_url_t *u; + size_t add; add = 0; u = ngx_pcalloc(cf->pool, sizeof(ngx_url_t)); - if (u == NULL) { + if (u == NULL) + { return NULL; } - if (ngx_strncasecmp(url->data, (u_char *) "http://", 7) == 0) { + if (ngx_strncasecmp(url->data, (u_char *)"http://", 7) == 0) + { add = 7; + port = 80 + } + else if (ngx_strncasecmp(url->data, (u_char *)"https://", 8) == 0) + { + add = 8; + port = 443; } u->url.len = url->len - add; u->url.data = url->data + add; - u->default_port = 80; + u->default_port = port; u->uri_part = 1; - if (ngx_parse_url(cf->pool, u) != NGX_OK) { - if (u->err) { + if (ngx_parse_url(cf->pool, u) != NGX_OK) + { + if (u->err) + { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "%s in url \"%V\"", u->err, &u->url); + "%s in url \"%V\"", u->err, &u->url); } return NULL; } @@ -1580,20 +1646,20 @@ ngx_rtmp_notify_parse_url(ngx_conf_t *cf, ngx_str_t *url) return u; } - static char * ngx_rtmp_notify_on_srv_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_rtmp_notify_srv_conf_t *nscf = conf; + ngx_rtmp_notify_srv_conf_t *nscf = conf; - ngx_str_t *name, *value; - ngx_url_t *u; - ngx_uint_t n; + ngx_str_t *name, *value; + ngx_url_t *u; + ngx_uint_t n; value = cf->args->elts; u = ngx_rtmp_notify_parse_url(cf, &value[1]); - if (u == NULL) { + if (u == NULL) + { return NGX_CONF_ERROR; } @@ -1601,14 +1667,15 @@ ngx_rtmp_notify_on_srv_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) n = 0; - switch (name->len) { - case sizeof("on_connect") - 1: - n = NGX_RTMP_NOTIFY_CONNECT; - break; + switch (name->len) + { + case sizeof("on_connect") - 1: + n = NGX_RTMP_NOTIFY_CONNECT; + break; - case sizeof("on_disconnect") - 1: - n = NGX_RTMP_NOTIFY_DISCONNECT; - break; + case sizeof("on_disconnect") - 1: + n = NGX_RTMP_NOTIFY_DISCONNECT; + break; } nscf->url[n] = u; @@ -1616,20 +1683,20 @@ ngx_rtmp_notify_on_srv_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_OK; } - static char * ngx_rtmp_notify_on_app_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_rtmp_notify_app_conf_t *nacf = conf; + ngx_rtmp_notify_app_conf_t *nacf = conf; - ngx_str_t *name, *value; - ngx_url_t *u; - ngx_uint_t n; + ngx_str_t *name, *value; + ngx_url_t *u; + ngx_uint_t n; value = cf->args->elts; u = ngx_rtmp_notify_parse_url(cf, &value[1]); - if (u == NULL) { + if (u == NULL) + { return NGX_CONF_ERROR; } @@ -1637,34 +1704,38 @@ ngx_rtmp_notify_on_app_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) n = 0; - switch (name->len) { - case sizeof("on_done") - 1: /* and on_play */ - if (name->data[3] == 'd') { - n = NGX_RTMP_NOTIFY_DONE; - } else { - n = NGX_RTMP_NOTIFY_PLAY; - } - break; + switch (name->len) + { + case sizeof("on_done") - 1: /* and on_play */ + if (name->data[3] == 'd') + { + n = NGX_RTMP_NOTIFY_DONE; + } + else + { + n = NGX_RTMP_NOTIFY_PLAY; + } + break; - case sizeof("on_update") - 1: - n = NGX_RTMP_NOTIFY_UPDATE; - break; + case sizeof("on_update") - 1: + n = NGX_RTMP_NOTIFY_UPDATE; + break; - case sizeof("on_publish") - 1: - n = NGX_RTMP_NOTIFY_PUBLISH; - break; + case sizeof("on_publish") - 1: + n = NGX_RTMP_NOTIFY_PUBLISH; + break; - case sizeof("on_play_done") - 1: - n = NGX_RTMP_NOTIFY_PLAY_DONE; - break; + case sizeof("on_play_done") - 1: + n = NGX_RTMP_NOTIFY_PLAY_DONE; + break; - case sizeof("on_record_done") - 1: - n = NGX_RTMP_NOTIFY_RECORD_DONE; - break; + case sizeof("on_record_done") - 1: + n = NGX_RTMP_NOTIFY_RECORD_DONE; + break; - case sizeof("on_publish_done") - 1: - n = NGX_RTMP_NOTIFY_PUBLISH_DONE; - break; + case sizeof("on_publish_done") - 1: + n = NGX_RTMP_NOTIFY_PUBLISH_DONE; + break; } nacf->url[n] = u; @@ -1672,29 +1743,29 @@ ngx_rtmp_notify_on_app_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_OK; } - static char * ngx_rtmp_notify_method(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_rtmp_notify_app_conf_t *nacf = conf; + ngx_rtmp_notify_app_conf_t *nacf = conf; - ngx_rtmp_notify_srv_conf_t *nscf; - ngx_str_t *value; + ngx_rtmp_notify_srv_conf_t *nscf; + ngx_str_t *value; value = cf->args->elts; value++; if (value->len == sizeof("get") - 1 && - ngx_strncasecmp(value->data, (u_char *) "get", value->len) == 0) + ngx_strncasecmp(value->data, (u_char *)"get", value->len) == 0) { nacf->method = NGX_RTMP_NETCALL_HTTP_GET; - - } else if (value->len == sizeof("post") - 1 && - ngx_strncasecmp(value->data, (u_char *) "post", value->len) == 0) + } + else if (value->len == sizeof("post") - 1 && + ngx_strncasecmp(value->data, (u_char *)"post", value->len) == 0) { nacf->method = NGX_RTMP_NETCALL_HTTP_POST; - - } else { + } + else + { return "got unexpected method"; } @@ -1704,7 +1775,6 @@ ngx_rtmp_notify_method(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_OK; } - static ngx_int_t ngx_rtmp_notify_postconfiguration(ngx_conf_t *cf) { From 86df8b205988c547c9773ea2172abe3179ebece1 Mon Sep 17 00:00:00 2001 From: Loic Baron Date: Fri, 10 Jun 2022 12:34:03 +0100 Subject: [PATCH 2/5] rm formatting --- ngx_rtmp_notify_module.c | 1275 ++++++++++++++++++-------------------- 1 file changed, 606 insertions(+), 669 deletions(-) diff --git a/ngx_rtmp_notify_module.c b/ngx_rtmp_notify_module.c index 3de37b602..e5f12eba8 100644 --- a/ngx_rtmp_notify_module.c +++ b/ngx_rtmp_notify_module.c @@ -3,6 +3,7 @@ * Copyright (C) Roman Arutyunyan */ + #include #include #include @@ -12,37 +13,41 @@ #include "ngx_rtmp_record_module.h" #include "ngx_rtmp_relay_module.h" -static ngx_rtmp_connect_pt next_connect; -static ngx_rtmp_disconnect_pt next_disconnect; -static ngx_rtmp_publish_pt next_publish; -static ngx_rtmp_play_pt next_play; -static ngx_rtmp_close_stream_pt next_close_stream; -static ngx_rtmp_record_done_pt next_record_done; + +static ngx_rtmp_connect_pt next_connect; +static ngx_rtmp_disconnect_pt next_disconnect; +static ngx_rtmp_publish_pt next_publish; +static ngx_rtmp_play_pt next_play; +static ngx_rtmp_close_stream_pt next_close_stream; +static ngx_rtmp_record_done_pt next_record_done; + static char *ngx_rtmp_notify_on_srv_event(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_rtmp_notify_on_app_event(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_rtmp_notify_method(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static ngx_int_t ngx_rtmp_notify_postconfiguration(ngx_conf_t *cf); -static void *ngx_rtmp_notify_create_app_conf(ngx_conf_t *cf); -static char *ngx_rtmp_notify_merge_app_conf(ngx_conf_t *cf, - void *parent, void *child); +static void * ngx_rtmp_notify_create_app_conf(ngx_conf_t *cf); +static char * ngx_rtmp_notify_merge_app_conf(ngx_conf_t *cf, + void *parent, void *child); static void *ngx_rtmp_notify_create_srv_conf(ngx_conf_t *cf); static char *ngx_rtmp_notify_merge_srv_conf(ngx_conf_t *cf, void *parent, - void *child); + void *child); static ngx_int_t ngx_rtmp_notify_done(ngx_rtmp_session_t *s, char *cbname, - ngx_uint_t url_idx); + ngx_uint_t url_idx); -ngx_str_t ngx_rtmp_notify_urlencoded = - ngx_string("application/x-www-form-urlencoded"); -#define NGX_RTMP_NOTIFY_PUBLISHING 0x01 -#define NGX_RTMP_NOTIFY_PLAYING 0x02 +ngx_str_t ngx_rtmp_notify_urlencoded = + ngx_string("application/x-www-form-urlencoded"); -enum -{ + +#define NGX_RTMP_NOTIFY_PUBLISHING 0x01 +#define NGX_RTMP_NOTIFY_PLAYING 0x02 + + +enum { NGX_RTMP_NOTIFY_PLAY, NGX_RTMP_NOTIFY_PUBLISH, NGX_RTMP_NOTIFY_PLAY_DONE, @@ -53,179 +58,183 @@ enum NGX_RTMP_NOTIFY_APP_MAX }; -enum -{ + +enum { NGX_RTMP_NOTIFY_CONNECT, NGX_RTMP_NOTIFY_DISCONNECT, NGX_RTMP_NOTIFY_SRV_MAX }; -typedef struct -{ - ngx_url_t *url[NGX_RTMP_NOTIFY_APP_MAX]; - ngx_flag_t active; - ngx_uint_t method; - ngx_msec_t update_timeout; - ngx_flag_t update_strict; - ngx_flag_t relay_redirect; + +typedef struct { + ngx_url_t *url[NGX_RTMP_NOTIFY_APP_MAX]; + ngx_flag_t active; + ngx_uint_t method; + ngx_msec_t update_timeout; + ngx_flag_t update_strict; + ngx_flag_t relay_redirect; } ngx_rtmp_notify_app_conf_t; -typedef struct -{ - ngx_url_t *url[NGX_RTMP_NOTIFY_SRV_MAX]; - ngx_uint_t method; + +typedef struct { + ngx_url_t *url[NGX_RTMP_NOTIFY_SRV_MAX]; + ngx_uint_t method; } ngx_rtmp_notify_srv_conf_t; -typedef struct -{ - ngx_uint_t flags; - u_char name[NGX_RTMP_MAX_NAME]; - u_char args[NGX_RTMP_MAX_ARGS]; - ngx_event_t update_evt; - time_t start; + +typedef struct { + ngx_uint_t flags; + u_char name[NGX_RTMP_MAX_NAME]; + u_char args[NGX_RTMP_MAX_ARGS]; + ngx_event_t update_evt; + time_t start; } ngx_rtmp_notify_ctx_t; -typedef struct -{ - u_char *cbname; - ngx_uint_t url_idx; + +typedef struct { + u_char *cbname; + ngx_uint_t url_idx; } ngx_rtmp_notify_done_t; -static ngx_command_t ngx_rtmp_notify_commands[] = { - - {ngx_string("on_connect"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_CONF_TAKE1, - ngx_rtmp_notify_on_srv_event, - NGX_RTMP_SRV_CONF_OFFSET, - 0, - NULL}, - - {ngx_string("on_disconnect"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_CONF_TAKE1, - ngx_rtmp_notify_on_srv_event, - NGX_RTMP_SRV_CONF_OFFSET, - 0, - NULL}, - - {ngx_string("on_publish"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL}, - - {ngx_string("on_play"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL}, - - {ngx_string("on_publish_done"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL}, - - {ngx_string("on_play_done"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL}, - - {ngx_string("on_done"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL}, - - {ngx_string("on_record_done"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_RTMP_REC_CONF | - NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL}, - - {ngx_string("on_update"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, - ngx_rtmp_notify_on_app_event, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL}, - - {ngx_string("notify_method"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, - ngx_rtmp_notify_method, - NGX_RTMP_APP_CONF_OFFSET, - 0, - NULL}, - - {ngx_string("notify_update_timeout"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, - ngx_conf_set_msec_slot, - NGX_RTMP_APP_CONF_OFFSET, - offsetof(ngx_rtmp_notify_app_conf_t, update_timeout), - NULL}, - - {ngx_string("notify_update_strict"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, - ngx_conf_set_flag_slot, - NGX_RTMP_APP_CONF_OFFSET, - offsetof(ngx_rtmp_notify_app_conf_t, update_strict), - NULL}, - - {ngx_string("notify_relay_redirect"), - NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_RTMP_APP_CONF | NGX_CONF_TAKE1, - ngx_conf_set_flag_slot, - NGX_RTMP_APP_CONF_OFFSET, - offsetof(ngx_rtmp_notify_app_conf_t, relay_redirect), - NULL}, - - ngx_null_command}; - -static ngx_rtmp_module_t ngx_rtmp_notify_module_ctx = { - NULL, /* preconfiguration */ - ngx_rtmp_notify_postconfiguration, /* postconfiguration */ - NULL, /* create main configuration */ - NULL, /* init main configuration */ - ngx_rtmp_notify_create_srv_conf, /* create server configuration */ - ngx_rtmp_notify_merge_srv_conf, /* merge server configuration */ - ngx_rtmp_notify_create_app_conf, /* create app configuration */ - ngx_rtmp_notify_merge_app_conf /* merge app configuration */ + +static ngx_command_t ngx_rtmp_notify_commands[] = { + + { ngx_string("on_connect"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_CONF_TAKE1, + ngx_rtmp_notify_on_srv_event, + NGX_RTMP_SRV_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("on_disconnect"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_CONF_TAKE1, + ngx_rtmp_notify_on_srv_event, + NGX_RTMP_SRV_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("on_publish"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("on_play"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("on_publish_done"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("on_play_done"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("on_done"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("on_record_done"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_RTMP_REC_CONF| + NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("on_update"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, + ngx_rtmp_notify_on_app_event, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("notify_method"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, + ngx_rtmp_notify_method, + NGX_RTMP_APP_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("notify_update_timeout"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, + ngx_conf_set_msec_slot, + NGX_RTMP_APP_CONF_OFFSET, + offsetof(ngx_rtmp_notify_app_conf_t, update_timeout), + NULL }, + + { ngx_string("notify_update_strict"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, + ngx_conf_set_flag_slot, + NGX_RTMP_APP_CONF_OFFSET, + offsetof(ngx_rtmp_notify_app_conf_t, update_strict), + NULL }, + + { ngx_string("notify_relay_redirect"), + NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1, + ngx_conf_set_flag_slot, + NGX_RTMP_APP_CONF_OFFSET, + offsetof(ngx_rtmp_notify_app_conf_t, relay_redirect), + NULL }, + + ngx_null_command }; -ngx_module_t ngx_rtmp_notify_module = { + +static ngx_rtmp_module_t ngx_rtmp_notify_module_ctx = { + NULL, /* preconfiguration */ + ngx_rtmp_notify_postconfiguration, /* postconfiguration */ + NULL, /* create main configuration */ + NULL, /* init main configuration */ + ngx_rtmp_notify_create_srv_conf, /* create server configuration */ + ngx_rtmp_notify_merge_srv_conf, /* merge server configuration */ + ngx_rtmp_notify_create_app_conf, /* create app configuration */ + ngx_rtmp_notify_merge_app_conf /* merge app configuration */ +}; + + +ngx_module_t ngx_rtmp_notify_module = { NGX_MODULE_V1, - &ngx_rtmp_notify_module_ctx, /* module context */ - ngx_rtmp_notify_commands, /* module directives */ - NGX_RTMP_MODULE, /* module type */ - NULL, /* init master */ - NULL, /* init module */ - NULL, /* init process */ - NULL, /* init thread */ - NULL, /* exit thread */ - NULL, /* exit process */ - NULL, /* exit master */ - NGX_MODULE_V1_PADDING}; + &ngx_rtmp_notify_module_ctx, /* module context */ + ngx_rtmp_notify_commands, /* module directives */ + NGX_RTMP_MODULE, /* module type */ + NULL, /* init master */ + NULL, /* init module */ + NULL, /* init process */ + NULL, /* init thread */ + NULL, /* exit thread */ + NULL, /* exit process */ + NULL, /* exit master */ + NGX_MODULE_V1_PADDING +}; + static void * ngx_rtmp_notify_create_app_conf(ngx_conf_t *cf) { - ngx_rtmp_notify_app_conf_t *nacf; - ngx_uint_t n; + ngx_rtmp_notify_app_conf_t *nacf; + ngx_uint_t n; nacf = ngx_pcalloc(cf->pool, sizeof(ngx_rtmp_notify_app_conf_t)); - if (nacf == NULL) - { + if (nacf == NULL) { return NULL; } - for (n = 0; n < NGX_RTMP_NOTIFY_APP_MAX; ++n) - { + for (n = 0; n < NGX_RTMP_NOTIFY_APP_MAX; ++n) { nacf->url[n] = NGX_CONF_UNSET_PTR; } @@ -237,24 +246,22 @@ ngx_rtmp_notify_create_app_conf(ngx_conf_t *cf) return nacf; } + static char * ngx_rtmp_notify_merge_app_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_rtmp_notify_app_conf_t *prev = parent; ngx_rtmp_notify_app_conf_t *conf = child; - ngx_uint_t n; + ngx_uint_t n; - for (n = 0; n < NGX_RTMP_NOTIFY_APP_MAX; ++n) - { + for (n = 0; n < NGX_RTMP_NOTIFY_APP_MAX; ++n) { ngx_conf_merge_ptr_value(conf->url[n], prev->url[n], NULL); - if (conf->url[n]) - { + if (conf->url[n]) { conf->active = 1; } } - if (conf->active) - { + if (conf->active) { prev->active = 1; } @@ -268,20 +275,19 @@ ngx_rtmp_notify_merge_app_conf(ngx_conf_t *cf, void *parent, void *child) return NGX_CONF_OK; } + static void * ngx_rtmp_notify_create_srv_conf(ngx_conf_t *cf) { - ngx_rtmp_notify_srv_conf_t *nscf; - ngx_uint_t n; + ngx_rtmp_notify_srv_conf_t *nscf; + ngx_uint_t n; nscf = ngx_pcalloc(cf->pool, sizeof(ngx_rtmp_notify_srv_conf_t)); - if (nscf == NULL) - { + if (nscf == NULL) { return NULL; } - for (n = 0; n < NGX_RTMP_NOTIFY_SRV_MAX; ++n) - { + for (n = 0; n < NGX_RTMP_NOTIFY_SRV_MAX; ++n) { nscf->url[n] = NGX_CONF_UNSET_PTR; } @@ -290,15 +296,15 @@ ngx_rtmp_notify_create_srv_conf(ngx_conf_t *cf) return nscf; } + static char * ngx_rtmp_notify_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_rtmp_notify_srv_conf_t *prev = parent; ngx_rtmp_notify_srv_conf_t *conf = child; - ngx_uint_t n; + ngx_uint_t n; - for (n = 0; n < NGX_RTMP_NOTIFY_SRV_MAX; ++n) - { + for (n = 0; n < NGX_RTMP_NOTIFY_SRV_MAX; ++n) { ngx_conf_merge_ptr_value(conf->url[n], prev->url[n], NULL); } @@ -308,21 +314,21 @@ ngx_rtmp_notify_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) return NGX_CONF_OK; } + static ngx_chain_t * ngx_rtmp_notify_create_request(ngx_rtmp_session_t *s, ngx_pool_t *pool, - ngx_uint_t url_idx, ngx_chain_t *args) + ngx_uint_t url_idx, ngx_chain_t *args) { ngx_rtmp_notify_app_conf_t *nacf; - ngx_chain_t *al, *bl, *cl; - ngx_url_t *url; + ngx_chain_t *al, *bl, *cl; + ngx_url_t *url; nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); url = nacf->url[url_idx]; al = ngx_rtmp_netcall_http_format_session(s, pool); - if (al == NULL) - { + if (al == NULL) { return NULL; } @@ -330,8 +336,7 @@ ngx_rtmp_notify_create_request(ngx_rtmp_session_t *s, ngx_pool_t *pool, bl = NULL; - if (nacf->method == NGX_RTMP_NETCALL_HTTP_POST) - { + if (nacf->method == NGX_RTMP_NETCALL_HTTP_POST) { cl = al; al = bl; bl = cl; @@ -342,25 +347,25 @@ ngx_rtmp_notify_create_request(ngx_rtmp_session_t *s, ngx_pool_t *pool, &ngx_rtmp_notify_urlencoded); } + static ngx_chain_t * ngx_rtmp_notify_connect_create(ngx_rtmp_session_t *s, void *arg, - ngx_pool_t *pool) + ngx_pool_t *pool) { - ngx_rtmp_connect_t *v = arg; + ngx_rtmp_connect_t *v = arg; - ngx_rtmp_notify_srv_conf_t *nscf; - ngx_url_t *url; - ngx_chain_t *al, *bl; - ngx_buf_t *b; - ngx_str_t *addr_text; - size_t app_len, args_len, flashver_len, - swf_url_len, tc_url_len, page_url_len; + ngx_rtmp_notify_srv_conf_t *nscf; + ngx_url_t *url; + ngx_chain_t *al, *bl; + ngx_buf_t *b; + ngx_str_t *addr_text; + size_t app_len, args_len, flashver_len, + swf_url_len, tc_url_len, page_url_len; nscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_notify_module); al = ngx_alloc_chain_link(pool); - if (al == NULL) - { + if (al == NULL) { return NULL; } @@ -378,70 +383,68 @@ ngx_rtmp_notify_connect_create(ngx_rtmp_session_t *s, void *arg, addr_text = &s->connection->addr_text; b = ngx_create_temp_buf(pool, - sizeof("call=connect") - 1 + - sizeof("&app=") - 1 + app_len * 3 + - sizeof("&flashver=") - 1 + flashver_len * 3 + - sizeof("&swfurl=") - 1 + swf_url_len * 3 + - sizeof("&tcurl=") - 1 + tc_url_len * 3 + - sizeof("&pageurl=") - 1 + page_url_len * 3 + - sizeof("&addr=") - 1 + addr_text->len * 3 + - sizeof("&epoch=") - 1 + NGX_INT32_LEN + - 1 + args_len); - - if (b == NULL) - { + sizeof("call=connect") - 1 + + sizeof("&app=") - 1 + app_len * 3 + + sizeof("&flashver=") - 1 + flashver_len * 3 + + sizeof("&swfurl=") - 1 + swf_url_len * 3 + + sizeof("&tcurl=") - 1 + tc_url_len * 3 + + sizeof("&pageurl=") - 1 + page_url_len * 3 + + sizeof("&addr=") - 1 + addr_text->len * 3 + + sizeof("&epoch=") - 1 + NGX_INT32_LEN + + 1 + args_len + ); + + if (b == NULL) { return NULL; } al->buf = b; al->next = NULL; - b->last = ngx_cpymem(b->last, (u_char *)"app=", sizeof("app=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, v->app, app_len, + b->last = ngx_cpymem(b->last, (u_char*) "app=", sizeof("app=") - 1); + b->last = (u_char*) ngx_escape_uri(b->last, v->app, app_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char *)"&flashver=", + b->last = ngx_cpymem(b->last, (u_char*) "&flashver=", sizeof("&flashver=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, v->flashver, flashver_len, + b->last = (u_char*) ngx_escape_uri(b->last, v->flashver, flashver_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char *)"&swfurl=", + b->last = ngx_cpymem(b->last, (u_char*) "&swfurl=", sizeof("&swfurl=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, v->swf_url, swf_url_len, + b->last = (u_char*) ngx_escape_uri(b->last, v->swf_url, swf_url_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char *)"&tcurl=", + b->last = ngx_cpymem(b->last, (u_char*) "&tcurl=", sizeof("&tcurl=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, v->tc_url, tc_url_len, + b->last = (u_char*) ngx_escape_uri(b->last, v->tc_url, tc_url_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char *)"&pageurl=", + b->last = ngx_cpymem(b->last, (u_char*) "&pageurl=", sizeof("&pageurl=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, v->page_url, page_url_len, + b->last = (u_char*) ngx_escape_uri(b->last, v->page_url, page_url_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char *)"&addr=", sizeof("&addr=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, addr_text->data, + b->last = ngx_cpymem(b->last, (u_char*) "&addr=", sizeof("&addr=") -1); + b->last = (u_char*) ngx_escape_uri(b->last, addr_text->data, addr_text->len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char *)"&epoch=", sizeof("&epoch=") - 1); - b->last = ngx_sprintf(b->last, "%uD", (uint32_t)s->epoch); + b->last = ngx_cpymem(b->last, (u_char*) "&epoch=", sizeof("&epoch=") -1); + b->last = ngx_sprintf(b->last, "%uD", (uint32_t) s->epoch); - b->last = ngx_cpymem(b->last, (u_char *)"&call=connect", + b->last = ngx_cpymem(b->last, (u_char*) "&call=connect", sizeof("&call=connect") - 1); - if (args_len) - { + if (args_len) { *b->last++ = '&'; - b->last = (u_char *)ngx_cpymem(b->last, v->args, args_len); + b->last = (u_char *) ngx_cpymem(b->last, v->args, args_len); } url = nscf->url[NGX_RTMP_NOTIFY_CONNECT]; bl = NULL; - if (nscf->method == NGX_RTMP_NETCALL_HTTP_POST) - { + if (nscf->method == NGX_RTMP_NETCALL_HTTP_POST) { bl = al; al = NULL; } @@ -451,53 +454,50 @@ ngx_rtmp_notify_connect_create(ngx_rtmp_session_t *s, void *arg, &ngx_rtmp_notify_urlencoded); } + static ngx_chain_t * ngx_rtmp_notify_disconnect_create(ngx_rtmp_session_t *s, void *arg, - ngx_pool_t *pool) + ngx_pool_t *pool) { - ngx_rtmp_notify_srv_conf_t *nscf; - ngx_url_t *url; - ngx_chain_t *al, *bl, *pl; - ngx_buf_t *b; + ngx_rtmp_notify_srv_conf_t *nscf; + ngx_url_t *url; + ngx_chain_t *al, *bl, *pl; + ngx_buf_t *b; nscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_notify_module); pl = ngx_alloc_chain_link(pool); - if (pl == NULL) - { + if (pl == NULL) { return NULL; } b = ngx_create_temp_buf(pool, sizeof("&call=disconnect") + - sizeof("&app=") + s->app.len * 3 + - 1 + s->args.len); - if (b == NULL) - { + sizeof("&app=") + s->app.len * 3 + + 1 + s->args.len); + if (b == NULL) { return NULL; } pl->buf = b; pl->next = NULL; - b->last = ngx_cpymem(b->last, (u_char *)"&call=disconnect", + b->last = ngx_cpymem(b->last, (u_char*) "&call=disconnect", sizeof("&call=disconnect") - 1); - b->last = ngx_cpymem(b->last, (u_char *)"&app=", sizeof("&app=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, s->app.data, s->app.len, + b->last = ngx_cpymem(b->last, (u_char*) "&app=", sizeof("&app=") - 1); + b->last = (u_char*) ngx_escape_uri(b->last, s->app.data, s->app.len, NGX_ESCAPE_ARGS); - if (s->args.len) - { + if (s->args.len) { *b->last++ = '&'; - b->last = (u_char *)ngx_cpymem(b->last, s->args.data, s->args.len); + b->last = (u_char *) ngx_cpymem(b->last, s->args.data, s->args.len); } url = nscf->url[NGX_RTMP_NOTIFY_DISCONNECT]; al = ngx_rtmp_netcall_http_format_session(s, pool); - if (al == NULL) - { + if (al == NULL) { return NULL; } @@ -505,8 +505,7 @@ ngx_rtmp_notify_disconnect_create(ngx_rtmp_session_t *s, void *arg, bl = NULL; - if (nscf->method == NGX_RTMP_NETCALL_HTTP_POST) - { + if (nscf->method == NGX_RTMP_NETCALL_HTTP_POST) { bl = al; al = NULL; } @@ -516,19 +515,19 @@ ngx_rtmp_notify_disconnect_create(ngx_rtmp_session_t *s, void *arg, &ngx_rtmp_notify_urlencoded); } + static ngx_chain_t * ngx_rtmp_notify_publish_create(ngx_rtmp_session_t *s, void *arg, - ngx_pool_t *pool) + ngx_pool_t *pool) { - ngx_rtmp_publish_t *v = arg; + ngx_rtmp_publish_t *v = arg; - ngx_chain_t *pl; - ngx_buf_t *b; - size_t name_len, type_len, args_len; + ngx_chain_t *pl; + ngx_buf_t *b; + size_t name_len, type_len, args_len; pl = ngx_alloc_chain_link(pool); - if (pl == NULL) - { + if (pl == NULL) { return NULL; } @@ -538,50 +537,48 @@ ngx_rtmp_notify_publish_create(ngx_rtmp_session_t *s, void *arg, b = ngx_create_temp_buf(pool, sizeof("&call=publish") + - sizeof("&name=") + name_len * 3 + - sizeof("&type=") + type_len * 3 + - 1 + args_len); - if (b == NULL) - { + sizeof("&name=") + name_len * 3 + + sizeof("&type=") + type_len * 3 + + 1 + args_len); + if (b == NULL) { return NULL; } pl->buf = b; pl->next = NULL; - b->last = ngx_cpymem(b->last, (u_char *)"&call=publish", + b->last = ngx_cpymem(b->last, (u_char*) "&call=publish", sizeof("&call=publish") - 1); - b->last = ngx_cpymem(b->last, (u_char *)"&name=", sizeof("&name=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, v->name, name_len, + b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1); + b->last = (u_char*) ngx_escape_uri(b->last, v->name, name_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char *)"&type=", sizeof("&type=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, v->type, type_len, + b->last = ngx_cpymem(b->last, (u_char*) "&type=", sizeof("&type=") - 1); + b->last = (u_char*) ngx_escape_uri(b->last, v->type, type_len, NGX_ESCAPE_ARGS); - if (args_len) - { + if (args_len) { *b->last++ = '&'; - b->last = (u_char *)ngx_cpymem(b->last, v->args, args_len); + b->last = (u_char *) ngx_cpymem(b->last, v->args, args_len); } return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_PUBLISH, pl); } + static ngx_chain_t * ngx_rtmp_notify_play_create(ngx_rtmp_session_t *s, void *arg, - ngx_pool_t *pool) + ngx_pool_t *pool) { - ngx_rtmp_play_t *v = arg; + ngx_rtmp_play_t *v = arg; - ngx_chain_t *pl; - ngx_buf_t *b; - size_t name_len, args_len; + ngx_chain_t *pl; + ngx_buf_t *b; + size_t name_len, args_len; pl = ngx_alloc_chain_link(pool); - if (pl == NULL) - { + if (pl == NULL) { return NULL; } @@ -590,54 +587,52 @@ ngx_rtmp_notify_play_create(ngx_rtmp_session_t *s, void *arg, b = ngx_create_temp_buf(pool, sizeof("&call=play") + - sizeof("&name=") + name_len * 3 + - sizeof("&start=&duration=&reset=") + - NGX_INT32_LEN * 3 + 1 + args_len); - if (b == NULL) - { + sizeof("&name=") + name_len * 3 + + sizeof("&start=&duration=&reset=") + + NGX_INT32_LEN * 3 + 1 + args_len); + if (b == NULL) { return NULL; } pl->buf = b; pl->next = NULL; - b->last = ngx_cpymem(b->last, (u_char *)"&call=play", + b->last = ngx_cpymem(b->last, (u_char*) "&call=play", sizeof("&call=play") - 1); - b->last = ngx_cpymem(b->last, (u_char *)"&name=", sizeof("&name=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, v->name, name_len, + b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1); + b->last = (u_char*) ngx_escape_uri(b->last, v->name, name_len, NGX_ESCAPE_ARGS); b->last = ngx_snprintf(b->last, b->end - b->last, "&start=%uD&duration=%uD&reset=%d", - (uint32_t)v->start, (uint32_t)v->duration, + (uint32_t) v->start, (uint32_t) v->duration, v->reset & 1); - if (args_len) - { + if (args_len) { *b->last++ = '&'; - b->last = (u_char *)ngx_cpymem(b->last, v->args, args_len); + b->last = (u_char *) ngx_cpymem(b->last, v->args, args_len); } return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_PLAY, pl); } + static ngx_chain_t * ngx_rtmp_notify_done_create(ngx_rtmp_session_t *s, void *arg, - ngx_pool_t *pool) + ngx_pool_t *pool) { - ngx_rtmp_notify_done_t *ds = arg; + ngx_rtmp_notify_done_t *ds = arg; - ngx_chain_t *pl; - ngx_buf_t *b; - size_t cbname_len, name_len, args_len; - ngx_rtmp_notify_ctx_t *ctx; + ngx_chain_t *pl; + ngx_buf_t *b; + size_t cbname_len, name_len, args_len; + ngx_rtmp_notify_ctx_t *ctx; ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module); pl = ngx_alloc_chain_link(pool); - if (pl == NULL) - { + if (pl == NULL) { return NULL; } @@ -647,63 +642,55 @@ ngx_rtmp_notify_done_create(ngx_rtmp_session_t *s, void *arg, b = ngx_create_temp_buf(pool, sizeof("&call=") + cbname_len + - sizeof("&name=") + name_len * 3 + - 1 + args_len); - if (b == NULL) - { + sizeof("&name=") + name_len * 3 + + 1 + args_len); + if (b == NULL) { return NULL; } pl->buf = b; pl->next = NULL; - b->last = ngx_cpymem(b->last, (u_char *)"&call=", sizeof("&call=") - 1); + b->last = ngx_cpymem(b->last, (u_char*) "&call=", sizeof("&call=") - 1); b->last = ngx_cpymem(b->last, ds->cbname, cbname_len); - if (name_len) - { - b->last = ngx_cpymem(b->last, (u_char *)"&name=", sizeof("&name=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, ctx->name, name_len, + if (name_len) { + b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1); + b->last = (u_char*) ngx_escape_uri(b->last, ctx->name, name_len, NGX_ESCAPE_ARGS); } - if (args_len) - { + if (args_len) { *b->last++ = '&'; - b->last = (u_char *)ngx_cpymem(b->last, ctx->args, args_len); + b->last = (u_char *) ngx_cpymem(b->last, ctx->args, args_len); } return ngx_rtmp_notify_create_request(s, pool, ds->url_idx, pl); } + static ngx_chain_t * ngx_rtmp_notify_update_create(ngx_rtmp_session_t *s, void *arg, - ngx_pool_t *pool) + ngx_pool_t *pool) { - ngx_chain_t *pl; - ngx_buf_t *b; - size_t name_len, args_len; - ngx_rtmp_notify_ctx_t *ctx; - ngx_str_t sfx; + ngx_chain_t *pl; + ngx_buf_t *b; + size_t name_len, args_len; + ngx_rtmp_notify_ctx_t *ctx; + ngx_str_t sfx; ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module); pl = ngx_alloc_chain_link(pool); - if (pl == NULL) - { + if (pl == NULL) { return NULL; } - if (ctx->flags & NGX_RTMP_NOTIFY_PUBLISHING) - { + if (ctx->flags & NGX_RTMP_NOTIFY_PUBLISHING) { ngx_str_set(&sfx, "_publish"); - } - else if (ctx->flags & NGX_RTMP_NOTIFY_PLAYING) - { + } else if (ctx->flags & NGX_RTMP_NOTIFY_PLAYING) { ngx_str_set(&sfx, "_play"); - } - else - { + } else { ngx_str_null(&sfx); } @@ -712,142 +699,134 @@ ngx_rtmp_notify_update_create(ngx_rtmp_session_t *s, void *arg, b = ngx_create_temp_buf(pool, sizeof("&call=update") + sfx.len + - sizeof("&time=") + NGX_TIME_T_LEN + - sizeof("×tamp=") + NGX_INT32_LEN + - sizeof("&name=") + name_len * 3 + - 1 + args_len); - if (b == NULL) - { + sizeof("&time=") + NGX_TIME_T_LEN + + sizeof("×tamp=") + NGX_INT32_LEN + + sizeof("&name=") + name_len * 3 + + 1 + args_len); + if (b == NULL) { return NULL; } pl->buf = b; pl->next = NULL; - b->last = ngx_cpymem(b->last, (u_char *)"&call=update", + b->last = ngx_cpymem(b->last, (u_char*) "&call=update", sizeof("&call=update") - 1); b->last = ngx_cpymem(b->last, sfx.data, sfx.len); - b->last = ngx_cpymem(b->last, (u_char *)"&time=", + b->last = ngx_cpymem(b->last, (u_char *) "&time=", sizeof("&time=") - 1); b->last = ngx_sprintf(b->last, "%T", ngx_cached_time->sec - ctx->start); - b->last = ngx_cpymem(b->last, (u_char *)"×tamp=", + b->last = ngx_cpymem(b->last, (u_char *) "×tamp=", sizeof("×tamp=") - 1); b->last = ngx_sprintf(b->last, "%D", s->current_time); - if (name_len) - { - b->last = ngx_cpymem(b->last, (u_char *)"&name=", sizeof("&name=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, ctx->name, name_len, + if (name_len) { + b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1); + b->last = (u_char*) ngx_escape_uri(b->last, ctx->name, name_len, NGX_ESCAPE_ARGS); } - if (args_len) - { + if (args_len) { *b->last++ = '&'; - b->last = (u_char *)ngx_cpymem(b->last, ctx->args, args_len); + b->last = (u_char *) ngx_cpymem(b->last, ctx->args, args_len); } return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_UPDATE, pl); } + static ngx_chain_t * ngx_rtmp_notify_record_done_create(ngx_rtmp_session_t *s, void *arg, ngx_pool_t *pool) { - ngx_rtmp_record_done_t *v = arg; + ngx_rtmp_record_done_t *v = arg; - ngx_rtmp_notify_ctx_t *ctx; - ngx_chain_t *pl; - ngx_buf_t *b; - size_t name_len, args_len; + ngx_rtmp_notify_ctx_t *ctx; + ngx_chain_t *pl; + ngx_buf_t *b; + size_t name_len, args_len; ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module); pl = ngx_alloc_chain_link(pool); - if (pl == NULL) - { + if (pl == NULL) { return NULL; } - name_len = ngx_strlen(ctx->name); - args_len = ngx_strlen(ctx->args); + name_len = ngx_strlen(ctx->name); + args_len = ngx_strlen(ctx->args); b = ngx_create_temp_buf(pool, sizeof("&call=record_done") + - sizeof("&recorder=") + v->recorder.len + - sizeof("&name=") + name_len * 3 + - sizeof("&path=") + v->path.len * 3 + - 1 + args_len); - if (b == NULL) - { + sizeof("&recorder=") + v->recorder.len + + sizeof("&name=") + name_len * 3 + + sizeof("&path=") + v->path.len * 3 + + 1 + args_len); + if (b == NULL) { return NULL; } pl->buf = b; pl->next = NULL; - b->last = ngx_cpymem(b->last, (u_char *)"&call=record_done", + b->last = ngx_cpymem(b->last, (u_char*) "&call=record_done", sizeof("&call=record_done") - 1); - b->last = ngx_cpymem(b->last, (u_char *)"&recorder=", + b->last = ngx_cpymem(b->last, (u_char *) "&recorder=", sizeof("&recorder=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, v->recorder.data, + b->last = (u_char*) ngx_escape_uri(b->last, v->recorder.data, v->recorder.len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char *)"&name=", sizeof("&name=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, ctx->name, name_len, + b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1); + b->last = (u_char*) ngx_escape_uri(b->last, ctx->name, name_len, NGX_ESCAPE_ARGS); - b->last = ngx_cpymem(b->last, (u_char *)"&path=", sizeof("&path=") - 1); - b->last = (u_char *)ngx_escape_uri(b->last, v->path.data, v->path.len, + b->last = ngx_cpymem(b->last, (u_char*) "&path=", sizeof("&path=") - 1); + b->last = (u_char*) ngx_escape_uri(b->last, v->path.data, v->path.len, NGX_ESCAPE_ARGS); - if (args_len) - { + if (args_len) { *b->last++ = '&'; - b->last = (u_char *)ngx_cpymem(b->last, ctx->args, args_len); + b->last = (u_char *) ngx_cpymem(b->last, ctx->args, args_len); } return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_RECORD_DONE, pl); } + static ngx_int_t ngx_rtmp_notify_parse_http_retcode(ngx_rtmp_session_t *s, - ngx_chain_t *in) + ngx_chain_t *in) { - ngx_buf_t *b; - ngx_int_t n; - u_char c; + ngx_buf_t *b; + ngx_int_t n; + u_char c; /* find 10th character */ n = 9; - while (in) - { + while (in) { b = in->buf; - if (b->last - b->pos > n) - { + if (b->last - b->pos > n) { c = b->pos[n]; - if (c >= (u_char)'0' && c <= (u_char)'9') - { + if (c >= (u_char)'0' && c <= (u_char)'9') { ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "notify: HTTP retcode: %dxx", (int)(c - '0')); - switch (c) - { - case (u_char)'2': - return NGX_OK; - case (u_char)'3': - return NGX_AGAIN; - default: - return NGX_ERROR; + "notify: HTTP retcode: %dxx", (int)(c - '0')); + switch (c) { + case (u_char) '2': + return NGX_OK; + case (u_char) '3': + return NGX_AGAIN; + default: + return NGX_ERROR; } } ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, - "notify: invalid HTTP retcode: %d..", (int)c); + "notify: invalid HTTP retcode: %d..", (int)c); return NGX_ERROR; } @@ -856,7 +835,7 @@ ngx_rtmp_notify_parse_http_retcode(ngx_rtmp_session_t *s, } ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, - "notify: empty or broken HTTP response"); + "notify: empty or broken HTTP response"); /* * not enough data; @@ -866,17 +845,17 @@ ngx_rtmp_notify_parse_http_retcode(ngx_rtmp_session_t *s, return NGX_ERROR; } + static ngx_int_t ngx_rtmp_notify_parse_http_header(ngx_rtmp_session_t *s, - ngx_chain_t *in, ngx_str_t *name, u_char *data, size_t len) + ngx_chain_t *in, ngx_str_t *name, u_char *data, size_t len) { - ngx_buf_t *b; - ngx_int_t matched; - u_char *p, c; - ngx_uint_t n; + ngx_buf_t *b; + ngx_int_t matched; + u_char *p, c; + ngx_uint_t n; - enum - { + enum { parse_name, parse_space, parse_value, @@ -886,85 +865,74 @@ ngx_rtmp_notify_parse_http_header(ngx_rtmp_session_t *s, n = 0; matched = 0; - while (in) - { + while (in) { b = in->buf; - for (p = b->pos; p != b->last; ++p) - { + for (p = b->pos; p != b->last; ++p) { c = *p; - if (c == '\r') - { + if (c == '\r') { continue; } - switch (state) - { - case parse_value_newline: - if (c == ' ' || c == '\t') - { - state = parse_space; - break; - } - - if (matched) - { - return n; - } + switch (state) { + case parse_value_newline: + if (c == ' ' || c == '\t') { + state = parse_space; + break; + } - if (c == '\n') - { - return NGX_OK; - } + if (matched) { + return n; + } - n = 0; - state = parse_name; - /* fall through */ + if (c == '\n') { + return NGX_OK; + } - case parse_name: - switch (c) - { - case ':': - matched = (n == name->len); - n = 0; - state = parse_space; - break; - case '\n': n = 0; + state = parse_name; + /* fall through */ + + case parse_name: + switch (c) { + case ':': + matched = (n == name->len); + n = 0; + state = parse_space; + break; + case '\n': + n = 0; + break; + default: + if (n < name->len && + ngx_tolower(c) == ngx_tolower(name->data[n])) + { + ++n; + break; + } + n = name->len + 1; + } break; - default: - if (n < name->len && - ngx_tolower(c) == ngx_tolower(name->data[n])) - { - ++n; + + case parse_space: + if (c == ' ' || c == '\t') { break; } - n = name->len + 1; - } - break; - - case parse_space: - if (c == ' ' || c == '\t') - { - break; - } - state = parse_value; - /* fall through */ + state = parse_value; + /* fall through */ - case parse_value: - if (c == '\n') - { - state = parse_value_newline; - break; - } + case parse_value: + if (c == '\n') { + state = parse_value_newline; + break; + } - if (matched && n + 1 < len) - { - data[n++] = c; - } + if (matched && n + 1 < len) { + data[n++] = c; + } - break; + break; } } @@ -974,41 +942,40 @@ ngx_rtmp_notify_parse_http_header(ngx_rtmp_session_t *s, return NGX_OK; } + static void ngx_rtmp_notify_clear_flag(ngx_rtmp_session_t *s, ngx_uint_t flag) { - ngx_rtmp_notify_ctx_t *ctx; + ngx_rtmp_notify_ctx_t *ctx; ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module); ctx->flags &= ~flag; } + static ngx_int_t ngx_rtmp_notify_connect_handle(ngx_rtmp_session_t *s, - void *arg, ngx_chain_t *in) + void *arg, ngx_chain_t *in) { ngx_rtmp_connect_t *v = arg; - ngx_int_t rc; - u_char app[NGX_RTMP_MAX_NAME]; + ngx_int_t rc; + u_char app[NGX_RTMP_MAX_NAME]; - static ngx_str_t location = ngx_string("location"); + static ngx_str_t location = ngx_string("location"); rc = ngx_rtmp_notify_parse_http_retcode(s, in); - if (rc == NGX_ERROR) - { + if (rc == NGX_ERROR) { return NGX_ERROR; } - if (rc == NGX_AGAIN) - { + if (rc == NGX_AGAIN) { ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, "notify: connect redirect received"); rc = ngx_rtmp_notify_parse_http_header(s, in, &location, app, sizeof(app) - 1); - if (rc > 0) - { + if (rc > 0) { *ngx_cpymem(v->app, app, rc) = 0; ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: connect redirect to '%s'", v->app); @@ -1018,12 +985,13 @@ ngx_rtmp_notify_connect_handle(ngx_rtmp_session_t *s, return next_connect(s, v); } + static void ngx_rtmp_notify_set_name(u_char *dst, size_t dst_len, u_char *src, - size_t src_len) + size_t src_len) { - u_char result[16], *p; - ngx_md5_t md5; + u_char result[16], *p; + ngx_md5_t md5; ngx_md5_init(&md5); ngx_md5_update(&md5, src, src_len); @@ -1033,29 +1001,28 @@ ngx_rtmp_notify_set_name(u_char *dst, size_t dst_len, u_char *src, *p = '\0'; } + static ngx_int_t ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, - void *arg, ngx_chain_t *in) + void *arg, ngx_chain_t *in) { - ngx_rtmp_publish_t *v = arg; - ngx_int_t rc; - ngx_str_t local_name; - ngx_rtmp_relay_target_t target; - ngx_url_t *u; + ngx_rtmp_publish_t *v = arg; + ngx_int_t rc; + ngx_str_t local_name; + ngx_rtmp_relay_target_t target; + ngx_url_t *u; ngx_rtmp_notify_app_conf_t *nacf; - u_char name[NGX_RTMP_MAX_NAME]; + u_char name[NGX_RTMP_MAX_NAME]; - static ngx_str_t location = ngx_string("location"); + static ngx_str_t location = ngx_string("location"); rc = ngx_rtmp_notify_parse_http_retcode(s, in); - if (rc == NGX_ERROR) - { + if (rc == NGX_ERROR) { ngx_rtmp_notify_clear_flag(s, NGX_RTMP_NOTIFY_PUBLISHING); return NGX_ERROR; } - if (rc != NGX_AGAIN) - { + if (rc != NGX_AGAIN) { goto next; } @@ -1066,13 +1033,11 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, rc = ngx_rtmp_notify_parse_http_header(s, in, &location, name, sizeof(name) - 1); - if (rc <= 0) - { + if (rc <= 0) { goto next; } - if (ngx_strncasecmp(name, (u_char *)"rtmp://", 7)) - { + if (ngx_strncasecmp(name, (u_char *) "rtmp://", 7)) { *ngx_cpymem(v->name, name, rc) = 0; ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: publish redirect to '%s'", v->name); @@ -1082,9 +1047,8 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, /* push */ nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (nacf->relay_redirect) - { - ngx_rtmp_notify_set_name(v->name, NGX_RTMP_MAX_NAME, name, (size_t)rc); + if (nacf->relay_redirect) { + 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, @@ -1103,8 +1067,7 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, u->uri_part = 1; u->no_resolve = 1; /* want ip here */ - if (ngx_parse_url(s->connection->pool, u) != NGX_OK) - { + if (ngx_parse_url(s->connection->pool, u) != NGX_OK) { ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: push failed '%V'", &local_name); return NGX_ERROR; @@ -1117,29 +1080,28 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s, return next_publish(s, v); } + static ngx_int_t ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, - void *arg, ngx_chain_t *in) + void *arg, ngx_chain_t *in) { - ngx_rtmp_play_t *v = arg; - ngx_int_t rc; - ngx_str_t local_name; - ngx_rtmp_relay_target_t target; - ngx_url_t *u; + ngx_rtmp_play_t *v = arg; + ngx_int_t rc; + ngx_str_t local_name; + ngx_rtmp_relay_target_t target; + ngx_url_t *u; ngx_rtmp_notify_app_conf_t *nacf; - u_char name[NGX_RTMP_MAX_NAME]; + u_char name[NGX_RTMP_MAX_NAME]; - static ngx_str_t location = ngx_string("location"); + static ngx_str_t location = ngx_string("location"); rc = ngx_rtmp_notify_parse_http_retcode(s, in); - if (rc == NGX_ERROR) - { + if (rc == NGX_ERROR) { ngx_rtmp_notify_clear_flag(s, NGX_RTMP_NOTIFY_PLAYING); return NGX_ERROR; } - if (rc != NGX_AGAIN) - { + if (rc != NGX_AGAIN) { goto next; } @@ -1150,13 +1112,11 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, rc = ngx_rtmp_notify_parse_http_header(s, in, &location, name, sizeof(name) - 1); - if (rc <= 0) - { + if (rc <= 0) { goto next; } - if (ngx_strncasecmp(name, (u_char *)"rtmp://", 7)) - { + if (ngx_strncasecmp(name, (u_char *) "rtmp://", 7)) { *ngx_cpymem(v->name, name, rc) = 0; ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: play redirect to '%s'", v->name); @@ -1166,9 +1126,8 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, /* pull */ nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (nacf->relay_redirect) - { - ngx_rtmp_notify_set_name(v->name, NGX_RTMP_MAX_NAME, name, (size_t)rc); + if (nacf->relay_redirect) { + ngx_rtmp_notify_set_name(v->name, NGX_RTMP_MAX_NAME, name, (size_t) rc); } ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, @@ -1187,8 +1146,7 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, u->uri_part = 1; u->no_resolve = 1; /* want ip here */ - if (ngx_parse_url(s->connection->pool, u) != NGX_OK) - { + if (ngx_parse_url(s->connection->pool, u) != NGX_OK) { ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: pull failed '%V'", &local_name); return NGX_ERROR; @@ -1201,20 +1159,21 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s, return next_play(s, v); } + static ngx_int_t ngx_rtmp_notify_update_handle(ngx_rtmp_session_t *s, - void *arg, ngx_chain_t *in) + void *arg, ngx_chain_t *in) { ngx_rtmp_notify_app_conf_t *nacf; - ngx_rtmp_notify_ctx_t *ctx; - ngx_int_t rc; + ngx_rtmp_notify_ctx_t *ctx; + ngx_int_t rc; nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); rc = ngx_rtmp_notify_parse_http_retcode(s, in); if ((!nacf->update_strict && rc == NGX_ERROR) || - (nacf->update_strict && rc != NGX_OK)) + (nacf->update_strict && rc != NGX_OK)) { ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: update failed"); @@ -1233,14 +1192,15 @@ ngx_rtmp_notify_update_handle(ngx_rtmp_session_t *s, return NGX_OK; } + static void ngx_rtmp_notify_update(ngx_event_t *e) { - ngx_connection_t *c; - ngx_rtmp_session_t *s; + ngx_connection_t *c; + ngx_rtmp_session_t *s; ngx_rtmp_notify_app_conf_t *nacf; - ngx_rtmp_netcall_init_t ci; - ngx_url_t *url; + ngx_rtmp_netcall_init_t ci; + ngx_url_t *url; c = e->data; s = c->data; @@ -1258,8 +1218,7 @@ ngx_rtmp_notify_update(ngx_event_t *e) ci.create = ngx_rtmp_notify_update_create; ci.handle = ngx_rtmp_notify_update_handle; - if (ngx_rtmp_netcall_create(s, &ci) == NGX_OK) - { + if (ngx_rtmp_netcall_create(s, &ci) == NGX_OK) { return; } @@ -1268,28 +1227,26 @@ ngx_rtmp_notify_update(ngx_event_t *e) ngx_rtmp_notify_update_handle(s, NULL, NULL); } + static void ngx_rtmp_notify_init(ngx_rtmp_session_t *s, - u_char name[NGX_RTMP_MAX_NAME], u_char args[NGX_RTMP_MAX_ARGS], - ngx_uint_t flags) + u_char name[NGX_RTMP_MAX_NAME], u_char args[NGX_RTMP_MAX_ARGS], + ngx_uint_t flags) { - ngx_rtmp_notify_ctx_t *ctx; - ngx_rtmp_notify_app_conf_t *nacf; - ngx_event_t *e; + ngx_rtmp_notify_ctx_t *ctx; + ngx_rtmp_notify_app_conf_t *nacf; + ngx_event_t *e; nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (!nacf->active) - { + if (!nacf->active) { return; } ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module); - if (ctx == NULL) - { + if (ctx == NULL) { ctx = ngx_pcalloc(s->connection->pool, sizeof(ngx_rtmp_notify_ctx_t)); - if (ctx == NULL) - { + if (ctx == NULL) { return; } @@ -1307,8 +1264,7 @@ ngx_rtmp_notify_init(ngx_rtmp_session_t *s, return; } - if (ctx->update_evt.timer_set) - { + if (ctx->update_evt.timer_set) { return; } @@ -1327,23 +1283,22 @@ ngx_rtmp_notify_init(ngx_rtmp_session_t *s, nacf->update_timeout); } + static ngx_int_t ngx_rtmp_notify_connect(ngx_rtmp_session_t *s, ngx_rtmp_connect_t *v) { - ngx_rtmp_notify_srv_conf_t *nscf; - ngx_rtmp_netcall_init_t ci; - ngx_url_t *url; + ngx_rtmp_notify_srv_conf_t *nscf; + ngx_rtmp_netcall_init_t ci; + ngx_url_t *url; - if (s->auto_pushed || s->relay) - { + if (s->auto_pushed || s->relay) { goto next; } nscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_notify_module); url = nscf->url[NGX_RTMP_NOTIFY_CONNECT]; - if (url == NULL) - { + if (url == NULL) { goto next; } @@ -1364,23 +1319,22 @@ ngx_rtmp_notify_connect(ngx_rtmp_session_t *s, ngx_rtmp_connect_t *v) return next_connect(s, v); } + static ngx_int_t ngx_rtmp_notify_disconnect(ngx_rtmp_session_t *s) { - ngx_rtmp_notify_srv_conf_t *nscf; - ngx_rtmp_netcall_init_t ci; - ngx_url_t *url; + ngx_rtmp_notify_srv_conf_t *nscf; + ngx_rtmp_netcall_init_t ci; + ngx_url_t *url; - if (s->auto_pushed || s->relay) - { + if (s->auto_pushed || s->relay) { goto next; } nscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_notify_module); url = nscf->url[NGX_RTMP_NOTIFY_DISCONNECT]; - if (url == NULL) - { + if (url == NULL) { goto next; } @@ -1398,21 +1352,20 @@ ngx_rtmp_notify_disconnect(ngx_rtmp_session_t *s) return next_disconnect(s); } + static ngx_int_t ngx_rtmp_notify_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v) { - ngx_rtmp_notify_app_conf_t *nacf; - ngx_rtmp_netcall_init_t ci; - ngx_url_t *url; + ngx_rtmp_notify_app_conf_t *nacf; + ngx_rtmp_netcall_init_t ci; + ngx_url_t *url; - if (s->auto_pushed) - { + if (s->auto_pushed) { goto next; } nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (nacf == NULL) - { + if (nacf == NULL) { goto next; } @@ -1420,8 +1373,7 @@ ngx_rtmp_notify_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v) ngx_rtmp_notify_init(s, v->name, v->args, NGX_RTMP_NOTIFY_PUBLISHING); - if (url == NULL) - { + if (url == NULL) { goto next; } @@ -1442,21 +1394,20 @@ ngx_rtmp_notify_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v) return next_publish(s, v); } + static ngx_int_t ngx_rtmp_notify_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v) { - ngx_rtmp_notify_app_conf_t *nacf; - ngx_rtmp_netcall_init_t ci; - ngx_url_t *url; + ngx_rtmp_notify_app_conf_t *nacf; + ngx_rtmp_netcall_init_t ci; + ngx_url_t *url; - if (s->auto_pushed) - { + if (s->auto_pushed) { goto next; } nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (nacf == NULL) - { + if (nacf == NULL) { goto next; } @@ -1464,8 +1415,7 @@ ngx_rtmp_notify_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v) ngx_rtmp_notify_init(s, v->name, v->args, NGX_RTMP_NOTIFY_PLAYING); - if (url == NULL) - { + if (url == NULL) { goto next; } @@ -1486,49 +1436,43 @@ ngx_rtmp_notify_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v) return next_play(s, v); } + static ngx_int_t ngx_rtmp_notify_close_stream(ngx_rtmp_session_t *s, ngx_rtmp_close_stream_t *v) { - ngx_rtmp_notify_ctx_t *ctx; - ngx_rtmp_notify_app_conf_t *nacf; + ngx_rtmp_notify_ctx_t *ctx; + ngx_rtmp_notify_app_conf_t *nacf; - if (s->auto_pushed) - { + if (s->auto_pushed) { goto next; } ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module); - if (ctx == NULL) - { + if (ctx == NULL) { goto next; } nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (nacf == NULL) - { + if (nacf == NULL) { goto next; } - if (ctx->flags & NGX_RTMP_NOTIFY_PUBLISHING) - { + if (ctx->flags & NGX_RTMP_NOTIFY_PUBLISHING) { ngx_rtmp_notify_done(s, "publish_done", NGX_RTMP_NOTIFY_PUBLISH_DONE); } - if (ctx->flags & NGX_RTMP_NOTIFY_PLAYING) - { + if (ctx->flags & NGX_RTMP_NOTIFY_PLAYING) { ngx_rtmp_notify_done(s, "play_done", NGX_RTMP_NOTIFY_PLAY_DONE); } - if (ctx->flags) - { + if (ctx->flags) { ngx_rtmp_notify_done(s, "done", NGX_RTMP_NOTIFY_DONE); } - if (ctx->update_evt.timer_set) - { + if (ctx->update_evt.timer_set) { ngx_del_timer(&ctx->update_evt); } @@ -1538,20 +1482,19 @@ ngx_rtmp_notify_close_stream(ngx_rtmp_session_t *s, return next_close_stream(s, v); } + static ngx_int_t ngx_rtmp_notify_record_done(ngx_rtmp_session_t *s, ngx_rtmp_record_done_t *v) { - ngx_rtmp_netcall_init_t ci; - ngx_rtmp_notify_app_conf_t *nacf; + ngx_rtmp_netcall_init_t ci; + ngx_rtmp_notify_app_conf_t *nacf; - if (s->auto_pushed) - { + if (s->auto_pushed) { goto next; } nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); - if (nacf == NULL || nacf->url[NGX_RTMP_NOTIFY_RECORD_DONE] == NULL) - { + if (nacf == NULL || nacf->url[NGX_RTMP_NOTIFY_RECORD_DONE] == NULL) { goto next; } @@ -1562,9 +1505,9 @@ ngx_rtmp_notify_record_done(ngx_rtmp_session_t *s, ngx_rtmp_record_done_t *v) ngx_memzero(&ci, sizeof(ci)); - ci.url = nacf->url[NGX_RTMP_NOTIFY_RECORD_DONE]; + ci.url = nacf->url[NGX_RTMP_NOTIFY_RECORD_DONE]; ci.create = ngx_rtmp_notify_record_done_create; - ci.arg = v; + ci.arg = v; ngx_rtmp_netcall_create(s, &ci); @@ -1572,26 +1515,26 @@ ngx_rtmp_notify_record_done(ngx_rtmp_session_t *s, ngx_rtmp_record_done_t *v) return next_record_done(s, v); } + static ngx_int_t ngx_rtmp_notify_done(ngx_rtmp_session_t *s, char *cbname, ngx_uint_t url_idx) { - ngx_rtmp_netcall_init_t ci; - ngx_rtmp_notify_done_t ds; - ngx_rtmp_notify_app_conf_t *nacf; - ngx_url_t *url; + ngx_rtmp_netcall_init_t ci; + ngx_rtmp_notify_done_t ds; + ngx_rtmp_notify_app_conf_t *nacf; + ngx_url_t *url; nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); url = nacf->url[url_idx]; - if (url == NULL) - { + if (url == NULL) { return NGX_OK; } ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: %s '%V'", cbname, &url->url); - ds.cbname = (u_char *)cbname; + ds.cbname = (u_char *) cbname; ds.url_idx = url_idx; ngx_memzero(&ci, sizeof(ci)); @@ -1603,17 +1546,17 @@ ngx_rtmp_notify_done(ngx_rtmp_session_t *s, char *cbname, ngx_uint_t url_idx) return ngx_rtmp_netcall_create(s, &ci); } + static ngx_url_t * ngx_rtmp_notify_parse_url(ngx_conf_t *cf, ngx_str_t *url) { - ngx_url_t *u; - size_t add; + ngx_url_t *u; + size_t add; add = 0; u = ngx_pcalloc(cf->pool, sizeof(ngx_url_t)); - if (u == NULL) - { + if (u == NULL) { return NULL; } @@ -1633,12 +1576,10 @@ ngx_rtmp_notify_parse_url(ngx_conf_t *cf, ngx_str_t *url) u->default_port = port; u->uri_part = 1; - if (ngx_parse_url(cf->pool, u) != NGX_OK) - { - if (u->err) - { + if (ngx_parse_url(cf->pool, u) != NGX_OK) { + if (u->err) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "%s in url \"%V\"", u->err, &u->url); + "%s in url \"%V\"", u->err, &u->url); } return NULL; } @@ -1646,20 +1587,20 @@ ngx_rtmp_notify_parse_url(ngx_conf_t *cf, ngx_str_t *url) return u; } + static char * ngx_rtmp_notify_on_srv_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_rtmp_notify_srv_conf_t *nscf = conf; + ngx_rtmp_notify_srv_conf_t *nscf = conf; - ngx_str_t *name, *value; - ngx_url_t *u; - ngx_uint_t n; + ngx_str_t *name, *value; + ngx_url_t *u; + ngx_uint_t n; value = cf->args->elts; u = ngx_rtmp_notify_parse_url(cf, &value[1]); - if (u == NULL) - { + if (u == NULL) { return NGX_CONF_ERROR; } @@ -1667,15 +1608,14 @@ ngx_rtmp_notify_on_srv_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) n = 0; - switch (name->len) - { - case sizeof("on_connect") - 1: - n = NGX_RTMP_NOTIFY_CONNECT; - break; + switch (name->len) { + case sizeof("on_connect") - 1: + n = NGX_RTMP_NOTIFY_CONNECT; + break; - case sizeof("on_disconnect") - 1: - n = NGX_RTMP_NOTIFY_DISCONNECT; - break; + case sizeof("on_disconnect") - 1: + n = NGX_RTMP_NOTIFY_DISCONNECT; + break; } nscf->url[n] = u; @@ -1683,20 +1623,20 @@ ngx_rtmp_notify_on_srv_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_OK; } + static char * ngx_rtmp_notify_on_app_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_rtmp_notify_app_conf_t *nacf = conf; + ngx_rtmp_notify_app_conf_t *nacf = conf; - ngx_str_t *name, *value; - ngx_url_t *u; - ngx_uint_t n; + ngx_str_t *name, *value; + ngx_url_t *u; + ngx_uint_t n; value = cf->args->elts; u = ngx_rtmp_notify_parse_url(cf, &value[1]); - if (u == NULL) - { + if (u == NULL) { return NGX_CONF_ERROR; } @@ -1704,38 +1644,34 @@ ngx_rtmp_notify_on_app_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) n = 0; - switch (name->len) - { - case sizeof("on_done") - 1: /* and on_play */ - if (name->data[3] == 'd') - { - n = NGX_RTMP_NOTIFY_DONE; - } - else - { - n = NGX_RTMP_NOTIFY_PLAY; - } - break; + switch (name->len) { + case sizeof("on_done") - 1: /* and on_play */ + if (name->data[3] == 'd') { + n = NGX_RTMP_NOTIFY_DONE; + } else { + n = NGX_RTMP_NOTIFY_PLAY; + } + break; - case sizeof("on_update") - 1: - n = NGX_RTMP_NOTIFY_UPDATE; - break; + case sizeof("on_update") - 1: + n = NGX_RTMP_NOTIFY_UPDATE; + break; - case sizeof("on_publish") - 1: - n = NGX_RTMP_NOTIFY_PUBLISH; - break; + case sizeof("on_publish") - 1: + n = NGX_RTMP_NOTIFY_PUBLISH; + break; - case sizeof("on_play_done") - 1: - n = NGX_RTMP_NOTIFY_PLAY_DONE; - break; + case sizeof("on_play_done") - 1: + n = NGX_RTMP_NOTIFY_PLAY_DONE; + break; - case sizeof("on_record_done") - 1: - n = NGX_RTMP_NOTIFY_RECORD_DONE; - break; + case sizeof("on_record_done") - 1: + n = NGX_RTMP_NOTIFY_RECORD_DONE; + break; - case sizeof("on_publish_done") - 1: - n = NGX_RTMP_NOTIFY_PUBLISH_DONE; - break; + case sizeof("on_publish_done") - 1: + n = NGX_RTMP_NOTIFY_PUBLISH_DONE; + break; } nacf->url[n] = u; @@ -1743,29 +1679,29 @@ ngx_rtmp_notify_on_app_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_OK; } + static char * ngx_rtmp_notify_method(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_rtmp_notify_app_conf_t *nacf = conf; + ngx_rtmp_notify_app_conf_t *nacf = conf; - ngx_rtmp_notify_srv_conf_t *nscf; - ngx_str_t *value; + ngx_rtmp_notify_srv_conf_t *nscf; + ngx_str_t *value; value = cf->args->elts; value++; if (value->len == sizeof("get") - 1 && - ngx_strncasecmp(value->data, (u_char *)"get", value->len) == 0) + ngx_strncasecmp(value->data, (u_char *) "get", value->len) == 0) { nacf->method = NGX_RTMP_NETCALL_HTTP_GET; - } - else if (value->len == sizeof("post") - 1 && - ngx_strncasecmp(value->data, (u_char *)"post", value->len) == 0) + + } else if (value->len == sizeof("post") - 1 && + ngx_strncasecmp(value->data, (u_char *) "post", value->len) == 0) { nacf->method = NGX_RTMP_NETCALL_HTTP_POST; - } - else - { + + } else { return "got unexpected method"; } @@ -1775,6 +1711,7 @@ ngx_rtmp_notify_method(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_OK; } + static ngx_int_t ngx_rtmp_notify_postconfiguration(ngx_conf_t *cf) { From fffa5b906f452ec60c832008fdd96e4d2a8fdbfd Mon Sep 17 00:00:00 2001 From: Loic Baron Date: Tue, 21 Jun 2022 09:48:06 +0100 Subject: [PATCH 3/5] fix declare port --- ngx_rtmp_notify_module.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ngx_rtmp_notify_module.c b/ngx_rtmp_notify_module.c index e5f12eba8..14cd0bb4f 100644 --- a/ngx_rtmp_notify_module.c +++ b/ngx_rtmp_notify_module.c @@ -1552,6 +1552,7 @@ ngx_rtmp_notify_parse_url(ngx_conf_t *cf, ngx_str_t *url) { ngx_url_t *u; size_t add; + size_t port; add = 0; From 9980737299f8b047a2c161b3aa95f4e3a7db65de Mon Sep 17 00:00:00 2001 From: Loic Baron Date: Tue, 21 Jun 2022 09:55:02 +0100 Subject: [PATCH 4/5] fix missing semi-column --- ngx_rtmp_notify_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ngx_rtmp_notify_module.c b/ngx_rtmp_notify_module.c index 14cd0bb4f..e7d57555e 100644 --- a/ngx_rtmp_notify_module.c +++ b/ngx_rtmp_notify_module.c @@ -1564,7 +1564,7 @@ ngx_rtmp_notify_parse_url(ngx_conf_t *cf, ngx_str_t *url) if (ngx_strncasecmp(url->data, (u_char *)"http://", 7) == 0) { add = 7; - port = 80 + port = 80; } else if (ngx_strncasecmp(url->data, (u_char *)"https://", 8) == 0) { From 5eb8432fea41371c87f4bdacfc71d19b7bbfe701 Mon Sep 17 00:00:00 2001 From: Loic Baron Date: Tue, 21 Jun 2022 09:56:29 +0100 Subject: [PATCH 5/5] init default port to 80 --- ngx_rtmp_notify_module.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ngx_rtmp_notify_module.c b/ngx_rtmp_notify_module.c index e7d57555e..aecc83552 100644 --- a/ngx_rtmp_notify_module.c +++ b/ngx_rtmp_notify_module.c @@ -1555,6 +1555,7 @@ ngx_rtmp_notify_parse_url(ngx_conf_t *cf, ngx_str_t *url) size_t port; add = 0; + port = 80; u = ngx_pcalloc(cf->pool, sizeof(ngx_url_t)); if (u == NULL) {