Mercurial > hg > nginx-quic
annotate src/os/win32/ngx_files.c @ 8717:e06283038ec8 quic
QUIC: clear SSL_OP_ENABLE_MIDDLEBOX_COMPAT on SSL context switch.
The SSL_OP_ENABLE_MIDDLEBOX_COMPAT option is provided by QuicTLS and enabled
by default in the newly created SSL contexts. SSL_set_quic_method() is used
to clear it, which is required for SSL handshake to work on QUIC connections.
Switching context in the ngx_http_ssl_servername() SNI callback overrides SSL
options from the new SSL context. This results in the option set again.
Fix is to explicitly clear it when switching to another SSL context.
Initially reported here (in Russian):
http://mailman.nginx.org/pipermail/nginx-ru/2021-November/063989.html
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 07 Dec 2021 15:49:51 +0300 |
parents | ccb5ff87ab3e |
children | b0a06c50c1b4 |
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:
344
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:
344
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 |
4412 | 4 * Copyright (C) Nginx, Inc. |
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:
344
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
6 |
42
cd035a94e0b6
nginx-0.0.1-2002-12-27-10:27:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
7 |
cd035a94e0b6
nginx-0.0.1-2002-12-27-10:27:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
8 #include <ngx_config.h> |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
42
diff
changeset
|
9 #include <ngx_core.h> |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
12 #define NGX_UTF16_BUFLEN 256 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
13 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
14 static ngx_int_t ngx_win32_check_filename(u_char *name, u_short *u, |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
15 size_t len); |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
16 static u_short *ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t *len); |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
17 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
18 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
19 /* FILE_FLAG_BACKUP_SEMANTICS allows to obtain a handle to a directory */ |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
20 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
21 ngx_fd_t |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
22 ngx_open_file(u_char *name, u_long mode, u_long create, u_long access) |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
23 { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
24 size_t len; |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
25 u_short *u; |
3137
179f6dfcb7fe
preserve errno while ngx_free()
Igor Sysoev <igor@sysoev.ru>
parents:
2974
diff
changeset
|
26 ngx_fd_t fd; |
179f6dfcb7fe
preserve errno while ngx_free()
Igor Sysoev <igor@sysoev.ru>
parents:
2974
diff
changeset
|
27 ngx_err_t err; |
179f6dfcb7fe
preserve errno while ngx_free()
Igor Sysoev <igor@sysoev.ru>
parents:
2974
diff
changeset
|
28 u_short utf16[NGX_UTF16_BUFLEN]; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
29 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
30 len = NGX_UTF16_BUFLEN; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
31 u = ngx_utf8_to_utf16(utf16, name, &len); |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
32 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
33 if (u == NULL) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
34 return INVALID_HANDLE_VALUE; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
35 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
36 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
37 fd = INVALID_HANDLE_VALUE; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
38 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
39 if (create == NGX_FILE_OPEN |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
40 && ngx_win32_check_filename(name, u, len) != NGX_OK) |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
41 { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
42 goto failed; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
43 } |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
44 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
45 fd = CreateFileW(u, mode, |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
46 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
47 NULL, create, FILE_FLAG_BACKUP_SEMANTICS, NULL); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
48 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
49 failed: |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
50 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
51 if (u != utf16) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
52 err = ngx_errno; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
53 ngx_free(u); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
54 ngx_set_errno(err); |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
55 } |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
56 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
57 return fd; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
58 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
59 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
60 |
561 | 61 ssize_t |
62 ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) | |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
280
diff
changeset
|
64 u_long n; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
65 ngx_err_t err; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
66 OVERLAPPED ovlp, *povlp; |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 |
3156 | 68 ovlp.Internal = 0; |
69 ovlp.InternalHigh = 0; | |
70 ovlp.Offset = (u_long) offset; | |
71 ovlp.OffsetHigh = (u_long) (offset >> 32); | |
72 ovlp.hEvent = NULL; | |
461 | 73 |
3156 | 74 povlp = &ovlp; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
75 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
76 if (ReadFile(file->fd, buf, size, &n, povlp) == 0) { |
2974
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
77 err = ngx_errno; |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
78 |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
79 if (err == ERROR_HANDLE_EOF) { |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
80 return 0; |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
81 } |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
82 |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
83 ngx_log_error(NGX_LOG_ERR, file->log, err, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
84 "ReadFile() \"%s\" failed", file->name.data); |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
85 return NGX_ERROR; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
86 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
87 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
88 file->offset += n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
89 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
90 return n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
91 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
92 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
93 |
561 | 94 ssize_t |
95 ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
96 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
280
diff
changeset
|
97 u_long n; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
98 OVERLAPPED ovlp, *povlp; |
183
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
99 |
3156 | 100 ovlp.Internal = 0; |
101 ovlp.InternalHigh = 0; | |
102 ovlp.Offset = (u_long) offset; | |
103 ovlp.OffsetHigh = (u_long) (offset >> 32); | |
104 ovlp.hEvent = NULL; | |
183
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
105 |
3156 | 106 povlp = &ovlp; |
183
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
107 |
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
108 if (WriteFile(file->fd, buf, size, &n, povlp) == 0) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
109 ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
110 "WriteFile() \"%s\" failed", file->name.data); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
111 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
112 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
113 |
3158 | 114 if (n != size) { |
115 ngx_log_error(NGX_LOG_CRIT, file->log, 0, | |
116 "WriteFile() \"%s\" has written only %ul of %uz", | |
117 file->name.data, n, size); | |
118 return NGX_ERROR; | |
119 } | |
120 | |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
121 file->offset += n; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
122 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
123 return n; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
124 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
125 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
126 |
561 | 127 ssize_t |
128 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, | |
129 ngx_pool_t *pool) | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
130 { |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
131 u_char *buf, *prev; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
132 size_t size; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
133 ssize_t total, n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
134 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
135 total = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
136 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
137 while (cl) { |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
138 buf = cl->buf->pos; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
139 prev = buf; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
140 size = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
141 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
142 /* coalesce the neighbouring bufs */ |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
143 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
144 while (cl && prev == cl->buf->pos) { |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
145 size += cl->buf->last - cl->buf->pos; |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
146 prev = cl->buf->last; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
147 cl = cl->next; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
148 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
149 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
150 n = ngx_write_file(file, buf, size, offset); |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
151 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
152 if (n == NGX_ERROR) { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
153 return NGX_ERROR; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
154 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
155 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
156 total += n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
157 offset += n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
158 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
159 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
160 return total; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
161 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
162 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
163 |
1634
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
164 ssize_t |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
165 ngx_read_fd(ngx_fd_t fd, void *buf, size_t size) |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
166 { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
167 u_long n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
168 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
169 if (ReadFile(fd, buf, size, &n, NULL) != 0) { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
170 return (size_t) n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
171 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
172 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
173 return -1; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
174 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
175 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
176 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
177 ssize_t |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
178 ngx_write_fd(ngx_fd_t fd, void *buf, size_t size) |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
179 { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
180 u_long n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
181 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
182 if (WriteFile(fd, buf, size, &n, NULL) != 0) { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
183 return (size_t) n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
184 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
185 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
186 return -1; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
187 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
188 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
189 |
2769
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
190 ssize_t |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
191 ngx_write_console(ngx_fd_t fd, void *buf, size_t size) |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
192 { |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
193 u_long n; |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
194 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
195 (void) CharToOemBuff(buf, buf, size); |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
196 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
197 if (WriteFile(fd, buf, size, &n, NULL) != 0) { |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
198 return (size_t) n; |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
199 } |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
200 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
201 return -1; |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
202 } |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
203 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
204 |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
205 ngx_err_t |
1693
f4eb04fd8579
use malloc() in ngx_win32_rename_file, set crit level instead of error
Igor Sysoev <igor@sysoev.ru>
parents:
1634
diff
changeset
|
206 ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log) |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
207 { |
499 | 208 u_char *name; |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
209 ngx_err_t err; |
499 | 210 ngx_uint_t collision; |
211 ngx_atomic_uint_t num; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
212 |
4017
4f4086cf1a07
Fix buffer overrun under Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3651
diff
changeset
|
213 name = ngx_alloc(to->len + 1 + NGX_ATOMIC_T_LEN + 1 + sizeof("DELETE"), |
4f4086cf1a07
Fix buffer overrun under Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3651
diff
changeset
|
214 log); |
501 | 215 if (name == NULL) { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
216 return NGX_ENOMEM; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
217 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
218 |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
219 ngx_memcpy(name, to->data, to->len); |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
220 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
221 collision = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
222 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
223 /* mutex_lock() (per cache or single ?) */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
224 |
499 | 225 for ( ;; ) { |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
226 num = ngx_next_temp_number(collision); |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
227 |
2900
812445a822e3
add trailing zero to a file name
Igor Sysoev <igor@sysoev.ru>
parents:
2782
diff
changeset
|
228 ngx_sprintf(name + to->len, ".%0muA.DELETE%Z", num); |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
229 |
499 | 230 if (MoveFile((const char *) to->data, (const char *) name) != 0) { |
231 break; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
232 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
233 |
499 | 234 collision = 1; |
235 | |
2901
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
236 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, |
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
237 "MoveFile() \"%s\" to \"%s\" failed", to->data, name); |
499 | 238 } |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
239 |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
240 if (MoveFile((const char *) from->data, (const char *) to->data) == 0) { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
241 err = ngx_errno; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
242 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
243 } else { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
244 err = 0; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
245 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
246 |
1051 | 247 if (DeleteFile((const char *) name) == 0) { |
2901
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
248 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, |
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
249 "DeleteFile() \"%s\" failed", name); |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
250 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
251 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
252 /* mutex_unlock() */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
253 |
1693
f4eb04fd8579
use malloc() in ngx_win32_rename_file, set crit level instead of error
Igor Sysoev <igor@sysoev.ru>
parents:
1634
diff
changeset
|
254 ngx_free(name); |
f4eb04fd8579
use malloc() in ngx_win32_rename_file, set crit level instead of error
Igor Sysoev <igor@sysoev.ru>
parents:
1634
diff
changeset
|
255 |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
256 return err; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
257 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
258 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
259 |
561 | 260 ngx_int_t |
2462
90d5ddfedbb1
use GetFileAttributesEx() instead of GetFileAttributes()
Igor Sysoev <igor@sysoev.ru>
parents:
2459
diff
changeset
|
261 ngx_file_info(u_char *file, ngx_file_info_t *sb) |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
262 { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
263 size_t len; |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
264 long rc; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
265 u_short *u; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
266 ngx_err_t err; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
267 WIN32_FILE_ATTRIBUTE_DATA fa; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
268 u_short utf16[NGX_UTF16_BUFLEN]; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
269 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
270 len = NGX_UTF16_BUFLEN; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
271 |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
272 u = ngx_utf8_to_utf16(utf16, file, &len); |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
273 |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
274 if (u == NULL) { |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
275 return NGX_FILE_ERROR; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
276 } |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
277 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
278 rc = NGX_FILE_ERROR; |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
279 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
280 if (ngx_win32_check_filename(file, u, len) != NGX_OK) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
281 goto failed; |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
282 } |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
283 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
284 rc = GetFileAttributesExW(u, GetFileExInfoStandard, &fa); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
285 |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
286 sb->dwFileAttributes = fa.dwFileAttributes; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
287 sb->ftCreationTime = fa.ftCreationTime; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
288 sb->ftLastAccessTime = fa.ftLastAccessTime; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
289 sb->ftLastWriteTime = fa.ftLastWriteTime; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
290 sb->nFileSizeHigh = fa.nFileSizeHigh; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
291 sb->nFileSizeLow = fa.nFileSizeLow; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
292 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
293 failed: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
294 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
295 if (u != utf16) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
296 err = ngx_errno; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
297 ngx_free(u); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
298 ngx_set_errno(err); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
299 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
300 |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
301 return rc; |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
302 } |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
303 |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
304 |
561 | 305 ngx_int_t |
681 | 306 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) |
307 { | |
308 uint64_t intervals; | |
309 FILETIME ft; | |
310 | |
311 /* 116444736000000000 is commented in src/os/win32/ngx_time.c */ | |
312 | |
313 intervals = s * 10000000 + 116444736000000000; | |
314 | |
315 ft.dwLowDateTime = (DWORD) intervals; | |
316 ft.dwHighDateTime = (DWORD) (intervals >> 32); | |
317 | |
318 if (SetFileTime(fd, NULL, NULL, &ft) != 0) { | |
319 return NGX_OK; | |
320 } | |
321 | |
322 return NGX_ERROR; | |
323 } | |
324 | |
325 | |
3651 | 326 ngx_int_t |
327 ngx_create_file_mapping(ngx_file_mapping_t *fm) | |
328 { | |
329 LARGE_INTEGER size; | |
330 | |
331 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE, | |
332 NGX_FILE_DEFAULT_ACCESS); | |
7086 | 333 |
3651 | 334 if (fm->fd == NGX_INVALID_FILE) { |
335 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
336 ngx_open_file_n " \"%s\" failed", fm->name); | |
337 return NGX_ERROR; | |
338 } | |
339 | |
340 fm->handle = NULL; | |
341 | |
342 size.QuadPart = fm->size; | |
343 | |
344 if (SetFilePointerEx(fm->fd, size, NULL, FILE_BEGIN) == 0) { | |
345 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
346 "SetFilePointerEx(\"%s\", %uz) failed", | |
347 fm->name, fm->size); | |
348 goto failed; | |
349 } | |
350 | |
351 if (SetEndOfFile(fm->fd) == 0) { | |
352 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
353 "SetEndOfFile() \"%s\" failed", fm->name); | |
354 goto failed; | |
355 } | |
356 | |
357 fm->handle = CreateFileMapping(fm->fd, NULL, PAGE_READWRITE, | |
358 (u_long) ((off_t) fm->size >> 32), | |
359 (u_long) ((off_t) fm->size & 0xffffffff), | |
360 NULL); | |
361 if (fm->handle == NULL) { | |
362 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
363 "CreateFileMapping(%s, %uz) failed", | |
364 fm->name, fm->size); | |
365 goto failed; | |
366 } | |
367 | |
368 fm->addr = MapViewOfFile(fm->handle, FILE_MAP_WRITE, 0, 0, 0); | |
369 | |
370 if (fm->addr != NULL) { | |
371 return NGX_OK; | |
372 } | |
373 | |
374 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
375 "MapViewOfFile(%uz) of file mapping \"%s\" failed", | |
376 fm->size, fm->name); | |
377 | |
378 failed: | |
379 | |
380 if (fm->handle) { | |
381 if (CloseHandle(fm->handle) == 0) { | |
382 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
383 "CloseHandle() of file mapping \"%s\" failed", | |
384 fm->name); | |
385 } | |
386 } | |
387 | |
388 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
389 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
390 ngx_close_file_n " \"%s\" failed", fm->name); | |
391 } | |
392 | |
393 return NGX_ERROR; | |
394 } | |
395 | |
396 | |
397 void | |
398 ngx_close_file_mapping(ngx_file_mapping_t *fm) | |
399 { | |
400 if (UnmapViewOfFile(fm->addr) == 0) { | |
401 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
402 "UnmapViewOfFile(%p) of file mapping \"%s\" failed", | |
403 fm->addr, &fm->name); | |
404 } | |
405 | |
406 if (CloseHandle(fm->handle) == 0) { | |
407 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
408 "CloseHandle() of file mapping \"%s\" failed", | |
409 &fm->name); | |
410 } | |
411 | |
412 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
413 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
414 ngx_close_file_n " \"%s\" failed", fm->name); | |
415 } | |
416 } | |
417 | |
418 | |
4564
13eb3193cd63
Fixed win32 build after realpath changes in r4559.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
419 u_char * |
2259 | 420 ngx_realpath(u_char *path, u_char *resolved) |
421 { | |
422 /* STUB */ | |
4564
13eb3193cd63
Fixed win32 build after realpath changes in r4559.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
423 return path; |
2259 | 424 } |
425 | |
426 | |
561 | 427 ngx_int_t |
428 ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) | |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
429 { |
7433
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
430 u_char *pattern, *p; |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
431 ngx_err_t err; |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
432 |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
433 pattern = malloc(name->len + 3); |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
434 if (pattern == NULL) { |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
435 return NGX_ERROR; |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
436 } |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
437 |
7433
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
438 p = ngx_cpymem(pattern, name->data, name->len); |
577 | 439 |
7433
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
440 *p++ = '/'; |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
441 *p++ = '*'; |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
442 *p = '\0'; |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
443 |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
444 dir->dir = FindFirstFile((const char *) pattern, &dir->finddata); |
5749
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
445 |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
446 if (dir->dir == INVALID_HANDLE_VALUE) { |
7433
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
447 err = ngx_errno; |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
448 ngx_free(pattern); |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
449 ngx_set_errno(err); |
577 | 450 return NGX_ERROR; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
451 } |
577 | 452 |
7433
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
453 ngx_free(pattern); |
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
454 |
457 | 455 dir->valid_info = 1; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
456 dir->ready = 1; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
457 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
458 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
459 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
460 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
461 |
561 | 462 ngx_int_t |
463 ngx_read_dir(ngx_dir_t *dir) | |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
464 { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
465 if (dir->ready) { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
466 dir->ready = 0; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
467 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
468 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
469 |
727 | 470 if (FindNextFile(dir->dir, &dir->finddata) != 0) { |
3200
26784c34e8be
*) reset cached dirent.d_type after stat()
Igor Sysoev <igor@sysoev.ru>
parents:
3178
diff
changeset
|
471 dir->type = 1; |
681 | 472 return NGX_OK; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
473 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
474 |
681 | 475 return NGX_ERROR; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
476 } |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
477 |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
478 |
501 | 479 ngx_int_t |
5749
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
480 ngx_close_dir(ngx_dir_t *dir) |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
481 { |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
482 if (FindClose(dir->dir) == 0) { |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
483 return NGX_ERROR; |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
484 } |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
485 |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
486 return NGX_OK; |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
487 } |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
488 |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
489 |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
490 ngx_int_t |
727 | 491 ngx_open_glob(ngx_glob_t *gl) |
492 { | |
2459 | 493 u_char *p; |
494 size_t len; | |
495 ngx_err_t err; | |
1632 | 496 |
727 | 497 gl->dir = FindFirstFile((const char *) gl->pattern, &gl->finddata); |
498 | |
499 if (gl->dir == INVALID_HANDLE_VALUE) { | |
1980 | 500 |
2459 | 501 err = ngx_errno; |
502 | |
503 if ((err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) | |
504 && gl->test) | |
505 { | |
1980 | 506 gl->no_match = 1; |
507 return NGX_OK; | |
508 } | |
509 | |
727 | 510 return NGX_ERROR; |
511 } | |
512 | |
1632 | 513 for (p = gl->pattern; *p; p++) { |
514 if (*p == '/') { | |
515 gl->last = p + 1 - gl->pattern; | |
516 } | |
517 } | |
518 | |
519 len = ngx_strlen(gl->finddata.cFileName); | |
520 gl->name.len = gl->last + len; | |
521 | |
522 gl->name.data = ngx_alloc(gl->name.len + 1, gl->log); | |
523 if (gl->name.data == NULL) { | |
524 return NGX_ERROR; | |
525 } | |
526 | |
527 ngx_memcpy(gl->name.data, gl->pattern, gl->last); | |
528 ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName, | |
529 len + 1); | |
530 | |
727 | 531 gl->ready = 1; |
532 | |
533 return NGX_OK; | |
534 } | |
535 | |
536 | |
537 ngx_int_t | |
538 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) | |
539 { | |
1632 | 540 size_t len; |
727 | 541 ngx_err_t err; |
542 | |
1980 | 543 if (gl->no_match) { |
544 return NGX_DONE; | |
545 } | |
546 | |
727 | 547 if (gl->ready) { |
1632 | 548 *name = gl->name; |
727 | 549 |
550 gl->ready = 0; | |
551 return NGX_OK; | |
552 } | |
553 | |
1632 | 554 ngx_free(gl->name.data); |
555 gl->name.data = NULL; | |
556 | |
727 | 557 if (FindNextFile(gl->dir, &gl->finddata) != 0) { |
1632 | 558 |
559 len = ngx_strlen(gl->finddata.cFileName); | |
560 gl->name.len = gl->last + len; | |
561 | |
562 gl->name.data = ngx_alloc(gl->name.len + 1, gl->log); | |
563 if (gl->name.data == NULL) { | |
564 return NGX_ERROR; | |
565 } | |
566 | |
567 ngx_memcpy(gl->name.data, gl->pattern, gl->last); | |
568 ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName, | |
569 len + 1); | |
570 | |
571 *name = gl->name; | |
727 | 572 |
573 return NGX_OK; | |
574 } | |
575 | |
576 err = ngx_errno; | |
577 | |
578 if (err == NGX_ENOMOREFILES) { | |
579 return NGX_DONE; | |
580 } | |
581 | |
582 ngx_log_error(NGX_LOG_ALERT, gl->log, err, | |
583 "FindNextFile(%s) failed", gl->pattern); | |
584 | |
585 return NGX_ERROR; | |
586 } | |
587 | |
588 | |
589 void | |
590 ngx_close_glob(ngx_glob_t *gl) | |
591 { | |
1632 | 592 if (gl->name.data) { |
593 ngx_free(gl->name.data); | |
594 } | |
595 | |
1980 | 596 if (gl->dir == INVALID_HANDLE_VALUE) { |
597 return; | |
598 } | |
599 | |
1632 | 600 if (FindClose(gl->dir) == 0) { |
727 | 601 ngx_log_error(NGX_LOG_ALERT, gl->log, ngx_errno, |
602 "FindClose(%s) failed", gl->pattern); | |
603 } | |
604 } | |
605 | |
606 | |
607 ngx_int_t | |
501 | 608 ngx_de_info(u_char *name, ngx_dir_t *dir) |
609 { | |
610 return NGX_OK; | |
611 } | |
612 | |
613 | |
614 ngx_int_t | |
615 ngx_de_link_info(u_char *name, ngx_dir_t *dir) | |
616 { | |
617 return NGX_OK; | |
618 } | |
619 | |
620 | |
561 | 621 ngx_int_t |
3178 | 622 ngx_read_ahead(ngx_fd_t fd, size_t n) |
623 { | |
624 return ~NGX_FILE_ERROR; | |
625 } | |
626 | |
627 | |
628 ngx_int_t | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
629 ngx_directio_on(ngx_fd_t fd) |
2134
13652cba8633
fix building by bcc broken in r2130
Igor Sysoev <igor@sysoev.ru>
parents:
1980
diff
changeset
|
630 { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3158
diff
changeset
|
631 return ~NGX_FILE_ERROR; |
2134
13652cba8633
fix building by bcc broken in r2130
Igor Sysoev <igor@sysoev.ru>
parents:
1980
diff
changeset
|
632 } |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
633 |
2615 | 634 |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
635 ngx_int_t |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
636 ngx_directio_off(ngx_fd_t fd) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
637 { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3158
diff
changeset
|
638 return ~NGX_FILE_ERROR; |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
639 } |
2615 | 640 |
641 | |
642 size_t | |
643 ngx_fs_bsize(u_char *name) | |
644 { | |
645 u_char root[4]; | |
646 u_long sc, bs, nfree, ncl; | |
647 | |
648 if (name[2] == ':') { | |
649 ngx_cpystrn(root, name, 4); | |
650 name = root; | |
651 } | |
652 | |
653 if (GetDiskFreeSpace((const char *) name, &sc, &bs, &nfree, &ncl) == 0) { | |
654 return 512; | |
655 } | |
656 | |
657 return sc * bs; | |
658 } | |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
659 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
660 |
7973
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
661 off_t |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
662 ngx_fs_available(u_char *name) |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
663 { |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
664 ULARGE_INTEGER navail; |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
665 |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
666 if (GetDiskFreeSpaceEx((const char *) name, &navail, NULL, NULL) == 0) { |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
667 return NGX_MAX_OFF_T_VALUE; |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
668 } |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
669 |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
670 return (off_t) navail.QuadPart; |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
671 } |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
672 |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7433
diff
changeset
|
673 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
674 static ngx_int_t |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
675 ngx_win32_check_filename(u_char *name, u_short *u, size_t len) |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
676 { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
677 u_char *p, ch; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
678 u_long n; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
679 u_short *lu; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
680 ngx_err_t err; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
681 enum { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
682 sw_start = 0, |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
683 sw_normal, |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
684 sw_after_slash, |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
685 sw_after_colon, |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
686 sw_after_dot |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
687 } state; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
688 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
689 /* check for NTFS streams (":"), trailing dots and spaces */ |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
690 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
691 lu = NULL; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
692 state = sw_start; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
693 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
694 for (p = name; *p; p++) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
695 ch = *p; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
696 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
697 switch (state) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
698 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
699 case sw_start: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
700 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
701 /* |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
702 * skip till first "/" to allow paths starting with drive and |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
703 * relative path, like "c:html/" |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
704 */ |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
705 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
706 if (ch == '/' || ch == '\\') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
707 state = sw_after_slash; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
708 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
709 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
710 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
711 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
712 case sw_normal: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
713 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
714 if (ch == ':') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
715 state = sw_after_colon; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
716 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
717 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
718 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
719 if (ch == '.' || ch == ' ') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
720 state = sw_after_dot; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
721 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
722 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
723 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
724 if (ch == '/' || ch == '\\') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
725 state = sw_after_slash; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
726 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
727 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
728 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
729 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
730 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
731 case sw_after_slash: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
732 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
733 if (ch == '/' || ch == '\\') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
734 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
735 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
736 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
737 if (ch == '.') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
738 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
739 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
740 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
741 if (ch == ':') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
742 state = sw_after_colon; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
743 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
744 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
745 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
746 state = sw_normal; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
747 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
748 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
749 case sw_after_colon: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
750 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
751 if (ch == '/' || ch == '\\') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
752 state = sw_after_slash; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
753 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
754 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
755 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
756 goto invalid; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
757 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
758 case sw_after_dot: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
759 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
760 if (ch == '/' || ch == '\\') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
761 goto invalid; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
762 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
763 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
764 if (ch == ':') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
765 goto invalid; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
766 } |
4703 | 767 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
768 if (ch == '.' || ch == ' ') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
769 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
770 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
771 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
772 state = sw_normal; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
773 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
774 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
775 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
776 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
777 if (state == sw_after_dot) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
778 goto invalid; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
779 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
780 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
781 /* check if long name match */ |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
782 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
783 lu = malloc(len * 2); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
784 if (lu == NULL) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
785 return NGX_ERROR; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
786 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
787 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
788 n = GetLongPathNameW(u, lu, len); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
789 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
790 if (n == 0) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
791 goto failed; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
792 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
793 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
794 if (n != len - 1 || _wcsicmp(u, lu) != 0) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
795 goto invalid; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
796 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
797 |
5437
dea321e5c021
Win32: plugged memory leak.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4703
diff
changeset
|
798 ngx_free(lu); |
dea321e5c021
Win32: plugged memory leak.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4703
diff
changeset
|
799 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
800 return NGX_OK; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
801 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
802 invalid: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
803 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
804 ngx_set_errno(NGX_ENOENT); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
805 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
806 failed: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
807 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
808 if (lu) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
809 err = ngx_errno; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
810 ngx_free(lu); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
811 ngx_set_errno(err); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
812 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
813 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
814 return NGX_ERROR; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
815 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
816 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
817 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
818 static u_short * |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
819 ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t *len) |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
820 { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
821 u_char *p; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
822 u_short *u, *last; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
823 uint32_t n; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
824 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
825 p = utf8; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
826 u = utf16; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
827 last = utf16 + *len; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
828 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
829 while (u < last) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
830 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
831 if (*p < 0x80) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
832 *u++ = (u_short) *p; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
833 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
834 if (*p == 0) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
835 *len = u - utf16; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
836 return utf16; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
837 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
838 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
839 p++; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
840 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
841 continue; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
842 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
843 |
5501
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
844 if (u + 1 == last) { |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
845 *len = u - utf16; |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
846 break; |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
847 } |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
848 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
849 n = ngx_utf8_decode(&p, 4); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
850 |
5501
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
851 if (n > 0x10ffff) { |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
852 ngx_set_errno(NGX_EILSEQ); |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
853 return NULL; |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
854 } |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
855 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
856 if (n > 0xffff) { |
5501
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
857 n -= 0x10000; |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
858 *u++ = (u_short) (0xd800 + (n >> 10)); |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
859 *u++ = (u_short) (0xdc00 + (n & 0x03ff)); |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
860 continue; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
861 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
862 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
863 *u++ = (u_short) n; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
864 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
865 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
866 /* the given buffer is not enough, allocate a new one */ |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
867 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
868 u = malloc(((p - utf8) + ngx_strlen(p) + 1) * sizeof(u_short)); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
869 if (u == NULL) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
870 return NULL; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
871 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
872 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
873 ngx_memcpy(u, utf16, *len * 2); |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
874 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
875 utf16 = u; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
876 u += *len; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
877 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
878 for ( ;; ) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
879 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
880 if (*p < 0x80) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
881 *u++ = (u_short) *p; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
882 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
883 if (*p == 0) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
884 *len = u - utf16; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
885 return utf16; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
886 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
887 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
888 p++; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
889 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
890 continue; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
891 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
892 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
893 n = ngx_utf8_decode(&p, 4); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
894 |
5501
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
895 if (n > 0x10ffff) { |
5785
fbdab7f38fd6
Style: use ngx_free() instead of free().
Tatsuhiko Kubo <cubicdaiya@gmail.com>
parents:
5749
diff
changeset
|
896 ngx_free(utf16); |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
897 ngx_set_errno(NGX_EILSEQ); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
898 return NULL; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
899 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
900 |
5501
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
901 if (n > 0xffff) { |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
902 n -= 0x10000; |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
903 *u++ = (u_short) (0xd800 + (n >> 10)); |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
904 *u++ = (u_short) (0xdc00 + (n & 0x03ff)); |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
905 continue; |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
906 } |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
907 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
908 *u++ = (u_short) n; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
909 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
910 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
911 /* unreachable */ |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
912 } |