Skip to content

Commit

Permalink
FreeRDP: add CConnectFreeRDP::GetContext()
Browse files Browse the repository at this point in the history
  • Loading branch information
KangLin committed Dec 30, 2024
1 parent 4481241 commit f0c6cbd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
62 changes: 36 additions & 26 deletions Plugins/FreeRDP/Client/ConnectFreeRDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,25 @@ void CConnectFreeRDP::slotClipBoardChanged()
m_ClipBoard.slotClipBoardChanged();
}

rdpContext* CConnectFreeRDP::GetContext()
{
return (rdpContext*)m_pContext;
}

rdpSettings* CConnectFreeRDP::GetSettings()
{
if(GetContext())
return GetContext()->settings;
return nullptr;
}

CConnectFreeRDP* CConnectFreeRDP::GetConnectFreeRDP(rdpContext* context)
{
if(context)
return ((ClientContext*)context)->pThis;
return nullptr;
}

BOOL CConnectFreeRDP::cbGlobalInit()
{
qDebug(log) << Q_FUNC_INFO;
Expand Down Expand Up @@ -470,7 +489,7 @@ int CConnectFreeRDP::cbClientStart(rdpContext *context)
freerdp* instance = freerdp_client_get_instance(context);
if(!instance)
return -2;
CConnectFreeRDP* pThis = ((ClientContext*)context)->pThis;
CConnectFreeRDP* pThis = GetConnectFreeRDP(context);
auto settings = context->settings;

QString szHost;
Expand Down Expand Up @@ -603,14 +622,15 @@ BOOL CConnectFreeRDP::cb_pre_connect(freerdp* instance)
qDebug(log) << Q_FUNC_INFO;
rdpChannels* channels = nullptr;
rdpSettings* settings = nullptr;
rdpContext* context = instance->context;
rdpContext* context = nullptr;

if (!instance || !instance->context || !instance->context->settings)
{
return FALSE;
}

CConnectFreeRDP* pThis = ((ClientContext*)context)->pThis;
context = instance->context;
CConnectFreeRDP* pThis = GetConnectFreeRDP(context);
if(!pThis) return FALSE;
settings = instance->context->settings;
channels = context->channels;
Expand Down Expand Up @@ -727,7 +747,7 @@ const char* CConnectFreeRDP::GetTitle(freerdp* instance)
BOOL addPort;
const char* name = nullptr;

CConnectFreeRDP* pThis = ((ClientContext*)instance->context)->pThis;
CConnectFreeRDP* pThis = GetConnectFreeRDP(instance->context);
rdpSettings* settings = instance->context->settings;

if (!settings)
Expand Down Expand Up @@ -769,7 +789,7 @@ BOOL CConnectFreeRDP::cb_post_connect(freerdp* instance)
rdpContext* context = instance->context;
rdpSettings* settings = instance->context->settings;
rdpUpdate* update = instance->context->update;
CConnectFreeRDP* pThis = ((ClientContext*)instance->context)->pThis;
CConnectFreeRDP* pThis = GetConnectFreeRDP(instance->context);

const char* pWindowTitle = GetTitle(instance);
if(pWindowTitle)
Expand Down Expand Up @@ -857,7 +877,7 @@ void CConnectFreeRDP::OnChannelConnectedEventHandler(void *context,
ChannelConnectedEventArgs *e)
{
rdpContext* pContext = (rdpContext*)context;
CConnectFreeRDP* pThis = ((ClientContext*)context)->pThis;
CConnectFreeRDP* pThis = GetConnectFreeRDP(pContext);
if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) {
qDebug(log) << "channel" << e->name << "connected";
pThis->m_ClipBoard.Init((CliprdrClientContext*)e->pInterface,
Expand Down Expand Up @@ -906,7 +926,7 @@ void CConnectFreeRDP::OnChannelDisconnectedEventHandler(void *context,
ChannelDisconnectedEventArgs *e)
{
rdpContext* pContext = (rdpContext*)context;
CConnectFreeRDP* pThis = ((ClientContext*)context)->pThis;
CConnectFreeRDP* pThis = GetConnectFreeRDP(pContext);

if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) {
qDebug(log) << "channel" << e->name << "disconnected";
Expand Down Expand Up @@ -969,8 +989,7 @@ UINT32 CConnectFreeRDP::GetImageFormat()
BOOL CConnectFreeRDP::CreateImage(rdpContext *context)
{
Q_ASSERT(context);
ClientContext* pContext = (ClientContext*)context;
CConnectFreeRDP* pThis = pContext->pThis;
CConnectFreeRDP* pThis = GetConnectFreeRDP(context);
rdpGdi* gdi = context->gdi;
Q_ASSERT(pThis && gdi);
pThis->m_Image = QImage(gdi->primary_buffer,
Expand Down Expand Up @@ -1185,8 +1204,8 @@ BOOL CConnectFreeRDP::cb_authenticate(freerdp* instance, char** username,
qDebug(log) << Q_FUNC_INFO;
if(!instance)
return FALSE;
rdpContext* pContext = (rdpContext*)instance->context;
CConnectFreeRDP* pThis = ((ClientContext*)pContext)->pThis;

CConnectFreeRDP* pThis = GetConnectFreeRDP(instance->context);
if(!username || !password || !domain) return FALSE;
if(*username && *password ) return TRUE;

Expand Down Expand Up @@ -1217,8 +1236,7 @@ BOOL CConnectFreeRDP::cb_GatewayAuthenticate(freerdp *instance,
if(!instance)
return FALSE;

rdpContext* pContext = (rdpContext*)instance->context;
CConnectFreeRDP* pThis = ((ClientContext*)pContext)->pThis;
CConnectFreeRDP* pThis = GetConnectFreeRDP(instance->context);
if(!username || !password || !domain) return FALSE;
if(*username && *password ) return TRUE;

Expand Down Expand Up @@ -1283,9 +1301,7 @@ DWORD CConnectFreeRDP::cb_verify_certificate_ex(freerdp *instance,
{
qDebug(log) << Q_FUNC_INFO;

rdpContext* pContext = (rdpContext*)instance->context;
Q_ASSERT(pContext);
CConnectFreeRDP* pThis = ((ClientContext*)pContext)->pThis;
CConnectFreeRDP* pThis = GetConnectFreeRDP(instance->context);
Q_ASSERT(pThis);
if(common_name)
{
Expand Down Expand Up @@ -1381,8 +1397,7 @@ DWORD CConnectFreeRDP::cb_verify_changed_certificate_ex(freerdp *instance,
const char *old_fingerprint, DWORD flags)
{
qDebug(log) << Q_FUNC_INFO;
rdpContext* pContext = (rdpContext*)instance->context;
CConnectFreeRDP* pThis = ((ClientContext*)pContext)->pThis;
CConnectFreeRDP* pThis = GetConnectFreeRDP(instance->context);
if(common_name)
emit pThis->sigServerName(common_name);

Expand Down Expand Up @@ -1536,8 +1551,7 @@ QImage CConnectFreeRDP::GetImage(QRect r)
BOOL CConnectFreeRDP::cb_end_paint(rdpContext *context)
{
//qDebug(log) << Q_FUNC_INFO;
ClientContext* pContext = (ClientContext*)context;
CConnectFreeRDP* pThis = pContext->pThis;
CConnectFreeRDP* pThis = GetConnectFreeRDP(context);
INT32 ninvalid;
HGDI_RGN cinvalid;
REGION16 invalidRegion;
Expand Down Expand Up @@ -1605,8 +1619,7 @@ BOOL CConnectFreeRDP::cb_end_paint(rdpContext *context)
BOOL CConnectFreeRDP::cb_desktop_resize(rdpContext* context)
{
qDebug(log) << Q_FUNC_INFO;
ClientContext* pContext = (ClientContext*)context;
CConnectFreeRDP* pThis = pContext->pThis;
CConnectFreeRDP* pThis = GetConnectFreeRDP(context);
rdpSettings* settings;
if (!context || !context->settings)
return FALSE;
Expand All @@ -1627,8 +1640,6 @@ BOOL CConnectFreeRDP::cb_desktop_resize(rdpContext* context)
BOOL CConnectFreeRDP::cb_play_bell_sound(rdpContext *context, const PLAY_SOUND_UPDATE *play_sound)
{
qDebug(log) << Q_FUNC_INFO;
ClientContext* pContext = (ClientContext*)context;
CConnectFreeRDP* pThis = pContext->pThis;
WINPR_UNUSED(play_sound);
QApplication::beep();
return TRUE;
Expand All @@ -1650,8 +1661,7 @@ BOOL CConnectFreeRDP::cb_play_bell_sound(rdpContext *context, const PLAY_SOUND_U
BOOL CConnectFreeRDP::cb_keyboard_set_indicators(rdpContext *context, UINT16 led_flags)
{
qDebug(log) << Q_FUNC_INFO;
ClientContext* pContext = (ClientContext*)context;
CConnectFreeRDP* pThis = pContext->pThis;
CConnectFreeRDP* pThis = GetConnectFreeRDP(context);

int state = CFrmViewer::LED_STATE::Unknown;

Expand Down
6 changes: 6 additions & 0 deletions Plugins/FreeRDP/Client/ConnectFreeRDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ public Q_SLOTS:
CConnectFreeRDP* pThis;
};
ClientContext* m_pContext;
public:
rdpContext* GetContext();
rdpSettings* GetSettings();
static CConnectFreeRDP* GetConnectFreeRDP(rdpContext *context);

private:
CParameterFreeRDP* m_pParameter;

RDP_CLIENT_ENTRY_POINTS m_ClientEntryPoints;
Expand Down

0 comments on commit f0c6cbd

Please sign in to comment.