1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00
LibQQt/examples/qqtnetworkexample/qqtcloudprotocol.cpp

1025 lines
27 KiB
C++
Raw Normal View History

2017-10-17 22:00:45 +08:00
#include "qqtcloudprotocol.h"
#include "qqtversion.h"
#include "qqtcore.h"
#include "qqt-qt.h"
2018-04-22 13:03:28 +08:00
QQtTcpClient* QQTUpgradeClientInstance ( QObject* parent )
2017-10-17 22:00:45 +08:00
{
2018-04-22 13:03:28 +08:00
static QQtTcpClient* cli = NULL;
2018-01-15 09:08:57 +08:00
if ( !cli )
2017-10-17 22:00:45 +08:00
{
QStringList ip;
ip << "222.175.114.244" << "124.133.1.54";
//"www.QQToo.com"
2018-04-22 13:03:28 +08:00
cli = new QQtTcpClient ( parent );
2018-01-15 09:08:57 +08:00
cli->SetServerIPAddress ( ip );
cli->SetServerPort ( 8089 );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
return cli;
}
2018-04-22 13:03:28 +08:00
QQtTcpClient* QQTCloudClientInstance ( QObject* parent )
2017-10-17 22:00:45 +08:00
{
2018-04-22 13:03:28 +08:00
static QQtTcpClient* cli = NULL;
2018-01-15 09:08:57 +08:00
if ( !cli )
2017-10-17 22:00:45 +08:00
{
QStringList ip;
ip << "222.175.114.244" << "124.133.1.54";
2018-04-22 13:03:28 +08:00
cli = new QQtTcpClient ( parent );
2018-01-15 09:08:57 +08:00
cli->SetServerIPAddress ( ip );
cli->SetServerPort ( 7079 );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
return cli;
}
2018-01-15 09:08:57 +08:00
QQTCloudProtocol::QQTCloudProtocol ( QObject* parent ) : QQtProtocol ( parent )
2017-10-17 22:00:45 +08:00
{
m_isLogined = false;
m_heartCount = 0;
m_UID = 0;
2018-01-15 09:08:57 +08:00
timer = new QTimer ( this );
timer->setSingleShot ( false );
connect ( timer, SIGNAL ( timeout() ), this, SLOT ( sendHeatBeatMessage() ) );
2017-10-17 22:00:45 +08:00
2018-01-15 09:08:57 +08:00
connect ( this, SIGNAL ( signalSendData() ), this, SLOT ( sendUploadFileData() ), Qt::QueuedConnection );
connect ( this, SIGNAL ( signalDownData() ), this, SLOT ( sendDownFileData() ), Qt::QueuedConnection );
connect ( this, SIGNAL ( signalDownSucc() ), this, SLOT ( sendDownFileSuccess() ), Qt::QueuedConnection );
2017-10-17 22:00:45 +08:00
}
2017-10-24 13:52:25 +08:00
QTCheckVersionResult& QQTCloudProtocol::GetVersionResult() { return m_versionresult; }
2017-10-17 22:00:45 +08:00
2017-10-24 13:52:25 +08:00
QTCloudListDirResult& QQTCloudProtocol::GetDirList() { return m_dirs; }
2017-10-17 22:00:45 +08:00
2017-10-24 13:52:25 +08:00
QTCloudListFileResult& QQTCloudProtocol::GetListedFiles() { return m_files; }
2017-10-17 22:00:45 +08:00
bool QQTCloudProtocol::isLogined() { return m_isLogined; }
void QQTCloudProtocol::startHeartBeat()
{
m_heartCount = 0;
/*
* TODO:
*
* QNativeSocketEngine::write() was not called in QAbstractSocket::ConnectedState
*/
2018-01-15 09:08:57 +08:00
timer->start ( 30 * 1000 );
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::stopHeartBeat()
{
m_heartCount = MAX_HEARDBEAT + 1;
timer->stop();
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::sendMessage ( quint16 cmd, QByteArray& data )
2017-10-17 22:00:45 +08:00
{
QQTNetworkMessage qMsg;
2018-01-15 09:08:57 +08:00
qMsg.setUid ( m_UID );
qMsg.setCmd ( cmd );
qMsg.setData ( data );
2017-10-17 22:00:45 +08:00
qMsg.translate();
//pline() << qMsg;
QByteArray b;
2018-01-15 09:08:57 +08:00
qMsg.packer ( b );
write ( b );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
bool QQTCloudProtocol::dispatcher ( const QByteArray& m )
2017-10-17 22:00:45 +08:00
{
bool ret = true;
QQTNetworkMessage qMsg;
2018-01-15 09:08:57 +08:00
qMsg.parser ( m );
2017-10-17 22:00:45 +08:00
//pline() << qMsg;
2018-01-15 09:08:57 +08:00
switch ( qMsg.cmd() )
2017-10-17 22:00:45 +08:00
{
case _TCPCMD_LOGINRESUALT:
2018-01-15 09:08:57 +08:00
recvLoginResultMessage ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_HEARTBEATRESP:
2018-01-15 09:08:57 +08:00
recvHeatBeatResultMessage ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_CHECKVERSIONRSP:
2018-01-15 09:08:57 +08:00
recvCheckVersionResult ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_RECEIVEDIRLIST:
2018-01-15 09:08:57 +08:00
recvListDirResultMessage ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_RECEIVEADDRESUALT:
2018-01-15 09:08:57 +08:00
recvAddDirResultMessage ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_RECEIVEALTERRESUALT:
2018-01-15 09:08:57 +08:00
recvModDirResultMessage ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_RECEIVEDELETERESUALT:
2018-01-15 09:08:57 +08:00
recvDelDirResultMessage ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_RECEIVEFILELIST:
2018-01-15 09:08:57 +08:00
recvListFilesResultMessage ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_RECEIVEPUBLICDIRLIST:
2018-01-15 09:08:57 +08:00
recvListPubDirResultMessage ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_RECEIVEPUBLICFILELIST:
2018-01-15 09:08:57 +08:00
recvListPubFilesResultMessage ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_RECEIVEFILEINFO:
2018-01-15 09:08:57 +08:00
recvDownFileResultMessage ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_RECEIVEFILEDATA:
2018-01-15 09:08:57 +08:00
recvDownFileDataResultMessage ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_RECEIVECOMFIREFILEINFO:
2018-01-15 09:08:57 +08:00
recvUploadFileResult ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_RECEIVECOMFIREFILEDATA:
2018-01-15 09:08:57 +08:00
recvUploadFileDataResult ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case _TCPCMD_RECEIVECOMFIREFILE:
2018-01-15 09:08:57 +08:00
recvUploadFileSuccess ( qMsg );
2017-10-17 22:00:45 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
default:
//pline() << "receive unknown command:" << hex << qMsg.cmd();
ret = false;
break;
}
return ret;
}
void QQTCloudProtocol::sendHeatBeatMessage()
{
/*
* TODO:
*/
2018-01-15 09:08:57 +08:00
if ( m_heartCount > MAX_HEARDBEAT )
2017-10-17 22:00:45 +08:00
{
#if 1
/*
* 30 * 2 s
*/
static int curp = 0;
2018-01-15 09:08:57 +08:00
if ( curp >= 2 )
2017-10-17 22:00:45 +08:00
{
curp = 0;
emit signalReconnectQequest();
return;
}
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
curp++;
#else
/*
* 30s 150s 300s 600s
*/
static int p[4] = {1, 5, 10, 20};
static int curp = 0;
static int curpos = 0;
2018-01-15 09:08:57 +08:00
if ( curp >= p[curpos] )
2017-10-17 22:00:45 +08:00
{
curp = 0;
2018-01-15 09:08:57 +08:00
curpos = ( curpos + 1 ) % 4;
2017-10-17 22:00:45 +08:00
connectToSingelHost();
return;
}
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
curp++;
#endif
return;
}
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
pline() << "HeartBeat Count:" << m_heartCount;
m_heartCount++;
QQTNetworkMessage qMsg;
2018-01-15 09:08:57 +08:00
qMsg.setUid ( m_UID );
qMsg.setCmd ( _TCPCMD_HEART );
2017-10-17 22:00:45 +08:00
qMsg.translate();
pline() << qMsg;
QByteArray b;
2018-01-15 09:08:57 +08:00
qMsg.packer ( b );
write ( b );
2017-10-17 22:00:45 +08:00
//waitForBytesWritten();
}
void QQTCloudProtocol::sendLoginMessage()
{
/*
* hex
*/
QSettings set;
2018-01-15 09:08:57 +08:00
QByteArray _name = set.value ( "Device/DeviceNo" ).toByteArray();
QByteArray _pwd = set.value ( "Device/Password" ).toByteArray();
2017-10-17 22:00:45 +08:00
QString name, pwd;
2018-01-15 09:08:57 +08:00
for ( int i = 0; i < _name.size(); i++ )
name += QString::number ( ( quint8 ) _name[i], 16 );
for ( int i = 0; i < _pwd.size(); i++ )
pwd += QString::number ( ( quint8 ) _pwd[i], 16 );
2017-10-17 22:00:45 +08:00
name = name.toUpper();
pwd = pwd.toUpper();
m_isLogined = false;
QTCloudLogin t;
t.m_name = name;
t.m_password = pwd;
QQTNetworkMessage qMsg;
2018-01-15 09:08:57 +08:00
qMsg.setUid ( m_UID );
qMsg.setCmd ( _TCPCMD_LOGIN );
2017-10-17 22:00:45 +08:00
QByteArray d;
2018-01-15 09:08:57 +08:00
packLoginData ( d, t );
qMsg.setData ( d );
2017-10-17 22:00:45 +08:00
qMsg.translate();
//pline() << qMsg;
QByteArray b;
2018-01-15 09:08:57 +08:00
qMsg.packer ( b );
write ( b );
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::sendLogoutMessage()
{
m_isLogined = false;
QQTNetworkMessage qMsg;
2018-01-15 09:08:57 +08:00
qMsg.setUid ( m_UID );
qMsg.setCmd ( _TCPCMD_EXIT );
2017-10-17 22:00:45 +08:00
qMsg.translate();
//pline() << qMsg;
QByteArray b;
2018-01-15 09:08:57 +08:00
qMsg.packer ( b );
write ( b );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvConnPoolFullMessage ( QQTNetworkMessage& ) {}
2017-10-17 22:00:45 +08:00
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvLoginResultMessage ( QQTNetworkMessage& qMsg )
2017-10-17 22:00:45 +08:00
{
m_UID = qMsg.uid();
QTCloudLoginResult qtLoginResult;
2018-01-15 09:08:57 +08:00
parseLoginResultData ( qtLoginResult, qMsg.data() );
switch ( qtLoginResult.m_result )
2017-10-17 22:00:45 +08:00
{
case 0x00:
{
pline() << "Login success id:" << hex << m_UID;
m_isLogined = true;
emit signalLoginSucc();
}
2017-10-24 13:52:25 +08:00
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case 0x10:
pline() << "Other user logined";
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case 0x11:
pline() << "User unexisted";
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case 0x12:
pline() << "Password error upflowed";
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case 0x23:
case 0x22:
case 0x21:
pline() << "Password error" << hex << qtLoginResult.m_result;
break;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
case 0xFF:
default:
pline() << "unknown error" << qtLoginResult.m_result;
break;
}
2018-01-15 09:08:57 +08:00
if ( 0x00 != qtLoginResult.m_result )
2017-10-17 22:00:45 +08:00
emit signalLoginFail();
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvHeatBeatResultMessage ( QQTNetworkMessage& )
2017-10-17 22:00:45 +08:00
{
m_heartCount = 0;
pline() << "HeartBeat Callback";
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::packCheckVersionData ( QByteArray& l, const QTCheckVersion& t )
2017-10-17 22:00:45 +08:00
{
2018-01-15 09:08:57 +08:00
packKeyWordToByteArray ( l, _TCP_SECTION_SOFTWAREID, t.m_softwareid );
packKeyWordToByteArray ( l, _TCP_SECTION_DEVICECODE, t.m_devicecode );
packKeyWordToByteArray ( l, _TCP_SECTION_SOFTWARECODE, t.m_softwarecode );
packKeyWordToByteArray ( l, _TCP_SECTION_VERSION, t.m_version );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::parseCheckVersionResultData ( QTCheckVersionResult& t, const QByteArray& l )
2017-10-17 22:00:45 +08:00
{
quint32 pos = 0;
QByteArray b = l;
2018-01-15 09:08:57 +08:00
t.m_softwareid = parseKeyWordInByteArray ( b, _TCP_SECTION_SOFTWAREID, pos );
t.m_devicecode = parseKeyWordInByteArray ( b, _TCP_SECTION_DEVICECODE, pos );
t.m_softwarecode = parseKeyWordInByteArray ( b, _TCP_SECTION_SOFTWARECODE, pos );
t.m_version = parseKeyWordInByteArray ( b, _TCP_SECTION_VERSION, pos );
t.m_NewSoftwareID = parseKeyWordInByteArray ( b, _TCP_SECTION_NEWSOFTWAREID, pos );
2017-10-17 22:00:45 +08:00
/*
*
*/
2018-01-15 09:08:57 +08:00
QByteArray m_Explain = parseKeyWordInByteArray ( b, _TCP_SECTION_EXPLAIN, pos );
QTextCodec* Codec = QTextCodec::codecForName ( "gbk" );
t.m_Explain = Codec->toUnicode ( m_Explain );
2017-10-17 22:00:45 +08:00
2018-01-15 09:08:57 +08:00
t.m_ReleaseStatus = parseKeyWordInByteArray ( b, _TCP_SECTION_RELEASESTAT, pos );
t.m_ReleaseDate = parseKeyWordInByteArray ( b, _TCP_SECTION_RELEASEDATE, pos );
t.m_FileName = parseKeyWordInByteArray ( b, _TCP_SECTION_FILENAME, pos );
t.m_FileMD5 = parseKeyWordInByteArray ( b, _TCP_SECTION_FILEMD5, pos );
t.m_FileSize = parseKeyWordInByteArray ( b, _TCP_SECTION_FILESIZE, pos );
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::sendCheckVersion()
{
QTCheckVersion t;
t.m_softwareid = "0";
t.m_devicecode = "0601";
t.m_softwarecode = "211100";
2018-01-15 09:08:57 +08:00
t.m_version = "";
2017-10-17 22:00:45 +08:00
quint16 _tcpcmd = _TCPCMD_CHECKVERSION;
QQTNetworkMessage qMsg;
2018-01-15 09:08:57 +08:00
qMsg.setUid ( m_UID );
qMsg.setCmd ( _tcpcmd );
2017-10-17 22:00:45 +08:00
QByteArray d;
2018-01-15 09:08:57 +08:00
packCheckVersionData ( d, t );
qMsg.setData ( d );
2017-10-17 22:00:45 +08:00
qMsg.translate();
//pline() << qMsg;
QByteArray b;
2018-01-15 09:08:57 +08:00
qMsg.packer ( b );
write ( b );
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::sendCheckNewVersion()
{
QTCheckVersion t;
t.m_softwareid = m_versionresult.m_NewSoftwareID;
t.m_devicecode = "";
t.m_softwarecode = "";
2018-01-15 09:08:57 +08:00
t.m_version = "";
2017-10-17 22:00:45 +08:00
quint16 _tcpcmd = _TCPCMD_CHECKVERSION;
QQTNetworkMessage qMsg;
2018-01-15 09:08:57 +08:00
qMsg.setUid ( m_UID );
qMsg.setCmd ( _tcpcmd );
2017-10-17 22:00:45 +08:00
QByteArray d;
2018-01-15 09:08:57 +08:00
packCheckVersionData ( d, t );
qMsg.setData ( d );
2017-10-17 22:00:45 +08:00
qMsg.translate();
//pline() << qMsg;
QByteArray b;
2018-01-15 09:08:57 +08:00
qMsg.packer ( b );
write ( b );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvCheckVersionResult ( QQTNetworkMessage& qMsg )
2017-10-17 22:00:45 +08:00
{
2018-01-15 09:08:57 +08:00
parseCheckVersionResultData ( m_versionresult, qMsg.data() );
2017-10-17 22:00:45 +08:00
emit signalCheckVersionResult();
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::packListDirData ( QByteArray& l, const QTCloudListDir& t )
2017-10-17 22:00:45 +08:00
{
l = t.m_code.toLatin1();
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::parseListDirResultData ( QTCloudListDirResult& r, const QByteArray& l )
2017-10-17 22:00:45 +08:00
{
quint32 pos = 0;
QByteArray b = l;
QByteArray h;
2018-01-15 09:08:57 +08:00
h = parseKeyWordInByteArray ( b, _TCP_SECTION_UPCODE, pos );
2017-10-17 22:00:45 +08:00
r.m_upcode = h;
2018-01-15 09:08:57 +08:00
while ( pos < b.length() )
2017-10-17 22:00:45 +08:00
{
_QTCloudListDirResult _r;
QByteArray __r;
2018-01-15 09:08:57 +08:00
__r = parseKeyWordInByteArray ( b, _TCP_SECTION_ID, pos );
2017-10-17 22:00:45 +08:00
_r.m_id = __r;
2018-01-15 09:08:57 +08:00
__r = parseKeyWordInByteArray ( b, _TCP_SECTION_CODE, pos );
2017-10-17 22:00:45 +08:00
_r.m_code = __r;
2018-01-15 09:08:57 +08:00
__r = parseKeyWordInByteArray ( b, _TCP_SECTION_NAME, pos );
2017-10-17 22:00:45 +08:00
_r.m_name = __r;
2018-01-15 09:08:57 +08:00
r.m_dir.push_back ( _r );
2017-10-17 22:00:45 +08:00
}
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::packAddDirData ( QByteArray& l, const QTCloudAddDir& t )
2017-10-17 22:00:45 +08:00
{
2018-01-15 09:08:57 +08:00
packKeyWordToByteArray ( l, _TCP_SECTION_UPCODE, t.m_upcode );
packKeyWordToByteArray ( l, _TCP_SECTION_CODE, t.m_code );
packKeyWordToByteArray ( l, _TCP_SECTION_NAME, t.m_name );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::parseAddDirResultData ( QTCloudAddDirResult& t, const QByteArray& l )
2017-10-17 22:00:45 +08:00
{
quint32 pos = 0;
QByteArray b = l;
2018-01-15 09:08:57 +08:00
t.m_upcode = parseKeyWordInByteArray ( b, _TCP_SECTION_UPCODE, pos );
t.m_result = parseKeyWordInByteArray ( b, _TCP_SECTION_RESULE, pos );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::packDelFileData ( QByteArray& l, const QTCloudDelFile& t )
2017-10-17 22:00:45 +08:00
{
2018-01-15 09:08:57 +08:00
packKeyWordToByteArray ( l, _TCP_SECTION_CODE, t.m_code );
packKeyWordToByteArray ( l, _TCP_SECTION_ID, t.m_id );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::parseListFileResultData ( QTCloudListFileResult& r, const QByteArray& l )
2017-10-17 22:00:45 +08:00
{
quint32 pos = 0;
QByteArray b = l;
QByteArray h;
2018-01-15 09:08:57 +08:00
h = parseKeyWordInByteArray ( b, _TCP_SECTION_CODE, pos );
2017-10-17 22:00:45 +08:00
r.m_code = h;
2018-01-15 09:08:57 +08:00
while ( pos < b.length() )
2017-10-17 22:00:45 +08:00
{
_QTCloudListFileResult _r;
QByteArray __r;
2018-01-15 09:08:57 +08:00
__r = parseKeyWordInByteArray ( b, _TCP_SECTION_ID, pos );
2017-10-17 22:00:45 +08:00
_r.m_id = __r;
2018-01-15 09:08:57 +08:00
__r = parseKeyWordInByteArray ( b, _TCP_SECTION_NAME, pos );
2017-10-17 22:00:45 +08:00
_r.m_name = __r;
2018-01-15 09:08:57 +08:00
__r = parseKeyWordInByteArray ( b, _TCP_SECTION_SIZE, pos );
2017-10-17 22:00:45 +08:00
_r.m_size = __r;
2018-01-15 09:08:57 +08:00
__r = parseKeyWordInByteArray ( b, _TCP_SECTION_DATE, pos );
2017-10-17 22:00:45 +08:00
_r.m_date = __r;
2018-01-15 09:08:57 +08:00
r.m_file.push_back ( _r );
2017-10-17 22:00:45 +08:00
}
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::packDownDevFileData ( QByteArray& l, const QTCloudDownDevFile& t )
2017-10-17 22:00:45 +08:00
{
l = t.m_id.toLatin1();
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::parseDownDevFileResultData ( QTCloudDownDevFileResult& t, const QByteArray& l )
2017-10-17 22:00:45 +08:00
{
quint32 pos = 0;
QByteArray b = l;
2018-01-15 09:08:57 +08:00
t.m_fileno = parseKeyWordInByteArray ( b, _TCP_SECTION_FILENO, pos );
t.m_name = parseKeyWordInByteArray ( b, _TCP_SECTION_NAME, pos );
t.m_length = parseKeyWordInByteArray ( b, _TCP_SECTION_LENGTH, pos );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::packDownDevFileSuccessData ( QByteArray& l, const QTCloudDownFileSuccess& t )
2017-10-17 22:00:45 +08:00
{
l << t.m_fileno;
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::packDownDevFileDataData ( QByteArray& l, const QTCloudDownFileData& t )
2017-10-17 22:00:45 +08:00
{
l << t.m_fileno << t.m_dno;
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::parseDownDevFileDataResultData ( QTCloudDownFileDataResult& t, const QByteArray& l )
2017-10-17 22:00:45 +08:00
{
quint32 pos = 0;
QByteArray b = l;
b >> t.m_fileno >> t.m_dno >> t.m_addr >> t.m_dlen;
2018-01-15 09:08:57 +08:00
t.m_data.resize ( t.m_dlen );
2017-10-17 22:00:45 +08:00
b >> t.m_data;
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::packUploadFileData ( QByteArray& l, const QTCloudUploadFile& t )
2017-10-17 22:00:45 +08:00
{
2018-01-15 09:08:57 +08:00
l = QString ( _TCPCMD_DATASENDFILEINFO ).arg ( t.m_code ).arg ( t.m_name ).arg ( t.m_overwrite ).arg (
t.m_length ).toLatin1();
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::parseUploadFileResultData ( QTCloudUploadFileResult& t, const QByteArray& l )
2017-10-17 22:00:45 +08:00
{
QByteArray b = l;
b >> t.m_fileno >> t.m_state;
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::packUploadFileDataData ( QByteArray& l, const QTCloudUploadFileData& t )
2017-10-17 22:00:45 +08:00
{
l << t.m_fileno << t.m_dno << t.m_addr << t.m_dlen << t.m_data;
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::parseUploadFileDataResultData ( QTCloudUploadFileDataResult& t, const QByteArray& l )
2017-10-17 22:00:45 +08:00
{
QByteArray b = l;
b >> t.m_fileno >> t.m_dno;
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::parseUploadFileSuccessData ( QTCloudUploadFileSuccess& t, const QByteArray& l )
2017-10-17 22:00:45 +08:00
{
QByteArray b = l;
b >> t.m_fileno;
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::sendListDirectory ( QString code )
2017-10-17 22:00:45 +08:00
{
QTCloudListDir t;
t.m_code = code;
quint16 _tcpcmd = _TCPCMD_SEARCHDIR;
QQTNetworkMessage qMsg;
2018-01-15 09:08:57 +08:00
qMsg.setUid ( m_UID );
qMsg.setCmd ( _tcpcmd );
2017-10-17 22:00:45 +08:00
QByteArray d;
2018-01-15 09:08:57 +08:00
packListDirData ( d, t );
qMsg.setData ( d );
2017-10-17 22:00:45 +08:00
qMsg.translate();
//pline() << qMsg;
QByteArray b;
2018-01-15 09:08:57 +08:00
qMsg.packer ( b );
write ( b );
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::sendAddDirectory()
{
QTCloudAddDir t;
t.m_upcode = "";
t.m_code = "";
t.m_name = "Method2";
quint16 _tcpcmd = _TCPCMD_ADDDIR;
QByteArray d;
2018-01-15 09:08:57 +08:00
packAddDirData ( d, t );
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::sendModDirectory()
{
QTCloudModDirName t;
t.m_upcode = "";
t.m_code = "";
t.m_name = "Method2";
quint16 _tcpcmd = _TCPCMD_ALTERDIR;
QByteArray d;
//(d, t);
2018-01-15 09:08:57 +08:00
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::sendDelDirectory()
{
QTCloudDelDir t;
t.m_upcode = "";
t.m_code = "";
t.m_name = "Method2";
quint16 _tcpcmd = _TCPCMD_DELETEDIR;
QByteArray d;
//(d, t);
2018-01-15 09:08:57 +08:00
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvAddDirResultMessage ( QQTNetworkMessage& ) {}
2017-10-17 22:00:45 +08:00
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvDelDirResultMessage ( QQTNetworkMessage& ) {}
2017-10-17 22:00:45 +08:00
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvModDirResultMessage ( QQTNetworkMessage& ) {}
2017-10-17 22:00:45 +08:00
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::sendListFiles ( QString code )
2017-10-17 22:00:45 +08:00
{
QTCloudListFile t;
t.m_code = code;
quint16 _tcpcmd = _TCPCMD_SEARCHFILE;
QByteArray d;
2018-01-15 09:08:57 +08:00
packListDirData ( d, t );
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::sendDelFile ( QString code, QString id )
2017-10-17 22:00:45 +08:00
{
QTCloudDelFile t;
t.m_code = code;
t.m_id = id;
quint16 _tcpcmd = _TCPCMD_DELETEFILE;
QByteArray d;
2018-01-15 09:08:57 +08:00
packDelFileData ( d, t );
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
pline() << t.m_code << t.m_id;
}
void QQTCloudProtocol::sendListPubDirectory()
{
QTCloudListPubDir t;
t.m_code = "";
quint16 _tcpcmd = _TCPCMD_SEARCHPUBLICDIR;
QByteArray d;
2018-01-15 09:08:57 +08:00
packListDirData ( d, t );
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::sendListPubFiles()
{
QTCloudListPubFile t;
t.m_code = "";
quint16 _tcpcmd = _TCPCMD_SEARCHPUBLICFILE;
QByteArray d;
2018-01-15 09:08:57 +08:00
packListDirData ( d, t );
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::sendDownDevFiles ( const QString& id, const QString& localfile )
2017-10-17 22:00:45 +08:00
{
m_downfileresult.m_localfile = localfile;
m_work = 1;
QTCloudDownDevFile t;
t.m_id = id;
quint16 _tcpcmd = _TCPCMD_DOWNLOADFILE;
QByteArray d;
2018-01-15 09:08:57 +08:00
packDownDevFileData ( d, t );
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::sendDownPubFiles()
{
QTCloudDownPubFile t;
_QTCloudListFileResult _result;
2018-01-15 09:08:57 +08:00
foreach ( _result, m_pubfiles.m_file )
2017-10-24 13:52:25 +08:00
{
2017-10-17 22:00:45 +08:00
break;
}
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
t.m_id = _result.m_id;
quint16 _tcpcmd = _TCPCMD_DOWNLOADPUBFILE;
QByteArray d;
2018-01-15 09:08:57 +08:00
packDownDevFileData ( d, t );
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::sendDownFileData()
{
pline() << m_downfiledata.m_fileno << m_downfiledata.m_dno;
quint16 _tcpcmd = _TCPCMD_COMFIREFILEINFO;
QByteArray d;
2018-01-15 09:08:57 +08:00
packDownDevFileDataData ( d, m_downfiledata );
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::sendCancelDown()
{
QTCloudCancelDownFile t;
t.m_fileno = m_downfiledata.m_fileno;
quint16 _tcpcmd = _TCPCMD_CANCELREVFILE;
m_work = 0;
emit signalCancelDown();;
QByteArray d;
2018-01-15 09:08:57 +08:00
packDownDevFileSuccessData ( d, t );
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::sendDownFileSuccess()
{
QTCloudDownFileSuccess t;
t.m_fileno = m_downfiledata.m_fileno;
quint16 _tcpcmd = _TCPCMD_DOWNFILEOK;
QByteArray d;
2018-01-15 09:08:57 +08:00
packDownDevFileSuccessData ( d, t );
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::sendUploadFile ( const QString& code, const QString& cloudname, const QString& localfile )
2017-10-17 22:00:45 +08:00
{
m_uploadfile.m_code = code;
m_uploadfile.m_name = cloudname;
m_uploadfile.m_localfile = localfile;
2018-01-15 09:08:57 +08:00
QFileInfo f ( m_uploadfile.m_localfile );
m_uploadfile.m_length = QString::number ( f.size() );
2017-10-17 22:00:45 +08:00
m_uploadfile.m_overwrite = _TCP_RESULT_TRUE;
quint16 _tcpcmd = _TCPCMD_SENDFILEINFO;
QQTNetworkMessage qMsg;
2018-01-15 09:08:57 +08:00
qMsg.setUid ( m_UID );
qMsg.setCmd ( _tcpcmd );
2017-10-17 22:00:45 +08:00
QByteArray d;
2018-01-15 09:08:57 +08:00
packUploadFileData ( d, m_uploadfile );
qMsg.setData ( d );
2017-10-17 22:00:45 +08:00
qMsg.translate();
//pline() << qMsg;
QByteArray b;
2018-01-15 09:08:57 +08:00
qMsg.packer ( b );
write ( b );
2017-10-17 22:00:45 +08:00
//waitForBytesWritten(-1);
}
void QQTCloudProtocol::sendUploadFileData()
{
m_uploadfiledata.m_addr = m_uploadfiledata.m_dno * _TCP_BLOCKDATA_SIZE;
2018-01-15 09:08:57 +08:00
QFile f ( m_uploadfile.m_localfile );
f.open ( QIODevice::ReadOnly );
if ( f.isOpen() )
2017-10-17 22:00:45 +08:00
{
2018-01-15 09:08:57 +08:00
f.seek ( m_uploadfiledata.m_addr );
m_uploadfiledata.m_data = f.read ( _TCP_BLOCKDATA_SIZE );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
f.close();
m_uploadfiledata.m_dlen = m_uploadfiledata.m_data.length();
quint16 _tcpcmd = _TCPCMD_SENDFILEDATA;
QQTNetworkMessage qMsg;
2018-01-15 09:08:57 +08:00
qMsg.setUid ( m_UID );
qMsg.setCmd ( _tcpcmd );
2017-10-17 22:00:45 +08:00
QByteArray d;
2018-01-15 09:08:57 +08:00
packUploadFileDataData ( d, m_uploadfiledata );
qMsg.setData ( d );
2017-10-17 22:00:45 +08:00
qMsg.translate();
pline() << qMsg;
QByteArray b;
2018-01-15 09:08:57 +08:00
qMsg.packer ( b );
write ( b );
2017-10-17 22:00:45 +08:00
2018-01-15 09:08:57 +08:00
pline() << m_uploadfile.m_name << m_uploadfile.m_localfile << m_uploadfiledata.m_fileno << m_uploadfiledata.m_dno <<
m_uploadfiledata.m_addr << m_uploadfiledata.m_dlen;
2017-10-17 22:00:45 +08:00
}
void QQTCloudProtocol::sendCancelUpload()
{
QTCloudCancelUploadFile t;
t.m_fileno = m_uploadfiledata.m_fileno;
quint16 _tcpcmd = _TCPCMD_CANCELSENDFILE;
QByteArray d;
2018-01-15 09:08:57 +08:00
packDownDevFileSuccessData ( d, t );
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
emit signalCancelUpload();
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::sendDownUpgradeFile ( const QString& id, const QString& localfile )
2017-10-17 22:00:45 +08:00
{
m_downfileresult.m_localfile = localfile;
m_work = 1;
QTCloudDownDevFile t;
t.m_id = id;
quint16 _tcpcmd = _TCPCMD_DOWNUPGRADEFILE;
QByteArray d;
2018-01-15 09:08:57 +08:00
packDownDevFileData ( d, t );
sendMessage ( _tcpcmd, d );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvListDirResultMessage ( QQTNetworkMessage& qMsg )
2017-10-17 22:00:45 +08:00
{
m_dirs.m_upcode = "";
m_dirs.m_dir.clear();
2018-01-15 09:08:57 +08:00
parseListDirResultData ( m_dirs, qMsg.data() );
2017-10-17 22:00:45 +08:00
pline() << m_dirs.m_upcode;
_QTCloudListDirResult _result;
2018-01-15 09:08:57 +08:00
foreach ( _result, m_dirs.m_dir )
2017-10-24 13:52:25 +08:00
{
2017-10-17 22:00:45 +08:00
/*
* model中
*/
pline() << _result.m_id << _result.m_code << _result.m_name;
}
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
emit signalListDirOK();
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvListFilesResultMessage ( QQTNetworkMessage& qMsg )
2017-10-17 22:00:45 +08:00
{
m_files.m_code = "";
m_files.m_file.clear();
2018-01-15 09:08:57 +08:00
parseListFileResultData ( m_files, qMsg.data() );
2017-10-17 22:00:45 +08:00
pline() << m_files.m_code;
_QTCloudListFileResult _result;
2018-01-15 09:08:57 +08:00
foreach ( _result, m_files.m_file )
2017-10-24 13:52:25 +08:00
{
2017-10-17 22:00:45 +08:00
/*
* model中
*/
pline() << _result.m_id << _result.m_name << _result.m_size << _result.m_date;
}
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
emit signalListFileOK();
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvListPubDirResultMessage ( QQTNetworkMessage& qMsg )
2017-10-17 22:00:45 +08:00
{
m_pubdirs.m_upcode = "";
m_pubdirs.m_dir.clear();
2018-01-15 09:08:57 +08:00
parseListDirResultData ( m_pubdirs, qMsg.data() );
2017-10-17 22:00:45 +08:00
pline() << m_pubdirs.m_upcode;
_QTCloudListDirResult _result;
2018-01-15 09:08:57 +08:00
foreach ( _result, m_pubdirs.m_dir )
2017-10-24 13:52:25 +08:00
{
2017-10-17 22:00:45 +08:00
/*
* model中
*/
pline() << _result.m_id << _result.m_code << _result.m_name;
}
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvListPubFilesResultMessage ( QQTNetworkMessage& qMsg )
2017-10-17 22:00:45 +08:00
{
m_pubfiles.m_code = "";
m_pubfiles.m_file.clear();
2018-01-15 09:08:57 +08:00
parseListFileResultData ( m_pubfiles, qMsg.data() );
2017-10-17 22:00:45 +08:00
pline() << m_pubfiles.m_code;
_QTCloudListFileResult _result;
2018-01-15 09:08:57 +08:00
foreach ( _result, m_pubfiles.m_file )
2017-10-24 13:52:25 +08:00
{
2017-10-17 22:00:45 +08:00
/*
* model中
*/
pline() << _result.m_id << _result.m_name << _result.m_size << _result.m_date;
}
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvDownFileResultMessage ( QQTNetworkMessage& qMsg )
2017-10-17 22:00:45 +08:00
{
2018-01-15 09:08:57 +08:00
parseDownDevFileResultData ( m_downfileresult, qMsg.data() );
2017-10-17 22:00:45 +08:00
pline() << m_downfileresult.m_fileno << m_downfileresult.m_name << m_downfileresult.m_length;
m_downfiledata.m_fileno = m_downfileresult.m_fileno.toInt();
QString tmpFile = m_downfileresult.m_localfile;
#ifdef __EMBEDDED_LINUX__
2018-01-15 09:08:57 +08:00
system ( QString ( "touch %1" ).arg ( tmpFile ).toLatin1().data() );
2017-10-17 22:00:45 +08:00
#endif
2018-01-15 09:08:57 +08:00
QFile f ( tmpFile );
f.open ( QIODevice::WriteOnly | QIODevice::Truncate );
2017-10-17 22:00:45 +08:00
pline() << tmpFile << f.size();
f.close();
2018-01-15 09:08:57 +08:00
emit signalUpdateProgress ( 0 );
2017-10-17 22:00:45 +08:00
emit signalDownData();
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvDownFileDataResultMessage ( QQTNetworkMessage& qMsg )
2017-10-17 22:00:45 +08:00
{
2018-01-15 09:08:57 +08:00
if ( 0 == m_work )
2017-10-17 22:00:45 +08:00
return;
2018-01-15 09:08:57 +08:00
2017-10-17 22:00:45 +08:00
QTCloudDownFileDataResult result;
2018-01-15 09:08:57 +08:00
parseDownDevFileDataResultData ( result, qMsg.data() );
2017-10-17 22:00:45 +08:00
pline() << result.m_fileno << result.m_dno << result.m_addr <<
2017-10-24 13:52:25 +08:00
result.m_dlen;// << m_downfiledata.m_data;
2017-10-17 22:00:45 +08:00
int nFileSize = 0;
QString tmpFile = m_downfileresult.m_localfile;
2018-01-15 09:08:57 +08:00
QFile f ( tmpFile );
f.open ( QIODevice::WriteOnly | QIODevice::Append );
f.write ( result.m_data );
2017-10-17 22:00:45 +08:00
nFileSize = f.size();
f.close();
pline() << nFileSize << m_downfileresult.m_length;
int percent = 0;
2018-01-15 09:08:57 +08:00
if ( nFileSize > 0 )
2017-10-17 22:00:45 +08:00
percent = 100 * nFileSize / m_downfileresult.m_length.toInt();
2018-01-15 09:08:57 +08:00
emit signalUpdateProgress ( percent );
2017-10-17 22:00:45 +08:00
pline() << percent;
2018-01-15 09:08:57 +08:00
if ( nFileSize < m_downfileresult.m_length.toInt() )
2017-10-17 22:00:45 +08:00
{
m_downfiledata.m_dno++;
emit signalDownData();
}
else
{
m_downfiledata.m_dno = 0;
emit signalDownSucc();
}
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvUploadFileResult ( QQTNetworkMessage& qMsg )
2017-10-17 22:00:45 +08:00
{
QTCloudUploadFileResult result;
2018-01-15 09:08:57 +08:00
parseUploadFileResultData ( result, qMsg.data() );
2017-10-17 22:00:45 +08:00
pline() << result.m_fileno << result.m_state;
2018-01-15 09:08:57 +08:00
perr ( result.m_state, 0x00 ) << "ok to send file data";
perr ( result.m_state, 0x01 ) << "unsupport file type";
perr ( result.m_state, 0x02 ) << "file too length";
perr ( result.m_state, 0x03 ) << "too much file";
perr ( result.m_state, 0x04 ) << "files too long";
perr ( result.m_state, 0x14 ) << "no much storage";
if ( result.m_state == 0x00 )
2017-10-17 22:00:45 +08:00
{
m_uploadfiledata.m_fileno = result.m_fileno;
m_uploadfiledata.m_dno = 0;
/*
* 使Timer确认不是网络速率的原因
*/
2018-01-15 09:08:57 +08:00
emit signalUpdateProgress ( 0 );
2017-10-17 22:00:45 +08:00
emit signalSendData();
}
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvUploadFileDataResult ( QQTNetworkMessage& qMsg )
2017-10-17 22:00:45 +08:00
{
QTCloudUploadFileDataResult result;
2018-01-15 09:08:57 +08:00
parseUploadFileDataResultData ( result, qMsg.data() );
2017-10-24 13:52:25 +08:00
pline() << result.m_fileno << result.m_dno << result.m_dno* _TCP_BLOCKDATA_SIZE << m_uploadfile.m_length.toInt();
2017-10-17 22:00:45 +08:00
/*
*
*/
m_uploadfiledata.m_dno = result.m_dno + 1;
int percent = 0;
2018-01-15 09:08:57 +08:00
if ( m_uploadfile.m_length.toInt() > 0 )
2017-10-17 22:00:45 +08:00
percent = 100 * m_uploadfiledata.m_dno * _TCP_BLOCKDATA_SIZE /
2017-10-24 13:52:25 +08:00
m_uploadfile.m_length.toInt();
2017-10-17 22:00:45 +08:00
2018-01-15 09:08:57 +08:00
if ( m_uploadfiledata.m_dno * _TCP_BLOCKDATA_SIZE < m_uploadfile.m_length.toInt() )
2017-10-17 22:00:45 +08:00
{
emit signalSendData();
2018-01-15 09:08:57 +08:00
emit signalUpdateProgress ( percent );
2017-10-17 22:00:45 +08:00
}
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::recvUploadFileSuccess ( QQTNetworkMessage& qMsg )
2017-10-17 22:00:45 +08:00
{
QTCloudUploadFileSuccess result;
2018-01-15 09:08:57 +08:00
parseUploadFileSuccessData ( result, qMsg.data() );
pline() << result.m_fileno << m_uploadfiledata.m_dno << m_uploadfiledata.m_dno* _TCP_BLOCKDATA_SIZE <<
m_uploadfile.m_length.toInt() << "upload success";
emit signalUpdateProgress ( 100 );
2017-10-17 22:00:45 +08:00
emit signalUploadSucc();
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::packLoginData ( QByteArray& l, const QTCloudLogin& t )
2017-10-17 22:00:45 +08:00
{
2018-01-15 09:08:57 +08:00
l = QString ( _TCPCMD_DATALOGIN ).arg ( t.m_name ).arg ( t.m_password ).toLatin1();
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
void QQTCloudProtocol::parseLoginResultData ( QTCloudLoginResult& t, const QByteArray& l )
2017-10-17 22:00:45 +08:00
{
QByteArray _l = l;
_l >> t.m_result;
}
2018-01-15 09:08:57 +08:00
QByteArray& QQTCloudProtocol::packKeyWordToByteArray ( QByteArray& array, const QString& key, const QString& value )
2017-10-17 22:00:45 +08:00
{
return array << key.toLatin1() << "=\"" << value.toLatin1() << "\"";
}
2018-01-15 09:08:57 +08:00
QByteArray QQTCloudProtocol::parseKeyWordInByteArray ( const QByteArray& array, const QByteArray& section,
quint32& pos )
2017-10-17 22:00:45 +08:00
{
int index = pos, indexTemp = 0;
2018-01-15 09:08:57 +08:00
index = array.indexOf ( section, index );
index = array.indexOf ( '\"', index );
indexTemp = array.indexOf ( '\"', index + 1 );
2017-10-17 22:00:45 +08:00
pos = indexTemp + 1;
2018-01-15 09:08:57 +08:00
return array.mid ( index + 1, ( indexTemp - index - 1 ) );
2017-10-17 22:00:45 +08:00
}
2018-01-15 09:08:57 +08:00
quint16 QQTCloudProtocol::splitter ( const QByteArray& s )
2017-10-17 22:00:45 +08:00
{
2018-01-15 09:08:57 +08:00
QByteArray l = s.left ( 4 );
2017-10-17 22:00:45 +08:00
quint16 b0 = 0, b1 = 0;
l >> b0 >> b1;
return b1;
}
quint16 QQTCloudProtocol::minlength()
{
return 16;
}
quint16 QQTCloudProtocol::maxlength()
{
return 32768;
}