@@ -40,7 +40,7 @@ typedef struct {
40
40
ngx_str_t path ;
41
41
ngx_uint_t filter ;
42
42
ngx_str_t method ;
43
- ngx_rtmp_control_handler_t handler ;
43
+ ngx_array_t sessions ; /* ngx_rtmp_session_t * */
44
44
} ngx_rtmp_control_ctx_t ;
45
45
46
46
@@ -146,8 +146,9 @@ ngx_rtmp_control_record_handler(ngx_http_request_t *r, ngx_rtmp_session_t *s)
146
146
cacf = ngx_rtmp_get_module_app_conf (s , ngx_rtmp_core_module );
147
147
racf = cacf -> app_conf [ngx_rtmp_record_module .ctx_index ];
148
148
149
- ngx_str_null (& rec );
150
- ngx_http_arg (r , (u_char * ) "rec" , sizeof ("rec" ) - 1 , & rec );
149
+ if (ngx_http_arg (r , (u_char * ) "rec" , sizeof ("rec" ) - 1 , & rec ) != NGX_OK ) {
150
+ rec .len = 0 ;
151
+ }
151
152
152
153
rn = ngx_rtmp_record_find (racf , & rec );
153
154
if (rn == NGX_CONF_UNSET_UINT ) {
@@ -203,10 +204,9 @@ ngx_rtmp_control_redirect_handler(ngx_http_request_t *r, ngx_rtmp_session_t *s)
203
204
ngx_rtmp_control_ctx_t * ctx ;
204
205
ngx_rtmp_close_stream_t vc ;
205
206
206
- ngx_str_null (& name );
207
- ngx_http_arg (r , (u_char * ) "newname" , sizeof ("newname" ) - 1 , & name );
208
-
209
- if (name .len == 0 ) {
207
+ if (ngx_http_arg (r , (u_char * ) "newname" , sizeof ("newname" ) - 1 , & name )
208
+ != NGX_OK )
209
+ {
210
210
return "newname not specified" ;
211
211
}
212
212
@@ -260,7 +260,7 @@ ngx_rtmp_control_walk_session(ngx_http_request_t *r,
260
260
ngx_rtmp_live_ctx_t * lctx )
261
261
{
262
262
ngx_str_t addr , * paddr ;
263
- ngx_rtmp_session_t * s ;
263
+ ngx_rtmp_session_t * s , * * ss ;
264
264
ngx_rtmp_control_ctx_t * ctx ;
265
265
266
266
s = lctx -> session ;
@@ -269,10 +269,9 @@ ngx_rtmp_control_walk_session(ngx_http_request_t *r,
269
269
return NGX_CONF_OK ;
270
270
}
271
271
272
- ngx_str_null (& addr );
273
- ngx_http_arg (r , (u_char * ) "addr" , sizeof ("addr" ) - 1 , & addr );
274
-
275
- if (addr .len ) {
272
+ if (ngx_http_arg (r , (u_char * ) "addr" , sizeof ("addr" ) - 1 , & addr )
273
+ == NGX_OK )
274
+ {
276
275
paddr = & s -> connection -> addr_text ;
277
276
if (paddr -> len != addr .len ||
278
277
ngx_strncmp (paddr -> data , addr .data , addr .len ))
@@ -300,7 +299,14 @@ ngx_rtmp_control_walk_session(ngx_http_request_t *r,
300
299
break ;
301
300
}
302
301
303
- return ctx -> handler (r , s );
302
+ ss = ngx_array_push (& ctx -> sessions );
303
+ if (ss == NULL ) {
304
+ return "allocation error" ;
305
+ }
306
+
307
+ * ss = s ;
308
+
309
+ return NGX_CONF_OK ;
304
310
}
305
311
306
312
@@ -333,12 +339,10 @@ ngx_rtmp_control_walk_app(ngx_http_request_t *r,
333
339
ngx_rtmp_live_stream_t * ls ;
334
340
ngx_rtmp_live_app_conf_t * lacf ;
335
341
336
- ngx_memzero (& name , sizeof (name ));
337
- ngx_http_arg (r , (u_char * ) "name" , sizeof ("name" ) - 1 , & name );
338
-
339
342
lacf = cacf -> app_conf [ngx_rtmp_live_module .ctx_index ];
340
343
341
- if (name .len == 0 ) {
344
+ if (ngx_http_arg (r , (u_char * ) "name" , sizeof ("name" ) - 1 , & name ) != NGX_OK )
345
+ {
342
346
for (n = 0 ; n < (ngx_uint_t ) lacf -> nbuckets ; ++ n ) {
343
347
for (ls = lacf -> streams [n ]; ls ; ls = ls -> next ) {
344
348
s = ngx_rtmp_control_walk_stream (r , ls );
@@ -378,8 +382,9 @@ ngx_rtmp_control_walk_server(ngx_http_request_t *r,
378
382
const char * s ;
379
383
ngx_rtmp_core_app_conf_t * * pcacf ;
380
384
381
- ngx_memzero (& app , sizeof (app ));
382
- ngx_http_arg (r , (u_char * ) "app" , sizeof ("app" ) - 1 , & app );
385
+ if (ngx_http_arg (r , (u_char * ) "app" , sizeof ("app" ) - 1 , & app ) != NGX_OK ) {
386
+ app .len = 0 ;
387
+ }
383
388
384
389
pcacf = cscf -> applications .elts ;
385
390
@@ -401,12 +406,15 @@ ngx_rtmp_control_walk_server(ngx_http_request_t *r,
401
406
402
407
403
408
static const char *
404
- ngx_rtmp_control_walk (ngx_http_request_t * r )
409
+ ngx_rtmp_control_walk (ngx_http_request_t * r , ngx_rtmp_control_handler_t h )
405
410
{
406
411
ngx_rtmp_core_main_conf_t * cmcf = ngx_rtmp_core_main_conf ;
407
412
408
413
ngx_str_t srv ;
409
- ngx_uint_t sn ;
414
+ ngx_uint_t sn , n ;
415
+ const char * msg ;
416
+ ngx_rtmp_session_t * * s ;
417
+ ngx_rtmp_control_ctx_t * ctx ;
410
418
ngx_rtmp_core_srv_conf_t * * pcscf ;
411
419
412
420
sn = 0 ;
@@ -421,7 +429,22 @@ ngx_rtmp_control_walk(ngx_http_request_t *r)
421
429
pcscf = cmcf -> servers .elts ;
422
430
pcscf += sn ;
423
431
424
- return ngx_rtmp_control_walk_server (r , * pcscf );
432
+ msg = ngx_rtmp_control_walk_server (r , * pcscf );
433
+ if (msg != NGX_CONF_OK ) {
434
+ return msg ;
435
+ }
436
+
437
+ ctx = ngx_http_get_module_ctx (r , ngx_rtmp_control_module );
438
+
439
+ s = ctx -> sessions .elts ;
440
+ for (n = 0 ; n < ctx -> sessions .nelts ; n ++ ) {
441
+ msg = h (r , s [n ]);
442
+ if (msg != NGX_CONF_OK ) {
443
+ return msg ;
444
+ }
445
+ }
446
+
447
+ return NGX_CONF_OK ;
425
448
}
426
449
427
450
@@ -434,11 +457,9 @@ ngx_rtmp_control_record(ngx_http_request_t *r, ngx_str_t *method)
434
457
ngx_rtmp_control_ctx_t * ctx ;
435
458
436
459
ctx = ngx_http_get_module_ctx (r , ngx_rtmp_control_module );
437
-
438
460
ctx -> filter = NGX_RTMP_CONTROL_FILTER_PUBLISHER ;
439
- ctx -> handler = ngx_rtmp_control_record_handler ;
440
461
441
- msg = ngx_rtmp_control_walk (r );
462
+ msg = ngx_rtmp_control_walk (r , ngx_rtmp_control_record_handler );
442
463
if (msg != NGX_CONF_OK ) {
443
464
goto error ;
444
465
}
@@ -501,9 +522,7 @@ ngx_rtmp_control_drop(ngx_http_request_t *r, ngx_str_t *method)
501
522
goto error ;
502
523
}
503
524
504
- ctx -> handler = ngx_rtmp_control_drop_handler ;
505
-
506
- msg = ngx_rtmp_control_walk (r );
525
+ msg = ngx_rtmp_control_walk (r , ngx_rtmp_control_drop_handler );
507
526
if (msg != NGX_CONF_OK ) {
508
527
goto error ;
509
528
}
@@ -555,7 +574,6 @@ ngx_rtmp_control_redirect(ngx_http_request_t *r, ngx_str_t *method)
555
574
ngx_rtmp_control_ctx_t * ctx ;
556
575
557
576
ctx = ngx_http_get_module_ctx (r , ngx_rtmp_control_module );
558
- ctx -> handler = ngx_rtmp_control_redirect_handler ;
559
577
560
578
if (ctx -> method .len == sizeof ("publisher" ) - 1 &&
561
579
ngx_memcmp (ctx -> method .data , "publisher" , ctx -> method .len ) == 0 )
@@ -578,7 +596,7 @@ ngx_rtmp_control_redirect(ngx_http_request_t *r, ngx_str_t *method)
578
596
goto error ;
579
597
}
580
598
581
- msg = ngx_rtmp_control_walk (r );
599
+ msg = ngx_rtmp_control_walk (r , ngx_rtmp_control_redirect_handler );
582
600
if (msg != NGX_CONF_OK ) {
583
601
goto error ;
584
602
}
@@ -666,6 +684,10 @@ ngx_rtmp_control_handler(ngx_http_request_t *r)
666
684
667
685
ngx_http_set_ctx (r , ctx , ngx_rtmp_control_module );
668
686
687
+ if (ngx_array_init (& ctx -> sessions , r -> pool , 1 , sizeof (void * )) != NGX_OK ) {
688
+ return NGX_ERROR ;
689
+ }
690
+
669
691
ctx -> method = method ;
670
692
671
693
#define NGX_RTMP_CONTROL_SECTION (flag , secname ) \
@@ -689,7 +711,7 @@ ngx_rtmp_control_handler(ngx_http_request_t *r)
689
711
static void *
690
712
ngx_rtmp_control_create_loc_conf (ngx_conf_t * cf )
691
713
{
692
- ngx_rtmp_control_loc_conf_t * conf ;
714
+ ngx_rtmp_control_loc_conf_t * conf ;
693
715
694
716
conf = ngx_pcalloc (cf -> pool , sizeof (ngx_rtmp_control_loc_conf_t ));
695
717
if (conf == NULL ) {
@@ -705,8 +727,8 @@ ngx_rtmp_control_create_loc_conf(ngx_conf_t *cf)
705
727
static char *
706
728
ngx_rtmp_control_merge_loc_conf (ngx_conf_t * cf , void * parent , void * child )
707
729
{
708
- ngx_rtmp_control_loc_conf_t * prev = parent ;
709
- ngx_rtmp_control_loc_conf_t * conf = child ;
730
+ ngx_rtmp_control_loc_conf_t * prev = parent ;
731
+ ngx_rtmp_control_loc_conf_t * conf = child ;
710
732
711
733
ngx_conf_merge_bitmask_value (conf -> control , prev -> control , 0 );
712
734
0 commit comments