SFtp::SymLink parameters are now references instead of pointers & various other small changes.

git-svn-id: svn://ultimatepp.org/upp/trunk@12159 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
oblivion 2018-08-11 09:47:10 +00:00
parent f50acb57aa
commit fec49f573e
5 changed files with 22 additions and 32 deletions

View file

@ -55,7 +55,7 @@ void Ssh::Check()
SetError(-1, "Operation aborted.");
if(sock && ssh->socket->IsError())
SetError(-1, "Socket error. " << ssh->socket->GetErrorDesc());
SetError(-1, "[Socket error]: " << ssh->socket->GetErrorDesc());
}
bool Ssh::Run(Gate<>&& fn)
@ -104,7 +104,7 @@ dword Ssh::GetWaitEvents()
void Ssh::Wait()
{
while(!IsTimeout()) {
ssh->wait();
ssh->whenwait();
if(!ssh->socket)
return;
SocketWaitEvent we;

View file

@ -36,7 +36,7 @@ protected:
LIBSSH2_SESSION* session;
TcpSocket* socket;
Tuple<int, String> error;
Event<> wait;
Event<> whenwait;
bool init;
int64 oid;
int otype;
@ -55,8 +55,8 @@ protected:
virtual bool Init() { return true; }
virtual void Exit() {}
virtual void Check();
void Wait();
void Check();
bool Run(Gate<>&& fn);
bool WouldBlock(int rc) { return rc == LIBSSH2_ERROR_EAGAIN; }
bool WouldBlock() { return ssh->session && WouldBlock(libssh2_session_last_errno(ssh->session)); }

View file

@ -58,7 +58,6 @@ SFtpHandle SFtp::Open(const String& path, dword flags, long mode)
LLOG(Format("File '%s' is successfully opened.", path));
return h;
});
return h;
}
@ -70,7 +69,7 @@ bool SFtp::Close(SFtpHandle handle)
SetError(-1, "Unable to close file handle.");
if(rc == 0)
LLOG("File handle freed.");
return rc == 0;
return !rc;
});
}
@ -147,12 +146,9 @@ bool SFtp::Read(SFtpHandle handle, Event<const void*, int>&& consumer, int size,
SetError(-1, "Read aborted.");
ssh->start_time = msecs();
}
auto b = !rc || done == size;
if(b)
if(!rc)
LLOG("EOF received.");
return b;
return !rc || done == size;
}
bool SFtp::Write(SFtpHandle handle, const void* buffer, int size, int& done)
@ -168,11 +164,9 @@ bool SFtp::Write(SFtpHandle handle, const void* buffer, int size, int& done)
SetError(-1, "Write aborted.");
ssh->start_time = msecs();
}
auto b = !rc || done == size;
if(b)
if(!rc)
LLOG("EOF received.");
return b;
return !rc || done == size;;
}
int SFtp::Get(SFtpHandle handle, void *ptr, int size)
@ -200,7 +194,6 @@ bool SFtp::Put(SFtpHandle handle, const void *ptr, int size)
Run([=, &done]() mutable {
return Write(handle, (char*) ptr, size, done);
});
return done;
}
@ -240,7 +233,6 @@ SFtpHandle SFtp::OpenDir(const String& path)
LLOG(Format("Directory '%s' is successfully opened.", path));
return h;
});
return h;
}
@ -303,7 +295,6 @@ bool SFtp::ListDir(SFtpHandle handle, DirList& list)
while(rc > 0);
LLOG(Format("Directory listing is successful. (%d entries)", list.GetCount()));
return true;
});
}
@ -313,7 +304,7 @@ bool SFtp::ListDir(const String& path, DirList& list)
return h && ListDir(h, list) && Close(h);
}
bool SFtp::SymLink(const String& path, String* target, int type)
bool SFtp::SymLink(const String& path, String& target, int type)
{
Buffer<char> buffer(512);
@ -330,7 +321,7 @@ bool SFtp::SymLink(const String& path, String* target, int type)
if(!WouldBlock(rc) && rc != 0)
SetError(rc);
if(!rc) {
target->Set((const char*) buffer, rc);
target.Set(buffer, rc);
LLOG(Format("Symbolic link '%s' for path '%s' is successfult created.", target, path));
}
return !rc;
@ -349,7 +340,7 @@ bool SFtp::SymLink(const String& path, String* target, int type)
SetError(rc);
if(rc > 0) {
LLOG("Symbolic link operation is successful.");
target->Set(buffer, rc);
target.Set(buffer, rc);
}
return rc > 0;
});
@ -478,7 +469,6 @@ bool SFtp::ModifyAttr(const String& path, int attr, const Value& v)
default:
break;
}
return SetAttrs(path, ~finfo);;
}
@ -490,7 +480,7 @@ SFtp::SFtp(SshSession& session)
ssh->socket = &session.GetSocket();
ssh->timeout = session.GetTimeout();
ssh->waitstep = session.GetWaitStep();
ssh->wait = Proxy(session.WhenWait);
ssh->whenwait = Proxy(session.WhenWait);
}
SFtp::~SFtp()

View file

@ -106,9 +106,9 @@ public:
bool ListDir(SFtpHandle handle, DirList& list);
bool ListDir(const String& path, DirList& list);
// Symlink
bool MakeLink(const String& orig, const String& link) { return SymLink(orig, const_cast<String*>(&link), LIBSSH2_SFTP_SYMLINK); }
bool ReadLink(const String& path, String& target) { return SymLink(path, &target, LIBSSH2_SFTP_READLINK); }
bool RealizePath(const String& path, String& target) { return SymLink(path, &target, LIBSSH2_SFTP_REALPATH); }
bool MakeLink(const String& orig, String& target) { return SymLink(orig, target, LIBSSH2_SFTP_SYMLINK); }
bool ReadLink(const String& path, String& target) { return SymLink(path, target, LIBSSH2_SFTP_READLINK); }
bool RealizePath(const String& path, String& target) { return SymLink(path, target, LIBSSH2_SFTP_REALPATH); }
// Attributes
bool GetAttrs(SFtpHandle handle, SFtpAttrs& attrs);
@ -149,7 +149,7 @@ private:
int LStat(const String& path, SFtpAttrs& a, int type);
Value 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 SymLink(const String& path, String& target, int type);
bool Read(SFtpHandle handle, Event<const void*, int>&& consumer, int size, int& done);
bool Write(SFtpHandle handle, const void* buffer, int size, int& done);

View file

@ -150,7 +150,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const
if(!Run([=] () mutable {
#ifdef flagUSEMALLOC
LLOG("Using libssh2's memory managers.");
ssh->session = libssh2_session_init_ex(NULL, NULL, NULL, this);
ssh->session = libssh2_session_init_ex(nullptr, nullptr, nullptr, this);
#else
LLOG("Using Upp's memory managers.");
ssh->session = libssh2_session_init_ex((*ssh_malloc), (*ssh_free), (*ssh_realloc), this);
@ -318,7 +318,7 @@ ValueMap SshSession::GetMethods()
ValueMap methods;
if(ssh->session) {
for(int i = METHOD_EXCHANGE; i < METHOD_SCOMPRESSION; i++) {
const char **p = NULL;
const char **p = nullptr;
auto rc = libssh2_session_supported_algs(ssh->session, i, &p);
if(rc > 0) {
auto& v = methods(i);
@ -355,7 +355,7 @@ int SshSession::TryAgent(const String& username)
FreeAgent(agent);
SetError(-1, "Couldn't request identities to ssh-agent.");
}
libssh2_agent_publickey *id = NULL, *previd = NULL;
libssh2_agent_publickey *id = nullptr, *previd = nullptr;
for(;;) {
auto rc = libssh2_agent_get_identity(agent, &id, previd);
@ -369,7 +369,7 @@ int SshSession::TryAgent(const String& username)
username, id->comment));
}
else {
LLOG(Format("Authentication with username %s and public key %s succeeded.",
LLOG(Format("Authentication with username %s and public key %s succeesful.",
username, id->comment));
break;
}
@ -405,7 +405,7 @@ SshSession::SshSession()
{
session.Create();
ssh->otype = SESSION;
ssh->wait = Proxy(WhenWait);
ssh->whenwait = Proxy(WhenWait);
session->authmethod = PASSWORD;
session->connected = false;
session->keyfile = true;