Mercurial > hg > nginx
comparison src/http/modules/perl/ngx_http_perl_module.c @ 3174:479fd46cd1c4
use ngx_conf_set_str_array_slot() for perl_require
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 28 Sep 2009 16:07:14 +0000 |
parents | 008a3462e1d0 |
children | cad19e8e0cc8 |
comparison
equal
deleted
inserted
replaced
3173:008a3462e1d0 | 3174:479fd46cd1c4 |
---|---|
12 | 12 |
13 typedef struct { | 13 typedef struct { |
14 PerlInterpreter *perl; | 14 PerlInterpreter *perl; |
15 HV *nginx; | 15 HV *nginx; |
16 ngx_str_t modules; | 16 ngx_str_t modules; |
17 ngx_array_t requires; | 17 ngx_array_t *requires; |
18 } ngx_http_perl_main_conf_t; | 18 } ngx_http_perl_main_conf_t; |
19 | 19 |
20 | 20 |
21 typedef struct { | 21 typedef struct { |
22 SV *sub; | 22 SV *sub; |
55 static void *ngx_http_perl_create_main_conf(ngx_conf_t *cf); | 55 static void *ngx_http_perl_create_main_conf(ngx_conf_t *cf); |
56 static char *ngx_http_perl_init_main_conf(ngx_conf_t *cf, void *conf); | 56 static char *ngx_http_perl_init_main_conf(ngx_conf_t *cf, void *conf); |
57 static void *ngx_http_perl_create_loc_conf(ngx_conf_t *cf); | 57 static void *ngx_http_perl_create_loc_conf(ngx_conf_t *cf); |
58 static char *ngx_http_perl_merge_loc_conf(ngx_conf_t *cf, void *parent, | 58 static char *ngx_http_perl_merge_loc_conf(ngx_conf_t *cf, void *parent, |
59 void *child); | 59 void *child); |
60 static char *ngx_http_perl_require(ngx_conf_t *cf, ngx_command_t *cmd, | |
61 void *conf); | |
62 static char *ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 60 static char *ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
63 static char *ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 61 static char *ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
64 | 62 |
65 #if (NGX_HAVE_PERL_MULTIPLICITY) | 63 #if (NGX_HAVE_PERL_MULTIPLICITY) |
66 static void ngx_http_perl_cleanup_perl(void *data); | 64 static void ngx_http_perl_cleanup_perl(void *data); |
79 offsetof(ngx_http_perl_main_conf_t, modules), | 77 offsetof(ngx_http_perl_main_conf_t, modules), |
80 NULL }, | 78 NULL }, |
81 | 79 |
82 { ngx_string("perl_require"), | 80 { ngx_string("perl_require"), |
83 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, | 81 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, |
84 ngx_http_perl_require, | 82 ngx_conf_set_str_array_slot, |
85 NGX_HTTP_MAIN_CONF_OFFSET, | 83 NGX_HTTP_MAIN_CONF_OFFSET, |
86 0, | 84 offsetof(ngx_http_perl_main_conf_t, requires), |
87 NULL }, | 85 NULL }, |
88 | 86 |
89 { ngx_string("perl"), | 87 { ngx_string("perl"), |
90 NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1, | 88 NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1, |
91 ngx_http_perl, | 89 ngx_http_perl, |
493 | 491 |
494 if (ngx_set_environment(cf->cycle, NULL) == NULL) { | 492 if (ngx_set_environment(cf->cycle, NULL) == NULL) { |
495 return NGX_CONF_ERROR; | 493 return NGX_CONF_ERROR; |
496 } | 494 } |
497 | 495 |
498 if (ngx_http_perl_run_requires(aTHX_ &pmcf->requires, cf->log) | 496 if (ngx_http_perl_run_requires(aTHX_ pmcf->requires, cf->log) |
499 != NGX_OK) | 497 != NGX_OK) |
500 { | 498 { |
501 return NGX_CONF_ERROR; | 499 return NGX_CONF_ERROR; |
502 } | 500 } |
503 | 501 |
599 "version " NGINX_VERSION " of nginx.pm is required, " | 597 "version " NGINX_VERSION " of nginx.pm is required, " |
600 "but %s was found", ver); | 598 "but %s was found", ver); |
601 goto fail; | 599 goto fail; |
602 } | 600 } |
603 | 601 |
604 if (ngx_http_perl_run_requires(aTHX_ &pmcf->requires, cf->log) != NGX_OK) { | 602 if (ngx_http_perl_run_requires(aTHX_ pmcf->requires, cf->log) != NGX_OK) { |
605 goto fail; | 603 goto fail; |
606 } | 604 } |
607 | 605 |
608 } | 606 } |
609 | 607 |
620 | 618 |
621 | 619 |
622 static ngx_int_t | 620 static ngx_int_t |
623 ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, ngx_log_t *log) | 621 ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, ngx_log_t *log) |
624 { | 622 { |
625 char **script; | |
626 u_char *err; | 623 u_char *err; |
627 STRLEN len; | 624 STRLEN len; |
625 ngx_str_t *script; | |
628 ngx_uint_t i; | 626 ngx_uint_t i; |
627 | |
628 if (requires == NGX_CONF_UNSET_PTR) { | |
629 return NGX_OK; | |
630 } | |
629 | 631 |
630 script = requires->elts; | 632 script = requires->elts; |
631 for (i = 0; i < requires->nelts; i++) { | 633 for (i = 0; i < requires->nelts; i++) { |
632 | 634 |
633 require_pv(script[i]); | 635 require_pv((char *) script[i].data); |
634 | 636 |
635 if (SvTRUE(ERRSV)) { | 637 if (SvTRUE(ERRSV)) { |
636 | 638 |
637 err = (u_char *) SvPV(ERRSV, len); | 639 err = (u_char *) SvPV(ERRSV, len); |
638 while (--len && (err[len] == CR || err[len] == LF)) { /* void */ } | 640 while (--len && (err[len] == CR || err[len] == LF)) { /* void */ } |
639 | 641 |
640 ngx_log_error(NGX_LOG_EMERG, log, 0, | 642 ngx_log_error(NGX_LOG_EMERG, log, 0, |
641 "require_pv(\"%s\") failed: \"%*s\"", | 643 "require_pv(\"%s\") failed: \"%*s\"", |
642 script[i], len + 1, err); | 644 script[i].data, len + 1, err); |
643 | 645 |
644 return NGX_ERROR; | 646 return NGX_ERROR; |
645 } | 647 } |
646 } | 648 } |
647 | 649 |
779 pmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_perl_main_conf_t)); | 781 pmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_perl_main_conf_t)); |
780 if (pmcf == NULL) { | 782 if (pmcf == NULL) { |
781 return NULL; | 783 return NULL; |
782 } | 784 } |
783 | 785 |
784 if (ngx_array_init(&pmcf->requires, cf->pool, 1, sizeof(u_char *)) | 786 pmcf->requires = NGX_CONF_UNSET_PTR; |
785 != NGX_OK) | |
786 { | |
787 return NULL; | |
788 } | |
789 | 787 |
790 return pmcf; | 788 return pmcf; |
791 } | 789 } |
792 | 790 |
793 | 791 |
890 return NGX_CONF_OK; | 888 return NGX_CONF_OK; |
891 } | 889 } |
892 | 890 |
893 | 891 |
894 static char * | 892 static char * |
895 ngx_http_perl_require(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
896 { | |
897 ngx_http_perl_main_conf_t *pmcf = conf; | |
898 | |
899 u_char **p; | |
900 ngx_str_t *value; | |
901 | |
902 value = cf->args->elts; | |
903 | |
904 p = ngx_array_push(&pmcf->requires); | |
905 | |
906 if (p == NULL) { | |
907 return NGX_CONF_ERROR; | |
908 } | |
909 | |
910 *p = value[1].data; | |
911 | |
912 return NGX_CONF_OK; | |
913 } | |
914 | |
915 | |
916 static char * | |
917 ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 893 ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
918 { | 894 { |
919 ngx_http_perl_loc_conf_t *plcf = conf; | 895 ngx_http_perl_loc_conf_t *plcf = conf; |
920 | 896 |
921 ngx_str_t *value; | 897 ngx_str_t *value; |