Mercurial > hg > nginx
annotate src/core/ngx_file.c @ 1601:cba2bb1796e4
change emerg to a warn for absolute index
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 23 Oct 2007 14:15:06 +0000 |
parents | e958b3cab51a |
children | 8c4532a48b0a |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
5 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
495 | 11 static ngx_atomic_uint_t ngx_temp_number; |
800 | 12 static ngx_atomic_uint_t ngx_random_number; |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
13 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
14 |
493 | 15 ssize_t |
16 ngx_write_chain_to_temp_file(ngx_temp_file_t *tf, ngx_chain_t *chain) | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
17 { |
467 | 18 ngx_int_t rc; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
19 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
20 if (tf->file.fd == NGX_INVALID_FILE) { |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
21 rc = ngx_create_temp_file(&tf->file, tf->path, tf->pool, |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1058
diff
changeset
|
22 tf->persistent, tf->clean, tf->access); |
208
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
23 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
24 if (rc == NGX_ERROR || rc == NGX_AGAIN) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
25 return rc; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
26 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
27 |
667 | 28 if (tf->log_level) { |
29 ngx_log_error(tf->log_level, tf->file.log, 0, "%s %V", | |
637 | 30 tf->warn, &tf->file.name); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
31 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
32 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
33 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
34 return ngx_write_chain_to_file(&tf->file, chain, tf->offset, tf->pool); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
35 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
36 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
37 |
493 | 38 ngx_int_t |
39 ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path, ngx_pool_t *pool, | |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1058
diff
changeset
|
40 ngx_uint_t persistent, ngx_uint_t clean, ngx_uint_t access) |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 { |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
42 uint32_t n; |
509 | 43 ngx_err_t err; |
563 | 44 ngx_pool_cleanup_t *cln; |
45 ngx_pool_cleanup_file_t *clnf; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
1091
58f1641783ca
allocate less memory on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1090
diff
changeset
|
47 file->name.len = path->name.len + 1 + path->len + 10; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 |
501 | 49 file->name.data = ngx_palloc(pool, file->name.len + 1); |
50 if (file->name.data == NULL) { | |
467 | 51 return NGX_ERROR; |
52 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 #if 0 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 for (i = 0; i < file->name.len; i++) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 file->name.data[i] = 'X'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 #endif |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
59 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 ngx_memcpy(file->name.data, path->name.data, path->name.len); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
61 |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
62 n = (uint32_t) ngx_next_temp_number(0); |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
63 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 for ( ;; ) { |
517 | 65 (void) ngx_sprintf(file->name.data + path->name.len + 1 + path->len, |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
66 "%010uD%Z", n); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
68 ngx_create_hashed_filename(file, path); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
69 |
563 | 70 cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t)); |
71 if (cln == NULL) { | |
72 return NGX_ERROR; | |
73 } | |
74 | |
1046 | 75 file->fd = ngx_open_tempfile(file->name.data, persistent, access); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
77 ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
78 "temp fd:%d", file->fd); |
75
869b10be682f
nginx-0.0.1-2003-04-14-21:04:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
74
diff
changeset
|
79 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
80 if (file->fd != NGX_INVALID_FILE) { |
563 | 81 |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1058
diff
changeset
|
82 cln->handler = clean ? ngx_pool_delete_file : ngx_pool_cleanup_file; |
563 | 83 clnf = cln->data; |
509 | 84 |
563 | 85 clnf->fd = file->fd; |
86 clnf->name = file->name.data; | |
87 clnf->log = pool->log; | |
509 | 88 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 return NGX_OK; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
92 err = ngx_errno; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
93 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 if (err == NGX_EEXIST) { |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
95 n = (uint32_t) ngx_next_temp_number(1); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 continue; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
99 if ((path->level[0] == 0) |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
100 || (err != NGX_ENOENT |
461 | 101 #if (NGX_WIN32) |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
102 && err != NGX_ENOTDIR |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
103 #endif |
467 | 104 )) |
105 { | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 ngx_log_error(NGX_LOG_CRIT, file->log, err, |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
107 ngx_open_tempfile_n " \"%s\" failed", |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 file->name.data); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 return NGX_ERROR; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 if (ngx_create_path(file, path) == NGX_ERROR) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 return NGX_ERROR; |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
114 } |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
118 |
493 | 119 void |
120 ngx_create_hashed_filename(ngx_file_t *file, ngx_path_t *path) | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 { |
517 | 122 size_t name, pos, level; |
123 ngx_uint_t i; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
124 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 name = file->name.len; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
126 pos = path->name.len + 1; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
128 file->name.data[path->name.len + path->len] = '/'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 for (i = 0; i < 3; i++) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 level = path->level[i]; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 if (level == 0) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 break; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
136 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 name -= level; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 file->name.data[pos - 1] = '/'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
139 ngx_memcpy(&file->name.data[pos], &file->name.data[name], level); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 pos += level + 1; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
143 ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
144 "hashed path: %s", file->name.data); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
146 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 |
493 | 148 ngx_int_t |
149 ngx_create_path(ngx_file_t *file, ngx_path_t *path) | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 { |
517 | 151 size_t pos; |
152 ngx_err_t err; | |
153 ngx_uint_t i; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 pos = path->name.len; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 for (i = 0; i < 3; i++) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 if (path->level[i] == 0) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 break; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 pos += path->level[i] + 1; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 file->name.data[pos] = '\0'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
165 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
166 ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
167 "temp file: \"%s\"", file->name.data); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 |
669 | 169 if (ngx_create_dir(file->name.data, 0700) == NGX_FILE_ERROR) { |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
170 err = ngx_errno; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 if (err != NGX_EEXIST) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
172 ngx_log_error(NGX_LOG_CRIT, file->log, err, |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
173 ngx_create_dir_n " \"%s\" failed", |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
174 file->name.data); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 return NGX_ERROR; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 file->name.data[pos] = '/'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
181 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
182 return NGX_OK; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 } |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
184 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
185 |
637 | 186 ngx_err_t |
669 | 187 ngx_create_full_path(u_char *dir, ngx_uint_t access) |
637 | 188 { |
189 u_char *p, ch; | |
190 ngx_err_t err; | |
191 | |
192 for (p = dir + 1; *p; p++) { | |
193 ch = *p; | |
194 | |
195 if (ch != '/') { | |
196 continue; | |
197 } | |
198 | |
199 *p = '\0'; | |
200 | |
669 | 201 if (ngx_create_dir(dir, access) == NGX_FILE_ERROR) { |
637 | 202 err = ngx_errno; |
203 if (err != NGX_EEXIST) { | |
204 return err; | |
205 } | |
206 } | |
207 | |
208 *p = '/'; | |
209 } | |
210 | |
211 return 0; | |
212 } | |
213 | |
214 | |
493 | 215 void |
499 | 216 ngx_init_temp_number(void) |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
217 { |
493 | 218 ngx_temp_number = 0; |
800 | 219 ngx_random_number = 123456; |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
220 } |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
221 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
222 |
495 | 223 ngx_atomic_uint_t |
493 | 224 ngx_next_temp_number(ngx_uint_t collision) |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
225 { |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
226 if (collision) { |
800 | 227 ngx_temp_number += ngx_random_number; |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
228 } |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
229 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
230 return ngx_temp_number++; |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
231 } |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
232 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
233 |
493 | 234 char * |
235 ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
236 { |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
237 char *p = conf; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
238 |
467 | 239 ssize_t level; |
629 | 240 ngx_str_t *value; |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
241 ngx_uint_t i, n; |
479 | 242 ngx_path_t *path, **slot; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
243 |
467 | 244 slot = (ngx_path_t **) (p + cmd->offset); |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
245 |
467 | 246 if (*slot) { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
247 return "is duplicate"; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
248 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
249 |
501 | 250 path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t)); |
251 if (path == NULL) { | |
467 | 252 return NGX_CONF_ERROR; |
253 } | |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
254 |
467 | 255 value = cf->args->elts; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
256 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
257 path->name = value[1]; |
629 | 258 |
661 | 259 if (path->name.data[path->name.len - 1] == '/') { |
260 path->name.len--; | |
261 } | |
262 | |
1352 | 263 if (ngx_conf_full_name(cf->cycle, &path->name, 0) == NGX_ERROR) { |
629 | 264 return NULL; |
265 } | |
266 | |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
267 path->len = 0; |
479 | 268 path->cleaner = (ngx_gc_handler_pt) cmd->post; |
467 | 269 path->conf_file = cf->conf_file->file.name.data; |
270 path->line = cf->conf_file->line; | |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
271 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
272 for (i = 0, n = 2; n < cf->args->nelts; i++, n++) { |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
273 level = ngx_atoi(value[n].data, value[n].len); |
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
274 if (level == NGX_ERROR || level == 0) { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
275 return "invalid value"; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
276 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
277 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
278 path->level[i] = level; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
279 path->len += level + 1; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
280 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
281 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
282 while (i < 3) { |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
283 path->level[i++] = 0; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
284 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
285 |
479 | 286 *slot = path; |
467 | 287 |
479 | 288 if (ngx_add_path(cf, slot) == NGX_ERROR) { |
289 return NGX_CONF_ERROR; | |
290 } | |
291 | |
292 return NGX_CONF_OK; | |
293 } | |
294 | |
295 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
296 char * |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
297 ngx_conf_set_access_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
298 { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
299 char *confp = conf; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
300 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
301 u_char *p; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
302 ngx_str_t *value; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
303 ngx_uint_t i, right, shift, *access; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
304 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
305 access = (ngx_uint_t *) (confp + cmd->offset); |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
306 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
307 if (*access != NGX_CONF_UNSET_UINT) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
308 return "is duplicate"; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
309 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
310 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
311 value = cf->args->elts; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
312 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
313 *access = 0600; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
314 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
315 for (i = 1; i < cf->args->nelts; i++) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
316 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
317 p = value[i].data; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
318 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
319 if (ngx_strncmp(p, "user:", sizeof("user:") - 1) == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
320 shift = 6; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
321 p += sizeof("user:") - 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
322 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
323 } else if (ngx_strncmp(p, "group:", sizeof("group:") - 1) == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
324 shift = 3; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
325 p += sizeof("group:") - 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
326 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
327 } else if (ngx_strncmp(p, "all:", sizeof("all:") - 1) == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
328 shift = 0; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
329 p += sizeof("all:") - 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
330 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
331 } else { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
332 goto invalid; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
333 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
334 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
335 if (ngx_strcmp(p, "rw") == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
336 right = 6; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
337 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
338 } else if (ngx_strcmp(p, "r") == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
339 right = 4; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
340 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
341 } else { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
342 goto invalid; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
343 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
344 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
345 *access |= right << shift; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
346 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
347 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
348 return NGX_CONF_OK; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
349 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
350 invalid: |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
351 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
352 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid value \"%V\"", &value[i]); |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
353 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
354 return NGX_CONF_ERROR; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
355 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
356 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
357 |
493 | 358 ngx_int_t |
359 ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot) | |
479 | 360 { |
361 ngx_uint_t i, n; | |
362 ngx_path_t *path, **p; | |
363 | |
364 path = *slot; | |
365 | |
366 p = cf->cycle->pathes.elts; | |
467 | 367 for (i = 0; i < cf->cycle->pathes.nelts; i++) { |
479 | 368 if (p[i]->name.len == path->name.len |
369 && ngx_strcmp(p[i]->name.data, path->name.data) == 0) | |
467 | 370 { |
371 for (n = 0; n < 3; n++) { | |
479 | 372 if (p[i]->level[n] != path->level[n]) { |
373 if (path->conf_file == NULL) { | |
481 | 374 if (p[i]->conf_file == NULL) { |
375 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
376 "the default path name \"%V\" has " | |
377 "the same name as another default path, " | |
378 "but the different levels, you need to " | |
379 "redefine one of them in http section", | |
380 &p[i]->name); | |
381 return NGX_ERROR; | |
382 } | |
383 | |
479 | 384 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
385 "the path name \"%V\" in %s:%ui has " | |
481 | 386 "the same name as default path, but " |
479 | 387 "the different levels, you need to " |
388 "define default path in http section", | |
389 &p[i]->name, p[i]->conf_file, p[i]->line); | |
390 return NGX_ERROR; | |
391 } | |
392 | |
467 | 393 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
479 | 394 "the same path name \"%V\" in %s:%ui " |
395 "has the different levels than", | |
396 &p[i]->name, p[i]->conf_file, p[i]->line); | |
397 return NGX_ERROR; | |
467 | 398 } |
399 | |
479 | 400 if (p[i]->level[n] == 0) { |
467 | 401 break; |
402 } | |
403 } | |
404 | |
479 | 405 *slot = p[i]; |
467 | 406 |
479 | 407 return NGX_OK; |
467 | 408 } |
409 } | |
410 | |
501 | 411 p = ngx_array_push(&cf->cycle->pathes); |
412 if (p == NULL) { | |
479 | 413 return NGX_ERROR; |
467 | 414 } |
415 | |
479 | 416 *p = path; |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
417 |
479 | 418 return NGX_OK; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
419 } |
467 | 420 |
421 | |
493 | 422 ngx_int_t |
423 ngx_create_pathes(ngx_cycle_t *cycle, ngx_uid_t user) | |
467 | 424 { |
425 ngx_err_t err; | |
426 ngx_uint_t i; | |
427 ngx_path_t **path; | |
428 #if !(NGX_WIN32) | |
429 ngx_file_info_t fi; | |
430 #endif | |
431 | |
432 path = cycle->pathes.elts; | |
433 for (i = 0; i < cycle->pathes.nelts; i++) { | |
434 | |
669 | 435 if (ngx_create_dir(path[i]->name.data, 0700) == NGX_FILE_ERROR) { |
467 | 436 err = ngx_errno; |
437 if (err != NGX_EEXIST) { | |
438 ngx_log_error(NGX_LOG_EMERG, cycle->log, err, | |
439 ngx_create_dir_n " \"%s\" failed", | |
440 path[i]->name.data); | |
441 return NGX_ERROR; | |
442 } | |
443 } | |
444 | |
517 | 445 if (user == (ngx_uid_t) NGX_CONF_UNSET_UINT) { |
467 | 446 continue; |
447 } | |
448 | |
449 #if !(NGX_WIN32) | |
450 | |
451 if (ngx_file_info((const char *) path[i]->name.data, &fi) == -1) { | |
452 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
453 ngx_file_info_n " \"%s\" failed", path[i]->name.data); | |
454 return NGX_ERROR; | |
455 } | |
456 | |
457 if (fi.st_uid != user) { | |
458 if (chown((const char *) path[i]->name.data, user, -1) == -1) { | |
459 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
460 "chown(\"%s\", %d) failed", | |
461 path[i]->name.data, user); | |
462 return NGX_ERROR; | |
463 } | |
464 } | |
465 | |
466 if ((fi.st_mode & (S_IRUSR|S_IWUSR|S_IXUSR)) | |
467 != (S_IRUSR|S_IWUSR|S_IXUSR)) | |
468 { | |
469 fi.st_mode |= (S_IRUSR|S_IWUSR|S_IXUSR); | |
470 | |
471 if (chmod((const char *) path[i]->name.data, fi.st_mode) == -1) { | |
472 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
473 "chmod() \"%s\" failed", path[i]->name.data); | |
474 return NGX_ERROR; | |
475 } | |
476 } | |
477 | |
478 #endif | |
479 } | |
480 | |
481 return NGX_OK; | |
482 } | |
956 | 483 |
484 | |
485 ngx_int_t | |
486 ngx_walk_tree(ngx_tree_ctx_t *ctx, ngx_str_t *tree) | |
487 { | |
488 void *data, *prev; | |
489 u_char *p, *name; | |
490 size_t len; | |
491 ngx_int_t rc; | |
492 ngx_err_t err; | |
977
b9836e87dd4d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
956
diff
changeset
|
493 ngx_str_t file, buf; |
956 | 494 ngx_dir_t dir; |
495 | |
496 buf.len = 0; | |
497 buf.data = NULL; | |
498 | |
499 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
500 "walk tree \"%V\"", tree); | |
501 | |
502 if (ngx_open_dir(tree, &dir) == NGX_ERROR) { | |
503 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | |
504 ngx_open_dir_n " \"%s\" failed", tree->data); | |
505 return NGX_ERROR; | |
506 } | |
507 | |
508 prev = ctx->data; | |
509 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
510 if (ctx->alloc) { |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
511 data = ngx_alloc(ctx->alloc, ctx->log); |
956 | 512 if (data == NULL) { |
513 goto failed; | |
514 } | |
515 | |
516 if (ctx->init_handler(data, prev) == NGX_ABORT) { | |
517 goto failed; | |
518 } | |
519 | |
520 ctx->data = data; | |
1319 | 521 |
522 } else { | |
523 data = NULL; | |
956 | 524 } |
525 | |
526 for ( ;; ) { | |
527 | |
528 ngx_set_errno(0); | |
529 | |
530 if (ngx_read_dir(&dir) == NGX_ERROR) { | |
531 err = ngx_errno; | |
532 | |
533 if (err == NGX_ENOMOREFILES) { | |
534 rc = NGX_OK; | |
535 | |
536 } else { | |
537 ngx_log_error(NGX_LOG_CRIT, ctx->log, err, | |
538 ngx_read_dir_n " \"%s\" failed", tree->data); | |
539 rc = NGX_ERROR; | |
540 } | |
541 | |
542 goto done; | |
543 } | |
544 | |
545 len = ngx_de_namelen(&dir); | |
546 name = ngx_de_name(&dir); | |
547 | |
548 ngx_log_debug2(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
549 "tree name %uz:\"%s\"", len, name); | |
550 | |
551 if (len == 1 && name[0] == '.') { | |
552 continue; | |
553 } | |
554 | |
555 if (len == 2 && name[0] == '.' && name[1] == '.') { | |
556 continue; | |
557 } | |
558 | |
559 file.len = tree->len + 1 + len; | |
560 | |
561 if (file.len + NGX_DIR_MASK_LEN > buf.len) { | |
562 | |
563 if (buf.len) { | |
564 ngx_free(buf.data); | |
565 } | |
566 | |
567 buf.len = tree->len + 1 + len + NGX_DIR_MASK_LEN; | |
568 | |
569 buf.data = ngx_alloc(buf.len + 1, ctx->log); | |
570 if (buf.data == NULL) { | |
571 goto failed; | |
572 } | |
573 } | |
574 | |
575 p = ngx_cpymem(buf.data, tree->data, tree->len); | |
576 *p++ = '/'; | |
577 ngx_memcpy(p, name, len + 1); | |
578 | |
579 file.data = buf.data; | |
580 | |
581 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
582 "tree path \"%s\"", file.data); | |
583 | |
584 if (!dir.valid_info) { | |
585 if (ngx_de_info(file.data, &dir) == NGX_FILE_ERROR) { | |
586 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | |
587 ngx_de_info_n " \"%s\" failed", file.data); | |
588 continue; | |
589 } | |
590 } | |
591 | |
592 if (ngx_de_is_file(&dir)) { | |
593 | |
594 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
595 "tree file \"%s\"", file.data); | |
596 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
597 ctx->size = ngx_de_size(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
598 ctx->access = ngx_de_access(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
599 ctx->mtime = ngx_de_mtime(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
600 |
956 | 601 if (ctx->file_handler(ctx, &file) == NGX_ABORT) { |
602 goto failed; | |
603 } | |
604 | |
605 } else if (ngx_de_is_dir(&dir)) { | |
606 | |
607 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
608 "tree enter dir \"%s\"", file.data); | |
609 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
610 ctx->access = ngx_de_access(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
611 ctx->mtime = ngx_de_mtime(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
612 |
956 | 613 if (ctx->pre_tree_handler(ctx, &file) == NGX_ABORT) { |
614 goto failed; | |
615 } | |
616 | |
617 if (ngx_walk_tree(ctx, &file) == NGX_ABORT) { | |
618 goto failed; | |
619 } | |
620 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
621 ctx->access = ngx_de_access(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
622 ctx->mtime = ngx_de_mtime(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
623 |
956 | 624 if (ctx->post_tree_handler(ctx, &file) == NGX_ABORT) { |
625 goto failed; | |
626 } | |
627 | |
628 } else { | |
629 | |
630 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
631 "tree special \"%s\"", file.data); | |
632 | |
633 if (ctx->spec_handler(ctx, &file) == NGX_ABORT) { | |
634 goto failed; | |
635 } | |
636 } | |
637 } | |
638 | |
639 failed: | |
640 | |
641 rc = NGX_ABORT; | |
642 | |
643 done: | |
644 | |
645 if (buf.len) { | |
646 ngx_free(buf.data); | |
647 } | |
648 | |
1319 | 649 if (data) { |
650 ngx_free(data); | |
956 | 651 ctx->data = prev; |
652 } | |
653 | |
654 if (ngx_close_dir(&dir) == NGX_ERROR) { | |
655 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | |
656 ngx_close_dir_n " \"%s\" failed", tree->data); | |
657 } | |
658 | |
659 return rc; | |
660 } |