[ttssh2-commit] [10401] scp関連を1つのファイルにまとめた

Zurück zum Archiv-Index
scmno****@osdn***** scmno****@osdn*****
2022年 12月 11日 (日) 21:07:47 JST


Revision: 10401
          https://osdn.net/projects/ttssh2/scm/svn/commits/10401
Author:   zmatsuo
Date:     2022-12-11 21:07:47 +0900 (Sun, 11 Dec 2022)
Log Message:
-----------
scp関連を1つのファイルにまとめた

- scp送信APIをscp.cpp,h にまとめた
  - ttxssh.dll へのIF
  - scpへのリクエストはscp.h,cpp 経由で行うよう変更

Modified Paths:
--------------
    trunk/teraterm/teraterm/CMakeLists.txt
    trunk/teraterm/teraterm/ttdde.c
    trunk/teraterm/teraterm/ttermpro.v16.vcxproj
    trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters
    trunk/teraterm/teraterm/ttermpro.v8.vcproj

Added Paths:
-----------
    trunk/teraterm/teraterm/scp.cpp
    trunk/teraterm/teraterm/scp.h

-------------- next part --------------
Modified: trunk/teraterm/teraterm/CMakeLists.txt
===================================================================
--- trunk/teraterm/teraterm/CMakeLists.txt	2022-12-11 12:07:36 UTC (rev 10400)
+++ trunk/teraterm/teraterm/CMakeLists.txt	2022-12-11 12:07:47 UTC (rev 10401)
@@ -48,6 +48,8 @@
   prnabort.h
   protodlg.cpp
   protodlg.h
+  scp.cpp
+  scp.h
   setupdirdlg.cpp
   setupdirdlg.h
   sizetip.c

Added: trunk/teraterm/teraterm/scp.cpp
===================================================================
--- trunk/teraterm/teraterm/scp.cpp	                        (rev 0)
+++ trunk/teraterm/teraterm/scp.cpp	2022-12-11 12:07:47 UTC (rev 10401)
@@ -0,0 +1,128 @@
+/*
+ * (C) 2022- TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ *	TODO
+ *	- unicode(wchar_t) filename
+ *	- init()/uninit() per ssh connect/disconnect
+ */
+
+#include <windows.h>
+
+#include "scp.h"
+
+typedef int (CALLBACK *PSSH_start_scp)(char *, char *);
+typedef int (CALLBACK * PSSH_scp_sending_status)(void);
+
+static HMODULE h = NULL;
+static PSSH_start_scp start_scp = NULL;
+static PSSH_start_scp receive_file = NULL;
+static PSSH_scp_sending_status scp_sending_status = NULL;
+
+/**
+ * @brief SCP\x8A֐\x94\x82̃A\x83h\x83\x8C\x83X\x82\xF0\x8E擾
+ * @retval TRUE ok
+ * @retval FALSE dll\x82\xAA\x82Ȃ\xA2/dll\x82\xAAscp\x91\x97\x90M\x82ɑΉ\x9E\x82\xB5\x82Ă\xA2\x82Ȃ\xA2
+ */
+static BOOL ScpInit(void)
+{
+	if (h == NULL) {
+		if ((h = GetModuleHandle("ttxssh.dll")) == NULL) {
+			return FALSE;
+		}
+	}
+
+	if (start_scp == NULL) {
+		start_scp = (PSSH_start_scp)GetProcAddress(h, "TTXScpSendfile");
+		if (start_scp == NULL) {
+			return FALSE;
+		}
+	}
+	if (scp_sending_status == NULL) {
+		scp_sending_status = (PSSH_scp_sending_status)GetProcAddress(h, "TTXScpSendingStatus");
+		if (scp_sending_status == NULL) {
+			return FALSE;
+		}
+	}
+
+	if (receive_file == NULL) {
+		receive_file = (PSSH_start_scp)GetProcAddress(h, "TTXScpReceivefile");
+		if (receive_file == NULL) {
+			return FALSE;
+		}
+	}
+
+	return TRUE;
+}
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x82𑗐M\x82\xB7\x82\xE9
+ */
+BOOL ScpSend(const char *local, const char *remote)
+{
+	if (start_scp == NULL) {
+		ScpInit();
+	}
+	if (start_scp == NULL) {
+		return FALSE;
+	}
+	BOOL r = (BOOL)start_scp((char*)local, (char*)remote);
+	return r;
+}
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x91\x97\x90M\x8F\xF3\x91\xD4
+ *	@retval	FALSE	\x91\x97\x90M\x82\xB5\x82Ă\xA2\x82Ȃ\xA2
+ *	@retval	TRUE	\x91\x97\x90M\x92\x86
+ */
+BOOL ScpGetStatus(void)
+{
+	if (scp_sending_status == NULL) {
+		ScpInit();
+	}
+	if (scp_sending_status == NULL) {
+		return FALSE;
+	}
+	BOOL r = (BOOL)scp_sending_status();
+	return r;
+}
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x8E\xF3\x90M\x82\xB7\x82\xE9
+ */
+BOOL ScpReceive(const char *remotefile, const char *localfile)
+{
+	if (receive_file == NULL) {
+		ScpInit();
+	}
+	if (receive_file == NULL) {
+		return FALSE;
+	}
+	BOOL r = (BOOL)receive_file((char*)remotefile, (char*)localfile);
+	return r;
+}

Added: trunk/teraterm/teraterm/scp.h
===================================================================
--- trunk/teraterm/teraterm/scp.h	                        (rev 0)
+++ trunk/teraterm/teraterm/scp.h	2022-12-11 12:07:47 UTC (rev 10401)
@@ -0,0 +1,41 @@
+/*
+ * (C) 2022- TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+BOOL ScpSend(const char *local, const char *remote);
+BOOL ScpGetStatus(void);
+BOOL ScpReceive(const char *remotefile, const char *localfile);
+
+#ifdef __cplusplus
+}
+#endif

Modified: trunk/teraterm/teraterm/ttdde.c
===================================================================
--- trunk/teraterm/teraterm/ttdde.c	2022-12-11 12:07:36 UTC (rev 10400)
+++ trunk/teraterm/teraterm/ttdde.c	2022-12-11 12:07:47 UTC (rev 10401)
@@ -45,10 +45,10 @@
 #include "sendmem.h"
 #include "codeconv.h"
 #include "broadcast.h"
-
 #include "filesys.h"
 #include "sendmem.h"
 #include "codeconv.h"
+#include "scp.h"
 
 #define ServiceName "TERATERM"
 #define ItemName "DATA"
@@ -772,64 +772,22 @@
 
 	case CmdScpSend:  // add 'scpsend' (2008.1.1 yutaka)
 		{
-		typedef int (CALLBACK *PSSH_start_scp)(char *, char *);
-		static PSSH_start_scp func = NULL;
-		static HMODULE h = NULL;
-		char msg[128];
-
-		if (func == NULL) {
-			if ( ((h = GetModuleHandle("ttxssh.dll")) == NULL) ) {
-				_snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetModuleHandle(\"ttxssh.dll\")) %d", GetLastError());
-				goto scp_send_error;
+			if (ScpSend(ParamFileName, ParamSecondFileName) == FALSE) {
+				const char *msg = "ttxssh.dll not support scp";
+				MessageBox(NULL, msg, "Tera Term: scprecv command error", MB_OK | MB_ICONERROR);
+				return DDE_FNOTPROCESSED;
 			}
-			func = (PSSH_start_scp)GetProcAddress(h, "TTXScpSendfile");
-			if (func == NULL) {
-				_snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetProcAddress(\"TTXScpSendfile\")) %d", GetLastError());
-				goto scp_send_error;
-			}
 		}
-
-		if (func != NULL) {
-			// DdeCmnd = TRUE;
-			func(ParamFileName, ParamSecondFileName);
-			break;
-		}
-
-scp_send_error:
-		MessageBox(NULL, msg, "Tera Term: scpsend command error", MB_OK | MB_ICONERROR);
-		return DDE_FNOTPROCESSED;
-		}
 		break;
 
 	case CmdScpRcv:
 		{
-		typedef int (CALLBACK *PSSH_start_scp)(char *, char *);
-		static PSSH_start_scp func = NULL;
-		static HMODULE h = NULL;
-		char msg[128];
-
-		if (func == NULL) {
-			if ( ((h = GetModuleHandle("ttxssh.dll")) == NULL) ) {
-				_snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetModuleHandle(\"ttxssh.dll\")) %d", GetLastError());
-				goto scp_rcv_error;
+			if (ScpReceive(ParamFileName, ParamSecondFileName) == FALSE) {
+				const char *msg = "ttxssh.dll not support scp";
+				MessageBox(NULL, msg, "Tera Term: scpsend command error", MB_OK | MB_ICONERROR);
+				return DDE_FNOTPROCESSED;
 			}
-			func = (PSSH_start_scp)GetProcAddress(h, "TTXScpReceivefile");
-			if (func == NULL) {
-				_snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetProcAddress(\"TTXScpReceivefile\")) %d", GetLastError());
-				goto scp_rcv_error;
-			}
 		}
-
-		if (func != NULL) {
-			// DdeCmnd = TRUE;
-			func(ParamFileName, ParamSecondFileName);
-			break;
-		}
-
-scp_rcv_error:
-		MessageBox(NULL, msg, "Tera Term: scpsend command error", MB_OK | MB_ICONERROR);
-		return DDE_FNOTPROCESSED;
-		}
 		break;
 
 	case CmdSetBaud:  // add 'setbaud' (2008.2.13 steven patch)

Modified: trunk/teraterm/teraterm/ttermpro.v16.vcxproj
===================================================================
--- trunk/teraterm/teraterm/ttermpro.v16.vcxproj	2022-12-11 12:07:36 UTC (rev 10400)
+++ trunk/teraterm/teraterm/ttermpro.v16.vcxproj	2022-12-11 12:07:47 UTC (rev 10401)
@@ -171,6 +171,7 @@
     <ClCompile Include="font_pp.cpp" />
     <ClCompile Include="ftdlg.cpp" />
     <ClCompile Include="keyboard.c" />
+    <ClCompile Include="scp.cpp" />
     <ClCompile Include="sendfiledlg.cpp" />
     <ClCompile Include="setupdirdlg.cpp" />
     <ClCompile Include="sizetip.c" />
@@ -225,6 +226,7 @@
     <ClInclude Include="filesys_log_res.h" />
     <ClInclude Include="font_pp.h" />
     <ClInclude Include="font_pp_res.h" />
+    <ClInclude Include="scp.h" />
     <ClInclude Include="sendfiledlg.h" />
     <ClInclude Include="sendmem.h" />
     <ClCompile Include="sendmem.cpp" />

Modified: trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters
===================================================================
--- trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters	2022-12-11 12:07:36 UTC (rev 10400)
+++ trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters	2022-12-11 12:07:47 UTC (rev 10401)
@@ -222,6 +222,9 @@
     <ClCompile Include="themefile.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="scp.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Image Include="..\..\cygterm\cygterm.ico">
@@ -510,5 +513,8 @@
     <ClInclude Include="theme.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="scp.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>
\ No newline at end of file

Modified: trunk/teraterm/teraterm/ttermpro.v8.vcproj
===================================================================
--- trunk/teraterm/teraterm/ttermpro.v8.vcproj	2022-12-11 12:07:36 UTC (rev 10400)
+++ trunk/teraterm/teraterm/ttermpro.v8.vcproj	2022-12-11 12:07:47 UTC (rev 10401)
@@ -237,6 +237,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\scp.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\sendfiledlg.cpp"
 				>
 			</File>
@@ -451,6 +455,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\scp.h"
+				>
+			</File>
+			<File
 				RelativePath=".\sendfiledlg.h"
 				>
 			</File>


ttssh2-commit メーリングリストの案内
Zurück zum Archiv-Index