[Ttssh2-commit] [3821] YMODEM プロトコル

svnno****@sourc***** svnno****@sourc*****
2010年 3月 25日 (木) 19:02:45 JST


Revision: 3821
          http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=3821
Author:   yutakapon
Date:     2010-03-25 19:02:44 +0900 (Thu, 25 Mar 2010)

Log Message:
-----------
YMODEM プロトコル
 ・複数ファイル受信に対応した
 ・受信ファイルの末尾に、余分な EOF(0x1A) が付加されていた場合、除去するようにした。

Modified Paths:
--------------
    trunk/teraterm/teraterm/filesys.cpp
    trunk/teraterm/ttpfile/ymodem.c


-------------- next part --------------
Modified: trunk/teraterm/teraterm/filesys.cpp
===================================================================
--- trunk/teraterm/teraterm/filesys.cpp	2010-03-24 05:32:01 UTC (rev 3820)
+++ trunk/teraterm/teraterm/filesys.cpp	2010-03-25 10:02:44 UTC (rev 3821)
@@ -1317,6 +1317,7 @@
 		FileVar->OpId = OpYRcv;
 		// ƒtƒ@ƒCƒ‹“]‘—Žž‚̃IƒvƒVƒ‡ƒ“‚Í"Yopt1K"‚ÉŒˆ‚ß‘Å‚¿B
 		Opt = Yopt1K;
+		(*SetFileVar)(FileVar);
 	}
 
 	TalkStatus = IdTalkQuiet;

Modified: trunk/teraterm/ttpfile/ymodem.c
===================================================================
--- trunk/teraterm/ttpfile/ymodem.c	2010-03-24 05:32:01 UTC (rev 3820)
+++ trunk/teraterm/ttpfile/ymodem.c	2010-03-25 10:02:44 UTC (rev 3821)
@@ -281,10 +281,11 @@
 
 	case IdYReceive:
 #if 0   // for debug
-		strcpy(inistr, "sb teraterm2.ini\r\n");
-//		strcpy(inistr, "sb foo.txt\r\n");
+		strcpy(inistr, "sb -b svnrev.exe lrzsz-0.12.20.tar.gz\r\n");
+//		strcpy(inistr, "sb url3.txt url4.txt url5.txt\r\n");
 		YWrite(fv,yv,cv, inistr , strlen(inistr));
 #endif
+		yv->TextFlag = 0;
 
 		YSendNAK(fv,yv,cv);
 
@@ -325,7 +326,7 @@
 BOOL YReadPacket(PFileVar fv, PYVar yv, PComVar cv)
 {
 	BYTE b, d;
-	int i, c;
+	int i, c, nak;
 	BOOL GetPkt;
 
 	c = YRead1Byte(fv,yv,cv,&b);
@@ -353,16 +354,23 @@
 			  }
 			  else if (b==EOT)
 			  {
+				  // EOT‚ª—ˆ‚½‚çA1‚‚̃tƒ@ƒCƒ‹ŽóM‚ªŠ®—¹‚µ‚½‚±‚Æ‚ðŽ¦‚·B
 				  if (fv->FileOpen) {
 					  fv->FileOpen = 0;
 					  _lclose(fv->FileHandle);
 					  fv->FileHandle = -1;
 				  }
 
+				  initialize_file_info(fv, yv);
+
+				  // EOT‚ɑ΂µ‚ÄACK‚ð•Ô‚·
 				  b = ACK;
-				  fv->Success = TRUE;
 				  YWrite(fv,yv,cv,&b, 1);
-				  return FALSE;
+
+				  // ŽŸ‚̃tƒ@ƒCƒ‹‘—M‚𑣂·‚½‚߁A'C'‚ð‘—‚éB
+		  		  YSendNAK(fv,yv,cv);
+
+				  return TRUE;
 			  }
 			  else {
 				  /* flush comm buffer */
@@ -377,8 +385,17 @@
 			  FTSetTimeOut(fv,yv->TOutShort);
 			  break;
 		  case XpktBLK2:
+			  nak = 1;
 			  yv->PktIn[2] = b;
-			  if ((b ^ yv->PktIn[1]) == 0xff)
+			  if ((b ^ yv->PktIn[1]) == 0xff) {
+				  nak = 0;
+				  if (yv->SendFileInfo) {
+					  if (yv->PktIn[1] == (BYTE)(yv->PktNum + 1))  // ŽŸ‚̃uƒƒbƒN”ԍ†‚©
+						  nak = 0;
+				  }
+			  }
+
+			  if (nak == 0)
 			  {
 				  yv->PktBufPtr = 3;
 				  yv->PktBufCount = yv->DataLen + yv->CheckLen;
@@ -408,19 +425,6 @@
 
 	if (! GetPkt) return TRUE;
 
-#if 0
-	if ((yv->PktIn[1]==0) && (yv->PktNum==0) &&
-		(yv->PktNumOffset==0))
-	{
-		if (yv->NAKMode!=YnakC)
-			yv->NAKCount = 10;
-		else
-			yv->NAKCount = 3;
-		YSendNAK(fv,yv,cv);
-		return TRUE;
-	}
-#endif
-
 	GetPkt = YCheckPacket(yv);
 	if (! GetPkt)
 	{
@@ -428,6 +432,21 @@
 		return TRUE;
 	}
 
+	// ƒI[ƒ‹ƒ[ƒ‚È‚ç‚΁A‘Sƒtƒ@ƒCƒ‹ŽóM‚ÌŠ®—¹‚ðŽ¦‚·B
+	if (yv->PktIn[1] == 0x00 && yv->PktIn[2] == 0xFF &&
+		yv->SendFileInfo == 0
+		) {
+		c = yv->DataLen;
+		while ((c>0) && (yv->PktIn[2+c]==0x00))
+			c--;
+		if (c == 0) {
+		  b = ACK;
+		  YWrite(fv,yv,cv,&b, 1);
+		  fv->Success = TRUE;
+		  return FALSE;
+		}
+	}
+
 	d = yv->PktIn[1] - yv->PktNum;
 	if (d>1)
 	{
@@ -441,8 +460,17 @@
 	yv->NAKMode = YnakC;
 	yv->NAKCount = 10;
 
+	// d•¡‚µ‚Ä‚¢‚éê‡‚́A‰½‚à‚µ‚È‚¢B
+	if (yv->SendFileInfo &&
+		yv->PktIn[1] == (BYTE)(yv->PktNum)) { 
+		return TRUE;
+	}
+
+	yv->PktNum = yv->PktIn[1];
+
 	// YMODEM‚̏ꍇAblock#0‚ªuƒtƒ@ƒCƒ‹î•ñv‚Æ‚È‚éB
-	if (d == 0) {
+	if (d == 0 &&
+		yv->SendFileInfo == 0) {
 		long modtime;
         long bytes_total;
 		int mode;
@@ -466,10 +494,11 @@
 		fv->DirLen = 0;
 		SetDlgItemText(fv->HWin, IDC_PROTOFNAME, &(fv->FullName[fv->DirLen]));
 
+		yv->SendFileInfo = 1;
+
 		return TRUE;
 	}
 
-	yv->PktNum = yv->PktIn[1];
 	if (yv->PktNum==0)
 		yv->PktNumOffset = yv->PktNumOffset + 256;
 
@@ -478,6 +507,11 @@
 		while ((c>0) && (yv->PktIn[2+c]==0x1A))
 			c--;
 
+	// ÅIƒuƒƒbƒN‚Ì—]•ª‚ȃf[ƒ^‚ðœ‹Ž‚·‚é
+	if (fv->ByteCount + c > fv->FileSize) {
+		c = fv->FileSize - fv->ByteCount;
+	}
+
 	if (yv->TextFlag>0)
 		for (i = 0 ; i <= c-1 ; i++)
 		{



Ttssh2-commit メーリングリストの案内