Jelajahi Sumber

1、集成libssh2。
2、完成部分dailybuild工作;

Jeff 5 tahun lalu
induk
melakukan
369c01fb58

+ 273 - 13
SATService/SATService/SATExecutor.cpp

@@ -4,6 +4,7 @@
 #include "CharEncoding.h"
 #include "SynSerial.h"
 #include "IRControl.h"
+#include "WinSsh2Proc.h"
 
 CSATExecutor::CSATExecutor(void)
 {
@@ -23,6 +24,26 @@ CSATExecutor::~CSATExecutor(void)
 
 bool CSATExecutor::IsTaskExist(SATHTTP::STTask &task)
 {
+#ifdef _DEBUG
+	if ( task.taskInfo.strTaskType == "FUNCTIONALITY" ) 
+	{
+		AutoThreadSection ats(&m_csSomkingTask);
+		// 如果任务存在,删除原来的;
+		std::list<SATHTTP::STTask>::iterator it = m_vtSmokingTask.begin();
+		for ( ; it != m_vtSmokingTask.end(); it++ ) {
+			// 不要使用nTaskId,这个值没啥用;//不要使用Id这个值,如果任务被停止会变更;
+			if ( it->taskInfo.nInstanceId == task.taskInfo.nInstanceId ) {
+				m_vtSmokingTask.erase(it);
+				break;
+			}
+		}
+
+		// 再将任务添加入队列;
+		m_vtSmokingTask.push_back(task);
+		return true;
+	}
+#endif
+
 	bool found = false;
 	std::list<SATHTTP::STTask>::iterator it = m_vtTask.begin();
 	for ( ; it != m_vtTask.end(); it++ ) {
@@ -41,6 +62,41 @@ bool CSATExecutor::IsTaskExist(SATHTTP::STTask &task)
 	return found;
 }
 
+void CSATExecutor::DownloadTask(SATHTTP::STTask &task)
+{
+	// 将任务压入队列中;
+	AutoThreadSection ats(&m_csTask);
+	// 同时下载任务;
+	GLOBAL::WriteTextLog(GLOBAL::SAT_EXE, _T("【任务脚本下载】:%s"), task.Job.strUniqueId.c_str());
+	std::string host = GLOBAL::g_stSATConfig.szCaseServer;
+	std::string url = host + "/ajaxInteractiveManage!getCaseFileListUrl.action";
+	std::vector<SATHTTP::STCase>::iterator _case = task.vtCases.begin();
+	for ( int i = 1; _case != task.vtCases.end(); _case++) {
+		// 下载脚本;
+		_case->_nCaseStep = i++;
+		SATHTTP::STScriptUrlResp stScriptUrlResp;
+		// 脚本保存路径;
+		std::string strScriptSaveDir = GLOBAL::g_stSATConfig.szScriptDir;
+		strScriptSaveDir.append(task.Job.strProjectName+"\\");
+		strScriptSaveDir.append(task.Job.strUniqueId+"\\");
+		// 把冒号改成下划线;
+		strScriptSaveDir.append(GLOBAL::Replace(task.Job.strDeviceId, "_", ":")+"\\");
+		if ( DownloadScript(url, _case->strId, strScriptSaveDir, stScriptUrlResp) ) {
+			_case->_strFileDir = stScriptUrlResp._strFileDir;
+			_case->_strFileName = stScriptUrlResp._strFileName;
+			_case->_strScriptPath = stScriptUrlResp._strScripFile;
+		} else {
+			// 脚本下载失败时,需要标记脚本为已运行且异常;
+			_case->_nExecutionState = SATHTTP::EXECUTED;
+			_case->_nExecutionResult = SATHTTP::ABNORMAL;
+			GLOBAL::WriteTextLog(GLOBAL::SAT_EXE, _T("【下载脚本失败】:%s"), _case->strCaseName.c_str());
+		}
+	}
+
+	TaskRoundSetting(&task);
+	m_vtTask.push_back(task);
+}
+
 SATHTTP::STTask* CSATExecutor::IsThereATaskInProcess()
 {
 	std::list<SATHTTP::STTask>::iterator it = m_vtTask.begin();
@@ -1150,6 +1206,127 @@ int CSATExecutor::AttachTaskInfo2Buffer(SATPROTO::TaskInfo (&pbuff)[SATPROTO::MA
 	return count;
 }
 
+void CSATExecutor::SmokeTaskPretreated(std::list<SATHTTP::STTask>::iterator &it)
+{
+	if ( it == m_vtSmokingTask.end() )
+		return;
+
+	/* logic
+	pkBuildServerInfo = {}
+	if 获取服务器信息(pTask->szBuildServerName, pkBuildServerInfo) == false then
+		return
+	end
+
+	pkSoftInfo = {}
+	if 获取软件信息(pTask->szTaskName, pkSoftInfo) == false then
+		return
+	end
+
+	pkTimeInfo = {}
+	if 获取执行时间信息(pTask->szTaskName, pkTimeInfo) == false then
+	return
+	end
+
+	while ( 是否到达执行时间(pkTimeInfo) == false )
+		sleep(1000)
+	end	
+	//
+	*/
+#ifdef _DEBUG
+	SATHTTP::STTask *pTask = (SATHTTP::STTask*)&*it;
+
+	SATHTTP::STBuildServerInfo buildSerInfo;
+	buildSerInfo.strBuildServerName = _T("RT2851");
+	buildSerInfo.strBuildServerAddress = _T("10.201.251.254");
+	buildSerInfo.nBuildServerPort = 22;
+	buildSerInfo.strBuildServerUser = "wjf";
+	buildSerInfo.strBuildServerPwd = "wjf2019";
+	buildSerInfo.strBuildServerImgPath = "/home/RT2841_2851_dailybuild";
+	
+	pTask->SoftwareInfo.strProjectId = "100";
+	pTask->SoftwareInfo.strSoftwareName = "2851";
+	pTask->SoftwareInfo.strSoftwareNumber = "";
+	pTask->SoftwareInfo.strSoftwareVersion = "";
+
+	//pTask->taskInfo.strSomkingCycle = _T("{ \"type\" : 0, \"day\" : 0, \"week\" : 0, \"time\" : \"20:30\" } ");
+	pTask->taskInfo.stSomkingCycle.nType = 1;
+	pTask->taskInfo.stSomkingCycle.nWeek = 0;
+	pTask->taskInfo.stSomkingCycle.nDay = 0;
+	pTask->taskInfo.stSomkingCycle.strTime = "16:05";
+
+	bool bTimeIsUp = false;
+	// 获取当前日历时间(1900-01-01开始的Unix时间戳);
+	__time64_t gmt = time(NULL);
+	struct tm gmtm = { 0 };
+	// 时间戳转成本地时间;
+	localtime_s(&gmtm, &gmt); 
+
+	// 获取执行时间;
+	int hour, minute;
+	sscanf(pTask->taskInfo.stSomkingCycle.strTime.c_str(), _T("%d:%d"), &hour, &minute);
+	// 是否到达指定时间;
+	if ( pTask->taskInfo.stSomkingCycle.nType == 0 ) {// 立即;
+		bTimeIsUp = true;
+	}
+	else if ( pTask->taskInfo.stSomkingCycle.nType == 1 ) {// 每天;
+		if ( gmtm.tm_hour == hour && gmtm.tm_min >= minute )
+			bTimeIsUp = true;
+	}
+	else if ( pTask->taskInfo.stSomkingCycle.nType == 2 ) {// 每周;
+		if ( gmtm.tm_wday == pTask->taskInfo.stSomkingCycle.nWeek && gmtm.tm_hour == hour && gmtm.tm_min >= minute )
+			bTimeIsUp = true;
+	}
+	else if ( pTask->taskInfo.stSomkingCycle.nType == 3 ) {// 每月;
+		if ( gmtm.tm_mday == pTask->taskInfo.stSomkingCycle.nDay && 
+			gmtm.tm_wday == pTask->taskInfo.stSomkingCycle.nWeek && gmtm.tm_hour == hour && gmtm.tm_min >= minute )
+			bTimeIsUp = true;
+	}
+
+	// 到达执行时间;
+	if ( bTimeIsUp ) {
+		// 检测编译服务器是否有升级包;
+
+		// 如果有升级包,下载到本地;
+
+		// 如果下载成功且md5校验成功, adb命令上传到电视中;
+
+		// 上传成功,等待升级成功;
+
+		DownloadTask(*pTask);
+		// 移除;
+		it = m_vtSmokingTask.erase(it);
+	}
+#endif
+}
+
+bool CSATExecutor::IsUpgradeImageExist(SATHTTP::STBuildServerInfo &buildSerInfo, SATHTTP::STUpgradeImgInfo &softWareInfo, std::string &imagePath)
+{
+	// 获取当前时间(1900-01-01开始的Unix时间戳);
+	__time64_t gmt = time(NULL);
+	struct tm gmtm = { 0 };
+	// 时间戳转成本地时间;
+	localtime_s(&gmtm, &gmt); 
+	// 拼路径;
+	TCHAR szImageName[MAX_PATH] = {0};
+	TCHAR szImagePath[MAX_PATH] = {0};
+	// 路径;
+	_stprintf_s(szImagePath, _T("%s/DailyBuild_%s_%02d%02d"), 
+		buildSerInfo.strBuildServerImgPath.c_str(), 
+		softWareInfo.strSoftwareName.c_str(), gmtm.tm_mon+1, gmtm.tm_mday);
+	// 文件;
+	_stprintf_s(szImageName, _T("signed-ota_rt2851_update.zip"));
+
+	// 连接服务器查看路径是否存在;
+	CWinSsh2Proc winssh2;
+	if ( winssh2.InitSocket() ) {
+		if ( winssh2.ssh2_connect(buildSerInfo.strBuildServerAddress, buildSerInfo.strBuildServerUser, buildSerInfo.strBuildServerPwd, buildSerInfo.nBuildServerPort) ) {
+			winssh2.ssh2_execute_command(szImagePath, imagePath);
+		}
+	}
+
+	return false;
+}
+
 void CSATExecutor::StartWork()
 {
 	m_hEventHearbeat = CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -1161,35 +1338,71 @@ void CSATExecutor::StartWork()
 	m_hEventExcuteScript = CreateEvent(NULL, TRUE, FALSE, NULL);
 	if ( m_hEventExcuteScript == NULL ) {
 		_tprintf_s(_T("创建事件失败2\n"));
-		return;
+		goto clear;
+	}
+
+	m_hEventSomkingScript = CreateEvent(NULL, TRUE, FALSE, NULL);
+	if ( m_hEventSomkingScript == NULL ) {
+		_tprintf_s(_T("创建事件失败3\n"));
+		goto clear;
 	}
 
 	m_hThreadHearbeat = CreateThread(NULL, 0, HearbeatThread, this, 0, NULL);
 	if ( m_hThreadHearbeat == NULL) {
-		SetEvent(m_hEventHearbeat);
-		SetEvent(m_hEventExcuteScript);
-		CloseHandle(m_hEventHearbeat);
-		CloseHandle(m_hEventExcuteScript);
-		m_hEventHearbeat = NULL;
-		m_hEventExcuteScript = NULL;
 		_tprintf_s(_T("创建线程失败\n"));
-		return;
+		goto clear;
 	}
 
 	m_hThreadExcuteScript = CreateThread(NULL, 0, ExecuteScriptThread, this, 0, NULL);
 	if ( m_hThreadExcuteScript == NULL ) {
+		goto clear;
+	}
+
+	m_hThreadSomkingScript = CreateThread(NULL, 0, SomkingScriptThread, this, 0, NULL);
+	if ( m_hThreadSomkingScript == NULL ) {
+		goto clear;
+	}
+
+	return;
+
+clear:
+	if ( m_hEventHearbeat ) {
 		SetEvent(m_hEventHearbeat);
-		SetEvent(m_hEventExcuteScript);
 		CloseHandle(m_hEventHearbeat);
-		CloseHandle(m_hEventExcuteScript);
 		m_hEventHearbeat = NULL;
+	}
+
+	if ( m_hEventExcuteScript ) {
+		SetEvent(m_hEventExcuteScript);
+		CloseHandle(m_hEventExcuteScript);
 		m_hEventExcuteScript = NULL;
+	}
+
+	if ( m_hEventSomkingScript ) {
+		SetEvent(m_hEventSomkingScript);
+		CloseHandle(m_hEventSomkingScript);
+		m_hEventSomkingScript = NULL;
+	}
+
+	if ( m_hThreadHearbeat ) {
 		WaitForSingleObject(m_hThreadHearbeat,INFINITE);
 		if (m_hThreadHearbeat)
 			CloseHandle(m_hThreadHearbeat);
 		m_hThreadHearbeat = NULL;
-		_tprintf_s(_T("创建线程失败2\n"));
-		return;
+	}
+
+	if ( m_hThreadExcuteScript ) {
+		WaitForSingleObject(m_hThreadExcuteScript,INFINITE);
+		if (m_hThreadExcuteScript)
+			CloseHandle(m_hThreadExcuteScript);
+		m_hThreadExcuteScript = NULL;
+	}
+
+	if ( m_hThreadSomkingScript ) {
+		WaitForSingleObject(m_hThreadSomkingScript,INFINITE);
+		if (m_hThreadSomkingScript)
+			CloseHandle(m_hThreadSomkingScript);
+		m_hThreadSomkingScript = NULL;
 	}
 }
 
@@ -1231,6 +1444,24 @@ void CSATExecutor::EndofWork()
 		m_hEventExcuteScript = NULL;
 	}
 
+	//////////////////////////////////////////////////////////////////////////
+	// 设置事件有信号;
+	if ( m_hEventSomkingScript )
+		SetEvent(m_hEventSomkingScript);
+
+	// 等待线程结束;
+	if ( m_hThreadSomkingScript ) {
+		WaitForSingleObject(m_hThreadSomkingScript, INFINITE);
+		CloseHandle(m_hThreadSomkingScript);
+		m_hThreadSomkingScript = NULL;
+	}
+
+	// 关闭事件句柄;
+	if ( m_hEventSomkingScript ) {
+		CloseHandle(m_hEventSomkingScript);
+		m_hEventSomkingScript = NULL;
+	}
+
 	// 如果有脚本在执行,结束脚本;
 	CPythonExecutor *pExecutor = NULL;
 	for ( std::list<SATHTTP::STTask>::iterator it = m_vtTask.begin(); it != m_vtTask.end(); it++ ) {
@@ -1276,6 +1507,7 @@ DWORD CSATExecutor::HearbeatThread(LPVOID lpVoid)
 			std::vector<SATHTTP::STTask>::iterator it = stHeartbeatResp.vtTask.begin();
 			for ( ; it != stHeartbeatResp.vtTask.end(); it++ ) {
 				if (!that->IsTaskExist(*it)) {
+#if 0
 					// 将任务压入队列中;
 					AutoThreadSection ats(&that->m_csTask);
 					// 同时下载任务;
@@ -1307,12 +1539,14 @@ DWORD CSATExecutor::HearbeatThread(LPVOID lpVoid)
 
 					that->TaskRoundSetting(&*it);
 					that->m_vtTask.push_back(*it);
-					
 					// 通知SAT服务器,脚本开始执行;
 					// 待开发:同时将任务存储到数据库中;
 					/*
 					db process
 					*/
+#else
+					that->DownloadTask(*it);
+#endif
 				}
 			}
 		}
@@ -1567,5 +1801,31 @@ DWORD CSATExecutor::WathTVPortThread(PVOID lpVoid)
 		Sleep(200);
 	}
 
+	return 0;
+}
+
+DWORD CSATExecutor::SomkingScriptThread(LPVOID lpVoid)
+{
+	CSATExecutor *that = (CSATExecutor*)lpVoid;
+	if ( !that ) return 0;
+	
+	// 如果任务存在,删除原来的;
+	std::list<SATHTTP::STTask>::iterator it = that->m_vtSmokingTask.end();
+
+	do 
+	{
+		AutoThreadSection ats(&that->m_csSomkingTask);
+		if ( that->m_vtSmokingTask.size() == 0 )
+			continue;
+
+		if ( it == that->m_vtSmokingTask.end() )
+			it = that->m_vtSmokingTask.begin();
+		else 
+			it++;
+		
+		that->SmokeTaskPretreated(it);
+		
+	} while (WaitForSingleObject(that->m_hEventSomkingScript, 15000) == WAIT_TIMEOUT);
+
 	return 0;
 }

+ 15 - 0
SATService/SATService/SATExecutor.h

@@ -43,6 +43,9 @@ protected:
 	HANDLE  m_hEventExcuteScript;
 	// 执行线程句柄;
 	HANDLE	m_hThreadExcuteScript;
+	// 冒烟任务;
+	HANDLE  m_hEventSomkingScript;
+	HANDLE	m_hThreadSomkingScript;
 
 	// 是否登录成功;
 	BOOL	m_bLogin;
@@ -50,7 +53,9 @@ protected:
 	BOOL	m_bStopWathTV;
 
 	ThreadSection					m_csTask;
+	ThreadSection					m_csSomkingTask;
 	std::list<SATHTTP::STTask>		m_vtTask;
+	std::list<SATHTTP::STTask>		m_vtSmokingTask;
 	std::vector<SATHTTP::STDevice>	m_vtDevice;
 	SATHTTP::STLoginReq				m_stLoginReq;
 	SATHTTP::STLoginResp			m_stLoginResp;
@@ -59,6 +64,8 @@ protected:
 
 	// 任务是否存在;
 	bool IsTaskExist(SATHTTP::STTask &task);
+	// 下载任务脚本,并将任务加入队列;
+	void DownloadTask(SATHTTP::STTask &task);
 	// 是否有任务在执行;
 	SATHTTP::STTask* IsThereATaskInProcess();
 	// 提取未执行的任务;
@@ -117,6 +124,12 @@ public:
 	bool GetCaseXMLResult(std::string xmlpath, std::vector<STCaseItem> &vtCaseItem);
 	// 将任务列表附加到缓存中;
 	int AttachTaskInfo2Buffer(SATPROTO::TaskInfo (&pbuff)[SATPROTO::MAX_TASKS]);
+	// 冒烟测试任务处理(如果任务是冒烟测试类型,进行预处理);
+	void SmokeTaskPretreated(std::list<SATHTTP::STTask>::iterator &it);
+
+public:
+	// 指定服务器是否有升级包, 并返回镜像路径;
+	bool IsUpgradeImageExist(SATHTTP::STBuildServerInfo &buildSerInfo, SATHTTP::STUpgradeImgInfo &softWareInfo, std::string &imagePath);
 
 	// 其他接口;
 public:
@@ -133,6 +146,8 @@ public:
 	static DWORD WINAPI ExecuteScriptThread(LPVOID lpVoid);
 	// 监听异常关机重启;
 	static DWORD WINAPI WathTVPortThread(LPVOID lpVoid);
+	// 冒烟任务;
+	static DWORD WINAPI SomkingScriptThread(LPVOID lpVoid);
 };
 
 

+ 17 - 9
SATService/SATService/SATService.vcproj

@@ -42,7 +42,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="../cJSON;C:\Python27\Include"
+				AdditionalIncludeDirectories="../cJSON;C:\Python27\Include;..\libssh2\include"
 				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"
@@ -62,9 +62,9 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="SATHTTP.lib IRControl.lib"
+				AdditionalDependencies="SATHTTP.lib IRControl.lib libssh2.lib"
 				LinkIncremental="2"
-				AdditionalLibraryDirectories="C:\Python27\libs"
+				AdditionalLibraryDirectories="C:\Python27\libs;..\libssh2"
 				UACExecutionLevel="2"
 				GenerateDebugInformation="true"
 				SubSystem="1"
@@ -121,7 +121,7 @@
 				Name="VCCLCompilerTool"
 				Optimization="2"
 				EnableIntrinsicFunctions="true"
-				AdditionalIncludeDirectories="../cJSON;C:\Python27\Include"
+				AdditionalIncludeDirectories="../cJSON;C:\Python27\Include;..\libssh2\include"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
 				RuntimeLibrary="2"
 				EnableFunctionLevelLinking="true"
@@ -140,9 +140,9 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="SATHTTP.lib IRControl.lib"
+				AdditionalDependencies="SATHTTP.lib IRControl.lib libssh2.lib"
 				LinkIncremental="1"
-				AdditionalLibraryDirectories="C:\Python27\libs"
+				AdditionalLibraryDirectories="C:\Python27\libs;..\libssh2"
 				UACExecutionLevel="2"
 				GenerateDebugInformation="true"
 				SubSystem="1"
@@ -201,7 +201,7 @@
 				Name="VCCLCompilerTool"
 				Optimization="2"
 				EnableIntrinsicFunctions="true"
-				AdditionalIncludeDirectories="../cJSON;C:\Python27\Include"
+				AdditionalIncludeDirectories="../cJSON;C:\Python27\Include;..\libssh2\include"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;RTEST"
 				RuntimeLibrary="2"
 				EnableFunctionLevelLinking="true"
@@ -220,9 +220,9 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="SATHTTP.lib IRControl.lib"
+				AdditionalDependencies="SATHTTP.lib IRControl.lib libssh2.lib"
 				LinkIncremental="1"
-				AdditionalLibraryDirectories="C:\Python27\libs"
+				AdditionalLibraryDirectories="C:\Python27\libs;..\libssh2"
 				UACExecutionLevel="2"
 				GenerateDebugInformation="true"
 				SubSystem="1"
@@ -310,6 +310,10 @@
 				RelativePath=".\WindowService.cpp"
 				>
 			</File>
+			<File
+				RelativePath=".\WinSsh2Proc.cpp"
+				>
+			</File>
 		</Filter>
 		<Filter
 			Name="Í·Îļþ"
@@ -360,6 +364,10 @@
 				RelativePath=".\WindowService.h"
 				>
 			</File>
+			<File
+				RelativePath=".\WinSsh2Proc.h"
+				>
+			</File>
 		</Filter>
 		<Filter
 			Name="×ÊÔ´Îļþ"

+ 343 - 0
SATService/SATService/WinSsh2Proc.cpp

@@ -0,0 +1,343 @@
+#include "StdAfx.h"
+#include "WinSsh2Proc.h"
+
+CWinSsh2Proc::CWinSsh2Proc(void)
+{
+
+}
+
+CWinSsh2Proc::~CWinSsh2Proc(void)
+{
+
+}
+
+bool CWinSsh2Proc::InitSocket()
+{
+	WSADATA wsadata;
+	int err = WSAStartup(MAKEWORD(2, 0), &wsadata);
+	if( err != 0 ) {
+		fprintf(stderr, "WSAStartup failed with error: %d\n", err);
+		return false;
+	}
+
+	return true;
+}
+
+int CWinSsh2Proc::waitsocket(int socket_fd, LIBSSH2_SESSION *session)
+{
+	struct timeval timeout;
+	int rc;
+	fd_set fd;
+	fd_set *writefd = NULL;
+	fd_set *readfd = NULL;
+	int dir;
+
+	timeout.tv_sec = 10;
+	timeout.tv_usec = 0;
+
+	FD_ZERO(&fd);
+
+	FD_SET(socket_fd, &fd);
+
+	/* now make sure we wait in the correct direction */
+	dir = libssh2_session_block_directions(session);
+
+	if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
+		readfd = &fd;
+
+	if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
+		writefd = &fd;
+
+	rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
+
+	return rc;
+}
+
+bool CWinSsh2Proc::ssh2_connect(std::string host, std::string user, std::string pwd, int port /*=22*/)
+{
+	m_user = user;
+	m_pwd = pwd;
+	m_port = port;
+	m_host = host;
+	// 创建socket连接;
+	unsigned long hostaddr = inet_addr(host.c_str());
+	SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
+	m_sin.sin_family = AF_INET;
+	m_sin.sin_port = htons(port);
+	m_sin.sin_addr.s_addr = hostaddr;
+	if ( connect(sock, (const sockaddr*)&m_sin, sizeof(m_sin)) != 0 ) {
+		printf("failed to connect!\n");
+		return false;
+	}
+
+	closesocket(sock);
+
+	return true;
+}
+
+/*
+void CWinSsh2Proc::ssh2_disconnect()
+{
+	int rc;
+	int bytecount = 0;
+	int exitcode = 127;
+	char *exitsignal = (char *)"none";
+	m_bStatus = false;
+	if ( m_pChannel == NULL )
+		goto shutdown;
+
+	while((rc = libssh2_channel_close(m_pChannel)) == LIBSSH2_ERROR_EAGAIN)
+		waitsocket(m_sock, m_pSession);
+
+	if(rc == 0) {
+		exitcode = libssh2_channel_get_exit_status(m_pChannel);
+		libssh2_channel_get_exit_signal(m_pChannel, &exitsignal, NULL, NULL, NULL, NULL, NULL);
+	}
+
+	if(exitsignal)
+		fprintf(stderr, "\nGot signal: %s\n", exitsignal);
+	else
+		fprintf(stderr, "\nEXIT: %d bytecount: %d\n", exitcode, bytecount);
+
+	libssh2_channel_free(m_pChannel);
+	m_pChannel = NULL;
+
+shutdown:
+	libssh2_session_disconnect(m_pSession, "Normal Shutdown, Thank you for playing");
+	libssh2_session_free(m_pSession);
+	m_pSession = NULL;
+
+#ifdef WIN32
+	closesocket(m_sock);
+#else
+	close(m_sock);
+#endif
+	fprintf(stderr, "all done\n");
+
+	libssh2_exit();
+}
+*/
+
+bool CWinSsh2Proc::ssh2_execute_command(std::string cmd, std::string &result, DWORD dwTimeout /*= 1000*/)
+{
+	int rc;
+	bool bRet = false;
+	SOCKET sock = INVALID_SOCKET;
+	LIBSSH2_SESSION* pSession = NULL;
+	LIBSSH2_CHANNEL* pChannel = NULL;
+	if ( !ssh2_init_session(&pSession, sock) )
+		return false;
+
+	// 请求一个shell;
+	while((pChannel= libssh2_channel_open_session(pSession)) == NULL && 
+		libssh2_session_last_error(pSession, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN) {
+		waitsocket(sock, pSession);
+	}
+
+	if ( pChannel == NULL ) {
+		printf("Error\n");
+		goto shutdown;
+	}
+#if 0
+	// 请求一个模拟终端;
+	if( libssh2_channel_request_pty(pChannel,"VT100") != LIBSSH2_ERROR_NONE ) {
+		printf("ssh请求伪终端失败,退出。\n");
+		goto skip_shell;
+	}
+
+	// 在模拟终端上开户shell;
+	if(libssh2_channel_shell(pChannel) != LIBSSH2_ERROR_NONE ) {
+		printf("ssh shell请求失败,退出\n");
+		goto shutdown;
+	}
+#else	
+	while((rc = libssh2_channel_exec(pChannel, cmd.c_str())) == LIBSSH2_ERROR_EAGAIN) {
+			waitsocket(sock, pSession);
+	}
+	if ( rc != LIBSSH2_ERROR_NONE )
+		goto skip_shell;
+#endif
+
+	// 设置为阻塞模式;
+	libssh2_channel_set_blocking(pChannel,0);
+
+	if ( cmd.at(cmd.size()-1) != '\n' )
+		cmd.append("\n");
+
+	while((rc = libssh2_channel_write(pChannel, cmd.c_str(),  cmd.size())) == LIBSSH2_ERROR_EAGAIN ) {
+		printf("ssh写堵塞,重试\n");
+		waitsocket(sock, pSession);
+	}
+
+	if ( rc < 0 )
+		goto shutdown;
+
+	Sleep(dwTimeout);
+	ssh2_read_channel(pChannel, result);
+	bRet = true;
+
+skip_shell:
+	if(pChannel) {
+		libssh2_channel_free(pChannel);
+		pChannel = NULL;
+	}
+
+shutdown:
+	libssh2_session_disconnect(pSession,"Normal Shutdown, Thank you for playing");
+	libssh2_session_free(pSession);
+
+#ifdef WIN32
+	closesocket(sock);
+#else
+	close(sock);
+#endif
+	libssh2_exit();
+
+	return bRet;
+}
+
+void CWinSsh2Proc::ssh2_read_channel(LIBSSH2_CHANNEL* pChannel, std::string &buffer)
+{
+	if ( pChannel == NULL )
+		return;
+
+	int rc;
+	char buf[1024] = "";
+	buffer.clear();
+	do {
+		rc = libssh2_channel_read(pChannel, buf, sizeof(buf) - 1);
+		if(rc > 0) {
+			buf[rc] = 0;
+			buffer.append(buf, rc);
+			memset(buf, 0, sizeof(buf));
+		}
+	}while( rc > 0 );
+
+	printf("%s \n", buffer.c_str());
+}
+
+bool CWinSsh2Proc::ssh2_init_session(LIBSSH2_SESSION** pSession, SOCKET &sock)
+{
+	// 初始化库;
+	int rc = libssh2_init(0);
+	if ( rc != LIBSSH2_ERROR_NONE ) {
+		fprintf(stderr, "libssh2 initialization failed (%d)\n", rc);
+		return false;
+	}
+
+	sock = socket(AF_INET, SOCK_STREAM, 0);
+	if ( connect(sock, (const sockaddr*)&m_sin, sizeof(m_sin)) != 0 ) {
+		fprintf(stderr, "failed to connect!\n");
+		return false;
+	}
+
+	// 建立ssh会话实例;
+	*pSession = libssh2_session_init();
+	libssh2_session_set_blocking(*pSession, 1);
+
+	rc = libssh2_session_handshake(*pSession, sock);
+	if ( rc != LIBSSH2_ERROR_NONE ){
+		printf("Failure establishing SSH session: %d\n", rc);
+		// 释放资源;
+		SHUTDOWN(*pSession, sock)
+		return false;
+	}
+
+	// 登录linux;
+	rc = libssh2_userauth_password(*pSession, m_user.c_str(), m_pwd.c_str());
+	if( rc != LIBSSH2_ERROR_NONE ) {
+		printf("Authentication by password failed: %d\n", rc);
+		// 释放资源;
+		SHUTDOWN(*pSession, sock)
+		return false;
+	}
+	
+	return true;
+}
+
+bool CWinSsh2Proc::ssh2_sftp_download(std::string sftppath, std::string localpath)
+{
+	SOCKET sock = -1;
+	LIBSSH2_SESSION *session;
+	LIBSSH2_SFTP *sftp_session;
+	LIBSSH2_SFTP_HANDLE *sftp_handle;
+	// 初始化库;
+	int rc = libssh2_init(0);
+	if ( rc != LIBSSH2_ERROR_NONE ) {
+		fprintf(stderr, "libssh2 initialization failed (%d)\n", rc);
+		return false;
+	}
+
+	// 创建socket连接;
+	sock = socket(AF_INET, SOCK_STREAM, 0);
+	if ( connect(sock, (const sockaddr*)&m_sin, sizeof(m_sin)) != 0 ) {
+		fprintf(stderr, "failed to connect!\n");
+		return false;
+	}
+
+	// 建立ssh会话实例;
+	session = libssh2_session_init();
+	/* Since we have set non-blocking, tell libssh2 we are blocking */
+	libssh2_session_set_blocking(session, 1);
+
+	//while ( LIBSSH2_ERROR_EAGAIN == (rc = libssh2_session_handshake(m_pSession, m_sock)) );
+	rc = libssh2_session_handshake(session, sock);
+	if ( rc != LIBSSH2_ERROR_NONE ){
+		fprintf(stderr, "Failure establishing SSH session: %d\n", rc);
+		return false;
+	}
+
+	// 登录linux;
+	bool bDone = false;
+	//while ( LIBSSH2_ERROR_EAGAIN == (rc = libssh2_userauth_password(m_pSession, user.c_str(), pwd.c_str())));
+	rc = libssh2_userauth_password(session, m_user.c_str(), m_pwd.c_str());
+	if( rc != LIBSSH2_ERROR_NONE ) {
+		fprintf(stderr, "Authentication by password failed: %d\n", rc);
+		goto shutdown;
+	}
+
+	sftp_session = libssh2_sftp_init(session);
+	if (!sftp_session) {
+		goto shutdown;
+	}
+
+	/* Request a file via SFTP */
+	sftp_handle = libssh2_sftp_open(sftp_session, sftppath.c_str(), LIBSSH2_FXF_READ, 0);
+
+
+	if (!sftp_handle) {
+		goto shutdown;
+	}
+
+	FILE *stream;
+	if (fopen_s(&stream, localpath.c_str(), "wb") == 0) {
+		do {
+			char mem[1024];
+
+			/* loop until we fail */
+			rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem));
+
+			if (rc > 0) {
+				//从内存到磁盘
+				fwrite(mem, 1, rc, stream);
+			}
+			else {
+				break;
+			}
+		} while (1);
+
+		bDone = true;
+		fclose(stream);
+	}
+
+
+	libssh2_sftp_close(sftp_handle);
+	libssh2_sftp_shutdown(sftp_session);
+
+shutdown:
+	libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing");
+	libssh2_session_free(session);
+	closesocket(sock);//INVALID_SOCKET
+	
+	return bDone;
+}

+ 45 - 0
SATService/SATService/WinSsh2Proc.h

@@ -0,0 +1,45 @@
+#ifndef __WIN_SSH2_20200506__
+#define __WIN_SSH2_20200506__
+
+#include "libssh2_config.h"
+#include "libssh2.h"
+#include "libssh2_sftp.h"
+
+#include <winsock2.h>
+#pragma comment(lib, "ws2_32.lib")
+
+#pragma once
+
+#define SHUTDOWN(session, sock) \
+libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing");\
+libssh2_session_free(session);\
+closesocket(sock);\
+libssh2_exit(); 
+
+class CWinSsh2Proc
+{
+public:
+	CWinSsh2Proc(void);
+	~CWinSsh2Proc(void);
+
+private:
+	int				m_port;
+	std::string		m_host;
+	std::string		m_user;
+	std::string		m_pwd;
+	sockaddr_in		m_sin;
+
+	void ssh2_read_channel(LIBSSH2_CHANNEL* pChannel, std::string &buffer);
+	bool ssh2_init_session(LIBSSH2_SESSION** pSession, SOCKET &sock);
+	void ssh2_free(LIBSSH2_SESSION*	pSession, LIBSSH2_CHANNEL*	pChannel);	
+public:
+	static bool InitSocket();
+	static int waitsocket(int socket_fd, LIBSSH2_SESSION *session);
+	bool ssh2_connect(std::string host, std::string user, std::string pwd, int port = 22);
+	void ssh2_disconnect();
+	bool ssh2_execute_command(std::string cmd, std::string &result, DWORD dwTimeout = 1000);
+	bool ssh2_sftp_download(std::string sftppath, std::string localpath);
+};
+
+
+#endif //__WIN_SSH2_20200506__

+ 1344 - 0
SATService/libssh2/include/libssh2.h

@@ -0,0 +1,1344 @@
+/* Copyright (c) 2004-2009, Sara Golemon <sarag@libssh2.org>
+ * Copyright (c) 2009-2015 Daniel Stenberg
+ * Copyright (c) 2010 Simon Josefsson <simon@josefsson.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ *   Redistributions of source code must retain the above
+ *   copyright notice, this list of conditions and the
+ *   following disclaimer.
+ *
+ *   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.
+ *
+ *   Neither the name of the copyright holder nor the names
+ *   of any other contributors may be used to endorse or
+ *   promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "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 COPYRIGHT OWNER OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef LIBSSH2_H
+#define LIBSSH2_H 1
+
+#define LIBSSH2_COPYRIGHT "2004-2019 The libssh2 project and its contributors."
+
+/* We use underscore instead of dash when appending DEV in dev versions just
+   to make the BANNER define (used by src/session.c) be a valid SSH
+   banner. Release versions have no appended strings and may of course not
+   have dashes either. */
+#define LIBSSH2_VERSION                             "1.9.0_DEV"
+
+/* The numeric version number is also available "in parts" by using these
+   defines: */
+#define LIBSSH2_VERSION_MAJOR                       1
+#define LIBSSH2_VERSION_MINOR                       9
+#define LIBSSH2_VERSION_PATCH                       0
+
+/* This is the numeric version of the libssh2 version number, meant for easier
+   parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
+   always follow this syntax:
+
+         0xXXYYZZ
+
+   Where XX, YY and ZZ are the main version, release and patch numbers in
+   hexadecimal (using 8 bits each). All three numbers are always represented
+   using two digits.  1.2 would appear as "0x010200" while version 9.11.7
+   appears as "0x090b07".
+
+   This 6-digit (24 bits) hexadecimal number does not show pre-release number,
+   and it is always a greater number in a more recent release. It makes
+   comparisons with greater than and less than work.
+*/
+#define LIBSSH2_VERSION_NUM                         0x010900
+
+/*
+ * This is the date and time when the full source package was created. The
+ * timestamp is not stored in the source code repo, as the timestamp is
+ * properly set in the tarballs by the maketgz script.
+ *
+ * The format of the date should follow this template:
+ *
+ * "Mon Feb 12 11:35:33 UTC 2007"
+ */
+#define LIBSSH2_TIMESTAMP "DEV"
+
+#ifndef RC_INVOKED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef _WIN32
+# include <basetsd.h>
+# include <winsock2.h>
+#endif
+
+#include <stddef.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+/* Allow alternate API prefix from CFLAGS or calling app */
+#ifndef LIBSSH2_API
+# ifdef LIBSSH2_WIN32
+#  ifdef _WINDLL
+#   ifdef LIBSSH2_LIBRARY
+#    define LIBSSH2_API __declspec(dllexport)
+#   else
+#    define LIBSSH2_API __declspec(dllimport)
+#   endif /* LIBSSH2_LIBRARY */
+#  else
+#   define LIBSSH2_API
+#  endif
+# else /* !LIBSSH2_WIN32 */
+#  define LIBSSH2_API
+# endif /* LIBSSH2_WIN32 */
+#endif /* LIBSSH2_API */
+
+#ifdef HAVE_SYS_UIO_H
+# include <sys/uio.h>
+#endif
+
+#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
+# include <sys/bsdskt.h>
+typedef unsigned char uint8_t;
+typedef unsigned short int uint16_t;
+typedef unsigned int uint32_t;
+typedef int int32_t;
+typedef unsigned long long uint64_t;
+typedef long long int64_t;
+#endif
+
+#ifdef _MSC_VER
+typedef unsigned char uint8_t;
+typedef unsigned short int uint16_t;
+typedef unsigned int uint32_t;
+typedef __int32 int32_t;
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+typedef unsigned __int64 libssh2_uint64_t;
+typedef __int64 libssh2_int64_t;
+#if (!defined(HAVE_SSIZE_T) && !defined(ssize_t))
+typedef SSIZE_T ssize_t;
+#define HAVE_SSIZE_T
+#endif
+#else
+#include <stdint.h>
+typedef unsigned long long libssh2_uint64_t;
+typedef long long libssh2_int64_t;
+#endif
+
+#ifdef WIN32
+typedef SOCKET libssh2_socket_t;
+#define LIBSSH2_INVALID_SOCKET INVALID_SOCKET
+#else /* !WIN32 */
+typedef int libssh2_socket_t;
+#define LIBSSH2_INVALID_SOCKET -1
+#endif /* WIN32 */
+
+/*
+ * Determine whether there is small or large file support on windows.
+ */
+
+#if defined(_MSC_VER) && !defined(_WIN32_WCE)
+#  if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64)
+#    define LIBSSH2_USE_WIN32_LARGE_FILES
+#  else
+#    define LIBSSH2_USE_WIN32_SMALL_FILES
+#  endif
+#endif
+
+#if defined(__MINGW32__) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES)
+#  define LIBSSH2_USE_WIN32_LARGE_FILES
+#endif
+
+#if defined(__WATCOMC__) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES)
+#  define LIBSSH2_USE_WIN32_LARGE_FILES
+#endif
+
+#if defined(__POCC__)
+#  undef LIBSSH2_USE_WIN32_LARGE_FILES
+#endif
+
+#if defined(_WIN32) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES) && \
+    !defined(LIBSSH2_USE_WIN32_SMALL_FILES)
+#  define LIBSSH2_USE_WIN32_SMALL_FILES
+#endif
+
+/*
+ * Large file (>2Gb) support using WIN32 functions.
+ */
+
+#ifdef LIBSSH2_USE_WIN32_LARGE_FILES
+#  include <io.h>
+#  include <sys/types.h>
+#  include <sys/stat.h>
+#  define LIBSSH2_STRUCT_STAT_SIZE_FORMAT    "%I64d"
+typedef struct _stati64 libssh2_struct_stat;
+typedef __int64 libssh2_struct_stat_size;
+#endif
+
+/*
+ * Small file (<2Gb) support using WIN32 functions.
+ */
+
+#ifdef LIBSSH2_USE_WIN32_SMALL_FILES
+#  include <sys/types.h>
+#  include <sys/stat.h>
+#  ifndef _WIN32_WCE
+#    define LIBSSH2_STRUCT_STAT_SIZE_FORMAT    "%d"
+typedef struct _stat libssh2_struct_stat;
+typedef off_t libssh2_struct_stat_size;
+#  endif
+#endif
+
+#ifndef LIBSSH2_STRUCT_STAT_SIZE_FORMAT
+#  ifdef __VMS
+/* We have to roll our own format here because %z is a C99-ism we don't
+   have. */
+#    if __USE_OFF64_T || __USING_STD_STAT
+#      define LIBSSH2_STRUCT_STAT_SIZE_FORMAT      "%Ld"
+#    else
+#      define LIBSSH2_STRUCT_STAT_SIZE_FORMAT      "%d"
+#    endif
+#  else
+#    define LIBSSH2_STRUCT_STAT_SIZE_FORMAT      "%zd"
+#  endif
+typedef struct stat libssh2_struct_stat;
+typedef off_t libssh2_struct_stat_size;
+#endif
+
+/* Part of every banner, user specified or not */
+#define LIBSSH2_SSH_BANNER                  "SSH-2.0-libssh2_" LIBSSH2_VERSION
+
+#define LIBSSH2_SSH_DEFAULT_BANNER            LIBSSH2_SSH_BANNER
+#define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF  LIBSSH2_SSH_DEFAULT_BANNER "\r\n"
+
+/* Default generate and safe prime sizes for
+   diffie-hellman-group-exchange-sha1 */
+#define LIBSSH2_DH_GEX_MINGROUP     1024
+#define LIBSSH2_DH_GEX_OPTGROUP     1536
+#define LIBSSH2_DH_GEX_MAXGROUP     2048
+
+/* Defaults for pty requests */
+#define LIBSSH2_TERM_WIDTH      80
+#define LIBSSH2_TERM_HEIGHT     24
+#define LIBSSH2_TERM_WIDTH_PX   0
+#define LIBSSH2_TERM_HEIGHT_PX  0
+
+/* 1/4 second */
+#define LIBSSH2_SOCKET_POLL_UDELAY      250000
+/* 0.25 * 120 == 30 seconds */
+#define LIBSSH2_SOCKET_POLL_MAXLOOPS    120
+
+/* Maximum size to allow a payload to compress to, plays it safe by falling
+   short of spec limits */
+#define LIBSSH2_PACKET_MAXCOMP      32000
+
+/* Maximum size to allow a payload to deccompress to, plays it safe by
+   allowing more than spec requires */
+#define LIBSSH2_PACKET_MAXDECOMP    40000
+
+/* Maximum size for an inbound compressed payload, plays it safe by
+   overshooting spec limits */
+#define LIBSSH2_PACKET_MAXPAYLOAD   40000
+
+/* Malloc callbacks */
+#define LIBSSH2_ALLOC_FUNC(name)   void *name(size_t count, void **abstract)
+#define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, \
+                                              void **abstract)
+#define LIBSSH2_FREE_FUNC(name)    void name(void *ptr, void **abstract)
+
+typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT
+{
+    char *text;
+    unsigned int length;
+    unsigned char echo;
+} LIBSSH2_USERAUTH_KBDINT_PROMPT;
+
+typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE
+{
+    char *text;
+    unsigned int length;
+} LIBSSH2_USERAUTH_KBDINT_RESPONSE;
+
+/* 'publickey' authentication callback */
+#define LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC(name) \
+  int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \
+           const unsigned char *data, size_t data_len, void **abstract)
+
+/* 'keyboard-interactive' authentication callback */
+#define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) \
+ void name_(const char *name, int name_len, const char *instruction, \
+            int instruction_len, int num_prompts, \
+            const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts,              \
+            LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, void **abstract)
+
+/* Callbacks for special SSH packets */
+#define LIBSSH2_IGNORE_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, const char *message, int message_len, \
+           void **abstract)
+
+#define LIBSSH2_DEBUG_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, int always_display, const char *message, \
+           int message_len, const char *language, int language_len, \
+           void **abstract)
+
+#define LIBSSH2_DISCONNECT_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, int reason, const char *message, \
+           int message_len, const char *language, int language_len, \
+           void **abstract)
+
+#define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, \
+           void **abstract)
+
+#define LIBSSH2_MACERROR_FUNC(name) \
+ int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, \
+          void **abstract)
+
+#define LIBSSH2_X11_OPEN_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \
+           const char *shost, int sport, void **abstract)
+
+#define LIBSSH2_CHANNEL_CLOSE_FUNC(name) \
+  void name(LIBSSH2_SESSION *session, void **session_abstract, \
+            LIBSSH2_CHANNEL *channel, void **channel_abstract)
+
+/* I/O callbacks */
+#define LIBSSH2_RECV_FUNC(name)                                         \
+    ssize_t name(libssh2_socket_t socket,                               \
+                 void *buffer, size_t length,                           \
+                 int flags, void **abstract)
+#define LIBSSH2_SEND_FUNC(name)                                         \
+    ssize_t name(libssh2_socket_t socket,                               \
+                 const void *buffer, size_t length,                     \
+                 int flags, void **abstract)
+
+/* libssh2_session_callback_set() constants */
+#define LIBSSH2_CALLBACK_IGNORE             0
+#define LIBSSH2_CALLBACK_DEBUG              1
+#define LIBSSH2_CALLBACK_DISCONNECT         2
+#define LIBSSH2_CALLBACK_MACERROR           3
+#define LIBSSH2_CALLBACK_X11                4
+#define LIBSSH2_CALLBACK_SEND               5
+#define LIBSSH2_CALLBACK_RECV               6
+
+/* libssh2_session_method_pref() constants */
+#define LIBSSH2_METHOD_KEX          0
+#define LIBSSH2_METHOD_HOSTKEY      1
+#define LIBSSH2_METHOD_CRYPT_CS     2
+#define LIBSSH2_METHOD_CRYPT_SC     3
+#define LIBSSH2_METHOD_MAC_CS       4
+#define LIBSSH2_METHOD_MAC_SC       5
+#define LIBSSH2_METHOD_COMP_CS      6
+#define LIBSSH2_METHOD_COMP_SC      7
+#define LIBSSH2_METHOD_LANG_CS      8
+#define LIBSSH2_METHOD_LANG_SC      9
+
+/* flags */
+#define LIBSSH2_FLAG_SIGPIPE        1
+#define LIBSSH2_FLAG_COMPRESS       2
+
+typedef struct _LIBSSH2_SESSION                     LIBSSH2_SESSION;
+typedef struct _LIBSSH2_CHANNEL                     LIBSSH2_CHANNEL;
+typedef struct _LIBSSH2_LISTENER                    LIBSSH2_LISTENER;
+typedef struct _LIBSSH2_KNOWNHOSTS                  LIBSSH2_KNOWNHOSTS;
+typedef struct _LIBSSH2_AGENT                       LIBSSH2_AGENT;
+
+typedef struct _LIBSSH2_POLLFD {
+    unsigned char type; /* LIBSSH2_POLLFD_* below */
+
+    union {
+        libssh2_socket_t socket; /* File descriptors -- examined with
+                                    system select() call */
+        LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */
+        LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound
+                                       connections waiting to be accepted? */
+    } fd;
+
+    unsigned long events; /* Requested Events */
+    unsigned long revents; /* Returned Events */
+} LIBSSH2_POLLFD;
+
+/* Poll FD Descriptor Types */
+#define LIBSSH2_POLLFD_SOCKET       1
+#define LIBSSH2_POLLFD_CHANNEL      2
+#define LIBSSH2_POLLFD_LISTENER     3
+
+/* Note: Win32 Doesn't actually have a poll() implementation, so some of these
+   values are faked with select() data */
+/* Poll FD events/revents -- Match sys/poll.h where possible */
+#define LIBSSH2_POLLFD_POLLIN           0x0001 /* Data available to be read or
+                                                  connection available --
+                                                  All */
+#define LIBSSH2_POLLFD_POLLPRI          0x0002 /* Priority data available to
+                                                  be read -- Socket only */
+#define LIBSSH2_POLLFD_POLLEXT          0x0002 /* Extended data available to
+                                                  be read -- Channel only */
+#define LIBSSH2_POLLFD_POLLOUT          0x0004 /* Can may be written --
+                                                  Socket/Channel */
+/* revents only */
+#define LIBSSH2_POLLFD_POLLERR          0x0008 /* Error Condition -- Socket */
+#define LIBSSH2_POLLFD_POLLHUP          0x0010 /* HangUp/EOF -- Socket */
+#define LIBSSH2_POLLFD_SESSION_CLOSED   0x0010 /* Session Disconnect */
+#define LIBSSH2_POLLFD_POLLNVAL         0x0020 /* Invalid request -- Socket
+                                                  Only */
+#define LIBSSH2_POLLFD_POLLEX           0x0040 /* Exception Condition --
+                                                  Socket/Win32 */
+#define LIBSSH2_POLLFD_CHANNEL_CLOSED   0x0080 /* Channel Disconnect */
+#define LIBSSH2_POLLFD_LISTENER_CLOSED  0x0080 /* Listener Disconnect */
+
+#define HAVE_LIBSSH2_SESSION_BLOCK_DIRECTION
+/* Block Direction Types */
+#define LIBSSH2_SESSION_BLOCK_INBOUND                  0x0001
+#define LIBSSH2_SESSION_BLOCK_OUTBOUND                 0x0002
+
+/* Hash Types */
+#define LIBSSH2_HOSTKEY_HASH_MD5                            1
+#define LIBSSH2_HOSTKEY_HASH_SHA1                           2
+#define LIBSSH2_HOSTKEY_HASH_SHA256                         3
+
+/* Hostkey Types */
+#define LIBSSH2_HOSTKEY_TYPE_UNKNOWN            0
+#define LIBSSH2_HOSTKEY_TYPE_RSA                1
+#define LIBSSH2_HOSTKEY_TYPE_DSS                2
+#define LIBSSH2_HOSTKEY_TYPE_ECDSA_256          3
+#define LIBSSH2_HOSTKEY_TYPE_ECDSA_384          4
+#define LIBSSH2_HOSTKEY_TYPE_ECDSA_521          5
+#define LIBSSH2_HOSTKEY_TYPE_ED25519            6
+
+/* Disconnect Codes (defined by SSH protocol) */
+#define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT          1
+#define SSH_DISCONNECT_PROTOCOL_ERROR                       2
+#define SSH_DISCONNECT_KEY_EXCHANGE_FAILED                  3
+#define SSH_DISCONNECT_RESERVED                             4
+#define SSH_DISCONNECT_MAC_ERROR                            5
+#define SSH_DISCONNECT_COMPRESSION_ERROR                    6
+#define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE                7
+#define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED       8
+#define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE              9
+#define SSH_DISCONNECT_CONNECTION_LOST                      10
+#define SSH_DISCONNECT_BY_APPLICATION                       11
+#define SSH_DISCONNECT_TOO_MANY_CONNECTIONS                 12
+#define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER               13
+#define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE       14
+#define SSH_DISCONNECT_ILLEGAL_USER_NAME                    15
+
+/* Error Codes (defined by libssh2) */
+#define LIBSSH2_ERROR_NONE                      0
+
+/* The library once used -1 as a generic error return value on numerous places
+   through the code, which subsequently was converted to
+   LIBSSH2_ERROR_SOCKET_NONE uses over time. As this is a generic error code,
+   the goal is to never ever return this code but instead make sure that a
+   more accurate and descriptive error code is used. */
+#define LIBSSH2_ERROR_SOCKET_NONE               -1
+
+#define LIBSSH2_ERROR_BANNER_RECV               -2
+#define LIBSSH2_ERROR_BANNER_SEND               -3
+#define LIBSSH2_ERROR_INVALID_MAC               -4
+#define LIBSSH2_ERROR_KEX_FAILURE               -5
+#define LIBSSH2_ERROR_ALLOC                     -6
+#define LIBSSH2_ERROR_SOCKET_SEND               -7
+#define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE      -8
+#define LIBSSH2_ERROR_TIMEOUT                   -9
+#define LIBSSH2_ERROR_HOSTKEY_INIT              -10
+#define LIBSSH2_ERROR_HOSTKEY_SIGN              -11
+#define LIBSSH2_ERROR_DECRYPT                   -12
+#define LIBSSH2_ERROR_SOCKET_DISCONNECT         -13
+#define LIBSSH2_ERROR_PROTO                     -14
+#define LIBSSH2_ERROR_PASSWORD_EXPIRED          -15
+#define LIBSSH2_ERROR_FILE                      -16
+#define LIBSSH2_ERROR_METHOD_NONE               -17
+#define LIBSSH2_ERROR_AUTHENTICATION_FAILED     -18
+#define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED    \
+    LIBSSH2_ERROR_AUTHENTICATION_FAILED
+#define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED      -19
+#define LIBSSH2_ERROR_CHANNEL_OUTOFORDER        -20
+#define LIBSSH2_ERROR_CHANNEL_FAILURE           -21
+#define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED    -22
+#define LIBSSH2_ERROR_CHANNEL_UNKNOWN           -23
+#define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED   -24
+#define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED   -25
+#define LIBSSH2_ERROR_CHANNEL_CLOSED            -26
+#define LIBSSH2_ERROR_CHANNEL_EOF_SENT          -27
+#define LIBSSH2_ERROR_SCP_PROTOCOL              -28
+#define LIBSSH2_ERROR_ZLIB                      -29
+#define LIBSSH2_ERROR_SOCKET_TIMEOUT            -30
+#define LIBSSH2_ERROR_SFTP_PROTOCOL             -31
+#define LIBSSH2_ERROR_REQUEST_DENIED            -32
+#define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED      -33
+#define LIBSSH2_ERROR_INVAL                     -34
+#define LIBSSH2_ERROR_INVALID_POLL_TYPE         -35
+#define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL        -36
+#define LIBSSH2_ERROR_EAGAIN                    -37
+#define LIBSSH2_ERROR_BUFFER_TOO_SMALL          -38
+#define LIBSSH2_ERROR_BAD_USE                   -39
+#define LIBSSH2_ERROR_COMPRESS                  -40
+#define LIBSSH2_ERROR_OUT_OF_BOUNDARY           -41
+#define LIBSSH2_ERROR_AGENT_PROTOCOL            -42
+#define LIBSSH2_ERROR_SOCKET_RECV               -43
+#define LIBSSH2_ERROR_ENCRYPT                   -44
+#define LIBSSH2_ERROR_BAD_SOCKET                -45
+#define LIBSSH2_ERROR_KNOWN_HOSTS               -46
+#define LIBSSH2_ERROR_CHANNEL_WINDOW_FULL       -47
+#define LIBSSH2_ERROR_KEYFILE_AUTH_FAILED       -48
+
+/* this is a define to provide the old (<= 1.2.7) name */
+#define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV
+
+/* Global API */
+#define LIBSSH2_INIT_NO_CRYPTO        0x0001
+
+/*
+ * libssh2_init()
+ *
+ * Initialize the libssh2 functions.  This typically initialize the
+ * crypto library.  It uses a global state, and is not thread safe --
+ * you must make sure this function is not called concurrently.
+ *
+ * Flags can be:
+ * 0:                              Normal initialize
+ * LIBSSH2_INIT_NO_CRYPTO:         Do not initialize the crypto library (ie.
+ *                                 OPENSSL_add_cipher_algoritms() for OpenSSL
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int libssh2_init(int flags);
+
+/*
+ * libssh2_exit()
+ *
+ * Exit the libssh2 functions and free's all memory used internal.
+ */
+LIBSSH2_API void libssh2_exit(void);
+
+/*
+ * libssh2_free()
+ *
+ * Deallocate memory allocated by earlier call to libssh2 functions.
+ */
+LIBSSH2_API void libssh2_free(LIBSSH2_SESSION *session, void *ptr);
+
+/*
+ * libssh2_session_supported_algs()
+ *
+ * Fills algs with a list of supported acryptographic algorithms. Returns a
+ * non-negative number (number of supported algorithms) on success or a
+ * negative number (an eror code) on failure.
+ *
+ * NOTE: on success, algs must be deallocated (by calling libssh2_free) when
+ * not needed anymore
+ */
+LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
+                                               int method_type,
+                                               const char ***algs);
+
+/* Session API */
+LIBSSH2_API LIBSSH2_SESSION *
+libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
+                        LIBSSH2_FREE_FUNC((*my_free)),
+                        LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract);
+#define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL)
+
+LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session);
+
+LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session,
+                                               int cbtype, void *callback);
+LIBSSH2_API int libssh2_session_banner_set(LIBSSH2_SESSION *session,
+                                           const char *banner);
+LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session,
+                                   const char *banner);
+
+LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int sock);
+LIBSSH2_API int libssh2_session_handshake(LIBSSH2_SESSION *session,
+                                          libssh2_socket_t sock);
+LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session,
+                                              int reason,
+                                              const char *description,
+                                              const char *lang);
+#define libssh2_session_disconnect(session, description) \
+  libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, \
+                                (description), "")
+
+LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session);
+
+LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session,
+                                             int hash_type);
+
+LIBSSH2_API const char *libssh2_session_hostkey(LIBSSH2_SESSION *session,
+                                                size_t *len, int *type);
+
+LIBSSH2_API int libssh2_session_method_pref(LIBSSH2_SESSION *session,
+                                            int method_type,
+                                            const char *prefs);
+LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session,
+                                                int method_type);
+LIBSSH2_API int libssh2_session_last_error(LIBSSH2_SESSION *session,
+                                           char **errmsg,
+                                           int *errmsg_len, int want_buf);
+LIBSSH2_API int libssh2_session_last_errno(LIBSSH2_SESSION *session);
+LIBSSH2_API int libssh2_session_set_last_error(LIBSSH2_SESSION* session,
+                                               int errcode,
+                                               const char *errmsg);
+LIBSSH2_API int libssh2_session_block_directions(LIBSSH2_SESSION *session);
+
+LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag,
+                                     int value);
+LIBSSH2_API const char *libssh2_session_banner_get(LIBSSH2_SESSION *session);
+
+/* Userauth API */
+LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session,
+                                        const char *username,
+                                        unsigned int username_len);
+LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);
+
+LIBSSH2_API int
+libssh2_userauth_password_ex(LIBSSH2_SESSION *session,
+                             const char *username,
+                             unsigned int username_len,
+                             const char *password,
+                             unsigned int password_len,
+                             LIBSSH2_PASSWD_CHANGEREQ_FUNC
+                             ((*passwd_change_cb)));
+
+#define libssh2_userauth_password(session, username, password) \
+ libssh2_userauth_password_ex((session), (username),           \
+                              (unsigned int)strlen(username),  \
+                              (password), (unsigned int)strlen(password), NULL)
+
+LIBSSH2_API int
+libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
+                                       const char *username,
+                                       unsigned int username_len,
+                                       const char *publickey,
+                                       const char *privatekey,
+                                       const char *passphrase);
+
+#define libssh2_userauth_publickey_fromfile(session, username, publickey, \
+                                            privatekey, passphrase)     \
+    libssh2_userauth_publickey_fromfile_ex((session), (username),       \
+                                           (unsigned int)strlen(username), \
+                                           (publickey),                 \
+                                           (privatekey), (passphrase))
+
+LIBSSH2_API int
+libssh2_userauth_publickey(LIBSSH2_SESSION *session,
+                           const char *username,
+                           const unsigned char *pubkeydata,
+                           size_t pubkeydata_len,
+                           LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC
+                           ((*sign_callback)),
+                           void **abstract);
+
+LIBSSH2_API int
+libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session,
+                                       const char *username,
+                                       unsigned int username_len,
+                                       const char *publickey,
+                                       const char *privatekey,
+                                       const char *passphrase,
+                                       const char *hostname,
+                                       unsigned int hostname_len,
+                                       const char *local_username,
+                                       unsigned int local_username_len);
+
+#define libssh2_userauth_hostbased_fromfile(session, username, publickey, \
+                                            privatekey, passphrase, hostname) \
+ libssh2_userauth_hostbased_fromfile_ex((session), (username), \
+                                        (unsigned int)strlen(username), \
+                                        (publickey),                    \
+                                        (privatekey), (passphrase),     \
+                                        (hostname),                     \
+                                        (unsigned int)strlen(hostname), \
+                                        (username),                     \
+                                        (unsigned int)strlen(username))
+
+LIBSSH2_API int
+libssh2_userauth_publickey_frommemory(LIBSSH2_SESSION *session,
+                                      const char *username,
+                                      size_t username_len,
+                                      const char *publickeyfiledata,
+                                      size_t publickeyfiledata_len,
+                                      const char *privatekeyfiledata,
+                                      size_t privatekeyfiledata_len,
+                                      const char *passphrase);
+
+/*
+ * response_callback is provided with filled by library prompts array,
+ * but client must allocate and fill individual responses. Responses
+ * array is already allocated. Responses data will be freed by libssh2
+ * after callback return, but before subsequent callback invokation.
+ */
+LIBSSH2_API int
+libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session,
+                                         const char *username,
+                                         unsigned int username_len,
+                                         LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(
+                                                       (*response_callback)));
+
+#define libssh2_userauth_keyboard_interactive(session, username,        \
+                                              response_callback)        \
+    libssh2_userauth_keyboard_interactive_ex((session), (username),     \
+                                             (unsigned int)strlen(username), \
+                                             (response_callback))
+
+LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds,
+                             long timeout);
+
+/* Channel API */
+#define LIBSSH2_CHANNEL_WINDOW_DEFAULT  (2*1024*1024)
+#define LIBSSH2_CHANNEL_PACKET_DEFAULT  32768
+#define LIBSSH2_CHANNEL_MINADJUST       1024
+
+/* Extended Data Handling */
+#define LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL        0
+#define LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE        1
+#define LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE         2
+
+#define SSH_EXTENDED_DATA_STDERR 1
+
+/* Returned by any function that would block during a read/write opperation */
+#define LIBSSH2CHANNEL_EAGAIN LIBSSH2_ERROR_EAGAIN
+
+LIBSSH2_API LIBSSH2_CHANNEL *
+libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type,
+                        unsigned int channel_type_len,
+                        unsigned int window_size, unsigned int packet_size,
+                        const char *message, unsigned int message_len);
+
+#define libssh2_channel_open_session(session) \
+  libssh2_channel_open_ex((session), "session", sizeof("session") - 1, \
+                          LIBSSH2_CHANNEL_WINDOW_DEFAULT, \
+                          LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0)
+
+LIBSSH2_API LIBSSH2_CHANNEL *
+libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host,
+                                int port, const char *shost, int sport);
+#define libssh2_channel_direct_tcpip(session, host, port) \
+  libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22)
+
+LIBSSH2_API LIBSSH2_LISTENER *
+libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host,
+                                  int port, int *bound_port,
+                                  int queue_maxsize);
+#define libssh2_channel_forward_listen(session, port) \
+ libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16)
+
+LIBSSH2_API int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
+
+LIBSSH2_API LIBSSH2_CHANNEL *
+libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener);
+
+LIBSSH2_API int libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel,
+                                          const char *varname,
+                                          unsigned int varname_len,
+                                          const char *value,
+                                          unsigned int value_len);
+
+#define libssh2_channel_setenv(channel, varname, value)                 \
+    libssh2_channel_setenv_ex((channel), (varname),                     \
+                              (unsigned int)strlen(varname), (value),   \
+                              (unsigned int)strlen(value))
+
+LIBSSH2_API int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel,
+                                               const char *term,
+                                               unsigned int term_len,
+                                               const char *modes,
+                                               unsigned int modes_len,
+                                               int width, int height,
+                                               int width_px, int height_px);
+#define libssh2_channel_request_pty(channel, term)                      \
+    libssh2_channel_request_pty_ex((channel), (term),                   \
+                                   (unsigned int)strlen(term),          \
+                                   NULL, 0,                             \
+                                   LIBSSH2_TERM_WIDTH,                  \
+                                   LIBSSH2_TERM_HEIGHT,                 \
+                                   LIBSSH2_TERM_WIDTH_PX,               \
+                                   LIBSSH2_TERM_HEIGHT_PX)
+
+LIBSSH2_API int libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL *channel,
+                                                    int width, int height,
+                                                    int width_px,
+                                                    int height_px);
+#define libssh2_channel_request_pty_size(channel, width, height) \
+  libssh2_channel_request_pty_size_ex((channel), (width), (height), 0, 0)
+
+LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel,
+                                           int single_connection,
+                                           const char *auth_proto,
+                                           const char *auth_cookie,
+                                           int screen_number);
+#define libssh2_channel_x11_req(channel, screen_number) \
+ libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number))
+
+LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
+                                                const char *request,
+                                                unsigned int request_len,
+                                                const char *message,
+                                                unsigned int message_len);
+#define libssh2_channel_shell(channel) \
+  libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, \
+                                  NULL, 0)
+#define libssh2_channel_exec(channel, command) \
+  libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, \
+                                  (command), (unsigned int)strlen(command))
+#define libssh2_channel_subsystem(channel, subsystem) \
+  libssh2_channel_process_startup((channel), "subsystem",              \
+                                  sizeof("subsystem") - 1, (subsystem), \
+                                  (unsigned int)strlen(subsystem))
+
+LIBSSH2_API ssize_t libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel,
+                                            int stream_id, char *buf,
+                                            size_t buflen);
+#define libssh2_channel_read(channel, buf, buflen) \
+  libssh2_channel_read_ex((channel), 0, (buf), (buflen))
+#define libssh2_channel_read_stderr(channel, buf, buflen) \
+  libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
+
+LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel,
+                                          int extended);
+
+LIBSSH2_API unsigned long
+libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
+                               unsigned long *read_avail,
+                               unsigned long *window_size_initial);
+#define libssh2_channel_window_read(channel) \
+  libssh2_channel_window_read_ex((channel), NULL, NULL)
+
+/* libssh2_channel_receive_window_adjust is DEPRECATED, do not use! */
+LIBSSH2_API unsigned long
+libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
+                                      unsigned long adjustment,
+                                      unsigned char force);
+
+LIBSSH2_API int
+libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel,
+                                       unsigned long adjustment,
+                                       unsigned char force,
+                                       unsigned int *storewindow);
+
+LIBSSH2_API ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
+                                             int stream_id, const char *buf,
+                                             size_t buflen);
+
+#define libssh2_channel_write(channel, buf, buflen) \
+  libssh2_channel_write_ex((channel), 0, (buf), (buflen))
+#define libssh2_channel_write_stderr(channel, buf, buflen)              \
+    libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR,       \
+                             (buf), (buflen))
+
+LIBSSH2_API unsigned long
+libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel,
+                                unsigned long *window_size_initial);
+#define libssh2_channel_window_write(channel) \
+  libssh2_channel_window_write_ex((channel), NULL)
+
+LIBSSH2_API void libssh2_session_set_blocking(LIBSSH2_SESSION* session,
+                                              int blocking);
+LIBSSH2_API int libssh2_session_get_blocking(LIBSSH2_SESSION* session);
+
+LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel,
+                                              int blocking);
+
+LIBSSH2_API void libssh2_session_set_timeout(LIBSSH2_SESSION* session,
+                                             long timeout);
+LIBSSH2_API long libssh2_session_get_timeout(LIBSSH2_SESSION* session);
+
+/* libssh2_channel_handle_extended_data is DEPRECATED, do not use! */
+LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel,
+                                                      int ignore_mode);
+LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel,
+                                                      int ignore_mode);
+
+/* libssh2_channel_ignore_extended_data() is defined below for BC with version
+ * 0.1
+ *
+ * Future uses should use libssh2_channel_handle_extended_data() directly if
+ * LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read
+ * (FIFO) from the standard data channel
+ */
+/* DEPRECATED */
+#define libssh2_channel_ignore_extended_data(channel, ignore) \
+  libssh2_channel_handle_extended_data((channel),                       \
+                                       (ignore) ?                       \
+                                       LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : \
+                                       LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL)
+
+#define LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA     -1
+#define LIBSSH2_CHANNEL_FLUSH_ALL               -2
+LIBSSH2_API int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel,
+                                         int streamid);
+#define libssh2_channel_flush(channel) libssh2_channel_flush_ex((channel), 0)
+#define libssh2_channel_flush_stderr(channel) \
+ libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR)
+
+LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel);
+LIBSSH2_API int libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL* channel,
+                                                char **exitsignal,
+                                                size_t *exitsignal_len,
+                                                char **errmsg,
+                                                size_t *errmsg_len,
+                                                char **langtag,
+                                                size_t *langtag_len);
+LIBSSH2_API int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_eof(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel);
+
+/* libssh2_scp_recv is DEPRECATED, do not use! */
+LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
+                                              const char *path,
+                                              struct stat *sb);
+/* Use libssh2_scp_recv2 for large (> 2GB) file support on windows */
+LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv2(LIBSSH2_SESSION *session,
+                                               const char *path,
+                                               libssh2_struct_stat *sb);
+LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session,
+                                                 const char *path, int mode,
+                                                 size_t size, long mtime,
+                                                 long atime);
+LIBSSH2_API LIBSSH2_CHANNEL *
+libssh2_scp_send64(LIBSSH2_SESSION *session, const char *path, int mode,
+                   libssh2_int64_t size, time_t mtime, time_t atime);
+
+#define libssh2_scp_send(session, path, mode, size) \
+  libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0)
+
+LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest,
+                                      unsigned int *dest_len,
+                                      const char *src, unsigned int src_len);
+
+LIBSSH2_API
+const char *libssh2_version(int req_version_num);
+
+#define HAVE_LIBSSH2_KNOWNHOST_API 0x010101 /* since 1.1.1 */
+#define HAVE_LIBSSH2_VERSION_API   0x010100 /* libssh2_version since 1.1 */
+
+struct libssh2_knownhost {
+    unsigned int magic;  /* magic stored by the library */
+    void *node; /* handle to the internal representation of this host */
+    char *name; /* this is NULL if no plain text host name exists */
+    char *key;  /* key in base64/printable format */
+    int typemask;
+};
+
+/*
+ * libssh2_knownhost_init
+ *
+ * Init a collection of known hosts. Returns the pointer to a collection.
+ *
+ */
+LIBSSH2_API LIBSSH2_KNOWNHOSTS *
+libssh2_knownhost_init(LIBSSH2_SESSION *session);
+
+/*
+ * libssh2_knownhost_add
+ *
+ * Add a host and its associated key to the collection of known hosts.
+ *
+ * The 'type' argument specifies on what format the given host and keys are:
+ *
+ * plain  - ascii "hostname.domain.tld"
+ * sha1   - SHA1(<salt> <host>) base64-encoded!
+ * custom - another hash
+ *
+ * If 'sha1' is selected as type, the salt must be provided to the salt
+ * argument. This too base64 encoded.
+ *
+ * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files.  If
+ * a custom type is used, salt is ignored and you must provide the host
+ * pre-hashed when checking for it in the libssh2_knownhost_check() function.
+ *
+ * The keylen parameter may be omitted (zero) if the key is provided as a
+ * NULL-terminated base64-encoded string.
+ */
+
+/* host format (2 bits) */
+#define LIBSSH2_KNOWNHOST_TYPE_MASK    0xffff
+#define LIBSSH2_KNOWNHOST_TYPE_PLAIN   1
+#define LIBSSH2_KNOWNHOST_TYPE_SHA1    2 /* always base64 encoded */
+#define LIBSSH2_KNOWNHOST_TYPE_CUSTOM  3
+
+/* key format (2 bits) */
+#define LIBSSH2_KNOWNHOST_KEYENC_MASK     (3<<16)
+#define LIBSSH2_KNOWNHOST_KEYENC_RAW      (1<<16)
+#define LIBSSH2_KNOWNHOST_KEYENC_BASE64   (2<<16)
+
+/* type of key (3 bits) */
+#define LIBSSH2_KNOWNHOST_KEY_MASK         (15<<18)
+#define LIBSSH2_KNOWNHOST_KEY_SHIFT        18
+#define LIBSSH2_KNOWNHOST_KEY_RSA1         (1<<18)
+#define LIBSSH2_KNOWNHOST_KEY_SSHRSA       (2<<18)
+#define LIBSSH2_KNOWNHOST_KEY_SSHDSS       (3<<18)
+#define LIBSSH2_KNOWNHOST_KEY_ECDSA_256    (4<<18)
+#define LIBSSH2_KNOWNHOST_KEY_ECDSA_384    (5<<18)
+#define LIBSSH2_KNOWNHOST_KEY_ECDSA_521    (6<<18)
+#define LIBSSH2_KNOWNHOST_KEY_ED25519      (7<<18)
+#define LIBSSH2_KNOWNHOST_KEY_UNKNOWN      (15<<18)
+
+LIBSSH2_API int
+libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
+                      const char *host,
+                      const char *salt,
+                      const char *key, size_t keylen, int typemask,
+                      struct libssh2_knownhost **store);
+
+/*
+ * libssh2_knownhost_addc
+ *
+ * Add a host and its associated key to the collection of known hosts.
+ *
+ * Takes a comment argument that may be NULL.  A NULL comment indicates
+ * there is no comment and the entry will end directly after the key
+ * when written out to a file.  An empty string "" comment will indicate an
+ * empty comment which will cause a single space to be written after the key.
+ *
+ * The 'type' argument specifies on what format the given host and keys are:
+ *
+ * plain  - ascii "hostname.domain.tld"
+ * sha1   - SHA1(<salt> <host>) base64-encoded!
+ * custom - another hash
+ *
+ * If 'sha1' is selected as type, the salt must be provided to the salt
+ * argument. This too base64 encoded.
+ *
+ * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files.  If
+ * a custom type is used, salt is ignored and you must provide the host
+ * pre-hashed when checking for it in the libssh2_knownhost_check() function.
+ *
+ * The keylen parameter may be omitted (zero) if the key is provided as a
+ * NULL-terminated base64-encoded string.
+ */
+
+LIBSSH2_API int
+libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts,
+                       const char *host,
+                       const char *salt,
+                       const char *key, size_t keylen,
+                       const char *comment, size_t commentlen, int typemask,
+                       struct libssh2_knownhost **store);
+
+/*
+ * libssh2_knownhost_check
+ *
+ * Check a host and its associated key against the collection of known hosts.
+ *
+ * The type is the type/format of the given host name.
+ *
+ * plain  - ascii "hostname.domain.tld"
+ * custom - prehashed base64 encoded. Note that this cannot use any salts.
+ *
+ *
+ * 'knownhost' may be set to NULL if you don't care about that info.
+ *
+ * Returns:
+ *
+ * LIBSSH2_KNOWNHOST_CHECK_* values, see below
+ *
+ */
+
+#define LIBSSH2_KNOWNHOST_CHECK_MATCH    0
+#define LIBSSH2_KNOWNHOST_CHECK_MISMATCH 1
+#define LIBSSH2_KNOWNHOST_CHECK_NOTFOUND 2
+#define LIBSSH2_KNOWNHOST_CHECK_FAILURE  3
+
+LIBSSH2_API int
+libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
+                        const char *host, const char *key, size_t keylen,
+                        int typemask,
+                        struct libssh2_knownhost **knownhost);
+
+/* this function is identital to the above one, but also takes a port
+   argument that allows libssh2 to do a better check */
+LIBSSH2_API int
+libssh2_knownhost_checkp(LIBSSH2_KNOWNHOSTS *hosts,
+                         const char *host, int port,
+                         const char *key, size_t keylen,
+                         int typemask,
+                         struct libssh2_knownhost **knownhost);
+
+/*
+ * libssh2_knownhost_del
+ *
+ * Remove a host from the collection of known hosts. The 'entry' struct is
+ * retrieved by a call to libssh2_knownhost_check().
+ *
+ */
+LIBSSH2_API int
+libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts,
+                      struct libssh2_knownhost *entry);
+
+/*
+ * libssh2_knownhost_free
+ *
+ * Free an entire collection of known hosts.
+ *
+ */
+LIBSSH2_API void
+libssh2_knownhost_free(LIBSSH2_KNOWNHOSTS *hosts);
+
+/*
+ * libssh2_knownhost_readline()
+ *
+ * Pass in a line of a file of 'type'. It makes libssh2 read this line.
+ *
+ * LIBSSH2_KNOWNHOST_FILE_OPENSSH is the only supported type.
+ *
+ */
+LIBSSH2_API int
+libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
+                           const char *line, size_t len, int type);
+
+/*
+ * libssh2_knownhost_readfile
+ *
+ * Add hosts+key pairs from a given file.
+ *
+ * Returns a negative value for error or number of successfully added hosts.
+ *
+ * This implementation currently only knows one 'type' (openssh), all others
+ * are reserved for future use.
+ */
+
+#define LIBSSH2_KNOWNHOST_FILE_OPENSSH 1
+
+LIBSSH2_API int
+libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
+                           const char *filename, int type);
+
+/*
+ * libssh2_knownhost_writeline()
+ *
+ * Ask libssh2 to convert a known host to an output line for storage.
+ *
+ * Note that this function returns LIBSSH2_ERROR_BUFFER_TOO_SMALL if the given
+ * output buffer is too small to hold the desired output.
+ *
+ * This implementation currently only knows one 'type' (openssh), all others
+ * are reserved for future use.
+ *
+ */
+LIBSSH2_API int
+libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
+                            struct libssh2_knownhost *known,
+                            char *buffer, size_t buflen,
+                            size_t *outlen, /* the amount of written data */
+                            int type);
+
+/*
+ * libssh2_knownhost_writefile
+ *
+ * Write hosts+key pairs to a given file.
+ *
+ * This implementation currently only knows one 'type' (openssh), all others
+ * are reserved for future use.
+ */
+
+LIBSSH2_API int
+libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
+                            const char *filename, int type);
+
+/*
+ * libssh2_knownhost_get()
+ *
+ * Traverse the internal list of known hosts. Pass NULL to 'prev' to get
+ * the first one. Or pass a poiner to the previously returned one to get the
+ * next.
+ *
+ * Returns:
+ * 0 if a fine host was stored in 'store'
+ * 1 if end of hosts
+ * [negative] on errors
+ */
+LIBSSH2_API int
+libssh2_knownhost_get(LIBSSH2_KNOWNHOSTS *hosts,
+                      struct libssh2_knownhost **store,
+                      struct libssh2_knownhost *prev);
+
+#define HAVE_LIBSSH2_AGENT_API 0x010202 /* since 1.2.2 */
+
+struct libssh2_agent_publickey {
+    unsigned int magic;              /* magic stored by the library */
+    void *node;     /* handle to the internal representation of key */
+    unsigned char *blob;           /* public key blob */
+    size_t blob_len;               /* length of the public key blob */
+    char *comment;                 /* comment in printable format */
+};
+
+/*
+ * libssh2_agent_init
+ *
+ * Init an ssh-agent handle. Returns the pointer to the handle.
+ *
+ */
+LIBSSH2_API LIBSSH2_AGENT *
+libssh2_agent_init(LIBSSH2_SESSION *session);
+
+/*
+ * libssh2_agent_connect()
+ *
+ * Connect to an ssh-agent.
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int
+libssh2_agent_connect(LIBSSH2_AGENT *agent);
+
+/*
+ * libssh2_agent_list_identities()
+ *
+ * Request an ssh-agent to list identities.
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int
+libssh2_agent_list_identities(LIBSSH2_AGENT *agent);
+
+/*
+ * libssh2_agent_get_identity()
+ *
+ * Traverse the internal list of public keys. Pass NULL to 'prev' to get
+ * the first one. Or pass a poiner to the previously returned one to get the
+ * next.
+ *
+ * Returns:
+ * 0 if a fine public key was stored in 'store'
+ * 1 if end of public keys
+ * [negative] on errors
+ */
+LIBSSH2_API int
+libssh2_agent_get_identity(LIBSSH2_AGENT *agent,
+               struct libssh2_agent_publickey **store,
+               struct libssh2_agent_publickey *prev);
+
+/*
+ * libssh2_agent_userauth()
+ *
+ * Do publickey user authentication with the help of ssh-agent.
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int
+libssh2_agent_userauth(LIBSSH2_AGENT *agent,
+               const char *username,
+               struct libssh2_agent_publickey *identity);
+
+/*
+ * libssh2_agent_disconnect()
+ *
+ * Close a connection to an ssh-agent.
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int
+libssh2_agent_disconnect(LIBSSH2_AGENT *agent);
+
+/*
+ * libssh2_agent_free()
+ *
+ * Free an ssh-agent handle.  This function also frees the internal
+ * collection of public keys.
+ */
+LIBSSH2_API void
+libssh2_agent_free(LIBSSH2_AGENT *agent);
+
+/*
+ * libssh2_agent_set_identity_path()
+ *
+ * Allows a custom agent identity socket path beyond SSH_AUTH_SOCK env
+ *
+ */
+LIBSSH2_API void
+libssh2_agent_set_identity_path(LIBSSH2_AGENT *agent,
+                                const char *path);
+
+/*
+ * libssh2_agent_get_identity_path()
+ *
+ * Returns the custom agent identity socket path if set
+ *
+ */
+LIBSSH2_API const char *
+libssh2_agent_get_identity_path(LIBSSH2_AGENT *agent);
+
+/*
+ * libssh2_keepalive_config()
+ *
+ * Set how often keepalive messages should be sent.  WANT_REPLY
+ * indicates whether the keepalive messages should request a response
+ * from the server.  INTERVAL is number of seconds that can pass
+ * without any I/O, use 0 (the default) to disable keepalives.  To
+ * avoid some busy-loop corner-cases, if you specify an interval of 1
+ * it will be treated as 2.
+ *
+ * Note that non-blocking applications are responsible for sending the
+ * keepalive messages using libssh2_keepalive_send().
+ */
+LIBSSH2_API void libssh2_keepalive_config(LIBSSH2_SESSION *session,
+                                          int want_reply,
+                                          unsigned interval);
+
+/*
+ * libssh2_keepalive_send()
+ *
+ * Send a keepalive message if needed.  SECONDS_TO_NEXT indicates how
+ * many seconds you can sleep after this call before you need to call
+ * it again.  Returns 0 on success, or LIBSSH2_ERROR_SOCKET_SEND on
+ * I/O errors.
+ */
+LIBSSH2_API int libssh2_keepalive_send(LIBSSH2_SESSION *session,
+                                       int *seconds_to_next);
+
+/* NOTE NOTE NOTE
+   libssh2_trace() has no function in builds that aren't built with debug
+   enabled
+ */
+LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask);
+#define LIBSSH2_TRACE_TRANS (1<<1)
+#define LIBSSH2_TRACE_KEX   (1<<2)
+#define LIBSSH2_TRACE_AUTH  (1<<3)
+#define LIBSSH2_TRACE_CONN  (1<<4)
+#define LIBSSH2_TRACE_SCP   (1<<5)
+#define LIBSSH2_TRACE_SFTP  (1<<6)
+#define LIBSSH2_TRACE_ERROR (1<<7)
+#define LIBSSH2_TRACE_PUBLICKEY (1<<8)
+#define LIBSSH2_TRACE_SOCKET (1<<9)
+
+typedef void (*libssh2_trace_handler_func)(LIBSSH2_SESSION*,
+                                           void *,
+                                           const char *,
+                                           size_t);
+LIBSSH2_API int libssh2_trace_sethandler(LIBSSH2_SESSION *session,
+                                         void *context,
+                                         libssh2_trace_handler_func callback);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* !RC_INVOKED */
+
+#endif /* LIBSSH2_H */

+ 47 - 0
SATService/libssh2/include/libssh2_config.h

@@ -0,0 +1,47 @@
+#ifndef LIBSSH2_CONFIG_H
+#define LIBSSH2_CONFIG_H
+
+#ifndef WIN32
+#define WIN32
+#endif
+#ifndef _CRT_SECURE_NO_DEPRECATE
+#define _CRT_SECURE_NO_DEPRECATE 1
+#endif /* _CRT_SECURE_NO_DEPRECATE */
+#include <winsock2.h>
+#include <mswsock.h>
+#include <ws2tcpip.h>
+
+#ifdef __MINGW32__
+#define HAVE_UNISTD_H
+#define HAVE_INTTYPES_H
+#define HAVE_SYS_TIME_H
+#define HAVE_GETTIMEOFDAY
+#endif /* __MINGW32__ */
+
+#define HAVE_LIBCRYPT32
+#define HAVE_WINSOCK2_H
+#define HAVE_IOCTLSOCKET
+#define HAVE_SELECT
+
+#ifdef _MSC_VER
+#if _MSC_VER < 1900
+#define snprintf _snprintf
+#if _MSC_VER < 1500
+#define vsnprintf _vsnprintf
+#endif
+#define strdup _strdup
+#define strncasecmp _strnicmp
+#define strcasecmp _stricmp
+#endif
+#else
+#ifndef __MINGW32__
+#define strncasecmp strnicmp
+#define strcasecmp stricmp
+#endif /* __MINGW32__ */
+#endif /* _MSC_VER */
+
+/* Enable newer diffie-hellman-group-exchange-sha1 syntax */
+#define LIBSSH2_DH_GEX_NEW 1
+
+#endif /* LIBSSH2_CONFIG_H */
+

+ 122 - 0
SATService/libssh2/include/libssh2_publickey.h

@@ -0,0 +1,122 @@
+/* Copyright (c) 2004-2006, Sara Golemon <sarag@libssh2.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ *   Redistributions of source code must retain the above
+ *   copyright notice, this list of conditions and the
+ *   following disclaimer.
+ *
+ *   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.
+ *
+ *   Neither the name of the copyright holder nor the names
+ *   of any other contributors may be used to endorse or
+ *   promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "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 COPYRIGHT OWNER OR
+ * CONTRIBUTORS 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.
+ */
+
+/* Note: This include file is only needed for using the
+ * publickey SUBSYSTEM which is not the same as publickey
+ * authentication.  For authentication you only need libssh2.h
+ *
+ * For more information on the publickey subsystem,
+ * refer to IETF draft: secsh-publickey
+ */
+
+#ifndef LIBSSH2_PUBLICKEY_H
+#define LIBSSH2_PUBLICKEY_H 1
+
+#include "libssh2.h"
+
+typedef struct _LIBSSH2_PUBLICKEY               LIBSSH2_PUBLICKEY;
+
+typedef struct _libssh2_publickey_attribute {
+    const char *name;
+    unsigned long name_len;
+    const char *value;
+    unsigned long value_len;
+    char mandatory;
+} libssh2_publickey_attribute;
+
+typedef struct _libssh2_publickey_list {
+    unsigned char *packet; /* For freeing */
+
+    const unsigned char *name;
+    unsigned long name_len;
+    const unsigned char *blob;
+    unsigned long blob_len;
+    unsigned long num_attrs;
+    libssh2_publickey_attribute *attrs; /* free me */
+} libssh2_publickey_list;
+
+/* Generally use the first macro here, but if both name and value are string
+   literals, you can use _fast() to take advantage of preprocessing */
+#define libssh2_publickey_attribute(name, value, mandatory) \
+  { (name), strlen(name), (value), strlen(value), (mandatory) },
+#define libssh2_publickey_attribute_fast(name, value, mandatory) \
+  { (name), sizeof(name) - 1, (value), sizeof(value) - 1, (mandatory) },
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Publickey Subsystem */
+LIBSSH2_API LIBSSH2_PUBLICKEY *
+libssh2_publickey_init(LIBSSH2_SESSION *session);
+
+LIBSSH2_API int
+libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey,
+                         const unsigned char *name,
+                         unsigned long name_len,
+                         const unsigned char *blob,
+                         unsigned long blob_len, char overwrite,
+                         unsigned long num_attrs,
+                         const libssh2_publickey_attribute attrs[]);
+#define libssh2_publickey_add(pkey, name, blob, blob_len, overwrite,    \
+                              num_attrs, attrs)                         \
+  libssh2_publickey_add_ex((pkey), (name), strlen(name), (blob), (blob_len), \
+                           (overwrite), (num_attrs), (attrs))
+
+LIBSSH2_API int libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY *pkey,
+                                            const unsigned char *name,
+                                            unsigned long name_len,
+                                            const unsigned char *blob,
+                                            unsigned long blob_len);
+#define libssh2_publickey_remove(pkey, name, blob, blob_len) \
+  libssh2_publickey_remove_ex((pkey), (name), strlen(name), (blob), (blob_len))
+
+LIBSSH2_API int
+libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey,
+                             unsigned long *num_keys,
+                             libssh2_publickey_list **pkey_list);
+LIBSSH2_API void
+libssh2_publickey_list_free(LIBSSH2_PUBLICKEY *pkey,
+                            libssh2_publickey_list *pkey_list);
+
+LIBSSH2_API int libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY *pkey);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* ifndef: LIBSSH2_PUBLICKEY_H */

+ 351 - 0
SATService/libssh2/include/libssh2_sftp.h

@@ -0,0 +1,351 @@
+/* Copyright (c) 2004-2008, Sara Golemon <sarag@libssh2.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ *   Redistributions of source code must retain the above
+ *   copyright notice, this list of conditions and the
+ *   following disclaimer.
+ *
+ *   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.
+ *
+ *   Neither the name of the copyright holder nor the names
+ *   of any other contributors may be used to endorse or
+ *   promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "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 COPYRIGHT OWNER OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef LIBSSH2_SFTP_H
+#define LIBSSH2_SFTP_H 1
+
+#include "libssh2.h"
+
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Note: Version 6 was documented at the time of writing
+ * However it was marked as "DO NOT IMPLEMENT" due to pending changes
+ *
+ * Let's start with Version 3 (The version found in OpenSSH) and go from there
+ */
+#define LIBSSH2_SFTP_VERSION        3
+
+typedef struct _LIBSSH2_SFTP                LIBSSH2_SFTP;
+typedef struct _LIBSSH2_SFTP_HANDLE         LIBSSH2_SFTP_HANDLE;
+typedef struct _LIBSSH2_SFTP_ATTRIBUTES     LIBSSH2_SFTP_ATTRIBUTES;
+typedef struct _LIBSSH2_SFTP_STATVFS        LIBSSH2_SFTP_STATVFS;
+
+/* Flags for open_ex() */
+#define LIBSSH2_SFTP_OPENFILE           0
+#define LIBSSH2_SFTP_OPENDIR            1
+
+/* Flags for rename_ex() */
+#define LIBSSH2_SFTP_RENAME_OVERWRITE   0x00000001
+#define LIBSSH2_SFTP_RENAME_ATOMIC      0x00000002
+#define LIBSSH2_SFTP_RENAME_NATIVE      0x00000004
+
+/* Flags for stat_ex() */
+#define LIBSSH2_SFTP_STAT               0
+#define LIBSSH2_SFTP_LSTAT              1
+#define LIBSSH2_SFTP_SETSTAT            2
+
+/* Flags for symlink_ex() */
+#define LIBSSH2_SFTP_SYMLINK            0
+#define LIBSSH2_SFTP_READLINK           1
+#define LIBSSH2_SFTP_REALPATH           2
+
+/* Flags for sftp_mkdir() */
+#define LIBSSH2_SFTP_DEFAULT_MODE      -1
+
+/* SFTP attribute flag bits */
+#define LIBSSH2_SFTP_ATTR_SIZE              0x00000001
+#define LIBSSH2_SFTP_ATTR_UIDGID            0x00000002
+#define LIBSSH2_SFTP_ATTR_PERMISSIONS       0x00000004
+#define LIBSSH2_SFTP_ATTR_ACMODTIME         0x00000008
+#define LIBSSH2_SFTP_ATTR_EXTENDED          0x80000000
+
+/* SFTP statvfs flag bits */
+#define LIBSSH2_SFTP_ST_RDONLY              0x00000001
+#define LIBSSH2_SFTP_ST_NOSUID              0x00000002
+
+struct _LIBSSH2_SFTP_ATTRIBUTES {
+    /* If flags & ATTR_* bit is set, then the value in this struct will be
+     * meaningful Otherwise it should be ignored
+     */
+    unsigned long flags;
+
+    libssh2_uint64_t filesize;
+    unsigned long uid, gid;
+    unsigned long permissions;
+    unsigned long atime, mtime;
+};
+
+struct _LIBSSH2_SFTP_STATVFS {
+    libssh2_uint64_t  f_bsize;    /* file system block size */
+    libssh2_uint64_t  f_frsize;   /* fragment size */
+    libssh2_uint64_t  f_blocks;   /* size of fs in f_frsize units */
+    libssh2_uint64_t  f_bfree;    /* # free blocks */
+    libssh2_uint64_t  f_bavail;   /* # free blocks for non-root */
+    libssh2_uint64_t  f_files;    /* # inodes */
+    libssh2_uint64_t  f_ffree;    /* # free inodes */
+    libssh2_uint64_t  f_favail;   /* # free inodes for non-root */
+    libssh2_uint64_t  f_fsid;     /* file system ID */
+    libssh2_uint64_t  f_flag;     /* mount flags */
+    libssh2_uint64_t  f_namemax;  /* maximum filename length */
+};
+
+/* SFTP filetypes */
+#define LIBSSH2_SFTP_TYPE_REGULAR           1
+#define LIBSSH2_SFTP_TYPE_DIRECTORY         2
+#define LIBSSH2_SFTP_TYPE_SYMLINK           3
+#define LIBSSH2_SFTP_TYPE_SPECIAL           4
+#define LIBSSH2_SFTP_TYPE_UNKNOWN           5
+#define LIBSSH2_SFTP_TYPE_SOCKET            6
+#define LIBSSH2_SFTP_TYPE_CHAR_DEVICE       7
+#define LIBSSH2_SFTP_TYPE_BLOCK_DEVICE      8
+#define LIBSSH2_SFTP_TYPE_FIFO              9
+
+/*
+ * Reproduce the POSIX file modes here for systems that are not POSIX
+ * compliant.
+ *
+ * These is used in "permissions" of "struct _LIBSSH2_SFTP_ATTRIBUTES"
+ */
+/* File type */
+#define LIBSSH2_SFTP_S_IFMT         0170000     /* type of file mask */
+#define LIBSSH2_SFTP_S_IFIFO        0010000     /* named pipe (fifo) */
+#define LIBSSH2_SFTP_S_IFCHR        0020000     /* character special */
+#define LIBSSH2_SFTP_S_IFDIR        0040000     /* directory */
+#define LIBSSH2_SFTP_S_IFBLK        0060000     /* block special */
+#define LIBSSH2_SFTP_S_IFREG        0100000     /* regular */
+#define LIBSSH2_SFTP_S_IFLNK        0120000     /* symbolic link */
+#define LIBSSH2_SFTP_S_IFSOCK       0140000     /* socket */
+
+/* File mode */
+/* Read, write, execute/search by owner */
+#define LIBSSH2_SFTP_S_IRWXU        0000700     /* RWX mask for owner */
+#define LIBSSH2_SFTP_S_IRUSR        0000400     /* R for owner */
+#define LIBSSH2_SFTP_S_IWUSR        0000200     /* W for owner */
+#define LIBSSH2_SFTP_S_IXUSR        0000100     /* X for owner */
+/* Read, write, execute/search by group */
+#define LIBSSH2_SFTP_S_IRWXG        0000070     /* RWX mask for group */
+#define LIBSSH2_SFTP_S_IRGRP        0000040     /* R for group */
+#define LIBSSH2_SFTP_S_IWGRP        0000020     /* W for group */
+#define LIBSSH2_SFTP_S_IXGRP        0000010     /* X for group */
+/* Read, write, execute/search by others */
+#define LIBSSH2_SFTP_S_IRWXO        0000007     /* RWX mask for other */
+#define LIBSSH2_SFTP_S_IROTH        0000004     /* R for other */
+#define LIBSSH2_SFTP_S_IWOTH        0000002     /* W for other */
+#define LIBSSH2_SFTP_S_IXOTH        0000001     /* X for other */
+
+/* macros to check for specific file types, added in 1.2.5 */
+#define LIBSSH2_SFTP_S_ISLNK(m) \
+  (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFLNK)
+#define LIBSSH2_SFTP_S_ISREG(m) \
+  (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFREG)
+#define LIBSSH2_SFTP_S_ISDIR(m) \
+  (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFDIR)
+#define LIBSSH2_SFTP_S_ISCHR(m) \
+  (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFCHR)
+#define LIBSSH2_SFTP_S_ISBLK(m) \
+  (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFBLK)
+#define LIBSSH2_SFTP_S_ISFIFO(m) \
+  (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFIFO)
+#define LIBSSH2_SFTP_S_ISSOCK(m) \
+  (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFSOCK)
+
+/* SFTP File Transfer Flags -- (e.g. flags parameter to sftp_open())
+ * Danger will robinson... APPEND doesn't have any effect on OpenSSH servers */
+#define LIBSSH2_FXF_READ                        0x00000001
+#define LIBSSH2_FXF_WRITE                       0x00000002
+#define LIBSSH2_FXF_APPEND                      0x00000004
+#define LIBSSH2_FXF_CREAT                       0x00000008
+#define LIBSSH2_FXF_TRUNC                       0x00000010
+#define LIBSSH2_FXF_EXCL                        0x00000020
+
+/* SFTP Status Codes (returned by libssh2_sftp_last_error() ) */
+#define LIBSSH2_FX_OK                       0
+#define LIBSSH2_FX_EOF                      1
+#define LIBSSH2_FX_NO_SUCH_FILE             2
+#define LIBSSH2_FX_PERMISSION_DENIED        3
+#define LIBSSH2_FX_FAILURE                  4
+#define LIBSSH2_FX_BAD_MESSAGE              5
+#define LIBSSH2_FX_NO_CONNECTION            6
+#define LIBSSH2_FX_CONNECTION_LOST          7
+#define LIBSSH2_FX_OP_UNSUPPORTED           8
+#define LIBSSH2_FX_INVALID_HANDLE           9
+#define LIBSSH2_FX_NO_SUCH_PATH             10
+#define LIBSSH2_FX_FILE_ALREADY_EXISTS      11
+#define LIBSSH2_FX_WRITE_PROTECT            12
+#define LIBSSH2_FX_NO_MEDIA                 13
+#define LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM   14
+#define LIBSSH2_FX_QUOTA_EXCEEDED           15
+#define LIBSSH2_FX_UNKNOWN_PRINCIPLE        16 /* Initial mis-spelling */
+#define LIBSSH2_FX_UNKNOWN_PRINCIPAL        16
+#define LIBSSH2_FX_LOCK_CONFlICT            17 /* Initial mis-spelling */
+#define LIBSSH2_FX_LOCK_CONFLICT            17
+#define LIBSSH2_FX_DIR_NOT_EMPTY            18
+#define LIBSSH2_FX_NOT_A_DIRECTORY          19
+#define LIBSSH2_FX_INVALID_FILENAME         20
+#define LIBSSH2_FX_LINK_LOOP                21
+
+/* Returned by any function that would block during a read/write opperation */
+#define LIBSSH2SFTP_EAGAIN LIBSSH2_ERROR_EAGAIN
+
+/* SFTP API */
+LIBSSH2_API LIBSSH2_SFTP *libssh2_sftp_init(LIBSSH2_SESSION *session);
+LIBSSH2_API int libssh2_sftp_shutdown(LIBSSH2_SFTP *sftp);
+LIBSSH2_API unsigned long libssh2_sftp_last_error(LIBSSH2_SFTP *sftp);
+LIBSSH2_API LIBSSH2_CHANNEL *libssh2_sftp_get_channel(LIBSSH2_SFTP *sftp);
+
+/* File / Directory Ops */
+LIBSSH2_API LIBSSH2_SFTP_HANDLE *
+libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp,
+                     const char *filename,
+                     unsigned int filename_len,
+                     unsigned long flags,
+                     long mode, int open_type);
+#define libssh2_sftp_open(sftp, filename, flags, mode)                  \
+    libssh2_sftp_open_ex((sftp), (filename), strlen(filename), (flags), \
+                         (mode), LIBSSH2_SFTP_OPENFILE)
+#define libssh2_sftp_opendir(sftp, path) \
+    libssh2_sftp_open_ex((sftp), (path), strlen(path), 0, 0, \
+                         LIBSSH2_SFTP_OPENDIR)
+
+LIBSSH2_API ssize_t libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *handle,
+                                      char *buffer, size_t buffer_maxlen);
+
+LIBSSH2_API int libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE *handle, \
+                                        char *buffer, size_t buffer_maxlen,
+                                        char *longentry,
+                                        size_t longentry_maxlen,
+                                        LIBSSH2_SFTP_ATTRIBUTES *attrs);
+#define libssh2_sftp_readdir(handle, buffer, buffer_maxlen, attrs)      \
+    libssh2_sftp_readdir_ex((handle), (buffer), (buffer_maxlen), NULL, 0, \
+                            (attrs))
+
+LIBSSH2_API ssize_t libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *handle,
+                                       const char *buffer, size_t count);
+LIBSSH2_API int libssh2_sftp_fsync(LIBSSH2_SFTP_HANDLE *handle);
+
+LIBSSH2_API int libssh2_sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle);
+#define libssh2_sftp_close(handle) libssh2_sftp_close_handle(handle)
+#define libssh2_sftp_closedir(handle) libssh2_sftp_close_handle(handle)
+
+LIBSSH2_API void libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE *handle, size_t offset);
+LIBSSH2_API void libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle,
+                                     libssh2_uint64_t offset);
+#define libssh2_sftp_rewind(handle) libssh2_sftp_seek64((handle), 0)
+
+LIBSSH2_API size_t libssh2_sftp_tell(LIBSSH2_SFTP_HANDLE *handle);
+LIBSSH2_API libssh2_uint64_t libssh2_sftp_tell64(LIBSSH2_SFTP_HANDLE *handle);
+
+LIBSSH2_API int libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *handle,
+                                      LIBSSH2_SFTP_ATTRIBUTES *attrs,
+                                      int setstat);
+#define libssh2_sftp_fstat(handle, attrs) \
+    libssh2_sftp_fstat_ex((handle), (attrs), 0)
+#define libssh2_sftp_fsetstat(handle, attrs) \
+    libssh2_sftp_fstat_ex((handle), (attrs), 1)
+
+/* Miscellaneous Ops */
+LIBSSH2_API int libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp,
+                                       const char *source_filename,
+                                       unsigned int srouce_filename_len,
+                                       const char *dest_filename,
+                                       unsigned int dest_filename_len,
+                                       long flags);
+#define libssh2_sftp_rename(sftp, sourcefile, destfile) \
+    libssh2_sftp_rename_ex((sftp), (sourcefile), strlen(sourcefile), \
+                           (destfile), strlen(destfile),                \
+                           LIBSSH2_SFTP_RENAME_OVERWRITE | \
+                           LIBSSH2_SFTP_RENAME_ATOMIC | \
+                           LIBSSH2_SFTP_RENAME_NATIVE)
+
+LIBSSH2_API int libssh2_sftp_unlink_ex(LIBSSH2_SFTP *sftp,
+                                       const char *filename,
+                                       unsigned int filename_len);
+#define libssh2_sftp_unlink(sftp, filename) \
+    libssh2_sftp_unlink_ex((sftp), (filename), strlen(filename))
+
+LIBSSH2_API int libssh2_sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle,
+                                      LIBSSH2_SFTP_STATVFS *st);
+
+LIBSSH2_API int libssh2_sftp_statvfs(LIBSSH2_SFTP *sftp,
+                                     const char *path,
+                                     size_t path_len,
+                                     LIBSSH2_SFTP_STATVFS *st);
+
+LIBSSH2_API int libssh2_sftp_mkdir_ex(LIBSSH2_SFTP *sftp,
+                                      const char *path,
+                                      unsigned int path_len, long mode);
+#define libssh2_sftp_mkdir(sftp, path, mode) \
+    libssh2_sftp_mkdir_ex((sftp), (path), strlen(path), (mode))
+
+LIBSSH2_API int libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp,
+                                      const char *path,
+                                      unsigned int path_len);
+#define libssh2_sftp_rmdir(sftp, path) \
+    libssh2_sftp_rmdir_ex((sftp), (path), strlen(path))
+
+LIBSSH2_API int libssh2_sftp_stat_ex(LIBSSH2_SFTP *sftp,
+                                     const char *path,
+                                     unsigned int path_len,
+                                     int stat_type,
+                                     LIBSSH2_SFTP_ATTRIBUTES *attrs);
+#define libssh2_sftp_stat(sftp, path, attrs) \
+    libssh2_sftp_stat_ex((sftp), (path), strlen(path), LIBSSH2_SFTP_STAT, \
+                         (attrs))
+#define libssh2_sftp_lstat(sftp, path, attrs) \
+    libssh2_sftp_stat_ex((sftp), (path), strlen(path), LIBSSH2_SFTP_LSTAT, \
+                         (attrs))
+#define libssh2_sftp_setstat(sftp, path, attrs) \
+    libssh2_sftp_stat_ex((sftp), (path), strlen(path), LIBSSH2_SFTP_SETSTAT, \
+                         (attrs))
+
+LIBSSH2_API int libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp,
+                                        const char *path,
+                                        unsigned int path_len,
+                                        char *target,
+                                        unsigned int target_len,
+                                        int link_type);
+#define libssh2_sftp_symlink(sftp, orig, linkpath) \
+    libssh2_sftp_symlink_ex((sftp), (orig), strlen(orig), (linkpath), \
+                            strlen(linkpath), LIBSSH2_SFTP_SYMLINK)
+#define libssh2_sftp_readlink(sftp, path, target, maxlen) \
+    libssh2_sftp_symlink_ex((sftp), (path), strlen(path), (target), (maxlen), \
+    LIBSSH2_SFTP_READLINK)
+#define libssh2_sftp_realpath(sftp, path, target, maxlen) \
+    libssh2_sftp_symlink_ex((sftp), (path), strlen(path), (target), (maxlen), \
+                            LIBSSH2_SFTP_REALPATH)
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* LIBSSH2_SFTP_H */