Release
[hcoop/zz_old/debian/suphp.git] / src / File.hpp
1 /*
2 suPHP - (c)2002-2008 Sebastian Marsching <sebastian@marsching.com>
3
4 This file is part of suPHP.
5
6 suPHP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 suPHP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with suPHP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef SUPHP_FILE_H
22
23 namespace suPHP {
24 class File;
25
26 enum FileMode {
27 FILEMODE_USER_READ,
28 FILEMODE_USER_WRITE,
29 FILEMODE_USER_EXEC,
30 FILEMODE_GROUP_READ,
31 FILEMODE_GROUP_WRITE,
32 FILEMODE_GROUP_EXEC,
33 FILEMODE_OTHERS_READ,
34 FILEMODE_OTHERS_WRITE,
35 FILEMODE_OTHERS_EXEC
36 };
37 };
38
39 #define SUPHP_FILE_H
40
41 #include <string>
42 #include <iostream>
43 #include <fstream>
44
45 #include "IOException.hpp"
46 #include "SystemException.hpp"
47 #include "SmartPtr.hpp"
48 #include "UserInfo.hpp"
49 #include "GroupInfo.hpp"
50
51
52 namespace suPHP {
53 /**
54 * Class encapsulating file information and access.
55 */
56 class File {
57 private:
58 std::string path;
59 bool hasPermissionBit(FileMode perm) const throw (SystemException);
60
61 public:
62 /**
63 * Constructor
64 */
65 File(std::string path);
66
67 /**
68 * Returns path to file
69 */
70 std::string getPath() const;
71
72 /**
73 * Returns input stream to read from file
74 */
75 SmartPtr<std::ifstream> getInputStream() const throw (IOException);
76
77 /**
78 * Does file exists?
79 */
80 bool exists() const;
81
82 /**
83 * Returns real path to file (without symlinks in path)
84 */
85 std::string getRealPath() const throw (SystemException);
86
87 /**
88 * Returns File object representing parent directory
89 */
90 File getParentDirectory() const;
91
92 /**
93 * Returns permission bit
94 */
95 bool hasUserReadBit() const throw (SystemException);
96
97 /**
98 * Returns permission bit
99 */
100 bool hasUserWriteBit() const throw (SystemException);
101
102 /**
103 * Returns permission bit
104 */
105 bool hasUserExecuteBit() const throw (SystemException);
106
107 /**
108 * Returns permission bit
109 */
110 bool hasGroupReadBit() const throw (SystemException);
111
112 /**
113 * Returns permission bit
114 */
115 bool hasGroupWriteBit() const throw (SystemException);
116
117 /**
118 * Returns permission bit
119 */
120 bool hasGroupExecuteBit() const throw (SystemException);
121
122 /**
123 * Returns permission bit
124 */
125 bool hasOthersReadBit() const throw (SystemException);
126
127 /**
128 * Returns permission bit
129 */
130 bool hasOthersWriteBit() const throw (SystemException);
131
132 /**
133 * Returns permission bit
134 */
135 bool hasOthersExecuteBit() const throw (SystemException);
136
137 /**
138 * Returns owner (user) of file
139 */
140 UserInfo getUser() const throw (SystemException);
141
142 /**
143 * Returns owning group of file
144 */
145 GroupInfo getGroup() const throw (SystemException);
146
147 /**
148 * Checks whether this file is a symlink
149 */
150 bool isSymlink() const throw (SystemException);
151 };
152 };
153
154 #endif // SUPHP_FILE_H