Qt 4.8
Signals | Public Functions | Public Variables | Private Types | Private Slots | Private Functions | Properties | Friends | List of all members
QFtpPI Class Reference
Inheritance diagram for QFtpPI:
QObject

Signals

void connectState (int)
 
void error (int, const QString &)
 
void finished (const QString &)
 
void rawFtpReply (int, const QString &)
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

void abort ()
 
void clearPendingCommands ()
 
void connectToHost (const QString &host, quint16 port)
 
QString currentCommand () const
 
 QFtpPI (QObject *parent=0)
 
bool sendCommand (const QString &cmd)
 
bool sendCommands (const QStringList &cmds)
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Public Variables

QFtpDTP dtp
 
bool rawCommand
 
bool transferConnectionExtended
 

Private Types

enum  AbortState { None, AbortStarted, WaitForAbortToFinish }
 
enum  State {
  Begin, Idle, Waiting, Success,
  Failure
}
 

Private Slots

void connected ()
 
void connectionClosed ()
 
void delayedCloseFinished ()
 
void dtpConnectState (int)
 
void error (QAbstractSocket::SocketError)
 
void hostFound ()
 
void readyRead ()
 

Private Functions

bool processReply ()
 
bool startNextCmd ()
 

Properties

AbortState abortState
 
QByteArray bytesFromSocket
 
QTcpSocket commandSocket
 
QString currentCmd
 
QStringList pendingCommands
 
char replyCode [3]
 
QString replyText
 
State state
 
bool waitForDtpToClose
 
bool waitForDtpToConnect
 

Friends

class QFtpDTP
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 152 of file qftp.cpp.

Enumerations

◆ AbortState

enum QFtpPI::AbortState
private
Enumerator
None 
AbortStarted 
WaitForAbortToFinish 

Definition at line 203 of file qftp.cpp.

◆ State

enum QFtpPI::State
private
Enumerator
Begin 
Idle 
Waiting 
Success 
Failure 

Definition at line 195 of file qftp.cpp.

195  {
196  Begin,
197  Idle,
198  Waiting,
199  Success,
200  Failure
201  };

Constructors and Destructors

◆ QFtpPI()

QFtpPI::QFtpPI ( QObject parent = 0)

Definition at line 822 of file qftp.cpp.

822  :
823  QObject(parent),
824  rawCommand(false),
826  dtp(this),
827  commandSocket(0),
829  currentCmd(QString()),
830  waitForDtpToConnect(false),
831  waitForDtpToClose(false)
832 {
833  commandSocket.setObjectName(QLatin1String("QFtpPI_socket"));
835  SLOT(hostFound()));
837  SLOT(connected()));
838  connect(&commandSocket, SIGNAL(disconnected()),
841  SLOT(readyRead()));
844 
845  connect(&dtp, SIGNAL(connectState(int)),
846  SLOT(dtpConnectState(int)));
847 }
bool transferConnectionExtended
Definition: qftp.cpp:172
State state
Definition: qftp.cpp:215
void error(int, const QString &)
#define SLOT(a)
Definition: qobjectdefs.h:226
QString currentCmd
Definition: qftp.cpp:218
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void connectionClosed()
Definition: qftp.cpp:937
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define SIGNAL(a)
Definition: qobjectdefs.h:227
bool waitForDtpToConnect
Definition: qftp.cpp:220
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
SocketError
This enum describes the socket errors that can occur.
bool waitForDtpToClose
Definition: qftp.cpp:221
AbortState abortState
Definition: qftp.cpp:216
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QTcpSocket commandSocket
Definition: qftp.cpp:212
void hostFound()
Definition: qftp.cpp:920
void connected()
Definition: qftp.cpp:925
void dtpConnectState(int)
Definition: qftp.cpp:1263
QFtpDTP dtp
Definition: qftp.cpp:174
void connectState(int)
void readyRead()
Definition: qftp.cpp:965
bool rawCommand
Definition: qftp.cpp:171

Functions

◆ abort()

void QFtpPI::abort ( )

Definition at line 891 of file qftp.cpp.

892 {
894 
895  if (abortState != None)
896  // ABOR already sent
897  return;
898 
899  if (currentCmd.isEmpty())
900  return; //no command in progress
901 
902  if (currentCmd.startsWith(QLatin1String("STOR "))) {
904 #if defined(QFTPPI_DEBUG)
905  qDebug("QFtpPI send: ABOR");
906 #endif
907  commandSocket.write("ABOR\r\n", 6);
908 
910  } else {
911  //Deviation from RFC 959:
912  //Most FTP servers do not support ABOR, or require the telnet
913  //IP & synch sequence (TCP urgent data) which is not supported by QTcpSocket.
914  //Following what most FTP clients do, just reset the data connection and wait for 426
917  }
918 }
QString currentCmd
Definition: qftp.cpp:218
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
Q_CORE_EXPORT void qDebug(const char *,...)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void abortConnection()
Definition: qftp.cpp:456
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void clear()
Removes all items from the list.
Definition: qlist.h:764
AbortState abortState
Definition: qftp.cpp:216
QTcpSocket commandSocket
Definition: qftp.cpp:212
QStringList pendingCommands
Definition: qftp.cpp:217
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
QFtpDTP dtp
Definition: qftp.cpp:174

◆ clearPendingCommands()

void QFtpPI::clearPendingCommands ( )

Definition at line 883 of file qftp.cpp.

884 {
887  currentCmd.clear();
888  state = Idle;
889 }
State state
Definition: qftp.cpp:215
QString currentCmd
Definition: qftp.cpp:218
void abortConnection()
Definition: qftp.cpp:456
void clear()
Removes all items from the list.
Definition: qlist.h:764
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QStringList pendingCommands
Definition: qftp.cpp:217
QFtpDTP dtp
Definition: qftp.cpp:174

◆ connected

void QFtpPI::connected ( )
privateslot

Definition at line 925 of file qftp.cpp.

Referenced by QFtpPI().

926 {
927  state = Begin;
928 #if defined(QFTPPI_DEBUG)
929 // qDebug("QFtpPI state: %d [connected()]", state);
930 #endif
931  // try to improve performance by setting TCP_NODELAY
933 
935 }
State state
Definition: qftp.cpp:215
void setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value)
Sets the given option to the value described by value.
#define emit
Definition: qobjectdefs.h:76
QTcpSocket commandSocket
Definition: qftp.cpp:212
void connectState(int)

◆ connectionClosed

void QFtpPI::connectionClosed ( )
privateslot

Definition at line 937 of file qftp.cpp.

Referenced by QFtpPI().

938 {
941 }
#define emit
Definition: qobjectdefs.h:76
void close()
Closes the I/O device for the socket, disconnects the socket&#39;s connection with the host...
QTcpSocket commandSocket
Definition: qftp.cpp:212
void connectState(int)

◆ connectState

void QFtpPI::connectState ( int  )
signal

◆ connectToHost()

void QFtpPI::connectToHost ( const QString host,
quint16  port 
)

Definition at line 849 of file qftp.cpp.

850 {
852 #ifndef QT_NO_BEARERMANAGEMENT
853  //copy network session down to the socket & DTP
854  commandSocket.setProperty("_q_networksession", property("_q_networksession"));
855  dtp.setProperty("_q_networksession", property("_q_networksession"));
856 #endif
857  commandSocket.connectToHost(host, port);
858 }
void connectToHost(const QString &hostName, quint16 port, OpenMode mode=ReadWrite)
Attempts to make a connection to hostName on the given port.
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
#define emit
Definition: qobjectdefs.h:76
QTcpSocket commandSocket
Definition: qftp.cpp:212
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
QFtpDTP dtp
Definition: qftp.cpp:174
void connectState(int)

◆ currentCommand()

QString QFtpPI::currentCommand ( ) const
inline

Definition at line 168 of file qftp.cpp.

Referenced by QFtpDTP::socketReadyRead().

169  { return currentCmd; }
QString currentCmd
Definition: qftp.cpp:218

◆ delayedCloseFinished

void QFtpPI::delayedCloseFinished ( )
privateslot

Definition at line 943 of file qftp.cpp.

944 {
946 }
#define emit
Definition: qobjectdefs.h:76
void connectState(int)

◆ dtpConnectState

void QFtpPI::dtpConnectState ( int  s)
privateslot

Definition at line 1263 of file qftp.cpp.

Referenced by QFtpPI().

1264 {
1265  switch (s) {
1266  case QFtpDTP::CsClosed:
1267  if (waitForDtpToClose) {
1268  // there is an unprocessed reply
1269  if (processReply())
1270  replyText = QLatin1String("");
1271  else
1272  return;
1273  }
1274  waitForDtpToClose = false;
1275  readyRead();
1276  return;
1277  case QFtpDTP::CsConnected:
1278  waitForDtpToConnect = false;
1279  startNextCmd();
1280  return;
1284  QFtp::tr("Connection refused for data connection"));
1285  startNextCmd();
1286  return;
1287  default:
1288  return;
1289  }
1290 }
void error(int, const QString &)
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool waitForDtpToConnect
Definition: qftp.cpp:220
QString replyText
Definition: qftp.cpp:213
#define emit
Definition: qobjectdefs.h:76
bool waitForDtpToClose
Definition: qftp.cpp:221
bool processReply()
Definition: qftp.cpp:1022
bool startNextCmd()
Definition: qftp.cpp:1200
void readyRead()
Definition: qftp.cpp:965

◆ error [1/2]

void QFtpPI::error ( int  ,
const QString  
)
signal

◆ error [2/2]

void QFtpPI::error ( QAbstractSocket::SocketError  e)
privateslot

Definition at line 948 of file qftp.cpp.

949 {
953  QFtp::tr("Host %1 not found").arg(commandSocket.peerName()));
954  } else if (e == QTcpSocket::ConnectionRefusedError) {
957  QFtp::tr("Connection refused to host %1").arg(commandSocket.peerName()));
958  } else if (e == QTcpSocket::SocketTimeoutError) {
961  QFtp::tr("Connection timed out to host %1").arg(commandSocket.peerName()));
962  }
963 }
QString peerName() const
Returns the name of the peer as specified by connectToHost(), or an empty QString if connectToHost() ...
void error(int, const QString &)
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
#define emit
Definition: qobjectdefs.h:76
QTcpSocket commandSocket
Definition: qftp.cpp:212
void connectState(int)

◆ finished

void QFtpPI::finished ( const QString )
signal

Referenced by processReply(), and startNextCmd().

◆ hostFound

void QFtpPI::hostFound ( )
privateslot

Definition at line 920 of file qftp.cpp.

Referenced by QFtpPI().

921 {
923 }
#define emit
Definition: qobjectdefs.h:76
void connectState(int)

◆ processReply()

bool QFtpPI::processReply ( )
private

Definition at line 1022 of file qftp.cpp.

Referenced by dtpConnectState(), and readyRead().

1023 {
1024 #if defined(QFTPPI_DEBUG)
1025 // qDebug("QFtpPI state: %d [processReply() begin]", state);
1026  if (replyText.length() < 400)
1027  qDebug("QFtpPI recv: %d %s", 100*replyCode[0]+10*replyCode[1]+replyCode[2], replyText.toLatin1().constData());
1028  else
1029  qDebug("QFtpPI recv: %d (text skipped)", 100*replyCode[0]+10*replyCode[1]+replyCode[2]);
1030 #endif
1031 
1032  int replyCodeInt = 100*replyCode[0] + 10*replyCode[1] + replyCode[2];
1033 
1034  // process 226 replies ("Closing Data Connection") only when the data
1035  // connection is really closed to avoid short reads of the DTP
1036  if (replyCodeInt == 226 || (replyCodeInt == 250 && currentCmd.startsWith(QLatin1String("RETR")))) {
1038  waitForDtpToClose = true;
1039  return false;
1040  }
1041  }
1042 
1043  switch (abortState) {
1044  case AbortStarted:
1046  break;
1047  case WaitForAbortToFinish:
1048  abortState = None;
1049  return true;
1050  default:
1051  break;
1052  }
1053 
1054  // get new state
1055  static const State table[5] = {
1056  /* 1yz 2yz 3yz 4yz 5yz */
1057  Waiting, Success, Idle, Failure, Failure
1058  };
1059  switch (state) {
1060  case Begin:
1061  if (replyCode[0] == 1) {
1062  return true;
1063  } else if (replyCode[0] == 2) {
1064  state = Idle;
1065  emit finished(QFtp::tr("Connected to host %1").arg(commandSocket.peerName()));
1066  break;
1067  }
1068  // reply codes not starting with 1 or 2 are not handled.
1069  return true;
1070  case Waiting:
1071  if (static_cast<signed char>(replyCode[0]) < 0 || replyCode[0] > 5)
1072  state = Failure;
1073  else
1074 #if defined(Q_OS_IRIX) && defined(Q_CC_GNU)
1075  {
1076  // work around a crash on 64 bit gcc IRIX
1077  State *t = (State *) table;
1078  state = t[replyCode[0] - 1];
1079  }
1080 #else
1081  if (replyCodeInt == 202)
1082  state = Failure;
1083  else
1084  state = table[replyCode[0] - 1];
1085 #endif
1086  break;
1087  default:
1088  // ignore unrequested message
1089  return true;
1090  }
1091 #if defined(QFTPPI_DEBUG)
1092 // qDebug("QFtpPI state: %d [processReply() intermediate]", state);
1093 #endif
1094 
1095  // special actions on certain replies
1096  emit rawFtpReply(replyCodeInt, replyText);
1097  if (rawCommand) {
1098  rawCommand = false;
1099  } else if (replyCodeInt == 227) {
1100  // 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)
1101  // rfc959 does not define this response precisely, and gives
1102  // both examples where the parenthesis are used, and where
1103  // they are missing. We need to scan for the address and host
1104  // info.
1105  QRegExp addrPortPattern(QLatin1String("(\\d+),(\\d+),(\\d+),(\\d+),(\\d+),(\\d+)"));
1106  if (addrPortPattern.indexIn(replyText) == -1) {
1107 #if defined(QFTPPI_DEBUG)
1108  qDebug("QFtp: bad 227 response -- address and port information missing");
1109 #endif
1110  // this error should be reported
1111  } else {
1112  QStringList lst = addrPortPattern.capturedTexts();
1113  QString host = lst[1] + QLatin1Char('.') + lst[2] + QLatin1Char('.') + lst[3] + QLatin1Char('.') + lst[4];
1114  quint16 port = (lst[5].toUInt() << 8) + lst[6].toUInt();
1115  waitForDtpToConnect = true;
1116  dtp.connectToHost(host, port);
1117  }
1118  } else if (replyCodeInt == 229) {
1119  // 229 Extended Passive mode OK (|||10982|)
1120  int portPos = replyText.indexOf(QLatin1Char('('));
1121  if (portPos == -1) {
1122 #if defined(QFTPPI_DEBUG)
1123  qDebug("QFtp: bad 229 response -- port information missing");
1124 #endif
1125  // this error should be reported
1126  } else {
1127  ++portPos;
1128  QChar delimiter = replyText.at(portPos);
1129  QStringList epsvParameters = replyText.mid(portPos).split(delimiter);
1130 
1131  waitForDtpToConnect = true;
1133  epsvParameters.at(3).toInt());
1134  }
1135 
1136  } else if (replyCodeInt == 230) {
1137  if (currentCmd.startsWith(QLatin1String("USER ")) && pendingCommands.count()>0 &&
1139  // no need to send the PASS -- we are already logged in
1141  }
1142  // 230 User logged in, proceed.
1144  } else if (replyCodeInt == 213) {
1145  // 213 File status.
1146  if (currentCmd.startsWith(QLatin1String("SIZE ")))
1148  } else if (replyCode[0]==1 && currentCmd.startsWith(QLatin1String("STOR "))) {
1150  dtp.writeData();
1151  }
1152 
1153  // react on new state
1154  switch (state) {
1155  case Begin:
1156  // should never happen
1157  break;
1158  case Success:
1159  // success handling
1160  state = Idle;
1161  // no break!
1162  case Idle:
1163  if (dtp.hasError()) {
1165  dtp.clearError();
1166  }
1167  startNextCmd();
1168  break;
1169  case Waiting:
1170  // do nothing
1171  break;
1172  case Failure:
1173  // If the EPSV or EPRT commands fail, replace them with
1174  // the old PASV and PORT instead and try again.
1175  if (currentCmd.startsWith(QLatin1String("EPSV"))) {
1177  pendingCommands.prepend(QLatin1String("PASV\r\n"));
1178  } else if (currentCmd.startsWith(QLatin1String("EPRT"))) {
1180  pendingCommands.prepend(QLatin1String("PORT\r\n"));
1181  } else {
1183  }
1184  if (state != Waiting) {
1185  state = Idle;
1186  startNextCmd();
1187  }
1188  break;
1189  }
1190 #if defined(QFTPPI_DEBUG)
1191 // qDebug("QFtpPI state: %d [processReply() end]", state);
1192 #endif
1193  return true;
1194 }
bool transferConnectionExtended
Definition: qftp.cpp:172
qlonglong toLongLong(bool *ok=0, int base=10) const
Returns the string converted to a long long using base base, which is 10 by default and must be betwe...
Definition: qstring.cpp:5943
QString peerName() const
Returns the name of the peer as specified by connectToHost(), or an empty QString if connectToHost() ...
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
bool hasError() const
Definition: qftp.cpp:441
void connectToHost(const QString &host, quint16 port)
Definition: qftp.cpp:313
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
State state
Definition: qftp.cpp:215
void rawFtpReply(int, const QString &)
void writeData()
Definition: qftp.cpp:396
void error(int, const QString &)
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString currentCmd
Definition: qftp.cpp:218
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void pop_front()
This function is provided for STL compatibility.
Definition: qlist.h:302
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
char replyCode[3]
Definition: qftp.cpp:214
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QString errorMessage() const
Definition: qftp.cpp:446
Q_CORE_EXPORT void qDebug(const char *,...)
bool waitForDtpToConnect
Definition: qftp.cpp:220
QString replyText
Definition: qftp.cpp:213
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
unsigned short quint16
Definition: qglobal.h:936
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QString toString() const
Returns the address as a string.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
The State element defines configurations of objects and properties.
void finished(const QString &)
bool waitForDtpToClose
Definition: qftp.cpp:221
AbortState abortState
Definition: qftp.cpp:216
void setBytesTotal(qint64 bytes)
Definition: qftp.cpp:306
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void waitForConnection()
Definition: qftp.cpp:347
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
void clearError()
Definition: qftp.cpp:451
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Definition: qstring.cpp:4415
QTcpSocket commandSocket
Definition: qftp.cpp:212
QTcpSocket::SocketState state() const
Definition: qftp.cpp:356
QHostAddress peerAddress() const
Returns the address of the connected peer if the socket is in ConnectedState; otherwise returns QHost...
QStringList pendingCommands
Definition: qftp.cpp:217
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
bool startNextCmd()
Definition: qftp.cpp:1200
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QFtpDTP dtp
Definition: qftp.cpp:174
void connectState(int)
bool rawCommand
Definition: qftp.cpp:171

◆ rawFtpReply

void QFtpPI::rawFtpReply ( int  ,
const QString  
)
signal

Referenced by processReply().

◆ readyRead

void QFtpPI::readyRead ( )
privateslot

Definition at line 965 of file qftp.cpp.

Referenced by dtpConnectState(), and QFtpPI().

966 {
967  if (waitForDtpToClose)
968  return;
969 
970  while (commandSocket.canReadLine()) {
971  // read line with respect to line continuation
973  if (replyText.isEmpty()) {
974  if (line.length() < 3) {
975  // protocol error
976  return;
977  }
978  const int lowerLimit[3] = {1,0,0};
979  const int upperLimit[3] = {5,5,9};
980  for (int i=0; i<3; i++) {
981  replyCode[i] = line[i].digitValue();
982  if (replyCode[i]<lowerLimit[i] || replyCode[i]>upperLimit[i]) {
983  // protocol error
984  return;
985  }
986  }
987  }
988  QString endOfMultiLine;
989  endOfMultiLine[0] = '0' + replyCode[0];
990  endOfMultiLine[1] = '0' + replyCode[1];
991  endOfMultiLine[2] = '0' + replyCode[2];
992  endOfMultiLine[3] = QLatin1Char(' ');
993  QString lineCont(endOfMultiLine);
994  lineCont[3] = QLatin1Char('-');
995  QString lineLeft4 = line.left(4);
996 
997  while (lineLeft4 != endOfMultiLine) {
998  if (lineLeft4 == lineCont)
999  replyText += line.mid(4); // strip 'xyz-'
1000  else
1001  replyText += line;
1002  if (!commandSocket.canReadLine())
1003  return;
1005  lineLeft4 = line.left(4);
1006  }
1007  replyText += line.mid(4); // strip reply code 'xyz '
1008  if (replyText.endsWith(QLatin1String("\r\n")))
1009  replyText.chop(2);
1010 
1011  if (processReply())
1012  replyText = QLatin1String("");
1013  }
1014 }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
char replyCode[3]
Definition: qftp.cpp:214
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString replyText
Definition: qftp.cpp:213
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
bool waitForDtpToClose
Definition: qftp.cpp:221
bool processReply()
Definition: qftp.cpp:1022
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
qint64 readLine(char *data, qint64 maxlen)
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes...
Definition: qiodevice.cpp:1110
QTcpSocket commandSocket
Definition: qftp.cpp:212
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
bool canReadLine() const
Returns true if a line of data can be read from the socket; otherwise returns false.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ sendCommand()

bool QFtpPI::sendCommand ( const QString cmd)
inline

Definition at line 162 of file qftp.cpp.

163  { return sendCommands(QStringList(cmd)); }
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool sendCommands(const QStringList &cmds)
Definition: qftp.cpp:868

◆ sendCommands()

bool QFtpPI::sendCommands ( const QStringList cmds)

Definition at line 868 of file qftp.cpp.

869 {
870  if (!pendingCommands.isEmpty())
871  return false;
872 
874  emit error(QFtp::NotConnected, QFtp::tr("Not connected"));
875  return true; // there are no pending commands
876  }
877 
878  pendingCommands = cmds;
879  startNextCmd();
880  return true;
881 }
State state
Definition: qftp.cpp:215
void error(int, const QString &)
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define emit
Definition: qobjectdefs.h:76
QTcpSocket commandSocket
Definition: qftp.cpp:212
QStringList pendingCommands
Definition: qftp.cpp:217
bool startNextCmd()
Definition: qftp.cpp:1200
SocketState state() const
Returns the state of the socket.

◆ startNextCmd()

bool QFtpPI::startNextCmd ( )
private

Definition at line 1200 of file qftp.cpp.

Referenced by dtpConnectState(), processReply(), and sendCommands().

1201 {
1202  if (waitForDtpToConnect)
1203  // don't process any new commands until we are connected
1204  return true;
1205 
1206 #if defined(QFTPPI_DEBUG)
1207  if (state != Idle)
1208  qDebug("QFtpPI startNextCmd: Internal error! QFtpPI called in non-Idle state %d", state);
1209 #endif
1210  if (pendingCommands.isEmpty()) {
1211  currentCmd.clear();
1213  return false;
1214  }
1216 
1217  // PORT and PASV are edited in-place, depending on whether we
1218  // should try the extended transfer connection commands EPRT and
1219  // EPSV. The PORT command also triggers setting up a listener, and
1220  // the address/port arguments are edited in.
1222  if (currentCmd.startsWith(QLatin1String("PORT"))) {
1224  int port = dtp.setupListener(address);
1225  currentCmd = QLatin1String("EPRT |");
1226  currentCmd += (address.protocol() == QTcpSocket::IPv4Protocol) ? QLatin1Char('1') : QLatin1Char('2');
1227  currentCmd += QLatin1Char('|') + address.toString() + QLatin1Char('|') + QString::number(port);
1228  currentCmd += QLatin1Char('|');
1229  } else if (address.protocol() == QTcpSocket::IPv4Protocol) {
1230  int port = dtp.setupListener(address);
1231  QString portArg;
1232  quint32 ip = address.toIPv4Address();
1233  portArg += QString::number((ip & 0xff000000) >> 24);
1234  portArg += QLatin1Char(',') + QString::number((ip & 0xff0000) >> 16);
1235  portArg += QLatin1Char(',') + QString::number((ip & 0xff00) >> 8);
1236  portArg += QLatin1Char(',') + QString::number(ip & 0xff);
1237  portArg += QLatin1Char(',') + QString::number((port & 0xff00) >> 8);
1238  portArg += QLatin1Char(',') + QString::number(port & 0xff);
1239 
1240  currentCmd = QLatin1String("PORT ");
1241  currentCmd += portArg;
1242  } else {
1243  // No IPv6 connection can be set up with the PORT
1244  // command.
1245  return false;
1246  }
1247 
1248  currentCmd += QLatin1String("\r\n");
1249  } else if (currentCmd.startsWith(QLatin1String("PASV"))) {
1251  currentCmd = QLatin1String("EPSV\r\n");
1252  }
1253 
1255 #if defined(QFTPPI_DEBUG)
1256  qDebug("QFtpPI send: %s", currentCmd.left(currentCmd.length()-2).toLatin1().constData());
1257 #endif
1258  state = Waiting;
1260  return true;
1261 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
bool transferConnectionExtended
Definition: qftp.cpp:172
QHostAddress localAddress() const
Returns the host address of the local socket if available; otherwise returns QHostAddress::Null.
State state
Definition: qftp.cpp:215
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString currentCmd
Definition: qftp.cpp:218
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void pop_front()
This function is provided for STL compatibility.
Definition: qlist.h:302
quint32 toIPv4Address() const
Returns the IPv4 address as a number.
The QString class provides a Unicode character string.
Definition: qstring.h:83
int setupListener(const QHostAddress &address)
Definition: qftp.cpp:336
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
Q_CORE_EXPORT void qDebug(const char *,...)
bool waitForDtpToConnect
Definition: qftp.cpp:220
QString replyText
Definition: qftp.cpp:213
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
#define emit
Definition: qobjectdefs.h:76
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QString toString() const
Returns the address as a string.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
void finished(const QString &)
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QAbstractSocket::NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
unsigned int quint32
Definition: qglobal.h:938
QTcpSocket commandSocket
Definition: qftp.cpp:212
QStringList pendingCommands
Definition: qftp.cpp:217
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QFtpDTP dtp
Definition: qftp.cpp:174
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

Friends and Related Functions

◆ QFtpDTP

friend class QFtpDTP
friend

Definition at line 225 of file qftp.cpp.

Properties

◆ abortState

AbortState QFtpPI::abortState
private

Definition at line 216 of file qftp.cpp.

Referenced by abort(), processReply(), and QFtpDTP::socketReadyRead().

◆ bytesFromSocket

QByteArray QFtpPI::bytesFromSocket
private

Definition at line 223 of file qftp.cpp.

◆ commandSocket

QTcpSocket QFtpPI::commandSocket
private

◆ currentCmd

QString QFtpPI::currentCmd
private

Definition at line 218 of file qftp.cpp.

Referenced by abort(), clearPendingCommands(), processReply(), and startNextCmd().

◆ dtp

QFtpDTP QFtpPI::dtp

Definition at line 174 of file qftp.cpp.

Referenced by abort(), clearPendingCommands(), connectToHost(), processReply(), QFtpPI(), and startNextCmd().

◆ pendingCommands

QStringList QFtpPI::pendingCommands
private

Definition at line 217 of file qftp.cpp.

Referenced by abort(), clearPendingCommands(), processReply(), sendCommands(), and startNextCmd().

◆ rawCommand

bool QFtpPI::rawCommand

Definition at line 171 of file qftp.cpp.

Referenced by processReply().

◆ replyCode

char QFtpPI::replyCode[3]
private

Definition at line 214 of file qftp.cpp.

Referenced by processReply(), and readyRead().

◆ replyText

QString QFtpPI::replyText
private

Definition at line 213 of file qftp.cpp.

Referenced by dtpConnectState(), processReply(), readyRead(), and startNextCmd().

◆ state

State QFtpPI::state
private

Definition at line 215 of file qftp.cpp.

Referenced by clearPendingCommands(), connected(), processReply(), sendCommands(), and startNextCmd().

◆ transferConnectionExtended

bool QFtpPI::transferConnectionExtended

Definition at line 172 of file qftp.cpp.

Referenced by processReply(), and startNextCmd().

◆ waitForDtpToClose

bool QFtpPI::waitForDtpToClose
private

Definition at line 221 of file qftp.cpp.

Referenced by dtpConnectState(), processReply(), and readyRead().

◆ waitForDtpToConnect

bool QFtpPI::waitForDtpToConnect
private

Definition at line 220 of file qftp.cpp.

Referenced by dtpConnectState(), processReply(), and startNextCmd().


The documentation for this class was generated from the following file: