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
|
/*
Copyright 2005-2013 Jay Sorg
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
the rest
*/
#include "rdp.h"
#include <sys/un.h>
Bool noFontCacheExtension = 1;
/******************************************************************************/
/* print a time-stamped message to the log file (stderr). */
void
rdpLog(char *format, ...)
{
va_list args;
char buf[256];
time_t clock;
va_start(args, format);
time(&clock);
strftime(buf, 255, "%d/%m/%y %T ", localtime(&clock));
fprintf(stderr, "%s", buf);
vfprintf(stderr, format, args);
fflush(stderr);
va_end(args);
}
/******************************************************************************/
int
rdpBitsPerPixel(int depth)
{
if (depth == 1)
{
return 1;
}
else if (depth <= 8)
{
return 8;
}
else if (depth <= 16)
{
return 16;
}
else
{
return 32;
}
}
/******************************************************************************/
void
rdpClientStateChange(CallbackListPtr *cbl, pointer myData, pointer clt)
{
dispatchException &= ~DE_RESET; /* hack - force server not to reset */
}
/******************************************************************************/
int
DPMSSupported(void)
{
return 0;
}
/******************************************************************************/
int
DPSMGet(int *level)
{
return -1;
}
/******************************************************************************/
void
DPMSSet(int level)
{
}
/******************************************************************************/
void
AddOtherInputDevices(void)
{
}
/******************************************************************************/
void
OpenInputDevice(DeviceIntPtr dev, ClientPtr client, int *status)
{
}
/******************************************************************************/
int
SetDeviceValuators(register ClientPtr client, DeviceIntPtr dev,
int *valuators, int first_valuator, int num_valuators)
{
return BadMatch;
}
/******************************************************************************/
int
SetDeviceMode(register ClientPtr client, DeviceIntPtr dev, int mode)
{
return BadMatch;
}
/******************************************************************************/
int
ChangeKeyboardDevice(DeviceIntPtr old_dev, DeviceIntPtr new_dev)
{
return BadMatch;
}
/******************************************************************************/
int
ChangeDeviceControl(register ClientPtr client, DeviceIntPtr dev,
void *control)
{
return BadMatch;
}
/******************************************************************************/
int
ChangePointerDevice(DeviceIntPtr old_dev, DeviceIntPtr new_dev,
unsigned char x, unsigned char y)
{
return BadMatch;
}
/******************************************************************************/
void
CloseInputDevice(DeviceIntPtr d, ClientPtr client)
{
}
/* the g_ functions from os_calls.c */
/*****************************************************************************/
int
g_tcp_recv(int sck, void *ptr, int len, int flags)
{
return recv(sck, ptr, len, flags);
}
/*****************************************************************************/
void
g_tcp_close(int sck)
{
if (sck == 0)
{
return;
}
shutdown(sck, 2);
close(sck);
}
/*****************************************************************************/
int
g_tcp_last_error_would_block(int sck)
{
return (errno == EWOULDBLOCK) || (errno == EINPROGRESS);
}
/*****************************************************************************/
void
g_sleep(int msecs)
{
usleep(msecs * 1000);
}
/*****************************************************************************/
int
g_tcp_send(int sck, void *ptr, int len, int flags)
{
return send(sck, ptr, len, flags);
}
/*****************************************************************************/
void *
g_malloc(int size, int zero)
{
char *rv;
//#ifdef _XSERVER64
#if 1
/* I thought xalloc whould work here but I guess not, why, todo */
rv = (char *)malloc(size);
#else
rv = (char *)Xalloc(size);
#endif
if (zero)
{
if (rv != 0)
{
memset(rv, 0, size);
}
}
return rv;
}
/*****************************************************************************/
void
g_free(void *ptr)
{
if (ptr != 0)
{
//#ifdef _XSERVER64
#if 1
/* I thought xfree whould work here but I guess not, why, todo */
free(ptr);
#else
Xfree(ptr);
#endif
}
}
/*****************************************************************************/
void
g_sprintf(char *dest, char *format, ...)
{
va_list ap;
va_start(ap, format);
vsprintf(dest, format, ap);
va_end(ap);
}
/*****************************************************************************/
int
g_tcp_socket(void)
{
int rv;
int i;
i = 1;
rv = socket(PF_INET, SOCK_STREAM, 0);
setsockopt(rv, IPPROTO_TCP, TCP_NODELAY, (void *)&i, sizeof(i));
setsockopt(rv, SOL_SOCKET, SO_REUSEADDR, (void *)&i, sizeof(i));
return rv;
}
/*****************************************************************************/
int
g_tcp_local_socket_dgram(void)
{
return socket(AF_UNIX, SOCK_DGRAM, 0);
}
/*****************************************************************************/
int
g_tcp_local_socket_stream(void)
{
return socket(AF_UNIX, SOCK_STREAM, 0);
}
/*****************************************************************************/
void
g_memcpy(void *d_ptr, const void *s_ptr, int size)
{
memcpy(d_ptr, s_ptr, size);
}
/*****************************************************************************/
int
g_tcp_set_no_delay(int sck)
{
int i;
i = 1;
setsockopt(sck, IPPROTO_TCP, TCP_NODELAY, (void *)&i, sizeof(i));
return 0;
}
/*****************************************************************************/
int
g_tcp_set_non_blocking(int sck)
{
unsigned long i;
i = fcntl(sck, F_GETFL);
i = i | O_NONBLOCK;
fcntl(sck, F_SETFL, i);
return 0;
}
/*****************************************************************************/
int
g_tcp_accept(int sck)
{
struct sockaddr_in s;
unsigned int i;
i = sizeof(struct sockaddr_in);
memset(&s, 0, i);
return accept(sck, (struct sockaddr *)&s, &i);
}
/*****************************************************************************/
int
g_tcp_select(int sck1, int sck2, int sck3)
{
fd_set rfds;
struct timeval time;
int max;
int rv;
time.tv_sec = 0;
time.tv_usec = 0;
FD_ZERO(&rfds);
if (sck1 > 0)
{
FD_SET(((unsigned int)sck1), &rfds);
}
if (sck2 > 0)
{
FD_SET(((unsigned int)sck2), &rfds);
}
if (sck3 > 0)
{
FD_SET(((unsigned int)sck3), &rfds);
}
max = sck1;
if (sck2 > max)
{
max = sck2;
}
if (sck3 > max)
{
max = sck3;
}
rv = select(max + 1, &rfds, 0, 0, &time);
if (rv > 0)
{
rv = 0;
if (FD_ISSET(((unsigned int)sck1), &rfds))
{
rv = rv | 1;
}
if (FD_ISSET(((unsigned int)sck2), &rfds))
{
rv = rv | 2;
}
if (FD_ISSET(((unsigned int)sck3), &rfds))
{
rv = rv | 4;
}
}
else
{
rv = 0;
}
return rv;
}
/*****************************************************************************/
int
g_tcp_bind(int sck, char *port)
{
struct sockaddr_in s;
memset(&s, 0, sizeof(struct sockaddr_in));
s.sin_family = AF_INET;
s.sin_port = htons(atoi(port));
s.sin_addr.s_addr = INADDR_ANY;
return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_in));
}
/*****************************************************************************/
int
g_tcp_local_bind(int sck, char *port)
{
struct sockaddr_un s;
memset(&s, 0, sizeof(struct sockaddr_un));
s.sun_family = AF_UNIX;
strcpy(s.sun_path, port);
return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_un));
}
/*****************************************************************************/
int
g_tcp_listen(int sck)
{
return listen(sck, 2);
}
/*****************************************************************************/
/* returns boolean */
int
g_create_dir(const char *dirname)
{
return mkdir(dirname, (mode_t) - 1) == 0;
}
/*****************************************************************************/
/* returns boolean, non zero if the directory exists */
int
g_directory_exist(const char *dirname)
{
struct stat st;
if (stat(dirname, &st) == 0)
{
return S_ISDIR(st.st_mode);
}
else
{
return 0;
}
}
/*****************************************************************************/
/* returns error */
int
g_chmod_hex(const char *filename, int flags)
{
int fl;
fl = 0;
fl |= (flags & 0x4000) ? S_ISUID : 0;
fl |= (flags & 0x2000) ? S_ISGID : 0;
fl |= (flags & 0x1000) ? S_ISVTX : 0;
fl |= (flags & 0x0400) ? S_IRUSR : 0;
fl |= (flags & 0x0200) ? S_IWUSR : 0;
fl |= (flags & 0x0100) ? S_IXUSR : 0;
fl |= (flags & 0x0040) ? S_IRGRP : 0;
fl |= (flags & 0x0020) ? S_IWGRP : 0;
fl |= (flags & 0x0010) ? S_IXGRP : 0;
fl |= (flags & 0x0004) ? S_IROTH : 0;
fl |= (flags & 0x0002) ? S_IWOTH : 0;
fl |= (flags & 0x0001) ? S_IXOTH : 0;
return chmod(filename, fl);
}
/* produce a hex dump */
void
hexdump(unsigned char *p, unsigned int len)
{
unsigned char *line;
int i;
int thisline;
int offset;
offset = 0;
line = p;
while (offset < len)
{
ErrorF("%04x ", offset);
thisline = len - offset;
if (thisline > 16)
{
thisline = 16;
}
for (i = 0; i < thisline; i++)
{
ErrorF("%02x ", line[i]);
}
for (; i < 16; i++)
{
ErrorF(" ");
}
for (i = 0; i < thisline; i++)
{
ErrorF("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
}
ErrorF("\n");
offset += thisline;
line += thisline;
}
}
/*
stub for XpClient* functions.
*/
/*****************************************************************************/
Bool
XpClientIsBitmapClient(ClientPtr client)
{
return 1;
}
/*****************************************************************************/
Bool
XpClientIsPrintClient(ClientPtr client, FontPathElementPtr fpe)
{
return 0;
}
/*****************************************************************************/
int
PrinterOptions(int argc, char **argv, int i)
{
return i;
}
/*****************************************************************************/
void
PrinterInitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
{
}
/*****************************************************************************/
void
PrinterUseMsg(void)
{
}
/*****************************************************************************/
void
PrinterInitGlobals(void)
{
}
/*****************************************************************************/
void
FontCacheExtensionInit(INITARGS)
{
}
/******************************************************************************/
void
RegionAroundSegs(RegionPtr reg, xSegment *segs, int nseg)
{
int index;
BoxRec box;
RegionRec treg;
index = 0;
while (index < nseg)
{
if (segs[index].x1 < segs[index].x2)
{
box.x1 = segs[index].x1;
box.x2 = segs[index].x2;
}
else
{
box.x1 = segs[index].x2;
box.x2 = segs[index].x1;
}
box.x2++;
if (segs[index].y1 < segs[index].y2)
{
box.y1 = segs[index].y1;
box.y2 = segs[index].y2;
}
else
{
box.y1 = segs[index].y2;
box.y2 = segs[index].y1;
}
box.y2++;
RegionInit(&treg, &box, 0);
RegionUnion(reg, reg, &treg);
RegionUninit(&treg);
index++;
}
}
|