-rwxr-xr-x[-rw-r--r--] | PumpKINDlg.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/PumpKINDlg.cpp b/PumpKINDlg.cpp index f41b69f..3ff1500 100644..100755 --- a/PumpKINDlg.cpp +++ b/PumpKINDlg.cpp @@ -508,192 +508,193 @@ UINT tftp::GetOptions(tftp::tftpOptions* ops) tftpOptions& o = *ops;
LPSTR base = (LPSTR)&data.m_RQ.data;
UINT basePtr = 0;
if(Opcode()==opRRQ || Opcode()==opWRQ){
base = (LPSTR)memchr(&data.m_RQ.data,0,length-sizeof(opcode));
if(!base)
return 0;
base++;
basePtr = (base-(LPSTR)&data.m_RQ.data);
base = (LPSTR)memchr(base,0,length-basePtr);
if(!base)
return 0;
base++;
basePtr = (base-(LPSTR)&data.m_RQ.data);
}
ops->RemoveAll();
UINT rv = 0;
while(basePtr<(length-sizeof(opcode))){
CString onam = (LPSTR)&data.m_RQ.data[basePtr];
basePtr+=onam.GetLength()+1;
CString oval = (LPSTR)&data.m_RQ.data[basePtr];
basePtr+=oval.GetLength()+1;
onam.MakeLower();
o[onam]=oval;
rv++;
}
return rv;
}
tftp::tftp()
{
length=0;
}
void CXferSocket::OnSend(int nErrorCode)
{
if(nErrorCode){
ASSERT(m_Daddy);
m_Daddy->LogLine(IDS_LOG_XFERSEND);
return;
}
if(!m_Queue.IsEmpty()){
tftp *p = m_Queue.GetHead();
ASSERT(p);
m_Queue.RemoveHead();
if(!p->Send(this,&m_Peer)){
ASSERT(m_Daddy);
m_Daddy->LogLine(IDS_LOG_XFERUDPSEND);
}
delete p;
}
DoSelect();
if(m_Queue.IsEmpty()){
switch(state){
case stateDeny:
Destroy(FALSE);
break;
case stateFinish:
Destroy(TRUE);
break;
}
}
}
BOOL tftp::Send(CAsyncSocket *socket,SOCKADDR_IN* saddr)
{
ASSERT(socket);
int rv = socket->SendTo(udpBase(),length,(SOCKADDR*)saddr,sizeof(SOCKADDR_IN));
if(rv!=length)
return FALSE;
return TRUE;
}
void CXferSocket::DoSelect(BOOL do_select)
{
if(m_Peer.sin_addr.s_addr!=INADDR_NONE)
AsyncSelect(FD_CLOSE|FD_READ|((m_Queue.IsEmpty()&&!do_select)?0:FD_WRITE));
}
void CXferSocket::OnReceive(int nErrorCode)
{
if(nErrorCode){
ASSERT(m_Daddy);
m_Daddy->LogLine(IDS_LOG_XFERRECEIVE);
return;
}
ASSERT(m_Daddy);
DWORD fionread = 0;
VERIFY(IOCtl(FIONREAD,&fionread));
tftp *p = tftp::Allocate(fionread);
ASSERT(p);
SOCKADDR_IN sin;
if(!p->Receive(this,fionread,&sin)){
m_Daddy->LogLine(IDS_LOG_XFERUDPRECEIVE);
delete p;
+ return;
}else
if(m_Peer.sin_addr.s_addr==INADDR_NONE){
m_Peer.sin_addr=sin.sin_addr;
m_Peer.sin_port=sin.sin_port;
}
BOOL alive = TRUE;
if(state==stateInit){
state=stateXfer;
m_Peer.sin_port=sin.sin_port;
UpdateList();
}
if(sin.sin_addr.s_addr!=m_Peer.sin_addr.s_addr || sin.sin_port!=m_Peer.sin_port){
m_Daddy->LogLine(IDS_LOG_XFERSOURCETID);
// *** Bounce it!
}else{
alive = OnTFTP(p);
}
delete p;
if(alive){
DoSelect();
ResetTimeout();
}
}
void CXferSocket::SetPeer(SOCKADDR_IN *sin)
{
ASSERT(sin);
memmove(&m_Peer,sin,sizeof(m_Peer));
}
void CXferSocket::UpdateList()
{
ASSERT(m_Daddy);
LV_FINDINFO lvf;
memset(&lvf,0,sizeof(lvf));
lvf.flags=LVFI_PARAM;
lvf.lParam=(LPARAM)this;
int i = m_Daddy->m_List.FindItem(&lvf);
if(i<0){
ASSERT(IsKindOf(RUNTIME_CLASS(CRRQSocket)) || IsKindOf(RUNTIME_CLASS(CWRQSocket)));
i=m_Daddy->m_List.InsertItem(0,m_FileName,IsKindOf(RUNTIME_CLASS(CRRQSocket))?m_Daddy->m_iRRQ:m_Daddy->m_iWRQ);
ASSERT(!(i<0));
m_Daddy->m_List.SetItemData(i,(DWORD)this);
}
m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemFile,m_FileName);
m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemType,m_Type);
m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemPeer,inet_ntoa(m_Peer.sin_addr));
CString tmp;
tmp.Format(IDS_FMT_BYTES,GetACK());
m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemBytes,tmp);
if(m_xferSize>=0){
tmp.Format(IDS_FMT_BYTES,m_xferSize);
m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemTSize,tmp);
}
}
CXferSocket::CXferSocket()
: m_wndResolver(NULL), m_Retry(NULL), m_bRetry(FALSE),
m_blkSize(512), m_timeOut(30), m_xferSize(-1),
m__blkSize(512), m__timeOut(30)
{
m_Daddy=NULL;
m_Peer.sin_addr.s_addr=INADDR_NONE;
m_Peer.sin_family=AF_INET;
state=stateNone;
}
ULONG CXferSocket::GetACK()
{
return 0;
}
CXferSocket::CXferSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN* sin)
: m_wndResolver(NULL), m_Retry(NULL), m_bRetry(FALSE),
m_blkSize(512), m_timeOut(30), m_xferSize(-1),
m__blkSize(512), m__timeOut(30)
{
m_Peer.sin_family=AF_INET;
state=stateNone;
ASSERT(daddy);
m_Daddy=daddy;
m_timeOut=m__timeOut=m_Daddy->m_TFTPTimeOut.GetTotalSeconds();
if(sin){
m_Peer.sin_addr.s_addr=sin->sin_addr.s_addr;
m_Peer.sin_port=sin->sin_port;
}else
m_Peer.sin_addr.s_addr=INADDR_NONE;
m_FileName=fileName;
m_Type=type;
}
BOOL CRRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName)
{
if(!CAsyncSocket::Create(0,SOCK_DGRAM))
return FALSE;
ASSERT(m_Daddy);
|