代码拉取完成,页面将自动刷新
#ifndef _Q_FTP_P_
#define _Q_FTP_P_
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2022 Rochus Keller (me@rochus-keller.ch) for LeanQt
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qftp.h"
#include "qtcpsocket.h"
#include "qtcpserver.h"
QT_BEGIN_NAMESPACE
class QFtpPI;
/*
The QFtpDTP (DTP = Data Transfer Process) controls all client side
data transfer between the client and server.
*/
class QFtpDTP : public QObject
{
Q_OBJECT
public:
enum ConnectState {
CsHostFound,
CsConnected,
CsClosed,
CsHostNotFound,
CsConnectionRefused
};
QFtpDTP(QFtpPI *p, QObject *parent = 0);
void setData(QByteArray *);
void setDevice(QIODevice *);
void writeData();
void setBytesTotal(qint64 bytes);
bool hasError() const;
QString errorMessage() const;
void clearError();
void connectToHost(const QString & host, quint16 port);
int setupListener(const QHostAddress &address);
void waitForConnection();
QTcpSocket::SocketState state() const;
qint64 bytesAvailable() const;
qint64 read(char *data, qint64 maxlen);
QByteArray readAll();
void abortConnection();
static bool parseDir(const QByteArray &buffer, const QString &userName, QUrlInfo *info);
signals:
void listInfo(const QUrlInfo&);
void readyRead();
void dataTransferProgress(qint64, qint64);
void connectState(int);
private slots:
void socketConnected();
void socketReadyRead();
void socketError(QAbstractSocket::SocketError);
void socketConnectionClosed();
void socketBytesWritten(qint64);
void setupSocket();
void dataReadyRead();
private:
void clearData();
QTcpSocket *socket;
QTcpServer listener;
QFtpPI *pi;
QString err;
qint64 bytesDone;
qint64 bytesTotal;
bool callWriteData;
// If is_ba is true, ba is used; ba is never 0.
// Otherwise dev is used; dev can be 0 or not.
union {
QByteArray *ba;
QIODevice *dev;
} data;
bool is_ba;
QByteArray bytesFromSocket;
};
/**********************************************************************
*
* QFtpPI - Protocol Interpreter
*
*********************************************************************/
class QFtpPI : public QObject
{
Q_OBJECT
public:
QFtpPI(QObject *parent = 0);
void connectToHost(const QString &host, quint16 port);
bool sendCommands(const QStringList &cmds);
bool sendCommand(const QString &cmd)
{ return sendCommands(QStringList(cmd)); }
void clearPendingCommands();
void abort();
QString currentCommand() const
{ return currentCmd; }
bool rawCommand;
bool transferConnectionExtended;
QFtpDTP dtp; // the PI has a DTP which is not the design of RFC 959, but it
// makes the design simpler this way
signals:
void connectState(int);
void finished(const QString&);
void error(int, const QString&);
void rawFtpReply(int, const QString&);
private slots:
void hostFound();
void connected();
void connectionClosed();
void delayedCloseFinished();
void readyRead();
void error(QAbstractSocket::SocketError);
void dtpConnectState(int);
private:
// the states are modelled after the generalized state diagram of RFC 959,
// page 58
enum State {
Begin,
Idle,
Waiting,
Success,
Failure
};
enum AbortState {
None,
AbortStarted,
WaitForAbortToFinish
};
bool processReply();
bool startNextCmd();
QTcpSocket commandSocket;
QString replyText;
char replyCode[3];
State state;
AbortState abortState;
QStringList pendingCommands;
QString currentCmd;
bool waitForDtpToConnect;
bool waitForDtpToClose;
QByteArray bytesFromSocket;
friend class QFtpDTP;
};
/**********************************************************************
*
* QFtpCommand implemenatation
*
*********************************************************************/
class QFtpCommand
{
public:
QFtpCommand(QFtp::Command cmd, const QStringList &raw, const QByteArray &ba);
QFtpCommand(QFtp::Command cmd, const QStringList &raw, QIODevice *dev = 0);
~QFtpCommand();
int id;
QFtp::Command command;
QStringList rawCmds;
// If is_ba is true, ba is used; ba is never 0.
// Otherwise dev is used; dev can be 0 or not.
union {
QByteArray *ba;
QIODevice *dev;
} data;
bool is_ba;
static QBasicAtomicInt idCounter;
};
/**********************************************************************
*
* QFtpPrivate
*
*********************************************************************/
QT_BEGIN_INCLUDE_NAMESPACE
#include <private/qobject_p.h>
QT_END_INCLUDE_NAMESPACE
class QFtpPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QFtp)
public:
inline QFtpPrivate() : close_waitForStateChange(false), state(QFtp::Unconnected),
transferMode(QFtp::Passive), error(QFtp::NoError)
{ }
~QFtpPrivate() { while (!pending.isEmpty()) delete pending.takeFirst(); }
// private slots
void _q_startNextCommand();
void _q_piFinished(const QString&);
void _q_piError(int, const QString&);
void _q_piConnectState(int);
void _q_piFtpReply(int, const QString&);
int addCommand(QFtpCommand *cmd);
QFtpPI pi;
QList<QFtpCommand *> pending;
bool close_waitForStateChange;
QFtp::State state;
QFtp::TransferMode transferMode;
QFtp::Error error;
QString errorString;
QString host;
quint16 port;
QString proxyHost;
quint16 proxyPort;
};
QT_END_NAMESPACE
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。