diff --git a/uppsrc/Core/SSH/Channels.cpp b/uppsrc/Core/SSH/Channels.cpp index dd428bb66..75649c2e8 100644 --- a/uppsrc/Core/SSH/Channels.cpp +++ b/uppsrc/Core/SSH/Channels.cpp @@ -12,7 +12,7 @@ bool SshChannel::Init() LIBSSH2_CHANNEL *ch = libssh2_channel_open_session(ssh->session); if(!ch && !WouldBlock()) - SetError(-1); + ThrowError(-1); if(ch) { channel = MakeOne(ch); LLOG("A new channel is opened."); @@ -28,7 +28,7 @@ void SshChannel::Exit() Run([=]() mutable { int rc = libssh2_channel_free(*channel); if(!WouldBlock(rc) && rc < 0) - SetError(rc); + ThrowError(rc); if(!rc) { ssh->init = false; channel.Clear(); @@ -49,7 +49,7 @@ bool SshChannel::Close() { return Run([=]() mutable { int rc = libssh2_channel_close(*channel); - if(!WouldBlock(rc) && rc < 0) SetError(rc); + if(!WouldBlock(rc) && rc < 0) ThrowError(rc); if(!rc) LLOG("Channel close message is sent to the server."); return !rc; }); @@ -59,7 +59,7 @@ bool SshChannel::WaitClose() { return Run([=]() mutable { int rc = libssh2_channel_wait_closed(*channel); - if(!WouldBlock(rc) && rc < 0) SetError(rc); + if(!WouldBlock(rc) && rc < 0) ThrowError(rc); if(!rc) LLOG("Channel close message is acknowledged by the server."); return !rc; }); @@ -76,7 +76,7 @@ bool SshChannel::Request(const String& request, const String& params) params.GetLength() ); if(!WouldBlock(rc) && rc < 0) - SetError(rc); + ThrowError(rc); if(!rc) LLOG("\"" << request << "\" request (params: " << params << ") is successful."); return !rc; @@ -98,7 +98,7 @@ bool SshChannel::RequestTerminal(const String& term, int width, int height, cons LIBSSH2_TERM_HEIGHT_PX ); if(!WouldBlock(rc) && rc < 0) - SetError(rc); + ThrowError(rc); if(!rc) LLOG("Terminal (" << term << ") [W:" << width << ", H:" << height << "] opened."); return !rc; @@ -109,7 +109,7 @@ bool SshChannel::SetEnv(const String& variable, const String& value) { return Run([=]() mutable { int rc = libssh2_channel_setenv(*channel, variable, value); - if(!WouldBlock(rc) && rc < 0) SetError(rc); + if(!WouldBlock(rc) && rc < 0) ThrowError(rc); if(!rc) LLOG("Environment variable '" << variable << "' set to " << value); return !rc; }); @@ -119,7 +119,7 @@ bool SshChannel::PutEof() { return Run([=]() mutable { int rc = libssh2_channel_send_eof(*channel); - if(!WouldBlock(rc) && rc < 0) SetError(rc); + if(!WouldBlock(rc) && rc < 0) ThrowError(rc); if(!rc) LLOG("EOF message is sent to the server."); return !rc; }); @@ -129,7 +129,7 @@ bool SshChannel::GetEof() { return Run([=]() mutable { int rc = libssh2_channel_wait_eof(*channel); - if(!WouldBlock(rc) && rc < 0) SetError(rc); + if(!WouldBlock(rc) && rc < 0) ThrowError(rc); if(!rc) LLOG("EOF message is acknowledged by the server.");; return !rc; }); @@ -169,7 +169,7 @@ bool SshChannel::SetReadWindowSize(uint32 size, bool force) bool SshChannel::SetWndSz(uint32 size, bool force) { int rc = libssh2_channel_receive_window_adjust2(*channel, size, (unsigned char) force, nullptr); - if(!WouldBlock(rc) && rc < 0) SetError(rc); + if(!WouldBlock(rc) && rc < 0) ThrowError(rc); if(!rc) LLOG(Format("Receive window size set is to %d.", AsString(size))); return !rc; } @@ -205,9 +205,9 @@ int SshChannel::Get(void *ptr, int size, int sid) Run([=]() mutable { while(done < size && !IsEof() && !IsTimeout()) { int rc = Read(ptr, size, sid); - if(rc > 0) UpdateClient(); if(rc < 0) return false; if(!rc) break; + UpdateClient(); } return true; }); @@ -255,9 +255,9 @@ int SshChannel::Put(const void *ptr, int size, int sid) Run([=]() mutable { while(done < size && !IsEof() && !IsTimeout()) { int rc = Write(ptr, size, sid); - if(rc > 0) UpdateClient(); if(rc < 0) return false; if(!rc) break; + UpdateClient(); } return true; }); @@ -272,7 +272,7 @@ int SshChannel::Read(void *ptr, int size, int sid) libssh2_channel_read_ex(*channel, sid, (char*) ptr + done, size_t(sz)) ); if(rc < 0 && !WouldBlock(rc)) { - SetError(rc); + ThrowError(rc); } else if(rc > 0) { @@ -298,7 +298,7 @@ int SshChannel::Write(const void *ptr, int size, int sid) libssh2_channel_write_ex(*channel, sid, (const char*) ptr + done, size_t(sz)) ); if(rc < 0 && !WouldBlock(rc)) { - SetError(rc); + ThrowError(rc); } else if(rc > 0) { @@ -350,7 +350,7 @@ bool SshChannel::Shut(const String& msg, bool nowait) if(Close() && eof) WaitClose(); if(!IsNull(msg)) - ReportError(-1, msg); + SetError(-1, msg); return !IsError(); } diff --git a/uppsrc/Core/SSH/Core.cpp b/uppsrc/Core/SSH/Core.cpp index c88e413fc..a5ab6b3af 100644 --- a/uppsrc/Core/SSH/Core.cpp +++ b/uppsrc/Core/SSH/Core.cpp @@ -54,13 +54,13 @@ bool Ssh::Run(Gate<>&& fn, bool abortable) Mutex::Lock __(sLoopLock); if(IsTimeout()) - SetError(-1, "Operation timed out."); + ThrowError(-1, "Operation timed out."); if(abortable && ssh->status == ABORTED) - SetError(-1, "Operation aborted."); + ThrowError(-1, "Operation aborted."); if(ssh->socket && ssh->socket->IsError()) - SetError(-1, "[Socket error]: " << ssh->socket->GetErrorDesc()); + ThrowError(-1, "[Socket error]: " << ssh->socket->GetErrorDesc()); if(!ssh->init) ssh->init = Init(); @@ -77,10 +77,10 @@ bool Ssh::Run(Gate<>&& fn, bool abortable) ssh->status = IDLE; } catch(const Error& e) { - ReportError(e.code, e); + SetError(e.code, e); } catch(...) { - ReportError(-1, "Unhandled exception."); + SetError(-1, "Unhandled exception."); } return !IsError(); @@ -101,7 +101,7 @@ void Ssh::Wait() we.Wait(ssh->waitstep); } -void Ssh::SetError(int rc, const String& reason) +void Ssh::ThrowError(int rc, const String& reason) { if(IsNull(reason) && ssh && ssh->session) { Buffer libmsg(256, 0); @@ -112,7 +112,7 @@ void Ssh::SetError(int rc, const String& reason) throw Error(rc, reason); } -void Ssh::ReportError(int rc, const String& reason) +void Ssh::SetError(int rc, const String& reason) { ssh->status = FAILED; ssh->error.a = rc; diff --git a/uppsrc/Core/SSH/Core.h b/uppsrc/Core/SSH/Core.h index f0bddc0a7..4cc52f5ea 100644 --- a/uppsrc/Core/SSH/Core.h +++ b/uppsrc/Core/SSH/Core.h @@ -61,8 +61,8 @@ protected: bool WouldBlock(int rc) { return rc == LIBSSH2_ERROR_EAGAIN; } bool WouldBlock() { return ssh->session && WouldBlock(libssh2_session_last_errno(ssh->session)); } bool IsTimeout() const { return !IsNull(ssh->timeout) && ssh->timeout > 0 && msecs(ssh->start_time) >= ssh->timeout; } - void SetError(int rc, const String& reason = Null); - void ReportError(int rc, const String& reason); + void ThrowError(int rc, const String& reason = Null); + void SetError(int rc, const String& reason); void UpdateClient() { WhenWait ? WhenWait() : ssh->whenwait(); } private: diff --git a/uppsrc/Core/SSH/SFtp.cpp b/uppsrc/Core/SSH/SFtp.cpp index 8b34e1e2c..0848399a7 100644 --- a/uppsrc/Core/SSH/SFtp.cpp +++ b/uppsrc/Core/SSH/SFtp.cpp @@ -8,10 +8,10 @@ namespace Upp { bool SFtp::Init() { if(!ssh->session) - SetError(-1, "SSH session is invalid."); + ThrowError(-1, "SSH session is invalid."); auto session = libssh2_sftp_init(ssh->session); if(!session && !WouldBlock()) - SetError(-1); + ThrowError(-1); if(session) { sftp_session = MakeOne(session); LLOG("Session successfully initialized."); @@ -53,7 +53,7 @@ SFtpHandle SFtp::Open(const String& path, dword flags, long mode) Run([=, &h] () mutable { h = libssh2_sftp_open(*sftp_session, path, flags, mode); if(!h && !WouldBlock()) - SetError(-1); + ThrowError(-1); if(h) LLOG(Format("File '%s' is successfully opened.", path)); return h; @@ -78,7 +78,7 @@ bool SFtp::Rename(const String& oldpath, const String& newpath) return Run([=] () mutable { int rc = libssh2_sftp_rename(*sftp_session, oldpath, newpath); if(!WouldBlock(rc) && rc != 0) - SetError(rc); + ThrowError(rc); if(rc == 0) LLOG(Format("'%s' is successfully renamed to '%s'", oldpath, newpath)); return !rc; @@ -90,7 +90,7 @@ bool SFtp::Delete(const String& path) return Run([=] () mutable { int rc = libssh2_sftp_unlink(*sftp_session, path); if(!WouldBlock(rc) && rc != 0) - SetError(rc); + ThrowError(rc); if(rc == 0) LLOG(Format("File '%s' is successfully deleted.", path)); return !rc; @@ -102,7 +102,7 @@ bool SFtp::Sync(SFtpHandle handle) return Run([=] () mutable { int rc = libssh2_sftp_fsync(handle); if(!WouldBlock(rc) && rc != 0) - SetError(rc); + ThrowError(rc); if(rc == 0) LLOG("File successfully synchronized to disk."); return !rc; @@ -142,7 +142,7 @@ int SFtp::Get(SFtpHandle handle, void *ptr, int size) ); if(rc < 0) { if(!WouldBlock(rc)) - SetError(rc); + ThrowError(rc); return false; } else @@ -171,7 +171,7 @@ int SFtp::Put(SFtpHandle handle, const void *ptr, int size) ); if(rc < 0) { if(!WouldBlock(rc)) - SetError(rc); + ThrowError(rc); return false; } else @@ -254,7 +254,7 @@ SFtpHandle SFtp::OpenDir(const String& path) Run([=, &h] () mutable { h = libssh2_sftp_opendir(*sftp_session, path); if(!h && !WouldBlock()) - SetError(-1); + ThrowError(-1); if(h) LLOG(Format("Directory '%s' is successfully opened.", path)); return h; @@ -267,7 +267,7 @@ bool SFtp::MakeDir(const String& path, long mode) return Run([=] () mutable { int rc = libssh2_sftp_mkdir(*sftp_session, path, mode); if(!WouldBlock(rc) && rc != 0) - SetError(rc); + ThrowError(rc); if(!rc) LLOG(Format("Directory '%s' is succesfully created.", path)); return !rc; @@ -279,7 +279,7 @@ bool SFtp::RemoveDir(const String& path) return Run([=] () mutable { int rc = libssh2_sftp_rmdir(*sftp_session, path); if(!WouldBlock(rc) && rc != 0) - SetError(rc); + ThrowError(rc); if(!rc) LLOG(Format("Directory '%s' is succesfully deleted.", path)); return !rc; @@ -303,7 +303,7 @@ bool SFtp::ListDir(SFtpHandle handle, DirList& list) ); if(rc < 0) { if(!WouldBlock(rc)) - SetError(rc); + ThrowError(rc); break; } else @@ -349,7 +349,7 @@ bool SFtp::SymLink(const String& path, String& target, int type) type ); if(!WouldBlock(rc) && rc != 0) - SetError(rc); + ThrowError(rc); if(!rc) { target.Set(buffer, rc); LLOG(Format("Symbolic link '%s' for path '%s' is successfult created.", target, path)); @@ -368,7 +368,7 @@ bool SFtp::SymLink(const String& path, String& target, int type) type ); if(!WouldBlock(rc) && rc < 0) - SetError(rc); + ThrowError(rc); if(rc > 0) { target.Set(buffer, rc); LLOG("Symbolic link operation is successful. Target: " << target); @@ -394,7 +394,7 @@ bool SFtp::GetAttrs(SFtpHandle handle, SFtpAttrs& attrs) { return Run([=, &attrs] () mutable { int rc = FStat(handle, attrs, false); - if(rc < 0) SetError(rc); + if(rc < 0) ThrowError(rc); if(!rc) LLOG("File attributes successfully retrieved."); return !rc; }); @@ -404,7 +404,7 @@ bool SFtp::GetAttrs(const String& path, SFtpAttrs& attrs) { return Run([=, &path, &attrs] () mutable { int rc = LStat(path, attrs, LIBSSH2_SFTP_STAT); - if(rc < 0) SetError(rc); + if(rc < 0) ThrowError(rc); if(!rc) LLOG(Format("File attributes of '%s' is successfully retrieved.", path)); return !rc; }); @@ -414,7 +414,7 @@ bool SFtp::SetAttrs(SFtpHandle handle, const SFtpAttrs& attrs) { return Run([=, &attrs] () mutable { int rc = FStat(handle, const_cast(attrs), true); - if(rc < 0) SetError(rc); + if(rc < 0) ThrowError(rc); if(!rc) LLOG("File attributes successfully modified."); return !rc; }); @@ -424,7 +424,7 @@ bool SFtp::SetAttrs(const String& path, const SFtpAttrs& attrs) { return Run([=, &attrs] () mutable { int rc = LStat(path, const_cast(attrs), LIBSSH2_SFTP_SETSTAT); - if(rc < 0) SetError(rc); + if(rc < 0) ThrowError(rc); if(!rc) LLOG(Format("File attributes of '%s' is successfully modified.", path)); return !rc; }); diff --git a/uppsrc/Core/SSH/Scp.cpp b/uppsrc/Core/SSH/Scp.cpp index aca9e91ae..dc5b00693 100644 --- a/uppsrc/Core/SSH/Scp.cpp +++ b/uppsrc/Core/SSH/Scp.cpp @@ -12,7 +12,7 @@ bool Scp::OpenRead(const String& path, ScpAttrs& attrs) LIBSSH2_CHANNEL *ch = libssh2_scp_recv2(ssh->session, path, &attrs); if(!ch && !WouldBlock()) { LLOG("Unable to open file " << path); - SetError(-1); + ThrowError(-1); } if(ch) { channel = MakeOne(ch); @@ -28,7 +28,7 @@ bool Scp::OpenWrite(const String& path, int64 size, long mode) LIBSSH2_CHANNEL *ch = libssh2_scp_send64(ssh->session, path, mode, size, 0, 0); if(!ch && !WouldBlock()) { LLOG("Unable to open file " << path); - SetError(-1); + ThrowError(-1); } if(ch) { channel = MakeOne(ch); diff --git a/uppsrc/Core/SSH/Session.cpp b/uppsrc/Core/SSH/Session.cpp index bbeb0e833..a35b27908 100644 --- a/uppsrc/Core/SSH/Session.cpp +++ b/uppsrc/Core/SSH/Session.cpp @@ -101,7 +101,7 @@ bool SshSession::Connect(const String& url) auto b = findarg(u.scheme, "ssh", "sftp", "scp", "exec") >= 0 || (u.scheme.IsEmpty() && !u.host.IsEmpty()); int port = (u.port.IsEmpty() || !b) ? 22 : StrInt(u.port); if(b) return Connect(u.host, port, u.username, u.password); - ReportError(-1, "Malformed secure shell URL."); + SetError(-1, "Malformed secure shell URL."); return false; } @@ -111,7 +111,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const if(!Run([=, &ipinfo] () mutable { if(host.IsEmpty()) - SetError(-1, "Host is not specified."); + ThrowError(-1, "Host is not specified."); ssh->session = nullptr; session->socket.Timeout(0); if(!WhenProxy) { @@ -129,7 +129,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const if(ipinfo.InProgress()) return false; if(!ipinfo.GetResult()) - SetError(-1, "DNS lookup failed."); + ThrowError(-1, "DNS lookup failed."); WhenPhase(PHASE_CONNECTION); return true; })) goto Bailout; @@ -151,7 +151,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const else { if(!Run([=] () mutable { if(!WhenProxy()) - SetError(-1, "Proxy connection attempt failed."); + ThrowError(-1, "Proxy connection attempt failed."); LLOG("Proxy connection to " << host << ":" << port << " is successful."); return true; })) goto Bailout; @@ -166,7 +166,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const ssh->session = libssh2_session_init_ex(nullptr, nullptr, nullptr, this); #endif if(!ssh->session) - SetError(-1, "Failed to initalize libssh2 session."); + ThrowError(-1, "Failed to initalize libssh2 session."); #ifdef flagLIBSSH2TRACE if(libssh2_trace_sethandler(ssh->session, this, &ssh_session_libtrace)) LLOG("Warning: Unable to set trace (debug) handler for libssh2."); @@ -190,7 +190,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const int method = session->iomethods.GetKey(0); String mnames = GetMethodNames(method); int rc = libssh2_session_method_pref(ssh->session, method, ~mnames); - if(!WouldBlock(rc) && rc < 0) SetError(rc); + if(!WouldBlock(rc) && rc < 0) ThrowError(rc); if(!rc && !session->iomethods.IsEmpty()) { LLOG("Transport method: #" << method << " is set to [" << mnames << "]"); session->iomethods.Remove(0); @@ -201,7 +201,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const if(!Run([=] () mutable { int rc = libssh2_session_handshake(ssh->session, session->socket.GetSOCKET()); - if(!WouldBlock(rc) && rc < 0) SetError(rc); + if(!WouldBlock(rc) && rc < 0) ThrowError(rc); if(!rc) { LLOG("Handshake successful."); WhenPhase(PHASE_AUTHORIZATION); @@ -227,7 +227,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const break; } if(WhenVerify && !WhenVerify(host, port)) - SetError(-1); + ThrowError(-1); return true; })) goto Bailout; @@ -242,7 +242,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const } else if(!WouldBlock()) - SetError(-1); + ThrowError(-1); return false; } LLOG("Authentication methods list successfully retrieved: [" << session->authmethods << "]"); @@ -287,7 +287,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const break; case HOSTBASED: if(!session->keyfile) - SetError(-1, "Keys cannot be loaded from memory."); + ThrowError(-1, "Keys cannot be loaded from memory."); else rc = libssh2_userauth_hostbased_fromfile( ssh->session, @@ -311,7 +311,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const } if(rc != 0 && !WouldBlock(rc)) - SetError(rc); + ThrowError(rc); if(rc == 0 && libssh2_userauth_authenticated(ssh->session)) { LLOG("Client succesfully authenticated."); WhenPhase(PHASE_SUCCESS); @@ -421,14 +421,14 @@ int SshSession::TryAgent(const String& username) LLOG("Attempting to authenticate via ssh-agent..."); auto agent = libssh2_agent_init(ssh->session); if(!agent) - SetError(-1, "Couldn't initialize ssh-agent support."); + ThrowError(-1, "Couldn't initialize ssh-agent support."); if(libssh2_agent_connect(agent)) { libssh2_agent_free(agent); - SetError(-1, "Couldn't connect to ssh-agent."); + ThrowError(-1, "Couldn't connect to ssh-agent."); } if(libssh2_agent_list_identities(agent)) { FreeAgent(agent); - SetError(-1, "Couldn't request identities to ssh-agent."); + ThrowError(-1, "Couldn't request identities to ssh-agent."); } libssh2_agent_publickey *id = nullptr, *previd = nullptr; @@ -436,7 +436,7 @@ int SshSession::TryAgent(const String& username) auto rc = libssh2_agent_get_identity(agent, &id, previd); if(rc < 0) { FreeAgent(agent); - SetError(-1, "Unable to obtain identity from ssh-agent."); + ThrowError(-1, "Unable to obtain identity from ssh-agent."); } if(rc != 1) { if(libssh2_agent_userauth(agent, ~username, id)) { @@ -451,7 +451,7 @@ int SshSession::TryAgent(const String& username) } else { FreeAgent(agent); - SetError(-1, "Couldn't authenticate via ssh-agent"); + ThrowError(-1, "Couldn't authenticate via ssh-agent"); } previd = id; } diff --git a/uppsrc/Core/SSH/Shell.cpp b/uppsrc/Core/SSH/Shell.cpp index 8c17044bd..cf9885805 100644 --- a/uppsrc/Core/SSH/Shell.cpp +++ b/uppsrc/Core/SSH/Shell.cpp @@ -56,7 +56,7 @@ void SshShell::ReadWrite(String& in, const void* out, int out_len) auto rc = sigtimedwait(&set, nullptr, &timeout); if(rc < 0 && errno != EAGAIN) - SetError(-1, "sigtimedwait() failed."); + ThrowError(-1, "sigtimedwait() failed."); if(rc > 0) LLOG("SIGWINCH received."); resized = rc > 0; @@ -78,14 +78,14 @@ void SshShell::ReadWrite(String& in, const void* out, int out_len) case WAIT_ABANDONED: return; default: - SetError(-1, "WaitForSingleObject() failed."); + ThrowError(-1, "WaitForSingleObject() failed."); } DWORD n = 0; INPUT_RECORD ir[1]; if(!PeekConsoleInput(stdinput, ir, 1, &n)) - SetError(-1, "Unable to peek console input events."); + ThrowError(-1, "Unable to peek console input events."); if(n) { switch(ir[0].EventType) { case KEY_EVENT: @@ -103,10 +103,10 @@ void SshShell::ReadWrite(String& in, const void* out, int out_len) case FOCUS_EVENT: break; default: - SetError(-1, "Unknown console event type encountered."); + ThrowError(-1, "Unknown console event type encountered."); } if(!ReadConsoleInput(stdinput, ir, 1, &n)) - SetError(-1, "Unable to filter console input events."); + ThrowError(-1, "Unable to filter console input events."); } #endif break; @@ -142,10 +142,10 @@ bool SshShell::ConsoleInit() #ifdef PLATFORM_WIN32 stdinput = GetStdHandle(STD_INPUT_HANDLE); if(!stdinput) - SetError(-1, "Unable to obtain a handle for stdin."); + ThrowError(-1, "Unable to obtain a handle for stdin."); stdoutput = GetStdHandle(STD_OUTPUT_HANDLE); if(!stdoutput) - SetError(-1, "Unable to obtain a handle for stdout."); + ThrowError(-1, "Unable to obtain a handle for stdout."); #endif ConsoleRawMode(); return true; @@ -163,7 +163,7 @@ void SshShell::ConsoleRead() Send(String(buffer, n)); else if(n == -1 && errno != EAGAIN) - SetError(-1, "Couldn't read input from console."); + ThrowError(-1, "Couldn't read input from console."); } void SshShell::ConsoleWrite(const void* buffer, int len) @@ -172,7 +172,7 @@ void SshShell::ConsoleWrite(const void* buffer, int len) return; auto n = write(STDOUT_FILENO, buffer, size_t(len)); if(n == -1 && errno != EAGAIN) - SetError(-1, "Couldn't write output to console."); + ThrowError(-1, "Couldn't write output to console."); } void SshShell::ConsoleRawMode(bool b) @@ -213,7 +213,7 @@ void SshShell::ConsoleRead() const int RBUFSIZE = 1024 * 16; Buffer buffer(RBUFSIZE); if(!ReadConsole(stdinput, buffer, RBUFSIZE, &n, nullptr)) - SetError(-1, "Couldn't read input from console."); + ThrowError(-1, "Couldn't read input from console."); if(n > 0) Send(String(buffer, n)); } @@ -222,7 +222,7 @@ void SshShell::ConsoleWrite(const void* buffer, int len) { DWORD n = 0; if(!WriteConsole(stdoutput, buffer, len, &n, nullptr)) - SetError(-1, "Couldn't Write output to console."); + ThrowError(-1, "Couldn't Write output to console."); } void SshShell::ConsoleRawMode(bool b) @@ -265,12 +265,12 @@ bool SshShell::X11Init() #ifdef PLATFORM_POSIX int rc = libssh2_channel_x11_req(*channel, xscreen); if(!WouldBlock(rc) && rc < 0) - SetError(rc); + ThrowError(rc); if(!rc) LLOG("X11 tunnel succesfully initialized."); return !rc; #elif PLATFORM_WIN32 - SetError(-1, "X11 tunneling is not (yet) supported on Windows platform"); + ThrowError(-1, "X11 tunneling is not (yet) supported on Windows platform"); return false; #endif }); @@ -291,7 +291,7 @@ void SshShell::X11Loop() libssh2_channel_read(xhandle, xbuffer, size_t(xbuflen)) ); if(!WouldBlock(rc) && rc < 0) - SetError(-1, "[X11]: Read failed."); + ThrowError(-1, "[X11]: Read failed."); if(rc > 0) write(sock, xbuffer, rc); } diff --git a/uppsrc/Core/SSH/Tunnel.cpp b/uppsrc/Core/SSH/Tunnel.cpp index df2cfd300..fdfbc9777 100644 --- a/uppsrc/Core/SSH/Tunnel.cpp +++ b/uppsrc/Core/SSH/Tunnel.cpp @@ -16,7 +16,7 @@ bool SshTunnel::IsValid() default: NEVER(); } if(b) - ReportError(-1, "Invalid channel instance."); + SetError(-1, "Invalid channel instance."); return !b; } @@ -27,7 +27,7 @@ void SshTunnel::Exit() Run([=]() mutable{ int rc = libssh2_channel_forward_cancel(*listener); - if(!WouldBlock(rc) && rc < 0) SetError(rc); + if(!WouldBlock(rc) && rc < 0) ThrowError(rc); if(rc == 0) listener.Clear(); return !rc; }); @@ -42,7 +42,7 @@ bool SshTunnel::Connect(const String& host, int port) return Run([=]() mutable{ LIBSSH2_CHANNEL *ch = libssh2_channel_direct_tcpip(ssh->session, host , port); - if(!ch && !WouldBlock()) SetError(-1); + if(!ch && !WouldBlock()) ThrowError(-1); if(ch) { channel = MakeOne(ch); LLOG("Direct tcp-ip connection to " << host << ":" << port << " is established."); @@ -56,7 +56,7 @@ bool SshTunnel::Connect(const String& url) UrlInfo u(url); if(!u.host.IsEmpty() && u.port.IsEmpty()) return Connect(u.host, StrInt(u.port)); - ReportError(-1, "Malformed proxy connection URL."); + SetError(-1, "Malformed proxy connection URL."); return false; } @@ -76,7 +76,7 @@ bool SshTunnel::Listen(const String& host, int port, int* bound_port, int listen listen_count ); if(!lsn && !WouldBlock()) - SetError(-1); + ThrowError(-1); if(lsn) { listener = MakeOne(lsn); LLOG("Started listening on port #" << port); @@ -93,13 +93,13 @@ bool SshTunnel::Accept(SshTunnel& listener) return false; if(!listener.listener) { - ReportError(-1, "Invalid listener."); + SetError(-1, "Invalid listener."); return false; } return Run([=, &listener]() mutable { LIBSSH2_CHANNEL *ch = libssh2_channel_forward_accept(*listener.listener); - if(!ch && !WouldBlock()) SetError(-1); + if(!ch && !WouldBlock()) ThrowError(-1); if(ch) { channel = MakeOne(ch); LLOG("Connection accepted.");