Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/scp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10467 - (hide annotations) (download) (as text)
Tue Jan 10 13:17:43 2023 UTC (15 months ago) by zmatsuo
File MIME type: text/x-c++src
File size: 4588 byte(s)
ssh_known_hosts のフルパスの取得API追加

- TTXSSHGetKnownHostsFileName()
- scp.cpp,h に ttxssh.dll への追加インターフェイスをまとめた形になった
  - ttxif.cpp,h 等のほうが妥当か
1 zmatsuo 10401 /*
2     * (C) 2022- TeraTerm Project
3     * All rights reserved.
4     *
5     * Redistribution and use in source and binary forms, with or without
6     * modification, are permitted provided that the following conditions
7     * are met:
8     *
9     * 1. Redistributions of source code must retain the above copyright
10     * notice, this list of conditions and the following disclaimer.
11     * 2. Redistributions in binary form must reproduce the above copyright
12     * notice, this list of conditions and the following disclaimer in the
13     * documentation and/or other materials provided with the distribution.
14     * 3. The name of the author may not be used to endorse or promote products
15     * derived from this software without specific prior written permission.
16     *
17     * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27     */
28    
29     /*
30 zmatsuo 10467 * ttxssh.dll �����C���^�[�t�F�C�X
31     * - ttssh2/ttxssh/ttxssh.def �Q��
32     *
33 zmatsuo 10401 * TODO
34     * - unicode(wchar_t) filename
35     * - init()/uninit() per ssh connect/disconnect
36     */
37    
38 zmatsuo 10467 #define _CRTDBG_MAP_ALLOC
39     #include <stdlib.h>
40     #include <crtdbg.h>
41 zmatsuo 10401 #include <windows.h>
42    
43     #include "scp.h"
44    
45     typedef int (CALLBACK *PSSH_start_scp)(char *, char *);
46     typedef int (CALLBACK * PSSH_scp_sending_status)(void);
47 zmatsuo 10467 typedef size_t (CALLBACK *PSSH_GetKnownHostsFileName)(wchar_t *, size_t);
48 zmatsuo 10401
49     static HMODULE h = NULL;
50     static PSSH_start_scp start_scp = NULL;
51     static PSSH_start_scp receive_file = NULL;
52     static PSSH_scp_sending_status scp_sending_status = NULL;
53 zmatsuo 10467 static PSSH_GetKnownHostsFileName GetKnownHostsFileName;
54 zmatsuo 10401
55     /**
56     * @brief SCP�������A�h���X������
57     * @retval TRUE ok
58     * @retval FALSE dll������/dll��scp���M����������������
59     */
60     static BOOL ScpInit(void)
61     {
62     if (h == NULL) {
63     if ((h = GetModuleHandle("ttxssh.dll")) == NULL) {
64     return FALSE;
65     }
66     }
67    
68     if (start_scp == NULL) {
69     start_scp = (PSSH_start_scp)GetProcAddress(h, "TTXScpSendfile");
70     if (start_scp == NULL) {
71     return FALSE;
72     }
73     }
74     if (scp_sending_status == NULL) {
75     scp_sending_status = (PSSH_scp_sending_status)GetProcAddress(h, "TTXScpSendingStatus");
76     if (scp_sending_status == NULL) {
77     return FALSE;
78     }
79     }
80    
81     if (receive_file == NULL) {
82     receive_file = (PSSH_start_scp)GetProcAddress(h, "TTXScpReceivefile");
83     if (receive_file == NULL) {
84     return FALSE;
85     }
86     }
87    
88 zmatsuo 10467 if (GetKnownHostsFileName == NULL) {
89     GetKnownHostsFileName = (PSSH_GetKnownHostsFileName)GetProcAddress(h, "TTXReadKnownHostsFile");
90     if (GetKnownHostsFileName == NULL) {
91     return FALSE;
92     }
93     }
94    
95 zmatsuo 10401 return TRUE;
96     }
97    
98     /**
99     * �t�@�C�������M����
100     */
101     BOOL ScpSend(const char *local, const char *remote)
102     {
103     if (start_scp == NULL) {
104     ScpInit();
105     }
106     if (start_scp == NULL) {
107     return FALSE;
108     }
109     BOOL r = (BOOL)start_scp((char*)local, (char*)remote);
110     return r;
111     }
112    
113     /**
114     * �t�@�C�����M����
115     * @retval FALSE ���M����������
116     * @retval TRUE ���M��
117     */
118     BOOL ScpGetStatus(void)
119     {
120     if (scp_sending_status == NULL) {
121     ScpInit();
122     }
123     if (scp_sending_status == NULL) {
124     return FALSE;
125     }
126     BOOL r = (BOOL)scp_sending_status();
127     return r;
128     }
129    
130     /**
131     * �t�@�C�������M����
132     */
133     BOOL ScpReceive(const char *remotefile, const char *localfile)
134     {
135     if (receive_file == NULL) {
136     ScpInit();
137     }
138     if (receive_file == NULL) {
139     return FALSE;
140     }
141     BOOL r = (BOOL)receive_file((char*)remotefile, (char*)localfile);
142     return r;
143     }
144 zmatsuo 10467
145     /**
146     * knownhost�t�@�C����������
147     * �s�v����������free()��������
148     */
149     BOOL TTXSSHGetKnownHostsFileName(wchar_t **filename)
150     {
151     if (GetKnownHostsFileName == NULL) {
152     ScpInit();
153     }
154     if (GetKnownHostsFileName == NULL) {
155     *filename = NULL;
156     return FALSE;
157     }
158    
159     size_t size = GetKnownHostsFileName(NULL, 0);
160     if (size == 0) {
161     *filename = NULL;
162     return FALSE;
163     }
164     wchar_t *f = (wchar_t *)malloc(sizeof(wchar_t) * size);
165     if (f == NULL) {
166     *filename = NULL;
167     return FALSE;
168     }
169     GetKnownHostsFileName(f, size);
170    
171     *filename = f;
172     return TRUE;
173     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26