001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.daemon.platform;
027:
028: import com.sshtools.daemon.configuration.*;
029:
030: import com.sshtools.j2ssh.configuration.*;
031: import com.sshtools.j2ssh.io.*;
032: import com.sshtools.j2ssh.sftp.*;
033:
034: import org.apache.commons.logging.*;
035:
036: import java.io.*;
037:
038: /**
039: *
040: *
041: * @author $author$
042: * @version $Revision: 1.13 $
043: */
044: public abstract class NativeFileSystemProvider {
045: private static Log log = LogFactory
046: .getLog(NativeAuthenticationProvider.class);
047: private static NativeFileSystemProvider instance;
048:
049: /** */
050: public static final int OPEN_READ = SftpSubsystemClient.OPEN_READ;
051:
052: /** */
053: public static final int OPEN_WRITE = SftpSubsystemClient.OPEN_WRITE;
054:
055: /** */
056: public static final int OPEN_APPEND = SftpSubsystemClient.OPEN_APPEND;
057:
058: /** */
059: public static final int OPEN_CREATE = SftpSubsystemClient.OPEN_CREATE;
060:
061: /** */
062: public static final int OPEN_TRUNCATE = SftpSubsystemClient.OPEN_TRUNCATE;
063:
064: /** */
065: public static final int OPEN_EXCLUSIVE = SftpSubsystemClient.OPEN_EXCLUSIVE;
066:
067: static {
068: try {
069: if (ConfigurationLoader
070: .isConfigurationAvailable(PlatformConfiguration.class)) {
071: Class cls = ConfigurationLoader
072: .getExtensionClass(((PlatformConfiguration) ConfigurationLoader
073: .getConfiguration(PlatformConfiguration.class))
074: .getNativeFileSystemProvider());
075: instance = (NativeFileSystemProvider) cls.newInstance();
076: }
077: } catch (Exception e) {
078: log.error("Failed to load native file system provider", e);
079: instance = null;
080: }
081: }
082:
083: /**
084: *
085: *
086: * @param path
087: *
088: * @return
089: *
090: * @throws PermissionDeniedException
091: * @throws FileNotFoundException
092: * @throws IOException
093: */
094: public abstract boolean fileExists(String path) throws IOException;
095:
096: /**
097: *
098: *
099: * @param path
100: *
101: * @return
102: *
103: * @throws PermissionDeniedException
104: * @throws FileNotFoundException
105: * @throws IOException
106: */
107: public abstract String getCanonicalPath(String path)
108: throws IOException, FileNotFoundException;
109:
110: /**
111: *
112: *
113: * @param path
114: *
115: * @return
116: *
117: * @throws FileNotFoundException
118: */
119: public abstract String getRealPath(String path)
120: throws FileNotFoundException;
121:
122: /**
123: *
124: *
125: * @param path
126: *
127: * @return
128: *
129: * @throws PermissionDeniedException
130: * @throws FileNotFoundException
131: * @throws IOException
132: */
133: public abstract boolean makeDirectory(String path)
134: throws PermissionDeniedException, FileNotFoundException,
135: IOException;
136:
137: /**
138: *
139: *
140: * @param path
141: *
142: * @return
143: *
144: * @throws IOException
145: * @throws FileNotFoundException
146: */
147: public abstract FileAttributes getFileAttributes(String path)
148: throws IOException, FileNotFoundException;
149:
150: /**
151: *
152: *
153: * @param handle
154: *
155: * @return
156: *
157: * @throws IOException
158: * @throws InvalidHandleException
159: */
160: public abstract FileAttributes getFileAttributes(byte[] handle)
161: throws IOException, InvalidHandleException;
162:
163: /**
164: *
165: *
166: * @param path
167: *
168: * @return
169: *
170: * @throws PermissionDeniedException
171: * @throws FileNotFoundException
172: * @throws IOException
173: */
174: public abstract byte[] openDirectory(String path)
175: throws PermissionDeniedException, FileNotFoundException,
176: IOException;
177:
178: /**
179: *
180: *
181: * @param handle
182: *
183: * @return
184: *
185: * @throws InvalidHandleException
186: * @throws EOFException
187: */
188: public abstract SftpFile[] readDirectory(byte[] handle)
189: throws InvalidHandleException, EOFException, IOException;
190:
191: /**
192: *
193: *
194: * @param path
195: * @param flags
196: * @param attrs
197: *
198: * @return
199: *
200: * @throws PermissionDeniedException
201: * @throws FileNotFoundException
202: * @throws IOException
203: */
204: public abstract byte[] openFile(String path,
205: UnsignedInteger32 flags, FileAttributes attrs)
206: throws PermissionDeniedException, FileNotFoundException,
207: IOException;
208:
209: /**
210: *
211: *
212: * @param handle
213: * @param offset
214: * @param len
215: *
216: * @return
217: *
218: * @throws InvalidHandleException
219: * @throws EOFException
220: * @throws IOException
221: */
222: public abstract byte[] readFile(byte[] handle,
223: UnsignedInteger64 offset, UnsignedInteger32 len)
224: throws InvalidHandleException, EOFException, IOException;
225:
226: /**
227: *
228: *
229: * @param handle
230: * @param offset
231: * @param data
232: * @param off
233: * @param len
234: *
235: * @throws InvalidHandleException
236: * @throws IOException
237: */
238: public abstract void writeFile(byte[] handle,
239: UnsignedInteger64 offset, byte[] data, int off, int len)
240: throws InvalidHandleException, IOException;
241:
242: /**
243: *
244: *
245: * @param handle
246: *
247: * @throws InvalidHandleException
248: * @throws IOException
249: */
250: public abstract void closeFile(byte[] handle)
251: throws InvalidHandleException, IOException;
252:
253: /**
254: *
255: *
256: * @param path
257: *
258: * @throws PermissionDeniedException
259: * @throws IOException
260: * @throws FileNotFoundException
261: */
262: public abstract void removeFile(String path)
263: throws PermissionDeniedException, IOException,
264: FileNotFoundException;
265:
266: /**
267: *
268: *
269: * @param oldpath
270: * @param newpath
271: *
272: * @throws PermissionDeniedException
273: * @throws FileNotFoundException
274: * @throws IOException
275: */
276: public abstract void renameFile(String oldpath, String newpath)
277: throws PermissionDeniedException, FileNotFoundException,
278: IOException;
279:
280: /**
281: *
282: *
283: * @param path
284: *
285: * @throws PermissionDeniedException
286: * @throws FileNotFoundException
287: * @throws IOException
288: */
289: public abstract void removeDirectory(String path)
290: throws PermissionDeniedException, FileNotFoundException,
291: IOException;
292:
293: /**
294: *
295: *
296: * @param path
297: * @param attrs
298: *
299: * @throws PermissionDeniedException
300: * @throws IOException
301: * @throws FileNotFoundException
302: */
303: public abstract void setFileAttributes(String path,
304: FileAttributes attrs) throws PermissionDeniedException,
305: IOException, FileNotFoundException;
306:
307: /**
308: *
309: *
310: * @param handle
311: * @param attrs
312: *
313: * @throws PermissionDeniedException
314: * @throws IOException
315: * @throws InvalidHandleException
316: */
317: public abstract void setFileAttributes(byte[] handle,
318: FileAttributes attrs) throws PermissionDeniedException,
319: IOException, InvalidHandleException;
320:
321: /**
322: *
323: *
324: * @param path
325: *
326: * @return
327: *
328: * @throws UnsupportedFileOperationException
329: * @throws FileNotFoundException
330: * @throws IOException
331: * @throws PermissionDeniedException
332: */
333: public abstract SftpFile readSymbolicLink(String path)
334: throws UnsupportedFileOperationException,
335: FileNotFoundException, IOException,
336: PermissionDeniedException;
337:
338: /**
339: *
340: *
341: * @param link
342: * @param target
343: *
344: * @throws UnsupportedFileOperationException
345: * @throws FileNotFoundException
346: * @throws IOException
347: * @throws PermissionDeniedException
348: */
349: public abstract void createSymbolicLink(String link, String target)
350: throws UnsupportedFileOperationException,
351: FileNotFoundException, IOException,
352: PermissionDeniedException;
353:
354: public abstract String getDefaultPath(String username)
355: throws FileNotFoundException;
356:
357: /**
358: *
359: *
360: * @param username
361: * @param path
362: * @param permissions
363: *
364: * @throws PermissionDeniedException
365: * @throws FileNotFoundException
366: * @throws IOException
367: */
368: public abstract void verifyPermissions(String username,
369: String path, String permissions)
370: throws PermissionDeniedException, FileNotFoundException,
371: IOException;
372:
373: /**
374: *
375: *
376: * @return
377: */
378: public static NativeFileSystemProvider getInstance() {
379: return instance;
380: }
381: }
|