Welcome to mirror list, hosted at ThFree Co, Russian Federation.

freerdp.c « libfreerdp-core - github.com/FreeRDP/FreeRDP-old.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8f4ef3dd34de38e5b935859c7592a5857d05e2ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
/*
   FreeRDP: A Remote Desktop Protocol client.

   Copyright (C) Jay Sorg 2009-2011

   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.
*/

#include <stdarg.h>
#include "frdp.h"
#include "rdp.h"
#include "secure.h"
#include "mcs.h"
#include "iso.h"
#include "tcp.h"
#include "chan.h"
#include "ext.h"
#include <freerdp/freerdp.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/hexdump.h>

#define RDP_FROM_INST(_inst) ((rdpRdp *) (_inst->rdp))

void
ui_error(rdpInst * inst, char * format, ...)
{
	char * text1;
	char * text2;
	va_list ap;

	text1 = (char *) xmalloc(1024);
	text2 = (char *) xmalloc(1024);
	va_start(ap, format);
	vsnprintf(text1, 1023, format, ap);
	va_end(ap);
	text1[1023] = 0;
	snprintf(text2, 1023, "ERROR: %s", text1);
	text2[1023] = 0;
	inst->ui_error(inst, text2);
	xfree(text1);
	xfree(text2);
}

void
ui_warning(rdpInst * inst, char * format, ...)
{
	char * text1;
	char * text2;
	va_list ap;

	text1 = (char *) xmalloc(1024);
	text2 = (char *) xmalloc(1024);
	va_start(ap, format);
	vsnprintf(text1, 1023, format, ap);
	va_end(ap);
	text1[1023] = 0;
	snprintf(text2, 1023, "WARNING: %s", text1);
	text2[1023] = 0;
	inst->ui_warning(inst, text2);
	xfree(text1);
	xfree(text2);
}

void
ui_unimpl(rdpInst * inst, char * format, ...)
{
	char * text1;
	char * text2;
	va_list ap;

	text1 = (char *) xmalloc(1024);
	text2 = (char *) xmalloc(1024);
	va_start(ap, format);
	vsnprintf(text1, 1023, format, ap);
	va_end(ap);
	text1[1023] = 0;
	snprintf(text2, 1023, "NOT IMPLEMENTED: %s", text1);
	text2[1023] = 0;
	inst->ui_unimpl(inst, text2);
	xfree(text1);
	xfree(text2);
}

int
load_license(unsigned char ** data)
{
	return 0;
}

RD_BOOL
rd_lock_file(int fd, int start, int len)
{
	return 0;
}

int
rd_lseek_file(int fd, int offset)
{
	return 0;
}

int
rd_write_file(int fd, void * ptr, int len)
{
	return 0;
}

RD_BOOL
rd_pstcache_mkdir(void)
{
	return 0;
}

void
rd_close_file(int fd)
{
}

int
rd_read_file(int fd, void * ptr, int len)
{
	return 0;
}

int
rd_open_file(char * filename)
{
	return 0;
}

void
generate_random(uint8 * random)
{
	time_t index;

	index = time(NULL);
	srand((unsigned int)index);
	for (index = 0; index < 32; index++)
	{
		random[index] = rand();
	}
}

void
save_license(unsigned char * data, int length)
{
}

void
ui_begin_update(rdpInst * inst)
{
	inst->ui_begin_update(inst);
}

void
ui_end_update(rdpInst * inst)
{
	inst->ui_end_update(inst);
}

void
ui_line(rdpInst * inst, uint8 opcode, int startx, int starty, int endx, int endy, RD_PEN * pen)
{
	inst->ui_line(inst, opcode, startx, starty, endx, endy, pen);
}

void
ui_rect(rdpInst * inst, int x, int y, int cx, int cy, uint32 color)
{
	inst->ui_rect(inst, x, y, cx, cy, color);
}

void
ui_polygon(rdpInst * inst, uint8 opcode, uint8 fillmode, RD_POINT * point, int npoints, RD_BRUSH * brush, uint32 bgcolor, uint32 fgcolor)
{
	inst->ui_polygon(inst, opcode, fillmode, point, npoints, brush, bgcolor, fgcolor);
}

void
ui_polyline(rdpInst * inst, uint8 opcode, RD_POINT * points, int npoints, RD_PEN * pen)
{
	inst->ui_polyline(inst, opcode, points, npoints, pen);
}

void
ui_ellipse(rdpInst * inst, uint8 opcode, uint8 fillmode, int x, int y, int cx, int cy,
	   RD_BRUSH * brush, uint32 bgcolor, uint32 fgcolor)
{
	inst->ui_ellipse(inst, opcode, fillmode, x, y, cx, cy, brush, bgcolor, fgcolor);
}

void
ui_start_draw_glyphs(rdpInst * inst, uint32 bgcolor, uint32 fgcolor)
{
	inst->ui_start_draw_glyphs(inst, bgcolor, fgcolor);
}

void
ui_draw_glyph(rdpInst * inst, int x, int y, int cx, int cy, RD_HGLYPH glyph)
{
	inst->ui_draw_glyph(inst, x, y, cx, cy, glyph);
}

void
ui_end_draw_glyphs(rdpInst * inst, int x, int y, int cx, int cy)
{
	inst->ui_end_draw_glyphs(inst, x, y, cx, cy);
}

void
ui_desktop_save(rdpInst * inst, uint32 offset, int x, int y, int cx, int cy)
{
	inst->ui_desktop_save(inst, offset, x, y, cx, cy);
}

void
ui_desktop_restore(rdpInst * inst, uint32 offset, int x, int y, int cx, int cy)
{
	inst->ui_desktop_save(inst, offset, x, y, cx, cy);
}

uint32
ui_get_toggle_keys_state(rdpInst * inst)
{
	return inst->ui_get_toggle_keys_state(inst);
}

void
ui_bell(rdpInst * inst)
{
	inst->ui_bell(inst);
}

void
ui_destblt(rdpInst * inst, uint8 opcode, int x, int y, int cx, int cy)
{
	inst->ui_destblt(inst, opcode, x, y, cx, cy);
}

void
ui_patblt(rdpInst * inst, uint8 opcode, int x, int y, int cx, int cy, RD_BRUSH * brush,
	  uint32 bgcolor, uint32 fgcolor)
{
	inst->ui_patblt(inst, opcode, x, y, cx, cy, brush, bgcolor, fgcolor);
}

void
ui_screenblt(rdpInst * inst, uint8 opcode, int x, int y, int cx, int cy, int srcx, int srcy)
{
	inst->ui_screenblt(inst, opcode, x, y, cx, cy, srcx, srcy);
}

void
ui_memblt(rdpInst * inst, uint8 opcode, int x, int y, int cx, int cy, RD_HBITMAP src,
	  int srcx, int srcy)
{
	inst->ui_memblt(inst, opcode, x, y, cx, cy, src, srcx, srcy);
}

void
ui_triblt(rdpInst * inst, uint8 opcode, int x, int y, int cx, int cy, RD_HBITMAP src,
	  int srcx, int srcy, RD_BRUSH * brush, uint32 bgcolor, uint32 fgcolor)
{
	inst->ui_triblt(inst, opcode, x, y, cx, cy, src, srcx, srcy, brush, bgcolor, fgcolor);
}

RD_HGLYPH
ui_create_glyph(rdpInst * inst, int width, int height, uint8 * data)
{
	return inst->ui_create_glyph(inst, width, height, data);
}

void
ui_destroy_glyph(rdpInst * inst, RD_HGLYPH glyph)
{
	inst->ui_destroy_glyph(inst, glyph);
}

int
ui_select(rdpInst * inst, int rdp_socket)
{
	return inst->ui_select(inst, rdp_socket);
}

void
ui_set_clip(rdpInst * inst, int x, int y, int cx, int cy)
{
	inst->ui_set_clip(inst, x, y, cx, cy);
}

void
ui_reset_clip(rdpInst * inst)
{
	inst->ui_reset_clip(inst);
}

void
ui_resize_window(rdpInst * inst)
{
	inst->ui_resize_window(inst);
}

RD_HCURSOR
ui_create_cursor(rdpInst * inst, unsigned int x, unsigned int y, int width, int height,
		 uint8 * andmask, uint8 * xormask, int bpp)
{
	return inst->ui_create_cursor(inst, x, y, width, height, andmask, xormask, bpp);
}

void
ui_set_cursor(rdpInst * inst, RD_HCURSOR cursor)
{
	inst->ui_set_cursor(inst, cursor);
}

void
ui_set_null_cursor(rdpInst * inst)
{
	inst->ui_set_null_cursor(inst);
}

void
ui_set_default_cursor(rdpInst * inst)
{
	inst->ui_set_default_cursor(inst);
}

void
ui_destroy_cursor(rdpInst * inst, RD_HCURSOR cursor)
{
	inst->ui_destroy_cursor(inst, cursor);
}

RD_HBITMAP
ui_create_bitmap(rdpInst * inst, int width, int height, uint8 * data)
{
	return inst->ui_create_bitmap(inst, width, height, data);
}

void
ui_paint_bitmap(rdpInst * inst, int x, int y, int cx, int cy, int width, int height, uint8 * data)
{
	inst->ui_paint_bitmap(inst, x, y, cx, cy, width,  height, data);
}

void
ui_destroy_bitmap(rdpInst * inst, RD_HBITMAP bmp)
{
	inst->ui_destroy_bitmap(inst, bmp);
}

RD_HPALETTE
ui_create_palette(rdpInst * inst, RD_PALETTE * palette)
{
	return inst->ui_create_palette(inst, palette);
}

void
ui_set_palette(rdpInst * inst, RD_HPALETTE palette)
{
	inst->ui_set_palette(inst, palette);
}

void
ui_move_pointer(rdpInst * inst, int x, int y)
{
	inst->ui_move_pointer(inst, x, y);
}

RD_HBITMAP
ui_create_surface(rdpInst * inst, int width, int height, RD_HBITMAP old)
{
	return inst->ui_create_surface(inst, width, height, old);
}

void
ui_set_surface(rdpInst * inst, RD_HBITMAP surface)
{
	inst->ui_set_surface(inst, surface);
}

void
ui_destroy_surface(rdpInst * inst, RD_HBITMAP surface)
{
	inst->ui_destroy_surface(inst, surface);
}

void
ui_channel_data(rdpInst * inst, int chan_id, char * data, int data_size,
		int flags, int total_size)
{
	inst->ui_channel_data(inst, chan_id, data, data_size, flags, total_size);
}

RD_BOOL
ui_authenticate(rdpInst * inst)
{
	return inst->ui_authenticate(inst);
}

int
ui_decode(rdpInst * inst, uint8 * data, int data_size)
{
	return inst->ui_decode(inst, data, data_size);
}

RD_BOOL
ui_check_certificate(rdpInst * inst, const char * fingerprint,
		const char * subject, const char * issuer, RD_BOOL verified)
{
	return inst->ui_check_certificate(inst, fingerprint, subject, issuer, verified);
}

/* returns error */
static int
l_rdp_connect(rdpInst * inst)
{
	rdpRdp * rdp;
	int index;

	rdp = RDP_FROM_INST(inst);
	for (index = 0; index < rdp->settings->num_channels; index++)
	{
		rdp->settings->channels[index].chan_id = MCS_GLOBAL_CHANNEL + 1 + index;
	}
	ext_pre_connect(rdp->ext);
	if (rdp_connect(rdp))
	{
		ext_post_connect(rdp->ext);
		return 0;
	}
	return 1;
}

static int
l_rdp_get_fds(rdpInst * inst, void ** read_fds, int * read_count,
	void ** write_fds, int * write_count)
{
	rdpRdp * rdp;

	rdp = RDP_FROM_INST(inst);
#ifdef _WIN32
	read_fds[*read_count] = (void *) (rdp->sec->mcs->iso->tcp->wsa_event);
#else
	read_fds[*read_count] = (void *)(long) (rdp->sec->mcs->iso->tcp->sock);
#endif
	(*read_count)++;
	return 0;
}

/* Process receivable fds, return true if connection should live on */
static int
l_rdp_check_fds(rdpInst * inst)
{
	rdpRdp * rdp;
	RD_BOOL deactivated;
	int rv;

	rdp = RDP_FROM_INST(inst);
#ifdef _WIN32
	WSAResetEvent(rdp->sec->mcs->iso->tcp->wsa_event);
#endif
	rv = 0;
	if (tcp_can_recv(rdp->sec->mcs->iso->tcp->sock, 0))
	{
		if (!rdp_loop(rdp, &deactivated))
		{
			rv = 1;
		}
	}
	if ((rv != 0) && rdp->redirect)
	{
		rdp->redirect = False;
		if (rdp_reconnect(rdp))
		{
			rv = 0;
		}
	}
	return rv;
}

static int
l_rdp_send_input_scancode(rdpInst * inst, RD_BOOL up, RD_BOOL extended, uint8 keyCode)
{
	rdpRdp * rdp;
	rdp = RDP_FROM_INST(inst);
	rdp_send_input_scancode(rdp, time(NULL), up, extended, keyCode);
	return 0;
}

static int
l_rdp_send_input_unicode(rdpInst * inst, uint16 character)
{
	rdpRdp * rdp;
	rdp = RDP_FROM_INST(inst);
	rdp_send_input_unicode(rdp, time(NULL), character);
	return 0;
}

static int
l_rdp_send_input_mouse(rdpInst * inst, uint16 pointerFlags, uint16 xPos, uint16 yPos)
{
	rdpRdp * rdp;
	rdp = RDP_FROM_INST(inst);
	rdp_send_input_mouse(rdp, time(NULL), pointerFlags, xPos, yPos);
	return 0;
}

static int
l_rdp_sync_input(rdpInst * inst, int toggle_flags)
{
	rdpRdp * rdp;
	rdp = (rdpRdp *) (inst->rdp);
	rdp_sync_input(rdp, time(NULL), toggle_flags);
	return 0;
}

static int
l_rdp_channel_data(rdpInst * inst, int chan_id, char * data, int data_size)
{
	rdpRdp * rdp;
	rdpChannels * chan;

	rdp = RDP_FROM_INST(inst);
	chan = rdp->sec->mcs->chan;
	return vchan_send(chan, chan_id, data, data_size);
}

static void
l_rdp_suppress_output(rdpInst * inst, int allow_display_updates)
{
	rdpRdp * rdp;

	rdp = RDP_FROM_INST(inst);
	rdp_send_client_window_status(rdp, allow_display_updates);
}

static void
l_rdp_disconnect(rdpInst * inst)
{
	rdpRdp * rdp;

	rdp = RDP_FROM_INST(inst);
	rdp_disconnect(rdp);
}

static int
l_rdp_send_frame_ack(rdpInst * inst, int frame_id)
{
	rdpRdp * rdp;
	rdp = RDP_FROM_INST(inst);
	rdp_send_frame_ack(rdp, frame_id);
	return 0;
}

FREERDP_API RD_BOOL
freerdp_global_init(void)
{
	return rdp_global_init();
}

FREERDP_API void
freerdp_global_finish(void)
{
	rdp_global_finish();
}

rdpInst *
freerdp_new(rdpSet * settings)
{
	rdpInst * inst;

	inst = (rdpInst *) xmalloc(sizeof(rdpInst));
	inst->version = FREERDP_INTERFACE_VERSION;
	inst->size = sizeof(rdpInst);
	inst->settings = settings;
	inst->rdp_connect = l_rdp_connect;
	inst->rdp_get_fds = l_rdp_get_fds;
	inst->rdp_check_fds = l_rdp_check_fds;
	inst->rdp_send_input_scancode = l_rdp_send_input_scancode;
	inst->rdp_send_input_unicode = l_rdp_send_input_unicode;
	inst->rdp_send_input_mouse = l_rdp_send_input_mouse;
	inst->rdp_sync_input = l_rdp_sync_input;
	inst->rdp_channel_data = l_rdp_channel_data;
	inst->rdp_suppress_output = l_rdp_suppress_output;
	inst->rdp_disconnect = l_rdp_disconnect;
	inst->rdp_send_frame_ack = l_rdp_send_frame_ack;
	inst->rdp = (void *) rdp_new(settings, inst);
	inst->disc_reason = 0;
	return inst;
}

void
freerdp_free(rdpInst * inst)
{
	rdpRdp * rdp;

	if (inst != NULL)
	{
		rdp = RDP_FROM_INST(inst);
		rdp_free(rdp);
		xfree(inst);
	}
}