summaryrefslogtreecommitdiffabout
path: root/PumpKINDlg.cpp
Side-by-side diff
Diffstat (limited to 'PumpKINDlg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--PumpKINDlg.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/PumpKINDlg.cpp b/PumpKINDlg.cpp
index 1e6d03f..0b3bf41 100644
--- a/PumpKINDlg.cpp
+++ b/PumpKINDlg.cpp
@@ -1125,195 +1125,199 @@ CString tmp;
}
void CXferSocket::TurnSlashes(CString& fn,BOOL bBack)
{
int s = fn.Find(bBack?'/':'\\');
while(s>=0){
fn.SetAt(s,bBack?'\\':'/');
s = fn.Find(bBack?'/':'\\');
}
}
CString CXferSocket::ApplyRoot(LPCTSTR fileName)
{
ASSERT(m_Daddy);
CString fn = fileName;
CString rv = m_Daddy->m_TFTPRoot;
if(rv.IsEmpty())
rv = ".";
if(rv[rv.GetLength()-1]!='\\')
rv+="\\";
while((!fn.IsEmpty()) && fn[0]=='\\')
fn=fn.Mid(1);
rv+=fn;
return rv;
}
void CPumpKINDlg::OnOptions()
{
CPropertySheet cps(IDS_TITLE_OPTIONS,this);
CPropsServer server;
CPropsNetwork network;
CPropsSounds sounds;
server.m_RRQMode=m_RRQMode;
server.m_TFTPRoot=m_TFTPRoot;
server.m_TFTPSubdirs=m_bTFTPSubdirs;
server.m_WRQMode=m_WRQMode;
server.m_PromptTimeOut=m_PromptTimeOut;
network.m_ListenPort=m_ListenPort;
network.m_SpeakPort=m_SpeakPort;
network.m_TimeOut=m_TFTPTimeOut.GetTotalSeconds();
network.m_BlockSize=m_BlockSize;
sounds.m_Request = m_bnwRequest;
sounds.m_Success = m_bnwSuccess;
sounds.m_Abort = m_bnwAbort;
cps.AddPage(&server);
cps.AddPage(&network);
cps.AddPage(&sounds);
if(cps.DoModal()==IDOK){
m_RRQMode=server.m_RRQMode;
m_TFTPRoot=server.m_TFTPRoot;
m_bTFTPSubdirs=server.m_TFTPSubdirs;
m_WRQMode=server.m_WRQMode;
m_PromptTimeOut=server.m_PromptTimeOut;
m_ListenPort=network.m_ListenPort;
m_SpeakPort=network.m_SpeakPort;
m_TFTPTimeOut=CTimeSpan(network.m_TimeOut);
m_BlockSize=network.m_BlockSize;
m_bnwRequest = sounds.m_Request;
m_bnwSuccess = sounds.m_Success;
m_bnwAbort = sounds.m_Abort;
}
}
BOOL CRRQSocket::ConfirmRequest()
{
CConfirmRRQDlg cd(NULL);
cd.m_Daddy=this;
cd.m_File=m_FileName;
cd.m_Host=inet_ntoa(m_Peer.sin_addr);
if(cd.DoModal()==IDOK)
return TRUE;
return FALSE;
}
CWRQSocket::CWRQSocket(CPumpKINDlg* daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin)
: CXferSocket(daddy,fileName,type,sin)
{
state=stateNone;
m_ACK=0;
m_LastSlack=0;
m_bResume=FALSE;
}
BOOL CWRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName)
{
if(!CAsyncSocket::Create(0,SOCK_DGRAM))
return FALSE;
ASSERT(m_Daddy);
ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName);
m_Daddy->m_Xfers[m_hSocket]=this;
- TurnSlashes(m_FileName,TRUE);
UpdateList();
-CString fn = localFile?ApplyRootGently(localFile):ApplyRoot(m_FileName);
+CString lf;
+ if(!localFile) {
+ lf = m_FileName;
+ TurnSlashes(lf,TRUE);
+ }
+CString fn = localFile?ApplyRootGently(localFile):ApplyRoot(lf);
if(!localFile){ // This is an incoming request..
if(CheckBadRelativeness(m_FileName)){
Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
return TRUE;
}
BOOL exists;
if(!_access((LPCTSTR)fn,0))
m_Rename=exists=TRUE;
else
m_Rename=exists=FALSE;
// *** m_WRQMode only if server transfer
switch(m_Daddy->m_WRQMode){
case CPumpKINDlg::wrqTakeAll:
if(exists){
if(!RenameFile(fn)){
Deny(tftp::errDiskFull,IDS_TFTP_ERROR_FAILEDTORENAME);
return TRUE;
}
}
break;
case CPumpKINDlg::wrqConfirmIfExists:
if(!exists)
break;
case CPumpKINDlg::wrqAlwaysConfirm:
if(exists)
m_bResume=TRUE;
if(ConfirmRequest()){
if(m_Rename){
RenameFile(fn);
if(SaveAs(fn))
break;
}else
break;
}
case CPumpKINDlg::wrqDenyAll:
Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
return TRUE;
}
}
CFileException e;
if(!m_File.Open(
fn,
m_bResume
?(CFile::modeWrite|CFile::shareDenyWrite)
:(CFile::modeCreate|CFile::modeWrite|CFile::shareDenyWrite),
&e
)){
if(localFile){ // Outgoing request
CString tmp;
tmp.Format(IDS_LOG_FAILEDTOOPEN,fn);
m_Daddy->LogLine(tmp);
return FALSE;
}else{
Deny(&e);
return TRUE;
}
}
if(hostName){
m_HostName=hostName;
CString tmp;
tmp.Format(IDS_LOG_REQUESTING,m_FileName,m_HostName);
m_Daddy->LogLine(tmp);
CString inAddr = hostName;
int at = inAddr.Find('@');
if(at>=0)
inAddr=inAddr.Mid(at+1);
if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){
ASSERT(!m_wndResolver);
m_wndResolver = new CResolver(this);
ASSERT(m_wndResolver);
return m_wndResolver->Resolve();
}else{
OnHostKnown();
return TRUE;
}
}
CString v;
tftp::tftpOptions oack;
if(m_Options.Lookup(tftpoTSize,v)){
m_xferSize=atol(v);
if(!m_xferSize){
Deny(tftp::errOption,IDS_TFTP_ERROR_TSIZE);
return TRUE;
}
}
if(m_Options.Lookup(tftpoBSize,v)){
m_blkSize=atoi(v);
if(!m_blkSize){ // *** Do more about sanity check
Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE);
return TRUE;
}
v.Format("%u",m_blkSize);
oack[tftpoBSize]=v;
}