libfreerdp-common: added parsing of /vc and /dvc

This commit is contained in:
Marc-André Moreau 2012-11-18 00:08:03 -05:00
parent 925eb59bf1
commit 4a472d5536
13 changed files with 247 additions and 133 deletions

View File

@ -25,11 +25,11 @@
#include <stdlib.h>
#include <string.h>
#include <freerdp/addin.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/stream.h>
#include <freerdp/addin.h>
#include "audin_main.h"
#define MSG_SNDIN_VERSION 0x01
@ -439,22 +439,10 @@ static void audin_register_device_plugin(IWTSPlugin* pPlugin, IAudinDevice* devi
static BOOL audin_load_device_plugin(IWTSPlugin* pPlugin, const char* name, RDP_PLUGIN_DATA* data)
{
char* fullname;
PFREERDP_AUDIN_DEVICE_ENTRY entry;
FREERDP_AUDIN_DEVICE_ENTRY_POINTS entryPoints;
if (strrchr(name, '.') != NULL)
{
entry = (PFREERDP_AUDIN_DEVICE_ENTRY) freerdp_load_dynamic_addin(name, NULL, AUDIN_DEVICE_EXPORT_FUNC_NAME);
}
else
{
fullname = xzalloc(strlen(name) + 8);
strcpy(fullname, "audin_");
strcat(fullname, name);
entry = (PFREERDP_AUDIN_DEVICE_ENTRY) freerdp_load_dynamic_addin(fullname, NULL, AUDIN_DEVICE_EXPORT_FUNC_NAME);
free(fullname);
}
entry = (PFREERDP_AUDIN_DEVICE_ENTRY) freerdp_load_channel_addin_entry("audin", (LPSTR) name, NULL, 0);
if (entry == NULL)
return FALSE;

View File

@ -231,6 +231,8 @@ int dvcman_load_plugin(IWTSVirtualChannelManager* pChannelMgr, RDP_PLUGIN_DATA*
while (data && data->size > 0)
{
printf("Loading Dynamic Virtual Channel %s\n", data->data[0]);
pDVCPluginEntry = (PDVC_PLUGIN_ENTRY) freerdp_load_channel_addin_entry((char*) data->data[0],
NULL, NULL, FREERDP_ADDIN_CHANNEL_DYNAMIC);

View File

@ -640,6 +640,7 @@ static void drive_free(DEVICE* device)
drive_file_free(file);
list_free(disk->files);
free(disk);
}

View File

@ -100,18 +100,8 @@ BOOL devman_load_device_service(DEVMAN* devman, RDPDR_DEVICE* device)
if (!ServiceName)
return FALSE;
printf("Loading device service %s (static)\n", ServiceName);
entry = (PDEVICE_SERVICE_ENTRY) freerdp_load_channel_addin_entry(ServiceName, NULL, "DeviceServiceEntry", 0);
//entry = (PDEVICE_SERVICE_ENTRY) freerdp_channels_client_find_static_entry("DeviceServiceEntry", ServiceName);
if (!entry)
{
printf("loading device service %s (dynamic)\n", ServiceName);
entry = freerdp_load_plugin(ServiceName, "DeviceServiceEntry");
}
else
{
printf("loading device service %s (static)\n", ServiceName);
}
if (entry == NULL)
return FALSE;

View File

@ -45,11 +45,13 @@ COMMAND_LINE_ARGUMENT_A args[] =
{ "t", COMMAND_LINE_VALUE_REQUIRED, "<title>", NULL, NULL, -1, "title", "window title" },
{ "decorations", COMMAND_LINE_VALUE_BOOL, NULL, NULL, BoolValueFalse, -1, NULL, "window decorations" },
{ "a", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, "addin", "addin" },
{ "u", COMMAND_LINE_VALUE_REQUIRED, "[<domain>\\|@]<user>", NULL, NULL, -1, NULL, "username" },
{ "vc", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "static virtual channel" },
{ "dvc", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "dynamic virtual channel" },
{ "u", COMMAND_LINE_VALUE_REQUIRED, "[<domain>\\]<user>", NULL, NULL, -1, NULL, "username" },
{ "p", COMMAND_LINE_VALUE_REQUIRED, "<password>", NULL, NULL, -1, NULL, "password" },
{ "d", COMMAND_LINE_VALUE_REQUIRED, "<domain>", NULL, NULL, -1, NULL, "domain" },
{ "g", COMMAND_LINE_VALUE_REQUIRED, "<gateway>[:port]", NULL, NULL, -1, NULL, "gateway" },
{ "gu", COMMAND_LINE_VALUE_REQUIRED, "[<domain>\\|@]<user>", NULL, NULL, -1, NULL, "gateway username" },
{ "gu", COMMAND_LINE_VALUE_REQUIRED, "[<domain>\\]<user>", NULL, NULL, -1, NULL, "gateway username" },
{ "gp", COMMAND_LINE_VALUE_REQUIRED, "<password>", NULL, NULL, -1, NULL, "gateway password" },
{ "gd", COMMAND_LINE_VALUE_REQUIRED, "<domain>", NULL, NULL, -1, NULL, "gateway domain" },
{ "z", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "compression" },
@ -202,27 +204,6 @@ int freerdp_client_command_line_pre_filter(void* context, int index, LPCSTR arg)
return 1;
}
int freerdp_client_add_static_channel(rdpSettings* settings, int count, char** params)
{
RDP_PLUGIN_DATA* data;
data = (RDP_PLUGIN_DATA*) malloc(sizeof(RDP_PLUGIN_DATA));
ZeroMemory(data, sizeof(RDP_PLUGIN_DATA));
data->size = sizeof(RDP_PLUGIN_DATA);
if (count > 0)
data->data[0] = params[0];
if (count > 1)
data->data[1] = params[1];
if (count > 2)
data->data[2] = params[2];
if (count > 3)
data->data[3] = params[3];
return 1;
}
int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** params)
{
if (strcmp(params[0], "drive") == 0)
@ -321,6 +302,81 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p
return 0;
}
int freerdp_client_add_static_channel(rdpSettings* settings, int count, char** params)
{
int index;
RDP_STATIC_CHANNEL* channel;
channel = (RDP_STATIC_CHANNEL*) malloc(sizeof(RDP_STATIC_CHANNEL));
strncpy(channel->Name, params[0], 8);
channel->argc = count - 1;
channel->argv = (char**) malloc(sizeof(char*) * channel->argc);
for (index = 0; index < channel->argc; index++)
channel->argv[index] = _strdup(params[index + 1]);
freerdp_static_channel_collection_add(settings, channel);
return 0;
}
int freerdp_client_add_dynamic_channel(rdpSettings* settings, int count, char** params)
{
int index;
RDP_DYNAMIC_CHANNEL* channel;
channel = (RDP_DYNAMIC_CHANNEL*) malloc(sizeof(RDP_DYNAMIC_CHANNEL));
strncpy(channel->Name, params[0], 8);
channel->argc = count - 1;
channel->argv = (char**) malloc(sizeof(char*) * channel->argc);
for (index = 0; index < channel->argc; index++)
channel->argv[index] = _strdup(params[index + 1]);
freerdp_dynamic_channel_collection_add(settings, channel);
return 0;
}
char** freerdp_command_line_parse_comma_separated_values(char* list, int* count)
{
char** p;
char* str;
int nArgs;
int index;
int nCommas;
nArgs = nCommas = 0;
for (index = 0; list[index]; index++)
nCommas += (list[index] == ',') ? 1 : 0;
p = (char**) malloc(sizeof(char*) * (nCommas + 1));
ZeroMemory(p, sizeof(char*) * (nCommas + 1));
nArgs = nCommas + 1;
str = _strdup(list);
p[0] = str;
for (index = 1; index < nArgs; index++)
{
p[index] = strchr(p[index - 1], ',');
*p[index] = '\0';
p[index]++;
}
p[index] = str + strlen(str);
*count = nArgs;
return p;
}
int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT_A* arg)
{
rdpSettings* settings;
@ -329,64 +385,46 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT
CommandLineSwitchCase(arg, "a")
{
int nArgs;
char* str;
char* p[4];
int index;
int nCommas;
nCommas = 0;
char** p;
int count;
settings = (rdpSettings*) context;
for (index = 0; arg->Value[index]; index++)
nCommas += (arg->Value[index] == ',') ? 1 : 0;
p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count);
if (nCommas >= 1)
if (freerdp_client_add_device_channel(settings, count, p) > 0)
{
nArgs = nCommas + 1;
str = _strdup(arg->Value);
p[0] = str;
p[1] = p[2] = p[3] = NULL;
if (nCommas >= 1)
{
p[1] = strchr(p[0], ',');
*p[1] = '\0';
p[1]++;
}
if (nCommas >= 2)
{
p[2] = strchr(p[1], ',');
*p[2] = '\0';
p[2]++;
}
else
{
p[2] = str + strlen(str);
}
if (nCommas >= 3)
{
p[3] = strchr(p[2], ',');
*p[3] = '\0';
p[3]++;
}
else
{
p[3] = str + strlen(str);
}
printf("addin: %s %s %s\n", p[0], p[1], p[2]);
if (freerdp_client_add_device_channel(settings, nArgs, p) > 0)
{
settings->DeviceRedirection = TRUE;
}
free(str);
settings->DeviceRedirection = TRUE;
}
free(p);
}
CommandLineSwitchCase(arg, "vc")
{
char** p;
int count;
settings = (rdpSettings*) context;
p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count);
printf("addin: %s %s %s\n", p[0], p[1], p[2]);
freerdp_client_add_static_channel(settings, count, p);
free(p);
}
CommandLineSwitchCase(arg, "dvc")
{
char** p;
int count;
settings = (rdpSettings*) context;
p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count);
printf("addin: %s %s %s\n", p[0], p[1], p[2]);
freerdp_client_add_dynamic_channel(settings, count, p);
free(p);
}
CommandLineSwitchEnd(arg)

View File

@ -316,6 +316,22 @@ struct rdp_channel
};
typedef struct rdp_channel rdpChannel;
struct _RDP_STATIC_CHANNEL
{
char Name[8];
int argc;
char** argv;
};
typedef struct _RDP_STATIC_CHANNEL RDP_STATIC_CHANNEL;
struct _RDP_DYNAMIC_CHANNEL
{
char Name[8];
int argc;
char** argv;
};
typedef struct _RDP_DYNAMIC_CHANNEL RDP_DYNAMIC_CHANNEL;
/* Extensions */
struct rdp_ext_set
@ -922,6 +938,22 @@ struct rdp_settings
/* Parallel Port Redirection */
ALIGN64 BOOL RedirectParallelPorts; /* */
/**
* Static Virtual Channels
*/
ALIGN64 UINT32 StaticChannelCount;
ALIGN64 UINT32 StaticChannelArraySize;
ALIGN64 RDP_STATIC_CHANNEL** StaticChannelArray;
/**
* Dynamic Virtual Channels
*/
ALIGN64 UINT32 DynamicChannelCount;
ALIGN64 UINT32 DynamicChannelArraySize;
ALIGN64 RDP_DYNAMIC_CHANNEL** DynamicChannelArray;
/*
* Extensions
*/
@ -932,9 +964,11 @@ struct rdp_settings
};
typedef struct rdp_settings rdpSettings;
FREERDP_API void freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device);
FREERDP_API rdpSettings* freerdp_settings_new(void* instance);
FREERDP_API void freerdp_settings_free(rdpSettings* settings);
FREERDP_API void freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device);
FREERDP_API void freerdp_static_channel_collection_add(rdpSettings* settings, RDP_STATIC_CHANNEL* channel);
FREERDP_API void freerdp_dynamic_channel_collection_add(rdpSettings* settings, RDP_DYNAMIC_CHANNEL* channel);
#endif /* FREERDP_SETTINGS_H */

View File

@ -19,7 +19,8 @@ set(MODULE_NAME "freerdp-common")
set(MODULE_PREFIX "FREERDP_COMMON")
set(${MODULE_PREFIX}_SRCS
addin.c)
addin.c
settings.c)
add_complex_library(MODULE ${MODULE_NAME} TYPE "OBJECT"
MONOLITHIC ${MONOLITHIC_BUILD}
@ -39,3 +40,4 @@ else()
endif()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/libfreerdp")

View File

@ -140,6 +140,7 @@ void* freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, LPCSTR pszE
free(pszAddinInstallPath);
free(pszAddinFile);
free(pszFilePath);
return entry;
}

View File

@ -0,0 +1,63 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Settings Management
*
* Copyright 2012 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <freerdp/settings.h>
void freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device)
{
if (settings->DeviceArraySize < (settings->DeviceCount + 1))
{
settings->DeviceArraySize *= 2;
settings->DeviceArray = (RDPDR_DEVICE**) realloc(settings->DeviceArray, settings->DeviceArraySize);
}
settings->DeviceArray[settings->DeviceCount++] = device;
}
void freerdp_static_channel_collection_add(rdpSettings* settings, RDP_STATIC_CHANNEL* channel)
{
if (settings->StaticChannelArraySize < (settings->StaticChannelCount + 1))
{
settings->StaticChannelArraySize *= 2;
settings->StaticChannelArray = (RDP_STATIC_CHANNEL**)
realloc(settings->StaticChannelArray, settings->StaticChannelArraySize);
}
settings->StaticChannelArray[settings->StaticChannelCount++] = channel;
}
void freerdp_dynamic_channel_collection_add(rdpSettings* settings, RDP_DYNAMIC_CHANNEL* channel)
{
if (settings->DynamicChannelArraySize < (settings->DynamicChannelCount + 1))
{
settings->DynamicChannelArraySize *= 2;
settings->DynamicChannelArray = (RDP_DYNAMIC_CHANNEL**)
realloc(settings->DynamicChannelArray, settings->DynamicChannelArraySize);
}
settings->DynamicChannelArray[settings->DynamicChannelCount++] = channel;
}

View File

@ -400,6 +400,16 @@ rdpSettings* freerdp_settings_new(void* instance)
settings->DeviceArray = (RDPDR_DEVICE**) malloc(sizeof(RDPDR_DEVICE*) * settings->DeviceArraySize);
ZeroMemory(settings->DeviceArray, sizeof(RDPDR_DEVICE*) * settings->DeviceArraySize);
settings->StaticChannelArraySize = 16;
settings->StaticChannelArray = (RDP_STATIC_CHANNEL**)
malloc(sizeof(RDP_STATIC_CHANNEL*) * settings->StaticChannelArraySize);
ZeroMemory(settings->StaticChannelArray, sizeof(RDP_STATIC_CHANNEL*) * settings->StaticChannelArraySize);
settings->DynamicChannelArraySize = 16;
settings->DynamicChannelArray = (RDP_DYNAMIC_CHANNEL**)
malloc(sizeof(RDP_DYNAMIC_CHANNEL*) * settings->DynamicChannelArraySize);
ZeroMemory(settings->DynamicChannelArray, sizeof(RDP_DYNAMIC_CHANNEL*) * settings->DynamicChannelArraySize);
freerdp_detect_paths(settings);
settings_load_hkey_local_machine(settings);
@ -443,21 +453,12 @@ void freerdp_settings_free(rdpSettings* settings)
free(settings->ConfigPath);
free(settings->CurrentPath);
free(settings->DeviceArray);
free(settings->StaticChannelArray);
free(settings->DynamicChannelArray);
free(settings);
}
}
void freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device)
{
if (settings->DeviceArraySize < (settings->DeviceCount + 1))
{
settings->DeviceArraySize *= 2;
settings->DeviceArray = (RDPDR_DEVICE**) realloc(settings->DeviceArray, settings->DeviceArraySize);
}
settings->DeviceArray[settings->DeviceCount++] = device;
}
#ifdef _WIN32
#pragma warning(pop)
#endif

View File

@ -67,6 +67,11 @@ if(${CMAKE_SYSTEM_NAME} MATCHES SunOS)
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} rt)
endif()
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
MONOLITHIC ${MONOLITHIC_BUILD} INTERNAL
MODULE freerdp
MODULES freerdp-common)
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
MONOLITHIC ${MONOLITHIC_BUILD}
MODULE winpr

View File

@ -45,17 +45,6 @@
#include <freerdp/utils/args.h>
#include <freerdp/utils/passphrase.h>
void local_freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device)
{
if (settings->DeviceArraySize < (settings->DeviceCount + 1))
{
settings->DeviceArraySize *= 2;
settings->DeviceArray = (RDPDR_DEVICE**) realloc(settings->DeviceArray, settings->DeviceArraySize);
}
settings->DeviceArray[settings->DeviceCount++] = device;
}
void freerdp_parse_hostname(rdpSettings* settings, char* hostname)
{
char* p;
@ -790,7 +779,7 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
drive->Name = _strdup(data->data[1]);
drive->Path = _strdup(data->data[2]);
local_freerdp_device_collection_add(settings, (RDPDR_DEVICE*) drive);
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) drive);
}
else if (strcmp(data->data[0], "printer") == 0)
{
@ -805,7 +794,7 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
if (data->data[2])
printer->DriverName = _strdup(data->data[2]);
local_freerdp_device_collection_add(settings, (RDPDR_DEVICE*) printer);
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) printer);
}
else if (strcmp(data->data[0], "smartcard") == 0)
{
@ -818,7 +807,7 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
smartcard->Name = _strdup(data->data[1]);
smartcard->Path = _strdup(data->data[2]);
local_freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard);
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard);
}
else if (strcmp(data->data[0], "serial") == 0)
{
@ -831,7 +820,7 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
serial->Name = _strdup(data->data[1]);
serial->Path = _strdup(data->data[2]);
local_freerdp_device_collection_add(settings, (RDPDR_DEVICE*) serial);
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) serial);
}
else if (strcmp(data->data[0], "parallel") == 0)
{
@ -844,7 +833,7 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
parallel->Name = _strdup(data->data[1]);
parallel->Path = _strdup(data->data[2]);
local_freerdp_device_collection_add(settings, (RDPDR_DEVICE*) parallel);
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) parallel);
}
else
{

View File

@ -330,7 +330,7 @@ static void svc_plugin_process_terminated(rdpSvcPlugin* plugin)
freerdp_thread_free(plugin->priv->thread);
plugin->channel_entry_points.pVirtualChannelClose(plugin->priv->open_handle);
free(plugin->channel_entry_points.pExtendedData);
//free(plugin->channel_entry_points.pExtendedData);
svc_plugin_remove(plugin);