libfreerdp-core: improvements to the server-side activation/reactivation code
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Sat, 20 Jul 2013 01:52:28 +0000 (21:52 -0400)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Sat, 20 Jul 2013 01:52:28 +0000 (21:52 -0400)
libfreerdp/core/activation.c
libfreerdp/core/connection.c
libfreerdp/core/freerdp.c
libfreerdp/core/peer.c
libfreerdp/core/rdp.c
libfreerdp/core/rdp.h
libfreerdp/core/update.c

index 2a904b9..edc31a2 100644 (file)
@@ -281,13 +281,10 @@ BOOL rdp_recv_deactivate_all(rdpRdp* rdp, wStream* s)
        UINT16 lengthSourceDescriptor;
 
        if (rdp->state == CONNECTION_STATE_ACTIVE)
-       {
                rdp->deactivation_reactivation = TRUE;
-       }
        else
-       {
                rdp->deactivation_reactivation = FALSE;
-       }
+
        /*
         * Windows XP can send short DEACTIVATE_ALL PDU that doesn't contain
         * the following fields.
index 10adae2..b42f230 100644 (file)
@@ -30,6 +30,7 @@
 #include <winpr/crt.h>
 
 #include <freerdp/error.h>
+#include <freerdp/listener.h>
 
 /**
  *                                      Connection Sequence\n
@@ -966,6 +967,16 @@ BOOL rdp_server_reactivate(rdpRdp* rdp)
 int rdp_server_transition_to_state(rdpRdp* rdp, int state)
 {
        int status = 0;
+       freerdp_peer* client = NULL;
+
+       if (rdp->state >= CONNECTION_STATE_RDP_SECURITY_COMMENCEMENT)
+               client = rdp->context->peer;
+
+       if (rdp->state < CONNECTION_STATE_ACTIVE)
+       {
+               if (client)
+                       client->activated = FALSE;
+       }
 
        switch (state)
        {
@@ -1026,6 +1037,28 @@ int rdp_server_transition_to_state(rdpRdp* rdp, int state)
                case CONNECTION_STATE_ACTIVE:
                        rdp->state = CONNECTION_STATE_ACTIVE;
                        update_reset_state(rdp->update);
+
+                       if (client)
+                       {
+                               if (!client->connected)
+                               {
+                                       /**
+                                        * PostConnect should only be called once and should not
+                                        * be called after a reactivation sequence.
+                                        */
+
+                                       IFCALLRET(client->PostConnect, client->connected, client);
+
+                                       if (!client->connected)
+                                               return -1;
+                               }
+
+                               IFCALLRET(client->Activate, client->activated, client);
+
+                               if (!client->activated)
+                                       return -1;
+                       }
+
                        break;
 
                default:
index 3967500..983f43e 100644 (file)
@@ -357,18 +357,19 @@ int freerdp_context_new(freerdp* instance)
 
        instance->context = (rdpContext*) malloc(instance->ContextSize);
        ZeroMemory(instance->context, instance->ContextSize);
+
        context = instance->context;
+       context->instance = instance;
 
        context->pubSub = PubSub_New(TRUE);
        PubSub_AddEventTypes(context->pubSub, FreeRDP_Events, sizeof(FreeRDP_Events) / sizeof(wEventType));
 
-       rdp = rdp_new(instance);
+       rdp = rdp_new(context);
        instance->input = rdp->input;
        instance->update = rdp->update;
        instance->settings = rdp->settings;
 
        context->graphics = graphics_new(context);
-       context->instance = instance;
        context->rdp = rdp;
 
        context->input = instance->input;
index 09cb08d..c769b40 100644 (file)
@@ -106,29 +106,6 @@ static BOOL peer_recv_data_pdu(freerdp_peer* client, wStream* s)
                        if (!rdp_server_accept_client_font_list_pdu(client->context->rdp, s))
                                return FALSE;
 
-                       if (!client->connected)
-                       {
-                               /**
-                                * PostConnect should only be called once and should not be called
-                                * after a reactivation sequence.
-                                */
-
-                               IFCALLRET(client->PostConnect, client->connected, client);
-
-                               if (!client->connected)
-                                       return FALSE;
-                       }
-
-                       if (!client->activated)
-                       {
-                               /* Activate will be called everytime after the client is activated/reactivated. */
-                       
-                               IFCALLRET(client->Activate, client->activated, client);
-
-                               if (!client->activated)
-                                       return FALSE;
-                       }
-
                        break;
 
                case DATA_PDU_TYPE_SHUTDOWN_REQUEST:
@@ -412,14 +389,15 @@ void freerdp_peer_context_new(freerdp_peer* client)
 {
        rdpRdp* rdp;
 
-       rdp = rdp_new(NULL);
+       client->context = (rdpContext*) malloc(client->ContextSize);
+       ZeroMemory(client->context, client->ContextSize);
+
+       rdp = rdp_new(client->context);
+
        client->input = rdp->input;
        client->update = rdp->update;
        client->settings = rdp->settings;
 
-       client->context = (rdpContext*) malloc(client->ContextSize);
-       ZeroMemory(client->context, client->ContextSize);
-
        client->context->rdp = rdp;
        client->context->peer = client;
        client->context->input = client->input;
index 9e7464c..867fd5c 100644 (file)
@@ -984,23 +984,25 @@ int rdp_check_fds(rdpRdp* rdp)
  * @return new RDP module
  */
 
-rdpRdp* rdp_new(freerdp* instance)
+rdpRdp* rdp_new(rdpContext* context)
 {
        rdpRdp* rdp;
 
        rdp = (rdpRdp*) malloc(sizeof(rdpRdp));
 
-       if (rdp != NULL)
+       if (rdp)
        {
                ZeroMemory(rdp, sizeof(rdpRdp));
 
-               rdp->instance = instance;
-               rdp->settings = freerdp_settings_new((void*) instance);
+               rdp->context = context;
+
+               rdp->instance = context->instance;
+               rdp->settings = freerdp_settings_new((void*) context->instance);
 
-               if (instance != NULL)
-                       instance->settings = rdp->settings;
+               if (context->instance)
+                       context->instance->settings = rdp->settings;
 
-               rdp->extension = extension_new(instance);
+               rdp->extension = extension_new(context->instance);
                rdp->transport = transport_new(rdp->settings);
                rdp->license = license_new(rdp);
                rdp->input = input_new(rdp);
index 39f9e79..aa43b98 100644 (file)
@@ -120,6 +120,7 @@ struct rdp_rdp
 {
        int state;
        freerdp* instance;
+       rdpContext* context;
        struct rdp_mcs* mcs;
        struct rdp_nego* nego;
        struct rdp_input* input;
@@ -194,7 +195,7 @@ BOOL rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s);
 void rdp_set_blocking_mode(rdpRdp* rdp, BOOL blocking);
 int rdp_check_fds(rdpRdp* rdp);
 
-rdpRdp* rdp_new(freerdp* instance);
+rdpRdp* rdp_new(rdpContext* context);
 void rdp_free(rdpRdp* rdp);
 
 #ifdef WITH_DEBUG_RDP
index d812f89..197c6df 100644 (file)
@@ -783,9 +783,6 @@ static void update_send_synchronize(rdpContext* context)
 
 static void update_send_desktop_resize(rdpContext* context)
 {
-       if (context->peer)
-               context->peer->activated = FALSE;
-
        rdp_server_reactivate(context->rdp);
 }