FreeRDP
client/echo_main.c
1 
22 #include <freerdp/config.h>
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 
27 #include <winpr/crt.h>
28 #include <winpr/assert.h>
29 #include <winpr/stream.h>
30 
31 #include "echo_main.h"
32 #include <freerdp/client/channels.h>
33 #include <freerdp/channels/log.h>
34 #include <freerdp/channels/echo.h>
35 
36 #define TAG CHANNELS_TAG("echo.client")
37 
38 typedef struct
39 {
40  GENERIC_DYNVC_PLUGIN baseDynPlugin;
41 } ECHO_PLUGIN;
42 
48 static UINT echo_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data)
49 {
50  GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback;
51  const BYTE* pBuffer = Stream_ConstPointer(data);
52  const size_t cbSize = Stream_GetRemainingLength(data);
53 
54  WINPR_ASSERT(callback);
55  WINPR_ASSERT(callback->channel);
56  WINPR_ASSERT(callback->channel->Write);
57 
58  if (cbSize > UINT32_MAX)
59  return ERROR_INVALID_PARAMETER;
60 
61  /* echo back what we have received. ECHO does not have any message IDs. */
62  return callback->channel->Write(callback->channel, (ULONG)cbSize, pBuffer, NULL);
63 }
64 
70 static UINT echo_on_close(IWTSVirtualChannelCallback* pChannelCallback)
71 {
72  GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback;
73 
74  free(callback);
75 
76  return CHANNEL_RC_OK;
77 }
78 
79 static const IWTSVirtualChannelCallback echo_callbacks = { echo_on_data_received, NULL, /* Open */
80  echo_on_close, NULL };
81 
87 FREERDP_ENTRY_POINT(UINT VCAPITYPE echo_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))
88 {
89  return freerdp_generic_DVCPluginEntry(pEntryPoints, TAG, ECHO_DVC_CHANNEL_NAME,
90  sizeof(ECHO_PLUGIN), sizeof(GENERIC_CHANNEL_CALLBACK),
91  &echo_callbacks, NULL, NULL);
92 }