Skip to content

Commit 7a1bad6

Browse files
committed
[dev] moved hardcoded dir permissions and index filename to config.
1 parent f676ef4 commit 7a1bad6

File tree

1 file changed

+40
-33
lines changed

1 file changed

+40
-33
lines changed

hls/ngx_rtmp_hls_module.c

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ static ngx_rtmp_stream_begin_pt next_stream_begin;
1919
static ngx_rtmp_stream_eof_pt next_stream_eof;
2020

2121

22-
static char * ngx_rtmp_hls_variant(ngx_conf_t *cf, ngx_command_t *cmd,
22+
static char *ngx_rtmp_hls_variant(ngx_conf_t *cf, ngx_command_t *cmd,
2323
void *conf);
2424
static ngx_int_t ngx_rtmp_hls_postconfiguration(ngx_conf_t *cf);
25-
static void * ngx_rtmp_hls_create_app_conf(ngx_conf_t *cf);
26-
static char * ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf,
25+
static void *ngx_rtmp_hls_create_app_conf(ngx_conf_t *cf);
26+
static char *ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf,
2727
void *parent, void *child);
2828
static ngx_int_t ngx_rtmp_hls_flush_audio(ngx_rtmp_session_t *s);
2929
static ngx_int_t ngx_rtmp_hls_ensure_directory(ngx_rtmp_session_t *s,
3030
ngx_str_t *path);
31-
char * ngx_http_flv_set_permissions_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
31+
static char *ngx_rtmp_hls_set_permissions(ngx_conf_t *cf, ngx_command_t *cmd,
32+
void *conf);
3233

3334

3435
#define NGX_RTMP_HLS_BUFSIZE (1024*1024)
@@ -314,7 +315,7 @@ static ngx_command_t ngx_rtmp_hls_commands[] = {
314315

315316
{ ngx_string("hls_dir_access"),
316317
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
317-
ngx_http_flv_set_permissions_slot,
318+
ngx_rtmp_hls_set_permissions,
318319
NGX_RTMP_APP_CONF_OFFSET,
319320
offsetof(ngx_rtmp_hls_app_conf_t, dir_access),
320321
NULL },
@@ -467,7 +468,7 @@ ngx_rtmp_hls_write_variant_playlist(ngx_rtmp_session_t *s)
467468
ctx->name.len - ctx->var->suffix.len, ctx->name.data,
468469
&var->suffix);
469470
if (hacf->nested) {
470-
p = ngx_slprintf(p, last, "/%V", &hacf->nested_index_filename);
471+
p = ngx_slprintf(p, last, "/%V", &hacf->nested_index_filename);
471472
}
472473

473474
p = ngx_slprintf(p, last, "%s", ".m3u8\n");
@@ -1367,7 +1368,7 @@ ngx_rtmp_hls_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
13671368

13681369
len = hacf->path.len + 1 + ctx->name.len + sizeof(".m3u8");
13691370
if (hacf->nested) {
1370-
len += hacf->nested_index_filename.len + 1;
1371+
len += hacf->nested_index_filename.len + 1;
13711372
}
13721373

13731374
ctx->playlist.data = ngx_palloc(s->connection->pool, len);
@@ -1439,8 +1440,10 @@ ngx_rtmp_hls_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
14391440

14401441
if (hacf->nested) {
14411442
p = ngx_cpymem(p, "/", sizeof("/") - 1);
1442-
p = ngx_cpymem(p, hacf->nested_index_filename.data, hacf->nested_index_filename.len);
1443+
p = ngx_cpymem(p, hacf->nested_index_filename.data,
1444+
hacf->nested_index_filename.len);
14431445
}
1446+
14441447
p = ngx_cpymem(p, ".m3u8", sizeof(".m3u8") - 1);
14451448

14461449
ctx->playlist.len = p - ctx->playlist.data;
@@ -2339,44 +2342,47 @@ ngx_rtmp_hls_variant(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
23392342
return NGX_CONF_OK;
23402343
}
23412344

2342-
char *
2343-
ngx_http_flv_set_permissions_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2345+
2346+
static char *
2347+
ngx_rtmp_hls_set_permissions(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
23442348
{
2345-
char *p = conf;
2349+
ngx_rtmp_hls_app_conf_t *hacf = conf;
23462350

2347-
ngx_int_t *np;
2351+
size_t i;
2352+
ngx_uint_t f, base, step;
23482353
ngx_str_t *value;
2349-
ngx_conf_post_t *post;
2350-
ngx_uint_t i;
2351-
ngx_uint_t f;
2352-
2353-
np = (ngx_int_t *) (p + cmd->offset);
23542354

2355-
if (*np != NGX_CONF_UNSET) {
2355+
if (hacf->dir_access != NGX_CONF_UNSET_UINT) {
23562356
return "is duplicate";
23572357
}
23582358

23592359
value = cf->args->elts;
23602360
if (value[1].data[0] != '0') {
2361-
return "invalid octal : should start with 0";
2361+
return "invalid octal: should start with 0";
23622362
}
2363+
23632364
if (value[1].len != 4) {
2364-
return "invalid permission mask : should be exactly 4 characters long";
2365+
return "invalid permission mask: should be exactly 4 characters long";
2366+
}
2367+
2368+
hacf->dir_access = 0;
2369+
f = 1;
2370+
2371+
for (base = 8, step = 0; base != 1; base >>= 1) {
2372+
step++;
2373+
}
2374+
2375+
for (i = value[1].len - 2; i >= 1; i--) {
2376+
f <<= step;
23652377
}
2366-
*np = 0;
2367-
f = 64;
23682378

23692379
for (i = 1; i < value[1].len; i++) {
23702380
if (value[1].data[i] < '0' || value[1].data[i] > '7') {
2371-
return "invalid octal number";
2372-
}
2373-
*np += (value[1].data[i] - '0') * f;
2374-
f /= 8;
2375-
}
2381+
return "invalid octal number";
2382+
}
23762383

2377-
if (cmd->post) {
2378-
post = cmd->post;
2379-
return post->post_handler(cf, post, np);
2384+
hacf->dir_access += (value[1].data[i] - '0') * f;
2385+
f >>= step;
23802386
}
23812387

23822388
return NGX_CONF_OK;
@@ -2446,11 +2452,12 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
24462452
ngx_conf_merge_str_value(conf->base_url, prev->base_url, "");
24472453
ngx_conf_merge_value(conf->granularity, prev->granularity, 0);
24482454
ngx_conf_merge_value(conf->keys, prev->keys, 0);
2449-
/*ngx_conf_merge_str_value(conf->key_path, prev->key_path, "");*/
24502455
ngx_conf_merge_str_value(conf->key_url, prev->key_url, "");
24512456
ngx_conf_merge_uint_value(conf->frags_per_key, prev->frags_per_key, 0);
2452-
ngx_conf_merge_uint_value(conf->dir_access, prev->dir_access, NGX_RTMP_HLS_DEFAULT_DIR_ACCESS);
2453-
ngx_conf_merge_str_value(conf->nested_index_filename, prev->nested_index_filename, "index");
2457+
ngx_conf_merge_uint_value(conf->dir_access, prev->dir_access,
2458+
NGX_RTMP_HLS_DEFAULT_DIR_ACCESS);
2459+
ngx_conf_merge_str_value(conf->nested_index_filename,
2460+
prev->nested_index_filename, "index");
24542461

24552462
if (conf->fraglen) {
24562463
conf->winfrags = conf->playlen / conf->fraglen;

0 commit comments

Comments
 (0)