Commit cc1142c5 authored by Jekyll Wu's avatar Jekyll Wu
Browse files

Prepare the whole command before sending it by calling Session::sendText()

That reduces the number of calling, and also make the code easier to
debug if something goes wrong with the command

TODO: there is code duplication between class Application and class
SessionController on how to compose and send ssh command based upon a
KUrl using the ssh:// protocol.
parent 2af5c3b9
......@@ -478,14 +478,18 @@ Session* Application::createSSHSession(Profile::Ptr profile, const KUrl& url,
Session* session = SessionManager::instance()->createSession(profile);
session->sendText("ssh ");
if (url.port() > -1)
session->sendText("-p " + QString::number(url.port()) + ' ');
if (url.hasUser())
session->sendText(url.user() + '@');
if (url.hasHost())
session->sendText(url.host() + '\r');
QString sshCommand = "ssh ";
if (url.port() > -1) {
sshCommand += QString("-p %1 ").arg(url.port()) ;
}
if (url.hasUser()) {
sshCommand += (url.user() + '@');
}
if (url.hasHost()) {
sshCommand += url.host();
}
session->sendText(sshCommand + '\r');
// create view before starting the session process so that the session
// doesn't suffer a change in terminal size right after the session
......
......@@ -270,24 +270,35 @@ void SessionController::openUrl(const KUrl& url)
if (!command.isEmpty())
_session->emulation()->sendText(command + '\r');
} else if (url.protocol() == "ssh") {
_session->emulation()->sendText("ssh ");
if (url.port() > -1)
_session->emulation()->sendText("-p " + QString::number(url.port()) + ' ');
if (url.hasUser())
_session->emulation()->sendText(url.user() + '@');
if (url.hasHost())
_session->emulation()->sendText(url.host() + '\r');
QString sshCommand = "ssh ";
if (url.port() > -1) {
sshCommand += QString("-p %1 ").arg(url.port()) ;
}
if (url.hasUser()) {
sshCommand += (url.user() + '@');
}
if (url.hasHost()) {
sshCommand += url.host();
}
_session->sendText(sshCommand + '\r');
} else if (url.protocol() == "telnet") {
_session->emulation()->sendText("telnet ");
if (url.hasUser())
_session->emulation()->sendText("-l " + url.user() + ' ');
if (url.hasHost())
_session->emulation()->sendText(url.host() + ' ');
if (url.port() > -1)
_session->emulation()->sendText(QString::number(url.port()));
_session->emulation()->sendText("\r");
QString telnetCommand = "telnet ";
if (url.hasUser()) {
telnetCommand += QString("-l %1 ").arg(url.user()) ;
}
if (url.hasHost()) {
telnetCommand += (url.host() + ' ');
}
if (url.port() > -1) {
telnetCommand += QString::number(url.port()) ;
}
_session->sendText(telnetCommand + '\r');
} else {
//TODO Implement handling for other Url types
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment