From 73891b3191e5326dd77647e439d00c58d07cab7d Mon Sep 17 00:00:00 2001
From: xiaoming <2014500726@smail.xtu.edu.cn>
Date: Thu, 16 Jan 2025 10:15:32 +0800
Subject: [PATCH] Raw protocol adds four modes TCP Client, TCP Server, UDP
Send, UDP Receive
Signed-off-by: xiaoming <2014500726@smail.xtu.edu.cn>
---
CHANGELOG.md | 2 +
docs/changelog.md | 1 +
lang/quardCRT_zh_CN.ts | 205 +++++++++++-------
src/mainwindow.cpp | 20 +-
src/mainwindow.h | 2 +-
src/quickconnectwindow/quickconnectwindow.cpp | 14 +-
src/quickconnectwindow/quickconnectwindow.h | 1 +
src/quickconnectwindow/quickconnectwindow.ui | 30 ++-
src/scriptengine/pyrun.cpp | 4 +-
.../sessionoptionsrawproperties.cpp | 1 +
.../sessionoptionsrawproperties.ui | 44 +++-
src/sessionoptions/sessionoptionswindow.cpp | 3 +
src/sessionswindow/sessionswindow.cpp | 13 +-
src/sessionswindow/sessionswindow.h | 196 ++++++++++++++++-
14 files changed, 434 insertions(+), 102 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a7d51f4d..47ff404e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ en-US:
- Improve the log file path setting option
- Add TFTP server configuration to settings
- Add terminal recording video feature
+- Raw protocol adds four modes TCP Client, TCP Server, UDP Send, UDP Receive
- Add view own log window for quardCRT self debug
zh-CN:
@@ -18,6 +19,7 @@ zh-CN:
- 改进记录日志文件路径设置选项
- 增加TFTP服务器配置到设置中
- 增加终端录制视频功能
+- Raw协议增加四种模式TCP Client、TCP Server、UDP Send、UDP Receive
- 增加查看自身log窗口,用于quardCRT自身debug
## [[V0.5.1](https://github.com/QQxiaoming/quardCRT/releases/tag/V0.5.1)] - 2024-09-26
diff --git a/docs/changelog.md b/docs/changelog.md
index 844ce3b1..7552b660 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -9,6 +9,7 @@
- Improve the log file path setting option
- Add TFTP server configuration to settings
- Add terminal recording video feature
+- Raw protocol adds four modes TCP Client, TCP Server, UDP Send, UDP Receive
- Add view own log window for quardCRT self debug
## [[V0.5.1](https://github.com/QQxiaoming/quardCRT/releases/tag/V0.5.1)] - 2024-09-26
diff --git a/lang/quardCRT_zh_CN.ts b/lang/quardCRT_zh_CN.ts
index b0fb028e..fc820102 100644
--- a/lang/quardCRT_zh_CN.ts
+++ b/lang/quardCRT_zh_CN.ts
@@ -39,8 +39,8 @@
-
-
+
+
警告
@@ -1398,7 +1398,7 @@
-
+
键盘快捷键参考
@@ -1409,7 +1409,7 @@
-
+
隐私声明
@@ -1420,7 +1420,7 @@
-
+
关于 Python
@@ -1581,58 +1581,58 @@
" 会话?
-
+
此软件是一个终端仿真器,提供安全外壳 (SSH) 连接、 Telnet 连接、串口连接和其他功能。
-
+
此软件不收集任何个人信息,也不向服务器发送任何信息。
-
+
此软件不包含任何恶意代码,也不包含任何后门。
-
+
此软件是开源软件,您可以在 github 网站上查看源代码。
-
+
此软件按原样提供,不提供任何保证。
-
+
如果您有任何问题或建议,请联系作者。
-
+
版本
-
+
提交
-
+
日期
-
-
+
+
作者
-
+
网站
@@ -1783,7 +1783,7 @@
-
+
关于
@@ -1830,7 +1830,7 @@
-
+
屏幕截图保存到 %1
@@ -1958,67 +1958,67 @@
本机终端 -
-
+
全局快捷键:
-
+
显示/隐藏菜单栏
-
+
连接到本机终端
-
+
克隆当前会话
-
+
切换 UI 到标准模式
-
+
切换 UI 到迷你模式
-
+
切换到上一个会话
-
+
切换到下一个会话
-
+
切换到会话 [num]
-
+
跳转到行首
-
+
跳转到行尾
-
+
有会话尚未解锁,请先解锁。
-
+
确定要退出吗?
@@ -3852,9 +3852,9 @@ If you need to use another shell, please create a session through [quick-connect
-
-
-
+
+
+
主机地址
@@ -3866,15 +3866,15 @@ If you need to use another shell, please create a session through [quick-connect
-
-
-
+
+
+
端口
-
+
无
@@ -3889,57 +3889,78 @@ If you need to use another shell, please create a session through [quick-connect
-
+
+
+ TCP客户端
+
+
+
+
+ TCP服务端
+
+
+
+
+ UDP发送
+
+
+
+
+ UDP接收
+
+
+
用户名
-
+
密码
-
+
数据位
-
+
校验位
-
+
奇
-
+
偶
-
+
停止位
-
+
保存会话
-
+
在标签中打开
+
-
+
快速连接
@@ -3954,25 +3975,25 @@ If you need to use another shell, please create a session through [quick-connect
本机终端
-
-
-
-
+
+
+
+
例如 127.0.0.1
-
+
端口名称
-
+
波特率
-
+
-
+
命令
-
+
例如 /bin/bash
-
+
+
+ 模式
+
+
+
管道名称
-
+
例如 \\\.\pipe\namedpipe
-
+
例如 /tmp/socket
@@ -4254,6 +4280,31 @@ If you need to use another shell, please create a session through [quick-connect
端口
+
+
+
+ 模式
+
+
+
+
+ TCP客户端
+
+
+
+
+ TCP服务端
+
+
+
+
+ UDP发送
+
+
+
+
+ UDP接收
+
SessionOptionsSerialProperties
@@ -4526,72 +4577,72 @@ If you need to use another shell, please create a session through [quick-connect
串行端口 %1 已被移除。
-
+
保存日志...
-
+
日志文件 (*.log)
-
+
保存日志
-
-
-
-
+
+
+
+
无法写入文件 %1:
%2.
-
+
保存原始日志...
-
+
二进制文件 (*.bin)
-
+
保存原始日志
-
+
保存脚本...
-
+
Python 文件 (*.py)
-
+
保存脚本
-
+
解锁会话
-
+
密码错误!
-
+
接收 ASCII 文件
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index bdc53ef6..23f42954 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -927,7 +927,7 @@ CentralWidget::CentralWidget(QString dir, StartupUIMode mode, QLocale lang, bool
} else if(type == "localshell") {
startLocalShellSession(findCurrentFocusGroup(),-1);
} else if(type == "raw") {
- startRawSocketSession(findCurrentFocusGroup(),-1,hostname,port.toInt());
+ startRawSocketSession(findCurrentFocusGroup(),-1,hostname,port.toInt(),0);
} else if(type == "namepipe") {
startNamePipeSession(findCurrentFocusGroup(),-1,hostname);
} else if(type == "ssh") {
@@ -2571,7 +2571,7 @@ void CentralWidget::onPluginRequestLocalShellConnect(QString command, QString wo
}
void CentralWidget::onPluginRequestRawSocketConnect(QString host, int port) {
- startRawSocketSession(findCurrentFocusGroup(),-1,host,port);
+ startRawSocketSession(findCurrentFocusGroup(),-1,host,port,0);
}
void CentralWidget::onPluginRequestNamePipeConnect(QString namePipe) {
@@ -4120,7 +4120,7 @@ void CentralWidget::connectSessionFromSessionManager(QString name)
startLocalShellSession(findCurrentFocusGroup(),-1,data.LocalShellData.command,globalOptionsWindow->getNewTabWorkPath(),current_name);
break;
case QuickConnectWindow::Raw:
- startRawSocketSession(findCurrentFocusGroup(),-1,data.RawData.hostname,data.RawData.port, current_name);
+ startRawSocketSession(findCurrentFocusGroup(),-1,data.RawData.hostname,data.RawData.port,data.RawData.mode,current_name);
break;
case QuickConnectWindow::NamePipe:
startNamePipeSession(findCurrentFocusGroup(),-1,data.NamePipeData.pipeName, current_name);
@@ -4247,7 +4247,7 @@ QString CentralWidget::startSerialSession(MainWidgetGroup *group, int groupIndex
return name;
}
-QString CentralWidget::startRawSocketSession(MainWidgetGroup *group, int groupIndex, QString hostname, quint16 port, QString name)
+QString CentralWidget::startRawSocketSession(MainWidgetGroup *group, int groupIndex, QString hostname, quint16 port, int mode, QString name)
{
SessionsWindow *sessionsWindow = new SessionsWindow(SessionsWindow::RawSocket,this);
setGlobalOptions(sessionsWindow);
@@ -4260,7 +4260,7 @@ QString CentralWidget::startRawSocketSession(MainWidgetGroup *group, int groupIn
checkSessionName(name);
}
sessionsWindow->setName(name);
- sessionsWindow->startRawSocketSession(hostname,port);
+ sessionsWindow->startRawSocketSession(hostname,port,mode);
sessionList.push_back(sessionsWindow);
connect(sessionsWindow, &SessionsWindow::titleChanged, this, [=](int title,const QString& newTitle){
if(title == 0 || title == 2) {
@@ -4586,7 +4586,7 @@ void CentralWidget::startSession(MainWidgetGroup *group, int groupIndex, QuickCo
} else if(data.type == QuickConnectWindow::Raw) {
QString name = data.RawData.hostname;
if(data.openInTab) {
- name = startRawSocketSession(group,groupIndex,name,data.RawData.port);
+ name = startRawSocketSession(group,groupIndex,name,data.RawData.port,data.RawData.mode);
} else {
checkSessionName(name);
}
@@ -4837,6 +4837,7 @@ void CentralWidget::sessionWindow2InfoData(SessionsWindow *sessionsWindow, Quick
case QuickConnectWindow::Raw:
data.RawData.hostname = sessionsWindow->getHostname();
data.RawData.port = sessionsWindow->getPort();
+ data.RawData.mode = sessionsWindow->getRawMode();
break;
case QuickConnectWindow::NamePipe:
data.NamePipeData.pipeName = sessionsWindow->getPipeName();
@@ -4883,6 +4884,7 @@ int CentralWidget::setting2InfoData(GlobalSetting *settings, QuickConnectWindow:
case QuickConnectWindow::Raw:
data.RawData.hostname = settings->value("hostname").toString();
data.RawData.port = settings->value("port").toInt();
+ data.RawData.mode = settings->value("mode").toInt();
break;
case QuickConnectWindow::NamePipe:
data.NamePipeData.pipeName = settings->value("pipeName").toString();
@@ -4941,6 +4943,7 @@ void CentralWidget::infoData2Setting(GlobalSetting *settings,const QuickConnectW
case QuickConnectWindow::Raw:
settings->setValue("hostname",data.RawData.hostname);
settings->setValue("port",data.RawData.port);
+ settings->setValue("mode",data.RawData.mode);
break;
case QuickConnectWindow::NamePipe:
settings->setValue("pipeName",data.NamePipeData.pipeName);
@@ -5380,10 +5383,11 @@ int CentralWidget::se_sessionConnect(const QString &cmd,int id) {
return 0;
}
} else if(args[i] == "-raw") {
- if(i+2 < args.size()) {
+ if(i+3 < args.size()) {
QString hostname = args[i+1];
quint16 port = args[i+2].toUShort();
- startRawSocketSession(findCurrentFocusGroup(),-1,hostname,port);
+ int mode = args[i+3].toInt();
+ startRawSocketSession(findCurrentFocusGroup(),-1,hostname,port,mode);
return 0;
}
} else if(args[i] == "-namepipe") {
diff --git a/src/mainwindow.h b/src/mainwindow.h
index b9f0101c..4f485552 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -211,7 +211,7 @@ class CentralWidget : public QMainWindow
#if defined(Q_OS_WIN)
QString startWslSession(MainWidgetGroup *group, int groupIndex, const QString &command = QString(), const QString &workingDirectory = QDir::homePath(), QString name = QString());
#endif
- QString startRawSocketSession(MainWidgetGroup *group, int groupIndex, QString hostname, quint16 port, QString name = QString());
+ QString startRawSocketSession(MainWidgetGroup *group, int groupIndex, QString hostname, quint16 port, int mode, QString name = QString());
QString startNamePipeSession(MainWidgetGroup *group, int groupIndex, QString namePipe, QString name = QString());
QString startSSH2Session(MainWidgetGroup *group, int groupIndex,
QString hostname, quint16 port, QString username, QString password, QString name = QString());
diff --git a/src/quickconnectwindow/quickconnectwindow.cpp b/src/quickconnectwindow/quickconnectwindow.cpp
index 884278b7..1c7d2687 100644
--- a/src/quickconnectwindow/quickconnectwindow.cpp
+++ b/src/quickconnectwindow/quickconnectwindow.cpp
@@ -80,6 +80,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
case Telnet: {
ui->labelHostname->setText(tr("Hostname"));
ui->labelPort->setText(tr("Port"));
+ ui->labelWebSocket->setText(tr("WebSocket"));
ui->comboBoxHostname->setVisible(false);
ui->pushButtonRefresh->setVisible(false);
ui->lineEditHostname->setVisible(true);
@@ -88,6 +89,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->spinBoxPort->setToolTip("");
ui->labelWebSocket->setVisible(true);
ui->comboBoxWebSocket->setVisible(true);
+ ui->comboBoxRawMode->setVisible(false);
ui->labelDataBits->setVisible(false);
ui->comboBoxDataBits->setVisible(false);
ui->labelParity->setVisible(false);
@@ -121,6 +123,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->labelPort->setVisible(true);
ui->spinBoxPort->setVisible(true);
ui->spinBoxPort->setToolTip(tr("e.g. 110, 300, 600, 1200, 2400, \n4800, 9600, 14400, 19200, 38400, \n56000, 57600, 115200, 128000, 256000, \n460800, 921600"));
+ ui->comboBoxRawMode->setVisible(false);
ui->labelWebSocket->setVisible(false);
ui->comboBoxWebSocket->setVisible(false);
ui->labelDataBits->setVisible(true);
@@ -164,6 +167,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->spinBoxPort->setVisible(false);
ui->spinBoxPort->setToolTip("");
ui->labelWebSocket->setVisible(false);
+ ui->comboBoxRawMode->setVisible(false);
ui->comboBoxWebSocket->setVisible(false);
ui->labelDataBits->setVisible(false);
ui->comboBoxDataBits->setVisible(false);
@@ -180,6 +184,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
case Raw: {
ui->labelHostname->setText(tr("Hostname"));
ui->labelPort->setText(tr("Port"));
+ ui->labelWebSocket->setText(tr("Mode"));
ui->comboBoxHostname->setVisible(false);
ui->pushButtonRefresh->setVisible(false);
ui->lineEditHostname->setVisible(true);
@@ -190,7 +195,8 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->labelPort->setVisible(true);
ui->spinBoxPort->setVisible(true);
ui->spinBoxPort->setToolTip("");
- ui->labelWebSocket->setVisible(false);
+ ui->labelWebSocket->setVisible(true);
+ ui->comboBoxRawMode->setVisible(true);
ui->comboBoxWebSocket->setVisible(false);
ui->labelDataBits->setVisible(false);
ui->comboBoxDataBits->setVisible(false);
@@ -205,6 +211,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->spinBoxPort->setMinimum(0);
ui->spinBoxPort->setMaximum(65535);
ui->spinBoxPort->setValue(8080);
+ ui->comboBoxRawMode->setCurrentIndex(0);
break;
}
case NamePipe:{
@@ -219,6 +226,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->labelPort->setVisible(false);
ui->spinBoxPort->setVisible(false);
ui->spinBoxPort->setToolTip("");
+ ui->comboBoxRawMode->setVisible(false);
ui->labelWebSocket->setVisible(false);
ui->comboBoxWebSocket->setVisible(false);
ui->labelDataBits->setVisible(false);
@@ -251,6 +259,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->spinBoxPort->setVisible(true);
ui->spinBoxPort->setToolTip("");
ui->labelWebSocket->setVisible(false);
+ ui->comboBoxRawMode->setVisible(false);
ui->comboBoxWebSocket->setVisible(false);
ui->labelDataBits->setVisible(false);
ui->comboBoxDataBits->setVisible(false);
@@ -281,6 +290,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->labelWebSocket->setVisible(false);
ui->labelUsername->setVisible(false);
ui->lineEditUsername->setVisible(false);
+ ui->comboBoxRawMode->setVisible(false);
ui->comboBoxWebSocket->setVisible(false);
ui->labelDataBits->setVisible(false);
ui->comboBoxDataBits->setVisible(false);
@@ -332,6 +342,7 @@ void QuickConnectWindow::buttonBoxAccepted(void)
case Raw:
data.RawData.hostname = ui->lineEditHostname->text();
data.RawData.port = ui->spinBoxPort->value();
+ data.RawData.mode = ui->comboBoxRawMode->currentIndex();
emit this->sendQuickConnectData(data);
break;
case NamePipe:
@@ -399,6 +410,7 @@ void QuickConnectWindow::setQuickConnectData(QuickConnectData data)
case Raw:
ui->lineEditHostname->setText(data.RawData.hostname);
ui->spinBoxPort->setValue(data.RawData.port);
+ ui->comboBoxRawMode->setCurrentIndex(data.RawData.mode);
break;
case NamePipe:
ui->lineEditHostname->setText(data.NamePipeData.pipeName);
diff --git a/src/quickconnectwindow/quickconnectwindow.h b/src/quickconnectwindow/quickconnectwindow.h
index 2b52cc1c..adb395c8 100644
--- a/src/quickconnectwindow/quickconnectwindow.h
+++ b/src/quickconnectwindow/quickconnectwindow.h
@@ -67,6 +67,7 @@ class QuickConnectWindow : public QDialog
struct {
QString hostname;
int port;
+ int mode;
}RawData;
struct {
QString pipeName;
diff --git a/src/quickconnectwindow/quickconnectwindow.ui b/src/quickconnectwindow/quickconnectwindow.ui
index 459beb88..a2ced0db 100644
--- a/src/quickconnectwindow/quickconnectwindow.ui
+++ b/src/quickconnectwindow/quickconnectwindow.ui
@@ -173,6 +173,30 @@
+ -
+
+
-
+
+ TCP Client
+
+
+ -
+
+ TCP Server
+
+
+ -
+
+ UDP Send
+
+
+ -
+
+ UDP Recv
+
+
+
+
-
@@ -332,7 +356,7 @@
-
- Qt::Vertical
+ Qt::Orientation::Vertical
@@ -372,10 +396,10 @@
-
- Qt::Horizontal
+ Qt::Orientation::Horizontal
- QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+ QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok
diff --git a/src/scriptengine/pyrun.cpp b/src/scriptengine/pyrun.cpp
index 51c5bf17..d1f050b7 100644
--- a/src/scriptengine/pyrun.cpp
+++ b/src/scriptengine/pyrun.cpp
@@ -256,8 +256,8 @@ PyRun::PyRun(QObject *parent)
resultList->append(QString::number(centralWidget->se_sessionGetLogging(id)));
} else if (cmd == "sessionConnect") {
int id = cmdList.at(1).toInt();
- QString cmd = cmdList.at(2);
- centralWidget->se_sessionConnect(cmd,id);
+ QString ccmd = cmdList.at(2);
+ centralWidget->se_sessionConnect(ccmd,id);
} else if (cmd == "sessionDisconnect") {
int id = cmdList.at(1).toInt();
centralWidget->se_sessionDisconnect(id);
diff --git a/src/sessionoptions/sessionoptionsrawproperties.cpp b/src/sessionoptions/sessionoptionsrawproperties.cpp
index 2da49c6f..0ac74683 100644
--- a/src/sessionoptions/sessionoptionsrawproperties.cpp
+++ b/src/sessionoptions/sessionoptionsrawproperties.cpp
@@ -25,6 +25,7 @@ SessionOptionsRawProperties::SessionOptionsRawProperties(QWidget *parent) :
ui(new Ui::SessionOptionsRawProperties)
{
ui->setupUi(this);
+ ui->lineEditReadOnlyRawMode->setVisible(true);
}
SessionOptionsRawProperties::~SessionOptionsRawProperties()
diff --git a/src/sessionoptions/sessionoptionsrawproperties.ui b/src/sessionoptions/sessionoptionsrawproperties.ui
index 0b2f9d01..81f45d75 100644
--- a/src/sessionoptions/sessionoptionsrawproperties.ui
+++ b/src/sessionoptions/sessionoptionsrawproperties.ui
@@ -68,15 +68,55 @@
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Mode
+
+
+
+ -
+
+
-
+
+ TCP Client
+
+
+ -
+
+ TCP Server
+
+
+ -
+
+ UDP Send
+
+
+ -
+
+ UDP Recv
+
+
+
+
+ -
+
+
-
- Qt::Vertical
+ Qt::Orientation::Vertical
- QSizePolicy::MinimumExpanding
+ QSizePolicy::Policy::MinimumExpanding
diff --git a/src/sessionoptions/sessionoptionswindow.cpp b/src/sessionoptions/sessionoptionswindow.cpp
index 0462001f..95d07b69 100644
--- a/src/sessionoptions/sessionoptionswindow.cpp
+++ b/src/sessionoptions/sessionoptionswindow.cpp
@@ -234,6 +234,7 @@ void SessionOptionsWindow::setSessionProperties(QString name, QuickConnectWindow
case QuickConnectWindow::Raw:
sessionOptionsRawProperties->ui->lineEditHostname->setText(data.RawData.hostname);
sessionOptionsRawProperties->ui->spinBoxPort->setValue(data.RawData.port);
+ sessionOptionsRawProperties->ui->comboBoxRawMode->setCurrentIndex(data.RawData.mode);
break;
case QuickConnectWindow::NamePipe:
sessionOptionsNamePipeProperties->ui->lineEditPipeName->setText(data.NamePipeData.pipeName);
@@ -357,6 +358,7 @@ void SessionOptionsWindow::setReadOnly(bool enable) {
sessionOptionsRawProperties->ui->lineEditHostname->setReadOnly(enable);
sessionOptionsRawProperties->ui->spinBoxPort->setReadOnly(enable);
+ comboxSetReadOnly(sessionOptionsRawProperties->ui->comboBoxRawMode, sessionOptionsRawProperties->ui->lineEditReadOnlyRawMode);
sessionOptionsNamePipeProperties->ui->lineEditPipeName->setReadOnly(enable);
@@ -398,6 +400,7 @@ void SessionOptionsWindow::buttonBoxAccepted(void)
case QuickConnectWindow::Raw:
data.RawData.hostname = sessionOptionsRawProperties->ui->lineEditHostname->text();
data.RawData.port = sessionOptionsRawProperties->ui->spinBoxPort->value();
+ data.RawData.mode = sessionOptionsRawProperties->ui->comboBoxRawMode->currentIndex();
break;
case QuickConnectWindow::NamePipe:
data.NamePipeData.pipeName = sessionOptionsNamePipeProperties->ui->lineEditPipeName->text();
diff --git a/src/sessionswindow/sessionswindow.cpp b/src/sessionswindow/sessionswindow.cpp
index e53007f0..cdd1c327 100644
--- a/src/sessionswindow/sessionswindow.cpp
+++ b/src/sessionswindow/sessionswindow.cpp
@@ -208,9 +208,9 @@ SessionsWindow::SessionsWindow(SessionType tp, QWidget *parent)
break;
}
case RawSocket: {
- rawSocket = new QTcpSocket(this);
+ rawSocket = new QRawSocket(this);
realtimespeed_timer = new QTimer(this);
- connect(rawSocket,&QTcpSocket::readyRead,this,[=](){
+ connect(rawSocket,&QRawSocket::readyRead,this,[=](){
QByteArray data = rawSocket->readAll();
uint64_t size = data.size();
if(doRecvData(data)) {
@@ -234,7 +234,7 @@ SessionsWindow::SessionsWindow(SessionType tp, QWidget *parent)
tx_realtime += size;
}
});
- connect(rawSocket, &QTcpSocket::stateChanged, this, [=](QAbstractSocket::SocketState socketState){
+ connect(rawSocket, &QRawSocket::stateChanged, this, [=](QAbstractSocket::SocketState socketState){
if(socketState == QAbstractSocket::ConnectedState) {
state = Connected;
emit stateChanged(state);
@@ -243,7 +243,7 @@ SessionsWindow::SessionsWindow(SessionType tp, QWidget *parent)
emit stateChanged(state);
}
});
- connect(rawSocket, &QTcpSocket::errorOccurred, this, [=](QAbstractSocket::SocketError socketError){
+ connect(rawSocket, &QRawSocket::errorOccurred, this, [=](QAbstractSocket::SocketError socketError){
QMessageBox::warning(messageParentWidget, tr("Raw Socket Error"), getName() + "\n" + tr("Raw Socket error:\n%1.").arg(rawSocket->errorString()));
state = Error;
emit stateChanged(state);
@@ -726,7 +726,7 @@ void SessionsWindow::cloneSession(SessionsWindow *src, QString profile) {
startSerialSession(src->m_portName, src->m_baudRate, src->m_dataBits, src->m_parity, src->m_stopBits, src->m_flowControl, src->m_xEnable);
break;
case RawSocket:
- startRawSocketSession(src->m_hostname, src->m_port);
+ startRawSocketSession(src->m_hostname, src->m_port, src->getRawMode());
break;
case NamePipe:
startNamePipeSession(src->m_pipeName);
@@ -933,7 +933,8 @@ int SessionsWindow::startSerialSession(const QString &portName, uint32_t baudRat
return 0;
}
-int SessionsWindow::startRawSocketSession(const QString &hostname, quint16 port) {
+int SessionsWindow::startRawSocketSession(const QString &hostname, quint16 port, int mode) {
+ rawSocket->setRawMode(mode);
rawSocket->connectToHost(hostname, port);
m_hostname = hostname;
m_port = port;
diff --git a/src/sessionswindow/sessionswindow.h b/src/sessionswindow/sessionswindow.h
index 895a8ccc..901d0ceb 100644
--- a/src/sessionswindow/sessionswindow.h
+++ b/src/sessionswindow/sessionswindow.h
@@ -22,7 +22,10 @@
#include
#include
+#include
#include
+#include
+#include
#include
#include
#include
@@ -39,6 +42,194 @@
#include "qvncclientwidget.h"
#include "qextserialenumerator.h"
+class QRawSocket : public QObject
+{
+ Q_OBJECT
+public:
+ QRawSocket(QObject *parent = nullptr)
+ : QObject(parent){}
+ ~QRawSocket() {
+ disconnectFromHost();
+ switch (m_rawMode) {
+ case 0:
+ delete tcpSocket;
+ break;
+ case 1:
+ if(tcpSocket) {
+ delete tcpSocket;
+ }
+ delete tcpServer;
+ break;
+ case 2:
+ case 3:
+ delete udpSocket;
+ break;
+ default:
+ break;
+ }
+ }
+ int setRawMode(int mode) {
+ if(m_rawMode == -1) {
+ switch (mode) {
+ case 0:
+ tcpSocket = new QTcpSocket(this);
+ connect(tcpSocket,&QTcpSocket::readyRead,this,&QRawSocket::readyRead);
+ connect(tcpSocket,&QTcpSocket::errorOccurred,this,&QRawSocket::errorOccurred);
+ connect(tcpSocket,&QTcpSocket::stateChanged,this,&QRawSocket::stateChanged);
+ break;
+ case 1:
+ tcpServer = new QTcpServer(this);
+ connect(tcpServer, &QTcpServer::newConnection, [&](){
+ if (tcpSocket) {
+ // If there is already a connection, reject the new one
+ QTcpSocket *newSocket = tcpServer->nextPendingConnection();
+ newSocket->disconnectFromHost();
+ newSocket->deleteLater();
+ return;
+ }
+ tcpSocket = tcpServer->nextPendingConnection();
+ connect(tcpSocket,&QTcpSocket::readyRead,this,&QRawSocket::readyRead);
+ connect(tcpSocket,&QTcpSocket::errorOccurred,this,&QRawSocket::errorOccurred);
+ connect(tcpSocket,&QTcpSocket::stateChanged,this,&QRawSocket::stateChanged);
+ emit stateChanged(tcpSocket->state());
+ });
+ break;
+ case 2:
+ udpSocket = new QUdpSocket(this);
+ connect(udpSocket,&QUdpSocket::errorOccurred,this,&QRawSocket::errorOccurred);
+ break;
+ case 3:
+ udpSocket = new QUdpSocket(this);
+ connect(udpSocket,&QUdpSocket::readyRead,this,&QRawSocket::readyRead);
+ connect(udpSocket,&QUdpSocket::errorOccurred,this,&QRawSocket::errorOccurred);
+ break;
+ default:
+ return -1;
+ }
+ m_rawMode = mode;
+ return 0;
+ }
+ return -1;
+ }
+ int getRawMode() const { return m_rawMode; }
+ void connectToHost(const QString &hostName, quint16 port) {
+ switch(m_rawMode) {
+ case 0:
+ tcpSocket->connectToHost(hostName,port);
+ return;
+ case 1:
+ tcpServer->listen(QHostAddress(hostName),port);
+ return;
+ case 2:
+ udpSocket->connectToHost(hostName,port);
+ udpstate = QAbstractSocket::ConnectedState;
+ emit stateChanged(udpstate);
+ return;
+ case 3:
+ udpSocket->bind(QHostAddress(hostName),port);
+ udpstate = QAbstractSocket::ConnectedState;
+ emit stateChanged(udpstate);
+ return;
+ }
+ }
+ void disconnectFromHost() {
+ switch(m_rawMode) {
+ case 0:
+ tcpSocket->disconnectFromHost();
+ return;
+ case 1:
+ if(tcpSocket)
+ tcpSocket->close();
+ tcpServer->close();
+ return;
+ case 2:
+ udpSocket->disconnectFromHost();
+ udpstate = QAbstractSocket::ClosingState;
+ emit stateChanged(udpstate);
+ return;
+ case 3:
+ udpSocket->close();
+ udpstate = QAbstractSocket::ClosingState;
+ emit stateChanged(udpstate);
+ return;
+ }
+ }
+ QByteArray readAll() {
+ switch(m_rawMode) {
+ case 0:
+ return tcpSocket->readAll();
+ case 1:
+ if(tcpSocket)
+ return tcpSocket->readAll();
+ return QByteArray();
+ case 3:
+ QByteArray data;
+ while (udpSocket->hasPendingDatagrams()) {
+ QNetworkDatagram datagram = udpSocket->receiveDatagram();
+ data.append(datagram.data());
+ }
+ return data;
+ }
+ return QByteArray();
+ }
+ qint64 write(const QByteArray &data) {
+ switch(m_rawMode) {
+ case 0:
+ return tcpSocket->write(data);
+ case 1:
+ if(tcpSocket)
+ return tcpSocket->write(data);
+ return 0;
+ case 2:
+ return udpSocket->write(data);
+ }
+ return 0;
+ }
+ qint64 write(const char *data, qint64 len) {
+ return this->write(QByteArray(data,len));
+ }
+ QAbstractSocket::SocketState state() const {
+ switch(m_rawMode) {
+ case 0:
+ return tcpSocket->state();
+ case 1:
+ if(tcpSocket)
+ return tcpSocket->state();
+ return QAbstractSocket::UnconnectedState;
+ case 2:
+ case 3:
+ return udpstate;
+ }
+ return QAbstractSocket::UnconnectedState;
+ }
+ QString errorString() const {
+ switch(m_rawMode) {
+ case 0:
+ return tcpSocket->errorString();
+ case 1:
+ if(tcpSocket)
+ return tcpSocket->errorString();
+ return QString();
+ case 2:
+ case 3:
+ return udpSocket->errorString();
+ }
+ return QString();
+ }
+
+signals:
+ void readyRead();
+ void errorOccurred(QAbstractSocket::SocketError socketError);
+ void stateChanged(QAbstractSocket::SocketState);
+
+private:
+ QTcpSocket *tcpSocket = nullptr;
+ QTcpServer *tcpServer = nullptr;
+ QUdpSocket *udpSocket = nullptr;
+ int m_rawMode = -1;
+ QAbstractSocket::SocketState udpstate = QAbstractSocket::ClosingState;
+};
+
class SessionsWindow : public QObject
{
Q_OBJECT
@@ -133,7 +324,7 @@ class SessionsWindow : public QObject
int startTelnetSession(const QString &hostname, quint16 port, QTelnet::SocketType type);
int startSerialSession(const QString &portName, uint32_t baudRate,
int dataBits, int parity, int stopBits, bool flowControl, bool xEnable );
- int startRawSocketSession(const QString &hostname, quint16 port);
+ int startRawSocketSession(const QString &hostname, quint16 port, int mode);
int startNamePipeSession(const QString &name);
#ifdef ENABLE_SSH
int startSSH2Session(const QString &hostname, quint16 port, const QString &username, const QString &password);
@@ -234,6 +425,7 @@ class SessionsWindow : public QObject
quint16 getPort() const { return m_port; }
QString getPortName() const { return m_portName; }
QTelnet::SocketType getSocketType() const { return m_type; }
+ int getRawMode() const { if(rawSocket) return rawSocket->getRawMode(); else return 0;}
uint32_t getBaudRate() const { return m_baudRate; }
int getDataBits() const { return m_dataBits; }
int getParity() const { return m_parity; }
@@ -474,7 +666,7 @@ class SessionsWindow : public QObject
QTelnet *telnet;
QSerialPort *serialPort;
QextSerialEnumerator *serialMonitor;
- QTcpSocket *rawSocket;
+ QRawSocket *rawSocket;
IPtyProcess *localShell;
QLocalSocket *namePipe;
#ifdef ENABLE_SSH