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 extension_pre_connect(rdp->extension);
40 IFCALLRET(instance->PreConnect, status, instance);
44 printf("freerdp_pre_connect failed\n");
48 status = rdp_client_connect(rdp);
52 if (instance->settings->dump_rfx)
54 instance->update->pcap_rfx = pcap_open(instance->settings->dump_rfx_file, true);
55 if (instance->update->pcap_rfx)
56 instance->update->dump_rfx = true;
59 extension_post_connect(rdp->extension);
61 IFCALLRET(instance->PostConnect, status, instance);
65 printf("freerdp_post_connect failed\n");
69 if (instance->settings->play_rfx)
76 instance->update->pcap_rfx = pcap_open(instance->settings->play_rfx_file, false);
77 if (instance->update->pcap_rfx)
78 instance->update->play_rfx = true;
79 update = instance->update;
81 while (instance->update->play_rfx && pcap_has_next_record(update->pcap_rfx))
83 pcap_get_next_record_header(update->pcap_rfx, &record);
85 s->data = xrealloc(s->data, record.length);
86 record.data = s->data;
87 s->size = record.length;
89 pcap_get_next_record_content(update->pcap_rfx, &record);
92 update->BeginPaint(update->context);
93 update_recv_surfcmds(update, s->size, s);
94 update->EndPaint(update->context);
105 boolean freerdp_get_fds(freerdp* instance, void** rfds, int* rcount, void** wfds, int* wcount)
109 rdp = instance->context->rdp;
110 transport_get_fds(rdp->transport, rfds, rcount);
115 boolean freerdp_check_fds(freerdp* instance)
120 rdp = instance->context->rdp;
122 status = rdp_check_fds(rdp);
130 void freerdp_send_keep_alive(freerdp* instance)
132 input_send_synchronize_event(instance->context->rdp->input, 0);
135 static int freerdp_send_channel_data(freerdp* instance, int channel_id, uint8* data, int size)
137 return rdp_send_channel_data(instance->context->rdp, channel_id, data, size);
140 boolean freerdp_disconnect(freerdp* instance)
144 rdp = instance->context->rdp;
145 transport_disconnect(rdp->transport);
150 boolean freerdp_shall_disconnect(freerdp* instance)
153 return instance->context->rdp->disconnect;
156 void freerdp_get_version(int* major, int* minor, int* revision)
159 *major = FREERDP_VERSION_MAJOR;
162 *minor = FREERDP_VERSION_MINOR;
164 if (revision != NULL)
165 *revision = FREERDP_VERSION_REVISION;
168 void freerdp_context_new(freerdp* instance)
172 rdp = rdp_new(instance);
173 instance->input = rdp->input;
174 instance->update = rdp->update;
175 instance->settings = rdp->settings;
177 instance->context = (rdpContext*) xzalloc(instance->context_size);
178 instance->context->graphics = graphics_new(instance->context);
179 instance->context->instance = instance;
180 instance->context->rdp = rdp;
182 instance->update->context = instance->context;
183 instance->update->pointer->context = instance->context;
184 instance->update->primary->context = instance->context;
185 instance->update->secondary->context = instance->context;
186 instance->update->altsec->context = instance->context;
188 instance->input->context = instance->context;
190 IFCALL(instance->ContextNew, instance, instance->context);
193 void freerdp_context_free(freerdp* instance)
195 IFCALL(instance->ContextFree, instance, instance->context);
197 rdp_free(instance->context->rdp);
198 graphics_free(instance->context->graphics);
199 xfree(instance->context);
202 uint32 freerdp_error_info(freerdp* instance)
204 return instance->context->rdp->errorInfo;
207 freerdp* freerdp_new()
211 instance = xzalloc(sizeof(freerdp));
213 if (instance != NULL)
215 instance->context_size = sizeof(rdpContext);
216 instance->SendChannelData = freerdp_send_channel_data;
222 void freerdp_free(freerdp* freerdp)
226 freerdp_context_free(freerdp);