mirror of
https://github.com/arut/nginx-rtmp-module.git
synced 2025-08-06 15:00:18 +08:00
added all required arguments to old-style & new-style exec
This commit is contained in:
@ -65,6 +65,9 @@ typedef struct {
|
|||||||
ngx_uint_t flags;
|
ngx_uint_t flags;
|
||||||
u_char name[NGX_RTMP_MAX_NAME];
|
u_char name[NGX_RTMP_MAX_NAME];
|
||||||
u_char args[NGX_RTMP_MAX_ARGS];
|
u_char args[NGX_RTMP_MAX_ARGS];
|
||||||
|
ngx_str_t path;
|
||||||
|
ngx_str_t filename;
|
||||||
|
ngx_str_t recorder;
|
||||||
} ngx_rtmp_enotify_ctx_t;
|
} ngx_rtmp_enotify_ctx_t;
|
||||||
|
|
||||||
|
|
||||||
@ -138,6 +141,72 @@ ngx_module_t ngx_rtmp_enotify_module = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
ngx_rtmp_enotify_eval_cstr(ngx_rtmp_session_t *s, ngx_rtmp_eval_t *e,
|
||||||
|
ngx_str_t *ret)
|
||||||
|
{
|
||||||
|
ngx_rtmp_enotify_ctx_t *ctx;
|
||||||
|
|
||||||
|
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_enotify_module);
|
||||||
|
if (ctx == NULL) {
|
||||||
|
ret->len = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret->data = *(u_char **) ((u_char *) ctx + e->offset);
|
||||||
|
ret->len = ngx_strlen(ret->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
ngx_rtmp_enotify_eval_str(ngx_rtmp_session_t *s, ngx_rtmp_eval_t *e,
|
||||||
|
ngx_str_t *ret)
|
||||||
|
{
|
||||||
|
ngx_rtmp_enotify_ctx_t *ctx;
|
||||||
|
|
||||||
|
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_enotify_module);
|
||||||
|
if (ctx == NULL) {
|
||||||
|
ret->len = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ret = *(ngx_str_t *) ((u_char *) ctx + e->offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ngx_rtmp_eval_t ngx_rtmp_enotify_eval[] = {
|
||||||
|
|
||||||
|
{ ngx_string("name"),
|
||||||
|
ngx_rtmp_enotify_eval_cstr,
|
||||||
|
offsetof(ngx_rtmp_enotify_ctx_t, name) },
|
||||||
|
|
||||||
|
{ ngx_string("args"),
|
||||||
|
ngx_rtmp_enotify_eval_cstr,
|
||||||
|
offsetof(ngx_rtmp_enotify_ctx_t, args) },
|
||||||
|
|
||||||
|
{ ngx_string("path"),
|
||||||
|
ngx_rtmp_enotify_eval_str,
|
||||||
|
offsetof(ngx_rtmp_enotify_ctx_t, path) },
|
||||||
|
|
||||||
|
{ ngx_string("filename"),
|
||||||
|
ngx_rtmp_enotify_eval_str,
|
||||||
|
offsetof(ngx_rtmp_enotify_ctx_t, filename) },
|
||||||
|
|
||||||
|
{ ngx_string("recorder"),
|
||||||
|
ngx_rtmp_enotify_eval_str,
|
||||||
|
offsetof(ngx_rtmp_enotify_ctx_t, recorder) },
|
||||||
|
|
||||||
|
ngx_rtmp_null_eval
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static ngx_rtmp_eval_t * ngx_rtmp_enotify_eval_p[] = {
|
||||||
|
ngx_rtmp_eval_session,
|
||||||
|
ngx_rtmp_enotify_eval,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
ngx_rtmp_enotify_create_app_conf(ngx_conf_t *cf)
|
ngx_rtmp_enotify_create_app_conf(ngx_conf_t *cf)
|
||||||
{
|
{
|
||||||
@ -199,7 +268,7 @@ ngx_rtmp_enotify_exec(ngx_rtmp_session_t *s, ngx_rtmp_enotify_conf_t *ec)
|
|||||||
arg = ec->args.elts;
|
arg = ec->args.elts;
|
||||||
args[0] = (char *)ec->cmd.data;
|
args[0] = (char *)ec->cmd.data;
|
||||||
for (n = 0; n < ec->args.nelts; ++n, ++arg) {
|
for (n = 0; n < ec->args.nelts; ++n, ++arg) {
|
||||||
ngx_rtmp_eval(s, arg, ngx_rtmp_eval_session, &a);
|
ngx_rtmp_eval(s, arg, ngx_rtmp_enotify_eval_p, &a);
|
||||||
args[n + 1] = (char *) a.data;
|
args[n + 1] = (char *) a.data;
|
||||||
}
|
}
|
||||||
args[n + 1] = NULL;
|
args[n + 1] = NULL;
|
||||||
@ -382,6 +451,8 @@ ngx_rtmp_enotify_record_done(ngx_rtmp_session_t *s, ngx_rtmp_record_done_t *v)
|
|||||||
{
|
{
|
||||||
ngx_rtmp_enotify_app_conf_t *enacf;
|
ngx_rtmp_enotify_app_conf_t *enacf;
|
||||||
ngx_rtmp_enotify_conf_t *ec;
|
ngx_rtmp_enotify_conf_t *ec;
|
||||||
|
ngx_rtmp_enotify_ctx_t *ctx;
|
||||||
|
ngx_int_t n;
|
||||||
|
|
||||||
if (s->auto_pushed) {
|
if (s->auto_pushed) {
|
||||||
goto next;
|
goto next;
|
||||||
@ -398,6 +469,22 @@ ngx_rtmp_enotify_record_done(ngx_rtmp_session_t *s, ngx_rtmp_record_done_t *v)
|
|||||||
"enotify: record_done %V recorder=%V path='%V'",
|
"enotify: record_done %V recorder=%V path='%V'",
|
||||||
&ec->cmd, &v->recorder, &v->path);
|
&ec->cmd, &v->recorder, &v->path);
|
||||||
|
|
||||||
|
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_enotify_module);
|
||||||
|
if (ctx == NULL) {
|
||||||
|
goto next;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->recorder = v->recorder;
|
||||||
|
ctx->path = v->path;
|
||||||
|
ctx->filename = v->path;
|
||||||
|
|
||||||
|
for (n = ctx->filename.len;
|
||||||
|
n > 0 && !ngx_path_separator(ctx->filename.data[n - 1]);
|
||||||
|
--n);
|
||||||
|
|
||||||
|
ctx->filename.data += n;
|
||||||
|
ctx->filename.len -= n;
|
||||||
|
|
||||||
ngx_rtmp_enotify_exec(s, ec);
|
ngx_rtmp_enotify_exec(s, ec);
|
||||||
|
|
||||||
next:
|
next:
|
||||||
|
@ -80,24 +80,27 @@ ngx_rtmp_eval_append(ngx_rtmp_session_t *s, ngx_buf_t *b,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
ngx_rtmp_eval_append_var(ngx_rtmp_session_t *s, ngx_buf_t *b,
|
ngx_rtmp_eval_append_var(ngx_rtmp_session_t *s, ngx_buf_t *b,
|
||||||
ngx_rtmp_eval_t *e, ngx_str_t *name)
|
ngx_rtmp_eval_t **e, ngx_str_t *name)
|
||||||
{
|
{
|
||||||
ngx_uint_t k;
|
ngx_uint_t k;
|
||||||
ngx_str_t v;
|
ngx_str_t v;
|
||||||
|
ngx_rtmp_eval_t *ee;
|
||||||
|
|
||||||
for (k = 0; e->handler; ++k, ++e) {
|
for (; *e; ++e) {
|
||||||
if (e->name.len == name->len &&
|
for (k = 0, ee = *e; ee->handler; ++k, ++ee) {
|
||||||
ngx_memcmp(e->name.data, name->data, name->len) == 0)
|
if (ee->name.len == name->len &&
|
||||||
{
|
ngx_memcmp(ee->name.data, name->data, name->len) == 0)
|
||||||
e->handler(s, e, &v);
|
{
|
||||||
ngx_rtmp_eval_append(s, b, v.data, v.len);
|
ee->handler(s, ee, &v);
|
||||||
|
ngx_rtmp_eval_append(s, b, v.data, v.len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ngx_int_t
|
ngx_int_t
|
||||||
ngx_rtmp_eval(ngx_rtmp_session_t *s, ngx_str_t *in, ngx_rtmp_eval_t *e,
|
ngx_rtmp_eval(ngx_rtmp_session_t *s, ngx_str_t *in, ngx_rtmp_eval_t **e,
|
||||||
ngx_str_t *out)
|
ngx_str_t *out)
|
||||||
{
|
{
|
||||||
u_char c, *p;;
|
u_char c, *p;;
|
||||||
|
@ -31,7 +31,7 @@ extern ngx_rtmp_eval_t ngx_rtmp_eval_session[];
|
|||||||
|
|
||||||
|
|
||||||
ngx_int_t ngx_rtmp_eval(ngx_rtmp_session_t *s, ngx_str_t *in,
|
ngx_int_t ngx_rtmp_eval(ngx_rtmp_session_t *s, ngx_str_t *in,
|
||||||
ngx_rtmp_eval_t *e, ngx_str_t *out);
|
ngx_rtmp_eval_t **e, ngx_str_t *out);
|
||||||
|
|
||||||
|
|
||||||
#endif /* _NGX_RTMP_EVAL_H_INCLUDED_ */
|
#endif /* _NGX_RTMP_EVAL_H_INCLUDED_ */
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "ngx_rtmp_cmd_module.h"
|
#include "ngx_rtmp_cmd_module.h"
|
||||||
|
#include "ngx_rtmp_eval.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#ifdef HAVE_MALLOC_H
|
#ifdef HAVE_MALLOC_H
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
@ -121,6 +122,40 @@ ngx_module_t ngx_rtmp_exec_module = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
ngx_rtmp_exec_eval_cstr(ngx_rtmp_session_t *s, ngx_rtmp_eval_t *e,
|
||||||
|
ngx_str_t *ret)
|
||||||
|
{
|
||||||
|
ngx_rtmp_exec_ctx_t *ctx;
|
||||||
|
|
||||||
|
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_exec_module);
|
||||||
|
if (ctx == NULL) {
|
||||||
|
ret->len = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret->data = *(u_char **) ((u_char *) ctx + e->offset);
|
||||||
|
ret->len = ngx_strlen(ret->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ngx_rtmp_eval_t ngx_rtmp_exec_eval[] = {
|
||||||
|
|
||||||
|
{ ngx_string("name"),
|
||||||
|
ngx_rtmp_exec_eval_cstr,
|
||||||
|
offsetof(ngx_rtmp_exec_ctx_t, name) },
|
||||||
|
|
||||||
|
ngx_rtmp_null_eval
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static ngx_rtmp_eval_t * ngx_rtmp_exec_eval_p[] = {
|
||||||
|
ngx_rtmp_eval_session,
|
||||||
|
ngx_rtmp_exec_eval,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
ngx_rtmp_exec_create_app_conf(ngx_conf_t *cf)
|
ngx_rtmp_exec_create_app_conf(ngx_conf_t *cf)
|
||||||
{
|
{
|
||||||
@ -250,73 +285,6 @@ ngx_rtmp_exec_kill(ngx_rtmp_session_t *s, ngx_rtmp_exec_t *e, ngx_int_t term)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
ngx_rtmp_exec_append(ngx_str_t *result, u_char *data, size_t len)
|
|
||||||
{
|
|
||||||
if (len == 0) {
|
|
||||||
len = ngx_strlen(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* use malloc in child */
|
|
||||||
if (result->len == 0) {
|
|
||||||
result->data = malloc(len + 1);
|
|
||||||
result->len = len;
|
|
||||||
ngx_memcpy(result->data, data, len);
|
|
||||||
result->data[len] = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
result->data = realloc(result->data, result->len + len + 1);
|
|
||||||
ngx_memcpy(result->data + result->len, data, len);
|
|
||||||
result->len += len;
|
|
||||||
result->data[result->len] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static char *
|
|
||||||
ngx_rtmp_exec_prepare_arg(ngx_rtmp_session_t *s, ngx_str_t *arg)
|
|
||||||
{
|
|
||||||
ngx_rtmp_core_app_conf_t *cacf;
|
|
||||||
ngx_rtmp_exec_ctx_t *ctx;
|
|
||||||
u_char *p, *pp;
|
|
||||||
ngx_str_t result;
|
|
||||||
|
|
||||||
cacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_core_module);
|
|
||||||
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_exec_module);
|
|
||||||
|
|
||||||
/* substitute $app/${app} & $name/${name} */
|
|
||||||
ngx_str_set(&result, "");
|
|
||||||
pp = arg->data;
|
|
||||||
for ( ;; ) {
|
|
||||||
p = (u_char *)ngx_strchr(pp, '$');
|
|
||||||
ngx_rtmp_exec_append(&result, pp, p ? p - pp : 0);
|
|
||||||
if (p == NULL) {
|
|
||||||
return (char *)result.data;
|
|
||||||
}
|
|
||||||
pp = p + 1;
|
|
||||||
if (p != arg->data && p[-1] == '\\') {
|
|
||||||
goto dollar;
|
|
||||||
}
|
|
||||||
if (!ngx_strncmp(p + 1, "app", sizeof("app") - 1)
|
|
||||||
|| !ngx_strncmp(p + 1, "{app}", sizeof("{app}") - 1))
|
|
||||||
{
|
|
||||||
ngx_rtmp_exec_append(&result, cacf->name.data, cacf->name.len);
|
|
||||||
pp += (p[1] == '{' ? sizeof("{app}") - 1 : sizeof("app") - 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!ngx_strncmp(p + 1, "name", sizeof("name") - 1)
|
|
||||||
|| !ngx_strncmp(p + 1, "{name}", sizeof("{name}") - 1))
|
|
||||||
{
|
|
||||||
ngx_rtmp_exec_append(&result, ctx->name, 0);
|
|
||||||
pp += (p[1] == '{' ? sizeof("{name}") - 1 : sizeof("name") - 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
dollar:
|
|
||||||
ngx_rtmp_exec_append(&result, (u_char *)"$", 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t
|
static ngx_int_t
|
||||||
ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
|
ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
|
||||||
{
|
{
|
||||||
@ -328,7 +296,7 @@ ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
|
|||||||
int ret;
|
int ret;
|
||||||
ngx_rtmp_exec_conf_t *ec;
|
ngx_rtmp_exec_conf_t *ec;
|
||||||
ngx_rtmp_exec_t *e;
|
ngx_rtmp_exec_t *e;
|
||||||
ngx_str_t *arg;
|
ngx_str_t *arg, a;
|
||||||
char **args;
|
char **args;
|
||||||
|
|
||||||
eacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_exec_module);
|
eacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_exec_module);
|
||||||
@ -379,7 +347,8 @@ ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
|
|||||||
arg = ec->args.elts;
|
arg = ec->args.elts;
|
||||||
args[0] = (char *)ec->cmd.data;
|
args[0] = (char *)ec->cmd.data;
|
||||||
for (n = 0; n < ec->args.nelts; ++n, ++arg) {
|
for (n = 0; n < ec->args.nelts; ++n, ++arg) {
|
||||||
args[n + 1] = ngx_rtmp_exec_prepare_arg(s, arg);
|
ngx_rtmp_eval(s, arg, ngx_rtmp_exec_eval_p, &a);
|
||||||
|
args[n + 1] = (char *) a.data;
|
||||||
}
|
}
|
||||||
args[n + 1] = NULL;
|
args[n + 1] = NULL;
|
||||||
if (execvp((char *)ec->cmd.data, args) == -1) {
|
if (execvp((char *)ec->cmd.data, args) == -1) {
|
||||||
|
Reference in New Issue
Block a user