2 * FreeRDP: A Remote Desktop Protocol Implementation
3 * FreeRDP Client Common
5 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
24 #include <freerdp/client.h>
26 #include <freerdp/addin.h>
27 #include <freerdp/client/file.h>
28 #include <freerdp/client/cmdline.h>
29 #include <freerdp/client/channels.h>
30 #include <freerdp/client/assistance.h>
32 int freerdp_client_common_new(freerdp* instance, rdpContext* context)
34 RDP_CLIENT_ENTRY_POINTS* pEntryPoints = instance->pClientEntryPoints;
35 return pEntryPoints->ClientNew(instance, context);
38 void freerdp_client_common_free(freerdp* instance, rdpContext* context)
40 RDP_CLIENT_ENTRY_POINTS* pEntryPoints = instance->pClientEntryPoints;
41 pEntryPoints->ClientFree(instance, context);
46 rdpContext* freerdp_client_context_new(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
51 pEntryPoints->GlobalInit();
53 instance = freerdp_new();
54 instance->settings = pEntryPoints->settings;
55 instance->ContextSize = pEntryPoints->ContextSize;
56 instance->ContextNew = freerdp_client_common_new;
57 instance->ContextFree = freerdp_client_common_free;
58 instance->pClientEntryPoints = (RDP_CLIENT_ENTRY_POINTS*) malloc(pEntryPoints->Size);
59 CopyMemory(instance->pClientEntryPoints, pEntryPoints, pEntryPoints->Size);
60 freerdp_context_new(instance);
62 context = instance->context;
63 context->instance = instance;
64 context->settings = instance->settings;
66 freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0);
71 void freerdp_client_context_free(rdpContext* context)
73 freerdp* instance = context->instance;
77 freerdp_context_free(instance);
78 free(instance->pClientEntryPoints);
79 freerdp_free(instance);
83 int freerdp_client_start(rdpContext* context)
85 RDP_CLIENT_ENTRY_POINTS* pEntryPoints = context->instance->pClientEntryPoints;
86 return pEntryPoints->ClientStart(context);
89 int freerdp_client_stop(rdpContext* context)
91 RDP_CLIENT_ENTRY_POINTS* pEntryPoints = context->instance->pClientEntryPoints;
92 return pEntryPoints->ClientStop(context);
95 freerdp* freerdp_client_get_instance(rdpContext* context)
97 return context->instance;
100 HANDLE freerdp_client_get_thread(rdpContext* context)
102 return ((rdpClientContext*) context)->thread;
105 int freerdp_client_settings_parse_command_line(rdpSettings* settings, int argc, char** argv)
115 status = freerdp_client_settings_parse_command_line_arguments(settings, argc, argv);
117 if (settings->ConnectionFile)
119 status = freerdp_client_settings_parse_connection_file(settings, settings->ConnectionFile);
122 if (settings->AssistanceFile)
124 status = freerdp_client_settings_parse_assistance_file(settings, settings->AssistanceFile);
130 int freerdp_client_settings_parse_connection_file(rdpSettings* settings, const char* filename)
134 file = freerdp_client_rdp_file_new();
135 freerdp_client_parse_rdp_file(file, filename);
136 freerdp_client_populate_settings_from_rdp_file(file, settings);
137 freerdp_client_rdp_file_free(file);
142 int freerdp_client_settings_parse_connection_file_buffer(rdpSettings* settings, const BYTE* buffer, size_t size)
147 file = freerdp_client_rdp_file_new();
149 if (freerdp_client_parse_rdp_file_buffer(file, buffer, size)
150 && freerdp_client_populate_settings_from_rdp_file(file, settings))
155 freerdp_client_rdp_file_free(file);
160 int freerdp_client_settings_write_connection_file(const rdpSettings* settings, const char* filename, BOOL unicode)
164 file = freerdp_client_rdp_file_new();
166 if (!freerdp_client_populate_rdp_file_from_settings(file, settings))
169 if (!freerdp_client_write_rdp_file(file, filename, unicode))
172 freerdp_client_rdp_file_free(file);
177 int freerdp_client_settings_parse_assistance_file(rdpSettings* settings, const char* filename)
180 rdpAssistanceFile* file;
182 file = freerdp_client_assistance_file_new();
187 status = freerdp_client_assistance_parse_file(file, filename);
192 status = freerdp_client_populate_settings_from_assistance_file(file, settings);
197 freerdp_client_assistance_file_free(file);