-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 | |||
@@ -733,96 +733,101 @@ CFileException e; | |||
733 | return FALSE; | 733 | return FALSE; |
734 | } | 734 | } |
735 | Deny(&e); | 735 | Deny(&e); |
736 | return TRUE; | 736 | return TRUE; |
737 | } | 737 | } |
738 | m_xferSize=m_File.GetLength();// *** HANDLE EXCEPTION | 738 | m_xferSize=m_File.GetLength();// *** HANDLE EXCEPTION |
739 | if(hostName){ | 739 | if(hostName){ |
740 | m_HostName=hostName; | 740 | m_HostName=hostName; |
741 | 741 | ||
742 | CString tmp; | 742 | CString tmp; |
743 | tmp.Format(IDS_LOG_SENDING,m_FileName,m_HostName); | 743 | tmp.Format(IDS_LOG_SENDING,m_FileName,m_HostName); |
744 | m_Daddy->LogLine(tmp); | 744 | m_Daddy->LogLine(tmp); |
745 | 745 | ||
746 | CString inAddr = hostName; | 746 | CString inAddr = hostName; |
747 | int at = inAddr.Find('@'); | 747 | int at = inAddr.Find('@'); |
748 | if(at>=0) | 748 | if(at>=0) |
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; |
813 | return rv; | 818 | return rv; |
814 | } | 819 | } |
815 | 820 | ||
816 | void tftp::errSet(UINT code,LPCTSTR msg) | 821 | void tftp::errSet(UINT code,LPCTSTR msg) |
817 | { | 822 | { |
818 | ASSERT(this); | 823 | ASSERT(this); |
819 | ASSERT(length>=data.m_ERROR.tftpSize(msg)); | 824 | ASSERT(length>=data.m_ERROR.tftpSize(msg)); |
820 | strcpy((char*)data.m_ERROR.data,msg); | 825 | strcpy((char*)data.m_ERROR.data,msg); |
821 | data.m_ERROR.SetCode(code); | 826 | data.m_ERROR.SetCode(code); |
822 | } | 827 | } |
823 | 828 | ||
824 | void CXferSocket::PostTFTP(tftp* p,BOOL retryable) | 829 | void CXferSocket::PostTFTP(tftp* p,BOOL retryable) |
825 | { | 830 | { |
826 | ASSERT(p); | 831 | ASSERT(p); |
827 | m_Queue.AddTail(p); | 832 | m_Queue.AddTail(p); |
828 | DoSelect(); | 833 | DoSelect(); |
@@ -833,101 +838,99 @@ void CXferSocket::PostTFTP(tftp* p,BOOL retryable) | |||
833 | SetTry(); | 838 | SetTry(); |
834 | } | 839 | } |
835 | ResetTimeout(); | 840 | ResetTimeout(); |
836 | } | 841 | } |
837 | 842 | ||
838 | void CXferSocket::Deny(UINT errCode,UINT errID) | 843 | void CXferSocket::Deny(UINT errCode,UINT errID) |
839 | { | 844 | { |
840 | PostError(errCode,errID); | 845 | PostError(errCode,errID); |
841 | state=stateDeny; | 846 | state=stateDeny; |
842 | } | 847 | } |
843 | 848 | ||
844 | void CRRQSocket::DoXfer() | 849 | void CRRQSocket::DoXfer() |
845 | { | 850 | { |
846 | tftp *p = tftp::Allocate(tftp::tftpDATA::tftpSize(m_blkSize)); | 851 | tftp *p = tftp::Allocate(tftp::tftpDATA::tftpSize(m_blkSize)); |
847 | ASSERT(p); | 852 | ASSERT(p); |
848 | p->SetOpcode(tftp::opDATA); | 853 | p->SetOpcode(tftp::opDATA); |
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: |
918 | eCode=tftp::errUndefined; | 921 | eCode=tftp::errUndefined; |
919 | eMsgID=IDS_TFTP_ERROR_UNDEFINED; | 922 | eMsgID=IDS_TFTP_ERROR_UNDEFINED; |
920 | break; | 923 | break; |
921 | } | 924 | } |
922 | PostError(eCode,eMsgID); | 925 | PostError(eCode,eMsgID); |
923 | } | 926 | } |
924 | 927 | ||
925 | ULONG CRRQSocket::GetACK(void) | 928 | ULONG CRRQSocket::GetACK(void) |
926 | { | 929 | { |
927 | return (m_ACK*m_blkSize)-m_LastSlack; | 930 | return (m_ACK*m_blkSize)-m_LastSlack; |
928 | } | 931 | } |
929 | 932 | ||
930 | BOOL CRRQSocket::OnTFTP(tftp* p) | 933 | BOOL CRRQSocket::OnTFTP(tftp* p) |
931 | { | 934 | { |
932 | BOOL rv = TRUE; | 935 | BOOL rv = TRUE; |
933 | switch(p->Opcode()){ | 936 | switch(p->Opcode()){ |