aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/dcc/send.cpp
diff options
context:
space:
mode:
authorGravatar Szymon Tomasz Stefanek2010-06-02 14:57:24 +0000
committerGravatar Szymon Tomasz Stefanek2010-06-02 14:57:24 +0000
commit0edeeda7aa5ba240293cc2055666042b3e1a59fc (patch)
tree25c39452c7762a4eeafb836b8dab7d84820fe40f /src/modules/dcc/send.cpp
parentSome fixes in classeditor + code improvements in tablewidget kvs class (diff)
downloadKVIrc-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/send.cpp')
-rw-r--r--src/modules/dcc/send.cpp111
1 files changed, 80 insertions, 31 deletions
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;
}