diff --git a/uppsrc/Core/SSH/Core.cpp b/uppsrc/Core/SSH/Core.cpp index ac36bf558..bceaa5771 100644 --- a/uppsrc/Core/SSH/Core.cpp +++ b/uppsrc/Core/SSH/Core.cpp @@ -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; diff --git a/uppsrc/Core/SSH/Core.h b/uppsrc/Core/SSH/Core.h index 83fb4660b..89947a4f5 100644 --- a/uppsrc/Core/SSH/Core.h +++ b/uppsrc/Core/SSH/Core.h @@ -36,7 +36,7 @@ protected: LIBSSH2_SESSION* session; TcpSocket* socket; Tuple 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)); } diff --git a/uppsrc/Core/SSH/SFtp.cpp b/uppsrc/Core/SSH/SFtp.cpp index bd045ed57..54a1eb48c 100644 --- a/uppsrc/Core/SSH/SFtp.cpp +++ b/uppsrc/Core/SSH/SFtp.cpp @@ -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&& 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 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() diff --git a/uppsrc/Core/SSH/SFtp.h b/uppsrc/Core/SSH/SFtp.h index 8e3e9e048..57d726782 100644 --- a/uppsrc/Core/SSH/SFtp.h +++ b/uppsrc/Core/SSH/SFtp.h @@ -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(&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&& consumer, int size, int& done); bool Write(SFtpHandle handle, const void* buffer, int size, int& done); diff --git a/uppsrc/Core/SSH/Session.cpp b/uppsrc/Core/SSH/Session.cpp index 80a177bbe..68fba1fed 100644 --- a/uppsrc/Core/SSH/Session.cpp +++ b/uppsrc/Core/SSH/Session.cpp @@ -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;