Klaus Demo nginx / 0c2fd4a
use complex values in add_header, auth_basic_user_file, sub_filter, and xslt_stylesheet parameters Igor Sysoev 13 years ago
4 changed file(s) with 121 addition(s) and 214 deletion(s). Raw diff Collapse all Expand all
1212
1313
1414 typedef struct {
15 ngx_str_t passwd;
15 ngx_str_t passwd;
1616 } ngx_http_auth_basic_ctx_t;
1717
1818
1919 typedef struct {
20 ngx_str_t realm;
21 ngx_str_t user_file;
22 ngx_array_t *user_file_lengths;
23 ngx_array_t *user_file_values;
20 ngx_str_t realm;
21 ngx_http_complex_value_t user_file;
2422 } ngx_http_auth_basic_loc_conf_t;
2523
2624
116114
117115 alcf = ngx_http_get_module_loc_conf(r, ngx_http_auth_basic_module);
118116
119 if (alcf->realm.len == 0 || alcf->user_file.len == 0) {
117 if (alcf->realm.len == 0 || alcf->user_file.value.len == 0) {
120118 return NGX_DECLINED;
121119 }
122120
141139 return NGX_HTTP_INTERNAL_SERVER_ERROR;
142140 }
143141
144 if (alcf->user_file_lengths) {
145 if (ngx_http_script_run(r, &user_file, alcf->user_file_lengths->elts, 1,
146 alcf->user_file_values->elts)
147 == NULL)
148 {
149 return NGX_ERROR;
150 }
151
152 user_file.data[--user_file.len] = '\0';
153
154 } else {
155 user_file = alcf->user_file;
142 if (ngx_http_complex_value(r, &alcf->user_file, &user_file) != NGX_OK) {
143 return NGX_ERROR;
156144 }
157145
158146 fd = ngx_open_file(user_file.data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0);
400388 conf->realm = prev->realm;
401389 }
402390
403 if (conf->user_file.data == NULL) {
391 if (conf->user_file.value.len == 0) {
404392 conf->user_file = prev->user_file;
405 conf->user_file_lengths = prev->user_file_lengths;
406 conf->user_file_values = prev->user_file_values;
407393 }
408394
409395 return NGX_CONF_OK;
467453 {
468454 ngx_http_auth_basic_loc_conf_t *alcf = conf;
469455
470 ngx_str_t *value;
471 ngx_uint_t n;
472 ngx_http_script_compile_t sc;
473
474 if (alcf->user_file.data) {
456 ngx_str_t *value;
457 ngx_http_compile_complex_value_t ccv;
458
459 if (alcf->user_file.value.len) {
475460 return "is duplicate";
476461 }
477462
478463 value = cf->args->elts;
479464
480 alcf->user_file = value[1];
481
482 if (alcf->user_file.len == 0) {
483 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
484 "invalid parameter \"%V\"", &alcf->user_file);
465 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
466
467 ccv.cf = cf;
468 ccv.value = &value[1];
469 ccv.complex_value = &alcf->user_file;
470 ccv.zero = 1;
471 ccv.conf_prefix = 1;
472
473 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
485474 return NGX_CONF_ERROR;
486475 }
487476
488 if (alcf->user_file.data[0] != '$') {
489 if (ngx_conf_full_name(cf->cycle, &alcf->user_file, 1) != NGX_OK) {
490 return NGX_CONF_ERROR;
491 }
492 }
493
494 n = ngx_http_script_variables_count(&alcf->user_file);
495
496 if (n == 0) {
497 return NGX_CONF_OK;
498 }
499
500 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
501
502 sc.cf = cf;
503 sc.source = &alcf->user_file;
504 sc.lengths = &alcf->user_file_lengths;
505 sc.values = &alcf->user_file_values;
506 sc.variables = n;
507 sc.complete_lengths = 1;
508 sc.complete_values = 1;
509
510 if (ngx_http_script_compile(&sc) != NGX_OK) {
511 return NGX_CONF_ERROR;
512 }
513
514477 return NGX_CONF_OK;
515478 }
1515
1616
1717 typedef struct {
18 ngx_str_t name;
19 ngx_uint_t offset;
20 ngx_http_set_header_pt handler;
18 ngx_str_t name;
19 ngx_uint_t offset;
20 ngx_http_set_header_pt handler;
2121 } ngx_http_set_header_t;
2222
2323
2424 struct ngx_http_header_val_s {
25 ngx_table_elt_t value;
26 ngx_uint_t offset;
27 ngx_http_set_header_pt handler;
28 ngx_array_t *lengths;
29 ngx_array_t *values;
25 ngx_http_complex_value_t value;
26 ngx_uint_t hash;
27 ngx_str_t key;
28 ngx_http_set_header_pt handler;
29 ngx_uint_t offset;
3030 };
3131
3232
161161 h = conf->headers->elts;
162162 for (i = 0; i < conf->headers->nelts; i++) {
163163
164 if (h[i].lengths == NULL) {
165 value = h[i].value.value;
166
167 } else {
168 if (ngx_http_script_run(r, &value, h[i].lengths->elts, 0,
169 h[i].values->elts)
170 == NULL)
171 {
172 return NGX_ERROR;
173 }
164 if (ngx_http_complex_value(r, &h[i].value, &value) != NGX_OK) {
165 return NGX_ERROR;
174166 }
175167
176168 if (h[i].handler(r, &h[i], &value) != NGX_OK) {
330322 return NGX_ERROR;
331323 }
332324
333 h->hash = hv->value.hash;
334 h->key = hv->value.key;
325 h->hash = hv->hash;
326 h->key = hv->key;
335327 h->value = *value;
336328 }
337329
413405 }
414406 }
415407
416 h->hash = hv->value.hash;
417 h->key = hv->value.key;
408 h->hash = hv->hash;
409 h->key = hv->key;
418410 h->value = *value;
419411
420412 return NGX_OK;
577569 {
578570 ngx_http_headers_conf_t *hcf = conf;
579571
580 ngx_int_t n;
581 ngx_str_t *value;
582 ngx_uint_t i;
583 ngx_http_header_val_t *h;
584 ngx_http_set_header_t *sh;
585 ngx_http_script_compile_t sc;
572 ngx_str_t *value;
573 ngx_uint_t i;
574 ngx_http_header_val_t *hv;
575 ngx_http_set_header_t *set;
576 ngx_http_compile_complex_value_t ccv;
586577
587578 value = cf->args->elts;
588579
594585 }
595586 }
596587
597 h = ngx_array_push(hcf->headers);
598 if (h == NULL) {
588 hv = ngx_array_push(hcf->headers);
589 if (hv == NULL) {
599590 return NGX_CONF_ERROR;
600591 }
601592
602 h->value.hash = 1;
603 h->value.key = value[1];
604 h->value.value = value[2];
605 h->offset = 0;
606 h->handler = ngx_http_add_header;
607 h->lengths = NULL;
608 h->values = NULL;
609
610 sh = ngx_http_set_headers;
611 for (i = 0; sh[i].name.len; i++) {
612 if (ngx_strcasecmp(value[1].data, sh[i].name.data) != 0) {
593 hv->hash = 1;
594 hv->key = value[1];
595 hv->handler = ngx_http_add_header;
596 hv->offset = 0;
597
598 set = ngx_http_set_headers;
599 for (i = 0; set[i].name.len; i++) {
600 if (ngx_strcasecmp(value[1].data, set[i].name.data) != 0) {
613601 continue;
614602 }
615603
616 h->offset = sh[i].offset;
617 h->handler = sh[i].handler;
604 hv->offset = set[i].offset;
605 hv->handler = set[i].handler;
606
618607 break;
619608 }
620609
621 n = ngx_http_script_variables_count(&value[2]);
622
623 if (n == 0) {
624 return NGX_CONF_OK;
625 }
626
627 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
628
629 sc.cf = cf;
630 sc.source = &value[2];
631 sc.lengths = &h->lengths;
632 sc.values = &h->values;
633 sc.variables = n;
634 sc.complete_lengths = 1;
635 sc.complete_values = 1;
636
637 if (ngx_http_script_compile(&sc) != NGX_OK) {
610 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
611
612 ccv.cf = cf;
613 ccv.value = &value[2];
614 ccv.complex_value = &hv->value;
615
616 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
638617 return NGX_CONF_ERROR;
639618 }
640619
99
1010
1111 typedef struct {
12 ngx_str_t match;
13 ngx_str_t sub;
14
15 ngx_hash_t types;
16
17 ngx_array_t *sub_lengths;
18 ngx_array_t *sub_values;
19
20 ngx_flag_t once;
21
22 ngx_array_t *types_keys;
12 ngx_str_t match;
13 ngx_http_complex_value_t value;
14
15 ngx_hash_t types;
16
17 ngx_flag_t once;
18
19 ngx_array_t *types_keys;
2320 } ngx_http_sub_loc_conf_t;
2421
2522
3027
3128
3229 typedef struct {
33 ngx_str_t match;
34
35 ngx_uint_t once; /* unsigned once:1 */
36
37 ngx_buf_t *buf;
38
39 u_char *pos;
40 u_char *copy_start;
41 u_char *copy_end;
42
43 ngx_chain_t *in;
44 ngx_chain_t *out;
45 ngx_chain_t **last_out;
46 ngx_chain_t *busy;
47 ngx_chain_t *free;
48
49 ngx_str_t sub;
50
51 ngx_uint_t state;
52 size_t saved;
53 size_t looked;
30 ngx_str_t match;
31
32 ngx_uint_t once; /* unsigned once:1 */
33
34 ngx_buf_t *buf;
35
36 u_char *pos;
37 u_char *copy_start;
38 u_char *copy_end;
39
40 ngx_chain_t *in;
41 ngx_chain_t *out;
42 ngx_chain_t **last_out;
43 ngx_chain_t *busy;
44 ngx_chain_t *free;
45
46 ngx_str_t sub;
47
48 ngx_uint_t state;
49 size_t saved;
50 size_t looked;
5451 } ngx_http_sub_ctx_t;
5552
5653
153150
154151 ctx->match = slcf->match;
155152 ctx->last_out = &ctx->out;
156 ctx->sub = slcf->sub;
157153
158154 r->filter_need_in_memory = 1;
159155
345341
346342 if (ctx->sub.data == NULL) {
347343
348 if (ngx_http_script_run(r, &ctx->sub, slcf->sub_lengths->elts,
349 0, slcf->sub_values->elts)
350 == NULL)
344 if (ngx_http_complex_value(r, &slcf->value, &ctx->sub)
345 != NGX_OK)
351346 {
352347 return NGX_ERROR;
353348 }
608603 {
609604 ngx_http_sub_loc_conf_t *slcf = conf;
610605
611 ngx_str_t *value;
612 ngx_int_t n;
613 ngx_http_script_compile_t sc;
606 ngx_str_t *value;
607 ngx_http_compile_complex_value_t ccv;
614608
615609 if (slcf->match.len) {
616610 return "is duplicate";
622616
623617 slcf->match = value[1];
624618
625 n = ngx_http_script_variables_count(&value[2]);
626
627 if (n == 0) {
628 slcf->sub = value[2];
629 return NGX_CONF_OK;
630 }
631
632 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
633
634 sc.cf = cf;
635 sc.source = &value[2];
636 sc.lengths = &slcf->sub_lengths;
637 sc.values = &slcf->sub_values;
638 sc.variables = n;
639 sc.complete_lengths = 1;
640 sc.complete_values = 1;
641
642 if (ngx_http_script_compile(&sc) != NGX_OK) {
619 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
620
621 ccv.cf = cf;
622 ccv.value = &value[2];
623 ccv.complex_value = &slcf->value;
624
625 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
643626 return NGX_CONF_ERROR;
644627 }
645628
683666 ngx_conf_merge_value(conf->once, prev->once, 1);
684667 ngx_conf_merge_str_value(conf->match, prev->match, "");
685668
686 if (conf->sub.data == NULL && conf->sub_lengths == NULL) {
687 conf->sub = prev->sub;
688 conf->sub_lengths = prev->sub_lengths;
689 conf->sub_values = prev->sub_values;
669 if (conf->value.value.len == 0) {
670 conf->value = prev->value;
690671 }
691672
692673 if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
3737
3838
3939 typedef struct {
40 ngx_array_t *lengths;
41 ngx_array_t *values;
42 } ngx_http_xslt_param_t;
43
44
45 typedef struct {
4640 xsltStylesheetPtr stylesheet;
47 ngx_array_t params; /* ngx_http_xslt_param_t */
41 ngx_array_t params; /* ngx_http_complex_value_t */
4842 } ngx_http_xslt_sheet_t;
4943
5044
866860 ngx_http_xslt_params(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx,
867861 ngx_array_t *params)
868862 {
869 u_char *p, *last, *value, *dst, *src, **s;
870 size_t len;
871 ngx_uint_t i;
872 ngx_str_t string;
873 ngx_http_xslt_param_t *param;
863 u_char *p, *last, *value, *dst, *src, **s;
864 size_t len;
865 ngx_uint_t i;
866 ngx_str_t string;
867 ngx_http_complex_value_t *param;
874868
875869 param = params->elts;
876870
877871 for (i = 0; i < params->nelts; i++) {
878872
879 if (ngx_http_script_run(r, &string, param[i].lengths->elts, 1,
880 param[i].values->elts)
881 == NULL)
882 {
873 if (ngx_http_complex_value(r, &param[i], &string) != NGX_OK) {
883874 return NGX_ERROR;
884875 }
885
886 last = string.data + string.len - 1;
887 *last = '\0';
888876
889877 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
890878 "xslt filter param: \"%s\"", string.data);
891879
892880 p = string.data;
881 last = string.data + string.len - 1;
893882
894883 while (p && *p) {
895884
10721061 ngx_pool_cleanup_t *cln;
10731062 ngx_http_xslt_file_t *file;
10741063 ngx_http_xslt_sheet_t *sheet;
1075 ngx_http_xslt_param_t *param;
1076 ngx_http_script_compile_t sc;
1064 ngx_http_complex_value_t *param;
1065 ngx_http_compile_complex_value_t ccv;
10771066 ngx_http_xslt_filter_main_conf_t *xmcf;
10781067
10791068 value = cf->args->elts;
11411130 }
11421131
11431132 if (ngx_array_init(&sheet->params, cf->pool, n - 2,
1144 sizeof(ngx_http_xslt_param_t))
1133 sizeof(ngx_http_complex_value_t))
11451134 != NGX_OK)
11461135 {
11471136 return NGX_CONF_ERROR;
11541143 return NGX_CONF_ERROR;
11551144 }
11561145
1157 param->lengths = NULL;
1158 param->values = NULL;
1159
1160 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
1161
1162 sc.cf = cf;
1163 sc.source = &value[i];
1164 sc.lengths = &param->lengths;
1165 sc.values = &param->values;
1166 sc.variables = ngx_http_script_variables_count(&value[i]);
1167 sc.complete_lengths = 1;
1168 sc.complete_values = 1;
1169
1170 if (ngx_http_script_compile(&sc) != NGX_OK) {
1146 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1147
1148 ccv.cf = cf;
1149 ccv.value = &value[i];
1150 ccv.complex_value = param;
1151 ccv.zero = 1;
1152
1153 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
11711154 return NGX_CONF_ERROR;
11721155 }
1156
11731157 }
11741158
11751159 return NGX_CONF_OK;