~paulliu/ubuntu/precise/freerdp/fixext

« back to all changes in this revision

Viewing changes to X11/xfreerdp.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2010-10-25 14:29:02 UTC
  • mto: (9.1.1 sid) (1.1.7)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20101025142902-j8hmshnnxhu61l4m
Tags: upstream-0.8.1
ImportĀ upstreamĀ versionĀ 0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <errno.h>
31
31
#include <pwd.h>
32
32
#include <pthread.h>
 
33
#include <semaphore.h>
33
34
#include <freerdp/freerdp.h>
34
35
#include <freerdp/chanman.h>
35
36
#include <freerdp/kbd.h>
39
40
 
40
41
#define MAX_PLUGIN_DATA 20
41
42
 
 
43
static volatile int g_thread_count = 0;
 
44
static sem_t g_sem;
 
45
 
42
46
static int
43
47
set_default_params(xfInfo * xfi)
44
48
{
57
61
        settings->bitmap_cache = 1;
58
62
        settings->bitmap_compression = 1;
59
63
        settings->desktop_save = 0;
60
 
        settings->rdp5_performanceflags =
61
 
                RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
 
64
        settings->performanceflags =
 
65
                PERF_DISABLE_WALLPAPER | PERF_DISABLE_FULLWINDOWDRAG | PERF_DISABLE_MENUANIMATIONS;
62
66
        settings->off_screen_bitmaps = 1;
63
67
        settings->triblt = 0;
64
68
        settings->new_cursors = 1;
65
69
        settings->rdp_version = 5;
 
70
#ifndef DISABLE_TLS
 
71
        settings->tls = 1;
 
72
#endif
66
73
        xfi->fullscreen = xfi->fs_toggle = 0;
67
74
        return 0;
68
75
}
69
76
 
 
77
static int
 
78
out_args(void)
 
79
{
 
80
        char help[] =
 
81
                "\n"
 
82
                "FreeRDP - A Free Remote Desktop Protocol Client\n"
 
83
                "See http://freerdp.sourceforge.net for more information\n"
 
84
                "\n"
 
85
                "Usage: xfreerdp [options] server:port\n"
 
86
                "\t-a: color depth (8, 15, 16, 24 or 32)\n"
 
87
                "\t-u: username\n"
 
88
                "\t-p: password\n"
 
89
                "\t-d: domain\n"
 
90
                "\t-k: keyboard layout ID\n"
 
91
                "\t--kbd-list: list all keyboard layout IDs\n"
 
92
                "\t-s: shell\n"
 
93
                "\t-c: directory\n"
 
94
                "\t-g: geometry, using format WxH, default is 1024x768\n"
 
95
                "\t-t: alternative port number (default is 3389)\n"
 
96
                "\t-n: hostname\n"
 
97
                "\t-o: console audio\n"
 
98
                "\t-0: console session\n"
 
99
                "\t-f: fullscreen mode\n"
 
100
                "\t-z: enable bulk compression\n"
 
101
                "\t-x: performance flags (m, b or l for modem, broadband or lan)\n"
 
102
#ifndef DISABLE_TLS
 
103
                "\t--no-tls: disable TLS encryption\n"
 
104
#endif
 
105
                "\t--plugin: load a virtual channel plugin\n"
 
106
                "\t--no-osb: disable off screen bitmaps, default on\n"
 
107
                "\t--version: Print out the version and exit\n"
 
108
                "\t-h: show this help\n";
 
109
        printf("%s\n", help);
 
110
        return 0;
 
111
}
 
112
 
70
113
/* Returns "true" on errors or other reasons to not continue normal operation */
71
114
static int
72
115
process_params(xfInfo * xfi, int argc, char ** argv, int * pindex)
77
120
        RD_PLUGIN_DATA plugin_data[MAX_PLUGIN_DATA + 1];
78
121
        int index;
79
122
        int i, j;
 
123
        struct passwd * pw;
80
124
 
81
125
        set_default_params(xfi);
82
126
        settings = xfi->settings;
83
127
        p = getlogin();
 
128
        i = sizeof(settings->username) - 1;
84
129
        if (p != 0)
85
130
        {
86
 
                strncpy(settings->username, p, sizeof(settings->username) - 1);
 
131
                strncpy(settings->username, p, i);
 
132
        }
 
133
        else
 
134
        {
 
135
                pw = getpwuid(getuid());
 
136
                if (pw != 0)
 
137
                {
 
138
                        if (pw->pw_name != 0)
 
139
                        {
 
140
                                strncpy(settings->username, pw->pw_name, i);
 
141
                        }
 
142
                }
87
143
        }
88
144
 
89
145
        if (argc < *pindex + 1)
246
302
                {
247
303
                        settings->bulk_compression = 1;
248
304
                }
 
305
                else if (strcmp("--no-osb", argv[*pindex]) == 0)
 
306
                {
 
307
                        settings->off_screen_bitmaps = 0;
 
308
                }
249
309
                else if (strcmp("-f", argv[*pindex]) == 0)
250
310
                {
251
311
                        xfi->fullscreen = xfi->fs_toggle = 1;
261
321
                        }
262
322
                        if (strncmp("m", argv[*pindex], 1) == 0) /* modem */
263
323
                        {
264
 
                                settings->rdp5_performanceflags = RDP5_NO_WALLPAPER |
265
 
                                        RDP5_NO_FULLWINDOWDRAG |  RDP5_NO_MENUANIMATIONS |
266
 
                                        RDP5_NO_THEMING;
 
324
                                settings->performanceflags = PERF_DISABLE_WALLPAPER |
 
325
                                        PERF_DISABLE_FULLWINDOWDRAG | PERF_DISABLE_MENUANIMATIONS |
 
326
                                        PERF_DISABLE_THEMING;
267
327
                        }
268
328
                        else if (strncmp("b", argv[*pindex], 1) == 0) /* broadband */
269
329
                        {
270
 
                                settings->rdp5_performanceflags = RDP5_NO_WALLPAPER;
 
330
                                settings->performanceflags = PERF_DISABLE_WALLPAPER;
271
331
                        }
272
332
                        else if (strncmp("l", argv[*pindex], 1) == 0) /* lan */
273
333
                        {
274
 
                                settings->rdp5_performanceflags = RDP5_DISABLE_NOTHING;
 
334
                                settings->performanceflags = PERF_FLAG_NONE;
275
335
                        }
276
336
                        else
277
337
                        {
278
 
                                settings->rdp5_performanceflags = strtol(argv[*pindex], 0, 16);
 
338
                                settings->performanceflags = strtol(argv[*pindex], 0, 16);
279
339
                        }
280
340
                }
 
341
#ifndef DISABLE_TLS
 
342
                else if (strcmp("--no-tls", argv[*pindex]) == 0)
 
343
                {
 
344
                        settings->tls = 0;
 
345
                }
 
346
#endif
281
347
                else if (strcmp("--plugin", argv[*pindex]) == 0)
282
348
                {
283
349
                        *pindex = *pindex + 1;
310
376
                }
311
377
                else if ((strcmp("-h", argv[*pindex]) == 0) || strcmp("--help", argv[*pindex]) == 0)
312
378
                {
313
 
                        char help[] =
314
 
                                "\n"
315
 
                                "FreeRDP - A Free Remote Desktop Protocol Client\n"
316
 
                                "See http://freerdp.sourceforge.net for more information\n"
317
 
                                "\n"
318
 
                                "Usage: xfreerdp [options] server:port\n"
319
 
                                "\t-a: color depth (16, 24 or 32)\n"
320
 
                                "\t-u: username\n"
321
 
                                "\t-p: password\n"
322
 
                                "\t-d: domain\n"
323
 
                                "\t-k: keyboard layout ID\n"
324
 
                                "\t--kbd-list: list all keyboard layout IDs\n"
325
 
                                "\t-s: shell\n"
326
 
                                "\t-c: directory\n"
327
 
                                "\t-g: geometry, using format WxH, default is 1024x768\n"
328
 
                                "\t-t: alternative port number (default is 3389)\n"
329
 
                                "\t-n: hostname\n"
330
 
                                "\t-o: console audio\n"
331
 
                                "\t-0: console session\n"
332
 
                                "\t-f: fullscreen mode\n"
333
 
                                "\t-z: enable bulk compression\n"
334
 
                                "\t-x: performance flags (m, b or l for modem, broadband or lan)\n"
335
 
                                "\t--plugin: load a virtual channel plugin\n"
336
 
                                "\t-h: show this help\n"
337
 
                                "\n";
338
 
 
339
 
                        printf(help);
 
379
                        out_args();
340
380
                        return 1;
341
381
                }
342
382
                else if (argv[*pindex][0] != '-')
369
409
                        *pindex = *pindex + 1;
370
410
                        return 0;
371
411
                }
 
412
      else if (strcmp("--version", argv[*pindex]) == 0)
 
413
                {
 
414
                        printf("This is FreeRDP version %s\n", PACKAGE_VERSION);
 
415
                        return 1;
 
416
                }
372
417
                else
373
418
                {
374
419
                        printf("invalid option: %s\n", argv[*pindex]);
520
565
                }
521
566
        }
522
567
        /* cleanup */
 
568
        freerdp_chanman_close(xfi->chan_man, inst);
523
569
        inst->rdp_disconnect(inst);
524
570
        freerdp_free(inst);
525
571
        xf_uninit(xfi);
526
572
        return 0;
527
573
}
528
574
 
529
 
static int g_thread_count = 0;
530
 
 
531
575
static void *
532
576
thread_func(void * arg)
533
577
{
541
585
 
542
586
        pthread_detach(pthread_self());
543
587
        g_thread_count--;
544
 
 
 
588
        if (g_thread_count < 1)
 
589
        {
 
590
                sem_post(&g_sem);
 
591
        }
545
592
        return NULL;
546
593
}
547
594
 
554
601
        int index = 1;
555
602
 
556
603
        setlocale(LC_CTYPE, "");
 
604
        if (argc == 1)
 
605
        {
 
606
                out_args();
 
607
                return 0;
 
608
        }
 
609
        if (!freerdp_global_init())
 
610
        {
 
611
                printf("Error initializing freerdp\n");
 
612
                return 1;
 
613
        }
557
614
        freerdp_chanman_init();
558
 
 
 
615
        sem_init(&g_sem, 0, 0);
559
616
        while (1)
560
617
        {
561
618
                xfi = (xfInfo *) malloc(sizeof(xfInfo));
572
629
                }
573
630
 
574
631
                xf_kb_init(xfi->keyboard_layout_id);
575
 
                g_thread_count++;
576
632
                printf("starting thread %d to %s:%d\n", g_thread_count,
577
633
                        xfi->settings->server, xfi->settings->tcp_port_rdp);
578
 
                pthread_create(&thread, 0, thread_func, xfi);
 
634
                if (pthread_create(&thread, 0, thread_func, xfi) == 0)
 
635
                {
 
636
                        g_thread_count++;
 
637
                }
579
638
        }
580
639
 
581
 
        while (g_thread_count > 0)
 
640
        if (g_thread_count > 0)
582
641
        {
583
 
                sleep(1);
 
642
                printf("main thread, waiting for all threads to exit\n");
 
643
                sem_wait(&g_sem);
 
644
                printf("main thread, all threads did exit\n");
584
645
        }
585
646
 
586
647
        freerdp_chanman_uninit();
 
648
        freerdp_global_finish();
587
649
        return 0;
588
650
}