FreeRDP
Loading...
Searching...
No Matches
TestClientStaticBridge.c
1
11
12#include <winpr/crt.h>
13#include <winpr/wtsapi.h>
14
15#include <freerdp/client.h>
16#include <freerdp/channels/channels.h>
17
18#include "../client.h"
19#include "../mcs.h"
20#include "../rdp.h"
21
22#define TEST_CHANNEL_ID 1004
23#define TEST_OPEN_HANDLE 7
24
25typedef struct
26{
27 size_t deliveries;
28 size_t bridgeFrees;
29} TEST_STATE;
30
31static void VCAPITYPE test_open_event(LPVOID userParam, WINPR_ATTR_UNUSED DWORD openHandle,
32 UINT event, WINPR_ATTR_UNUSED LPVOID data,
33 WINPR_ATTR_UNUSED UINT32 dataLength,
34 WINPR_ATTR_UNUSED UINT32 totalLength,
35 WINPR_ATTR_UNUSED UINT32 flags)
36{
37 TEST_STATE* state = userParam;
38 WINPR_ASSERT(state);
39 if (event == CHANNEL_EVENT_DATA_RECEIVED)
40 state->deliveries++;
41}
42
43static BOOL test_bridge_send(WINPR_ATTR_UNUSED void* custom, WINPR_ATTR_UNUSED const BYTE* data,
44 WINPR_ATTR_UNUSED size_t length)
45{
46 return TRUE;
47}
48
49static void test_bridge_free(void* custom)
50{
51 TEST_STATE* state = custom;
52 WINPR_ASSERT(state);
53 state->bridgeFrees++;
54}
55
56int TestClientStaticBridge(WINPR_ATTR_UNUSED int argc, WINPR_ATTR_UNUSED char* argv[])
57{
58 int rc = -1;
59 TEST_STATE state = WINPR_C_ARRAY_INIT;
60 const BYTE data[] = { 1, 2, 3, 4 };
61
62 RDP_CLIENT_ENTRY_POINTS entry = WINPR_C_ARRAY_INIT;
63 entry.Version = RDP_CLIENT_INTERFACE_VERSION;
64 entry.Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
65 entry.ContextSize = sizeof(rdpClientContext);
66
67 rdpContext* context = freerdp_client_context_new(&entry);
68 if (!context || !context->channels || !context->rdp || !context->rdp->mcs)
69 goto out;
70
71 rdpChannels* channels = context->channels;
72 rdpMcs* mcs = context->rdp->mcs;
73 CHANNEL_OPEN_DATA* openData = &channels->openDataList[0];
74
75 channels->openDataCount = 1;
76 openData->channels = channels;
77 openData->lpUserParam = &state;
78 openData->pChannelOpenEventProcEx = test_open_event;
79 openData->stats.channelId = TEST_OPEN_HANDLE;
80 (void)strncpy(openData->stats.channelName, "test", CHANNEL_NAME_LEN);
81
82 mcs->channelCount = 1;
83 mcs->channels[0].ChannelId = TEST_CHANNEL_ID;
84 mcs->channels[0].joined = TRUE;
85 (void)strncpy(mcs->channels[0].Name, "test", CHANNEL_NAME_LEN);
86
87 /* Before migration, ordinary static transport data reaches the plugin. */
88 if (!freerdp_channels_data(context->instance, TEST_CHANNEL_ID, data, sizeof(data),
89 CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(data)) ||
90 (state.deliveries != 1))
91 goto out;
92
93 if (!freerdp_channels_set_static_bridge(context->instance, "test", test_bridge_send,
94 test_bridge_free, &state))
95 goto out;
96
97 /* Once migrated, the original static path is ignored. */
98 if (!freerdp_channels_data(context->instance, TEST_CHANNEL_ID, data, sizeof(data),
99 CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(data)) ||
100 (state.deliveries != 1))
101 goto out;
102
103 /* The DVC bridge remains the sole input path to the static plugin. */
104 if (!freerdp_channels_data_bridge(context->instance, TEST_CHANNEL_ID, data, sizeof(data),
105 CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(data)) ||
106 (state.deliveries != 2))
107 goto out;
108
109 if (!freerdp_channels_set_static_bridge(context->instance, "test", nullptr, nullptr, &state) ||
110 (state.bridgeFrees != 1))
111 goto out;
112
113 /* Closing the DVC does not restore a transport forbidden by Soft-Sync. */
114 if (!freerdp_channels_data(context->instance, TEST_CHANNEL_ID, data, sizeof(data),
115 CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(data)) ||
116 (state.deliveries != 2))
117 goto out;
118
119 rc = 0;
120out:
121 freerdp_client_context_free(context);
122 return rc;
123}