2013-03-13 03:23:59 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Echo Virtual Channel Extension
|
|
|
|
*
|
|
|
|
* Copyright 2013 Christian Hofstaedtler
|
2015-06-08 15:35:27 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2013-03-13 03:23:59 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
2014-07-29 00:47:42 +04:00
|
|
|
#include <winpr/stream.h>
|
2013-03-13 03:23:59 +04:00
|
|
|
|
|
|
|
#include "echo_main.h"
|
2015-06-08 15:35:27 +03:00
|
|
|
#include <freerdp/channels/log.h>
|
|
|
|
|
|
|
|
#define TAG CHANNELS_TAG("echo.client")
|
2013-03-13 03:23:59 +04:00
|
|
|
|
|
|
|
typedef struct _ECHO_LISTENER_CALLBACK ECHO_LISTENER_CALLBACK;
|
|
|
|
struct _ECHO_LISTENER_CALLBACK
|
|
|
|
{
|
|
|
|
IWTSListenerCallback iface;
|
|
|
|
|
|
|
|
IWTSPlugin* plugin;
|
|
|
|
IWTSVirtualChannelManager* channel_mgr;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _ECHO_CHANNEL_CALLBACK ECHO_CHANNEL_CALLBACK;
|
|
|
|
struct _ECHO_CHANNEL_CALLBACK
|
|
|
|
{
|
|
|
|
IWTSVirtualChannelCallback iface;
|
|
|
|
|
|
|
|
IWTSPlugin* plugin;
|
|
|
|
IWTSVirtualChannelManager* channel_mgr;
|
|
|
|
IWTSVirtualChannel* channel;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _ECHO_PLUGIN ECHO_PLUGIN;
|
|
|
|
struct _ECHO_PLUGIN
|
|
|
|
{
|
|
|
|
IWTSPlugin iface;
|
|
|
|
|
|
|
|
ECHO_LISTENER_CALLBACK* listener_callback;
|
|
|
|
};
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT echo_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream *data)
|
2013-03-13 03:23:59 +04:00
|
|
|
{
|
|
|
|
ECHO_CHANNEL_CALLBACK* callback = (ECHO_CHANNEL_CALLBACK*) pChannelCallback;
|
2014-07-29 00:47:42 +04:00
|
|
|
BYTE* pBuffer = Stream_Pointer(data);
|
|
|
|
UINT32 cbSize = Stream_GetRemainingLength(data);
|
2013-03-13 03:23:59 +04:00
|
|
|
|
|
|
|
/* echo back what we have received. ECHO does not have any message IDs. */
|
2015-06-08 15:35:27 +03:00
|
|
|
return callback->channel->Write(callback->channel, cbSize, pBuffer, NULL);
|
2013-03-13 03:23:59 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT echo_on_close(IWTSVirtualChannelCallback* pChannelCallback)
|
2013-03-13 03:23:59 +04:00
|
|
|
{
|
|
|
|
ECHO_CHANNEL_CALLBACK* callback = (ECHO_CHANNEL_CALLBACK*) pChannelCallback;
|
|
|
|
|
|
|
|
free(callback);
|
|
|
|
|
2015-06-08 15:35:27 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-03-13 03:23:59 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT echo_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
|
2015-09-07 14:54:19 +03:00
|
|
|
IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept,
|
2013-03-13 03:23:59 +04:00
|
|
|
IWTSVirtualChannelCallback** ppCallback)
|
|
|
|
{
|
|
|
|
ECHO_CHANNEL_CALLBACK* callback;
|
|
|
|
ECHO_LISTENER_CALLBACK* listener_callback = (ECHO_LISTENER_CALLBACK*) pListenerCallback;
|
|
|
|
|
2014-07-29 00:47:42 +04:00
|
|
|
callback = (ECHO_CHANNEL_CALLBACK*) calloc(1, sizeof(ECHO_CHANNEL_CALLBACK));
|
2013-03-13 03:23:59 +04:00
|
|
|
|
2014-07-29 00:47:42 +04:00
|
|
|
if (!callback)
|
2015-06-08 15:35:27 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2013-03-13 03:23:59 +04:00
|
|
|
|
|
|
|
callback->iface.OnDataReceived = echo_on_data_received;
|
|
|
|
callback->iface.OnClose = echo_on_close;
|
|
|
|
callback->plugin = listener_callback->plugin;
|
|
|
|
callback->channel_mgr = listener_callback->channel_mgr;
|
|
|
|
callback->channel = pChannel;
|
|
|
|
|
|
|
|
*ppCallback = (IWTSVirtualChannelCallback*) callback;
|
|
|
|
|
2015-06-08 15:35:27 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-03-13 03:23:59 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT echo_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
|
2013-03-13 03:23:59 +04:00
|
|
|
{
|
|
|
|
ECHO_PLUGIN* echo = (ECHO_PLUGIN*) pPlugin;
|
|
|
|
|
2014-07-29 00:47:42 +04:00
|
|
|
echo->listener_callback = (ECHO_LISTENER_CALLBACK*) calloc(1, sizeof(ECHO_LISTENER_CALLBACK));
|
2013-03-13 03:23:59 +04:00
|
|
|
|
2014-07-29 00:47:42 +04:00
|
|
|
if (!echo->listener_callback)
|
2015-06-08 15:35:27 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2013-03-13 03:23:59 +04:00
|
|
|
|
|
|
|
echo->listener_callback->iface.OnNewChannelConnection = echo_on_new_channel_connection;
|
|
|
|
echo->listener_callback->plugin = pPlugin;
|
|
|
|
echo->listener_callback->channel_mgr = pChannelMgr;
|
|
|
|
|
|
|
|
return pChannelMgr->CreateListener(pChannelMgr, "ECHO", 0,
|
|
|
|
(IWTSListenerCallback*) echo->listener_callback, NULL);
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT echo_plugin_terminated(IWTSPlugin* pPlugin)
|
2013-03-13 03:23:59 +04:00
|
|
|
{
|
|
|
|
ECHO_PLUGIN* echo = (ECHO_PLUGIN*) pPlugin;
|
|
|
|
|
2015-05-11 10:07:39 +03:00
|
|
|
free(echo);
|
2013-03-13 03:23:59 +04:00
|
|
|
|
2015-06-08 15:35:27 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-03-13 03:23:59 +04:00
|
|
|
}
|
|
|
|
|
2016-06-15 14:36:27 +03:00
|
|
|
#ifdef BUILTIN_CHANNELS
|
2014-10-27 18:33:51 +03:00
|
|
|
#define DVCPluginEntry echo_DVCPluginEntry
|
2016-02-29 17:18:19 +03:00
|
|
|
#else
|
|
|
|
#define DVCPluginEntry FREERDP_API DVCPluginEntry
|
2014-10-27 18:33:51 +03:00
|
|
|
#endif
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
|
2013-03-13 03:23:59 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status = CHANNEL_RC_OK;
|
2013-03-13 03:23:59 +04:00
|
|
|
ECHO_PLUGIN* echo;
|
|
|
|
|
|
|
|
echo = (ECHO_PLUGIN*) pEntryPoints->GetPlugin(pEntryPoints, "echo");
|
|
|
|
|
2014-07-29 00:47:42 +04:00
|
|
|
if (!echo)
|
2013-03-13 03:23:59 +04:00
|
|
|
{
|
2014-07-29 00:47:42 +04:00
|
|
|
echo = (ECHO_PLUGIN*) calloc(1, sizeof(ECHO_PLUGIN));
|
|
|
|
|
|
|
|
if (!echo)
|
2015-06-08 15:35:27 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2013-03-13 03:23:59 +04:00
|
|
|
|
|
|
|
echo->iface.Initialize = echo_plugin_initialize;
|
|
|
|
echo->iface.Connected = NULL;
|
|
|
|
echo->iface.Disconnected = NULL;
|
|
|
|
echo->iface.Terminated = echo_plugin_terminated;
|
|
|
|
|
2014-07-29 00:47:42 +04:00
|
|
|
status = pEntryPoints->RegisterPlugin(pEntryPoints, "echo", (IWTSPlugin*) echo);
|
2013-03-13 03:23:59 +04:00
|
|
|
}
|
|
|
|
|
2014-07-29 00:47:42 +04:00
|
|
|
return status;
|
2013-03-13 03:23:59 +04:00
|
|
|
}
|