Skip to content

Commit

Permalink
Use NGX_MAX_PATH_LEVEL where appropriate.
Browse files Browse the repository at this point in the history
The macro was unused since 0.7.44.
  • Loading branch information
mdocguard committed Jul 6, 2016
1 parent 5c4ca2a commit 6810b9f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
19 changes: 9 additions & 10 deletions src/core/ngx_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ ngx_create_hashed_filename(ngx_path_t *path, u_char *file, size_t len)

file[path->name.len + path->len] = '/';

for (n = 0; n < 3; n++) {
for (n = 0; n < NGX_MAX_PATH_LEVEL; n++) {
level = path->level[n];

if (level == 0) {
Expand All @@ -249,7 +249,7 @@ ngx_create_path(ngx_file_t *file, ngx_path_t *path)

pos = path->name.len;

for (i = 0; i < 3; i++) {
for (i = 0; i < NGX_MAX_PATH_LEVEL; i++) {
if (path->level[i] == 0) {
break;
}
Expand Down Expand Up @@ -399,6 +399,8 @@ char *
ngx_conf_merge_path_value(ngx_conf_t *cf, ngx_path_t **path, ngx_path_t *prev,
ngx_path_init_t *init)
{
ngx_uint_t i;

if (*path) {
return NGX_CONF_OK;
}
Expand All @@ -419,13 +421,10 @@ ngx_conf_merge_path_value(ngx_conf_t *cf, ngx_path_t **path, ngx_path_t *prev,
return NGX_CONF_ERROR;
}

(*path)->level[0] = init->level[0];
(*path)->level[1] = init->level[1];
(*path)->level[2] = init->level[2];

(*path)->len = init->level[0] + (init->level[0] ? 1 : 0)
+ init->level[1] + (init->level[1] ? 1 : 0)
+ init->level[2] + (init->level[2] ? 1 : 0);
for (i = 0; i < NGX_MAX_PATH_LEVEL; i++) {
(*path)->level[i] = init->level[i];
(*path)->len += init->level[i] + (init->level[i] ? 1 : 0);
}

if (ngx_add_path(cf, path) != NGX_OK) {
return NGX_CONF_ERROR;
Expand Down Expand Up @@ -518,7 +517,7 @@ ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot)
return NGX_ERROR;
}

for (n = 0; n < 3; n++) {
for (n = 0; n < NGX_MAX_PATH_LEVEL; n++) {
if (p[i]->level[n] != path->level[n]) {
if (path->conf_file == NULL) {
if (p[i]->conf_file == NULL) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/ngx_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typedef void (*ngx_path_loader_pt) (void *data);
typedef struct {
ngx_str_t name;
size_t len;
size_t level[3];
size_t level[NGX_MAX_PATH_LEVEL];

ngx_path_manager_pt manager;
ngx_path_loader_pt loader;
Expand All @@ -62,7 +62,7 @@ typedef struct {

typedef struct {
ngx_str_t name;
size_t level[3];
size_t level[NGX_MAX_PATH_LEVEL];
} ngx_path_init_t;


Expand Down
10 changes: 5 additions & 5 deletions src/http/ngx_http_file_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
return NGX_ERROR;
}

for (n = 0; n < 3; n++) {
for (n = 0; n < NGX_MAX_PATH_LEVEL; n++) {
if (cache->path->level[n] != ocache->path->level[n]) {
ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
"cache \"%V\" had previously different levels",
Expand Down Expand Up @@ -2257,7 +2257,7 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
p = value[i].data + 7;
last = value[i].data + value[i].len;

for (n = 0; n < 3 && p < last; n++) {
for (n = 0; n < NGX_MAX_PATH_LEVEL && p < last; n++) {

if (*p > '0' && *p < '3') {

Expand All @@ -2268,7 +2268,7 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
break;
}

if (*p++ == ':' && n < 2 && p != last) {
if (*p++ == ':' && n < NGX_MAX_PATH_LEVEL - 1 && p < last) {
continue;
}

Expand All @@ -2278,7 +2278,7 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
goto invalid_levels;
}

if (cache->path->len < 10 + 3) {
if (cache->path->len < 10 + NGX_MAX_PATH_LEVEL) {
continue;
}

Expand Down Expand Up @@ -2450,7 +2450,7 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_memcpy(p, "/temp", sizeof("/temp"));

ngx_memcpy(&cache->temp_path->level, &cache->path->level,
3 * sizeof(size_t));
NGX_MAX_PATH_LEVEL * sizeof(size_t));

cache->temp_path->len = cache->path->len;
cache->temp_path->conf_file = cf->conf_file->file.name.data;
Expand Down

0 comments on commit 6810b9f

Please sign in to comment.