[ttssh2-commit] [10467] ssh_known_hosts のフルパスの取得API追加

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2023年 1月 10日 (火) 22:17:44 JST


Revision: 10467
          https://osdn.net/projects/ttssh2/scm/svn/commits/10467
Author:   zmatsuo
Date:     2023-01-10 22:17:43 +0900 (Tue, 10 Jan 2023)
Log Message:
-----------
ssh_known_hosts のフルパスの取得API追加

- TTXSSHGetKnownHostsFileName()
- scp.cpp,h に ttxssh.dll への追加インターフェイスをまとめた形になった
  - ttxif.cpp,h 等のほうが妥当か

Modified Paths:
--------------
    trunk/teraterm/teraterm/scp.cpp
    trunk/teraterm/teraterm/scp.h
    trunk/teraterm/teraterm/setupdirdlg.cpp

-------------- next part --------------
Modified: trunk/teraterm/teraterm/scp.cpp
===================================================================
--- trunk/teraterm/teraterm/scp.cpp	2023-01-10 00:18:17 UTC (rev 10466)
+++ trunk/teraterm/teraterm/scp.cpp	2023-01-10 13:17:43 UTC (rev 10467)
@@ -27,11 +27,17 @@
  */
 
 /*
+ *	ttxssh.dll \x82ւ̃C\x83\x93\x83^\x81[\x83t\x83F\x83C\x83X
+ *	- ttssh2/ttxssh/ttxssh.def \x8EQ\x8F\xC6
+ *
  *	TODO
  *	- unicode(wchar_t) filename
  *	- init()/uninit() per ssh connect/disconnect
  */
 
+#define _CRTDBG_MAP_ALLOC
+#include <stdlib.h>
+#include <crtdbg.h>
 #include <windows.h>
 
 #include "scp.h"
@@ -38,11 +44,13 @@
 
 typedef int (CALLBACK *PSSH_start_scp)(char *, char *);
 typedef int (CALLBACK * PSSH_scp_sending_status)(void);
+typedef size_t (CALLBACK *PSSH_GetKnownHostsFileName)(wchar_t *, size_t);
 
 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;
+static PSSH_GetKnownHostsFileName GetKnownHostsFileName;
 
 /**
  * @brief SCP\x8A֐\x94\x82̃A\x83h\x83\x8C\x83X\x82\xF0\x8E擾
@@ -77,6 +85,13 @@
 		}
 	}
 
+	if (GetKnownHostsFileName == NULL) {
+		GetKnownHostsFileName = (PSSH_GetKnownHostsFileName)GetProcAddress(h, "TTXReadKnownHostsFile");
+		if (GetKnownHostsFileName == NULL) {
+			return FALSE;
+		}
+	}
+
 	return TRUE;
 }
 
@@ -126,3 +141,33 @@
 	BOOL r = (BOOL)receive_file((char*)remotefile, (char*)localfile);
 	return r;
 }
+
+/**
+ *	knownhost\x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x8E擾
+ *	\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7free()\x82\xB7\x82邱\x82\xC6
+ */
+BOOL TTXSSHGetKnownHostsFileName(wchar_t **filename)
+{
+	if (GetKnownHostsFileName == NULL) {
+		ScpInit();
+	}
+	if (GetKnownHostsFileName == NULL) {
+		*filename = NULL;
+		return FALSE;
+	}
+
+	size_t size = GetKnownHostsFileName(NULL, 0);
+	if (size == 0) {
+		*filename = NULL;
+		return FALSE;
+	}
+	wchar_t *f = (wchar_t *)malloc(sizeof(wchar_t) * size);
+	if (f == NULL) {
+		*filename = NULL;
+		return FALSE;
+	}
+	GetKnownHostsFileName(f, size);
+
+	*filename = f;
+	return TRUE;
+}

Modified: trunk/teraterm/teraterm/scp.h
===================================================================
--- trunk/teraterm/teraterm/scp.h	2023-01-10 00:18:17 UTC (rev 10466)
+++ trunk/teraterm/teraterm/scp.h	2023-01-10 13:17:43 UTC (rev 10467)
@@ -35,6 +35,7 @@
 BOOL ScpSend(const char *local, const char *remote);
 BOOL ScpGetStatus(void);
 BOOL ScpReceive(const char *remotefile, const char *localfile);
+BOOL TTXSSHGetKnownHostsFileName(wchar_t **filename);
 
 #ifdef __cplusplus
 }

Modified: trunk/teraterm/teraterm/setupdirdlg.cpp
===================================================================
--- trunk/teraterm/teraterm/setupdirdlg.cpp	2023-01-10 00:18:17 UTC (rev 10466)
+++ trunk/teraterm/teraterm/setupdirdlg.cpp	2023-01-10 13:17:43 UTC (rev 10467)
@@ -57,6 +57,7 @@
 #include "helpid.h"
 #include "win32helper.h"
 #include "tipwin2.h"
+#include "scp.h"
 
 #include "setupdirdlg.h"
 
@@ -396,31 +397,17 @@
 
 static wchar_t *GetTTXSSHKwnownHostFile(const SetupList *list, const TTTSet *)
 {
-	HMODULE h = GetModuleHandle("ttxssh.dll");
-	if (h == NULL) {
+	wchar_t *filename;
+	BOOL r = TTXSSHGetKnownHostsFileName(&filename);
+	if (!r) {
 		return NULL;
 	}
+	assert(!IsRelativePathW(filename));
 
-	size_t (CALLBACK *func)(wchar_t *, size_t) = NULL;
-	void **pfunc = (void **)&func;
-	*pfunc = (void *)GetProcAddress(h, "TTXReadKnownHostsFile");
-	if (func == NULL) {
-		return NULL;
-	}
-
-	size_t size = func(NULL, 0);
-	if (size == 0) {
-		return NULL;
-	}
-
-	wchar_t *temp = (wchar_t *)malloc(sizeof(wchar_t) * size);
-	func(temp, size);
-	assert(!IsRelativePathW(temp));
-
 	if (list->data_ptr != 0) {
 		wchar_t *virtual_store_path;
-		BOOL ret = convertVirtualStoreW(temp, &virtual_store_path);
-		free(temp);
+		BOOL ret = convertVirtualStoreW(filename, &virtual_store_path);
+		free(filename);
 		if (ret) {
 			return virtual_store_path;
 		} else {
@@ -428,7 +415,7 @@
 		}
 	}
 
-	return temp;
+	return filename;
 }
 
 /**


ttssh2-commit メーリングリストの案内
Back to archive index