diff options
| author | 2010-06-02 14:57:24 +0000 | |
|---|---|---|
| committer | 2010-06-02 14:57:24 +0000 | |
| commit | 0edeeda7aa5ba240293cc2055666042b3e1a59fc (patch) | |
| tree | 25c39452c7762a4eeafb836b8dab7d84820fe40f /src/modules/dcc | |
| parent | Some fixes in classeditor + code improvements in tablewidget kvs class (diff) | |
| download | KVIrc-0edeeda7aa5ba240293cc2055666042b3e1a59fc.tar.gz KVIrc-0edeeda7aa5ba240293cc2055666042b3e1a59fc.tar.bz2 KVIrc-0edeeda7aa5ba240293cc2055666042b3e1a59fc.zip | |
DCC works. Support 64bit resume offsets. Add option for routers that remap DCC SEND but not DCC RESUME. Some cleanups...
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@4417 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/dcc')
| -rw-r--r-- | src/modules/dcc/broker.cpp | 25 | ||||
| -rw-r--r-- | src/modules/dcc/requests.cpp | 2 | ||||
| -rw-r--r-- | src/modules/dcc/send.cpp | 111 |
3 files changed, 92 insertions, 46 deletions
diff --git a/src/modules/dcc/broker.cpp b/src/modules/dcc/broker.cpp index 2b82d8a5a..820fc781d 100644 --- a/src/modules/dcc/broker.cpp +++ b/src/modules/dcc/broker.cpp @@ -957,18 +957,17 @@ bool KviDccBroker::handleResumeRequest(KviDccRequest * dcc,const char * filename KviDccZeroPortTag * t = findZeroPortTag(QString(szZeroPortTag)); if(t) { - //debug("FOUND"); // valid zero port resume request - if(filePos < t->m_uFileSize) - { - //debug("VALID"); - // ok! - t->m_uResumePosition = filePos; + if(filePos >= t->m_uFileSize) + return false; // invalid resume size + + // ok! + t->m_uResumePosition = filePos; - KviStr szBuffy; - KviServerParser::encodeCtcpParameter(filename,szBuffy); + KviStr szBuffy; + KviServerParser::encodeCtcpParameter(filename,szBuffy); - dcc->ctcpMsg->msg->console()->connection()->sendFmtData( + dcc->ctcpMsg->msg->console()->connection()->sendFmtData( "PRIVMSG %s :%cDCC ACCEPT %s %s %u %s%c", dcc->ctcpMsg->msg->console()->connection()->encodeText(dcc->ctcpMsg->pSource->nick()).data(), 0x01, @@ -976,12 +975,10 @@ bool KviDccBroker::handleResumeRequest(KviDccRequest * dcc,const char * filename port, filePos, szZeroPortTag, - 0x01); + 0x01 + ); - return true; - } else { - return false; // invalid resume size - } + return true; } } //debug("NOT A ZeRO PORT"); diff --git a/src/modules/dcc/requests.cpp b/src/modules/dcc/requests.cpp index 88d6fe968..f758d36ec 100644 --- a/src/modules/dcc/requests.cpp +++ b/src/modules/dcc/requests.cpp @@ -566,7 +566,7 @@ static void dccModuleParseDccResume(KviDccRequest *dcc) // DCC SEND <filename> <remoteip> <remoteport> <filesize> <tag> bool bOk; - quint64 filePos = dcc->szParam3.toULong(&bOk); + quint64 filePos = (quint64)(dcc->szParam3.toULongLong(&bOk)); if(!bOk) { if(!dcc->ctcpMsg->msg->haltOutput()) diff --git a/src/modules/dcc/send.cpp b/src/modules/dcc/send.cpp index f9da44da8..b3a8628b0 100644 --- a/src/modules/dcc/send.cpp +++ b/src/modules/dcc/send.cpp @@ -1438,11 +1438,13 @@ bool KviDccFileTransfer::handleResumeAccepted(const char * filename,const char * bool KviDccFileTransfer::handleResumeRequest(const char * filename,const char * port,quint64 filePos) { - if(!g_pDccFileTransfers)return false; + if(!g_pDccFileTransfers) + return false; for(KviDccFileTransfer * t = g_pDccFileTransfers->first();t;t = g_pDccFileTransfers->next()) { - if(t->doResume(filename,port,filePos))return true; + if(t->doResume(filename,port,filePos)) + return true; } return false; @@ -1785,42 +1787,89 @@ bool KviDccFileTransfer::resumeAccepted(const char *filename,const char *port,co bool KviDccFileTransfer::doResume(const char * filename,const char * port,quint64 filePos) { - if(KviQString::equalCI(port,m_pMarshal->dccPort()) && - (!m_pSlaveRecvThread) && (!m_pDescriptor->bRecvFile)) - { - if(KviQString::equalCI(filename,m_pDescriptor->szFileName) || KVI_OPTION_BOOL(KviOption_boolAcceptBrokenFileNameDccResumeRequests)) - { - bool bOk; - quint64 iLocalFileSize = m_pDescriptor->szLocalFileSize.toULongLong(&bOk); - if(!bOk) - { - // ops...internal error - outputAndLog(KVI_OUT_DCCERROR,__tr2qs_ctx("Internal error in RESUME request","dcc")); - return false; - } - if(iLocalFileSize <= filePos) - { - outputAndLog(KVI_OUT_DCCERROR,__tr2qs_ctx("Invalid RESUME request: Position %1 is larger than file size","dcc").arg(filePos)); - return false; - } + if(m_pSlaveRecvThread) + return false; // we're already receiving stuff... + if(m_pSlaveSendThread) + return false; // we're already sending stuff... - outputAndLog(KVI_OUT_DCCERROR,__tr2qs_ctx("Accepting RESUME request, transfer will begin at position %1","dcc").arg(filePos)); + if(m_pDescriptor->bRecvFile) + return false; // we're receiving... can't resume anything - m_pDescriptor->szFileSize.setNum(filePos); + bool bFileNameMatches = KviQString::equalCI(filename,m_pDescriptor->szFileName); + bool bPortMatches = KviQString::equalCI(port,m_pMarshal->dccPort()); + if(!bPortMatches) + { + // port doesn't match + if(!bFileNameMatches) + return false; // neither filename nor port match + + if(!KVI_OPTION_BOOL(KviOption_boolAcceptMismatchedPortDccResumeRequests)) + return false; - KviStr szBuffy; - KviServerParser::encodeCtcpParameter(filename,szBuffy); + // hmm.. try to accept a mismatched port request - m_pDescriptor->console()->connection()->sendFmtData("PRIVMSG %s :%cDCC ACCEPT %s %s %u%c", - m_pDescriptor->console()->connection()->encodeText(m_pDescriptor->szNick).data(), - 0x01, - m_pDescriptor->console()->connection()->encodeText(szBuffy.ptr()).data(), - port,filePos,0x01); - return true; + if(_OUTPUT_VERBOSE) + outputAndLog(KVI_OUT_DCCMSG,__tr2qs_ctx("Processing RESUME request with mismatched port (%1)","dcc").arg(port)); + } + + // port matches + + if(!bFileNameMatches) + { + // bad file name + if(!bPortMatches) + return false; // neither filename nor port match + + // port matches (this is very likely to be the right transfer) + + if(!KVI_OPTION_BOOL(KviOption_boolAcceptBrokenFileNameDccResumeRequests)) + { + if(_OUTPUT_VERBOSE) + outputAndLog( + KVI_OUT_DCCMSG, + __tr2qs_ctx("Invalid RESUME request: Invalid file name (got '%1' but should be '%2')","dcc") + .arg(filename) + .arg(m_pDescriptor->szFileName) + ); + return false; // bad file name } + + if(_OUTPUT_VERBOSE) + outputAndLog(KVI_OUT_DCCMSG,__tr2qs_ctx("Processing RESUME request with broken filename (%1)","dcc").arg(filename)); } - return false; + + bool bOk; + quint64 iLocalFileSize = m_pDescriptor->szLocalFileSize.toULongLong(&bOk); + + if(!bOk) + { + // ops...internal error + outputAndLog(KVI_OUT_DCCERROR,__tr2qs_ctx("Internal error in RESUME request","dcc")); + return false; + } + + if(iLocalFileSize <= filePos) + { + outputAndLog(KVI_OUT_DCCERROR,__tr2qs_ctx("Invalid RESUME request: Position %1 is larger than file size","dcc").arg(filePos)); + return false; + } + + outputAndLog(KVI_OUT_DCCERROR,__tr2qs_ctx("Accepting RESUME request, transfer will begin at position %1","dcc").arg(filePos)); + + m_pDescriptor->szFileSize.setNum(filePos); + + KviStr szBuffy; + KviServerParser::encodeCtcpParameter(filename,szBuffy); + + m_pDescriptor->console()->connection()->sendFmtData("PRIVMSG %s :%cDCC ACCEPT %s %s %u%c", + m_pDescriptor->console()->connection()->encodeText(m_pDescriptor->szNick).data(), + 0x01, + m_pDescriptor->console()->connection()->encodeText(szBuffy.ptr()).data(), + port,filePos,0x01 + ); + + return true; } |
