/src/FreeRDP/channels/echo/client/echo_main.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /**  | 
2  |  |  * FreeRDP: A Remote Desktop Protocol Implementation  | 
3  |  |  * Echo Virtual Channel Extension  | 
4  |  |  *  | 
5  |  |  * Copyright 2013 Christian Hofstaedtler  | 
6  |  |  * Copyright 2015 Thincast Technologies GmbH  | 
7  |  |  * Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>  | 
8  |  |  *  | 
9  |  |  * Licensed under the Apache License, Version 2.0 (the "License");  | 
10  |  |  * you may not use this file except in compliance with the License.  | 
11  |  |  * You may obtain a copy of the License at  | 
12  |  |  *  | 
13  |  |  *     http://www.apache.org/licenses/LICENSE-2.0  | 
14  |  |  *  | 
15  |  |  * Unless required by applicable law or agreed to in writing, software  | 
16  |  |  * distributed under the License is distributed on an "AS IS" BASIS,  | 
17  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
18  |  |  * See the License for the specific language governing permissions and  | 
19  |  |  * limitations under the License.  | 
20  |  |  */  | 
21  |  |  | 
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  | 0  | #define TAG CHANNELS_TAG("echo.client") | 
37  |  |  | 
38  |  | typedef struct  | 
39  |  | { | 
40  |  |   GENERIC_DYNVC_PLUGIN baseDynPlugin;  | 
41  |  | } ECHO_PLUGIN;  | 
42  |  |  | 
43  |  | /**  | 
44  |  |  * Function description  | 
45  |  |  *  | 
46  |  |  * @return 0 on success, otherwise a Win32 error code  | 
47  |  |  */  | 
48  |  | static UINT echo_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data)  | 
49  | 0  | { | 
50  | 0  |   GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback;  | 
51  | 0  |   const BYTE* pBuffer = Stream_ConstPointer(data);  | 
52  | 0  |   const size_t cbSize = Stream_GetRemainingLength(data);  | 
53  |  | 
  | 
54  | 0  |   WINPR_ASSERT(callback);  | 
55  | 0  |   WINPR_ASSERT(callback->channel);  | 
56  | 0  |   WINPR_ASSERT(callback->channel->Write);  | 
57  |  |  | 
58  | 0  |   if (cbSize > UINT32_MAX)  | 
59  | 0  |     return ERROR_INVALID_PARAMETER;  | 
60  |  |  | 
61  |  |   /* echo back what we have received. ECHO does not have any message IDs. */  | 
62  | 0  |   return callback->channel->Write(callback->channel, (ULONG)cbSize, pBuffer, NULL);  | 
63  | 0  | }  | 
64  |  |  | 
65  |  | /**  | 
66  |  |  * Function description  | 
67  |  |  *  | 
68  |  |  * @return 0 on success, otherwise a Win32 error code  | 
69  |  |  */  | 
70  |  | static UINT echo_on_close(IWTSVirtualChannelCallback* pChannelCallback)  | 
71  | 0  | { | 
72  | 0  |   GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback;  | 
73  |  | 
  | 
74  | 0  |   free(callback);  | 
75  |  | 
  | 
76  | 0  |   return CHANNEL_RC_OK;  | 
77  | 0  | }  | 
78  |  |  | 
79  |  | static const IWTSVirtualChannelCallback echo_callbacks = { echo_on_data_received, NULL, /* Open */ | 
80  |  |                                                          echo_on_close, NULL };  | 
81  |  |  | 
82  |  | /**  | 
83  |  |  * Function description  | 
84  |  |  *  | 
85  |  |  * @return 0 on success, otherwise a Win32 error code  | 
86  |  |  */  | 
87  |  | FREERDP_ENTRY_POINT(UINT VCAPITYPE echo_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))  | 
88  | 0  | { | 
89  | 0  |   return freerdp_generic_DVCPluginEntry(pEntryPoints, TAG, ECHO_DVC_CHANNEL_NAME,  | 
90  | 0  |                                         sizeof(ECHO_PLUGIN), sizeof(GENERIC_CHANNEL_CALLBACK),  | 
91  | 0  |                                         &echo_callbacks, NULL, NULL);  | 
92  | 0  | }  |