Skip to content

Commit 67edc13

Browse files
committed
Fix the issue that the SSH connection cannot be reconnected by tapping the Enter key in some cases
Signed-off-by: xiaoming <2014500726@smail.xtu.edu.cn>
1 parent daceb0d commit 67edc13

16 files changed

+168
-58
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ en-US:
99
- Add logging information to the status bar
1010
- Add emphasized color border to the activated session in split screen mode
1111
- Fix the issue that clicking the new tab button in split screen mode may not create the session correctly or be located under the wrong tab group
12+
- Fix the issue that the SSH connection cannot be reconnected by tapping the Enter key in some cases
1213

1314
zh-CN:
1415

@@ -17,6 +18,7 @@ zh-CN:
1718
- 增加状态栏日志信息
1819
- 分屏模式下激活的会话增加强调色边框
1920
- 修复分屏模式下某些情况点击新标签按钮会话未正确创建或位于错误的标签页组下
21+
- 修复ssh连接部分情况下无法通过敲击回车键发起重连的问题
2022

2123
## [[V0.4.8](https://github.com/QQxiaoming/quardCRT/releases/tag/V0.4.8)] - 2024-07-26
2224

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Add logging information to the status bar
1010
- Add emphasized color border to the activated session in split screen mode
1111
- Fix the issue that clicking the new tab button in split screen mode may not create the session correctly or be located under the wrong tab group
12+
- Fix the issue that the SSH connection cannot be reconnected by tapping the Enter key in some cases
1213

1314
## [[V0.4.8](https://github.com/QQxiaoming/quardCRT/releases/tag/V0.4.8)] - 2024-07-26
1415

lib/qtssh/sshclient.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ SshClient::SshClient(const QString &name, QObject * parent):
7070
m_name(name),
7171
m_socket(this)
7272
{
73+
m_sshErrorString = "Unknown LIBSSH2 ERROR";
7374
/* New implementation */
7475
QObject::connect(this, &SshClient::sshEvent, this, &SshClient::_ssh_processEvent, Qt::QueuedConnection);
7576
QObject::connect(&m_socket, &QTcpSocket::connected, this, &SshClient::_connection_socketConnected);
@@ -262,12 +263,14 @@ void SshClient::_sendKeepAlive()
262263
if(ret == LIBSSH2_ERROR_SOCKET_SEND)
263264
{
264265
qCWarning(sshclient) << m_name << ": Connection I/O error !!!";
266+
setSSHErrorString("Connection I/O error !!!");
265267
m_socket.disconnectFromHost();
266268
}
267269
else if(((QDateTime::currentMSecsSinceEpoch() - m_lastProofOfLive) / 1000) > (MAX_LOST_KEEP_ALIVE * keepalive))
268270
{
269271
qCWarning(sshclient) << m_name << ": Connection lost !!!";
270272
setSshState(SshState::Error);
273+
setSSHErrorString("Connection lost !!!");
271274
m_socket.disconnectFromHost();
272275
}
273276
else
@@ -307,13 +310,15 @@ void SshClient::_connection_socketTimeout()
307310
m_connectionTimeout.stop();
308311
m_socket.disconnectFromHost();
309312
qCWarning(sshclient) << m_name << ": ssh socket connection timeout";
313+
setSSHErrorString("SSH socket connection timeout");
310314
setSshState(SshState::Error);
311315
emit sshEvent();
312316
}
313317

314318
void SshClient::_connection_socketError()
315319
{
316320
qCWarning(sshclient) << m_name << ": ssh socket connection error:" << m_sshState;
321+
setSSHErrorString(QString("SSH socket connection error: %1").arg(m_sshState));
317322
setSshState(SshState::Error);
318323
emit sshEvent();
319324
}
@@ -331,6 +336,7 @@ void SshClient::_connection_socketConnected()
331336
else
332337
{
333338
qCWarning(sshclient) << m_name << ": Unknown conenction on socket";
339+
setSSHErrorString("Unknown conenction on socket");
334340
setSshState(SshState::Error);
335341
emit sshEvent();
336342
}
@@ -381,6 +387,7 @@ void SshClient::_ssh_processEvent()
381387
if(m_session == nullptr)
382388
{
383389
qCCritical(sshclient) << m_name << ": libssh error during session init";
390+
setSSHErrorString(QString("libssh error during session init"));
384391
setSshState(SshState::Error);
385392
m_socket.disconnectFromHost();
386393
return;
@@ -410,7 +417,9 @@ void SshClient::_ssh_processEvent()
410417
}
411418
if(ret != 0)
412419
{
413-
qCCritical(sshclient) << m_name << "Handshake error" << sshErrorToString(ret);
420+
QString errStr(sshErrorToString(ret));
421+
setSSHErrorString(errStr);
422+
qCCritical(sshclient) << m_name << "Handshake error" << errStr;
414423
setSshState(SshState::Error);
415424
m_socket.disconnectFromHost();
416425
return;
@@ -423,6 +432,7 @@ void SshClient::_ssh_processEvent()
423432
if(fingerprint == nullptr)
424433
{
425434
qCCritical(sshclient) << m_name << "Fingerprint error";
435+
setSSHErrorString("Fingerprint error");
426436
setSshState(SshState::Error);
427437
m_socket.disconnectFromHost();
428438
return;
@@ -462,9 +472,11 @@ void SshClient::_ssh_processEvent()
462472
{
463473
return;
464474
}
475+
QString errStr(sshErrorToString(ret));
476+
setSSHErrorString(errStr);
477+
qCDebug(sshclient) << m_name << ": Failed to authenticate:" << errStr;
465478
setSshState(SshState::Error);
466479
m_socket.disconnectFromHost();
467-
qCDebug(sshclient) << m_name << ": Failed to authenticate:" << sshErrorToString(ret);
468480
return;
469481
}
470482
qCDebug(sshclient) << m_name << ": ssh start authentication userauth_list: " << alist;
@@ -496,7 +508,9 @@ void SshClient::_ssh_processEvent()
496508
}
497509
if(ret < 0)
498510
{
499-
qCWarning(sshclient) << m_name << ": Authentication with publickey failed:" << sshErrorToString(ret);
511+
QString errStr(sshErrorToString(ret));
512+
setSSHErrorString(errStr);
513+
qCWarning(sshclient) << m_name << ": Authentication with publickey failed:" << errStr;
500514
m_authenticationMethodes.removeFirst();
501515
}
502516
if(ret == 0)
@@ -552,6 +566,7 @@ void SshClient::_ssh_processEvent()
552566
{
553567
qCWarning(sshclient) << m_name << ": Authentication failed";
554568
m_socket.disconnectFromHost();
569+
setSSHErrorString("Authentication failed");
555570
setSshState(SshState::Error);
556571
return;
557572
}

lib/qtssh/sshclient.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,18 @@ private slots:
154154

155155
void setConnectTimeout(int timeoutMsec);
156156

157+
QString sshErrorString() const {
158+
return m_sshErrorString;
159+
}
160+
void setSSHErrorString(const QString &sshErrorString) {
161+
m_sshErrorString = sshErrorString;
162+
}
163+
157164
private: /* New function implementation with state machine */
158165
SshState m_sshState {SshState::Unconnected};
159166
QByteArrayList m_authenticationMethodes;
160167
void setSshState(const SshState &sshState);
161-
168+
QString m_sshErrorString;
162169

163170
private slots: /* New function implementation with state machine */
164171
void _connection_socketTimeout();

lib/qtssh/sshprocess.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ void SshProcess::sshDataReceived()
121121
{
122122
if(!m_error)
123123
{
124+
QString errStr(sshErrorToString(static_cast<int>(retsz)));
125+
sshClient()->setSSHErrorString(errStr);
124126
m_error = true;
125-
m_errMsg << QString("Can't read result (%1)").arg(sshErrorToString(static_cast<int>(retsz)));
127+
m_errMsg << QString("Can't read result (%1)").arg(errStr);
126128
emit failed();
127-
qCWarning(logsshprocess) << "Can't read result (" << sshErrorToString(static_cast<int>(retsz)) << ")";
129+
qCWarning(logsshprocess) << "Can't read result (" << errStr << ")";
128130
}
129131
setChannelState(ChannelState::Close);
130132
sshDataReceived();
@@ -142,10 +144,12 @@ void SshProcess::sshDataReceived()
142144
{
143145
if(!m_error)
144146
{
147+
QString errStr(sshErrorToString(static_cast<int>(retsz)));
148+
sshClient()->setSSHErrorString(errStr);
145149
m_error = true;
146-
m_errMsg << QString("Can't read stderr msg (%1)").arg(sshErrorToString(static_cast<int>(retsz)));
150+
m_errMsg << QString("Can't read stderr msg (%1)").arg(errStr);
147151
emit failed();
148-
qCWarning(logsshprocess) << "Can't read stderr msg (" << sshErrorToString(static_cast<int>(retsz)) << ")";
152+
qCWarning(logsshprocess) << "Can't read stderr msg (" << errStr << ")";
149153
}
150154
setChannelState(ChannelState::Close);
151155
sshDataReceived();
@@ -182,10 +186,12 @@ void SshProcess::sshDataReceived()
182186
{
183187
if(!m_error)
184188
{
189+
QString errStr(sshErrorToString(ret));
190+
sshClient()->setSSHErrorString(errStr);
185191
m_error = true;
186-
m_errMsg << QString("Failed to channel_close: %1").arg(sshErrorToString(ret));
192+
m_errMsg << QString("Failed to channel_close: %1").arg(errStr);
187193
emit failed();
188-
qCWarning(logsshprocess) << "Failed to channel_close: " << sshErrorToString(ret);
194+
qCWarning(logsshprocess) << "Failed to channel_close: " << errStr;
189195
}
190196
}
191197
setChannelState(ChannelState::WaitClose);
@@ -203,10 +209,12 @@ void SshProcess::sshDataReceived()
203209
{
204210
if(!m_error)
205211
{
212+
QString errStr(sshErrorToString(ret));
213+
sshClient()->setSSHErrorString(errStr);
206214
m_error = true;
207-
m_errMsg << QString("Failed to channel_wait_close: %1").arg(sshErrorToString(ret));
215+
m_errMsg << QString("Failed to channel_wait_close: %1").arg(errStr);
208216
emit failed();
209-
qCWarning(logsshprocess) << "Failed to channel_wait_close: " << sshErrorToString(ret);
217+
qCWarning(logsshprocess) << "Failed to channel_wait_close: " << errStr;
210218
}
211219
}
212220
setChannelState(ChannelState::Freeing);
@@ -225,10 +233,12 @@ void SshProcess::sshDataReceived()
225233
{
226234
if(!m_error)
227235
{
236+
QString errStr(sshErrorToString(ret));
237+
sshClient()->setSSHErrorString(errStr);
228238
m_error = true;
229-
m_errMsg << QString("Failed to free channel: %1").arg(sshErrorToString(ret));
239+
m_errMsg << QString("Failed to free channel: %1").arg(errStr);
230240
emit failed();
231-
qCWarning(logsshprocess) << "Failed to free channel: " << sshErrorToString(ret);
241+
qCWarning(logsshprocess) << "Failed to free channel: " << errStr;
232242
}
233243
}
234244
if(m_error)

lib/qtssh/sshscpget.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ void SshScpGet::sshDataReceived()
110110
{
111111
if(!m_error)
112112
{
113+
QString errStr(sshErrorToString(static_cast<int>(retsz)));
114+
sshClient()->setSSHErrorString(errStr);
113115
m_error = true;
114116
emit failed();
115-
qCWarning(logscpget) << "Can't read result (" << sshErrorToString(static_cast<int>(retsz)) << ")";
117+
qCWarning(logscpget) << "Can't read result (" << errStr << ")";
116118
}
117119
setChannelState(ChannelState::Close);
118120
sshDataReceived();
@@ -150,9 +152,11 @@ void SshScpGet::sshDataReceived()
150152
{
151153
if(!m_error)
152154
{
155+
QString errStr(sshErrorToString(ret));
156+
sshClient()->setSSHErrorString(errStr);
153157
m_error = true;
154158
emit failed();
155-
qCWarning(logscpget) << "Failed to channel_close: " << sshErrorToString(ret);
159+
qCWarning(logscpget) << "Failed to channel_close: " << errStr;
156160
}
157161
}
158162
setChannelState(ChannelState::WaitClose);
@@ -170,9 +174,11 @@ void SshScpGet::sshDataReceived()
170174
{
171175
if(!m_error)
172176
{
177+
QString errStr(sshErrorToString(ret));
178+
sshClient()->setSSHErrorString(errStr);
173179
m_error = true;
174180
emit failed();
175-
qCWarning(logscpget) << "Failed to channel_wait_close: " << sshErrorToString(ret);
181+
qCWarning(logscpget) << "Failed to channel_wait_close: " << errStr;
176182
}
177183
}
178184
setChannelState(ChannelState::Freeing);
@@ -191,9 +197,11 @@ void SshScpGet::sshDataReceived()
191197
{
192198
if(!m_error)
193199
{
200+
QString errStr(sshErrorToString(ret));
201+
sshClient()->setSSHErrorString(errStr);
194202
m_error = true;
195203
emit failed();
196-
qCWarning(logscpget) << "Failed to free channel: " << sshErrorToString(ret);
204+
qCWarning(logscpget) << "Failed to free channel: " << errStr;
197205
}
198206
}
199207
if(m_error)

lib/qtssh/sshscpsend.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ void SshScpSend::sshDataReceived()
103103
if(retsz < 0)
104104
{
105105
if(!m_error)
106-
{
106+
{
107+
QString errStr(sshErrorToString(static_cast<int>(retsz)));
108+
sshClient()->setSSHErrorString(errStr);
107109
m_error = true;
108110
emit failed();
109-
qCWarning(logscpsend) << "Can't write result (" << sshErrorToString(static_cast<int>(retsz)) << ")";
111+
qCWarning(logscpsend) << "Can't write result (" << errStr << ")";
110112
}
111113
setChannelState(ChannelState::Close);
112114
sshDataReceived();
@@ -147,10 +149,12 @@ void SshScpSend::sshDataReceived()
147149
if(ret < 0)
148150
{
149151
if(!m_error)
150-
{
152+
{
153+
QString errStr(sshErrorToString(ret));
154+
sshClient()->setSSHErrorString(errStr);
151155
m_error = true;
152156
emit failed();
153-
qCWarning(logscpsend) << "Failed to channel_close: " << sshErrorToString(ret);
157+
qCWarning(logscpsend) << "Failed to channel_close: " << errStr;
154158
}
155159
}
156160
setChannelState(ChannelState::WaitClose);
@@ -167,10 +171,12 @@ void SshScpSend::sshDataReceived()
167171
if(ret < 0)
168172
{
169173
if(!m_error)
170-
{
174+
{
175+
QString errStr(sshErrorToString(ret));
176+
sshClient()->setSSHErrorString(errStr);
171177
m_error = true;
172178
emit failed();
173-
qCWarning(logscpsend) << "Failed to channel_wait_close: " << sshErrorToString(ret);
179+
qCWarning(logscpsend) << "Failed to channel_wait_close: " << errStr;
174180
}
175181
}
176182
setChannelState(ChannelState::Freeing);
@@ -188,10 +194,12 @@ void SshScpSend::sshDataReceived()
188194
if(ret < 0)
189195
{
190196
if(!m_error)
191-
{
197+
{
198+
QString errStr(sshErrorToString(ret));
199+
sshClient()->setSSHErrorString(errStr);
192200
m_error = true;
193201
emit failed();
194-
qCWarning(logscpsend) << "Failed to free channel: " << sshErrorToString(ret);
202+
qCWarning(logscpsend) << "Failed to free channel: " << errStr;
195203
}
196204
}
197205
if(m_error)

0 commit comments

Comments
 (0)