Skip to content

Commit

Permalink
libfreerdp-common: added parsing of /vc and /dvc
Browse files Browse the repository at this point in the history
  • Loading branch information
awakecoding committed Nov 18, 2012
1 parent 925eb59 commit 4a472d5
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 127 deletions.
18 changes: 3 additions & 15 deletions channels/audin/client/audin_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions channels/drdynvc/client/dvcman.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions channels/drive/client/drive_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ static void drive_free(DEVICE* device)
drive_file_free(file);

list_free(disk->files);

free(disk);
}

Expand Down
12 changes: 1 addition & 11 deletions channels/rdpdr/client/devman.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
178 changes: 108 additions & 70 deletions client/common/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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);
settings->DeviceRedirection = TRUE;
}

p[0] = str;
p[1] = p[2] = p[3] = NULL;
free(p);
}
CommandLineSwitchCase(arg, "vc")
{
char** p;
int count;
settings = (rdpSettings*) context;

if (nCommas >= 1)
{
p[1] = strchr(p[0], ',');
*p[1] = '\0';
p[1]++;
}
p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count);

if (nCommas >= 2)
{
p[2] = strchr(p[1], ',');
*p[2] = '\0';
p[2]++;
}
else
{
p[2] = str + strlen(str);
}
printf("addin: %s %s %s\n", p[0], p[1], p[2]);

if (nCommas >= 3)
{
p[3] = strchr(p[2], ',');
*p[3] = '\0';
p[3]++;
}
else
{
p[3] = str + strlen(str);
}
freerdp_client_add_static_channel(settings, count, p);

printf("addin: %s %s %s\n", p[0], p[1], p[2]);
free(p);
}
CommandLineSwitchCase(arg, "dvc")
{
char** p;
int count;
settings = (rdpSettings*) context;

if (freerdp_client_add_device_channel(settings, nArgs, p) > 0)
{
settings->DeviceRedirection = TRUE;
}
p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count);

free(str);
}
printf("addin: %s %s %s\n", p[0], p[1], p[2]);

freerdp_client_add_dynamic_channel(settings, count, p);

free(p);
}

CommandLineSwitchEnd(arg)
Expand Down
38 changes: 36 additions & 2 deletions include/freerdp/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand All @@ -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 */
4 changes: 3 additions & 1 deletion libfreerdp/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -39,3 +40,4 @@ else()
endif()

set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/libfreerdp")

1 change: 1 addition & 0 deletions libfreerdp/common/addin.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void* freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, LPCSTR pszE

free(pszAddinInstallPath);
free(pszAddinFile);
free(pszFilePath);

return entry;
}
Expand Down
Loading

0 comments on commit 4a472d5

Please sign in to comment.