From ee658151289780f79feefaee34ab973683564751 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 8 Feb 2021 10:41:34 +0100 Subject: [PATCH] Added ConnectionStateChangeEvent for clients Clients can now subscribe to connection state change events to prevend data from being transmitted on sessions being redirected. (cherry picked from commit 27f6df97783c6f18377f91c9e229cce2b7d6c694) --- include/freerdp/event.h | 5 +++++ libfreerdp/core/connection.c | 17 +++++++++++++++++ libfreerdp/core/rdp.c | 5 ----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/freerdp/event.h b/include/freerdp/event.h index 74346b3..1562362 100644 --- a/include/freerdp/event.h +++ b/include/freerdp/event.h @@ -71,6 +71,11 @@ extern "C" BOOL firstActivation; DEFINE_EVENT_END(Activated) + DEFINE_EVENT_BEGIN(ConnectionStateChange) + int state; + BOOL active; + DEFINE_EVENT_END(ConnectionStateChange) + DEFINE_EVENT_BEGIN(Terminate) int code; DEFINE_EVENT_END(Terminate) diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index bbc6031..143a1cb 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -1194,6 +1194,14 @@ int rdp_client_transition_to_state(rdpRdp* rdp, int state) case CONNECTION_STATE_ACTIVE: rdp->state = CONNECTION_STATE_ACTIVE; + { + ActivatedEventArgs activatedEvent; + rdpContext* context = rdp->context; + EventArgsInit(&activatedEvent, "libfreerdp"); + activatedEvent.firstActivation = !rdp->deactivation_reactivation; + PubSub_OnActivated(context->pubSub, context, &activatedEvent); + } + break; default: @@ -1201,6 +1209,15 @@ int rdp_client_transition_to_state(rdpRdp* rdp, int state) break; } + { + ConnectionStateChangeEventArgs stateEvent; + rdpContext* context = rdp->context; + EventArgsInit(&stateEvent, "libfreerdp"); + stateEvent.state = rdp->state; + stateEvent.active = rdp->state == CONNECTION_STATE_ACTIVE; + PubSub_OnConnectionStateChange(context->pubSub, context, &stateEvent); + } + return status; } diff --git a/libfreerdp/core/rdp.c b/libfreerdp/core/rdp.c index 090fdd6..7da499e 100644 --- a/libfreerdp/core/rdp.c +++ b/libfreerdp/core/rdp.c @@ -1648,12 +1648,7 @@ int rdp_recv_callback(rdpTransport* transport, wStream* s, void* extra) if ((status >= 0) && (rdp->finalize_sc_pdus == FINALIZE_SC_COMPLETE)) { - ActivatedEventArgs activatedEvent; - rdpContext* context = rdp->context; rdp_client_transition_to_state(rdp, CONNECTION_STATE_ACTIVE); - EventArgsInit(&activatedEvent, "libfreerdp"); - activatedEvent.firstActivation = !rdp->deactivation_reactivation; - PubSub_OnActivated(context->pubSub, context, &activatedEvent); return 2; } -- 2.7.4