add more spacing
[personal-kdebase.git] / runtime / kioslave / sftp / kio_sftp.h
blob26b5e2d0e5fde8e56c49e8360928d5bd62b80ce3
1 /***************************************************************************
2 sftpProtocol.h - description
3 -------------------
4 begin : Sat Jun 30 20:08:47 CDT 2001
5 copyright : (C) 2001 by Lucas Fisher
6 email : ljfisher@purdue.edu
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17 #ifndef __kio_sftp_h__
18 #define __kio_sftp_h__
21 #include <QObject>
23 #include <kurl.h>
24 #include <kio/global.h>
25 #include <kio/slavebase.h>
26 #include <kdebug.h>
28 #include "process.h"
29 #include "sftpfileattr.h"
30 #include "ksshprocess.h"
32 #define KIO_SFTP_DB 7120
35 class sftpProtocol : public KIO::SlaveBase
38 public:
39 sftpProtocol(const QByteArray &pool_socket, const QByteArray &app_socket);
40 virtual ~sftpProtocol();
41 virtual void setHost(const QString& h, quint16 port, const QString& user, const QString& pass);
42 virtual void get(const KUrl& url);
43 virtual void listDir(const KUrl& url) ;
44 virtual void mimetype(const KUrl& url);
45 virtual void stat(const KUrl& url);
46 virtual void copy(const KUrl &src, const KUrl &dest, int permissions, KIO::JobFlags flags);
47 virtual void put(const KUrl& url, int permissions, KIO::JobFlags flags);
48 virtual void closeConnection();
49 virtual void slave_status();
50 virtual void del(const KUrl &url, bool isfile);
51 virtual void chmod(const KUrl& url, int permissions);
52 virtual void symlink(const QString& target, const KUrl& dest, KIO::JobFlags flags);
53 virtual void rename(const KUrl& src, const KUrl& dest, KIO::JobFlags flags);
54 virtual void mkdir(const KUrl&url, int permissions);
55 virtual void openConnection();
57 // KIO::FileJob interface
58 virtual void open(const KUrl &url, QIODevice::OpenMode mode);
59 virtual void read(KIO::filesize_t size);
60 virtual void write(const QByteArray &data);
61 virtual void seek(KIO::filesize_t offset);
62 virtual void close();
64 private: // Private variables
65 /** True if ioslave is connected to sftp server. */
66 bool mConnected;
68 /** Host we are connected to. */
69 QString mHost;
71 /** Port we are connected to. */
72 int mPort;
74 /** Ssh process to which we send the sftp packets. */
75 KSshProcess ssh;
77 /** Username to use when connecting */
78 QString mUsername;
80 /** User's password */
81 QString mPassword;
83 /** Message id of the last sftp packet we sent. */
84 unsigned int mMsgId;
86 /** Type of packet we are expecting to receive next. */
87 unsigned char mExpected;
89 /** Version of the sftp protocol we are using. */
90 int sftpVersion;
92 struct Status
94 int code;
95 KIO::filesize_t size;
96 QString text;
99 // KIO::FileJob interface
100 /** The opened handle */
101 QByteArray openHandle;
102 KUrl openUrl;
103 KIO::filesize_t openOffset;
105 private: // private methods
106 bool getPacket(QByteArray& msg);
108 /* Type is a sftp packet type found in .sftp.h'.
109 * Example: SSH2_FXP_READLINK, SSH2_FXP_RENAME, etc.
111 * Returns true if the type is supported by the sftp protocol
112 * version negotiated by the client and server (sftpVersion).
114 bool isSupportedOperation(int type);
115 /** Used to have the server canonicalize any given path name to an absolute path.
116 This is useful for converting path names containing ".." components or relative
117 pathnames without a leading slash into absolute paths.
118 Returns the canonicalized url. */
119 int sftpRealPath(const KUrl& url, KUrl& newUrl);
121 /** Send an sftp packet to stdin of the ssh process. */
122 bool putPacket(QByteArray& p);
123 /** Process SSH_FXP_STATUS packets. */
124 void processStatus(quint8, const QString& message = QString());
125 /** Process SSH_FXP_STATUS packes and return the result. */
126 Status doProcessStatus(quint8, const QString& message = QString());
127 /** Opens a directory handle for url.path. Returns true if succeeds. */
128 int sftpOpenDirectory(const KUrl& url, QByteArray& handle);
129 /** Closes a directory or file handle. */
130 int sftpClose(const QByteArray& handle);
131 /** Send a sftp command to rename a file or directory. */
132 int sftpRename(const KUrl& src, const KUrl& dest);
133 /** Set a files attributes. */
134 int sftpSetStat(const KUrl& url, const sftpFileAttr& attr);
135 /** Sends a sftp command to remove a file or directory. */
136 int sftpRemove(const KUrl& url, bool isfile);
137 /** Creates a symlink named dest to target. */
138 int sftpSymLink(const QString& target, const KUrl& dest);
139 /** Get directory listings. */
140 int sftpReadDir(const QByteArray& handle, const KUrl& url);
141 /** Retrieves the destination of a link. */
142 int sftpReadLink(const KUrl& url, QString& target);
143 /** Stats a file. */
144 int sftpStat(const KUrl& url, sftpFileAttr& attr);
145 /** No descriptions */
146 int sftpOpen(const KUrl& url, const quint32 pflags, const sftpFileAttr& attr, QByteArray& handle);
147 /** No descriptions */
148 int sftpRead(const QByteArray& handle, KIO::filesize_t offset, quint32 len, QByteArray& data);
149 /** No descriptions */
150 int sftpWrite(const QByteArray& handle, KIO::filesize_t offset, const QByteArray& data);
152 /** Performs faster upload when the source is a local file... */
153 void sftpCopyPut(const KUrl& src, const KUrl& dest, int mode, KIO::JobFlags flags);
154 /** Performs faster download when the destination is a local file... */
155 void sftpCopyGet(const KUrl& dest, const KUrl& src, int mode, KIO::JobFlags flags);
157 /** Read a file. This is used by get(), copy(), and mimetype(). */
158 Status sftpGet( const KUrl& src, KIO::filesize_t offset = 0, int fd = -1, bool abortAfterMimeType = false);
159 /** Write a file */
160 void sftpPut( const KUrl& dest, int permissions, KIO::JobFlags flags, int fd = -1);
162 #endif