2
* FreeRDP: A Remote Desktop Protocol Client
5
* Copyright 2011 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 "transport.h"
25
#include "connection.h"
26
#include "extension.h"
28
#include <freerdp/freerdp.h>
29
#include <freerdp/utils/memory.h>
31
boolean freerdp_connect(freerdp* instance)
34
boolean status = false;
36
rdp = instance->context->rdp;
38
IFCALLRET(instance->PreConnect, status, instance);
42
printf("freerdp_pre_connect failed\n");
46
rdp->extension = extension_new(instance);
47
extension_pre_connect(rdp->extension);
49
status = rdp_client_connect(rdp);
53
if (instance->settings->dump_rfx)
55
instance->update->pcap_rfx = pcap_open(instance->settings->dump_rfx_file, true);
56
if (instance->update->pcap_rfx)
57
instance->update->dump_rfx = true;
60
extension_post_connect(rdp->extension);
62
IFCALLRET(instance->PostConnect, status, instance);
66
printf("freerdp_post_connect failed\n");
70
if (instance->settings->play_rfx)
77
instance->update->pcap_rfx = pcap_open(instance->settings->play_rfx_file, false);
78
if (instance->update->pcap_rfx)
79
instance->update->play_rfx = true;
80
update = instance->update;
82
while (instance->update->play_rfx && pcap_has_next_record(update->pcap_rfx))
84
pcap_get_next_record_header(update->pcap_rfx, &record);
86
s->data = xrealloc(s->data, record.length);
87
record.data = s->data;
88
s->size = record.length;
90
pcap_get_next_record_content(update->pcap_rfx, &record);
93
update->BeginPaint(update->context);
94
update_recv_surfcmds(update, s->size, s);
95
update->EndPaint(update->context);
106
boolean freerdp_get_fds(freerdp* instance, void** rfds, int* rcount, void** wfds, int* wcount)
110
rdp = instance->context->rdp;
111
transport_get_fds(rdp->transport, rfds, rcount);
116
boolean freerdp_check_fds(freerdp* instance)
121
rdp = instance->context->rdp;
123
status = rdp_check_fds(rdp);
131
void freerdp_send_keep_alive(freerdp* instance)
133
input_send_synchronize_event(instance->context->rdp->input, 0);
136
static int freerdp_send_channel_data(freerdp* instance, int channel_id, uint8* data, int size)
138
return rdp_send_channel_data(instance->context->rdp, channel_id, data, size);
141
boolean freerdp_disconnect(freerdp* instance)
145
rdp = instance->context->rdp;
146
transport_disconnect(rdp->transport);
151
boolean freerdp_shall_disconnect(freerdp* instance)
154
return instance->context->rdp->disconnect;
157
void freerdp_get_version(int* major, int* minor, int* revision)
160
*major = FREERDP_VERSION_MAJOR;
163
*minor = FREERDP_VERSION_MINOR;
165
if (revision != NULL)
166
*revision = FREERDP_VERSION_REVISION;
169
void freerdp_context_new(freerdp* instance)
173
rdp = rdp_new(instance);
174
instance->input = rdp->input;
175
instance->update = rdp->update;
176
instance->settings = rdp->settings;
178
instance->context = (rdpContext*) xzalloc(instance->context_size);
179
instance->context->graphics = graphics_new(instance->context);
180
instance->context->instance = instance;
181
instance->context->rdp = rdp;
183
instance->update->context = instance->context;
184
instance->update->pointer->context = instance->context;
185
instance->update->primary->context = instance->context;
186
instance->update->secondary->context = instance->context;
187
instance->update->altsec->context = instance->context;
189
instance->input->context = instance->context;
191
IFCALL(instance->ContextNew, instance, instance->context);
194
void freerdp_context_free(freerdp* instance)
196
if (instance->context == NULL)
199
IFCALL(instance->ContextFree, instance, instance->context);
201
rdp_free(instance->context->rdp);
202
graphics_free(instance->context->graphics);
204
xfree(instance->context);
205
instance->context = NULL;
208
uint32 freerdp_error_info(freerdp* instance)
210
return instance->context->rdp->errorInfo;
213
freerdp* freerdp_new()
217
instance = xzalloc(sizeof(freerdp));
219
if (instance != NULL)
221
instance->context_size = sizeof(rdpContext);
222
instance->SendChannelData = freerdp_send_channel_data;
228
void freerdp_free(freerdp* instance)