Mercurial > hg > nginx
comparison src/http/modules/ngx_http_limit_conn_module.c @ 5859:ad9116427acf
Limit conn: removed deprecated "limit_zone" directive.
It's deprecated since 260d591cb6a3 (1.1.8). The "limit_conn_zone" directive
should be used instead.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Wed, 24 Sep 2014 21:55:19 +0400 |
parents | 00e4459739ed |
children | c9787372f16d |
comparison
equal
deleted
inserted
replaced
5858:02c2352d5b01 | 5859:ad9116427acf |
---|---|
52 static void *ngx_http_limit_conn_create_conf(ngx_conf_t *cf); | 52 static void *ngx_http_limit_conn_create_conf(ngx_conf_t *cf); |
53 static char *ngx_http_limit_conn_merge_conf(ngx_conf_t *cf, void *parent, | 53 static char *ngx_http_limit_conn_merge_conf(ngx_conf_t *cf, void *parent, |
54 void *child); | 54 void *child); |
55 static char *ngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, | 55 static char *ngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, |
56 void *conf); | 56 void *conf); |
57 static char *ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd, | |
58 void *conf); | |
59 static char *ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, | 57 static char *ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, |
60 void *conf); | 58 void *conf); |
61 static ngx_int_t ngx_http_limit_conn_init(ngx_conf_t *cf); | 59 static ngx_int_t ngx_http_limit_conn_init(ngx_conf_t *cf); |
62 | |
63 | |
64 static ngx_conf_deprecated_t ngx_conf_deprecated_limit_zone = { | |
65 ngx_conf_deprecated, "limit_zone", "limit_conn_zone" | |
66 }; | |
67 | 60 |
68 | 61 |
69 static ngx_conf_enum_t ngx_http_limit_conn_log_levels[] = { | 62 static ngx_conf_enum_t ngx_http_limit_conn_log_levels[] = { |
70 { ngx_string("info"), NGX_LOG_INFO }, | 63 { ngx_string("info"), NGX_LOG_INFO }, |
71 { ngx_string("notice"), NGX_LOG_NOTICE }, | 64 { ngx_string("notice"), NGX_LOG_NOTICE }, |
83 static ngx_command_t ngx_http_limit_conn_commands[] = { | 76 static ngx_command_t ngx_http_limit_conn_commands[] = { |
84 | 77 |
85 { ngx_string("limit_conn_zone"), | 78 { ngx_string("limit_conn_zone"), |
86 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE2, | 79 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE2, |
87 ngx_http_limit_conn_zone, | 80 ngx_http_limit_conn_zone, |
88 0, | |
89 0, | |
90 NULL }, | |
91 | |
92 { ngx_string("limit_zone"), | |
93 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE3, | |
94 ngx_http_limit_zone, | |
95 0, | 81 0, |
96 0, | 82 0, |
97 NULL }, | 83 NULL }, |
98 | 84 |
99 { ngx_string("limit_conn"), | 85 { ngx_string("limit_conn"), |
616 return NGX_CONF_OK; | 602 return NGX_CONF_OK; |
617 } | 603 } |
618 | 604 |
619 | 605 |
620 static char * | 606 static char * |
621 ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
622 { | |
623 ssize_t n; | |
624 ngx_str_t *value; | |
625 ngx_shm_zone_t *shm_zone; | |
626 ngx_http_limit_conn_ctx_t *ctx; | |
627 | |
628 ngx_conf_deprecated(cf, &ngx_conf_deprecated_limit_zone, NULL); | |
629 | |
630 value = cf->args->elts; | |
631 | |
632 if (value[2].data[0] != '$') { | |
633 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
634 "invalid variable name \"%V\"", &value[2]); | |
635 return NGX_CONF_ERROR; | |
636 } | |
637 | |
638 value[2].len--; | |
639 value[2].data++; | |
640 | |
641 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_conn_ctx_t)); | |
642 if (ctx == NULL) { | |
643 return NGX_CONF_ERROR; | |
644 } | |
645 | |
646 ctx->index = ngx_http_get_variable_index(cf, &value[2]); | |
647 if (ctx->index == NGX_ERROR) { | |
648 return NGX_CONF_ERROR; | |
649 } | |
650 | |
651 ctx->var = value[2]; | |
652 | |
653 n = ngx_parse_size(&value[3]); | |
654 | |
655 if (n == NGX_ERROR) { | |
656 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
657 "invalid size of limit_zone \"%V\"", &value[3]); | |
658 return NGX_CONF_ERROR; | |
659 } | |
660 | |
661 if (n < (ngx_int_t) (8 * ngx_pagesize)) { | |
662 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
663 "limit_zone \"%V\" is too small", &value[1]); | |
664 return NGX_CONF_ERROR; | |
665 } | |
666 | |
667 | |
668 shm_zone = ngx_shared_memory_add(cf, &value[1], n, | |
669 &ngx_http_limit_conn_module); | |
670 if (shm_zone == NULL) { | |
671 return NGX_CONF_ERROR; | |
672 } | |
673 | |
674 if (shm_zone->data) { | |
675 ctx = shm_zone->data; | |
676 | |
677 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
678 "limit_zone \"%V\" is already bound to variable \"%V\"", | |
679 &value[1], &ctx->var); | |
680 return NGX_CONF_ERROR; | |
681 } | |
682 | |
683 shm_zone->init = ngx_http_limit_conn_init_zone; | |
684 shm_zone->data = ctx; | |
685 | |
686 return NGX_CONF_OK; | |
687 } | |
688 | |
689 | |
690 static char * | |
691 ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 607 ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
692 { | 608 { |
693 ngx_shm_zone_t *shm_zone; | 609 ngx_shm_zone_t *shm_zone; |
694 ngx_http_limit_conn_conf_t *lccf = conf; | 610 ngx_http_limit_conn_conf_t *lccf = conf; |
695 ngx_http_limit_conn_limit_t *limit, *limits; | 611 ngx_http_limit_conn_limit_t *limit, *limits; |