6#include "ConnectFreeRDP.h"
8#undef PEN_FLAG_INVERTED
9#include "freerdp/client.h"
10#include "freerdp/client/channels.h"
11#include "freerdp/channels/rdpei.h"
12#include "freerdp/channels/rdpdr.h"
13#include "freerdp/channels/disp.h"
14#include "freerdp/channels/tsmf.h"
15#include "freerdp/channels/rdpsnd.h"
16#include "freerdp/client/encomsp.h"
17#include "freerdp/gdi/gfx.h"
18#include "freerdp/settings.h"
19#include "freerdp/locale/keyboard.h"
20#include "freerdp/channels/rdpgfx.h"
21#include "freerdp/channels/cliprdr.h"
22#include "freerdp/client/cmdline.h"
23#include <freerdp/gdi/video.h>
25#include "RabbitCommonTools.h"
26#include "ConvertKeyCode.h"
30#include <QApplication>
32#include <QSslCertificate>
33#include <QInputDialog>
34#include <QMutexLocker>
36#include <QPrinterInfo>
38#include <QSerialPortInfo>
39#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
40 #include <QSoundEffect>
45static Q_LOGGING_CATEGORY(log,
"FreeRDP.Connect")
46static Q_LOGGING_CATEGORY(logKey, "FreeRDP.Connect.Key")
47static Q_LOGGING_CATEGORY(logMouse, "FreeRDP.Connect.Mouse")
52 m_pParameter(
nullptr),
60 qDebug(log) << Q_FUNC_INFO;
61 m_pParameter = qobject_cast<CParameterFreeRDP*>(pConnecter->GetParameter());
62 Q_ASSERT(m_pParameter);
65CConnectFreeRDP::~CConnectFreeRDP()
67 qDebug(log) << Q_FUNC_INFO;
78 qDebug(log) << Q_FUNC_INFO;
81 m_writeEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
83 qCritical(log) <<
"CreateEvent failed";
85 ZeroMemory(&m_ClientEntryPoints,
sizeof(RDP_CLIENT_ENTRY_POINTS));
86 m_ClientEntryPoints.Version = RDP_CLIENT_INTERFACE_VERSION;
87 m_ClientEntryPoints.Size =
sizeof(RDP_CLIENT_ENTRY_POINTS);
89 m_ClientEntryPoints.GlobalInit = cbGlobalInit;
90 m_ClientEntryPoints.GlobalUninit = cbGlobalUninit;
91 m_ClientEntryPoints.ClientNew = cbClientNew;
92 m_ClientEntryPoints.ClientFree = cbClientFree;
93 m_ClientEntryPoints.ClientStart = cbClientStart;
94 m_ClientEntryPoints.ClientStop = cbClientStop;
97 auto pRdpContext = freerdp_client_context_new(&m_ClientEntryPoints);
101 m_pContext->pThis =
this;
103 qCritical(log) <<
"freerdp_client_context_new fail";
104 return OnInitReturnValue::Fail;
107 rdpSettings* settings = pRdpContext->settings;
109 qCritical(log) <<
"settings is null";
110 return OnInitReturnValue::Fail;
113 char* argv[]= {(
char*)QApplication::applicationFilePath().toStdString().c_str()};
114 int argc =
sizeof(argv) /
sizeof(
char*);
115 nRet = freerdp_client_settings_parse_command_line(settings, argc, argv, TRUE);
118 nRet = freerdp_client_settings_command_line_status_print(settings, nRet, argc, argv);
119 return OnInitReturnValue::Fail;
122#if FreeRDP_VERSION_MAJOR >= 3
123 if (!stream_dump_register_handlers(pRdpContext,
124 CONNECTION_STATE_MCS_CREATE_REQUEST,
126 return OnInitReturnValue::Fail;
129 auto &user = m_pParameter->m_Net.
m_User;
130 if(!user.GetUser().isEmpty())
131 freerdp_settings_set_string(
132 settings, FreeRDP_Username,
133 user.GetUser().toStdString().c_str());
134 if(!user.GetPassword().isEmpty())
135 freerdp_settings_set_string(
136 settings, FreeRDP_Password,
137 user.GetPassword().toStdString().c_str());
139 freerdp_settings_set_bool(
140 settings, FreeRDP_RedirectClipboard, m_pParameter->GetClipboard());
142#if FreeRDP_VERSION_MAJOR >= 3
143 bool bOnlyView = m_pParameter->GetOnlyView();
144 freerdp_settings_set_bool(
145 settings, FreeRDP_SuspendInput, bOnlyView);
148 freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth,
149 m_pParameter->GetDesktopWidth());
150 freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight,
151 m_pParameter->GetDesktopHeight());
152 freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth,
153 m_pParameter->GetColorDepth());
155 freerdp_settings_set_bool(settings, FreeRDP_UseMultimon,
156 m_pParameter->GetUseMultimon());
158 if(m_pParameter->GetReconnectInterval()) {
159 freerdp_settings_set_bool(
160 settings, FreeRDP_AutoReconnectionEnabled,
true);
161 freerdp_settings_set_uint32(
163 FreeRDP_AutoReconnectMaxRetries,
164 m_pParameter->GetReconnectInterval());
167 freerdp_settings_set_bool(
168 settings, FreeRDP_AutoReconnectionEnabled,
false);
172 RedirectionMicrophone();
174 RedirectionPrinter();
178 switch(m_pParameter->m_Proxy.GetUsedType())
180 case CParameterProxy::TYPE::None:
182 if(!m_pParameter->GetDomain().isEmpty())
183 freerdp_settings_set_string(
184 settings, FreeRDP_Domain,
185 m_pParameter->GetDomain().toStdString().c_str());
186 if(m_pParameter->m_Net.GetHost().isEmpty())
189 szErr = tr(
"The server is empty, please input it");
190 qCritical(log) << szErr;
192 emit
sigError(-1, szErr.toStdString().c_str());
193 return OnInitReturnValue::Fail;
195 auto &net = m_pParameter->m_Net;
196 freerdp_settings_set_string(
197 settings, FreeRDP_ServerHostname,
198 net.GetHost().toStdString().c_str());
199 freerdp_settings_set_uint32(
200 settings, FreeRDP_ServerPort,
203 nRet = freerdp_client_start(pRdpContext);
206 qCritical(log) <<
"freerdp_client_start fail";
207 return OnInitReturnValue::Fail;
212 case CParameterProxy::TYPE::SSHTunnel:
216 auto &ssh = m_pParameter->m_Proxy.m_SSH;
217 parameter->setServer(ssh.GetHost());
218 parameter->setPort(ssh.GetPort());
220 parameter->SetUser(user.GetUser());
221 parameter->SetUseSystemFile(user.GetUseSystemFile());
222 if(CParameterUser::TYPE::UserPassword == user.GetUsedType()) {
223 parameter->SetAuthenticationMethod(SSH_AUTH_METHOD_PASSWORD);
224 parameter->SetPassword(user.GetPassword());
226 if(CParameterUser::TYPE::PublicKey == user.GetUsedType()) {
227 parameter->SetAuthenticationMethod(SSH_AUTH_METHOD_PUBLICKEY);
228 parameter->SetPublicKeyFile(user.GetPublicKeyFile());
229 parameter->SetPrivateKeyFile(user.GetPrivateKeyFile());
230 parameter->SetPassphrase(user.GetPassphrase());
232 auto &net = m_pParameter->m_Net;
233 parameter->SetRemoteHost(net.GetHost());
234 parameter->SetRemotePort(net.GetPort());
240 return OnInitReturnValue::Fail;
241 bool check = connect(m_pThread, SIGNAL(sigServer(QString, quint16)),
242 this, SLOT(slotConnectProxyServer(QString, quint16)));
244 check = connect(m_pThread, SIGNAL(
sigError(
int,QString)),
245 this, SIGNAL(
sigError(
int,QString)));
258 return OnInitReturnValue::UseOnProcess;
263 qDebug(log) << Q_FUNC_INFO;
275 CloseHandle(m_writeEvent);
276 m_writeEvent =
nullptr;
280 rdpContext* pRdpContext = (rdpContext*)m_pContext;
281 if(!freerdp_disconnect(pRdpContext->instance))
282 qCritical(log) <<
"freerdp_disconnect fail";
284 if(freerdp_client_stop(pRdpContext))
285 qCritical(log) <<
"freerdp_client_stop fail";
287 freerdp_client_context_free(pRdpContext);
288 m_pContext =
nullptr;
311 rdpContext* pRdpContext = (rdpContext*)m_pContext;
313 if(
nullptr == freerdp_settings_get_string(pRdpContext->settings, FreeRDP_ServerHostname))
321 nCount = freerdp_get_event_handles(pRdpContext, &handles[nCount],
322 ARRAYSIZE(handles) - nCount);
325 qCritical(log) <<
"freerdp_get_event_handles failed";
330 handles[nCount] = m_writeEvent;
333 DWORD waitStatus = WaitForMultipleObjects(nCount, handles, FALSE, 500);
335 ResetEvent(m_writeEvent);
337 if (waitStatus == WAIT_FAILED)
339 qCritical(log) <<
"WaitForMultipleObjects: WAIT_FAILED";
344 if(waitStatus == WAIT_TIMEOUT)
351 if (!freerdp_check_event_handles(pRdpContext))
355 UINT32 err = freerdp_get_last_error(pRdpContext);
357 szErr =
"freerdp_check_event_handles fail.";
359 szErr += QString::number(err);
361 szErr += freerdp_get_last_error_category(err);
363 szErr += freerdp_get_last_error_name(err);
365 szErr += freerdp_get_last_error_string(err);
366 qCritical(log) << szErr;
390#if FreeRDP_VERSION_MAJOR >= 3
391 if(freerdp_shall_disconnect_context(pRdpContext))
393 if(freerdp_shall_disconnect(pRdpContext->instance))
396 qCritical(log) <<
"freerdp_shall_disconnect false";
404void CConnectFreeRDP::slotClipBoardChanged()
406 qDebug(log) << Q_FUNC_INFO;
407 if(m_pParameter && m_pParameter->GetOnlyView())
return;
408 if(m_pParameter->GetClipboard())
409 m_ClipBoard.slotClipBoardChanged();
412BOOL CConnectFreeRDP::cbGlobalInit()
414 qDebug(log) << Q_FUNC_INFO;
418void CConnectFreeRDP::cbGlobalUninit()
420 qDebug(log) << Q_FUNC_INFO;
423BOOL CConnectFreeRDP::cbClientNew(freerdp *instance, rdpContext *context)
425 qDebug(log) << Q_FUNC_INFO;
428 instance->PostDisconnect = cb_post_disconnect;
431#if FreeRDP_VERSION_MAJOR < 3
432 instance->Authenticate = cb_authenticate;
433 instance->GatewayAuthenticate = cb_GatewayAuthenticate;
435 instance->AuthenticateEx = cb_authenticate_ex;
436 instance->ChooseSmartcard = cb_choose_smartcard;
441 instance->PresentGatewayMessage = cb_present_gateway_message;
443 instance->LogonErrorInfo = cb_logon_error_info;
448void CConnectFreeRDP::cbClientFree(freerdp *instance, rdpContext *context)
450 qDebug(log) << Q_FUNC_INFO;
453int CConnectFreeRDP::cbClientStart(rdpContext *context)
455 qDebug(log) << Q_FUNC_INFO;
458 if (!context || !context->settings)
460 freerdp* instance = freerdp_client_get_instance(context);
464 auto settings = context->settings;
468 szHost = freerdp_settings_get_string(settings, FreeRDP_ServerHostname);
469 nPort = freerdp_settings_get_uint32(settings, FreeRDP_ServerPort);
471 auto &net = pThis->m_pParameter->m_Net;
472 szServer = net.GetHost() +
":" + QString::number(net.GetPort());
473 auto &proxy = pThis->m_pParameter->m_Proxy;
474 switch(proxy.GetUsedType()) {
475 case CParameterProxy::TYPE::SSHTunnel:
477 auto &sshNet = proxy.m_SSH;
478 szServer = szHost +
":" + QString::number(nPort)
479 +
" <-> " + sshNet.GetHost() +
":" + QString::number(sshNet.GetPort())
480 +
" <-> " + szServer;
487 BOOL status = freerdp_connect(instance);
489 QString szInfo = tr(
"Connect to ") + szServer;
490 qInfo(log) << szInfo;
494 UINT32 nErr = freerdp_get_last_error(context);
497 szErr = tr(
"Connect to ") + szServer + tr(
" fail.");
499 szErr += QString::number(nErr) +
" - ";
500 szErr += freerdp_get_last_error_name(nErr);
505 szErr += freerdp_get_last_error_string(nErr);
509 case FREERDP_ERROR_CONNECT_LOGON_FAILURE:
512 QString szErr = tr(
"Logon to ") + szServer;
513 szErr += tr(
" fail. Please check that the username and password are correct.") +
"\n";
517 case FREERDP_ERROR_CONNECT_WRONG_PASSWORD:
520 QString szErr = tr(
"Logon to ") + szServer;
521 szErr += tr(
" fail. Please check password are correct.") +
"\n";
525 case FREERDP_ERROR_AUTHENTICATION_FAILED:
528 QString szErr = tr(
"Logon to ") + szServer;
529 szErr += tr(
" authentication fail. please add a CA certificate to the store.") +
"\n";
533 case FREERDP_ERROR_CONNECT_TRANSPORT_FAILED:
536 QString szErr = tr(
"Logon to ") + szServer;
537 szErr += tr(
" connect transport layer fail.") +
"\n\n";
538 szErr += tr(
"Please:") +
"\n";
539 szErr += tr(
"1. Check for any network related issues") +
"\n";
540 szErr += tr(
"2. Check you have proper security settings ('NLA' enabled is required for most connections nowadays)") +
"\n";
541 szErr += tr(
"3. Check the certificate is proper (and guacd properly checks that)") +
"\n";
545 case FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED:
551 qCritical(log) << szErr;
552 emit pThis->
sigError(nRet, szErr.toStdString().c_str());
557int CConnectFreeRDP::cbClientStop(rdpContext *context)
560 qDebug(log) << Q_FUNC_INFO;
561#if FreeRDP_VERSION_MAJOR >= 3
562 nRet = freerdp_client_common_stop(context);
564 BOOL bRet = freerdp_abort_connect(context->instance);
566 { qCritical(log) <<
"freerdp_abort_connect fail";
593 qDebug(log) << Q_FUNC_INFO;
594 rdpChannels* channels =
nullptr;
595 rdpSettings* settings =
nullptr;
596 rdpContext* context = instance->context;
598 if (!instance || !instance->context || !instance->context->settings)
604 if(!pThis)
return FALSE;
605 settings = instance->context->settings;
606 channels = context->channels;
609#if defined (Q_OS_WIN)
610 if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMajorType, OSMAJORTYPE_WINDOWS))
612 if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_WINDOWS_NT))
614#elif defined(Q_OS_ANDROID)
615 if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMajorType, OSMAJORTYPE_ANDROID))
617 if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_UNSPECIFIED))
619#elif defined(Q_OS_IOS)
620 if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMajorType, OSMAJORTYPE_IOS))
622 if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_UNSPECIFIED))
624#elif defined (Q_OS_UNIX)
625 if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMajorType, OSMAJORTYPE_UNIX))
627 if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_NATIVE_XSERVER))
630 if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMajorType, OSMAJORTYPE_UNSPECIFIED))
632 if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_UNSPECIFIED))
637 PubSub_SubscribeChannelConnected(instance->context->pubSub,
638 OnChannelConnectedEventHandler);
639 PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
640 OnChannelDisconnectedEventHandler);
642#if FreeRDP_VERSION_MAJOR < 3
643 if (!freerdp_client_load_addins(channels, instance->context->settings))
648 if (freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly))
651 auto &user = pThis->m_pParameter->m_Net.
m_User;
652 if(!freerdp_settings_get_string(settings, FreeRDP_Username)) {
653 if(user.GetUser().isEmpty()) {
654 if(user.GetUser().isEmpty()) {
656 qWarning(log) <<
"Auth-only, but no user name set. Will be call instance->Authenticate.";
659 freerdp_settings_set_string(
660 settings, FreeRDP_Username,
661 user.GetUser().toStdString().c_str());
663 if (!freerdp_settings_get_string(settings, FreeRDP_Password)) {
664 if (user.GetPassword().isEmpty()) {
666 qWarning(log) <<
"auth-only, but no password set. Will be call instance->Authenticate";
668 freerdp_settings_set_string(
669 settings, FreeRDP_Password,
670 user.GetPassword().toStdString().c_str());
672#if FreeRDP_VERSION_MAJOR >= 3
673 if (!freerdp_settings_set_bool(settings, FreeRDP_DeactivateClientDecoding, TRUE))
676 qInfo(log) <<
"Authentication only. Don't connect to X.";
677 }
else if(freerdp_settings_get_bool(settings, FreeRDP_CredentialsFromStdin)){
679 }
else if(freerdp_settings_get_bool(settings, FreeRDP_SmartcardLogon)) {
690 UINT32 width = pThis->m_pParameter->GetDesktopWidth();
691 UINT32 height = pThis->m_pParameter->GetDesktopHeight();
692 if ((width < 64) || (height < 64) ||
693 (width > 4096) || (height > 4096))
695 QString szErr = tr(
"Invalid dimensions:")
696 + QString::number(width)
697 +
"*" + QString::number(height);
698 qCritical(log) << szErr;
702 qInfo(log) <<
"Init desktop size " << width <<
"*" << height;
706 <<
"width:" << freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth)
707 <<
"height:" << freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)
708 <<
"ColorDepth:" << freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth);
713const char* CConnectFreeRDP::GetTitle(freerdp* instance)
715 const char* windowTitle;
718 const char* name =
nullptr;
721 rdpSettings* settings = instance->context->settings;
726 windowTitle = freerdp_settings_get_string(settings, FreeRDP_WindowTitle);
730#if FreeRDP_VERSION_MAJOR >= 3
731 name = freerdp_settings_get_server_name(settings);
733 name = pThis->m_pParameter->m_Net.GetHost().toStdString().c_str();
735 port = freerdp_settings_get_uint32(settings, FreeRDP_ServerPort);
737 addPort = (port != 3389);
739 char buffer[MAX_PATH + 64] = { 0 };
742 sprintf_s(buffer,
sizeof(buffer),
"%s", name);
744 sprintf_s(buffer,
sizeof(buffer),
"%s:%" PRIu32, name, port);
746 freerdp_settings_set_string(settings, FreeRDP_WindowTitle, buffer);
747 return freerdp_settings_get_string(settings, FreeRDP_WindowTitle);
757 qDebug(log) << Q_FUNC_INFO;
759 rdpContext* context = instance->context;
760 rdpSettings* settings = instance->context->settings;
761 rdpUpdate* update = instance->context->update;
764 const char* pWindowTitle = GetTitle(instance);
767 WCHAR* windowTitle = NULL;
768#if FreeRDP_VERSION_MAJOR >= 3
769 windowTitle = ConvertUtf8ToWCharAlloc(pWindowTitle, NULL);
771 ConvertToUnicode(CP_UTF8, 0, pWindowTitle, -1, &windowTitle, 0);
775 QString title = QString::fromUtf16((
const char16_t*)windowTitle);
777 if(pThis->m_pParameter->GetServerName().isEmpty())
778 emit pThis->sigServerName(title);
782 int desktopWidth = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
783 int desktopHeight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
784 emit pThis->sigSetDesktopSize(desktopWidth, desktopHeight);
786 if (!gdi_init(instance, PIXEL_FORMAT_BGRA32))
789 if(!pThis->CreateImage(instance->context))
792 Q_ASSERT(instance->context->cache);
795 if(pThis->m_Cursor.RegisterPointer(context->graphics))
798 update->BeginPaint = cb_begin_paint;
799 update->EndPaint = cb_end_paint;
800 update->DesktopResize = cb_desktop_resize;
802 update->PlaySound = cb_play_bell_sound;
804 update->SetKeyboardIndicators = cb_keyboard_set_indicators;
805 update->SetKeyboardImeStatus = cb_keyboard_set_ime_status;
811void CConnectFreeRDP::cb_post_disconnect(freerdp* instance)
813 qDebug(log) << Q_FUNC_INFO;
814 rdpContext* context =
nullptr;
816 if (!instance || !instance->context)
819 context = instance->context;
821 PubSub_UnsubscribeChannelConnected(instance->context->pubSub,
822 OnChannelConnectedEventHandler);
823 PubSub_UnsubscribeChannelDisconnected(instance->context->pubSub,
824 OnChannelDisconnectedEventHandler);
828int CConnectFreeRDP::cb_logon_error_info(freerdp* instance, UINT32 data, UINT32 type)
831 const char* str_data = freerdp_get_logon_error_info_data(data);
832 const char* str_type = freerdp_get_logon_error_info_type(type);
833 QString szErr = tr(
"FreeRDP logon info: [");
837 qDebug(log) << szErr;
843void CConnectFreeRDP::OnChannelConnectedEventHandler(
void *context,
844 #
if FreeRDP_VERSION_MAJOR >= 3
847 ChannelConnectedEventArgs *e)
849 rdpContext* pContext = (rdpContext*)context;
851 if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) {
852 qDebug(log) <<
"channel" << e->name <<
"connected";
853 pThis->m_ClipBoard.Init((CliprdrClientContext*)e->pInterface,
854 pThis->m_pParameter->GetClipboard());
856#if FreeRDP_VERSION_MAJOR >= 3
858 freerdp_client_OnChannelConnectedEventHandler(pContext, e);
860 else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0)
862 if (freerdp_settings_get_bool(pContext->settings, FreeRDP_SoftwareGdi)) {
863 rdpGdi* gdi = pContext->gdi;
865 gdi_graphics_pipeline_init(gdi, (RdpgfxClientContext*) e->pInterface);
868 qDebug(log,
"Unimplemented: channel %s connected but libfreerdp is in HardwareGdi mode\n", e->name);
870 else if (strcmp(e->name, GEOMETRY_DVC_CHANNEL_NAME) == 0)
872 gdi_video_geometry_init(pContext->gdi, (GeometryClientContext*)e->pInterface);
874 else if (strcmp(e->name, VIDEO_DATA_DVC_CHANNEL_NAME) == 0)
876 gdi_video_data_init(pContext->gdi, (VideoClientContext*)e->pInterface);
878 qDebug(log) <<
"Unimplemented: channel" << e->name <<
"connected but we can’t use it";
882void CConnectFreeRDP::OnChannelDisconnectedEventHandler(
void *context,
883 #
if FreeRDP_VERSION_MAJOR >= 3
886 ChannelDisconnectedEventArgs *e)
888 rdpContext* pContext = (rdpContext*)context;
891 if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) {
892 qDebug(log) <<
"channel" << e->name <<
"disconnected";
893 pThis->m_ClipBoard.UnInit((CliprdrClientContext*)e->pInterface,
894 pThis->m_pParameter->GetClipboard());
896#if FreeRDP_VERSION_MAJOR >= 3
898 freerdp_client_OnChannelDisconnectedEventHandler(pContext, e);
900 else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0)
902 if (freerdp_settings_get_bool(pContext->settings, FreeRDP_SoftwareGdi)) {
903 rdpGdi* gdi = pContext->gdi;
904 gdi_graphics_pipeline_uninit(gdi, (RdpgfxClientContext*) e->pInterface);
907 qDebug(log,
"Unimplemented: channel %s connected but libfreerdp is in HardwareGdi mode\n", e->name);
910 qDebug(log) <<
"Unimplemented: channel" << e->name <<
"disconnected but we can’t use it";
915UINT32 CConnectFreeRDP::GetImageFormat(QImage::Format format)
918#if (QT_VERSION >= QT_VERSION_CHECK(5,2,0))
919 case QImage::Format_RGBA8888:
920 return PIXEL_FORMAT_RGBA32;
921 case QImage::Format_RGBX8888:
922 return PIXEL_FORMAT_RGBX32;
924 case QImage::Format_RGB16:
925 return PIXEL_FORMAT_RGB16;
926 case QImage::Format_ARGB32:
927 return PIXEL_FORMAT_BGRA32;
928 case QImage::Format_RGB32:
929 return PIXEL_FORMAT_BGRA32;
936UINT32 CConnectFreeRDP::GetImageFormat()
938 return GetImageFormat(m_Image.format());
941BOOL CConnectFreeRDP::CreateImage(rdpContext *context)
944 ClientContext* pContext = (ClientContext*)context;
946 rdpGdi* gdi = context->gdi;
947 Q_ASSERT(pThis && gdi);
948 pThis->m_Image = QImage(gdi->primary_buffer,
949 static_cast<int>(gdi->width),
950 static_cast<int>(gdi->height),
951 QImage::Format_ARGB32);
955#if FreeRDP_VERSION_MAJOR >= 3
957static CREDUI_INFOW wfUiInfo = {
sizeof(CREDUI_INFOW), NULL, L
"Enter your credentials",
958 L
"Remote Desktop Security", NULL };
960BOOL CConnectFreeRDP::cb_authenticate_ex(freerdp* instance,
961 char** username,
char** password,
962 char** domain, rdp_auth_reason reason)
964 qDebug(log) << Q_FUNC_INFO <<
"reason:" << reason;
968 if(!username || !password || !domain)
return FALSE;
970 rdpContext* pContext = (rdpContext*)instance->context;
975 WCHAR UserNameW[CREDUI_MAX_USERNAME_LENGTH + 1] = { 0 };
976 WCHAR UserW[CREDUI_MAX_USERNAME_LENGTH + 1] = { 0 };
977 WCHAR DomainW[CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1] = { 0 };
978 WCHAR PasswordW[CREDUI_MAX_PASSWORD_LENGTH + 1] = { 0 };
980 WINPR_ASSERT(instance);
981 WINPR_ASSERT(instance->context);
982 WINPR_ASSERT(instance->context->settings);
984 WINPR_ASSERT(username);
985 WINPR_ASSERT(domain);
986 WINPR_ASSERT(password);
988 const WCHAR auth[] = L
"Target credentials requested";
989 const WCHAR authPin[] = L
"PIN requested";
990 const WCHAR gwAuth[] = L
"Gateway credentials requested";
991 const WCHAR* titleW = auth;
994 dwFlags = CREDUI_FLAGS_DO_NOT_PERSIST | CREDUI_FLAGS_EXCLUDE_CERTIFICATES |
995 CREDUI_FLAGS_USERNAME_TARGET_CREDENTIALS;
1002 if ((*username) && (*password))
1005 case AUTH_SMARTCARD_PIN:
1006 dwFlags &= ~CREDUI_FLAGS_USERNAME_TARGET_CREDENTIALS;
1007 dwFlags |= CREDUI_FLAGS_PASSWORD_ONLY_OK | CREDUI_FLAGS_KEEP_USERNAME;
1012 *username = _strdup(
"PIN");
1025 ConvertUtf8ToWChar(*username, UserNameW, ARRAYSIZE(UserNameW));
1026 ConvertUtf8ToWChar(*username, UserW, ARRAYSIZE(UserW));
1030 ConvertUtf8ToWChar(*password, PasswordW, ARRAYSIZE(PasswordW));
1033 ConvertUtf8ToWChar(*domain, DomainW, ARRAYSIZE(DomainW));
1035 if (_wcsnlen(PasswordW, ARRAYSIZE(PasswordW)) == 0)
1037 status = CredUIPromptForCredentialsW(&wfUiInfo, titleW, NULL, 0, UserNameW,
1038 ARRAYSIZE(UserNameW), PasswordW,
1039 ARRAYSIZE(PasswordW), &fSave, dwFlags);
1040 if (status != NO_ERROR)
1043 "CredUIPromptForCredentials unexpected status: 0x%08lX",
1048 if ((dwFlags & CREDUI_FLAGS_KEEP_USERNAME) == 0)
1050 status = CredUIParseUserNameW(UserNameW, UserW, ARRAYSIZE(UserW), DomainW,
1051 ARRAYSIZE(DomainW));
1052 if (status != NO_ERROR)
1054 CHAR User[CREDUI_MAX_USERNAME_LENGTH + 1] = { 0 };
1055 CHAR UserName[CREDUI_MAX_USERNAME_LENGTH + 1] = { 0 };
1056 CHAR Domain[CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1] = { 0 };
1058 ConvertWCharNToUtf8(UserNameW, ARRAYSIZE(UserNameW), UserName, ARRAYSIZE(UserName));
1059 ConvertWCharNToUtf8(UserW, ARRAYSIZE(UserW), User, ARRAYSIZE(User));
1060 ConvertWCharNToUtf8(DomainW, ARRAYSIZE(DomainW), Domain, ARRAYSIZE(Domain));
1062 "Failed to parse UserName: %s into User: %s Domain: %s",
1063 UserName, User, Domain);
1069 *username = ConvertWCharNToUtf8Alloc(UserW, ARRAYSIZE(UserW), NULL);
1072 qCritical(log) <<
"ConvertWCharNToUtf8Alloc failed" << status;
1076 if (_wcsnlen(DomainW, ARRAYSIZE(DomainW)) > 0)
1077 *domain = ConvertWCharNToUtf8Alloc(DomainW, ARRAYSIZE(DomainW), NULL);
1079 *domain = _strdup(
"\0");
1084 qCritical(log) <<
"strdup failed" << status;
1088 *password = ConvertWCharNToUtf8Alloc(PasswordW, ARRAYSIZE(PasswordW), NULL);
1097 return cb_authenticate(instance, username, password, domain);
1102BOOL CConnectFreeRDP::cb_choose_smartcard(freerdp* instance,
1103 SmartcardCertInfo** cert_list,
1105 DWORD* choice, BOOL gateway)
1107 rdpContext* pContext = (rdpContext*)instance->context;
1109 QString msg(
"Multiple smartcards are available for use:\n");
1110 for (DWORD i = 0; i < count; i++)
1112 const SmartcardCertInfo* cert = cert_list[i];
1113 char* reader = ConvertWCharToUtf8Alloc(cert->reader, NULL);
1114 char* container_name = ConvertWCharToUtf8Alloc(cert->containerName, NULL);
1116 msg += QString::number(i) +
" ";
1117 msg += QString(container_name) +
"\n\t";
1118 msg +=
"Reader: " + QString(reader) +
"\n\t";
1119 msg +=
"User: " + QString(cert->userHint) + +
"@" + QString(cert->domainHint) +
"\n\t";
1120 msg +=
"Subject: " + QString(cert->subject) +
"\n\t";
1121 msg +=
"Issuer: " + QString(cert->issuer) +
"\n\t";
1122 msg +=
"UPN: " + QString(cert->upn) +
"\n";
1125 free(container_name);
1128 msg +=
"\nChoose a smartcard to use for ";
1130 msg +=
"gateway authentication";
1134 msg +=
"(0 - " + QString::number(count - 1) +
")";
1142 int n = num.toInt(&ok);
1154BOOL CConnectFreeRDP::cb_authenticate(freerdp* instance,
char** username,
1155 char** password,
char** domain)
1157 qDebug(log) << Q_FUNC_INFO;
1160 rdpContext* pContext = (rdpContext*)instance->context;
1162 if(!username || !password || !domain)
return FALSE;
1163 if(*username && *password )
return TRUE;
1165 int nRet = QDialog::Rejected;
1167 nRet, pThis->m_pParameter);
1168 if(QDialog::Accepted == nRet)
1170 QString szPassword = pThis->m_pParameter->m_Net.
m_User.GetPassword();
1171 QString szName = pThis->m_pParameter->m_Net.
m_User.GetUser();
1172 QString szDomain = pThis->m_pParameter->GetDomain();
1173 if(!szDomain.isEmpty() && domain)
1174 *domain = _strdup(szDomain.toStdString().c_str());
1175 if(!szName.isEmpty() && username)
1176 *username = _strdup(szName.toStdString().c_str());
1177 if(!szPassword.isEmpty() && password)
1178 *password = _strdup(szPassword.toStdString().c_str());
1185BOOL CConnectFreeRDP::cb_GatewayAuthenticate(freerdp *instance,
1186 char **username,
char **password,
char **domain)
1188 qDebug(log) << Q_FUNC_INFO;
1192 rdpContext* pContext = (rdpContext*)instance->context;
1194 if(!username || !password || !domain)
return FALSE;
1195 if(*username && *password )
return TRUE;
1197 int nRet = QDialog::Rejected;
1198 emit pThis->
sigBlockShowWidget(
"CDlgGetUserPasswordFreeRDP", nRet, pThis->m_pParameter);
1199 if(QDialog::Accepted == nRet)
1201 QString szPassword = pThis->m_pParameter->m_Net.
m_User.GetPassword();
1202 QString szName = pThis->m_pParameter->m_Net.
m_User.GetUser();
1203 QString szDomain = pThis->m_pParameter->GetDomain();
1204 if(!szDomain.isEmpty() && domain)
1205 *domain = _strdup(szDomain.toStdString().c_str());
1206 if(!szName.isEmpty() && username)
1207 *username = _strdup(szName.toStdString().c_str());
1208 if(!szPassword.isEmpty() && password)
1209 *password = _strdup(szPassword.toStdString().c_str());
1217 const BYTE* data,
size_t length,
1218 const char* hostname, UINT16 port, DWORD flags)
1220 qDebug(log) << Q_FUNC_INFO;
1221 rdpContext* pContext = (rdpContext*)instance->context;
1223 QSslCertificate cert(QByteArray((
const char*)data, length));
1226 instance, hostname, port,
1227 cert.issuerDisplayName().toStdString().c_str(),
1228 cert.subjectDisplayName().toStdString().c_str(),
1229 cert.issuerDisplayName().toStdString().c_str(),
1230 cert.serialNumber().toStdString().c_str(),
1252 const char *host, UINT16 port,
1253 const char *common_name,
const char *subject,
1254 const char *issuer,
const char *fingerprint, DWORD flags)
1256 qDebug(log) << Q_FUNC_INFO;
1258 rdpContext* pContext = (rdpContext*)instance->context;
1265 emit pThis->sigServerName(common_name);
1268 if(!pThis->m_pParameter->GetShowVerifyDiaglog()) {
1274 QString szType = tr(
"RDP-Server");
1275 if (flags & VERIFY_CERT_FLAG_GATEWAY)
1276 szType = tr(
"RDP-Gateway");
1277 if (flags & VERIFY_CERT_FLAG_REDIRECT)
1278 szType = tr(
"RDP-Redirect");
1280 QString title(tr(
"Verify certificate"));
1283 message += szType + tr(
": %1:%2").arg(host, QString::number(port)) +
"\n";
1284 message += tr(
"Common name: ") + common_name +
"\n";
1285 message += tr(
"Subject: ") + subject +
"\n";
1286 message += tr(
"Issuer: ") + issuer +
"\n";
1287 message += tr(
"Fingerprint: ") + fingerprint +
"\n";
1289 if(VERIFY_CERT_FLAG_CHANGED & flags) {
1290 message += tr(
"The above X.509 certificate is changed.\n"
1291 "It is possible that the server has changed its certificate, "
1292 "or Maybe it was attacked."
1293 "Please look at the OpenSSL documentation on "
1294 "how to add a private CA to the store.");
1296 message += tr(
"The above X.509 certificate could not be verified.\n"
1297 "Possibly because you do not have the CA certificate "
1298 "in your certificate store, or the certificate has expired.\n"
1299 "Please look at the OpenSSL documentation on "
1300 "how to add a private CA to the store.");
1304 message += tr(
"Yes - trusted") +
"\n";
1305 message += tr(
"Ignore - temporary trusted") +
"\n";
1306 message += tr(
"No - no trusted") +
"\n";
1308 QMessageBox::StandardButton nRet = QMessageBox::StandardButton::No;
1309 QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::Ignore | QMessageBox::No;
1310 bool bCheckBox =
false;
1312 tr(
"Don't show again"));
1313 pThis->m_pParameter->SetShowVerifyDiaglog(!bCheckBox);
1319 case QMessageBox::StandardButton::Yes:
1321 case QMessageBox::StandardButton::Ignore:
1349 const char *host, UINT16 port,
1350 const char *common_name,
const char *subject,
1351 const char *issuer,
const char *fingerprint,
1352 const char *old_subject,
const char *old_issuer,
1353 const char *old_fingerprint, DWORD flags)
1355 qDebug(log) << Q_FUNC_INFO;
1356 rdpContext* pContext = (rdpContext*)instance->context;
1359 emit pThis->sigServerName(common_name);
1361 if(!pThis->m_pParameter->GetShowVerifyDiaglog()) {
1367 QString szType = tr(
"RDP-Server");
1368 if (flags & VERIFY_CERT_FLAG_GATEWAY)
1369 szType = tr(
"RDP-Gateway");
1370 if (flags & VERIFY_CERT_FLAG_REDIRECT)
1371 szType = tr(
"RDP-Redirect");
1373 QString title(tr(
"Verify changed certificate"));
1375 message += szType + tr(
": %1:%2").arg(host, QString::number(port)) +
"\n";
1376 message += tr(
"Common name: ") + common_name +
"\n";
1377 message += tr(
"New subject: ") + subject +
"\n";
1378 message += tr(
"New issuer: ") + issuer +
"\n";
1379 message += tr(
"New fingerprint: ") + fingerprint +
"\n";
1380 message += tr(
"Old subject: ") + old_subject +
"\n";
1381 message += tr(
"Old issuer: ") + old_issuer +
"\n";
1382 message += tr(
"Old fingerprint: ") + old_fingerprint +
"\n";
1384 message += tr(
"The above X.509 certificate could not be verified, "
1385 "possibly because you do not have the CA certificate "
1386 "in your certificate store, or the certificate has expired. "
1387 "Please look at the OpenSSL documentation on "
1388 "how to add a private CA to the store.");
1391 message += tr(
"Yes - trusted") +
"\n";
1392 message += tr(
"Ignore - temporary trusted") +
"\n";
1393 message += tr(
"No - no trusted") +
"\n";
1395 bool bCheckBox =
false;
1396 QMessageBox::StandardButton nRet = QMessageBox::StandardButton::No;
1397 QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::Ignore | QMessageBox::No;
1399 tr(
"Don't show again"));
1400 pThis->m_pParameter->SetShowVerifyDiaglog(!bCheckBox);
1407 case QMessageBox::StandardButton::Yes:
1409 case QMessageBox::StandardButton::Ignore:
1420BOOL CConnectFreeRDP::cb_present_gateway_message(
1421 freerdp* instance, UINT32 type, BOOL isDisplayMandatory,
1422 BOOL isConsentMandatory,
size_t length,
const WCHAR* message)
1424 qDebug(log) << Q_FUNC_INFO;
1426 if (!isDisplayMandatory && !isConsentMandatory)
1430 if (type == GATEWAY_MESSAGE_CONSENT && isConsentMandatory)
1432 QString msgType = (type == GATEWAY_MESSAGE_CONSENT)
1433 ? tr(
"Consent message") : tr(
"Service message");
1435#if FreeRDP_VERSION_MAJOR >= 3
1436 char* pMsg = ConvertWCharToUtf8Alloc(message, NULL);
1442 msgType += QString::fromStdWString((
wchar_t*)message);
1445 msgType += tr(
"I understand and agree to the terms of this policy (Y/N)");
1447 rdpContext* pContext = (rdpContext*)instance->context;
1449 QMessageBox::StandardButton nRet = QMessageBox::No;
1450 bool bCheckBox =
false;
1452 QMessageBox::Yes|QMessageBox::No,
1455 case QMessageBox::Yes:
1463 return client_cli_present_gateway_message(
1464 instance, type, isDisplayMandatory,
1465 isConsentMandatory, length, message);
1470BOOL CConnectFreeRDP::cb_begin_paint(rdpContext *context)
1474 if (!context || !context->gdi || !context->gdi->primary
1475 || !context->gdi->primary->hdc)
1478 hdc = context->gdi->primary->hdc;
1480 if (!hdc || !hdc->hwnd || !hdc->hwnd->invalid)
1483 hdc->hwnd->invalid->null = TRUE;
1484 hdc->hwnd->ninvalid = 0;
1488BOOL CConnectFreeRDP::UpdateBuffer(INT32 x, INT32 y, INT32 w, INT32 h)
1490 if(x > m_Image.width() || y > m_Image.height()) {
1491 qCritical(log) <<
"The width and height out of range."
1492 <<
"Image width:" << m_Image.width()
1493 <<
"Image height:" << m_Image.height()
1494 <<
"w:" << w <<
"h:" << h;
1498 QRect rect(x, y, w, h);
1499 QImage img = m_Image.copy(rect);
1505BOOL CConnectFreeRDP::cb_end_paint(rdpContext *context)
1508 ClientContext* pContext = (ClientContext*)context;
1512 REGION16 invalidRegion;
1513 RECTANGLE_16 invalidRect;
1514 const RECTANGLE_16* extents;
1518 if (!context || !context->gdi || !context->gdi->primary
1519 || !context->gdi->primary->hdc)
1522 hdc = context->gdi->primary->hdc;
1524 if (!hdc || !hdc->hwnd || !hdc->hwnd->invalid)
1527 rdpGdi* gdi = context->gdi;
1528 if (gdi->suppressOutput)
1531 HGDI_WND hwnd = context->gdi->primary->hdc->hwnd;
1532 ninvalid = hwnd->ninvalid;
1533 cinvalid = hwnd->cinvalid;
1537 region16_init(&invalidRegion);
1539 for (i = 0; i < ninvalid; i++)
1541 if(cinvalid[i].null)
1543 qWarning(log) <<
"is null region" << cinvalid[i].x << cinvalid[i].y
1544 << cinvalid[i].w << cinvalid[i].h;
1547 invalidRect.left = cinvalid[i].x;
1548 invalidRect.top = cinvalid[i].y;
1549 invalidRect.right = cinvalid[i].x + cinvalid[i].w;
1550 invalidRect.bottom = cinvalid[i].y + cinvalid[i].h;
1551 region16_union_rect(&invalidRegion, &invalidRegion, &invalidRect);
1554 if (!region16_is_empty(&invalidRegion))
1556 extents = region16_extents(&invalidRegion);
1558 pThis->UpdateBuffer(extents->left,
1560 extents->right - extents->left,
1561 extents->bottom - extents->top);
1564 region16_uninit(&invalidRegion);
1569BOOL CConnectFreeRDP::cb_desktop_resize(rdpContext* context)
1571 qDebug(log) << Q_FUNC_INFO;
1572 ClientContext* pContext = (ClientContext*)context;
1574 rdpSettings* settings;
1575 if (!context || !context->settings)
1577 settings = context->settings;
1578 int desktopWidth = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
1579 int desktopHeight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
1581 if(!gdi_resize(context->gdi, desktopWidth, desktopHeight))
1583 if(!pThis->CreateImage(context))
1586 emit pThis->sigSetDesktopSize(desktopWidth, desktopHeight);
1587 pThis->UpdateBuffer(0, 0, desktopWidth, desktopHeight);
1591BOOL CConnectFreeRDP::cb_play_bell_sound(rdpContext *context,
const PLAY_SOUND_UPDATE *play_sound)
1593 qDebug(log) << Q_FUNC_INFO;
1594 ClientContext* pContext = (ClientContext*)context;
1596 WINPR_UNUSED(play_sound);
1597 QApplication::beep();
1601#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1602 QSoundEffect effect;
1603 effect.setSource(QUrl::fromLocalFile(szFile));
1608 QSound::play(szFile);
1614BOOL CConnectFreeRDP::cb_keyboard_set_indicators(rdpContext *context, UINT16 led_flags)
1616 qDebug(log) << Q_FUNC_INFO;
1617 ClientContext* pContext = (ClientContext*)context;
1620 int state = CFrmViewer::LED_STATE::Unknown;
1622 if (led_flags & KBD_SYNC_NUM_LOCK)
1623 state |= CFrmViewer::LED_STATE::NumLock;
1624 if (led_flags & KBD_SYNC_CAPS_LOCK)
1625 state |= CFrmViewer::LED_STATE::CapsLock;
1626 if (led_flags & KBD_SYNC_SCROLL_LOCK)
1627 state |= CFrmViewer::LED_STATE::ScrollLock;
1629 emit pThis->sigUpdateLedState(state);
1635BOOL CConnectFreeRDP::cb_keyboard_set_ime_status(
1636 rdpContext* context, UINT16 imeId, UINT32 imeState, UINT32 imeConvMode)
1642 "KeyboardSetImeStatus(unitId=%04" PRIx16
", imeState=%08" PRIx32
1643 ", imeConvMode=%08" PRIx32
") ignored",
1644 imeId, imeState, imeConvMode);
1651 SetEvent(m_writeEvent);
1656bool CConnectFreeRDP::SendMouseEvent(UINT16 flags, QPoint pos,
bool isExtended)
1658 if(m_pParameter && m_pParameter->GetOnlyView())
return true;
1659 if(!m_pContext)
return false;
1661#if FreeRDP_VERSION_MAJOR >= 3
1663 freerdp_client_send_extended_button_event(
1664 &m_pContext->Context, FALSE, flags, pos.x(), pos.y());
1666 freerdp_client_send_button_event(
1667 &m_pContext->Context, FALSE, flags, pos.x(), pos.y());
1669 if(!m_pContext->Context.input)
return false;
1670 return freerdp_input_send_mouse_event(
1671 m_pContext->Context.input, flags, pos.x(), pos.y());
1676void CConnectFreeRDP::wheelEvent(QWheelEvent *event)
1678 qDebug(logMouse) << Q_FUNC_INFO << event;
1679 if(!m_pContext)
return;
1680 if(m_pParameter && m_pParameter->GetOnlyView())
return;
1684#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1685 pos =
event->position();
1689 QPoint p =
event->angleDelta();
1692 flags |= PTR_FLAGS_WHEEL | p.y();
1696 flags |= PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | -p.y();
1701 flags |= PTR_FLAGS_HWHEEL | PTR_FLAGS_WHEEL_NEGATIVE | -p.x();
1705 flags |= PTR_FLAGS_HWHEEL | p.x();
1707#if FreeRDP_VERSION_MAJOR >= 3
1708 freerdp_client_send_wheel_event(&m_pContext->Context, flags);
1713 freerdp_input_send_mouse_event(
1714 m_pContext->Context.input, flags, pos.x(), pos.y());
1719void CConnectFreeRDP::mouseMoveEvent(QMouseEvent *event)
1721 qDebug(logMouse) << Q_FUNC_INFO <<
event <<
event->buttons() <<
event->button();
1722 if(!m_pContext)
return;
1723 if(m_pParameter && m_pParameter->GetOnlyView())
return;
1724 UINT16 flags = PTR_FLAGS_MOVE;
1725 SendMouseEvent(flags, event->pos(),
false);
1728void CConnectFreeRDP::mousePressEvent(QMouseEvent *event)
1730 qDebug(logMouse) << Q_FUNC_INFO <<
event <<
event->buttons() <<
event->button();
1731 if(!m_pContext)
return;
1732 if(m_pParameter && m_pParameter->GetOnlyView())
return;
1735 bool isExtended =
false;
1736 Qt::MouseButton button =
event->button();
1737 if (button & Qt::MouseButton::LeftButton)
1739 flags = PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1;
1741 else if (button & Qt::MouseButton::RightButton)
1743 flags = PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2;
1745 else if (button & Qt::MouseButton::MiddleButton)
1747 flags = PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON3;
1749 else if (button & Qt::MouseButton::ForwardButton)
1751 flags = PTR_XFLAGS_DOWN | PTR_XFLAGS_BUTTON2;
1754 else if (button & Qt::MouseButton::BackButton)
1756 flags = PTR_XFLAGS_DOWN | PTR_XFLAGS_BUTTON1;
1761 SendMouseEvent(flags, event->pos(), isExtended);
1765void CConnectFreeRDP::mouseReleaseEvent(QMouseEvent *event)
1767 qDebug(logMouse) << Q_FUNC_INFO <<
event <<
event->buttons() <<
event->button();
1768 if(!m_pContext)
return;
1769 if(m_pParameter && m_pParameter->GetOnlyView())
return;
1772 bool isExtended =
false;
1773 Qt::MouseButton button =
event->button();
1774 if (button & Qt::MouseButton::LeftButton)
1776 flags = PTR_FLAGS_BUTTON1;
1778 else if (button & Qt::MouseButton::MiddleButton)
1780 flags = PTR_FLAGS_BUTTON3;
1782 else if (button & Qt::MouseButton::RightButton)
1784 flags = PTR_FLAGS_BUTTON2;
1786 else if (button & Qt::MouseButton::ForwardButton)
1788 flags = PTR_XFLAGS_BUTTON2;
1791 else if (button & Qt::MouseButton::BackButton)
1793 flags = PTR_XFLAGS_BUTTON1;
1798 SendMouseEvent(flags, event->pos(), isExtended);
1802void CConnectFreeRDP::keyPressEvent(QKeyEvent *event)
1804 qDebug(logKey) << Q_FUNC_INFO << event;
1805 if(!m_pContext)
return;
1806 if(m_pParameter && m_pParameter->GetOnlyView())
return;
1809 if(RDP_SCANCODE_UNKNOWN != k)
1810#if FreeRDP_VERSION_MAJOR >= 3
1811 freerdp_input_send_keyboard_event_ex(
1812 m_pContext->Context.context.input,
true,
true, k);
1814 freerdp_input_send_keyboard_event_ex(
1815 m_pContext->Context.input,
true, k);
1819void CConnectFreeRDP::keyReleaseEvent(QKeyEvent *event)
1821 qDebug(logKey) << Q_FUNC_INFO << event;
1822 if(!m_pContext)
return;
1823 if(m_pParameter && m_pParameter->GetOnlyView())
return;
1825 if(RDP_SCANCODE_UNKNOWN != k)
1826#if FreeRDP_VERSION_MAJOR >= 3
1827 freerdp_input_send_keyboard_event_ex(
1828 m_pContext->Context.context.input,
false,
false, k);
1830 freerdp_input_send_keyboard_event_ex(
1831 m_pContext->Context.input,
false, k);
1835int CConnectFreeRDP::RedirectionSound()
1837 rdpContext* pRdpContext = (rdpContext*)m_pContext;
1838 freerdp* instance = freerdp_client_get_instance(pRdpContext);
1839 rdpSettings* settings = instance->context->settings;
1842 if(m_pParameter->GetRedirectionSound()
1843 == CParameterFreeRDP::RedirecionSoundType::Disable)
1846 freerdp_settings_set_bool(settings, FreeRDP_AudioPlayback, FALSE);
1847 freerdp_settings_set_bool(settings, FreeRDP_RemoteConsoleAudio, FALSE);
1849 }
else if(m_pParameter->GetRedirectionSound()
1850 == CParameterFreeRDP::RedirecionSoundType::Local)
1852 freerdp_settings_set_bool(settings, FreeRDP_AudioPlayback, TRUE);
1853 freerdp_settings_set_bool(settings, FreeRDP_AudioCapture, TRUE);
1854 }
else if(m_pParameter->GetRedirectionSound()
1855 == CParameterFreeRDP::RedirecionSoundType::Remote)
1857 freerdp_settings_set_bool(settings, FreeRDP_RemoteConsoleAudio, TRUE);
1872 ptr.p = CommandLineParseCommaSeparatedValuesEx(
"rdpsnd",
1873 m_pParameter->GetRedirectionSoundParameters().toStdString().c_str(),
1875 BOOL status = freerdp_client_add_static_channel(settings, count,
1876 #
if FreeRDP_VERSION_MAJOR < 3
1884 status = freerdp_client_add_dynamic_channel(settings, count,
1885 #
if FreeRDP_VERSION_MAJOR < 3
1895 qCritical(log) <<
"Load rdpsnd fail";
1902int CConnectFreeRDP::RedirectionMicrophone()
1904 if(m_pParameter->GetRedirectionSound()
1905 == CParameterFreeRDP::RedirecionSoundType::Remote)
1907 if(!m_pParameter->GetRedirectionMicrophone())
1910 rdpContext* pRdpContext = (rdpContext*)m_pContext;
1911 freerdp* instance = freerdp_client_get_instance(pRdpContext);
1913 rdpSettings* settings = instance->context->settings;
1916 freerdp_settings_set_bool(settings, FreeRDP_AudioCapture, TRUE);
1927 ptr.p = CommandLineParseCommaSeparatedValuesEx(
"audin",
1928 m_pParameter->GetRedirectionMicrophoneParameters().toStdString().c_str(),
1930 BOOL status = freerdp_client_add_dynamic_channel(settings, count,
1931 #
if FreeRDP_VERSION_MAJOR < 3
1940 qCritical(log) <<
"Load audin fail";
1947int CConnectFreeRDP::RedirectionDriver()
1949 QStringList lstDrives = m_pParameter->GetRedirectionDrives();
1950 if(lstDrives.isEmpty())
1953 rdpContext* pRdpContext = (rdpContext*)m_pContext;
1954 freerdp* instance = freerdp_client_get_instance(pRdpContext);
1955 rdpSettings* settings = instance->context->settings;
1958 foreach (
auto drive, lstDrives) {
1960 char* pDrive = _strdup(drive.toStdString().c_str());
1961 const char* argvDrive[] = {
"drive", pDrive};
1962 int count =
sizeof(argvDrive) /
sizeof(
const char*);
1963 BOOL status = freerdp_client_add_device_channel(settings, count,
1964 #
if FreeRDP_VERSION_MAJOR < 3
1968 if(pDrive) free(pDrive);
1971 qCritical(log) <<
"Load drive fail";
1979int CConnectFreeRDP::RedirectionPrinter()
1981 if(!m_pParameter->GetRedirectionPrinter())
1984 rdpContext* pRdpContext = (rdpContext*)m_pContext;
1985 freerdp* instance = freerdp_client_get_instance(pRdpContext);
1986 rdpSettings* settings = instance->context->settings;
1989 QStringList printerList = QPrinterInfo::availablePrinterNames();
1990 if(printerList.isEmpty())
1992 qCritical(log) <<
"The printer is empty";
1995 qDebug(log) << printerList;
1998 const char* argvPrinter[] = {
"printer",
nullptr,
nullptr};
1999 int count =
sizeof(argvPrinter) /
sizeof(
const char*);
2000 BOOL status = freerdp_client_add_device_channel(settings, count,
2001 #
if FreeRDP_VERSION_MAJOR < 3
2006 qCritical(log) <<
"Load printer fail";
2013int CConnectFreeRDP::RedirectionSerial()
2017 rdpContext* pRdpContext = (rdpContext*)m_pContext;
2018 freerdp* instance = freerdp_client_get_instance(pRdpContext);
2019 rdpSettings* settings = instance->context->settings;
2022 QList<QSerialPortInfo> lstSerial = QSerialPortInfo::availablePorts();
2025 foreach (
auto serial, lstSerial) {
2028 qDebug(log) <<
"systemLocation:" << serial.systemLocation()
2029 <<
"portName:" << serial.portName()
2030 <<
"serialNumber:" << serial.serialNumber();
2031 char* pSerial = _strdup(serial.systemLocation().toStdString().c_str());
2032 char* pName = _strdup(serial.portName().toStdString().c_str());
2033 const char* argvSerial[] = {
"serial", pName, pSerial};
2034 int count =
sizeof(argvSerial) /
sizeof(
const char*);
2035 BOOL status = freerdp_client_add_device_channel(settings, count,
2036 #
if FreeRDP_VERSION_MAJOR < 3
2040 if(pSerial) free(pSerial);
2041 if(pName) free(pName);
2045 qCritical(log) <<
"Load drive fail";
2053void CConnectFreeRDP::slotConnectProxyServer(QString szHost, quint16 nPort)
2055 qDebug(log) <<
"CConnectFreeRDP::slotConnectProxyServer" << nPort;
2056 rdpContext* pContext = (rdpContext*)m_pContext;
2057 rdpSettings* settings = pContext->settings;
2059 qCritical(log) <<
"settings is null";
2062 freerdp_settings_set_string(
2063 settings, FreeRDP_ServerHostname,
2064 szHost.toStdString().c_str());
2065 freerdp_settings_set_uint32(
2066 settings, FreeRDP_ServerPort,
2069 int nRet = freerdp_client_start(pContext);
2072 qCritical(log) <<
"freerdp_client_start fail";
2074 qDebug(log) <<
"CConnectFreeRDP::slotConnectProxyServer end";
void sigUpdateRect(const QRect &r, const QImage &image)
通知视图,图像更新
virtual OnInitReturnValue OnInit() override
具体的插件实现连接初始化
virtual int OnClean() override
清理
static int cb_verify_x509_certificate(freerdp *instance, const BYTE *data, size_t length, const char *hostname, UINT16 port, DWORD flags)
Callback used if user interaction is required to accept a certificate.
static DWORD cb_verify_changed_certificate_ex(freerdp *instance, const char *host, UINT16 port, const char *common_name, const char *subject, const char *issuer, const char *fingerprint, const char *old_subject, const char *old_issuer, const char *old_fingerprint, DWORD flags)
Callback set in the rdp_freerdp structure, and used to make a certificate validation when a stored ce...
virtual int WakeUp() override
唤醒连接线程(后台线程)
static DWORD cb_verify_certificate_ex(freerdp *instance, const char *host, UINT16 port, const char *common_name, const char *subject, const char *issuer, const char *fingerprint, DWORD flags)
Callback set in the rdp_freerdp structure, and used to make a certificate validation when the connect...
virtual int OnProcess() override
插件连接的具体操作处理。因为此插件是非Qt事件,所以在此函数中等待。
static BOOL cb_post_connect(freerdp *instance)
Callback given to freerdp_connect() to perform post-connection operations.
static BOOL cb_pre_connect(freerdp *instance)
Callback given to freerdp_connect() to process the pre-connect operations.
void sigError(const int nError, const QString &szError=QString())
当有错误产生时触发
void sigInformation(const QString &szInfo)
从后台线程中触发在主线程中显示信息,不阻塞后台线程
void sigBlockShowMessageBox(const QString &szTitle, const QString &szMessage, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton &nRet, bool &checkBox, QString checkBoxContext=QString())
阻塞后台线程,并在前台线程中显示消息对话框(QMessageBox)
void sigShowMessageBox(const QString &szTitle, const QString &szMessage, const QMessageBox::Icon &icon=QMessageBox::Information)
从后台线程中触发在主线程中显示消息对话框(QMessageBox),不阻塞后台线程
void sigBlockInputDialog(const QString &szTitle, const QString &szLable, const QString &szMessage, QString &szText)
阻塞后台线程,并在前台线程中显示输入对话框 (QInputDialog)
void sigConnected()
当插件连接成功后触发。仅由插件触发
void sigDisconnect()
通知用户断开连接。仅由插件触发。 当从插件中需要要断开连接时触发。例如:对端断开连接、重置连接或者连接出错。
void sigBlockShowWidget(const QString &className, int &nRet, void *pContext)
阻塞后台线程,并在前台线程中显示窗口。
static UINT32 QtToScanCode(int key, Qt::KeyboardModifiers modifiers)
CConvertKeyCode::QtToScanCode
CParameterUser m_User
[Instance user]
void sigChanged()
当参数改变时,触发 通常如果需要,则相应的参数会对应一个改变事件。
实现通过本地 SOCKET 与 SSH 隧道转发数据。适用于库没有实现传输层接口,只有 socket 的情况。