-rw-r--r-- | PumpKINDlg.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/PumpKINDlg.cpp b/PumpKINDlg.cpp index 2a01918..bb15211 100644 --- a/PumpKINDlg.cpp +++ b/PumpKINDlg.cpp | |||
@@ -749,64 +749,69 @@ CFileException e; | |||
749 | inAddr=inAddr.Mid(at+1); | 749 | inAddr=inAddr.Mid(at+1); |
750 | if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){ | 750 | if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){ |
751 | ASSERT(!m_wndResolver); | 751 | ASSERT(!m_wndResolver); |
752 | m_wndResolver = new CResolver(this); | 752 | m_wndResolver = new CResolver(this); |
753 | ASSERT(m_wndResolver); | 753 | ASSERT(m_wndResolver); |
754 | return m_wndResolver->Resolve(); | 754 | return m_wndResolver->Resolve(); |
755 | } | 755 | } |
756 | else | 756 | else |
757 | OnHostKnown(); | 757 | OnHostKnown(); |
758 | }else{ | 758 | }else{ |
759 | tftp::tftpOptions o; | 759 | tftp::tftpOptions o; |
760 | CString v; | 760 | CString v; |
761 | if(m_Options.Lookup(tftpoBSize,v)){ | 761 | if(m_Options.Lookup(tftpoBSize,v)){ |
762 | m__blkSize=atoi(v); | 762 | m__blkSize=atoi(v); |
763 | if(m__blkSize){ | 763 | if(m__blkSize){ |
764 | m_blkSize=m__blkSize; | 764 | m_blkSize=m__blkSize; |
765 | v.Format("%u",m_blkSize); | 765 | v.Format("%u",m_blkSize); |
766 | o[tftpoBSize]=v; | 766 | o[tftpoBSize]=v; |
767 | } | 767 | } |
768 | } | 768 | } |
769 | if(m_Options.Lookup(tftpoTSize,v)){ | 769 | if(m_Options.Lookup(tftpoTSize,v)){ |
770 | v.Format("%lu",m_xferSize); | 770 | v.Format("%lu",m_xferSize); |
771 | o[tftpoTSize]=v; | 771 | o[tftpoTSize]=v; |
772 | } | 772 | } |
773 | if(m_Options.Lookup(tftpoTOut,v)){ | 773 | if(m_Options.Lookup(tftpoTOut,v)){ |
774 | m__timeOut=atoi(v); | 774 | m__timeOut=atoi(v); |
775 | if(m__timeOut){ | 775 | if(m__timeOut){ |
776 | m_timeOut=m__timeOut; | 776 | m_timeOut=m__timeOut; |
777 | v.Format("%u",m_timeOut); | 777 | v.Format("%u",m_timeOut); |
778 | o[tftpoTOut]=v; | 778 | o[tftpoTOut]=v; |
779 | } | 779 | } |
780 | } | 780 | } |
781 | // XXX: see if we can enforce our preference regarding block size here. | ||
782 | if(m_xferSize >= (m_blkSize<<16)) { | ||
783 | Deny(tftp::errUndefined,IDS_TFTP_ERROR_TOOBIG); | ||
784 | return TRUE; | ||
785 | } | ||
781 | state = stateXfer; | 786 | state = stateXfer; |
782 | m_ACK=0; | 787 | m_ACK=0; |
783 | if(o.GetCount()){ | 788 | if(o.GetCount()){ |
784 | tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&o)); | 789 | tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&o)); |
785 | ASSERT(p); | 790 | ASSERT(p); |
786 | p->SetOpcode(tftp::opOACK); | 791 | p->SetOpcode(tftp::opOACK); |
787 | p->data.m_OACK.Set(&o); | 792 | p->data.m_OACK.Set(&o); |
788 | PostTFTP(p,TRUE); | 793 | PostTFTP(p,TRUE); |
789 | }else | 794 | }else |
790 | DoXfer(); | 795 | DoXfer(); |
791 | } | 796 | } |
792 | return TRUE; | 797 | return TRUE; |
793 | } | 798 | } |
794 | 799 | ||
795 | CRRQSocket::CRRQSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin) | 800 | CRRQSocket::CRRQSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin) |
796 | : CXferSocket(daddy,fileName,type,sin) | 801 | : CXferSocket(daddy,fileName,type,sin) |
797 | { | 802 | { |
798 | m_ACK=0; | 803 | m_ACK=0; |
799 | m_LastSlack=0; | 804 | m_LastSlack=0; |
800 | } | 805 | } |
801 | 806 | ||
802 | UINT tftp::tftpERROR::tftpSize(LPCTSTR msg) | 807 | UINT tftp::tftpERROR::tftpSize(LPCTSTR msg) |
803 | { | 808 | { |
804 | return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpERROR::tftpErrorCode)+strlen(msg)+1; | 809 | return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpERROR::tftpErrorCode)+strlen(msg)+1; |
805 | } | 810 | } |
806 | 811 | ||
807 | tftp* tftp::Allocate(UINT tftpSize) | 812 | tftp* tftp::Allocate(UINT tftpSize) |
808 | { | 813 | { |
809 | ASSERT(tftpSize); | 814 | ASSERT(tftpSize); |
810 | tftp* rv = (tftp*) new BYTE[tftpSlackSize+tftpSize]; | 815 | tftp* rv = (tftp*) new BYTE[tftpSlackSize+tftpSize]; |
811 | ASSERT(rv); | 816 | ASSERT(rv); |
812 | rv->length=tftpSize; | 817 | rv->length=tftpSize; |
@@ -849,69 +854,67 @@ tftp *p = tftp::Allocate(tftp::tftpDATA::tftpSize(m_blkSize)); | |||
849 | TRY{ | 854 | TRY{ |
850 | m_File.Seek(m_ACK*m_blkSize,CFile::begin); | 855 | m_File.Seek(m_ACK*m_blkSize,CFile::begin); |
851 | int bytes = m_File.Read(p->data.m_DATA.data,m_blkSize); | 856 | int bytes = m_File.Read(p->data.m_DATA.data,m_blkSize); |
852 | p->data.m_DATA.SetBlock(m_ACK+1); | 857 | p->data.m_DATA.SetBlock(m_ACK+1); |
853 | p->length=p->length-m_blkSize+bytes; | 858 | p->length=p->length-m_blkSize+bytes; |
854 | m_LastSlack = m_blkSize-bytes; | 859 | m_LastSlack = m_blkSize-bytes; |
855 | PostTFTP(p); | 860 | PostTFTP(p); |
856 | if(bytes<m_blkSize){ | 861 | if(bytes<m_blkSize){ |
857 | state=stateClosing; m_ACKtoClose = m_ACK+1; | 862 | state=stateClosing; m_ACKtoClose = m_ACK+1; |
858 | } | 863 | } |
859 | }CATCH(CFileException,e){ | 864 | }CATCH(CFileException,e){ |
860 | Deny(e); | 865 | Deny(e); |
861 | }END_CATCH | 866 | }END_CATCH |
862 | } | 867 | } |
863 | 868 | ||
864 | UINT tftp::tftpDATA::tftpSize(UINT blkSize) | 869 | UINT tftp::tftpDATA::tftpSize(UINT blkSize) |
865 | { | 870 | { |
866 | return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpDATA) | 871 | return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpDATA) |
867 | -sizeof(BYTE)+blkSize; | 872 | -sizeof(BYTE)+blkSize; |
868 | } | 873 | } |
869 | 874 | ||
870 | void CXferSocket::Deny(CFileException* e) | 875 | void CXferSocket::Deny(CFileException* e) |
871 | { | 876 | { |
872 | PostError(e); | 877 | PostError(e); |
873 | state=stateDeny; | 878 | state=stateDeny; |
874 | } | 879 | } |
875 | 880 | ||
876 | void CXferSocket::PostError(UINT errCode,UINT errID) | 881 | void CXferSocket::PostError(UINT errCode,UINT errID) |
877 | { | 882 | { |
878 | CString msg; | 883 | CString msg; |
879 | msg.LoadString(errID); | 884 | msg.LoadString(errID); |
880 | ASSERT(m_Daddy); | 885 | ASSERT(m_Daddy); |
881 | /*// *** | ||
882 | CString tmp; | 886 | CString tmp; |
883 | tmp.Format(IDS_LOG_SENTTFTPERROR,errCode,(LPCTSTR)msg); | 887 | tmp.Format(IDS_LOG_SENTTFTPERROR,errCode,(LPCTSTR)msg); |
884 | m_Daddy->LogLine(tmp); | 888 | m_Daddy->LogLine(tmp); |
885 | */ | ||
886 | tftp* err = tftp::Allocate(tftp::tftpERROR::tftpSize(msg)); | 889 | tftp* err = tftp::Allocate(tftp::tftpERROR::tftpSize(msg)); |
887 | err->SetOpcode(tftp::opERROR); | 890 | err->SetOpcode(tftp::opERROR); |
888 | err->errSet(errCode,msg); | 891 | err->errSet(errCode,msg); |
889 | PostTFTP(err); | 892 | PostTFTP(err); |
890 | } | 893 | } |
891 | 894 | ||
892 | void CXferSocket::PostError(CFileException* e) | 895 | void CXferSocket::PostError(CFileException* e) |
893 | { | 896 | { |
894 | UINT eCode; | 897 | UINT eCode; |
895 | UINT eMsgID; | 898 | UINT eMsgID; |
896 | switch(e->m_cause){ | 899 | switch(e->m_cause){ |
897 | case CFileException::fileNotFound: | 900 | case CFileException::fileNotFound: |
898 | eCode=tftp::errNotFound; | 901 | eCode=tftp::errNotFound; |
899 | eMsgID=IDS_TFTP_ERROR_NOTFOUND; | 902 | eMsgID=IDS_TFTP_ERROR_NOTFOUND; |
900 | break; | 903 | break; |
901 | case CFileException::accessDenied: | 904 | case CFileException::accessDenied: |
902 | eCode=tftp::errAccessViolation; | 905 | eCode=tftp::errAccessViolation; |
903 | eMsgID=IDS_TFTP_ERROR_ACCESS; | 906 | eMsgID=IDS_TFTP_ERROR_ACCESS; |
904 | break; | 907 | break; |
905 | case CFileException::directoryFull: | 908 | case CFileException::directoryFull: |
906 | eCode=tftp::errDiskFull; | 909 | eCode=tftp::errDiskFull; |
907 | eMsgID=IDS_TFTP_ERROR_DIRFULL; | 910 | eMsgID=IDS_TFTP_ERROR_DIRFULL; |
908 | break; | 911 | break; |
909 | case CFileException::sharingViolation: | 912 | case CFileException::sharingViolation: |
910 | eCode=tftp::errAccessViolation; | 913 | eCode=tftp::errAccessViolation; |
911 | eMsgID=IDS_TFTP_ERROR_SHARING; | 914 | eMsgID=IDS_TFTP_ERROR_SHARING; |
912 | break; | 915 | break; |
913 | case CFileException::diskFull: | 916 | case CFileException::diskFull: |
914 | eCode=tftp::errDiskFull; | 917 | eCode=tftp::errDiskFull; |
915 | eMsgID=IDS_TFTP_ERROR_DISKFULL; | 918 | eMsgID=IDS_TFTP_ERROR_DISKFULL; |
916 | break; | 919 | break; |
917 | default: | 920 | default: |