mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Core/SSH: Minor fixes
git-svn-id: svn://ultimatepp.org/upp/trunk@12150 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
d54f56ad0c
commit
8e69471e00
4 changed files with 38 additions and 37 deletions
|
|
@ -136,9 +136,10 @@ bool Ssh::Do()
|
|||
dword Ssh::GetWaitEvents()
|
||||
{
|
||||
ssh->events = 0;
|
||||
if(ssh->socket && ssh->session)
|
||||
if(ssh->socket && ssh->session)
|
||||
ssh->events = libssh2_session_block_directions(ssh->session);
|
||||
return ssh->events;
|
||||
return !!(ssh->events & LIBSSH2_SESSION_BLOCK_INBOUND) * WAIT_READ +
|
||||
!!(ssh->events & LIBSSH2_SESSION_BLOCK_OUTBOUND) * WAIT_WRITE;
|
||||
}
|
||||
|
||||
bool Ssh::Cleanup(Error& e)
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ void SFtp::Exit()
|
|||
});
|
||||
}
|
||||
|
||||
int SFtp::FStat(SFtpHandle* handle, SFtpAttrs& a, bool set)
|
||||
int SFtp::FStat(SFtpHandle handle, SFtpAttrs& a, bool set)
|
||||
{
|
||||
auto rc = libssh2_sftp_fstat_ex(HANDLE(handle), &a, set);
|
||||
return WouldBlock(rc) ? 1 : rc;
|
||||
|
|
@ -60,7 +60,7 @@ int SFtp::LStat(const String& path, SFtpAttrs& a, int type)
|
|||
return WouldBlock(rc) ? 1 : rc;
|
||||
}
|
||||
|
||||
SFtpHandle* SFtp::Open(const String& path, dword flags, long mode)
|
||||
SFtpHandle SFtp::Open(const String& path, dword flags, long mode)
|
||||
{
|
||||
auto b = Cmd(SFTP_OPEN, [=]() mutable {
|
||||
ASSERT(sftp->session);
|
||||
|
|
@ -74,7 +74,7 @@ SFtpHandle* SFtp::Open(const String& path, dword flags, long mode)
|
|||
return b ? sftp->handle : NULL;
|
||||
}
|
||||
|
||||
bool SFtp::Close(SFtpHandle* handle)
|
||||
bool SFtp::Close(SFtpHandle handle)
|
||||
{
|
||||
return Cmd(SFTP_CLOSE, [=]() mutable {
|
||||
auto rc = libssh2_sftp_close_handle(HANDLE(handle));
|
||||
|
|
@ -114,7 +114,7 @@ bool SFtp::Delete(const String& path)
|
|||
});
|
||||
}
|
||||
|
||||
bool SFtp::Sync(SFtpHandle* handle)
|
||||
bool SFtp::Sync(SFtpHandle handle)
|
||||
{
|
||||
return Cmd(SFTP_SYNC, [=]() mutable {
|
||||
auto rc = libssh2_sftp_fsync(HANDLE(handle));
|
||||
|
|
@ -126,7 +126,7 @@ bool SFtp::Sync(SFtpHandle* handle)
|
|||
});
|
||||
}
|
||||
|
||||
SFtp& SFtp::Seek(SFtpHandle* handle, int64 position)
|
||||
SFtp& SFtp::Seek(SFtpHandle handle, int64 position)
|
||||
{
|
||||
Cmd(SFTP_SEEK, [=]() mutable {
|
||||
LLOG("Seeking to offset " << position);
|
||||
|
|
@ -136,7 +136,7 @@ SFtp& SFtp::Seek(SFtpHandle* handle, int64 position)
|
|||
return *this;
|
||||
}
|
||||
|
||||
int64 SFtp::GetPos(SFtpHandle* handle)
|
||||
int64 SFtp::GetPos(SFtpHandle handle)
|
||||
{
|
||||
Cmd(SFTP_TELL, [=]() mutable {
|
||||
sftp->value = (int64) libssh2_sftp_tell64(HANDLE(handle));
|
||||
|
|
@ -146,7 +146,7 @@ int64 SFtp::GetPos(SFtpHandle* handle)
|
|||
return !IsBlocking() ? Null : pick(sftp->value);
|
||||
}
|
||||
|
||||
bool SFtp::DataRead(SFtpHandle* handle, int64 size, Event<const void*, int>&& fn, bool str)
|
||||
bool SFtp::DataRead(SFtpHandle handle, int64 size, Event<const void*, int>&& fn, bool str)
|
||||
{
|
||||
if(OpCode() == SFTP_START) {
|
||||
if(FStat(HANDLE(handle), *sftp->finfo, false) <= 0) OpCode() = SFTP_GET;
|
||||
|
|
@ -186,7 +186,7 @@ bool SFtp::DataRead(SFtpHandle* handle, int64 size, Event<const void*, int>&& fn
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SFtp::DataWrite(SFtpHandle* handle, Stream& in, int64 size)
|
||||
bool SFtp::DataWrite(SFtpHandle handle, Stream& in, int64 size)
|
||||
{
|
||||
auto poke = size > 0;
|
||||
ssize_t write_size = poke ? size : in.GetSize();
|
||||
|
|
@ -212,7 +212,7 @@ bool SFtp::DataWrite(SFtpHandle* handle, Stream& in, int64 size)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SFtp::Get(SFtpHandle* handle, Stream& out)
|
||||
bool SFtp::Get(SFtpHandle handle, Stream& out)
|
||||
{
|
||||
sftp->done = 0;
|
||||
sftp->finfo = Null;
|
||||
|
|
@ -221,7 +221,7 @@ bool SFtp::Get(SFtpHandle* handle, Stream& out)
|
|||
});
|
||||
}
|
||||
|
||||
String SFtp::Get(SFtpHandle* handle)
|
||||
String SFtp::Get(SFtpHandle handle)
|
||||
{
|
||||
sftp->done = 0;
|
||||
sftp->finfo = Null;
|
||||
|
|
@ -261,7 +261,7 @@ String SFtp::Get(const String& path)
|
|||
return !IsBlocking() ? Null : pick(sftp->value);
|
||||
}
|
||||
|
||||
bool SFtp::Put(SFtpHandle* handle, Stream& in)
|
||||
bool SFtp::Put(SFtpHandle handle, Stream& in)
|
||||
{
|
||||
sftp->done = 0;
|
||||
return Cmd(SFTP_PUT, [=, &in]() mutable {
|
||||
|
|
@ -330,7 +330,7 @@ bool SFtp::Poke(const String& data, const String& path, int64 offset, int64 leng
|
|||
});
|
||||
}
|
||||
|
||||
SFtpHandle* SFtp::OpenDir(const String& path)
|
||||
SFtpHandle SFtp::OpenDir(const String& path)
|
||||
{
|
||||
auto b = Cmd(SFTP_OPENDIR, [=]() mutable {
|
||||
ASSERT(sftp->session);
|
||||
|
|
@ -370,7 +370,7 @@ bool SFtp::RemoveDir(const String& path)
|
|||
});
|
||||
}
|
||||
|
||||
bool SFtp::ListDir(SFtpHandle* handle, DirList& list)
|
||||
bool SFtp::ListDir(SFtpHandle handle, DirList& list)
|
||||
{
|
||||
return Cmd(SFTP_LISTDIR, [=, &list]() mutable {
|
||||
char label[512];
|
||||
|
|
@ -465,7 +465,7 @@ bool SFtp::SymLink(const String& path, String* target, int type)
|
|||
});
|
||||
}
|
||||
|
||||
bool SFtp::GetAttrs(SFtpHandle* handle, SFtpAttrs& attrs)
|
||||
bool SFtp::GetAttrs(SFtpHandle handle, SFtpAttrs& attrs)
|
||||
{
|
||||
return Cmd(SFTP_GET_STAT, [=, &attrs]() mutable {
|
||||
auto rc = FStat(handle, attrs, false);
|
||||
|
|
@ -485,7 +485,7 @@ bool SFtp::GetAttrs(const String& path, SFtpAttrs& attrs)
|
|||
});
|
||||
}
|
||||
|
||||
bool SFtp::SetAttrs(SFtpHandle* handle, const SFtpAttrs& attrs)
|
||||
bool SFtp::SetAttrs(SFtpHandle handle, const SFtpAttrs& attrs)
|
||||
{
|
||||
return Cmd(SFTP_SET_STAT, [=, &attrs]() mutable {
|
||||
auto rc = FStat(handle, const_cast<SFtpAttrs&>(attrs), true);
|
||||
|
|
|
|||
|
|
@ -85,23 +85,23 @@ public:
|
|||
Value GetResult() const { return sftp->value; }
|
||||
|
||||
// File
|
||||
SFtpHandle* Open(const String& path, dword flags, long mode);
|
||||
SFtpHandle* OpenRead(const String& path) { return Open(path, READ, IRALL); }
|
||||
SFtpHandle* OpenWrite(const String& path) { return Open(path, CREATE | WRITE, IRALL | IWUSR); }
|
||||
bool Close(SFtpHandle* handle);
|
||||
SFtpHandle Open(const String& path, dword flags, long mode);
|
||||
SFtpHandle OpenRead(const String& path) { return Open(path, READ, IRALL); }
|
||||
SFtpHandle OpenWrite(const String& path) { return Open(path, CREATE | WRITE, IRALL | IWUSR); }
|
||||
bool Close(SFtpHandle handle);
|
||||
bool Rename(const String& oldpath, const String& newpath);
|
||||
bool Delete(const String& path);
|
||||
bool Sync(SFtpHandle* handle);
|
||||
SFtp& Seek(SFtpHandle* handle, int64 position);
|
||||
int64 GetPos(SFtpHandle* handle);
|
||||
bool Sync(SFtpHandle handle);
|
||||
SFtp& Seek(SFtpHandle handle, int64 position);
|
||||
int64 GetPos(SFtpHandle handle);
|
||||
|
||||
// Read/Write
|
||||
bool Get(SFtpHandle* handle, Stream& out);
|
||||
bool Get(SFtpHandle handle, Stream& out);
|
||||
bool Get(const String& path, Stream& out);
|
||||
bool Get(const String& path, Stream& out, int64 offset);
|
||||
String Get(SFtpHandle* handle);
|
||||
String Get(SFtpHandle handle);
|
||||
String Get(const String& path);
|
||||
bool Put(SFtpHandle* handle, Stream& in);
|
||||
bool Put(SFtpHandle handle, Stream& in);
|
||||
bool Put(Stream& in, const String& path);
|
||||
bool Put(Stream& in, const String& path, dword flags, long mode);
|
||||
bool Put(Stream& in, const String& path, int64 offset);
|
||||
|
|
@ -111,10 +111,10 @@ public:
|
|||
bool Poke(const String& data, const String& path, int64 offset, int64 length);
|
||||
|
||||
// Directory
|
||||
SFtpHandle* OpenDir(const String& path);
|
||||
SFtpHandle OpenDir(const String& path);
|
||||
bool MakeDir(const String& path, long mode);
|
||||
bool RemoveDir(const String& path);
|
||||
bool ListDir(SFtpHandle* handle, DirList& list);
|
||||
bool ListDir(SFtpHandle handle, DirList& list);
|
||||
bool ListDir(const String& path, DirList& list);
|
||||
String GetWorkDir();
|
||||
|
||||
|
|
@ -124,9 +124,9 @@ public:
|
|||
bool RealizePath(const String& path, String& target) { return SymLink(path, &target, LIBSSH2_SFTP_REALPATH); }
|
||||
|
||||
// Attributes
|
||||
bool GetAttrs(SFtpHandle* handle, SFtpAttrs& attrs);
|
||||
bool GetAttrs(SFtpHandle handle, SFtpAttrs& attrs);
|
||||
bool GetAttrs(const String& path, SFtpAttrs& attrs);
|
||||
bool SetAttrs(SFtpHandle* handle, const SFtpAttrs& attrs);
|
||||
bool SetAttrs(SFtpHandle handle, const SFtpAttrs& attrs);
|
||||
bool SetAttrs(const String& path, const SFtpAttrs& attrs);
|
||||
DirEntry GetInfo(const String& path);
|
||||
bool SetInfo(const DirEntry& entry) { return SetAttrs(entry.GetName(), ~entry); }
|
||||
|
|
@ -172,20 +172,20 @@ private:
|
|||
void Exit() override;
|
||||
bool Cleanup(Error& e) override;
|
||||
|
||||
inline SFtpHandle* HANDLE(SFtpHandle* h) { return h ? h : sftp->handle; }
|
||||
int FStat(SFtpHandle* handle, SFtpAttrs& a, bool set);
|
||||
SFtpHandle HANDLE(SFtpHandle h) { return h ? h : sftp->handle; }
|
||||
int FStat(SFtpHandle handle, SFtpAttrs& a, bool set);
|
||||
int LStat(const String& path, SFtpAttrs& a, int type);
|
||||
bool QueryAttr(const String& path, int attr);
|
||||
bool ModifyAttr(const String& path, int attr, const Value& v);
|
||||
bool SymLink(const String& path, String* target, int type);
|
||||
bool DataRead(SFtpHandle* handle, int64 size, Event<const void*, int>&& fn, bool str = false);
|
||||
bool DataWrite(SFtpHandle* handle, Stream& out, int64 size);
|
||||
bool DataRead(SFtpHandle handle, int64 size, Event<const void*, int>&& fn, bool str = false);
|
||||
bool DataWrite(SFtpHandle handle, Stream& out, int64 size);
|
||||
static void StartAsync(int cmd, SshSession& session, const String& path, Stream& io,
|
||||
Gate<int64, int64, int64> progress, Event<int64, const void*, int> consumer = Null);
|
||||
|
||||
struct SFtpData {
|
||||
LIBSSH2_SFTP* session;
|
||||
SFtpHandle* handle;
|
||||
SFtpHandle handle;
|
||||
DirEntry finfo;
|
||||
Value value;
|
||||
StringStream stream;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Upp {
|
|||
|
||||
INITIALIZE(SSH);
|
||||
|
||||
using SFtpHandle = LIBSSH2_SFTP_HANDLE;
|
||||
using SFtpHandle = LIBSSH2_SFTP_HANDLE*;
|
||||
using SFtpAttrs = LIBSSH2_SFTP_ATTRIBUTES;
|
||||
using SshHost = libssh2_knownhost;
|
||||
using SshAgent = LIBSSH2_AGENT;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue