| 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 |
|
|
* TODO |
| 31 |
|
|
* - unicode(wchar_t) filename |
| 32 |
|
|
* - init()/uninit() per ssh connect/disconnect |
| 33 |
|
|
*/ |
| 34 |
|
|
|
| 35 |
|
|
#include <windows.h> |
| 36 |
|
|
|
| 37 |
|
|
#include "scp.h" |
| 38 |
|
|
|
| 39 |
|
|
typedef int (CALLBACK *PSSH_start_scp)(char *, char *); |
| 40 |
|
|
typedef int (CALLBACK * PSSH_scp_sending_status)(void); |
| 41 |
|
|
|
| 42 |
|
|
static HMODULE h = NULL; |
| 43 |
|
|
static PSSH_start_scp start_scp = NULL; |
| 44 |
|
|
static PSSH_start_scp receive_file = NULL; |
| 45 |
|
|
static PSSH_scp_sending_status scp_sending_status = NULL; |
| 46 |
|
|
|
| 47 |
|
|
/** |
| 48 |
|
|
* @brief SCP�������A�h���X������ |
| 49 |
|
|
* @retval TRUE ok |
| 50 |
|
|
* @retval FALSE dll������/dll��scp���M���������������� |
| 51 |
|
|
*/ |
| 52 |
|
|
static BOOL ScpInit(void) |
| 53 |
|
|
{ |
| 54 |
|
|
if (h == NULL) { |
| 55 |
|
|
if ((h = GetModuleHandle("ttxssh.dll")) == NULL) { |
| 56 |
|
|
return FALSE; |
| 57 |
|
|
} |
| 58 |
|
|
} |
| 59 |
|
|
|
| 60 |
|
|
if (start_scp == NULL) { |
| 61 |
|
|
start_scp = (PSSH_start_scp)GetProcAddress(h, "TTXScpSendfile"); |
| 62 |
|
|
if (start_scp == NULL) { |
| 63 |
|
|
return FALSE; |
| 64 |
|
|
} |
| 65 |
|
|
} |
| 66 |
|
|
if (scp_sending_status == NULL) { |
| 67 |
|
|
scp_sending_status = (PSSH_scp_sending_status)GetProcAddress(h, "TTXScpSendingStatus"); |
| 68 |
|
|
if (scp_sending_status == NULL) { |
| 69 |
|
|
return FALSE; |
| 70 |
|
|
} |
| 71 |
|
|
} |
| 72 |
|
|
|
| 73 |
|
|
if (receive_file == NULL) { |
| 74 |
|
|
receive_file = (PSSH_start_scp)GetProcAddress(h, "TTXScpReceivefile"); |
| 75 |
|
|
if (receive_file == NULL) { |
| 76 |
|
|
return FALSE; |
| 77 |
|
|
} |
| 78 |
|
|
} |
| 79 |
|
|
|
| 80 |
|
|
return TRUE; |
| 81 |
|
|
} |
| 82 |
|
|
|
| 83 |
|
|
/** |
| 84 |
|
|
* �t�@�C�������M���� |
| 85 |
|
|
*/ |
| 86 |
|
|
BOOL ScpSend(const char *local, const char *remote) |
| 87 |
|
|
{ |
| 88 |
|
|
if (start_scp == NULL) { |
| 89 |
|
|
ScpInit(); |
| 90 |
|
|
} |
| 91 |
|
|
if (start_scp == NULL) { |
| 92 |
|
|
return FALSE; |
| 93 |
|
|
} |
| 94 |
|
|
BOOL r = (BOOL)start_scp((char*)local, (char*)remote); |
| 95 |
|
|
return r; |
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
|
|
/** |
| 99 |
|
|
* �t�@�C�����M���� |
| 100 |
|
|
* @retval FALSE ���M���������� |
| 101 |
|
|
* @retval TRUE ���M�� |
| 102 |
|
|
*/ |
| 103 |
|
|
BOOL ScpGetStatus(void) |
| 104 |
|
|
{ |
| 105 |
|
|
if (scp_sending_status == NULL) { |
| 106 |
|
|
ScpInit(); |
| 107 |
|
|
} |
| 108 |
|
|
if (scp_sending_status == NULL) { |
| 109 |
|
|
return FALSE; |
| 110 |
|
|
} |
| 111 |
|
|
BOOL r = (BOOL)scp_sending_status(); |
| 112 |
|
|
return r; |
| 113 |
|
|
} |
| 114 |
|
|
|
| 115 |
|
|
/** |
| 116 |
|
|
* �t�@�C�������M���� |
| 117 |
|
|
*/ |
| 118 |
|
|
BOOL ScpReceive(const char *remotefile, const char *localfile) |
| 119 |
|
|
{ |
| 120 |
|
|
if (receive_file == NULL) { |
| 121 |
|
|
ScpInit(); |
| 122 |
|
|
} |
| 123 |
|
|
if (receive_file == NULL) { |
| 124 |
|
|
return FALSE; |
| 125 |
|
|
} |
| 126 |
|
|
BOOL r = (BOOL)receive_file((char*)remotefile, (char*)localfile); |
| 127 |
|
|
return r; |
| 128 |
|
|
} |