mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
libfreerdp-core: move client channels code to separate file
This commit is contained in:
@@ -75,6 +75,8 @@ set(${MODULE_PREFIX}_SRCS
|
||||
orders.h
|
||||
freerdp.c
|
||||
graphics.c
|
||||
client.c
|
||||
client.h
|
||||
capabilities.c
|
||||
capabilities.h
|
||||
certificate.c
|
||||
@@ -109,8 +111,8 @@ set(${MODULE_PREFIX}_SRCS
|
||||
update.h
|
||||
message.c
|
||||
message.h
|
||||
channel.c
|
||||
channel.h
|
||||
channels.c
|
||||
channels.h
|
||||
window.c
|
||||
window.h
|
||||
listener.c
|
||||
|
||||
143
libfreerdp/core/channels.c
Normal file
143
libfreerdp/core/channels.c
Normal file
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* Virtual Channels
|
||||
*
|
||||
* Copyright 2011 Vic Lee
|
||||
*
|
||||
* 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 <string.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/stream.h>
|
||||
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/constants.h>
|
||||
|
||||
#include <freerdp/svc.h>
|
||||
#include <freerdp/peer.h>
|
||||
#include <freerdp/addin.h>
|
||||
#include <freerdp/utils/event.h>
|
||||
#include <freerdp/utils/debug.h>
|
||||
#include <freerdp/client/channels.h>
|
||||
#include <freerdp/client/drdynvc.h>
|
||||
#include <freerdp/channels/channels.h>
|
||||
|
||||
#include "rdp.h"
|
||||
#include "channels.h"
|
||||
|
||||
BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channelId, BYTE* data, int size)
|
||||
{
|
||||
DWORD i;
|
||||
int left;
|
||||
wStream* s;
|
||||
UINT32 flags;
|
||||
int chunkSize;
|
||||
rdpChannel* channel = NULL;
|
||||
|
||||
for (i = 0; i < rdp->settings->ChannelCount; i++)
|
||||
{
|
||||
if (rdp->settings->ChannelDefArray[i].ChannelId == channelId)
|
||||
{
|
||||
channel = &rdp->settings->ChannelDefArray[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!channel)
|
||||
{
|
||||
fprintf(stderr, "freerdp_channel_send: unknown channel_id %d\n", channelId);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
flags = CHANNEL_FLAG_FIRST;
|
||||
left = size;
|
||||
|
||||
while (left > 0)
|
||||
{
|
||||
s = rdp_send_stream_init(rdp);
|
||||
|
||||
if (left > (int) rdp->settings->VirtualChannelChunkSize)
|
||||
{
|
||||
chunkSize = rdp->settings->VirtualChannelChunkSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
chunkSize = left;
|
||||
flags |= CHANNEL_FLAG_LAST;
|
||||
}
|
||||
|
||||
if ((channel->options & CHANNEL_OPTION_SHOW_PROTOCOL))
|
||||
{
|
||||
flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
|
||||
}
|
||||
|
||||
Stream_Write_UINT32(s, size);
|
||||
Stream_Write_UINT32(s, flags);
|
||||
Stream_EnsureCapacity(s, chunkSize);
|
||||
Stream_Write(s, data, chunkSize);
|
||||
|
||||
rdp_send(rdp, s, channelId);
|
||||
|
||||
data += chunkSize;
|
||||
left -= chunkSize;
|
||||
flags = 0;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL freerdp_channel_process(freerdp* instance, wStream* s, UINT16 channelId)
|
||||
{
|
||||
UINT32 length;
|
||||
UINT32 flags;
|
||||
int chunkLength;
|
||||
|
||||
if (Stream_GetRemainingLength(s) < 8)
|
||||
return FALSE;
|
||||
|
||||
Stream_Read_UINT32(s, length);
|
||||
Stream_Read_UINT32(s, flags);
|
||||
chunkLength = Stream_GetRemainingLength(s);
|
||||
|
||||
IFCALL(instance->ReceiveChannelData, instance,
|
||||
channelId, Stream_Pointer(s), chunkLength, flags, length);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL freerdp_channel_peer_process(freerdp_peer* client, wStream* s, UINT16 channelId)
|
||||
{
|
||||
UINT32 length;
|
||||
UINT32 flags;
|
||||
int chunkLength;
|
||||
|
||||
if (Stream_GetRemainingLength(s) < 8)
|
||||
return FALSE;
|
||||
|
||||
Stream_Read_UINT32(s, length);
|
||||
Stream_Read_UINT32(s, flags);
|
||||
chunkLength = Stream_GetRemainingLength(s);
|
||||
|
||||
IFCALL(client->ReceiveChannelData, client,
|
||||
channelId, Stream_Pointer(s), chunkLength, flags, length);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -20,6 +20,8 @@
|
||||
#ifndef __CHANNEL_H
|
||||
#define __CHANNEL_H
|
||||
|
||||
#include "client.h"
|
||||
|
||||
BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channel_id, BYTE* data, int size);
|
||||
BOOL freerdp_channel_process(freerdp* instance, wStream* s, UINT16 channel_id);
|
||||
BOOL freerdp_channel_peer_process(freerdp_peer* client, wStream* s, UINT16 channel_id);
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* Virtual Channels
|
||||
* Client Channels
|
||||
*
|
||||
* Copyright 2011 Vic Lee
|
||||
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,102 +21,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/stream.h>
|
||||
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/constants.h>
|
||||
|
||||
#include <freerdp/svc.h>
|
||||
#include <freerdp/peer.h>
|
||||
#include <freerdp/addin.h>
|
||||
#include <freerdp/utils/event.h>
|
||||
#include <freerdp/utils/debug.h>
|
||||
#include <freerdp/client/channels.h>
|
||||
#include <freerdp/client/drdynvc.h>
|
||||
#include <freerdp/channels/channels.h>
|
||||
|
||||
#include "rdp.h"
|
||||
#include "channel.h"
|
||||
|
||||
/**
|
||||
* Channels Client
|
||||
*/
|
||||
|
||||
#define CHANNEL_MAX_COUNT 30
|
||||
|
||||
struct rdp_channel_client_data
|
||||
{
|
||||
PVIRTUALCHANNELENTRY entry;
|
||||
PCHANNEL_INIT_EVENT_FN pChannelInitEventProc;
|
||||
void* pInitHandle;
|
||||
};
|
||||
typedef struct rdp_channel_client_data CHANNEL_CLIENT_DATA;
|
||||
|
||||
struct rdp_channel_open_data
|
||||
{
|
||||
char name[8];
|
||||
int OpenHandle;
|
||||
int options;
|
||||
int flags;
|
||||
void* pInterface;
|
||||
PCHANNEL_OPEN_EVENT_FN pChannelOpenEventProc;
|
||||
};
|
||||
typedef struct rdp_channel_open_data CHANNEL_OPEN_DATA;
|
||||
|
||||
struct _CHANNEL_OPEN_EVENT
|
||||
{
|
||||
void* Data;
|
||||
UINT32 DataLength;
|
||||
void* UserData;
|
||||
int Index;
|
||||
};
|
||||
typedef struct _CHANNEL_OPEN_EVENT CHANNEL_OPEN_EVENT;
|
||||
|
||||
/**
|
||||
* pInitHandle: handle that identifies the client connection
|
||||
* Obtained by the client with VirtualChannelInit
|
||||
* Used by the client with VirtualChannelOpen
|
||||
*/
|
||||
|
||||
struct rdp_channel_init_data
|
||||
{
|
||||
rdpChannels* channels;
|
||||
void* pInterface;
|
||||
};
|
||||
typedef struct rdp_channel_init_data CHANNEL_INIT_DATA;
|
||||
|
||||
struct rdp_channels
|
||||
{
|
||||
/* internal */
|
||||
|
||||
int clientDataCount;
|
||||
CHANNEL_CLIENT_DATA clientDataList[CHANNEL_MAX_COUNT];
|
||||
|
||||
int openDataCount;
|
||||
CHANNEL_OPEN_DATA openDataList[CHANNEL_MAX_COUNT];
|
||||
|
||||
int initDataCount;
|
||||
CHANNEL_INIT_DATA initDataList[CHANNEL_MAX_COUNT];
|
||||
|
||||
/* control for entry into MyVirtualChannelInit */
|
||||
int can_call_init;
|
||||
rdpSettings* settings;
|
||||
|
||||
/* true once freerdp_channels_post_connect is called */
|
||||
int is_connected;
|
||||
|
||||
/* used for locating the channels for a given instance */
|
||||
freerdp* instance;
|
||||
|
||||
wMessagePipe* MsgPipe;
|
||||
|
||||
DrdynvcClientContext* drdynvc;
|
||||
};
|
||||
#include "client.h"
|
||||
|
||||
static void* g_pInterface;
|
||||
static CHANNEL_INIT_DATA g_ChannelInitData;
|
||||
@@ -1031,110 +936,3 @@ int freerdp_channels_load_plugin(rdpChannels* channels, rdpSettings* settings, c
|
||||
|
||||
return freerdp_channels_client_load(channels, settings, entry, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Channels Server
|
||||
*/
|
||||
|
||||
/**
|
||||
* Channels Common
|
||||
*/
|
||||
|
||||
BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channelId, BYTE* data, int size)
|
||||
{
|
||||
DWORD i;
|
||||
int left;
|
||||
wStream* s;
|
||||
UINT32 flags;
|
||||
int chunkSize;
|
||||
rdpChannel* channel = NULL;
|
||||
|
||||
for (i = 0; i < rdp->settings->ChannelCount; i++)
|
||||
{
|
||||
if (rdp->settings->ChannelDefArray[i].ChannelId == channelId)
|
||||
{
|
||||
channel = &rdp->settings->ChannelDefArray[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!channel)
|
||||
{
|
||||
fprintf(stderr, "freerdp_channel_send: unknown channel_id %d\n", channelId);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
flags = CHANNEL_FLAG_FIRST;
|
||||
left = size;
|
||||
|
||||
while (left > 0)
|
||||
{
|
||||
s = rdp_send_stream_init(rdp);
|
||||
|
||||
if (left > (int) rdp->settings->VirtualChannelChunkSize)
|
||||
{
|
||||
chunkSize = rdp->settings->VirtualChannelChunkSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
chunkSize = left;
|
||||
flags |= CHANNEL_FLAG_LAST;
|
||||
}
|
||||
|
||||
if ((channel->options & CHANNEL_OPTION_SHOW_PROTOCOL))
|
||||
{
|
||||
flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
|
||||
}
|
||||
|
||||
Stream_Write_UINT32(s, size);
|
||||
Stream_Write_UINT32(s, flags);
|
||||
Stream_EnsureCapacity(s, chunkSize);
|
||||
Stream_Write(s, data, chunkSize);
|
||||
|
||||
rdp_send(rdp, s, channelId);
|
||||
|
||||
data += chunkSize;
|
||||
left -= chunkSize;
|
||||
flags = 0;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL freerdp_channel_process(freerdp* instance, wStream* s, UINT16 channelId)
|
||||
{
|
||||
UINT32 length;
|
||||
UINT32 flags;
|
||||
int chunkLength;
|
||||
|
||||
if (Stream_GetRemainingLength(s) < 8)
|
||||
return FALSE;
|
||||
|
||||
Stream_Read_UINT32(s, length);
|
||||
Stream_Read_UINT32(s, flags);
|
||||
chunkLength = Stream_GetRemainingLength(s);
|
||||
|
||||
IFCALL(instance->ReceiveChannelData, instance,
|
||||
channelId, Stream_Pointer(s), chunkLength, flags, length);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL freerdp_channel_peer_process(freerdp_peer* client, wStream* s, UINT16 channelId)
|
||||
{
|
||||
UINT32 length;
|
||||
UINT32 flags;
|
||||
int chunkLength;
|
||||
|
||||
if (Stream_GetRemainingLength(s) < 8)
|
||||
return FALSE;
|
||||
|
||||
Stream_Read_UINT32(s, length);
|
||||
Stream_Read_UINT32(s, flags);
|
||||
chunkLength = Stream_GetRemainingLength(s);
|
||||
|
||||
IFCALL(client->ReceiveChannelData, client,
|
||||
channelId, Stream_Pointer(s), chunkLength, flags, length);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
109
libfreerdp/core/client.h
Normal file
109
libfreerdp/core/client.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* Client Channels
|
||||
*
|
||||
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FREERDP_CORE_CLIENT_H
|
||||
#define FREERDP_CORE_CLIENT_H
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/stream.h>
|
||||
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/constants.h>
|
||||
|
||||
#include <freerdp/svc.h>
|
||||
#include <freerdp/peer.h>
|
||||
#include <freerdp/addin.h>
|
||||
#include <freerdp/utils/event.h>
|
||||
#include <freerdp/utils/debug.h>
|
||||
#include <freerdp/client/channels.h>
|
||||
#include <freerdp/client/drdynvc.h>
|
||||
#include <freerdp/channels/channels.h>
|
||||
|
||||
#define CHANNEL_MAX_COUNT 30
|
||||
|
||||
struct rdp_channel_client_data
|
||||
{
|
||||
PVIRTUALCHANNELENTRY entry;
|
||||
PCHANNEL_INIT_EVENT_FN pChannelInitEventProc;
|
||||
void* pInitHandle;
|
||||
};
|
||||
typedef struct rdp_channel_client_data CHANNEL_CLIENT_DATA;
|
||||
|
||||
struct rdp_channel_open_data
|
||||
{
|
||||
char name[8];
|
||||
int OpenHandle;
|
||||
int options;
|
||||
int flags;
|
||||
void* pInterface;
|
||||
PCHANNEL_OPEN_EVENT_FN pChannelOpenEventProc;
|
||||
};
|
||||
typedef struct rdp_channel_open_data CHANNEL_OPEN_DATA;
|
||||
|
||||
struct _CHANNEL_OPEN_EVENT
|
||||
{
|
||||
void* Data;
|
||||
UINT32 DataLength;
|
||||
void* UserData;
|
||||
int Index;
|
||||
};
|
||||
typedef struct _CHANNEL_OPEN_EVENT CHANNEL_OPEN_EVENT;
|
||||
|
||||
/**
|
||||
* pInitHandle: handle that identifies the client connection
|
||||
* Obtained by the client with VirtualChannelInit
|
||||
* Used by the client with VirtualChannelOpen
|
||||
*/
|
||||
|
||||
struct rdp_channel_init_data
|
||||
{
|
||||
rdpChannels* channels;
|
||||
void* pInterface;
|
||||
};
|
||||
typedef struct rdp_channel_init_data CHANNEL_INIT_DATA;
|
||||
|
||||
struct rdp_channels
|
||||
{
|
||||
/* internal */
|
||||
|
||||
int clientDataCount;
|
||||
CHANNEL_CLIENT_DATA clientDataList[CHANNEL_MAX_COUNT];
|
||||
|
||||
int openDataCount;
|
||||
CHANNEL_OPEN_DATA openDataList[CHANNEL_MAX_COUNT];
|
||||
|
||||
int initDataCount;
|
||||
CHANNEL_INIT_DATA initDataList[CHANNEL_MAX_COUNT];
|
||||
|
||||
/* control for entry into MyVirtualChannelInit */
|
||||
int can_call_init;
|
||||
rdpSettings* settings;
|
||||
|
||||
/* true once freerdp_channels_post_connect is called */
|
||||
int is_connected;
|
||||
|
||||
/* used for locating the channels for a given instance */
|
||||
freerdp* instance;
|
||||
|
||||
wMessagePipe* MsgPipe;
|
||||
|
||||
DrdynvcClientContext* drdynvc;
|
||||
};
|
||||
|
||||
#endif /* FREERDP_CORE_CLIENT_H */
|
||||
@@ -42,7 +42,7 @@
|
||||
#include "connection.h"
|
||||
#include "redirection.h"
|
||||
#include "capabilities.h"
|
||||
#include "channel.h"
|
||||
#include "channels.h"
|
||||
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/settings.h>
|
||||
|
||||
Reference in New Issue
Block a user