~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/include/arch/win32/apr_arch_file_io.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#ifndef FILE_IO_H
 
18
#define FILE_IO_H
 
19
 
 
20
#include "apr.h"
 
21
#include "apr_private.h"
 
22
#include "apr_pools.h"
 
23
#include "apr_general.h"
 
24
#include "apr_tables.h"
 
25
#include "apr_thread_mutex.h"
 
26
#include "apr_file_io.h"
 
27
#include "apr_file_info.h"
 
28
#include "apr_errno.h"
 
29
#include "apr_arch_misc.h"
 
30
#include "apr_poll.h"
 
31
 
 
32
#ifdef HAVE_SYS_STAT_H
 
33
#include <sys/stat.h>
 
34
#endif
 
35
#if APR_HAVE_SYS_TYPES_H
 
36
#include <sys/types.h>
 
37
#endif
 
38
#ifdef HAVE_SYS_FCNTL_H
 
39
#include <fcntl.h>
 
40
#endif
 
41
#ifdef HAVE_TIME_H
 
42
#include <time.h>
 
43
#endif
 
44
#if APR_HAVE_DIRENT_H
 
45
#include <dirent.h>
 
46
#endif
 
47
#ifdef HAVE_MALLOC_H
 
48
#include <malloc.h>
 
49
#endif
 
50
 
 
51
#if APR_HAS_UNICODE_FS
 
52
#include "arch/win32/apr_arch_utf8.h"
 
53
#include <wchar.h>
 
54
 
 
55
typedef apr_uint16_t apr_wchar_t;
 
56
 
 
57
/* Helper functions for the WinNT ApiW() functions.  APR treats all
 
58
 * resource identifiers (files, etc) by their UTF-8 name, to provide 
 
59
 * access to all named identifiers.  [UTF-8 completely maps Unicode 
 
60
 * into char type strings.]
 
61
 *
 
62
 * The _path flavors below provide us fast mappings of the
 
63
 * Unicode filename //?/D:/path and //?/UNC/mach/share/path mappings,
 
64
 * which allow unlimited (well, 32000 wide character) length names.
 
65
 * These prefixes may appear in Unicode, but must not appear in the
 
66
 * Ascii API calls.  So we tack them on in utf8_to_unicode_path, and
 
67
 * strip them right back off in unicode_to_utf8_path.
 
68
 */
 
69
apr_status_t utf8_to_unicode_path(apr_wchar_t* dststr, apr_size_t dstchars, 
 
70
                                  const char* srcstr);
 
71
apr_status_t unicode_to_utf8_path(char* dststr, apr_size_t dstchars, 
 
72
                                  const apr_wchar_t* srcstr);
 
73
 
 
74
#endif /* APR_HAS_UNICODE_FS */
 
75
 
 
76
/* Another Helper functions for the WinNT ApiW() functions.  We need to
 
77
 * derive some 'resource' names (max length 255 characters, prefixed with
 
78
 * Global/ or Local/ on WinNT) from something that looks like a filename.
 
79
 * Since 'resource' names never contain slashes, convert these to '_'s
 
80
 * and return the appropriate char* or wchar* for ApiA or ApiW calls.
 
81
 */
 
82
 
 
83
void *res_name_from_filename(const char *file, int global, apr_pool_t *pool);
 
84
 
 
85
#define APR_FILE_MAX MAX_PATH
 
86
 
 
87
#define APR_FILE_BUFSIZE 4096
 
88
 
 
89
/* obscure ommissions from msvc's sys/stat.h */
 
90
#ifdef _MSC_VER
 
91
#define S_IFIFO        _S_IFIFO /* pipe */
 
92
#define S_IFBLK        0060000  /* Block Special */
 
93
#define S_IFLNK        0120000  /* Symbolic Link */
 
94
#define S_IFSOCK       0140000  /* Socket */
 
95
#define S_IFWHT        0160000  /* Whiteout */
 
96
#endif
 
97
 
 
98
/* Internal Flags for apr_file_open */
 
99
#define APR_OPENINFO     0x00100000 /* Open without READ or WRITE access */
 
100
#define APR_OPENLINK     0x00200000 /* Open a link itself, if supported */
 
101
#define APR_READCONTROL  0x00400000 /* Read the file's owner/perms */
 
102
#define APR_WRITECONTROL 0x00800000 /* Modifythe file's owner/perms */
 
103
#define APR_WRITEATTRS   0x01000000 /* Modify the file's attributes */
 
104
 
 
105
/* Entries missing from the MSVC 5.0 Win32 SDK:
 
106
 */
 
107
#ifndef FILE_ATTRIBUTE_DEVICE
 
108
#define FILE_ATTRIBUTE_DEVICE        0x00000040
 
109
#endif
 
110
#ifndef FILE_ATTRIBUTE_REPARSE_POINT
 
111
#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
 
112
#endif
 
113
#ifndef FILE_FLAG_OPEN_NO_RECALL
 
114
#define FILE_FLAG_OPEN_NO_RECALL     0x00100000
 
115
#endif
 
116
#ifndef FILE_FLAG_OPEN_REPARSE_POINT
 
117
#define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000
 
118
#endif
 
119
#ifndef TRUSTEE_IS_WELL_KNOWN_GROUP
 
120
#define TRUSTEE_IS_WELL_KNOWN_GROUP  5
 
121
#endif
 
122
 
 
123
/* Information bits available from the WIN32 FindFirstFile function */
 
124
#define APR_FINFO_WIN32_DIR (APR_FINFO_NAME  | APR_FINFO_TYPE \
 
125
                           | APR_FINFO_CTIME | APR_FINFO_ATIME \
 
126
                           | APR_FINFO_MTIME | APR_FINFO_SIZE)
 
127
 
 
128
/* Sneak the Readonly bit through finfo->protection for internal use _only_ */
 
129
#define APR_FREADONLY 0x10000000 
 
130
 
 
131
/* Private function for apr_stat/lstat/getfileinfo/dir_read */
 
132
int fillin_fileinfo(apr_finfo_t *finfo, WIN32_FILE_ATTRIBUTE_DATA *wininfo, 
 
133
                    int byhandle, apr_int32_t wanted);
 
134
 
 
135
/* Private function that extends apr_stat/lstat/getfileinfo/dir_read */
 
136
apr_status_t more_finfo(apr_finfo_t *finfo, const void *ufile, 
 
137
                        apr_int32_t wanted, int whatfile);
 
138
 
 
139
/* whatfile types for the ufile arg */
 
140
#define MORE_OF_HANDLE 0
 
141
#define MORE_OF_FSPEC  1
 
142
#define MORE_OF_WFSPEC 2
 
143
 
 
144
/* quick run-down of fields in windows' apr_file_t structure that may have 
 
145
 * obvious uses.
 
146
 * fname --  the filename as passed to the open call.
 
147
 * dwFileAttricutes -- Attributes used to open the file.
 
148
 * append -- Windows doesn't support the append concept when opening files.
 
149
 *           APR needs to keep track of this, and always make sure we append
 
150
 *           correctly when writing to a file with this flag set TRUE.
 
151
 */
 
152
 
 
153
// for apr_poll.c;
 
154
#define filedes filehand
 
155
 
 
156
struct apr_file_t {
 
157
    apr_pool_t *pool;
 
158
    HANDLE filehand;
 
159
    BOOLEAN pipe;              // Is this a pipe of a file?
 
160
    OVERLAPPED *pOverlapped;
 
161
    apr_interval_time_t timeout;
 
162
    apr_int32_t flags;
 
163
 
 
164
    /* File specific info */
 
165
    apr_finfo_t *finfo;
 
166
    char *fname;
 
167
    DWORD dwFileAttributes;
 
168
    int eof_hit;
 
169
    BOOLEAN buffered;          // Use buffered I/O?
 
170
    int ungetchar;             // Last char provided by an unget op. (-1 = no char)
 
171
    int append; 
 
172
 
 
173
    /* Stuff for buffered mode */
 
174
    char *buffer;
 
175
    apr_size_t bufpos;         // Read/Write position in buffer
 
176
    apr_size_t dataRead;       // amount of valid data read into buffer
 
177
    int direction;             // buffer being used for 0 = read, 1 = write
 
178
    apr_off_t filePtr;         // position in file of handle
 
179
    apr_thread_mutex_t *mutex; // mutex semaphore, must be owned to access the above fields
 
180
 
 
181
    /* if there is a timeout set, then this pollset is used */
 
182
    apr_pollset_t *pollset;
 
183
 
 
184
    /* Pipe specific info */    
 
185
};
 
186
 
 
187
struct apr_dir_t {
 
188
    apr_pool_t *pool;
 
189
    HANDLE dirhand;
 
190
    apr_size_t rootlen;
 
191
    char *dirname;
 
192
    char *name;
 
193
    union {
 
194
#if APR_HAS_UNICODE_FS
 
195
        struct {
 
196
            WIN32_FIND_DATAW *entry;
 
197
        } w;
 
198
#endif
 
199
#if APR_HAS_ANSI_FS
 
200
        struct {
 
201
            WIN32_FIND_DATAA *entry;
 
202
        } n;
 
203
#endif        
 
204
    };
 
205
    int bof;
 
206
};
 
207
 
 
208
/* There are many goofy characters the filesystem can't accept
 
209
 * or can confound the cmd.exe shell.  Here's the list
 
210
 * [declared in filesys.c]
 
211
 */
 
212
extern const char apr_c_is_fnchar[256];
 
213
 
 
214
#define IS_FNCHAR(c) (apr_c_is_fnchar[(unsigned char)(c)] & 1)
 
215
#define IS_SHCHAR(c) ((apr_c_is_fnchar[(unsigned char)(c)] & 2) == 2)
 
216
 
 
217
 
 
218
/* If the user passes APR_FILEPATH_TRUENAME to either
 
219
 * apr_filepath_root or apr_filepath_merge, this fn determines
 
220
 * that the root really exists.  It's expensive, wouldn't want
 
221
 * to do this too frequenly.
 
222
 */
 
223
apr_status_t filepath_root_test(char *path, apr_pool_t *p);
 
224
 
 
225
 
 
226
/* The apr_filepath_merge wants to canonicalize the cwd to the 
 
227
 * addpath if the user passes NULL as the old root path (this
 
228
 * isn't true of an empty string "", which won't be concatenated.
 
229
 *
 
230
 * But we need to figure out what the cwd of a given volume is,
 
231
 * when the user passes D:foo.  This fn will determine D:'s cwd.
 
232
 *
 
233
 * If flags includes the bit APR_FILEPATH_NATIVE, the path returned
 
234
 * is in the os-native format.
 
235
 */
 
236
apr_status_t filepath_drive_get(char **rootpath, char drive, 
 
237
                                apr_int32_t flags, apr_pool_t *p);
 
238
 
 
239
 
 
240
/* If the user passes d: vs. D: (or //mach/share vs. //MACH/SHARE),
 
241
 * we need to fold the case to canonical form.  This function is
 
242
 * supposed to do so.
 
243
 */
 
244
apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p);
 
245
 
 
246
 
 
247
apr_status_t file_cleanup(void *);
 
248
 
 
249
/**
 
250
 * Internal function to create a Win32/NT pipe that respects some async
 
251
 * timeout options.
 
252
 * @param in new read end of the created pipe
 
253
 * @param out new write end of the created pipe
 
254
 * @param blocking_mode one of
 
255
 * <pre>
 
256
 *       APR_FULL_BLOCK
 
257
 *       APR_READ_BLOCK
 
258
 *       APR_WRITE_BLOCK
 
259
 *       APR_FULL_NONBLOCK
 
260
 * </pre>
 
261
 * @remark It so happens that APR_FULL_BLOCK and APR_FULL_NONBLOCK
 
262
 * are common to apr_procattr_io_set() in, out and err modes.
 
263
 * Because APR_CHILD_BLOCK and APR_WRITE_BLOCK share the same value,
 
264
 * as do APR_PARENT_BLOCK and APR_READ_BLOCK, it's possible to use
 
265
 * that value directly for creating the stdout/stderr pipes.  When
 
266
 * creating the stdin pipe, the values must be transposed.
 
267
 * @see apr_procattr_io_set
 
268
 */
 
269
apr_status_t apr_create_nt_pipe(apr_file_t **in, apr_file_t **out, 
 
270
                                apr_int32_t blocking_mode, 
 
271
                                apr_pool_t *p);
 
272
 
 
273
/** @see apr_create_nt_pipe */
 
274
#define APR_READ_BLOCK     3
 
275
/** @see apr_create_nt_pipe */
 
276
#define APR_WRITE_BLOCK      4
 
277
 
 
278
#endif  /* ! FILE_IO_H */