2012-10-14 11:43:10 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* FreeRDP Client Common
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2013-06-14 01:52:24 +04:00
|
|
|
#include <freerdp/client.h>
|
2013-06-14 00:18:19 +04:00
|
|
|
|
2013-09-20 00:25:10 +04:00
|
|
|
#include <freerdp/addin.h>
|
2013-06-14 05:34:46 +04:00
|
|
|
#include <freerdp/client/file.h>
|
|
|
|
#include <freerdp/client/cmdline.h>
|
2013-09-20 00:25:10 +04:00
|
|
|
#include <freerdp/client/channels.h>
|
2013-06-14 05:34:46 +04:00
|
|
|
|
2013-06-16 01:01:10 +04:00
|
|
|
int freerdp_client_common_new(freerdp* instance, rdpContext* context)
|
|
|
|
{
|
2013-06-16 01:39:45 +04:00
|
|
|
RDP_CLIENT_ENTRY_POINTS* pEntryPoints = instance->pClientEntryPoints;
|
2013-06-16 01:01:10 +04:00
|
|
|
return pEntryPoints->ClientNew(instance, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_client_common_free(freerdp* instance, rdpContext* context)
|
|
|
|
{
|
2013-06-16 01:39:45 +04:00
|
|
|
RDP_CLIENT_ENTRY_POINTS* pEntryPoints = instance->pClientEntryPoints;
|
2013-06-16 01:01:10 +04:00
|
|
|
pEntryPoints->ClientFree(instance, context);
|
|
|
|
}
|
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
/* Common API */
|
|
|
|
|
2013-06-14 06:11:23 +04:00
|
|
|
rdpContext* freerdp_client_context_new(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
|
|
|
|
{
|
|
|
|
freerdp* instance;
|
|
|
|
rdpContext* context;
|
|
|
|
|
|
|
|
pEntryPoints->GlobalInit();
|
|
|
|
|
|
|
|
instance = freerdp_new();
|
2013-10-13 02:20:25 +04:00
|
|
|
instance->settings = pEntryPoints->settings;
|
2013-06-14 06:11:23 +04:00
|
|
|
instance->ContextSize = pEntryPoints->ContextSize;
|
2013-06-16 01:01:10 +04:00
|
|
|
instance->ContextNew = freerdp_client_common_new;
|
|
|
|
instance->ContextFree = freerdp_client_common_free;
|
|
|
|
instance->pClientEntryPoints = (RDP_CLIENT_ENTRY_POINTS*) malloc(pEntryPoints->Size);
|
|
|
|
CopyMemory(instance->pClientEntryPoints, pEntryPoints, pEntryPoints->Size);
|
2013-06-14 06:11:23 +04:00
|
|
|
freerdp_context_new(instance);
|
|
|
|
|
|
|
|
context = instance->context;
|
2013-07-11 19:53:15 +04:00
|
|
|
context->instance = instance;
|
|
|
|
context->settings = instance->settings;
|
2013-06-14 06:11:23 +04:00
|
|
|
|
2013-09-20 00:25:10 +04:00
|
|
|
freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0);
|
|
|
|
|
2013-06-14 06:11:23 +04:00
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_client_context_free(rdpContext* context)
|
|
|
|
{
|
|
|
|
freerdp* instance = context->instance;
|
2013-11-01 05:12:06 +04:00
|
|
|
|
2013-10-23 01:05:41 +04:00
|
|
|
if (instance)
|
|
|
|
{
|
|
|
|
freerdp_context_free(instance);
|
|
|
|
free(instance->pClientEntryPoints);
|
|
|
|
freerdp_free(instance);
|
|
|
|
}
|
2013-06-14 06:11:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int freerdp_client_start(rdpContext* context)
|
|
|
|
{
|
2013-06-16 01:39:45 +04:00
|
|
|
RDP_CLIENT_ENTRY_POINTS* pEntryPoints = context->instance->pClientEntryPoints;
|
|
|
|
return pEntryPoints->ClientStart(context);
|
2013-06-14 06:11:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int freerdp_client_stop(rdpContext* context)
|
|
|
|
{
|
2013-06-16 01:39:45 +04:00
|
|
|
RDP_CLIENT_ENTRY_POINTS* pEntryPoints = context->instance->pClientEntryPoints;
|
|
|
|
return pEntryPoints->ClientStop(context);
|
2013-06-14 06:11:23 +04:00
|
|
|
}
|
|
|
|
|
2013-06-14 23:07:17 +04:00
|
|
|
freerdp* freerdp_client_get_instance(rdpContext* context)
|
|
|
|
{
|
|
|
|
return context->instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE freerdp_client_get_thread(rdpContext* context)
|
|
|
|
{
|
|
|
|
return ((rdpClientContext*) context)->thread;
|
|
|
|
}
|
|
|
|
|
2013-10-13 05:07:12 +04:00
|
|
|
int freerdp_client_settings_parse_command_line(rdpSettings* settings, int argc, char** argv)
|
2013-06-14 05:34:46 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2013-10-13 05:07:12 +04:00
|
|
|
if (argc < 1)
|
2013-06-14 05:34:46 +04:00
|
|
|
return 0;
|
|
|
|
|
2013-10-13 05:07:12 +04:00
|
|
|
if (!argv)
|
2013-06-14 05:34:46 +04:00
|
|
|
return -1;
|
|
|
|
|
2013-10-13 05:07:12 +04:00
|
|
|
status = freerdp_client_settings_parse_command_line_arguments(settings, argc, argv);
|
2013-06-14 05:34:46 +04:00
|
|
|
|
|
|
|
if (settings->ConnectionFile)
|
|
|
|
{
|
2013-10-13 05:07:12 +04:00
|
|
|
status = freerdp_client_settings_parse_connection_file(settings, settings->ConnectionFile);
|
2013-06-14 05:34:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-10-13 05:07:12 +04:00
|
|
|
int freerdp_client_settings_parse_connection_file(rdpSettings* settings, const char* filename)
|
2013-06-14 05:34:46 +04:00
|
|
|
{
|
|
|
|
rdpFile* file;
|
|
|
|
|
|
|
|
file = freerdp_client_rdp_file_new();
|
|
|
|
freerdp_client_parse_rdp_file(file, filename);
|
2013-10-13 05:07:12 +04:00
|
|
|
freerdp_client_populate_settings_from_rdp_file(file, settings);
|
2013-06-14 05:34:46 +04:00
|
|
|
freerdp_client_rdp_file_free(file);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-13 05:07:12 +04:00
|
|
|
int freerdp_client_settings_parse_connection_file_buffer(rdpSettings* settings, BYTE* buffer, size_t size)
|
2013-06-14 05:34:46 +04:00
|
|
|
{
|
|
|
|
rdpFile* file;
|
2013-09-18 01:03:35 +04:00
|
|
|
int status = -1;
|
2013-06-14 00:18:19 +04:00
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
file = freerdp_client_rdp_file_new();
|
2013-09-18 01:03:35 +04:00
|
|
|
|
|
|
|
if (freerdp_client_parse_rdp_file_buffer(file, buffer, size)
|
2013-10-13 05:07:12 +04:00
|
|
|
&& freerdp_client_populate_settings_from_rdp_file(file, settings))
|
2013-09-18 01:03:35 +04:00
|
|
|
{
|
|
|
|
status = 0;
|
|
|
|
}
|
2013-07-06 07:20:56 +04:00
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
freerdp_client_rdp_file_free(file);
|
|
|
|
|
2013-09-18 01:03:35 +04:00
|
|
|
return status;
|
2013-07-06 07:20:56 +04:00
|
|
|
}
|
|
|
|
|
2013-10-13 05:07:12 +04:00
|
|
|
int freerdp_client_settings_write_connection_file(rdpSettings* settings, const char* filename, BOOL unicode)
|
2013-07-06 07:20:56 +04:00
|
|
|
{
|
2013-09-18 01:03:35 +04:00
|
|
|
rdpFile* file;
|
|
|
|
int status = -1;
|
2013-07-06 07:20:56 +04:00
|
|
|
|
2013-09-18 01:03:35 +04:00
|
|
|
file = freerdp_client_rdp_file_new();
|
2013-07-06 07:20:56 +04:00
|
|
|
|
2013-10-13 05:07:12 +04:00
|
|
|
if (freerdp_client_populate_rdp_file_from_settings(file, settings))
|
2013-09-18 01:03:35 +04:00
|
|
|
{
|
|
|
|
if (freerdp_client_write_rdp_file(file, filename, unicode))
|
|
|
|
{
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-07-06 07:20:56 +04:00
|
|
|
|
2013-09-18 01:03:35 +04:00
|
|
|
freerdp_client_rdp_file_free(file);
|
|
|
|
|
|
|
|
return status;
|
2013-06-14 05:34:46 +04:00
|
|
|
}
|