~ubuntu-branches/ubuntu/vivid/freerdp/vivid

« back to all changes in this revision

Viewing changes to libfreerdp-core/freerdp.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-11-11 12:20:50 UTC
  • mfrom: (1.1.9) (9.1.17 sid)
  • Revision ID: package-import@ubuntu.com-20141111122050-wyr8hrnwco9fcmum
Tags: 1.1.0~git20140921.1.440916e+dfsg1-2ubuntu1
* Merge with Debian unstable, remaining changes
  - Disable ffmpeg support
* Disable gstreamer support, this relies on gstreamer 0.10 and we don't want
  to add any more deps on that.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * FreeRDP: A Remote Desktop Protocol Client
3
 
 * FreeRDP Core
4
 
 *
5
 
 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6
 
 *
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
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
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.
18
 
 */
19
 
 
20
 
#include "rdp.h"
21
 
#include "input.h"
22
 
#include "update.h"
23
 
#include "surface.h"
24
 
#include "transport.h"
25
 
#include "connection.h"
26
 
#include "extension.h"
27
 
 
28
 
#include <freerdp/freerdp.h>
29
 
#include <freerdp/utils/memory.h>
30
 
 
31
 
boolean freerdp_connect(freerdp* instance)
32
 
{
33
 
        rdpRdp* rdp;
34
 
        boolean status = false;
35
 
 
36
 
        rdp = instance->context->rdp;
37
 
 
38
 
        IFCALLRET(instance->PreConnect, status, instance);
39
 
 
40
 
        if (status != true)
41
 
        {
42
 
                printf("freerdp_pre_connect failed\n");
43
 
                return false;
44
 
        }
45
 
 
46
 
        rdp->extension = extension_new(instance);
47
 
        extension_pre_connect(rdp->extension);
48
 
 
49
 
        status = rdp_client_connect(rdp);
50
 
 
51
 
        if (status)
52
 
        {
53
 
                if (instance->settings->dump_rfx)
54
 
                {
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;
58
 
                }
59
 
 
60
 
                extension_post_connect(rdp->extension);
61
 
 
62
 
                IFCALLRET(instance->PostConnect, status, instance);
63
 
 
64
 
                if (status != true)
65
 
                {
66
 
                        printf("freerdp_post_connect failed\n");
67
 
                        return false;
68
 
                }
69
 
 
70
 
                if (instance->settings->play_rfx)
71
 
                {
72
 
                        STREAM* s;
73
 
                        rdpUpdate* update;
74
 
                        pcap_record record;
75
 
 
76
 
                        s = stream_new(1024);
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;
81
 
 
82
 
                        while (instance->update->play_rfx && pcap_has_next_record(update->pcap_rfx))
83
 
                        {
84
 
                                pcap_get_next_record_header(update->pcap_rfx, &record);
85
 
 
86
 
                                s->data = xrealloc(s->data, record.length);
87
 
                                record.data = s->data;
88
 
                                s->size = record.length;
89
 
 
90
 
                                pcap_get_next_record_content(update->pcap_rfx, &record);
91
 
                                stream_set_pos(s, 0);
92
 
 
93
 
                                update->BeginPaint(update->context);
94
 
                                update_recv_surfcmds(update, s->size, s);
95
 
                                update->EndPaint(update->context);
96
 
                        }
97
 
 
98
 
                        xfree(s->data);
99
 
                        return true;
100
 
                }
101
 
        }
102
 
 
103
 
        return status;
104
 
}
105
 
 
106
 
boolean freerdp_get_fds(freerdp* instance, void** rfds, int* rcount, void** wfds, int* wcount)
107
 
{
108
 
        rdpRdp* rdp;
109
 
 
110
 
        rdp = instance->context->rdp;
111
 
        transport_get_fds(rdp->transport, rfds, rcount);
112
 
 
113
 
        return true;
114
 
}
115
 
 
116
 
boolean freerdp_check_fds(freerdp* instance)
117
 
{
118
 
        int status;
119
 
        rdpRdp* rdp;
120
 
 
121
 
        rdp = instance->context->rdp;
122
 
 
123
 
        status = rdp_check_fds(rdp);
124
 
 
125
 
        if (status < 0)
126
 
                return false;
127
 
 
128
 
        return true;
129
 
}
130
 
 
131
 
void freerdp_send_keep_alive(freerdp* instance)
132
 
{
133
 
        input_send_synchronize_event(instance->context->rdp->input, 0);
134
 
}
135
 
 
136
 
static int freerdp_send_channel_data(freerdp* instance, int channel_id, uint8* data, int size)
137
 
{
138
 
        return rdp_send_channel_data(instance->context->rdp, channel_id, data, size);
139
 
}
140
 
 
141
 
boolean freerdp_disconnect(freerdp* instance)
142
 
{
143
 
        rdpRdp* rdp;
144
 
 
145
 
        rdp = instance->context->rdp;
146
 
        transport_disconnect(rdp->transport);
147
 
 
148
 
        return true;
149
 
}
150
 
 
151
 
boolean freerdp_shall_disconnect(freerdp* instance)
152
 
{
153
 
 
154
 
        return instance->context->rdp->disconnect;
155
 
}
156
 
 
157
 
void freerdp_get_version(int* major, int* minor, int* revision)
158
 
{
159
 
        if (major != NULL)
160
 
                *major = FREERDP_VERSION_MAJOR;
161
 
 
162
 
        if (minor != NULL)
163
 
                *minor = FREERDP_VERSION_MINOR;
164
 
 
165
 
        if (revision != NULL)
166
 
                *revision = FREERDP_VERSION_REVISION;
167
 
}
168
 
 
169
 
void freerdp_context_new(freerdp* instance)
170
 
{
171
 
        rdpRdp* rdp;
172
 
 
173
 
        rdp = rdp_new(instance);
174
 
        instance->input = rdp->input;
175
 
        instance->update = rdp->update;
176
 
        instance->settings = rdp->settings;
177
 
 
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;
182
 
 
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;
188
 
 
189
 
        instance->input->context = instance->context;
190
 
 
191
 
        IFCALL(instance->ContextNew, instance, instance->context);
192
 
}
193
 
 
194
 
void freerdp_context_free(freerdp* instance)
195
 
{
196
 
        if (instance->context == NULL)
197
 
                return;
198
 
 
199
 
        IFCALL(instance->ContextFree, instance, instance->context);
200
 
 
201
 
        rdp_free(instance->context->rdp);
202
 
        graphics_free(instance->context->graphics);
203
 
 
204
 
        xfree(instance->context);
205
 
        instance->context = NULL;
206
 
}
207
 
 
208
 
uint32 freerdp_error_info(freerdp* instance)
209
 
{
210
 
        return instance->context->rdp->errorInfo;
211
 
}
212
 
 
213
 
freerdp* freerdp_new()
214
 
{
215
 
        freerdp* instance;
216
 
 
217
 
        instance = xzalloc(sizeof(freerdp));
218
 
 
219
 
        if (instance != NULL)
220
 
        {
221
 
                instance->context_size = sizeof(rdpContext);
222
 
                instance->SendChannelData = freerdp_send_channel_data;
223
 
        }
224
 
 
225
 
        return instance;
226
 
}
227
 
 
228
 
void freerdp_free(freerdp* instance)
229
 
{
230
 
        if (instance)
231
 
        {
232
 
                xfree(instance);
233
 
        }
234
 
}