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

Public Types

enum  ConnectState {
  CsHostFound, CsConnected, CsClosed, CsHostNotFound,
  CsConnectionRefused
}
 

Signals

void connectState (int)
 
void dataTransferProgress (qint64, qint64)
 
void listInfo (const QUrlInfo &)
 
void readyRead ()
 
- 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 abortConnection ()
 
qint64 bytesAvailable () const
 
void clearError ()
 
void connectToHost (const QString &host, quint16 port)
 
QString errorMessage () const
 
bool hasError () const
 
 QFtpDTP (QFtpPI *p, QObject *parent=0)
 
qint64 read (char *data, qint64 maxlen)
 
QByteArray readAll ()
 
void setBytesTotal (qint64 bytes)
 
void setData (QByteArray *)
 
void setDevice (QIODevice *)
 
int setupListener (const QHostAddress &address)
 
QTcpSocket::SocketState state () const
 
void waitForConnection ()
 
void writeData ()
 
- 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...
 

Static Public Functions

static bool parseDir (const QByteArray &buffer, const QString &userName, QUrlInfo *info)
 
- 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)
 

Private Slots

void dataReadyRead ()
 
void setupSocket ()
 
void socketBytesWritten (qint64)
 
void socketConnected ()
 
void socketConnectionClosed ()
 
void socketError (QAbstractSocket::SocketError)
 
void socketReadyRead ()
 

Private Functions

void clearData ()
 

Properties

qint64 bytesDone
 
QByteArray bytesFromSocket
 
qint64 bytesTotal
 
bool callWriteData
 
union {
   QByteArray *   ba
 
   QIODevice *   dev
 
data
 
QString err
 
bool is_ba
 
QTcpServer listener
 
QFtpPIpi
 
QTcpSocketsocket
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- 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 69 of file qftp.cpp.

Enumerations

◆ ConnectState

Enumerator
CsHostFound 
CsConnected 
CsClosed 
CsHostNotFound 
CsConnectionRefused 

Definition at line 74 of file qftp.cpp.

Constructors and Destructors

◆ QFtpDTP()

QFtpDTP::QFtpDTP ( QFtpPI p,
QObject parent = 0 
)

Definition at line 282 of file qftp.cpp.

282  :
283  QObject(parent),
284  socket(0),
285  listener(this),
286  pi(p),
287  callWriteData(false)
288 {
289  clearData();
290  listener.setObjectName(QLatin1String("QFtpDTP active state server"));
291  connect(&listener, SIGNAL(newConnection()), SLOT(setupSocket()));
292 }
bool callWriteData
Definition: qftp.cpp:133
void setupSocket()
Definition: qftp.cpp:798
#define SLOT(a)
Definition: qobjectdefs.h:226
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define SIGNAL(a)
Definition: qobjectdefs.h:227
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
QTcpSocket * socket
Definition: qftp.cpp:126
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QTcpServer listener
Definition: qftp.cpp:127
void clearData()
Definition: qftp.cpp:811
QFtpPI * pi
Definition: qftp.cpp:129

Functions

◆ abortConnection()

void QFtpDTP::abortConnection ( )

Definition at line 456 of file qftp.cpp.

Referenced by QFtpPI::abort(), and QFtpPI::clearPendingCommands().

457 {
458 #if defined(QFTPDTP_DEBUG)
459  qDebug("QFtpDTP::abortConnection, bytesAvailable == %lli",
460  socket ? socket->bytesAvailable() : (qint64) 0);
461 #endif
462  callWriteData = false;
463  clearData();
464 
465  if (socket)
466  socket->abort();
467 }
bool callWriteData
Definition: qftp.cpp:133
qint64 bytesAvailable() const
Returns the number of incoming bytes that are waiting to be read.
void abort()
Aborts the current connection and resets the socket.
Q_CORE_EXPORT void qDebug(const char *,...)
QTcpSocket * socket
Definition: qftp.cpp:126
__int64 qint64
Definition: qglobal.h:942
void clearData()
Definition: qftp.cpp:811

◆ bytesAvailable()

qint64 QFtpDTP::bytesAvailable ( ) const

Definition at line 361 of file qftp.cpp.

Referenced by socketReadyRead().

362 {
364  return (qint64) bytesFromSocket.size();
365  return socket->bytesAvailable();
366 }
qint64 bytesAvailable() const
Returns the number of incoming bytes that are waiting to be read.
QTcpSocket * socket
Definition: qftp.cpp:126
__int64 qint64
Definition: qglobal.h:942
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QByteArray bytesFromSocket
Definition: qftp.cpp:143
SocketState state() const
Returns the state of the socket.

◆ clearData()

void QFtpDTP::clearData ( )
private

Definition at line 811 of file qftp.cpp.

Referenced by abortConnection(), QFtpDTP(), socketConnectionClosed(), and writeData().

812 {
813  is_ba = false;
814  data.dev = 0;
815 }
union QFtpDTP::@310 data
bool is_ba
Definition: qftp.cpp:141

◆ clearError()

void QFtpDTP::clearError ( )
inline

Definition at line 451 of file qftp.cpp.

Referenced by QFtpPI::processReply().

452 {
453  err.clear();
454 }
QString err
Definition: qftp.cpp:130
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723

◆ connectState

void QFtpDTP::connectState ( int  )
signal

◆ connectToHost()

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

Definition at line 313 of file qftp.cpp.

Referenced by QFtpPI::processReply().

314 {
316 
317  if (socket) {
318  delete socket;
319  socket = 0;
320  }
321  socket = new QTcpSocket(this);
322 #ifndef QT_NO_BEARERMANAGEMENT
323  //copy network session down to the socket
324  socket->setProperty("_q_networksession", property("_q_networksession"));
325 #endif
326  socket->setObjectName(QLatin1String("QFtpDTP Passive state socket"));
330  connect(socket, SIGNAL(disconnected()), SLOT(socketConnectionClosed()));
332 
333  socket->connectToHost(host, port);
334 }
void socketConnectionClosed()
Definition: qftp.cpp:774
#define error(msg)
void connectToHost(const QString &hostName, quint16 port, OpenMode mode=ReadWrite)
Attempts to make a connection to hostName on the given port.
#define SLOT(a)
Definition: qobjectdefs.h:226
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
void socketError(QAbstractSocket::SocketError)
Definition: qftp.cpp:759
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void socketConnected()
Definition: qftp.cpp:678
void socketBytesWritten(qint64)
Definition: qftp.cpp:787
static QIntfbScreen * connected
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
QTcpSocket * socket
Definition: qftp.cpp:126
SocketError
This enum describes the socket errors that can occur.
The QTcpSocket class provides a TCP socket.
Definition: qtcpsocket.h:56
__int64 qint64
Definition: qglobal.h:942
void socketReadyRead()
Definition: qftp.cpp:687
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
void readyRead()
QByteArray bytesFromSocket
Definition: qftp.cpp:143
void clear()
Clears the contents of the byte array and makes it empty.

◆ dataReadyRead

void QFtpDTP::dataReadyRead ( )
privateslot

Definition at line 436 of file qftp.cpp.

437 {
438  writeData();
439 }
void writeData()
Definition: qftp.cpp:396

◆ dataTransferProgress

void QFtpDTP::dataTransferProgress ( qint64  ,
qint64   
)
signal

◆ errorMessage()

QString QFtpDTP::errorMessage ( ) const
inline

Definition at line 446 of file qftp.cpp.

Referenced by QFtpPI::processReply().

447 {
448  return err;
449 }
QString err
Definition: qftp.cpp:130

◆ hasError()

bool QFtpDTP::hasError ( ) const
inline

Definition at line 441 of file qftp.cpp.

Referenced by QFtpPI::processReply().

442 {
443  return !err.isNull();
444 }
QString err
Definition: qftp.cpp:130
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505

◆ listInfo

void QFtpDTP::listInfo ( const QUrlInfo )
signal

Referenced by socketReadyRead().

◆ parseDir()

bool QFtpDTP::parseDir ( const QByteArray buffer,
const QString userName,
QUrlInfo info 
)
static

Definition at line 651 of file qftp.cpp.

Referenced by socketReadyRead().

652 {
653  if (buffer.isEmpty())
654  return false;
655 
656  QString bufferStr = QString::fromLatin1(buffer).trimmed();
657 
658  // Unix style FTP servers
659  QRegExp unixPattern(QLatin1String("^([\\-dl])([a-zA-Z\\-]{9,9})\\s+\\d+\\s+(\\S*)\\s+"
660  "(\\S*)\\s+(\\d+)\\s+(\\S+\\s+\\S+\\s+\\S+)\\s+(\\S.*)"));
661  if (unixPattern.indexIn(bufferStr) == 0) {
662  _q_parseUnixDir(unixPattern.capturedTexts(), userName, info);
663  return true;
664  }
665 
666  // DOS style FTP servers
667  QRegExp dosPattern(QLatin1String("^(\\d\\d-\\d\\d-\\d\\d\\ \\ \\d\\d:\\d\\d[AP]M)\\s+"
668  "(<DIR>|\\d+)\\s+(\\S.*)$"));
669  if (dosPattern.indexIn(bufferStr) == 0) {
670  _q_parseDosDir(dosPattern.capturedTexts(), userName, info);
671  return true;
672  }
673 
674  // Unsupported
675  return false;
676 }
static mach_timebase_info_data_t info
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static void _q_parseDosDir(const QStringList &tokens, const QString &userName, QUrlInfo *info)
Definition: qftp.cpp:598
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
static void _q_parseUnixDir(const QStringList &tokens, const QString &userName, QUrlInfo *info)
Definition: qftp.cpp:489

◆ read()

qint64 QFtpDTP::read ( char *  data,
qint64  maxlen 
)

Definition at line 368 of file qftp.cpp.

Referenced by writeData().

369 {
370  qint64 read;
372  read = socket->read(data, maxlen);
373  } else {
374  read = qMin(maxlen, qint64(bytesFromSocket.size()));
375  memcpy(data, bytesFromSocket.data(), read);
376  bytesFromSocket.remove(0, read);
377  }
378 
379  bytesDone += read;
380  return read;
381 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
union QFtpDTP::@310 data
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
QTcpSocket * socket
Definition: qftp.cpp:126
__int64 qint64
Definition: qglobal.h:942
qint64 bytesDone
Definition: qftp.cpp:131
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QByteArray bytesFromSocket
Definition: qftp.cpp:143
QByteArray & remove(int index, int len)
Removes len bytes from the array, starting at index position pos, and returns a reference to the arra...
SocketState state() const
Returns the state of the socket.
qint64 read(char *data, qint64 maxlen)
Definition: qftp.cpp:368

◆ readAll()

QByteArray QFtpDTP::readAll ( )

Definition at line 383 of file qftp.cpp.

384 {
385  QByteArray tmp;
387  tmp = socket->readAll();
388  bytesDone += tmp.size();
389  } else {
390  tmp = bytesFromSocket;
392  }
393  return tmp;
394 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QTcpSocket * socket
Definition: qftp.cpp:126
qint64 bytesDone
Definition: qftp.cpp:131
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QByteArray bytesFromSocket
Definition: qftp.cpp:143
void clear()
Clears the contents of the byte array and makes it empty.
SocketState state() const
Returns the state of the socket.

◆ readyRead

void QFtpDTP::readyRead ( )
signal

◆ setBytesTotal()

void QFtpDTP::setBytesTotal ( qint64  bytes)

Definition at line 306 of file qftp.cpp.

Referenced by QFtpPI::processReply().

307 {
308  bytesTotal = bytes;
309  bytesDone = 0;
311 }
qint64 bytesTotal
Definition: qftp.cpp:132
#define emit
Definition: qobjectdefs.h:76
qint64 bytesDone
Definition: qftp.cpp:131
void dataTransferProgress(qint64, qint64)

◆ setData()

void QFtpDTP::setData ( QByteArray ba)

Definition at line 294 of file qftp.cpp.

295 {
296  is_ba = true;
297  data.ba = ba;
298 }
union QFtpDTP::@310 data
QByteArray * ba
Definition: qftp.cpp:138
bool is_ba
Definition: qftp.cpp:141

◆ setDevice()

void QFtpDTP::setDevice ( QIODevice dev)

Definition at line 300 of file qftp.cpp.

301 {
302  is_ba = false;
303  data.dev = dev;
304 }
union QFtpDTP::@310 data
QIODevice * dev
Definition: qftp.cpp:139
bool is_ba
Definition: qftp.cpp:141

◆ setupListener()

int QFtpDTP::setupListener ( const QHostAddress address)

Definition at line 336 of file qftp.cpp.

Referenced by QFtpPI::startNextCmd().

337 {
338 #ifndef QT_NO_BEARERMANAGEMENT
339  //copy network session down to the socket
340  listener.setProperty("_q_networksession", property("_q_networksession"));
341 #endif
342  if (!listener.isListening() && !listener.listen(address, 0))
343  return -1;
344  return listener.serverPort();
345 }
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
bool listen(const QHostAddress &address=QHostAddress::Any, quint16 port=0)
Tells the server to listen for incoming connections on address address and port port.
Definition: qtcpserver.cpp:281
bool isListening() const
Returns true if the server is currently listening for incoming connections; otherwise returns false...
Definition: qtcpserver.cpp:358
quint16 serverPort() const
Returns the server&#39;s port if the server is listening for connections; otherwise returns 0...
Definition: qtcpserver.cpp:466
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
QTcpServer listener
Definition: qftp.cpp:127

◆ setupSocket

void QFtpDTP::setupSocket ( )
privateslot

Definition at line 798 of file qftp.cpp.

Referenced by QFtpDTP().

799 {
801  socket->setObjectName(QLatin1String("QFtpDTP Active state socket"));
805  connect(socket, SIGNAL(disconnected()), SLOT(socketConnectionClosed()));
807 
808  listener.close();
809 }
void socketConnectionClosed()
Definition: qftp.cpp:774
#define error(msg)
#define SLOT(a)
Definition: qobjectdefs.h:226
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
void socketError(QAbstractSocket::SocketError)
Definition: qftp.cpp:759
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void socketConnected()
Definition: qftp.cpp:678
void socketBytesWritten(qint64)
Definition: qftp.cpp:787
static QIntfbScreen * connected
virtual QTcpSocket * nextPendingConnection()
Returns the next pending connection as a connected QTcpSocket object.
Definition: qtcpserver.cpp:554
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
QTcpSocket * socket
Definition: qftp.cpp:126
SocketError
This enum describes the socket errors that can occur.
__int64 qint64
Definition: qglobal.h:942
void socketReadyRead()
Definition: qftp.cpp:687
QTcpServer listener
Definition: qftp.cpp:127
void close()
Closes the server.
Definition: qtcpserver.cpp:371
void readyRead()

◆ socketBytesWritten

void QFtpDTP::socketBytesWritten ( qint64  bytes)
privateslot

Definition at line 787 of file qftp.cpp.

Referenced by connectToHost(), and setupSocket().

788 {
789  bytesDone += bytes;
790 #if defined(QFTPDTP_DEBUG)
791  qDebug("QFtpDTP::bytesWritten(%lli)", bytesDone);
792 #endif
794  if (callWriteData)
795  writeData();
796 }
bool callWriteData
Definition: qftp.cpp:133
void writeData()
Definition: qftp.cpp:396
qint64 bytesTotal
Definition: qftp.cpp:132
Q_CORE_EXPORT void qDebug(const char *,...)
#define emit
Definition: qobjectdefs.h:76
qint64 bytesDone
Definition: qftp.cpp:131
void dataTransferProgress(qint64, qint64)

◆ socketConnected

void QFtpDTP::socketConnected ( )
privateslot

Definition at line 678 of file qftp.cpp.

Referenced by connectToHost(), and setupSocket().

679 {
680  bytesDone = 0;
681 #if defined(QFTPDTP_DEBUG)
682  qDebug("QFtpDTP::connectState(CsConnected)");
683 #endif
685 }
void connectState(int)
Q_CORE_EXPORT void qDebug(const char *,...)
#define emit
Definition: qobjectdefs.h:76
qint64 bytesDone
Definition: qftp.cpp:131

◆ socketConnectionClosed

void QFtpDTP::socketConnectionClosed ( )
privateslot

Definition at line 774 of file qftp.cpp.

Referenced by connectToHost(), and setupSocket().

775 {
776  if (!is_ba && data.dev) {
777  clearData();
778  }
779 
781 #if defined(QFTPDTP_DEBUG)
782  qDebug("QFtpDTP::connectState(CsClosed)");
783 #endif
785 }
void connectState(int)
union QFtpDTP::@310 data
Q_CORE_EXPORT void qDebug(const char *,...)
QTcpSocket * socket
Definition: qftp.cpp:126
#define emit
Definition: qobjectdefs.h:76
bool is_ba
Definition: qftp.cpp:141
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
void clearData()
Definition: qftp.cpp:811
QByteArray bytesFromSocket
Definition: qftp.cpp:143

◆ socketError

void QFtpDTP::socketError ( QAbstractSocket::SocketError  e)
privateslot

Definition at line 759 of file qftp.cpp.

Referenced by connectToHost(), and setupSocket().

760 {
762 #if defined(QFTPDTP_DEBUG)
763  qDebug("QFtpDTP::connectState(CsHostNotFound)");
764 #endif
766  } else if (e == QTcpSocket::ConnectionRefusedError) {
767 #if defined(QFTPDTP_DEBUG)
768  qDebug("QFtpDTP::connectState(CsConnectionRefused)");
769 #endif
771  }
772 }
void connectState(int)
Q_CORE_EXPORT void qDebug(const char *,...)
#define emit
Definition: qobjectdefs.h:76

◆ socketReadyRead

void QFtpDTP::socketReadyRead ( )
privateslot

Definition at line 687 of file qftp.cpp.

Referenced by connectToHost(), and setupSocket().

688 {
689  if (!socket)
690  return;
691 
692  if (pi->currentCommand().isEmpty()) {
693  socket->close();
694 #if defined(QFTPDTP_DEBUG)
695  qDebug("QFtpDTP::connectState(CsClosed)");
696 #endif
698  return;
699  }
700 
701  if (pi->abortState != QFtpPI::None) {
702  // discard data
703  socket->readAll();
704  return;
705  }
706 
707  if (pi->currentCommand().startsWith(QLatin1String("LIST"))) {
708  while (socket->canReadLine()) {
709  QUrlInfo i;
710  QByteArray line = socket->readLine();
711 #if defined(QFTPDTP_DEBUG)
712  qDebug("QFtpDTP read (list): '%s'", line.constData());
713 #endif
714  if (parseDir(line, QLatin1String(""), &i)) {
715  emit listInfo(i);
716  } else {
717  // some FTP servers don't return a 550 if the file or directory
718  // does not exist, but rather write a text to the data socket
719  // -- try to catch these cases
720  if (line.endsWith("No such file or directory\r\n"))
721  err = QString::fromLatin1(line);
722  }
723  }
724  } else {
725  if (!is_ba && data.dev) {
726  do {
727  QByteArray ba;
729  qint64 bytesRead = socket->read(ba.data(), ba.size());
730  if (bytesRead < 0) {
731  // a read following a readyRead() signal will
732  // never fail.
733  return;
734  }
735  ba.resize(bytesRead);
736  bytesDone += bytesRead;
737 #if defined(QFTPDTP_DEBUG)
738  qDebug("QFtpDTP read: %lli bytes (total %lli bytes)", bytesRead, bytesDone);
739 #endif
740  if (data.dev) // make sure it wasn't deleted in the slot
741  data.dev->write(ba);
743 
744  // Need to loop; dataTransferProgress is often connected to
745  // slots that update the GUI (e.g., progress bar values), and
746  // if events are processed, more data may have arrived.
747  } while (socket->bytesAvailable());
748  } else {
749 #if defined(QFTPDTP_DEBUG)
750  qDebug("QFtpDTP readyRead: %lli bytes available (total %lli bytes read)",
752 #endif
754  emit readyRead();
755  }
756  }
757 }
qint64 bytesAvailable() const
Definition: qftp.cpp:361
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
qint64 bytesAvailable() const
Returns the number of incoming bytes that are waiting to be read.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
qint64 bytesTotal
Definition: qftp.cpp:132
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 connectState(int)
union QFtpDTP::@310 data
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
static bool parseDir(const QByteArray &buffer, const QString &userName, QUrlInfo *info)
Definition: qftp.cpp:651
Q_CORE_EXPORT void qDebug(const char *,...)
The QUrlInfo class stores information about URLs.
Definition: qurlinfo.h:60
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString err
Definition: qftp.cpp:130
QTcpSocket * socket
Definition: qftp.cpp:126
QByteArray * ba
Definition: qftp.cpp:138
QString currentCommand() const
Definition: qftp.cpp:168
#define emit
Definition: qobjectdefs.h:76
__int64 qint64
Definition: qglobal.h:942
void close()
Closes the I/O device for the socket, disconnects the socket&#39;s connection with the host...
AbortState abortState
Definition: qftp.cpp:216
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool is_ba
Definition: qftp.cpp:141
qint64 bytesDone
Definition: qftp.cpp:131
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
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void resize(int size)
Sets the size of the byte array to size bytes.
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
void listInfo(const QUrlInfo &)
void dataTransferProgress(qint64, qint64)
void readyRead()
bool canReadLine() const
Returns true if a line of data can be read from the socket; otherwise returns false.
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...
QFtpPI * pi
Definition: qftp.cpp:129

◆ state()

QTcpSocket::SocketState QFtpDTP::state ( ) const

Definition at line 356 of file qftp.cpp.

Referenced by QFtpPI::processReply().

357 {
359 }
QTcpSocket * socket
Definition: qftp.cpp:126
SocketState state() const
Returns the state of the socket.

◆ waitForConnection()

void QFtpDTP::waitForConnection ( )

Definition at line 347 of file qftp.cpp.

Referenced by QFtpPI::processReply().

348 {
349  // This function is only interesting in Active transfer mode; it works
350  // around a limitation in QFtp's design by blocking, waiting for an
351  // incoming connection. For the default Passive mode, it does nothing.
352  if (listener.isListening())
354 }
bool isListening() const
Returns true if the server is currently listening for incoming connections; otherwise returns false...
Definition: qtcpserver.cpp:358
bool waitForNewConnection(int msec=0, bool *timedOut=0)
Waits for at most msec milliseconds or until an incoming connection is available. ...
Definition: qtcpserver.cpp:505
QTcpServer listener
Definition: qftp.cpp:127

◆ writeData()

void QFtpDTP::writeData ( )

Definition at line 396 of file qftp.cpp.

Referenced by dataReadyRead(), QFtpPI::processReply(), and socketBytesWritten().

397 {
398  if (!socket)
399  return;
400 
401  if (is_ba) {
402 #if defined(QFTPDTP_DEBUG)
403  qDebug("QFtpDTP::writeData: write %d bytes", data.ba->size());
404 #endif
405  if (data.ba->size() == 0)
407  else
408  socket->write(data.ba->data(), data.ba->size());
409 
410  socket->close();
411 
412  clearData();
413  } else if (data.dev) {
414  callWriteData = false;
415  const qint64 blockSize = 16*1024;
416  char buf[16*1024];
417  qint64 read = data.dev->read(buf, blockSize);
418 #if defined(QFTPDTP_DEBUG)
419  qDebug("QFtpDTP::writeData: write() of size %lli bytes", read);
420 #endif
421  if (read > 0) {
422  socket->write(buf, read);
423  } else if (read == -1 || (!data.dev->isSequential() && data.dev->atEnd())) {
424  // error or EOF
425  if (bytesDone == 0 && socket->bytesToWrite() == 0)
427  socket->close();
428  clearData();
429  }
430 
431  // do we continue uploading?
432  callWriteData = data.dev != 0;
433  }
434 }
const int blockSize
bool callWriteData
Definition: qftp.cpp:133
qint64 bytesTotal
Definition: qftp.cpp:132
union QFtpDTP::@310 data
Q_CORE_EXPORT void qDebug(const char *,...)
QTcpSocket * socket
Definition: qftp.cpp:126
#define emit
Definition: qobjectdefs.h:76
__int64 qint64
Definition: qglobal.h:942
void close()
Closes the I/O device for the socket, disconnects the socket&#39;s connection with the host...
bool is_ba
Definition: qftp.cpp:141
qint64 bytesDone
Definition: qftp.cpp:131
qint64 bytesToWrite() const
Returns the number of bytes that are waiting to be written.
void dataTransferProgress(qint64, qint64)
void clearData()
Definition: qftp.cpp:811
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
qint64 read(char *data, qint64 maxlen)
Definition: qftp.cpp:368

Properties

◆ ba

QByteArray* QFtpDTP::ba

Definition at line 138 of file qftp.cpp.

Referenced by setData(), and socketReadyRead().

◆ bytesDone

qint64 QFtpDTP::bytesDone
private

◆ bytesFromSocket

QByteArray QFtpDTP::bytesFromSocket
private

Definition at line 143 of file qftp.cpp.

Referenced by bytesAvailable(), connectToHost(), read(), readAll(), and socketConnectionClosed().

◆ bytesTotal

qint64 QFtpDTP::bytesTotal
private

Definition at line 132 of file qftp.cpp.

Referenced by setBytesTotal(), socketBytesWritten(), socketReadyRead(), and writeData().

◆ callWriteData

bool QFtpDTP::callWriteData
private

Definition at line 133 of file qftp.cpp.

Referenced by abortConnection(), socketBytesWritten(), and writeData().

◆ data

union { ... } QFtpDTP::data

◆ dev

QIODevice* QFtpDTP::dev

Definition at line 139 of file qftp.cpp.

Referenced by setDevice().

◆ err

QString QFtpDTP::err
private

Definition at line 130 of file qftp.cpp.

Referenced by clearError(), errorMessage(), hasError(), and socketReadyRead().

◆ is_ba

bool QFtpDTP::is_ba
private

◆ listener

QTcpServer QFtpDTP::listener
private

Definition at line 127 of file qftp.cpp.

Referenced by QFtpDTP(), setupListener(), setupSocket(), and waitForConnection().

◆ pi

QFtpPI* QFtpDTP::pi
private

Definition at line 129 of file qftp.cpp.

Referenced by socketReadyRead().

◆ socket

QTcpSocket* QFtpDTP::socket
private

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