mirror of
https://github.com/arut/nginx-rtmp-module.git
synced 2025-08-06 15:00:18 +08:00
new optimized notifications
This commit is contained in:
@ -491,58 +491,76 @@ ngx_rtmp_netcall_send(ngx_event_t *wev)
|
|||||||
|
|
||||||
|
|
||||||
ngx_chain_t *
|
ngx_chain_t *
|
||||||
ngx_rtmp_netcall_http_format_header(ngx_int_t method, ngx_str_t *uri,
|
ngx_rtmp_netcall_http_format_request(ngx_int_t method, ngx_str_t *host,
|
||||||
ngx_str_t *host, ngx_pool_t *pool,
|
ngx_str_t *uri, ngx_chain_t *args,
|
||||||
size_t content_length,
|
ngx_chain_t *body, ngx_pool_t *pool,
|
||||||
ngx_str_t *content_type)
|
ngx_str_t *content_type)
|
||||||
{
|
{
|
||||||
ngx_chain_t *cl;
|
ngx_chain_t *al, *bl, *ret;
|
||||||
ngx_buf_t *b;
|
ngx_buf_t *b;
|
||||||
const char *method_s;
|
size_t content_length;
|
||||||
|
static const char *methods[2] = { "GET", "POST" };
|
||||||
|
static const char rq_tmpl[] = "HTTP/1.0\r\n"
|
||||||
|
"Host: %V\r\n"
|
||||||
|
"Content-Type: %V\r\n"
|
||||||
|
"Connection: Close\r\n"
|
||||||
|
"Content-Length: %uz\r\n"
|
||||||
|
"\r\n";
|
||||||
|
|
||||||
static char rq_tmpl[] =
|
content_length = 0;
|
||||||
"%s %V HTTP/1.0\r\n"
|
for (al = body; al; al = al->next) {
|
||||||
"Host: %V\r\n"
|
b = al->buf;
|
||||||
"Content-Type: %V\r\n"
|
content_length += (b->last - b->pos);
|
||||||
"Connection: Close\r\n"
|
}
|
||||||
"Content-Length: %uz\r\n"
|
|
||||||
"\r\n"
|
|
||||||
;
|
|
||||||
|
|
||||||
cl = ngx_alloc_chain_link(pool);
|
/* create first buffer */
|
||||||
if (cl == NULL) {
|
|
||||||
|
al = ngx_alloc_chain_link(pool);
|
||||||
|
if (al == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
b = ngx_create_temp_buf(pool, sizeof(rq_tmpl)
|
|
||||||
+ sizeof("POST") - 1 /* longest method */
|
|
||||||
+ uri->len
|
|
||||||
+ host->len
|
|
||||||
+ content_type->len
|
|
||||||
+ 5);
|
|
||||||
|
|
||||||
|
b = ngx_create_temp_buf(pool, sizeof("POST") + /* longest method + 1 */
|
||||||
|
uri->len + 1);
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cl->buf = b;
|
b->last = ngx_snprintf(b->last, b->end - b->last, "%s %V",
|
||||||
cl->next = NULL;
|
methods[method], &uri);
|
||||||
|
|
||||||
switch (method) {
|
al->buf = b;
|
||||||
case NGX_RTMP_NETCALL_HTTP_GET:
|
|
||||||
method_s = "GET";
|
ret = al;
|
||||||
break;
|
|
||||||
case NGX_RTMP_NETCALL_HTTP_POST:
|
if (args) {
|
||||||
method_s = "POST";
|
*b->last++ = '?';
|
||||||
break;
|
al->next = args;
|
||||||
default:
|
al = args;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b->last = ngx_snprintf(b->last, b->end - b->last, rq_tmpl,
|
/* create second buffer */
|
||||||
method_s, uri, host, content_type, content_length);
|
|
||||||
|
|
||||||
return cl;
|
bl = ngx_alloc_chain_link(pool);
|
||||||
|
if (bl == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
b = ngx_create_temp_buf(pool, sizeof(rq_tmpl) + host->len +
|
||||||
|
content_type->len + NGX_OFF_T_LEN);
|
||||||
|
if (b == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bl->buf = b;
|
||||||
|
|
||||||
|
b->last = ngx_snprintf(b->last, b->end - b->last, rq_tmpl,
|
||||||
|
&host, content_type, content_length);
|
||||||
|
|
||||||
|
al->next = bl;
|
||||||
|
bl->next = body;
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -551,6 +569,9 @@ ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s, ngx_pool_t *pool)
|
|||||||
{
|
{
|
||||||
ngx_chain_t *cl;
|
ngx_chain_t *cl;
|
||||||
ngx_buf_t *b;
|
ngx_buf_t *b;
|
||||||
|
ngx_str_t *addr_text;
|
||||||
|
|
||||||
|
addr_text = &s->connection->addr_text;
|
||||||
|
|
||||||
cl = ngx_alloc_chain_link(pool);
|
cl = ngx_alloc_chain_link(pool);
|
||||||
if (cl == NULL) {
|
if (cl == NULL) {
|
||||||
@ -562,7 +583,8 @@ ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s, ngx_pool_t *pool)
|
|||||||
sizeof("&flashver=") - 1 + s->flashver.len * 3 +
|
sizeof("&flashver=") - 1 + s->flashver.len * 3 +
|
||||||
sizeof("&swfurl=") - 1 + s->swf_url.len * 3 +
|
sizeof("&swfurl=") - 1 + s->swf_url.len * 3 +
|
||||||
sizeof("&tcurl=") - 1 + s->tc_url.len * 3 +
|
sizeof("&tcurl=") - 1 + s->tc_url.len * 3 +
|
||||||
sizeof("&pageurl=") - 1 + s->page_url.len * 3
|
sizeof("&pageurl=") - 1 + s->page_url.len * 3 +
|
||||||
|
sizeof("&addr=") - 1 + addr_text->len * 3
|
||||||
);
|
);
|
||||||
|
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
@ -571,28 +593,33 @@ ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s, ngx_pool_t *pool)
|
|||||||
|
|
||||||
cl->buf = b;
|
cl->buf = b;
|
||||||
|
|
||||||
b->last = ngx_cpymem(b->last, (u_char*)"app=", sizeof("app=") - 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, 0);
|
b->last = (u_char*) ngx_escape_uri(b->last, s->app.data, s->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);
|
sizeof("&flashver=") - 1);
|
||||||
b->last = (u_char*)ngx_escape_uri(b->last, s->flashver.data,
|
b->last = (u_char*) ngx_escape_uri(b->last, s->flashver.data,
|
||||||
s->flashver.len, 0);
|
s->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);
|
sizeof("&swfurl=") - 1);
|
||||||
b->last = (u_char*)ngx_escape_uri(b->last, s->swf_url.data,
|
b->last = (u_char*) ngx_escape_uri(b->last, s->swf_url.data,
|
||||||
s->swf_url.len, 0);
|
s->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);
|
sizeof("&tcurl=") - 1);
|
||||||
b->last = (u_char*)ngx_escape_uri(b->last, s->tc_url.data,
|
b->last = (u_char*) ngx_escape_uri(b->last, s->tc_url.data,
|
||||||
s->tc_url.len, 0);
|
s->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);
|
sizeof("&pageurl=") - 1);
|
||||||
b->last = (u_char*)ngx_escape_uri(b->last, s->page_url.data,
|
b->last = (u_char*) ngx_escape_uri(b->last, s->page_url.data,
|
||||||
s->page_url.len, 0);
|
s->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,
|
||||||
|
addr_text->len, NGX_ESCAPE_ARGS);
|
||||||
|
|
||||||
return cl;
|
return cl;
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ typedef ngx_int_t (*ngx_rtmp_netcall_sink_pt)(ngx_rtmp_session_t *s,
|
|||||||
typedef ngx_int_t (*ngx_rtmp_netcall_handle_pt)(ngx_rtmp_session_t *s,
|
typedef ngx_int_t (*ngx_rtmp_netcall_handle_pt)(ngx_rtmp_session_t *s,
|
||||||
void *arg, ngx_chain_t *in);
|
void *arg, ngx_chain_t *in);
|
||||||
|
|
||||||
#define NGX_RTMP_NETCALL_HTTP_GET 1
|
#define NGX_RTMP_NETCALL_HTTP_GET 0
|
||||||
#define NGX_RTMP_NETCALL_HTTP_POST 2
|
#define NGX_RTMP_NETCALL_HTTP_POST 1
|
||||||
|
|
||||||
|
|
||||||
/* If handle is NULL then netcall is created detached
|
/* If handle is NULL then netcall is created detached
|
||||||
@ -51,9 +51,9 @@ ngx_int_t ngx_rtmp_netcall_create(ngx_rtmp_session_t *s,
|
|||||||
/* HTTP handling */
|
/* HTTP handling */
|
||||||
ngx_chain_t * ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s,
|
ngx_chain_t * ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s,
|
||||||
ngx_pool_t *pool);
|
ngx_pool_t *pool);
|
||||||
ngx_chain_t * ngx_rtmp_netcall_http_format_header(ngx_int_t method,
|
ngx_chain_t * ngx_rtmp_netcall_http_format_request(ngx_int_t method,
|
||||||
ngx_str_t *uri, ngx_str_t *host, ngx_pool_t *pool,
|
ngx_str_t *host, ngx_str_t *uri, ngx_chain_t *args, ngx_chain_t *body,
|
||||||
size_t content_length, ngx_str_t *content_type);
|
ngx_pool_t *pool, ngx_str_t *content_type);
|
||||||
ngx_chain_t * ngx_rtmp_netcall_http_skip_header(ngx_chain_t *in);
|
ngx_chain_t * ngx_rtmp_netcall_http_skip_header(ngx_chain_t *in);
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ static ngx_rtmp_record_done_pt next_record_done;
|
|||||||
|
|
||||||
static char *ngx_rtmp_notify_on_event(ngx_conf_t *cf, ngx_command_t *cmd,
|
static char *ngx_rtmp_notify_on_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);
|
||||||
static ngx_int_t ngx_rtmp_notify_postconfiguration(ngx_conf_t *cf);
|
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 void * ngx_rtmp_notify_create_app_conf(ngx_conf_t *cf);
|
||||||
static char * ngx_rtmp_notify_merge_app_conf(ngx_conf_t *cf,
|
static char * ngx_rtmp_notify_merge_app_conf(ngx_conf_t *cf,
|
||||||
@ -50,6 +52,7 @@ enum {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
ngx_url_t *url[NGX_RTMP_NOTIFY_MAX];
|
ngx_url_t *url[NGX_RTMP_NOTIFY_MAX];
|
||||||
ngx_flag_t active;
|
ngx_flag_t active;
|
||||||
|
ngx_uint_t method;
|
||||||
} ngx_rtmp_notify_app_conf_t;
|
} ngx_rtmp_notify_app_conf_t;
|
||||||
|
|
||||||
|
|
||||||
@ -111,6 +114,13 @@ static ngx_command_t ngx_rtmp_notify_commands[] = {
|
|||||||
0,
|
0,
|
||||||
NULL },
|
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_null_command
|
ngx_null_command
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -158,6 +168,8 @@ ngx_rtmp_notify_create_app_conf(ngx_conf_t *cf)
|
|||||||
nacf->url[n] = NGX_CONF_UNSET_PTR;
|
nacf->url[n] = NGX_CONF_UNSET_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nacf->method = NGX_CONF_UNSET;
|
||||||
|
|
||||||
return nacf;
|
return nacf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,35 +192,57 @@ ngx_rtmp_notify_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||||||
prev->active = 1;
|
prev->active = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngx_conf_merge_uint_value(conf->method, prev->method,
|
||||||
|
NGX_RTMP_NETCALL_HTTP_POST);
|
||||||
|
|
||||||
return NGX_CONF_OK;
|
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_rtmp_notify_app_conf_t *nacf;
|
||||||
|
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) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
al->next = args;
|
||||||
|
|
||||||
|
bl = NULL;
|
||||||
|
|
||||||
|
if (nacf->method == NGX_RTMP_NETCALL_HTTP_POST) {
|
||||||
|
cl = al;
|
||||||
|
al = bl;
|
||||||
|
bl = cl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ngx_rtmp_netcall_http_format_request(nacf->method, &url->host,
|
||||||
|
&url->uri, al, bl, pool,
|
||||||
|
&ngx_rtmp_notify_urlencoded);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static ngx_chain_t *
|
static ngx_chain_t *
|
||||||
ngx_rtmp_notify_publish_create(ngx_rtmp_session_t *s, void *arg,
|
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_rtmp_notify_app_conf_t *nacf;
|
ngx_chain_t *pl;
|
||||||
ngx_chain_t *hl, *cl, *pl;
|
|
||||||
ngx_buf_t *b;
|
ngx_buf_t *b;
|
||||||
ngx_str_t *addr_text;
|
|
||||||
ngx_url_t *url;
|
|
||||||
size_t name_len, type_len, args_len;
|
size_t name_len, type_len, args_len;
|
||||||
|
|
||||||
nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module);
|
|
||||||
|
|
||||||
/* common variables */
|
|
||||||
cl = ngx_rtmp_netcall_http_format_session(s, pool);
|
|
||||||
|
|
||||||
if (cl == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* publish variables */
|
|
||||||
pl = ngx_alloc_chain_link(pool);
|
pl = ngx_alloc_chain_link(pool);
|
||||||
|
|
||||||
if (pl == NULL) {
|
if (pl == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -216,54 +250,36 @@ ngx_rtmp_notify_publish_create(ngx_rtmp_session_t *s, void *arg,
|
|||||||
name_len = ngx_strlen(v->name);
|
name_len = ngx_strlen(v->name);
|
||||||
type_len = ngx_strlen(v->type);
|
type_len = ngx_strlen(v->type);
|
||||||
args_len = ngx_strlen(v->args);
|
args_len = ngx_strlen(v->args);
|
||||||
addr_text = &s->connection->addr_text;
|
|
||||||
|
|
||||||
b = ngx_create_temp_buf(pool,
|
b = ngx_create_temp_buf(pool,
|
||||||
sizeof("&call=publish") +
|
sizeof("&call=publish") +
|
||||||
sizeof("&addr=") + addr_text->len *3 +
|
sizeof("&name=") + name_len * 3 +
|
||||||
sizeof("&name=") + name_len * 3 +
|
sizeof("&type=") + type_len * 3 +
|
||||||
sizeof("&type=") + type_len * 3 +
|
1 + args_len);
|
||||||
1 + args_len);
|
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pl->buf = b;
|
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);
|
sizeof("&call=publish") - 1);
|
||||||
|
|
||||||
b->last = ngx_cpymem(b->last, (u_char*)"&addr=", sizeof("&addr=") -1);
|
b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1);
|
||||||
b->last = (u_char*)ngx_escape_uri(b->last, addr_text->data,
|
b->last = (u_char*) ngx_escape_uri(b->last, v->name, name_len,
|
||||||
addr_text->len, 0);
|
NGX_ESCAPE_ARGS);
|
||||||
|
|
||||||
b->last = ngx_cpymem(b->last, (u_char*)"&name=", sizeof("&name=") - 1);
|
b->last = ngx_cpymem(b->last, (u_char*) "&type=", sizeof("&type=") - 1);
|
||||||
b->last = (u_char*)ngx_escape_uri(b->last, v->name, name_len, 0);
|
b->last = (u_char*) ngx_escape_uri(b->last, v->type, type_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, 0);
|
|
||||||
|
|
||||||
if (args_len) {
|
if (args_len) {
|
||||||
*b->last++ = '&';
|
*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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* HTTP header */
|
return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_PUBLISH, pl);
|
||||||
url = nacf->url[NGX_RTMP_NOTIFY_PUBLISH];
|
|
||||||
hl = ngx_rtmp_netcall_http_format_header(NGX_RTMP_NETCALL_HTTP_POST,
|
|
||||||
&url->uri, &url->host,
|
|
||||||
pool, cl->buf->last - cl->buf->pos + (pl->buf->last - pl->buf->pos),
|
|
||||||
&ngx_rtmp_notify_urlencoded);
|
|
||||||
|
|
||||||
if (hl == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
hl->next = cl;
|
|
||||||
cl->next = pl;
|
|
||||||
pl->next = NULL;
|
|
||||||
|
|
||||||
return hl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -273,80 +289,48 @@ ngx_rtmp_notify_play_create(ngx_rtmp_session_t *s, void *arg,
|
|||||||
{
|
{
|
||||||
ngx_rtmp_play_t *v = arg;
|
ngx_rtmp_play_t *v = arg;
|
||||||
|
|
||||||
ngx_rtmp_notify_app_conf_t *nacf;
|
ngx_chain_t *pl;
|
||||||
ngx_chain_t *hl, *cl, *pl;
|
|
||||||
ngx_buf_t *b;
|
ngx_buf_t *b;
|
||||||
ngx_str_t *addr_text;
|
|
||||||
ngx_url_t *url;
|
|
||||||
size_t name_len, args_len;
|
size_t name_len, args_len;
|
||||||
|
|
||||||
nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module);
|
|
||||||
|
|
||||||
/* common variables */
|
|
||||||
cl = ngx_rtmp_netcall_http_format_session(s, pool);
|
|
||||||
|
|
||||||
if (cl == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* play variables */
|
|
||||||
pl = ngx_alloc_chain_link(pool);
|
pl = ngx_alloc_chain_link(pool);
|
||||||
|
|
||||||
if (pl == NULL) {
|
if (pl == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
name_len = ngx_strlen(v->name);
|
name_len = ngx_strlen(v->name);
|
||||||
args_len = ngx_strlen(v->args);
|
args_len = ngx_strlen(v->args);
|
||||||
addr_text = &s->connection->addr_text;
|
|
||||||
|
|
||||||
b = ngx_create_temp_buf(pool,
|
b = ngx_create_temp_buf(pool,
|
||||||
sizeof("&call=play") +
|
sizeof("&call=play") +
|
||||||
sizeof("&addr=") + addr_text->len * 3 +
|
sizeof("&name=") + name_len * 3 +
|
||||||
sizeof("&name=") + name_len * 3 +
|
sizeof("&start=&duration=&reset=") +
|
||||||
sizeof("&start=&duration=&reset=") + NGX_OFF_T_LEN * 3
|
NGX_OFF_T_LEN * 3 + 1 + args_len);
|
||||||
+ 1 + args_len);
|
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pl->buf = b;
|
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);
|
sizeof("&call=play") - 1);
|
||||||
|
|
||||||
b->last = ngx_cpymem(b->last, (u_char*)"&addr=", sizeof("&addr=") -1);
|
b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1);
|
||||||
b->last = (u_char*)ngx_escape_uri(b->last, addr_text->data,
|
b->last = (u_char*) ngx_escape_uri(b->last, v->name, name_len,
|
||||||
addr_text->len, 0);
|
NGX_ESCAPE_ARGS);
|
||||||
|
|
||||||
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, 0);
|
|
||||||
|
|
||||||
b->last = ngx_snprintf(b->last, b->end - b->last,
|
b->last = ngx_snprintf(b->last, b->end - b->last,
|
||||||
"&start=%uD&duration=%uD&reset=%d",
|
"&start=%uD&duration=%uD&reset=%d",
|
||||||
(uint32_t)v->start, (uint32_t)v->duration, v->reset & 1);
|
(uint32_t) v->start, (uint32_t) v->duration,
|
||||||
|
v->reset & 1);
|
||||||
|
|
||||||
if (args_len) {
|
if (args_len) {
|
||||||
*b->last++ = '&';
|
*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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* HTTP header */
|
return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_PLAY, pl);
|
||||||
url = nacf->url[NGX_RTMP_NOTIFY_PLAY];
|
|
||||||
hl = ngx_rtmp_netcall_http_format_header(NGX_RTMP_NETCALL_HTTP_POST,
|
|
||||||
&url->uri, &url->host,
|
|
||||||
pool, cl->buf->last - cl->buf->pos + (pl->buf->last - pl->buf->pos),
|
|
||||||
&ngx_rtmp_notify_urlencoded);
|
|
||||||
|
|
||||||
if (hl == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
hl->next = cl;
|
|
||||||
cl->next = pl;
|
|
||||||
pl->next = NULL;
|
|
||||||
|
|
||||||
return hl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -356,23 +340,14 @@ ngx_rtmp_notify_done_create(ngx_rtmp_session_t *s, void *arg,
|
|||||||
{
|
{
|
||||||
ngx_rtmp_notify_done_t *ds = arg;
|
ngx_rtmp_notify_done_t *ds = arg;
|
||||||
|
|
||||||
ngx_chain_t *hl, *cl, *pl;
|
ngx_chain_t *pl;
|
||||||
ngx_buf_t *b;
|
ngx_buf_t *b;
|
||||||
size_t cbname_len, name_len, args_len;
|
size_t cbname_len, name_len, args_len;
|
||||||
ngx_str_t *addr_text;
|
|
||||||
ngx_rtmp_notify_ctx_t *ctx;
|
ngx_rtmp_notify_ctx_t *ctx;
|
||||||
|
|
||||||
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module);
|
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module);
|
||||||
|
|
||||||
/* common variables */
|
|
||||||
cl = ngx_rtmp_netcall_http_format_session(s, pool);
|
|
||||||
|
|
||||||
if (cl == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pl = ngx_alloc_chain_link(pool);
|
pl = ngx_alloc_chain_link(pool);
|
||||||
|
|
||||||
if (pl == NULL) {
|
if (pl == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -380,51 +355,33 @@ ngx_rtmp_notify_done_create(ngx_rtmp_session_t *s, void *arg,
|
|||||||
cbname_len = ngx_strlen(ds->cbname);
|
cbname_len = ngx_strlen(ds->cbname);
|
||||||
name_len = ctx ? ngx_strlen(ctx->name) : 0;
|
name_len = ctx ? ngx_strlen(ctx->name) : 0;
|
||||||
args_len = ctx ? ngx_strlen(ctx->args) : 0;
|
args_len = ctx ? ngx_strlen(ctx->args) : 0;
|
||||||
addr_text = &s->connection->addr_text;
|
|
||||||
|
|
||||||
b = ngx_create_temp_buf(pool,
|
b = ngx_create_temp_buf(pool,
|
||||||
sizeof("&call=") + cbname_len +
|
sizeof("&call=") + cbname_len +
|
||||||
sizeof("&addr=") + addr_text->len * 3 +
|
sizeof("&name=") + name_len * 3 +
|
||||||
sizeof("&name=") + name_len * 3
|
1 + args_len);
|
||||||
+ 1 + args_len);
|
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pl->buf = b;
|
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);
|
b->last = ngx_cpymem(b->last, ds->cbname, cbname_len);
|
||||||
|
|
||||||
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, 0);
|
|
||||||
|
|
||||||
if (name_len) {
|
if (name_len) {
|
||||||
b->last = ngx_cpymem(b->last, (u_char*)"&name=", sizeof("&name=") - 1);
|
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, 0);
|
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++ = '&';
|
||||||
b->last = (u_char *)ngx_cpymem(b->last, ctx->args, args_len);
|
b->last = (u_char *) ngx_cpymem(b->last, ctx->args, args_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* HTTP header */
|
return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_DONE, pl);
|
||||||
hl = ngx_rtmp_netcall_http_format_header(NGX_RTMP_NETCALL_HTTP_POST,
|
|
||||||
&ds->url->uri, &ds->url->host,
|
|
||||||
pool, cl->buf->last - cl->buf->pos + (pl->buf->last - pl->buf->pos),
|
|
||||||
&ngx_rtmp_notify_urlencoded);
|
|
||||||
|
|
||||||
if (hl == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
hl->next = cl;
|
|
||||||
cl->next = pl;
|
|
||||||
pl->next = NULL;
|
|
||||||
|
|
||||||
return hl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -434,88 +391,57 @@ ngx_rtmp_notify_record_done_create(ngx_rtmp_session_t *s, void *arg,
|
|||||||
{
|
{
|
||||||
ngx_rtmp_record_done_t *v = arg;
|
ngx_rtmp_record_done_t *v = arg;
|
||||||
|
|
||||||
ngx_rtmp_notify_app_conf_t *nacf;
|
|
||||||
ngx_rtmp_notify_ctx_t *ctx;
|
ngx_rtmp_notify_ctx_t *ctx;
|
||||||
ngx_chain_t *hl, *cl, *pl;
|
ngx_chain_t *pl;
|
||||||
ngx_buf_t *b;
|
ngx_buf_t *b;
|
||||||
ngx_str_t *addr_text;
|
|
||||||
ngx_url_t *url;
|
|
||||||
size_t name_len, args_len;
|
size_t name_len, args_len;
|
||||||
|
|
||||||
nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module);
|
|
||||||
|
|
||||||
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module);
|
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module);
|
||||||
|
|
||||||
/* common variables */
|
|
||||||
cl = ngx_rtmp_netcall_http_format_session(s, pool);
|
|
||||||
|
|
||||||
if (cl == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* publish variables */
|
|
||||||
pl = ngx_alloc_chain_link(pool);
|
pl = ngx_alloc_chain_link(pool);
|
||||||
|
|
||||||
if (pl == NULL) {
|
if (pl == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
name_len = ngx_strlen(ctx->name);
|
name_len = ngx_strlen(ctx->name);
|
||||||
args_len = ngx_strlen(ctx->args);
|
args_len = ngx_strlen(ctx->args);
|
||||||
addr_text = &s->connection->addr_text;
|
|
||||||
|
|
||||||
b = ngx_create_temp_buf(pool,
|
b = ngx_create_temp_buf(pool,
|
||||||
sizeof("&call=record_done") +
|
sizeof("&call=record_done") +
|
||||||
sizeof("&recorder=") + v->recorder.len +
|
sizeof("&recorder=") + v->recorder.len +
|
||||||
sizeof("&addr=") + addr_text->len *3 +
|
|
||||||
sizeof("&name=") + name_len * 3 +
|
sizeof("&name=") + name_len * 3 +
|
||||||
sizeof("&path=") + v->path.len * 3 +
|
sizeof("&path=") + v->path.len * 3 +
|
||||||
+ 1 + args_len);
|
1 + args_len);
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pl->buf = b;
|
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);
|
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);
|
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, 0);
|
v->recorder.len, NGX_ESCAPE_ARGS);
|
||||||
|
|
||||||
b->last = ngx_cpymem(b->last, (u_char*)"&addr=", sizeof("&addr=") -1);
|
b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1);
|
||||||
b->last = (u_char*)ngx_escape_uri(b->last, addr_text->data,
|
b->last = (u_char*) ngx_escape_uri(b->last, ctx->name, name_len,
|
||||||
addr_text->len, 0);
|
NGX_ESCAPE_ARGS);
|
||||||
|
|
||||||
b->last = ngx_cpymem(b->last, (u_char*)"&name=", sizeof("&name=") - 1);
|
b->last = ngx_cpymem(b->last, (u_char*) "&path=", sizeof("&path=") - 1);
|
||||||
b->last = (u_char*)ngx_escape_uri(b->last, ctx->name, name_len, 0);
|
b->last = (u_char*) ngx_escape_uri(b->last, v->path.data, v->path.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, 0);
|
|
||||||
|
|
||||||
if (args_len) {
|
if (args_len) {
|
||||||
*b->last++ = '&';
|
*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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* HTTP header */
|
return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_RECORD_DONE,
|
||||||
url = nacf->url[NGX_RTMP_NOTIFY_RECORD_DONE];
|
pl);
|
||||||
hl = ngx_rtmp_netcall_http_format_header(NGX_RTMP_NETCALL_HTTP_POST,
|
|
||||||
&url->uri, &url->host,
|
|
||||||
pool, cl->buf->last - cl->buf->pos + (pl->buf->last - pl->buf->pos),
|
|
||||||
&ngx_rtmp_notify_urlencoded);
|
|
||||||
|
|
||||||
if (hl == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
hl->next = cl;
|
|
||||||
cl->next = pl;
|
|
||||||
pl->next = NULL;
|
|
||||||
|
|
||||||
return hl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -800,7 +726,8 @@ ngx_rtmp_notify_done(ngx_rtmp_session_t *s, char *cbname, ngx_url_t *url)
|
|||||||
static char *
|
static char *
|
||||||
ngx_rtmp_notify_on_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
ngx_rtmp_notify_on_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
{
|
{
|
||||||
ngx_rtmp_notify_app_conf_t *nacf;
|
ngx_rtmp_notify_app_conf_t *nacf = conf;
|
||||||
|
|
||||||
ngx_str_t *url, *name;
|
ngx_str_t *url, *name;
|
||||||
ngx_url_t *u;
|
ngx_url_t *u;
|
||||||
size_t add;
|
size_t add;
|
||||||
@ -835,8 +762,6 @@ ngx_rtmp_notify_on_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
nacf = ngx_rtmp_conf_get_module_app_conf(cf, ngx_rtmp_notify_module);
|
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
switch (name->len) {
|
switch (name->len) {
|
||||||
@ -871,6 +796,34 @@ ngx_rtmp_notify_on_event(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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_str_t *value;
|
||||||
|
|
||||||
|
value = cf->args->elts;
|
||||||
|
value++;
|
||||||
|
|
||||||
|
if (value->len == sizeof("get") - 1 &&
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
nacf->method = NGX_RTMP_NETCALL_HTTP_POST;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return "unexpected method";
|
||||||
|
}
|
||||||
|
|
||||||
|
return NGX_CONF_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t
|
static ngx_int_t
|
||||||
ngx_rtmp_notify_postconfiguration(ngx_conf_t *cf)
|
ngx_rtmp_notify_postconfiguration(ngx_conf_t *cf)
|
||||||
{
|
{
|
||||||
|
@ -593,7 +593,6 @@ ngx_rtmp_play_remote_create(ngx_rtmp_session_t *s, void *arg, ngx_pool_t *pool)
|
|||||||
|
|
||||||
ngx_rtmp_play_app_conf_t *pacf;
|
ngx_rtmp_play_app_conf_t *pacf;
|
||||||
ngx_rtmp_play_ctx_t *ctx;
|
ngx_rtmp_play_ctx_t *ctx;
|
||||||
ngx_chain_t *hl;
|
|
||||||
ngx_str_t *addr_text, uri;
|
ngx_str_t *addr_text, uri;
|
||||||
u_char *p;
|
u_char *p;
|
||||||
size_t args_len, len;
|
size_t args_len, len;
|
||||||
@ -625,7 +624,8 @@ ngx_rtmp_play_remote_create(ngx_rtmp_session_t *s, void *arg, ngx_pool_t *pool)
|
|||||||
|
|
||||||
p = ngx_cpymem(p, ctx->name.data, ctx->name.len);
|
p = ngx_cpymem(p, ctx->name.data, ctx->name.len);
|
||||||
p = ngx_cpymem(p, (u_char*)"?addr=", sizeof("&addr=") -1);
|
p = ngx_cpymem(p, (u_char*)"?addr=", sizeof("&addr=") -1);
|
||||||
p = (u_char*)ngx_escape_uri(p, addr_text->data, addr_text->len, 0);
|
p = (u_char*)ngx_escape_uri(p, addr_text->data, addr_text->len,
|
||||||
|
NGX_ESCAPE_ARGS);
|
||||||
if (args_len) {
|
if (args_len) {
|
||||||
*p++ = '&';
|
*p++ = '&';
|
||||||
p = (u_char *) ngx_cpymem(p, v->args, args_len);
|
p = (u_char *) ngx_cpymem(p, v->args, args_len);
|
||||||
@ -633,15 +633,9 @@ ngx_rtmp_play_remote_create(ngx_rtmp_session_t *s, void *arg, ngx_pool_t *pool)
|
|||||||
|
|
||||||
uri.len = p - uri.data;
|
uri.len = p - uri.data;
|
||||||
|
|
||||||
/* HTTP header */
|
return ngx_rtmp_netcall_http_format_request(NGX_RTMP_NETCALL_HTTP_GET,
|
||||||
hl = ngx_rtmp_netcall_http_format_header(NGX_RTMP_NETCALL_HTTP_GET,
|
&pacf->url->host, &uri,
|
||||||
&uri, &pacf->url->host, pool, 0, &text_plain);
|
NULL, NULL, pool, &text_plain);
|
||||||
|
|
||||||
if (hl == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user