File: fish.h

package info (click to toggle)
kio-extras 4%3A18.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,364 kB
  • sloc: cpp: 25,948; ansic: 4,443; perl: 1,056; xml: 460; python: 28; sh: 20; makefile: 6
file content (217 lines) | stat: -rw-r--r-- 7,711 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/***************************************************************************
                          fish.h  -  a FISH kioslave
                             -------------------
    begin                : Thu Oct  4 17:09:14 CEST 2001
    copyright            : (C) 2001 by Jörg Walter
    email                : trouble@garni.ch
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, version 2 of the License                *
 *                                                                         *
 ***************************************************************************/
#ifndef FISH_H
#define FISH_H

#include <kio/global.h>
#include <kio/slavebase.h>
#include <kio/authinfo.h>

#define FISH_EXEC_CMD 'X'

class fishProtocol : public KIO::SlaveBase
{
public:
  fishProtocol(const QByteArray &pool_socket, const QByteArray &app_socket);
  ~fishProtocol() override;

  /**
Connects to a server and logs us in via SSH. Then starts FISH protocol.
@ref isConnected is set to true if logging on was successful.
It is set to false if the connection becomes closed.

 */
  void openConnection() override;

  /**
   Clean up connection
  */
  void shutdownConnection(bool forced=false);
  /** sets connection information for subsequent commands */
  void setHost(const QString & host, quint16 port, const QString & user, const QString & pass) override;
  /** Forced close of the connection */
  void closeConnection() override;
  /** get a file */
  void get(const QUrl& url) override;
  /** put a file */
  void put(const QUrl& url, int permissions, KIO::JobFlags flags ) override;
  /** aborts command sequence and calls error() */
  void error(int type, const QString &detail);
  /** executes next command in sequence or calls finished() if all is done */
  void finished();
  /** stat a file */
  void stat(const QUrl& url) override;
  /** find mimetype for a file */
  void mimetype(const QUrl& url) override;
  /** list a directory */
  void listDir(const QUrl& url) override;
  /** create a directory */
  void mkdir(const QUrl&url, int permissions) override;
  /** rename a file */
  void rename(const QUrl& src, const QUrl& dest, KIO::JobFlags flags) override;
  /** create a symlink */
  void symlink(const QString& target, const QUrl& dest, KIO::JobFlags flags) override;
  /** change file permissions */
  void chmod(const QUrl& url, int permissions) override;
  /** copies a file */
  void copy(const QUrl &src, const QUrl &dest, int permissions, KIO::JobFlags flags) override;
  /** report status */
  void slave_status() override;
  /** removes a file or directory */
  void del(const QUrl &u, bool isfile) override;
  /** special like background execute */
  void special( const QByteArray &data ) override;

private: // Private attributes
  /** fd for reading and writing to the process */
  int childFd;
  /** buffer for data to be written */
#ifndef Q_OS_WIN
  const char *outBuf;
#else
  QByteArray outBuf;
#endif
  /** current write position in buffer */
  KIO::fileoffset_t outBufPos;
  /** length of buffer */
  KIO::fileoffset_t outBufLen;
  /** use su if true else use ssh */
  bool local;
  /**  // FIXME: just a workaround for konq deficiencies */
  bool isStat;
  /**  // FIXME: just a workaround for konq deficiencies */
  QString redirectUser, redirectPass;

protected: // Protected attributes
  /** for LIST/STAT */
  KIO::UDSEntry udsEntry;
  /** for LIST/STAT */
  KIO::UDSEntry udsStatEntry;
  /** for LIST/STAT */
  long long udsType;
  /** for LIST/STAT */
  QString udsMime;
  /** for LIST/STAT */
  QString thisFn;
  /** for STAT */
  QString wantedFn;
  QString statPath;
  /** url of current request */
  QUrl url;
  /** true if connection is logged in successfully */
  bool isLoggedIn;
  /** host name of current connection */
  QString connectionHost;
  /** user name of current connection */
  QString connectionUser;
  /** port of current connection */
  int connectionPort;
  /** password of current connection */
  QString connectionPassword;
  /** AuthInfo object used for logging in */
  KIO::AuthInfo connectionAuth;
  /** number of lines received, == 0 -> everything went ok */
  int errorCount;
  /** queue for lines to be sent */
  QList<QByteArray> qlist;
  /** queue for commands to be sent */
  QStringList commandList;
  /** queue for commands to be sent */
  QList<int> commandCodes;
  /** bytes still to be read in raw mode */
  KIO::fileoffset_t rawRead;
  /** bytes still to be written in raw mode */
  KIO::fileoffset_t rawWrite;
  /** data bytes to read in next read command */
  KIO::fileoffset_t recvLen;
  /** data bytes to write in next write command */
  KIO::fileoffset_t sendLen;
  /** true if the last write operation was finished */
  bool writeReady;
  /** true if a command stack is currently executing */
  bool isRunning;
  /** reason of LIST command */
  enum { CHECK, LIST } listReason;
  /** true if FISH server understands APPEND command */
  bool hasAppend;
  /** permission of created file */
  int putPerm;
  /** true if file may be overwritten */
  bool checkOverwrite;
  /** current position of write */
  KIO::fileoffset_t putPos;
  /** true if file already existed */
  bool checkExist;
  /** true if this is the first login attempt (== use cached password) */
  bool firstLogin;
  /** write buffer */
  QByteArray rawData;
  /** buffer for storing bytes used for MimeMagic */
  QByteArray mimeBuffer;
  /** whther the mimetype has been sent already */
  bool mimeTypeSent;
  /** number of bytes read so far */
  KIO::fileoffset_t dataRead;
  /** details about each fishCommand */
  static const struct fish_info {
      const char *command;
      int params;
      const char *alt;
      int lines;
  } fishInfo[];
  /** last FISH command sent to server */
  enum fish_command_type { FISH_FISH, FISH_VER, FISH_PWD, FISH_LIST, FISH_STAT,
    FISH_RETR, FISH_STOR,
    FISH_CWD, FISH_CHMOD, FISH_DELE, FISH_MKD, FISH_RMD,
    FISH_RENAME, FISH_LINK, FISH_SYMLINK, FISH_CHOWN,
    FISH_CHGRP, FISH_READ, FISH_WRITE, FISH_COPY, FISH_APPEND, FISH_EXEC } fishCommand;
  int fishCodeLen;
protected: // Protected methods
  /** manages initial communication setup including password queries */
#ifndef Q_OS_WIN
  int establishConnection(char *buffer, KIO::fileoffset_t buflen);
#else
  int establishConnection(const QByteArray &buffer);
#endif
  int received(const char *buffer, KIO::fileoffset_t buflen);
  void sent();
  /** builds each FISH request and sets the error counter */
  bool sendCommand(fish_command_type cmd, ...);
  /** checks response string for result code, converting 000 and 001 appropriately */
  int handleResponse(const QString &str);
  /** parses a ls -l time spec */
  int makeTimeFromLs(const QString &dayStr, const QString &monthStr, const QString &timeyearStr);
  /** executes a chain of commands */
  void run();
  /** creates the subprocess */
  bool connectionStart();
  /** writes one chunk of data to stdin of child process */
#ifndef Q_OS_WIN
  void writeChild(const char *buf, KIO::fileoffset_t len);
#else
  void writeChild(const QByteArray &buf, KIO::fileoffset_t len);
#endif
  /** parses response from server and acts accordingly */
  void manageConnection(const QString &line);
  /** writes to process */
  void writeStdin(const QString &line);
  /** Verify port **/
  void setHostInternal(const QUrl & u);

};


#endif