From 536ca5e539908e12bed383225b9ee78b2531eda9 Mon Sep 17 00:00:00 2001 From: Syping Date: Sat, 4 Jul 2020 14:03:37 +0200 Subject: [PATCH] add socketFlush, tcpSocketStartTLS and luaEngineTLSAvailable --- .../luaengine/LuaEngineNetwork.cpp | 62 +++++++++++++++++-- .../luaengine/LuaEngineNetwork.h | 3 + tests/testengine/testengine.lua | 5 ++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp b/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp index 838ec47..014d403 100644 --- a/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp +++ b/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp @@ -29,12 +29,17 @@ void LuaEngineNetwork::pushClass(lua_State *L_p) // Local Socket pushFunction(L_p, "createLocalSocket", createLocalSocket); - // TCP Socket - pushFunction(L_p, "createTcpSocket", createTcpSocket); - // Socket pushFunction(L_p, "socketConnect", socketConnect); pushFunction(L_p, "socketDisconnect", socketDisconnect); + pushFunction(L_p, "socketFlush", socketFlush); + + // TCP Socket + pushFunction(L_p, "createTcpSocket", createTcpSocket); + pushFunction(L_p, "tcpSocketStartTLS", tcpSocketStartTLS); + + // TLS + pushFunction(L_p, "luaEngineTLSAvailable", luaEngineTLSAvailable); } void LuaEngineNetwork::pushClass(LuaEngine *luaEngine) @@ -69,13 +74,29 @@ int LuaEngineNetwork::createTcpSocket(lua_State *L_p) #ifdef QT_NO_SSL QTcpSocket *tcpSocket = new QTcpSocket(parent); #else - QSslSocket *tcpSocket = new QSslSocket(parent); + QTcpSocket *tcpSocket; + if (QSslSocket::supportsSsl()) { + tcpSocket = new QSslSocket(parent); + } + else { + tcpSocket = new QTcpSocket(parent); + } #endif tcpSocket->setObjectName(nameForPointer(tcpSocket)); pushPointer(L_p, tcpSocket); return 1; } +int LuaEngineNetwork::luaEngineTLSAvailable(lua_State *L_p) +{ +#ifdef QT_NO_SSL + pushVariant(L_p, false); +#else + pushVariant(L_p, QSslSocket::supportsSsl()); +#endif + return 1; +} + int LuaEngineNetwork::socketConnect(lua_State *L_p) { if (getArgumentCount(L_p) >= 2) { @@ -111,6 +132,39 @@ int LuaEngineNetwork::socketDisconnect(lua_State *L_p) return 0; } +int LuaEngineNetwork::socketFlush(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 1) { + void *pointer = getPointer(L_p, 1); + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QAbstractSocket")) { + bool isFlushed = ((QAbstractSocket*)pointer)->flush(); + pushVariant(L_p, isFlushed); + return 1; + } + } + } + return 0; +} + +int LuaEngineNetwork::tcpSocketStartTLS(lua_State *L_p) +{ +#ifndef QT_NO_SSL + if (getArgumentCount(L_p) >= 1) { + void *pointer = getPointer(L_p, 1); + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QSslSocket")) { + ((QSslSocket*)pointer)->startClientEncryption(); + pushVariant(L_p, true); + return 1; + } + } + } +#endif + pushVariant(L_p, false); + return 1; +} + QString LuaEngineNetwork::nameForPointer(void *pointer) { QString nameStorage; diff --git a/src/luaenginenetwork/luaengine/LuaEngineNetwork.h b/src/luaenginenetwork/luaengine/LuaEngineNetwork.h index 5f61951..c9e5688 100644 --- a/src/luaenginenetwork/luaengine/LuaEngineNetwork.h +++ b/src/luaenginenetwork/luaengine/LuaEngineNetwork.h @@ -30,8 +30,11 @@ public: static void pushClass(LuaEngine *luaEngine); static int createLocalSocket(lua_State *L_p); static int createTcpSocket(lua_State *L_p); + static int luaEngineTLSAvailable(lua_State *L_p); static int socketConnect(lua_State *L_p); static int socketDisconnect(lua_State *L_p); + static int socketFlush(lua_State *L_p); + static int tcpSocketStartTLS(lua_State *L_p); private: lua_State *L; diff --git a/tests/testengine/testengine.lua b/tests/testengine/testengine.lua index de1be32..d3feb9b 100644 --- a/tests/testengine/testengine.lua +++ b/tests/testengine/testengine.lua @@ -75,6 +75,11 @@ function main() createLabel("Right", imagesLayout) createSpacerItem(SizePolicyExpanding, SizePolicyMinimum, imagesLayout) + -- Third Tab + local thirdTab = createWidgetTab("Third Tab", tabBar) + local thirdTabLayout = createLayout(VerticalLayout, thirdTab) + createLabel("The Third Tab is here!", thirdTabLayout) + -- Last Tab local lastTab = createWidgetTab("Last Tab", tabBar) local lastTabLayout = createLayout(HorizontalLayout, lastTab)