apr_file_info.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. 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. #ifndef APR_FILE_INFO_H
  17. #define APR_FILE_INFO_H
  18. /**
  19. * @file apr_file_info.h
  20. * @brief APR File Information
  21. */
  22. #include "apr.h"
  23. #include "apr_user.h"
  24. #include "apr_pools.h"
  25. #include "apr_tables.h"
  26. #include "apr_time.h"
  27. #include "apr_errno.h"
  28. #if APR_HAVE_SYS_UIO_H
  29. #include <sys/uio.h>
  30. #endif
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif /* __cplusplus */
  34. /**
  35. * @defgroup apr_file_info File Information
  36. * @ingroup APR
  37. * @{
  38. */
  39. /* Many applications use the type member to determine the
  40. * existance of a file or initialization of the file info,
  41. * so the APR_NOFILE value must be distinct from APR_UNKFILE.
  42. */
  43. /** apr_filetype_e values for the filetype member of the
  44. * apr_file_info_t structure
  45. * @warning Not all of the filetypes below can be determined.
  46. * For example, a given platform might not correctly report
  47. * a socket descriptor as APR_SOCK if that type isn't
  48. * well-identified on that platform. In such cases where
  49. * a filetype exists but cannot be described by the recognized
  50. * flags below, the filetype will be APR_UNKFILE. If the
  51. * filetype member is not determined, the type will be APR_NOFILE.
  52. */
  53. typedef enum {
  54. APR_NOFILE = 0, /**< no file type determined */
  55. APR_REG, /**< a regular file */
  56. APR_DIR, /**< a directory */
  57. APR_CHR, /**< a character device */
  58. APR_BLK, /**< a block device */
  59. APR_PIPE, /**< a FIFO / pipe */
  60. APR_LNK, /**< a symbolic link */
  61. APR_SOCK, /**< a [unix domain] socket */
  62. APR_UNKFILE = 127 /**< a file of some other unknown type */
  63. } apr_filetype_e;
  64. /**
  65. * @defgroup apr_file_permissions File Permissions flags
  66. * @{
  67. */
  68. #define APR_FPROT_USETID 0x8000 /**< Set user id */
  69. #define APR_FPROT_UREAD 0x0400 /**< Read by user */
  70. #define APR_FPROT_UWRITE 0x0200 /**< Write by user */
  71. #define APR_FPROT_UEXECUTE 0x0100 /**< Execute by user */
  72. #define APR_FPROT_GSETID 0x4000 /**< Set group id */
  73. #define APR_FPROT_GREAD 0x0040 /**< Read by group */
  74. #define APR_FPROT_GWRITE 0x0020 /**< Write by group */
  75. #define APR_FPROT_GEXECUTE 0x0010 /**< Execute by group */
  76. #define APR_FPROT_WSTICKY 0x2000 /**< Sticky bit */
  77. #define APR_FPROT_WREAD 0x0004 /**< Read by others */
  78. #define APR_FPROT_WWRITE 0x0002 /**< Write by others */
  79. #define APR_FPROT_WEXECUTE 0x0001 /**< Execute by others */
  80. #define APR_FPROT_OS_DEFAULT 0x0FFF /**< use OS's default permissions */
  81. /* additional permission flags for apr_file_copy and apr_file_append */
  82. #define APR_FPROT_FILE_SOURCE_PERMS 0x1000 /**< Copy source file's permissions */
  83. /* backcompat */
  84. #define APR_USETID APR_FPROT_USETID /**< @deprecated @see APR_FPROT_USETID */
  85. #define APR_UREAD APR_FPROT_UREAD /**< @deprecated @see APR_FPROT_UREAD */
  86. #define APR_UWRITE APR_FPROT_UWRITE /**< @deprecated @see APR_FPROT_UWRITE */
  87. #define APR_UEXECUTE APR_FPROT_UEXECUTE /**< @deprecated @see APR_FPROT_UEXECUTE */
  88. #define APR_GSETID APR_FPROT_GSETID /**< @deprecated @see APR_FPROT_GSETID */
  89. #define APR_GREAD APR_FPROT_GREAD /**< @deprecated @see APR_FPROT_GREAD */
  90. #define APR_GWRITE APR_FPROT_GWRITE /**< @deprecated @see APR_FPROT_GWRITE */
  91. #define APR_GEXECUTE APR_FPROT_GEXECUTE /**< @deprecated @see APR_FPROT_GEXECUTE */
  92. #define APR_WSTICKY APR_FPROT_WSTICKY /**< @deprecated @see APR_FPROT_WSTICKY */
  93. #define APR_WREAD APR_FPROT_WREAD /**< @deprecated @see APR_FPROT_WREAD */
  94. #define APR_WWRITE APR_FPROT_WWRITE /**< @deprecated @see APR_FPROT_WWRITE */
  95. #define APR_WEXECUTE APR_FPROT_WEXECUTE /**< @deprecated @see APR_FPROT_WEXECUTE */
  96. #define APR_OS_DEFAULT APR_FPROT_OS_DEFAULT /**< @deprecated @see APR_FPROT_OS_DEFAULT */
  97. #define APR_FILE_SOURCE_PERMS APR_FPROT_FILE_SOURCE_PERMS /**< @deprecated @see APR_FPROT_FILE_SOURCE_PERMS */
  98. /** @} */
  99. /**
  100. * Structure for referencing directories.
  101. */
  102. typedef struct apr_dir_t apr_dir_t;
  103. /**
  104. * Structure for determining file permissions.
  105. */
  106. typedef apr_int32_t apr_fileperms_t;
  107. #if (defined WIN32) || (defined NETWARE)
  108. /**
  109. * Structure for determining the device the file is on.
  110. */
  111. typedef apr_uint32_t apr_dev_t;
  112. #else
  113. /**
  114. * Structure for determining the device the file is on.
  115. */
  116. typedef dev_t apr_dev_t;
  117. #endif
  118. /**
  119. * @defgroup apr_file_stat Stat Functions
  120. * @{
  121. */
  122. /** file info structure */
  123. typedef struct apr_finfo_t apr_finfo_t;
  124. #define APR_FINFO_LINK 0x00000001 /**< Stat the link not the file itself if it is a link */
  125. #define APR_FINFO_MTIME 0x00000010 /**< Modification Time */
  126. #define APR_FINFO_CTIME 0x00000020 /**< Creation or inode-changed time */
  127. #define APR_FINFO_ATIME 0x00000040 /**< Access Time */
  128. #define APR_FINFO_SIZE 0x00000100 /**< Size of the file */
  129. #define APR_FINFO_CSIZE 0x00000200 /**< Storage size consumed by the file */
  130. #define APR_FINFO_DEV 0x00001000 /**< Device */
  131. #define APR_FINFO_INODE 0x00002000 /**< Inode */
  132. #define APR_FINFO_NLINK 0x00004000 /**< Number of links */
  133. #define APR_FINFO_TYPE 0x00008000 /**< Type */
  134. #define APR_FINFO_USER 0x00010000 /**< User */
  135. #define APR_FINFO_GROUP 0x00020000 /**< Group */
  136. #define APR_FINFO_UPROT 0x00100000 /**< User protection bits */
  137. #define APR_FINFO_GPROT 0x00200000 /**< Group protection bits */
  138. #define APR_FINFO_WPROT 0x00400000 /**< World protection bits */
  139. #define APR_FINFO_ICASE 0x01000000 /**< if dev is case insensitive */
  140. #define APR_FINFO_NAME 0x02000000 /**< ->name in proper case */
  141. #define APR_FINFO_MIN 0x00008170 /**< type, mtime, ctime, atime, size */
  142. #define APR_FINFO_IDENT 0x00003000 /**< dev and inode */
  143. #define APR_FINFO_OWNER 0x00030000 /**< user and group */
  144. #define APR_FINFO_PROT 0x00700000 /**< all protections */
  145. #define APR_FINFO_NORM 0x0073b170 /**< an atomic unix apr_stat() */
  146. #define APR_FINFO_DIRENT 0x02000000 /**< an atomic unix apr_dir_read() */
  147. /**
  148. * The file information structure. This is analogous to the POSIX
  149. * stat structure.
  150. */
  151. struct apr_finfo_t {
  152. /** Allocates memory and closes lingering handles in the specified pool */
  153. apr_pool_t *pool;
  154. /** The bitmask describing valid fields of this apr_finfo_t structure
  155. * including all available 'wanted' fields and potentially more */
  156. apr_int32_t valid;
  157. /** The access permissions of the file. Mimics Unix access rights. */
  158. apr_fileperms_t protection;
  159. /** The type of file. One of APR_REG, APR_DIR, APR_CHR, APR_BLK, APR_PIPE,
  160. * APR_LNK or APR_SOCK. If the type is undetermined, the value is APR_NOFILE.
  161. * If the type cannot be determined, the value is APR_UNKFILE.
  162. */
  163. apr_filetype_e filetype;
  164. /** The user id that owns the file */
  165. apr_uid_t user;
  166. /** The group id that owns the file */
  167. apr_gid_t group;
  168. /** The inode of the file. */
  169. apr_ino_t inode;
  170. /** The id of the device the file is on. */
  171. apr_dev_t device;
  172. /** The number of hard links to the file. */
  173. apr_int32_t nlink;
  174. /** The size of the file */
  175. apr_off_t size;
  176. /** The storage size consumed by the file */
  177. apr_off_t csize;
  178. /** The time the file was last accessed */
  179. apr_time_t atime;
  180. /** The time the file was last modified */
  181. apr_time_t mtime;
  182. /** The time the file was created, or the inode was last changed */
  183. apr_time_t ctime;
  184. /** The pathname of the file (possibly unrooted) */
  185. const char *fname;
  186. /** The file's name (no path) in filesystem case */
  187. const char *name;
  188. /** Unused */
  189. struct apr_file_t *filehand;
  190. };
  191. /**
  192. * get the specified file's stats. The file is specified by filename,
  193. * instead of using a pre-opened file.
  194. * @param finfo Where to store the information about the file, which is
  195. * never touched if the call fails.
  196. * @param fname The name of the file to stat.
  197. * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_
  198. values
  199. * @param pool the pool to use to allocate the new file.
  200. *
  201. * @note If @c APR_INCOMPLETE is returned all the fields in @a finfo may
  202. * not be filled in, and you need to check the @c finfo->valid bitmask
  203. * to verify that what you're looking for is there.
  204. */
  205. APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo, const char *fname,
  206. apr_int32_t wanted, apr_pool_t *pool);
  207. /** @} */
  208. /**
  209. * @defgroup apr_dir Directory Manipulation Functions
  210. * @{
  211. */
  212. /**
  213. * Open the specified directory.
  214. * @param new_dir The opened directory descriptor.
  215. * @param dirname The full path to the directory (use / on all systems)
  216. * @param pool The pool to use.
  217. */
  218. APR_DECLARE(apr_status_t) apr_dir_open(apr_dir_t **new_dir,
  219. const char *dirname,
  220. apr_pool_t *pool);
  221. /**
  222. * close the specified directory.
  223. * @param thedir the directory descriptor to close.
  224. */
  225. APR_DECLARE(apr_status_t) apr_dir_close(apr_dir_t *thedir);
  226. /**
  227. * Read the next entry from the specified directory.
  228. * @param finfo the file info structure and filled in by apr_dir_read
  229. * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_
  230. values
  231. * @param thedir the directory descriptor returned from apr_dir_open
  232. * @remark No ordering is guaranteed for the entries read.
  233. *
  234. * @note If @c APR_INCOMPLETE is returned all the fields in @a finfo may
  235. * not be filled in, and you need to check the @c finfo->valid bitmask
  236. * to verify that what you're looking for is there. When no more
  237. * entries are available, APR_ENOENT is returned.
  238. */
  239. APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted,
  240. apr_dir_t *thedir);
  241. /**
  242. * Rewind the directory to the first entry.
  243. * @param thedir the directory descriptor to rewind.
  244. */
  245. APR_DECLARE(apr_status_t) apr_dir_rewind(apr_dir_t *thedir);
  246. /** @} */
  247. /**
  248. * @defgroup apr_filepath Filepath Manipulation Functions
  249. * @{
  250. */
  251. /** Cause apr_filepath_merge to fail if addpath is above rootpath
  252. * @bug in APR 0.9 and 1.x, this flag's behavior is undefined
  253. * if the rootpath is NULL or empty. In APR 2.0 this should be
  254. * changed to imply NOTABSOLUTE if the rootpath is NULL or empty.
  255. */
  256. #define APR_FILEPATH_NOTABOVEROOT 0x01
  257. /** internal: Only meaningful with APR_FILEPATH_NOTABOVEROOT */
  258. #define APR_FILEPATH_SECUREROOTTEST 0x02
  259. /** Cause apr_filepath_merge to fail if addpath is above rootpath,
  260. * even given a rootpath /foo/bar and an addpath ../bar/bash
  261. */
  262. #define APR_FILEPATH_SECUREROOT 0x03
  263. /** Fail apr_filepath_merge if the merged path is relative */
  264. #define APR_FILEPATH_NOTRELATIVE 0x04
  265. /** Fail apr_filepath_merge if the merged path is absolute */
  266. #define APR_FILEPATH_NOTABSOLUTE 0x08
  267. /** Return the file system's native path format (e.g. path delimiters
  268. * of ':' on MacOS9, '\' on Win32, etc.) */
  269. #define APR_FILEPATH_NATIVE 0x10
  270. /** Resolve the true case of existing directories and file elements
  271. * of addpath, (resolving any aliases on Win32) and append a proper
  272. * trailing slash if a directory
  273. */
  274. #define APR_FILEPATH_TRUENAME 0x20
  275. /**
  276. * Extract the rootpath from the given filepath
  277. * @param rootpath the root file path returned with APR_SUCCESS or APR_EINCOMPLETE
  278. * @param filepath the pathname to parse for its root component
  279. * @param flags the desired rules to apply, from
  280. * <PRE>
  281. * APR_FILEPATH_NATIVE Use native path separators (e.g. '\' on Win32)
  282. * APR_FILEPATH_TRUENAME Tests that the root exists, and makes it proper
  283. * </PRE>
  284. * @param p the pool to allocate the new path string from
  285. * @remark on return, filepath points to the first non-root character in the
  286. * given filepath. In the simplest example, given a filepath of "/foo",
  287. * returns the rootpath of "/" and filepath points at "foo". This is far
  288. * more complex on other platforms, which will canonicalize the root form
  289. * to a consistant format, given the APR_FILEPATH_TRUENAME flag, and also
  290. * test for the validity of that root (e.g., that a drive d:/ or network
  291. * share //machine/foovol/).
  292. * The function returns APR_ERELATIVE if filepath isn't rooted (an
  293. * error), APR_EINCOMPLETE if the root path is ambiguous (but potentially
  294. * legitimate, e.g. "/" on Windows is incomplete because it doesn't specify
  295. * the drive letter), or APR_EBADPATH if the root is simply invalid.
  296. * APR_SUCCESS is returned if filepath is an absolute path.
  297. */
  298. APR_DECLARE(apr_status_t) apr_filepath_root(const char **rootpath,
  299. const char **filepath,
  300. apr_int32_t flags,
  301. apr_pool_t *p);
  302. /**
  303. * Merge additional file path onto the previously processed rootpath
  304. * @param newpath the merged paths returned
  305. * @param rootpath the root file path (NULL uses the current working path)
  306. * @param addpath the path to add to the root path
  307. * @param flags the desired APR_FILEPATH_ rules to apply when merging
  308. * @param p the pool to allocate the new path string from
  309. * @remark if the flag APR_FILEPATH_TRUENAME is given, and the addpath
  310. * contains wildcard characters ('*', '?') on platforms that don't support
  311. * such characters within filenames, the paths will be merged, but the
  312. * result code will be APR_EPATHWILD, and all further segments will not
  313. * reflect the true filenames including the wildcard and following segments.
  314. */
  315. APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath,
  316. const char *rootpath,
  317. const char *addpath,
  318. apr_int32_t flags,
  319. apr_pool_t *p);
  320. /**
  321. * Split a search path into separate components
  322. * @param pathelts the returned components of the search path
  323. * @param liststr the search path (e.g., <tt>getenv("PATH")</tt>)
  324. * @param p the pool to allocate the array and path components from
  325. * @remark empty path components do not become part of @a pathelts.
  326. * @remark the path separator in @a liststr is system specific;
  327. * e.g., ':' on Unix, ';' on Windows, etc.
  328. */
  329. APR_DECLARE(apr_status_t) apr_filepath_list_split(apr_array_header_t **pathelts,
  330. const char *liststr,
  331. apr_pool_t *p);
  332. /**
  333. * Merge a list of search path components into a single search path
  334. * @param liststr the returned search path; may be NULL if @a pathelts is empty
  335. * @param pathelts the components of the search path
  336. * @param p the pool to allocate the search path from
  337. * @remark emtpy strings in the source array are ignored.
  338. * @remark the path separator in @a liststr is system specific;
  339. * e.g., ':' on Unix, ';' on Windows, etc.
  340. */
  341. APR_DECLARE(apr_status_t) apr_filepath_list_merge(char **liststr,
  342. apr_array_header_t *pathelts,
  343. apr_pool_t *p);
  344. /**
  345. * Return the default file path (for relative file names)
  346. * @param path the default path string returned
  347. * @param flags optional flag APR_FILEPATH_NATIVE to retrieve the
  348. * default file path in os-native format.
  349. * @param p the pool to allocate the default path string from
  350. */
  351. APR_DECLARE(apr_status_t) apr_filepath_get(char **path, apr_int32_t flags,
  352. apr_pool_t *p);
  353. /**
  354. * Set the default file path (for relative file names)
  355. * @param path the default path returned
  356. * @param p the pool to allocate any working storage
  357. */
  358. APR_DECLARE(apr_status_t) apr_filepath_set(const char *path, apr_pool_t *p);
  359. /** The FilePath character encoding is unknown */
  360. #define APR_FILEPATH_ENCODING_UNKNOWN 0
  361. /** The FilePath character encoding is locale-dependent */
  362. #define APR_FILEPATH_ENCODING_LOCALE 1
  363. /** The FilePath character encoding is UTF-8 */
  364. #define APR_FILEPATH_ENCODING_UTF8 2
  365. /**
  366. * Determine the encoding used internally by the FilePath functions
  367. * @param style points to a variable which receives the encoding style flag
  368. * @param p the pool to allocate any working storage
  369. * @remark Use apr_os_locale_encoding() and/or apr_os_default_encoding()
  370. * to get the name of the path encoding if it's not UTF-8.
  371. */
  372. APR_DECLARE(apr_status_t) apr_filepath_encoding(int *style, apr_pool_t *p);
  373. /** @} */
  374. /** @} */
  375. #ifdef __cplusplus
  376. }
  377. #endif
  378. #endif /* ! APR_FILE_INFO_H */