delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / kioslave / fish / fish.h
blob2991631d7f50e09d55bd91e0df000cc0041906ae
1 /***************************************************************************
2 fish.h - a FISH kioslave
3 -------------------
4 begin : Thu Oct 4 17:09:14 CEST 2001
5 copyright : (C) 2001 by Jörg Walter
6 email : trouble@garni.ch
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, version 2 of the License *
14 * *
15 ***************************************************************************/
16 #ifndef FISH_H
17 #define FISH_H
19 #include <kurl.h>
20 #include <kio/global.h>
21 #include <kio/slavebase.h>
22 #include <kprocess.h>
23 #include <kio/authinfo.h>
24 #include <time.h>
26 #define FISH_EXEC_CMD 'X'
28 class fishProtocol : public KIO::SlaveBase
30 public:
31 fishProtocol(const QByteArray &pool_socket, const QByteArray &app_socket);
32 virtual ~fishProtocol();
34 /**
35 Connects to a server and logs us in via SSH. Then starts FISH protocol.
36 @ref isConnected is set to true if logging on was successful.
37 It is set to false if the connection becomes closed.
40 void openConnection();
42 /**
43 Clean up connection
45 void shutdownConnection(bool forced=false);
46 /** sets connection information for subsequent commands */
47 void setHost(const QString & host, quint16 port, const QString & user, const QString & pass);
48 /** Forced close of the connection */
49 void closeConnection();
50 /** get a file */
51 void get(const KUrl& url);
52 /** put a file */
53 void put(const KUrl& url, int permissions, KIO::JobFlags flags );
54 /** aborts command sequence and calls error() */
55 void error(int type, const QString &detail);
56 /** executes next command in sequence or calls finished() if all is done */
57 void finished();
58 /** stat a file */
59 void stat(const KUrl& url);
60 /** find mimetype for a file */
61 void mimetype(const KUrl& url);
62 /** list a directory */
63 void listDir(const KUrl& url);
64 /** create a directory */
65 void mkdir(const KUrl&url, int permissions);
66 /** rename a file */
67 void rename(const KUrl& src, const KUrl& dest, KIO::JobFlags flags);
68 /** create a symlink */
69 void symlink(const QString& target, const KUrl& dest, KIO::JobFlags flags);
70 /** change file permissions */
71 void chmod(const KUrl& url, int permissions);
72 /** copies a file */
73 void copy(const KUrl &src, const KUrl &dest, int permissions, KIO::JobFlags flags);
74 /** report status */
75 void slave_status();
76 /** removes a file or directory */
77 void del(const KUrl &u, bool isfile);
78 /** special like background execute */
79 void special( const QByteArray &data );
81 private: // Private attributes
82 /** fd for reading and writing to the process */
83 int childFd;
84 /** buffer for data to be written */
85 #ifndef Q_WS_WIN
86 const char *outBuf;
87 #else
88 QByteArray outBuf;
89 #endif
90 /** current write position in buffer */
91 KIO::fileoffset_t outBufPos;
92 /** length of buffer */
93 KIO::fileoffset_t outBufLen;
94 /** use su if true else use ssh */
95 bool local;
96 /** // FIXME: just a workaround for konq deficiencies */
97 bool isStat;
98 /** // FIXME: just a workaround for konq deficiencies */
99 QString redirectUser, redirectPass;
101 protected: // Protected attributes
102 /** for LIST/STAT */
103 KIO::UDSEntry udsEntry;
104 /** for LIST/STAT */
105 KIO::UDSEntry udsStatEntry;
106 /** for LIST/STAT */
107 long long udsType;
108 /** for LIST/STAT */
109 QString udsMime;
110 /** for LIST/STAT */
111 QString thisFn;
112 /** for STAT */
113 QString wantedFn;
114 QString statPath;
115 /** url of current request */
116 KUrl url;
117 /** true if connection is logged in successfully */
118 bool isLoggedIn;
119 /** host name of current connection */
120 QString connectionHost;
121 /** user name of current connection */
122 QString connectionUser;
123 /** port of current connection */
124 int connectionPort;
125 /** password of current connection */
126 QString connectionPassword;
127 /** AuthInfo object used for logging in */
128 KIO::AuthInfo connectionAuth;
129 /** number of lines received, == 0 -> everything went ok */
130 int errorCount;
131 /** queue for lines to be sent */
132 QList<QByteArray> qlist;
133 /** queue for commands to be sent */
134 QStringList commandList;
135 /** queue for commands to be sent */
136 QList<int> commandCodes;
137 /** bytes still to be read in raw mode */
138 KIO::fileoffset_t rawRead;
139 /** bytes still to be written in raw mode */
140 KIO::fileoffset_t rawWrite;
141 /** data bytes to read in next read command */
142 KIO::fileoffset_t recvLen;
143 /** data bytes to write in next write command */
144 KIO::fileoffset_t sendLen;
145 /** true if the last write operation was finished */
146 bool writeReady;
147 /** true if a command stack is currently executing */
148 bool isRunning;
149 /** reason of LIST command */
150 enum { CHECK, LIST } listReason;
151 /** true if FISH server understands APPEND command */
152 bool hasAppend;
153 /** permission of created file */
154 int putPerm;
155 /** true if file may be overwritten */
156 bool checkOverwrite;
157 /** current position of write */
158 KIO::fileoffset_t putPos;
159 /** true if file already existed */
160 bool checkExist;
161 /** true if this is the first login attempt (== use cached password) */
162 bool firstLogin;
163 /** write buffer */
164 QByteArray rawData;
165 /** buffer for storing bytes used for MimeMagic */
166 QByteArray mimeBuffer;
167 /** whther the mimetype has been sent already */
168 bool mimeTypeSent;
169 /** number of bytes read so far */
170 KIO::fileoffset_t dataRead;
171 /** details about each fishCommand */
172 static const struct fish_info {
173 const char *command;
174 int params;
175 const char *alt;
176 int lines;
177 } fishInfo[];
178 /** last FISH command sent to server */
179 enum fish_command_type { FISH_FISH, FISH_VER, FISH_PWD, FISH_LIST, FISH_STAT,
180 FISH_RETR, FISH_STOR,
181 FISH_CWD, FISH_CHMOD, FISH_DELE, FISH_MKD, FISH_RMD,
182 FISH_RENAME, FISH_LINK, FISH_SYMLINK, FISH_CHOWN,
183 FISH_CHGRP, FISH_READ, FISH_WRITE, FISH_COPY, FISH_APPEND, FISH_EXEC } fishCommand;
184 int fishCodeLen;
185 protected: // Protected methods
186 /** manages initial communication setup including password queries */
187 #ifndef Q_WS_WIN
188 int establishConnection(char *buffer, KIO::fileoffset_t buflen);
189 #else
190 int establishConnection(const QByteArray &buffer);
191 #endif
192 int received(const char *buffer, KIO::fileoffset_t buflen);
193 void sent();
194 /** builds each FISH request and sets the error counter */
195 bool sendCommand(fish_command_type cmd, ...);
196 /** checks response string for result code, converting 000 and 001 appropriately */
197 int handleResponse(const QString &str);
198 /** parses a ls -l time spec */
199 int makeTimeFromLs(const QString &dayStr, const QString &monthStr, const QString &timeyearStr);
200 /** executes a chain of commands */
201 void run();
202 /** creates the subprocess */
203 bool connectionStart();
204 /** writes one chunk of data to stdin of child process */
205 #ifndef Q_WS_WIN
206 void writeChild(const char *buf, KIO::fileoffset_t len);
207 #else
208 void writeChild(const QByteArray &buf, KIO::fileoffset_t len);
209 #endif
210 /** parses response from server and acts accordingly */
211 void manageConnection(const QString &line);
212 /** writes to process */
213 void writeStdin(const QString &line);
214 /** Verify port **/
215 void setHostInternal(const KUrl & u);
220 #endif