Access: simplified rule parser code.

This commit is contained in:
Ruslan Ermilov 2017-05-15 17:16:32 +03:00
parent 9961198879
commit b313bc4bd3
2 changed files with 16 additions and 28 deletions

View File

@ -309,28 +309,22 @@ ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_http_access_rule_un_t *rule_un; ngx_http_access_rule_un_t *rule_un;
#endif #endif
all = 0;
ngx_memzero(&cidr, sizeof(ngx_cidr_t)); ngx_memzero(&cidr, sizeof(ngx_cidr_t));
value = cf->args->elts; value = cf->args->elts;
all = (value[1].len == 3 && ngx_strcmp(value[1].data, "all") == 0); if (value[1].len == 3 && ngx_strcmp(value[1].data, "all") == 0) {
all = 1;
if (!all) {
#if (NGX_HAVE_UNIX_DOMAIN) #if (NGX_HAVE_UNIX_DOMAIN)
} else if (value[1].len == 5 && ngx_strcmp(value[1].data, "unix:") == 0) {
if (value[1].len == 5 && ngx_strcmp(value[1].data, "unix:") == 0) { cidr.family = AF_UNIX;
cidr.family = AF_UNIX;
rc = NGX_OK;
} else {
rc = ngx_ptocidr(&value[1], &cidr);
}
#else
rc = ngx_ptocidr(&value[1], &cidr);
#endif #endif
} else {
rc = ngx_ptocidr(&value[1], &cidr);
if (rc == NGX_ERROR) { if (rc == NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid parameter \"%V\"", &value[1]); "invalid parameter \"%V\"", &value[1]);

View File

@ -299,28 +299,22 @@ ngx_stream_access_rule(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_stream_access_rule_un_t *rule_un; ngx_stream_access_rule_un_t *rule_un;
#endif #endif
all = 0;
ngx_memzero(&cidr, sizeof(ngx_cidr_t)); ngx_memzero(&cidr, sizeof(ngx_cidr_t));
value = cf->args->elts; value = cf->args->elts;
all = (value[1].len == 3 && ngx_strcmp(value[1].data, "all") == 0); if (value[1].len == 3 && ngx_strcmp(value[1].data, "all") == 0) {
all = 1;
if (!all) {
#if (NGX_HAVE_UNIX_DOMAIN) #if (NGX_HAVE_UNIX_DOMAIN)
} else if (value[1].len == 5 && ngx_strcmp(value[1].data, "unix:") == 0) {
if (value[1].len == 5 && ngx_strcmp(value[1].data, "unix:") == 0) { cidr.family = AF_UNIX;
cidr.family = AF_UNIX;
rc = NGX_OK;
} else {
rc = ngx_ptocidr(&value[1], &cidr);
}
#else
rc = ngx_ptocidr(&value[1], &cidr);
#endif #endif
} else {
rc = ngx_ptocidr(&value[1], &cidr);
if (rc == NGX_ERROR) { if (rc == NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid parameter \"%V\"", &value[1]); "invalid parameter \"%V\"", &value[1]);