@@ -10,6 +10,7 @@ typedef ngx_int_t(*ngx_http_vod_param_parser_t)(ngx_str_t* value, void* output,
10
10
11
11
typedef struct {
12
12
int name_conf_offset ;
13
+ char * name ;
13
14
ngx_http_vod_param_parser_t parser ;
14
15
int target_offset ;
15
16
} ngx_http_vod_uri_param_def_t ;
@@ -361,41 +362,99 @@ ngx_http_vod_parse_tracks_param(ngx_str_t* value, void* output, int offset)
361
362
}
362
363
363
364
static ngx_http_vod_uri_param_def_t uri_param_defs [] = {
364
- { offsetof(ngx_http_vod_loc_conf_t , clip_to_param_name ), ngx_http_vod_parse_uint32_param , offsetof(media_clip_source_t , clip_to ) },
365
- { offsetof(ngx_http_vod_loc_conf_t , clip_from_param_name ), ngx_http_vod_parse_uint32_param , offsetof(media_clip_source_t , clip_from ) },
366
- { offsetof(ngx_http_vod_loc_conf_t , tracks_param_name ), ngx_http_vod_parse_tracks_param , offsetof(media_clip_source_t , tracks_mask ) },
367
- { offsetof(ngx_http_vod_loc_conf_t , speed_param_name ), NULL , 0 },
365
+ { offsetof(ngx_http_vod_loc_conf_t , clip_to_param_name ), "clip to" , ngx_http_vod_parse_uint32_param , offsetof(media_clip_source_t , clip_to ) },
366
+ { offsetof(ngx_http_vod_loc_conf_t , clip_from_param_name ), "clip from" , ngx_http_vod_parse_uint32_param , offsetof(media_clip_source_t , clip_from ) },
367
+ { offsetof(ngx_http_vod_loc_conf_t , tracks_param_name ), "tracks" , ngx_http_vod_parse_tracks_param , offsetof(media_clip_source_t , tracks_mask ) },
368
+ { offsetof(ngx_http_vod_loc_conf_t , speed_param_name ), "speed" , NULL , 0 },
369
+ { -1 , NULL , NULL , 0 }
368
370
};
369
371
370
- ngx_int_t
371
- ngx_http_vod_init_uri_params_hash (ngx_conf_t * cf , ngx_http_vod_loc_conf_t * conf )
372
+ static ngx_http_vod_uri_param_def_t pd_uri_param_defs [] = {
373
+ { offsetof(ngx_http_vod_loc_conf_t , clip_to_param_name ), "clip to" , ngx_http_vod_parse_uint32_param , offsetof(media_clip_source_t , clip_to ) },
374
+ { offsetof(ngx_http_vod_loc_conf_t , clip_from_param_name ), "clip from" , ngx_http_vod_parse_uint32_param , offsetof(media_clip_source_t , clip_from ) },
375
+ { -1 , NULL , NULL , 0 }
376
+ };
377
+
378
+ static ngx_int_t
379
+ ngx_http_vod_init_hash (
380
+ ngx_conf_t * cf ,
381
+ ngx_http_vod_uri_param_def_t * elements ,
382
+ ngx_http_vod_loc_conf_t * conf ,
383
+ char * hash_name ,
384
+ ngx_hash_t * output )
372
385
{
373
- ngx_hash_key_t hash_keys [sizeof (uri_param_defs ) / sizeof (uri_param_defs [0 ])];
386
+ ngx_http_vod_uri_param_def_t * element ;
387
+ ngx_array_t elements_arr ;
388
+ ngx_hash_key_t * hash_key ;
374
389
ngx_hash_init_t hash ;
375
- ngx_str_t * param_name ;
376
- ngx_int_t rc ;
377
- unsigned i ;
390
+ ngx_str_t * cur_key ;
378
391
379
- for ( i = 0 ; i < sizeof (hash_keys ) / sizeof ( hash_keys [ 0 ]); i ++ )
392
+ if ( ngx_array_init ( & elements_arr , cf -> temp_pool , 32 , sizeof (ngx_hash_key_t )) != NGX_OK )
380
393
{
381
- param_name = (ngx_str_t * )((u_char * )conf + uri_param_defs [i ].name_conf_offset );
382
- hash_keys [i ].key = * param_name ;
383
- hash_keys [i ].key_hash = ngx_hash_key_lc (param_name -> data , param_name -> len );
384
- hash_keys [i ].value = & uri_param_defs [i ];
394
+ return NGX_ERROR ;
385
395
}
386
396
387
- hash .hash = & conf -> uri_params_hash ;
388
- hash .key = ngx_hash_key ;
397
+ for (element = elements ; element -> name_conf_offset >= 0 ; element ++ )
398
+ {
399
+ cur_key = (ngx_str_t * )((u_char * )conf + element -> name_conf_offset );
400
+ if (cur_key -> len == 0 )
401
+ {
402
+ break ;
403
+ }
404
+
405
+ hash_key = ngx_array_push (& elements_arr );
406
+ if (hash_key == NULL )
407
+ {
408
+ return NGX_ERROR ;
409
+ }
410
+
411
+ hash_key -> key = * cur_key ;
412
+ hash_key -> key_hash = ngx_hash_key_lc (cur_key -> data , cur_key -> len );
413
+ hash_key -> value = element ;
414
+ }
415
+
416
+ hash .hash = output ;
417
+ hash .key = ngx_hash_key_lc ;
389
418
hash .max_size = 512 ;
390
419
hash .bucket_size = ngx_align (64 , ngx_cacheline_size );
391
- hash .name = "uri_params_hash" ;
420
+ hash .name = hash_name ;
392
421
hash .pool = cf -> pool ;
393
422
hash .temp_pool = NULL ;
394
423
395
- rc = ngx_hash_init (& hash , hash_keys , sizeof (hash_keys ) / sizeof (hash_keys [0 ]));
424
+ if (ngx_hash_init (& hash , elements_arr .elts , elements_arr .nelts ) != NGX_OK )
425
+ {
426
+ return NGX_ERROR ;
427
+ }
428
+
429
+ return NGX_OK ;
430
+ }
431
+
432
+ ngx_int_t
433
+ ngx_http_vod_init_uri_params_hash (ngx_conf_t * cf , ngx_http_vod_loc_conf_t * conf )
434
+ {
435
+ ngx_int_t rc ;
436
+
437
+ rc = ngx_http_vod_init_hash (
438
+ cf ,
439
+ uri_param_defs ,
440
+ conf ,
441
+ "uri_params_hash" ,
442
+ & conf -> uri_params_hash );
443
+ if (rc != NGX_OK )
444
+ {
445
+ ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 , "failed to initialize uri params hash" );
446
+ return rc ;
447
+ }
448
+
449
+ rc = ngx_http_vod_init_hash (
450
+ cf ,
451
+ pd_uri_param_defs ,
452
+ conf ,
453
+ "pd_uri_params_hash" ,
454
+ & conf -> pd_uri_params_hash );
396
455
if (rc != NGX_OK )
397
456
{
398
- ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 , "ngx_hash_init failed %i" , rc );
457
+ ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 , "failed to initialize progressive download uri params hash" );
399
458
return rc ;
400
459
}
401
460
@@ -405,7 +464,7 @@ ngx_http_vod_init_uri_params_hash(ngx_conf_t *cf, ngx_http_vod_loc_conf_t* conf)
405
464
static ngx_int_t
406
465
ngx_http_vod_extract_uri_params (
407
466
ngx_http_request_t * r ,
408
- ngx_http_vod_loc_conf_t * conf ,
467
+ ngx_hash_t * params_hash ,
409
468
ngx_str_t * uri ,
410
469
media_sequence_t * sequence ,
411
470
uint32_t * clip_id ,
@@ -476,7 +535,7 @@ ngx_http_vod_extract_uri_params(
476
535
477
536
if (param_def == NULL )
478
537
{
479
- param_def = ngx_hash_find (& conf -> uri_params_hash , cur_key_hash , param_name , param_name_pos - param_name );
538
+ param_def = ngx_hash_find (params_hash , cur_key_hash , param_name , param_name_pos - param_name );
480
539
if (param_def != NULL )
481
540
{
482
541
p = ngx_copy (p , copy_start , last_slash - copy_start );
@@ -516,8 +575,7 @@ ngx_http_vod_extract_uri_params(
516
575
if (rc != NGX_OK )
517
576
{
518
577
ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 ,
519
- "ngx_http_vod_extract_uri_params: %V parser failed %i" ,
520
- (ngx_str_t * )((u_char * )conf + param_def -> name_conf_offset ), rc );
578
+ "ngx_http_vod_extract_uri_params: %s parser failed %i" , param_def -> name , rc );
521
579
return rc ;
522
580
}
523
581
}
@@ -550,7 +608,8 @@ ngx_http_vod_extract_uri_params(
550
608
ngx_int_t
551
609
ngx_http_vod_parse_uri_path (
552
610
ngx_http_request_t * r ,
553
- ngx_http_vod_loc_conf_t * conf ,
611
+ ngx_str_t * multi_uri_suffix ,
612
+ ngx_hash_t * params_hash ,
554
613
ngx_str_t * uri ,
555
614
request_params_t * request_params ,
556
615
media_set_t * media_set )
@@ -570,7 +629,7 @@ ngx_http_vod_parse_uri_path(
570
629
uint32_t i ;
571
630
int uri_count ;
572
631
573
- rc = ngx_http_vod_parse_multi_uri (r , uri , & conf -> multi_uri_suffix , & multi_uri );
632
+ rc = ngx_http_vod_parse_multi_uri (r , uri , multi_uri_suffix , & multi_uri );
574
633
if (rc != NGX_OK )
575
634
{
576
635
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
@@ -634,7 +693,7 @@ ngx_http_vod_parse_uri_path(
634
693
return rc ;
635
694
}
636
695
637
- rc = ngx_http_vod_extract_uri_params (r , conf , & cur_uri , cur_sequence , & clip_id , cur_source , & cur_clip );
696
+ rc = ngx_http_vod_extract_uri_params (r , params_hash , & cur_uri , cur_sequence , & clip_id , cur_source , & cur_clip );
638
697
if (rc != NGX_OK )
639
698
{
640
699
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
0 commit comments