~ubuntu-branches/ubuntu/wily/freerdp/wily-proposed

« back to all changes in this revision

Viewing changes to libfreerdp-utils/args.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt, Jeremy Bicha, Jean-Louis Dupond, Martin Pitt
  • Date: 2012-01-31 10:02:14 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120131100214-jaok3uwvni7sqxth
Tags: 1.0.0-0git1
Upload current Debian packaging git to get this rolling for precise.

[ Jeremy Bicha ]
* New upstream release. Closes: #647498.
* Updated symbols and bumped soname
* debian/control:
  - Added new build dependencies
  - Bump Standards-Version to 3.9.2
* debian/source/format: Set to 3.0 (quilt)
* debian/rules: Turn on strict symbols checking
* debian/watch: Watch github

[ Jean-Louis Dupond ]
* debian/control: Updated homepage
* debian/copyright: Reflect upstream switch to the Apache license

[ Martin Pitt ]
* debian/libfreerdp0.symbols: Fix version number, should
  be 1.0~beta5, not 1.0-beta5.
* debian/control: Add libavcodec-dev build dependency, upstream build system
  checks for that. Thanks Jean-Louis Dupond!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * FreeRDP: A Remote Desktop Protocol client.
 
3
 * Arguments Parsing
 
4
 *
 
5
 * Copyright 2009-2011 Jay Sorg
 
6
 * Copyright 2011 Vic Lee
 
7
 *
 
8
 * Licensed under the Apache License, Version 2.0 (the "License");
 
9
 * you may not use this file except in compliance with the License.
 
10
 * You may obtain a copy of the License at
 
11
 *
 
12
 *     http://www.apache.org/licenses/LICENSE-2.0
 
13
 *
 
14
 * Unless required by applicable law or agreed to in writing, software
 
15
 * distributed under the License is distributed on an "AS IS" BASIS,
 
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
17
 * See the License for the specific language governing permissions and
 
18
 * limitations under the License.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
#include <stdio.h>
 
23
#include <stdlib.h>
 
24
#include <string.h>
 
25
#include <freerdp/settings.h>
 
26
#include <freerdp/utils/print.h>
 
27
#include <freerdp/utils/memory.h>
 
28
#include <freerdp/utils/args.h>
 
29
 
 
30
/**
 
31
 * Parse command-line arguments and update rdpSettings members accordingly.
 
32
 * @param settings pointer to rdpSettings struct to be updated.
 
33
 * @param argc number of arguments available.
 
34
 * @param argv string array of the arguments.
 
35
 * @param plugin_callback function to be called when a plugin needs to be loaded.
 
36
 * @param plugin_user_data pointer to be passed to the plugin_callback function.
 
37
 * @param ui_callback function to be called when a UI-specific argument is being processed.
 
38
 * @param ui_user_data pointer to be passed to the ui_callback function.
 
39
 * @return number of arguments that were parsed, or FREERDP_ARGS_PARSE_RESULT on failure or --version/--help
 
40
 */
 
41
int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
 
42
        ProcessPluginArgs plugin_callback, void* plugin_user_data,
 
43
        ProcessUIArgs ui_callback, void* ui_user_data)
 
44
{
 
45
        int t;
 
46
        char* p;
 
47
        int i, j;
 
48
        int index = 1;
 
49
        int num_extensions = 0;
 
50
        RDP_PLUGIN_DATA* plugin_data;
 
51
 
 
52
        while (index < argc)
 
53
        {
 
54
                if ((strcmp("-h", argv[index]) == 0 ) || (strcmp("--help", argv[index]) == 0 ))
 
55
                {
 
56
                        printf("\n"
 
57
                                "FreeRDP - A Free Remote Desktop Protocol Client\n"
 
58
                                "See http://www.freerdp.com for more information\n"
 
59
                                "\n"
 
60
                                "Usage: %s [options] server:port\n"
 
61
                                "  -0: connect to console session\n"
 
62
                                "  -a: set color depth in bit, default is 16\n"
 
63
                                "  -c: initial working directory\n"
 
64
                                "  -D: hide window decorations\n"
 
65
                                "  -T: window title\n"
 
66
                                "  -d: domain\n"
 
67
                                "  -f: fullscreen mode\n"
 
68
                                "  -g: set geometry, using format WxH or X%% or 'workarea', default is 1024x768\n"
 
69
                                "  -h: print this help\n"
 
70
                                "  -k: set keyboard layout ID\n"
 
71
                                "  -K: do not interfere with window manager bindings\n"
 
72
                                "  -m: don't send mouse motion events\n"
 
73
                                "  -n: hostname\n"
 
74
                                "  -o: console audio\n"
 
75
                                "  -p: password\n"
 
76
                                "  -s: set startup-shell\n"
 
77
                                "  -t: alternative port number, default is 3389\n"
 
78
                                "  -u: username\n"
 
79
                                "  -x: performance flags (m[odem], b[roadband] or l[an])\n"
 
80
                                "  -X: embed into another window with a given XID.\n"
 
81
                                "  -z: enable compression\n"
 
82
                                "  --app: RemoteApp connection. This implies -g workarea\n"
 
83
                                "  --ext: load an extension\n"
 
84
                                "  --no-auth: disable authentication\n"
 
85
                                "  --no-fastpath: disable fast-path\n"
 
86
                                "  --gdi: graphics rendering (hw, sw)\n"
 
87
                                "  --no-osb: disable offscreen bitmaps\n"
 
88
                                "  --no-bmp-cache: disable bitmap cache\n"
 
89
                                "  --plugin: load a virtual channel plugin\n"
 
90
                                "  --rfx: enable RemoteFX\n"
 
91
                                "  --rfx-mode: RemoteFX operational flags (v[ideo], i[mage]), default is video\n"
 
92
                                "  --nsc: enable NSCodec (experimental)\n"
 
93
                                "  --disable-wallpaper: disables wallpaper\n"
 
94
                                "  --composition: enable desktop composition\n"
 
95
                                "  --disable-full-window-drag: disables full window drag\n"
 
96
                                "  --disable-menu-animations: disables menu animations\n"
 
97
                                "  --disable-theming: disables theming\n"
 
98
                                "  --no-rdp: disable Standard RDP encryption\n"
 
99
                                "  --no-tls: disable TLS encryption\n"
 
100
                                "  --no-nla: disable network level authentication\n"
 
101
                                "  --ntlm: force NTLM authentication protocol version (1 or 2)\n"
 
102
                                "  --ignore-certificate: ignore verification of logon certificate\n"
 
103
                                "  --sec: force protocol security (rdp, tls or nla)\n"
 
104
                                "  --version: print version information\n"
 
105
                                "\n", argv[0]);
 
106
                        return FREERDP_ARGS_PARSE_HELP; //TODO: What is the correct return
 
107
                }
 
108
                else if (strcmp("-a", argv[index]) == 0)
 
109
                {
 
110
                        index++;
 
111
                        if (index == argc)
 
112
                        {
 
113
                                printf("missing color depth\n");
 
114
                                return FREERDP_ARGS_PARSE_FAILURE;
 
115
                        }
 
116
                        settings->color_depth = atoi(argv[index]);
 
117
                }
 
118
                else if (strcmp("-u", argv[index]) == 0)
 
119
                {
 
120
                        index++;
 
121
                        if (index == argc)
 
122
                        {
 
123
                                printf("missing username\n");
 
124
                                return FREERDP_ARGS_PARSE_FAILURE;
 
125
                        }
 
126
                        settings->username = xstrdup(argv[index]);
 
127
                }
 
128
                else if (strcmp("-p", argv[index]) == 0)
 
129
                {
 
130
                        index++;
 
131
                        if (index == argc)
 
132
                        {
 
133
                                printf("missing password\n");
 
134
                                return FREERDP_ARGS_PARSE_FAILURE;
 
135
                        }
 
136
                        settings->password = xstrdup(argv[index]);
 
137
                        settings->autologon = 1;
 
138
 
 
139
                        /*
 
140
                         * Overwrite original password which could be revealed by a simple "ps aux" command.
 
141
                         * This approach won't hide the password length, but it is better than nothing.
 
142
                         */
 
143
 
 
144
                        memset(argv[index], '*', strlen(argv[index]));
 
145
                }
 
146
                else if (strcmp("-d", argv[index]) == 0)
 
147
                {
 
148
                        index++;
 
149
                        if (index == argc)
 
150
                        {
 
151
                                printf("missing domain\n");
 
152
                                return FREERDP_ARGS_PARSE_FAILURE;
 
153
                        }
 
154
                        settings->domain = xstrdup(argv[index]);
 
155
                }
 
156
                else if (strcmp("-s", argv[index]) == 0)
 
157
                {
 
158
                        index++;
 
159
                        if (index == argc)
 
160
                        {
 
161
                                printf("missing shell\n");
 
162
                                return FREERDP_ARGS_PARSE_FAILURE;
 
163
                        }
 
164
                        settings->shell = xstrdup(argv[index]);
 
165
                }
 
166
                else if (strcmp("-c", argv[index]) == 0)
 
167
                {
 
168
                        index++;
 
169
                        if (index == argc)
 
170
                        {
 
171
                                printf("missing directory\n");
 
172
                                return FREERDP_ARGS_PARSE_FAILURE;
 
173
                        }
 
174
                        settings->directory = xstrdup(argv[index]);
 
175
                }
 
176
                else if (strcmp("-g", argv[index]) == 0)
 
177
                {
 
178
                        index++;
 
179
                        if (index == argc)
 
180
                        {
 
181
                                printf("missing dimensions\n");
 
182
                                return FREERDP_ARGS_PARSE_FAILURE;
 
183
                        }
 
184
 
 
185
                        if (strncmp("workarea", argv[index], 1) == 0)
 
186
                        {
 
187
                                settings->workarea = true;
 
188
                        }
 
189
                        else
 
190
                        {
 
191
                                settings->width = (uint16) strtol(argv[index], &p, 10);
 
192
 
 
193
                                if (*p == 'x')
 
194
                                {
 
195
                                        settings->height = (uint16) strtol(p + 1, &p, 10);
 
196
                                }
 
197
                                if (*p == '%')
 
198
                                {
 
199
                                        settings->percent_screen = settings->width;
 
200
                                        if (settings->percent_screen <= 0 || settings->percent_screen > 100)
 
201
                                        {
 
202
                                                printf("invalid geometry percentage\n");
 
203
                                                return FREERDP_ARGS_PARSE_FAILURE;
 
204
                                        }
 
205
                                }
 
206
                                else
 
207
                                {
 
208
                                        if (ui_callback != NULL)
 
209
                                                ui_callback(settings, "-g", p, ui_user_data);
 
210
                                }
 
211
                        }
 
212
                }
 
213
                else if (strcmp("-f", argv[index]) == 0)
 
214
                {
 
215
                        settings->fullscreen = true;
 
216
                }
 
217
                else if (strcmp("-D", argv[index]) == 0)
 
218
                {
 
219
                        settings->decorations = false;
 
220
                }
 
221
                else if (strcmp("-T", argv[index]) == 0)
 
222
                {
 
223
                        index++;
 
224
                        if (index == argc)
 
225
                        {
 
226
                                printf("missing window title\n");
 
227
                                return FREERDP_ARGS_PARSE_FAILURE;
 
228
                        }
 
229
 
 
230
                        settings->window_title = xstrdup(argv[index]);
 
231
                }
 
232
                else if (strcmp("-t", argv[index]) == 0)
 
233
                {
 
234
                        index++;
 
235
                        if (index == argc)
 
236
                        {
 
237
                                printf("missing port number\n");
 
238
                                return FREERDP_ARGS_PARSE_FAILURE;
 
239
                        }
 
240
                        settings->port = atoi(argv[index]);
 
241
                }
 
242
                else if (strcmp("-k", argv[index]) == 0)
 
243
                {
 
244
                        index++;
 
245
                        if (index == argc)
 
246
                        {
 
247
                                printf("missing keyboard layout id\n");
 
248
                                return FREERDP_ARGS_PARSE_FAILURE;
 
249
                        }
 
250
                        sscanf(argv[index], "%X", &(settings->kbd_layout));
 
251
                }
 
252
                else if (strcmp("-K", argv[index]) == 0)
 
253
                {
 
254
                        settings->grab_keyboard = false;
 
255
                }
 
256
                else if (strcmp("-n", argv[index]) == 0)
 
257
                {
 
258
                        index++;
 
259
                        if (index == argc)
 
260
                        {
 
261
                                printf("missing client hostname\n");
 
262
                                return FREERDP_ARGS_PARSE_FAILURE;
 
263
                        }
 
264
                        strncpy(settings->client_hostname, argv[index], sizeof(settings->client_hostname) - 1);
 
265
                        settings->client_hostname[sizeof(settings->client_hostname) - 1] = 0;
 
266
                }
 
267
                else if (strcmp("-o", argv[index]) == 0)
 
268
                {
 
269
                        settings->console_audio = true;
 
270
                }
 
271
                else if (strcmp("-0", argv[index]) == 0)
 
272
                {
 
273
                        settings->console_session = true;
 
274
                }
 
275
                else if (strcmp("-z", argv[index]) == 0)
 
276
                {
 
277
                        settings->compression = true;
 
278
                }
 
279
                else if (strcmp("--ntlm", argv[index]) == 0)
 
280
                {
 
281
                        index++;
 
282
 
 
283
                        settings->ntlm_version = atoi(argv[index]);
 
284
 
 
285
                        if (settings->ntlm_version != 2)
 
286
                                settings->ntlm_version = 1;
 
287
                }
 
288
                else if (strcmp("--no-glyph-cache", argv[index]) == 0)
 
289
                {
 
290
                        settings->glyph_cache = false;
 
291
                }
 
292
                else if (strcmp("--no-osb", argv[index]) == 0)
 
293
                {
 
294
                        settings->offscreen_bitmap_cache = false;
 
295
                }
 
296
                else if (strcmp("--no-bmp-cache", argv[index]) == 0)
 
297
                {
 
298
                        settings->bitmap_cache = false;
 
299
                }
 
300
                else if (strcmp("--no-auth", argv[index]) == 0)
 
301
                {
 
302
                        settings->authentication = false;
 
303
                }
 
304
                else if (strcmp("--ignore-certificate", argv[index]) == 0)
 
305
                {
 
306
                        settings->ignore_certificate = true;
 
307
                }
 
308
                else if (strcmp("--no-fastpath", argv[index]) == 0)
 
309
                {
 
310
                        settings->fastpath_input = false;
 
311
                        settings->fastpath_output = false;
 
312
                }
 
313
                else if (strcmp("--gdi", argv[index]) == 0)
 
314
                {
 
315
                        index++;
 
316
                        if (index == argc)
 
317
                        {
 
318
                                printf("missing GDI backend\n");
 
319
                                return FREERDP_ARGS_PARSE_FAILURE;
 
320
                        }
 
321
                        if (strncmp("sw", argv[index], 1) == 0) /* software */
 
322
                        {
 
323
                                settings->sw_gdi = true;
 
324
                        }
 
325
                        else if (strncmp("hw", argv[index], 1) == 0) /* hardware */
 
326
                        {
 
327
                                settings->sw_gdi = false;
 
328
                        }
 
329
                        else
 
330
                        {
 
331
                                printf("unknown GDI backend\n");
 
332
                                return FREERDP_ARGS_PARSE_FAILURE;
 
333
                        }
 
334
                }
 
335
                else if (strcmp("--rfx", argv[index]) == 0)
 
336
                {
 
337
                        settings->rfx_codec = true;
 
338
                        settings->fastpath_output = true;
 
339
                        settings->color_depth = 32;
 
340
                        settings->frame_acknowledge = false;
 
341
                        settings->performance_flags = PERF_FLAG_NONE;
 
342
                        settings->large_pointer = true;
 
343
                }
 
344
                else if (strcmp("--rfx-mode", argv[index]) == 0)
 
345
                {
 
346
                        index++;
 
347
                        if (index == argc)
 
348
                        {
 
349
                                printf("missing RemoteFX mode flag\n");
 
350
                                return FREERDP_ARGS_PARSE_FAILURE;
 
351
                        }
 
352
                        if (argv[index][0] == 'v') /* video */
 
353
                        {
 
354
                                settings->rfx_codec_mode = 0x00;
 
355
                        }
 
356
                        else if (argv[index][0] == 'i') /* image */
 
357
                        {
 
358
                                settings->rfx_codec_mode = 0x02;
 
359
                        }
 
360
                        else
 
361
                        {
 
362
                                printf("unknown RemoteFX mode flag\n");
 
363
                                return FREERDP_ARGS_PARSE_FAILURE;
 
364
                        }
 
365
                }
 
366
                else if (strcmp("--nsc", argv[index]) == 0)
 
367
                {
 
368
                        settings->ns_codec = true;
 
369
                }
 
370
                else if (strcmp("--dump-rfx", argv[index]) == 0)
 
371
                {
 
372
                        index++;
 
373
                        if (index == argc)
 
374
                        {
 
375
                                printf("missing file name\n");
 
376
                                return FREERDP_ARGS_PARSE_FAILURE;
 
377
                        }
 
378
                        settings->dump_rfx_file = xstrdup(argv[index]);
 
379
                        settings->dump_rfx = true;
 
380
                }
 
381
                else if (strcmp("--play-rfx", argv[index]) == 0)
 
382
                {
 
383
                        index++;
 
384
                        if (index == argc)
 
385
                        {
 
386
                                printf("missing file name\n");
 
387
                                return FREERDP_ARGS_PARSE_FAILURE;
 
388
                        }
 
389
                        settings->play_rfx_file = xstrdup(argv[index]);
 
390
                        settings->play_rfx = true;
 
391
                }
 
392
                else if (strcmp("--fonts", argv[index]) == 0)
 
393
                {
 
394
                        settings->smooth_fonts = true;
 
395
                }
 
396
                else if (strcmp("--disable-wallpaper", argv[index]) == 0)
 
397
                {
 
398
                        settings->disable_wallpaper = true;
 
399
                }
 
400
                else if (strcmp("--disable-full-window-drag", argv[index]) == 0)
 
401
                {
 
402
                        settings->disable_full_window_drag = true;
 
403
                }
 
404
                else if (strcmp("--disable-menu-animations", argv[index]) == 0)
 
405
                {
 
406
                        settings->disable_menu_animations = true;
 
407
                }
 
408
                else if (strcmp("--disable-theming", argv[index]) == 0)
 
409
                {
 
410
                        settings->disable_theming = true;
 
411
                }
 
412
                else if (strcmp("--composition", argv[index]) == 0)
 
413
                {
 
414
                        settings->desktop_composition = true;
 
415
                }
 
416
                else if (strcmp("--no-motion", argv[index]) == 0)
 
417
                {
 
418
                        settings->mouse_motion = false;
 
419
                }
 
420
                else if (strcmp("--app", argv[index]) == 0)
 
421
                {
 
422
                        settings->remote_app = true;
 
423
                        settings->rail_langbar_supported = true;
 
424
                        settings->workarea = true;
 
425
                        settings->performance_flags = PERF_DISABLE_WALLPAPER | PERF_DISABLE_FULLWINDOWDRAG;
 
426
                }
 
427
                else if (strcmp("-x", argv[index]) == 0)
 
428
                {
 
429
                        index++;
 
430
                        if (index == argc)
 
431
                        {
 
432
                                printf("missing performance flag\n");
 
433
                                return FREERDP_ARGS_PARSE_FAILURE;
 
434
                        }
 
435
                        if (argv[index][0] == 'm') /* modem */
 
436
                        {
 
437
                                settings->performance_flags = PERF_DISABLE_WALLPAPER |
 
438
                                        PERF_DISABLE_FULLWINDOWDRAG | PERF_DISABLE_MENUANIMATIONS |
 
439
                                        PERF_DISABLE_THEMING;
 
440
 
 
441
                                settings->connection_type = CONNECTION_TYPE_MODEM;
 
442
                        }
 
443
                        else if (argv[index][0] == 'b') /* broadband */
 
444
                        {
 
445
                                settings->performance_flags = PERF_DISABLE_WALLPAPER;
 
446
                                settings->connection_type = CONNECTION_TYPE_BROADBAND_HIGH;
 
447
                        }
 
448
                        else if (argv[index][0] == 'l') /* lan */
 
449
                        {
 
450
                                settings->performance_flags = PERF_FLAG_NONE;
 
451
                                settings->connection_type = CONNECTION_TYPE_LAN;
 
452
                        }
 
453
                        else
 
454
                        {
 
455
                                settings->performance_flags = strtol(argv[index], 0, 16);
 
456
                        }
 
457
                }
 
458
                else if (strcmp("-X", argv[index]) == 0)
 
459
                {
 
460
                        index++;
 
461
 
 
462
                        if (index == argc)
 
463
                        {
 
464
                                printf("missing parent window XID\n");
 
465
                                return FREERDP_ARGS_PARSE_FAILURE;
 
466
                        }
 
467
 
 
468
                        settings->parent_window_xid = strtoul(argv[index], NULL, 16);
 
469
 
 
470
                        if (settings->parent_window_xid == 0)
 
471
                        {
 
472
                                printf("invalid parent window XID\n");
 
473
                                return FREERDP_ARGS_PARSE_FAILURE;
 
474
                        }
 
475
                }
 
476
                else if (strcmp("--no-rdp", argv[index]) == 0)
 
477
                {
 
478
                        settings->rdp_security = false;
 
479
                }
 
480
                else if (strcmp("--no-tls", argv[index]) == 0)
 
481
                {
 
482
                        settings->tls_security = false;
 
483
                }
 
484
                else if (strcmp("--no-nla", argv[index]) == 0)
 
485
                {
 
486
                        settings->nla_security = false;
 
487
                }
 
488
                else if (strcmp("--sec", argv[index]) == 0)
 
489
                {
 
490
                        index++;
 
491
                        if (index == argc)
 
492
                        {
 
493
                                printf("missing protocol security\n");
 
494
                                return FREERDP_ARGS_PARSE_FAILURE;
 
495
                        }
 
496
                        if (strncmp("rdp", argv[index], 1) == 0) /* Standard RDP */
 
497
                        {
 
498
                                settings->rdp_security = true;
 
499
                                settings->tls_security = false;
 
500
                                settings->nla_security = false;
 
501
                                settings->encryption = true;
 
502
                                settings->encryption_method = ENCRYPTION_METHOD_40BIT | ENCRYPTION_METHOD_128BIT | ENCRYPTION_METHOD_FIPS;
 
503
                                settings->encryption_level = ENCRYPTION_LEVEL_CLIENT_COMPATIBLE;
 
504
                        }
 
505
                        else if (strncmp("tls", argv[index], 1) == 0) /* TLS */
 
506
                        {
 
507
                                settings->rdp_security = false;
 
508
                                settings->tls_security = true;
 
509
                                settings->nla_security = false;
 
510
                        }
 
511
                        else if (strncmp("nla", argv[index], 1) == 0) /* NLA */
 
512
                        {
 
513
                                settings->rdp_security = false;
 
514
                                settings->tls_security = false;
 
515
                                settings->nla_security = true;
 
516
                        }
 
517
                        else
 
518
                        {
 
519
                                printf("unknown protocol security\n");
 
520
                                return FREERDP_ARGS_PARSE_FAILURE;
 
521
                        }
 
522
                }
 
523
                else if (strcmp("--plugin", argv[index]) == 0)
 
524
                {
 
525
                        index++;
 
526
                        t = index;
 
527
                        if (index == argc)
 
528
                        {
 
529
                                printf("missing plugin name\n");
 
530
                                return FREERDP_ARGS_PARSE_FAILURE;
 
531
                        }
 
532
                        plugin_data = NULL;
 
533
                        if (index < argc - 1 && strcmp("--data", argv[index + 1]) == 0)
 
534
                        {
 
535
                                index += 2;
 
536
                                i = 0;
 
537
                                while (index < argc && strcmp("--", argv[index]) != 0)
 
538
                                {
 
539
                                        plugin_data = (RDP_PLUGIN_DATA*)xrealloc(plugin_data, sizeof(RDP_PLUGIN_DATA) * (i + 2));
 
540
                                        plugin_data[i].size = sizeof(RDP_PLUGIN_DATA);
 
541
                                        plugin_data[i].data[0] = NULL;
 
542
                                        plugin_data[i].data[1] = NULL;
 
543
                                        plugin_data[i].data[2] = NULL;
 
544
                                        plugin_data[i].data[3] = NULL;
 
545
                                        plugin_data[i + 1].size = 0;
 
546
                                        for (j = 0, p = argv[index]; j < 4 && p != NULL; j++)
 
547
                                        {
 
548
                                                if (*p == '\'')
 
549
                                                {
 
550
                                                        plugin_data[i].data[j] = p + 1;
 
551
                                                        p = strchr(p + 1, '\'');
 
552
                                                        if (p)
 
553
                                                                *p++ = 0;
 
554
                                                }
 
555
                                                else
 
556
                                                        plugin_data[i].data[j] = p;
 
557
 
 
558
                                                p = strchr(p, ':');
 
559
                                                if (p != NULL)
 
560
                                                        *p++ = 0;
 
561
                                        }
 
562
                                        index++;
 
563
                                        i++;
 
564
                                }
 
565
                        }
 
566
 
 
567
                        if (plugin_callback != NULL)
 
568
                        {
 
569
                                if (!plugin_callback(settings, argv[t], plugin_data, plugin_user_data))
 
570
                                        return FREERDP_ARGS_PARSE_FAILURE;
 
571
                        }
 
572
                }
 
573
                else if (strcmp("--ext", argv[index]) == 0)
 
574
                {
 
575
                        index++;
 
576
                        if (index == argc)
 
577
                        {
 
578
                                printf("missing extension name\n");
 
579
                                return FREERDP_ARGS_PARSE_FAILURE;
 
580
                        }
 
581
                        if (num_extensions >= sizeof(settings->extensions) / sizeof(struct rdp_ext_set))
 
582
                        {
 
583
                                printf("maximum extensions reached\n");
 
584
                                return FREERDP_ARGS_PARSE_FAILURE;
 
585
                        }
 
586
                        snprintf(settings->extensions[num_extensions].name,
 
587
                                sizeof(settings->extensions[num_extensions].name),
 
588
                                "%s", argv[index]);
 
589
                        settings->extensions[num_extensions].data = NULL;
 
590
                        if (index < argc - 1 && strcmp("--data", argv[index + 1]) == 0)
 
591
                        {
 
592
                                index += 2;
 
593
                                settings->extensions[num_extensions].data = argv[index];
 
594
                                i = 0;
 
595
                                while (index < argc && strcmp("--", argv[index]) != 0)
 
596
                                {
 
597
                                        index++;
 
598
                                        i++;
 
599
                                }
 
600
                        }
 
601
                        num_extensions++;
 
602
                }
 
603
                else if (strcmp("--version", argv[index]) == 0)
 
604
                {
 
605
                        printf("This is FreeRDP version %s\n", FREERDP_VERSION_FULL);
 
606
                        return FREERDP_ARGS_PARSE_VERSION;
 
607
                }
 
608
                else if (argv[index][0] != '-')
 
609
                {
 
610
                        if (argv[index][0] == '[' && (p = strchr(argv[index], ']'))
 
611
                                && (p[1] == 0 || (p[1] == ':' && !strchr(p + 2, ':'))))
 
612
                        {
 
613
                                /* Either "[...]" or "[...]:..." with at most one : after the brackets */
 
614
                                settings->hostname = xstrdup(argv[index] + 1);
 
615
                                if ((p = strchr((char*)settings->hostname, ']')))
 
616
                                {
 
617
                                        *p = 0;
 
618
                                        if (p[1] == ':')
 
619
                                                settings->port = atoi(p + 2);
 
620
                                }
 
621
                        }
 
622
                        else
 
623
                        {
 
624
                                /* Port number is cut off and used if exactly one : in the string */
 
625
                                settings->hostname = xstrdup(argv[index]);
 
626
                                if ((p = strchr((char*)settings->hostname, ':')) && !strchr(p + 1, ':'))
 
627
                                {
 
628
                                        *p = 0;
 
629
                                        settings->port = atoi(p + 1);
 
630
                                }
 
631
                        }
 
632
                        /* server is the last argument for the current session. arguments
 
633
                           followed will be parsed for the next session. */
 
634
                        index++;
 
635
 
 
636
                        if (settings->smooth_fonts)
 
637
                                settings->performance_flags |= PERF_ENABLE_FONT_SMOOTHING;
 
638
 
 
639
                        if (settings->desktop_composition)
 
640
                                settings->performance_flags |= PERF_ENABLE_DESKTOP_COMPOSITION;
 
641
 
 
642
                        if (settings->disable_wallpaper)
 
643
                                settings->performance_flags |= PERF_DISABLE_WALLPAPER;
 
644
 
 
645
                        if (settings->disable_full_window_drag)
 
646
                                settings->performance_flags |= PERF_DISABLE_FULLWINDOWDRAG;
 
647
 
 
648
                        if (settings->disable_menu_animations)
 
649
                                settings->performance_flags |= PERF_DISABLE_MENUANIMATIONS;
 
650
 
 
651
                        if (settings->disable_theming)
 
652
                                settings->performance_flags |= PERF_DISABLE_THEMING;
 
653
 
 
654
                        return index;
 
655
                }
 
656
                else
 
657
                {
 
658
                        if (ui_callback != NULL)
 
659
                        {
 
660
                                t = ui_callback(settings, argv[index], (index + 1 < argc && argv[index + 1][0] != '-' ?
 
661
                                        argv[index + 1] : NULL), ui_user_data);
 
662
                                if (t == 0)
 
663
                                {
 
664
                                        printf("invalid option: %s\n", argv[index]);
 
665
                                        return FREERDP_ARGS_PARSE_FAILURE;
 
666
                                }
 
667
                                index += t - 1;
 
668
                        }
 
669
                }
 
670
                index++;
 
671
        }
 
672
        printf("missing server name\n");
 
673
        return FREERDP_ARGS_PARSE_FAILURE;
 
674
}