/[rdesktop]/jpeg/rdesktop/trunk/rdesktop.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /jpeg/rdesktop/trunk/rdesktop.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1035 by astrand, Fri Dec 30 20:32:06 2005 UTC revision 1255 by stargo, Sun Sep 17 11:04:50 2006 UTC
# Line 69  int g_pos = 0;                 /* 0 position unspecifi Line 69  int g_pos = 0;                 /* 0 position unspecifi
69                                     2 xpos neg,                                     2 xpos neg,
70                                     4 ypos neg  */                                     4 ypos neg  */
71  extern int g_tcp_port_rdp;  extern int g_tcp_port_rdp;
72  int g_server_bpp = 8;  int g_server_depth = -1;
73  int g_win_button_size = 0;      /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
74  BOOL g_bitmap_compression = True;  BOOL g_bitmap_compression = True;
75  BOOL g_sendmotion = True;  BOOL g_sendmotion = True;
# Line 84  BOOL g_fullscreen = False; Line 84  BOOL g_fullscreen = False;
84  BOOL g_grab_keyboard = True;  BOOL g_grab_keyboard = True;
85  BOOL g_hide_decorations = False;  BOOL g_hide_decorations = False;
86  BOOL g_use_rdp5 = True;  BOOL g_use_rdp5 = True;
87    BOOL g_rdpclip = True;
88  BOOL g_console_session = False;  BOOL g_console_session = False;
89  BOOL g_numlock_sync = False;  BOOL g_numlock_sync = False;
90    BOOL lspci_enabled = False;
91  BOOL g_owncolmap = False;  BOOL g_owncolmap = False;
92  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
93    BOOL g_seamless_rdp = False;
94  uint32 g_embed_wnd;  uint32 g_embed_wnd;
95  uint32 g_rdp5_performanceflags =  uint32 g_rdp5_performanceflags =
96          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
# Line 145  usage(char *program) Line 148  usage(char *program)
148  #ifdef HAVE_ICONV  #ifdef HAVE_ICONV
149          fprintf(stderr, "   -L: local codepage\n");          fprintf(stderr, "   -L: local codepage\n");
150  #endif  #endif
151            fprintf(stderr, "   -A: enable SeamlessRDP mode\n");
152          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
153          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
154          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
# Line 175  usage(char *program) Line 179  usage(char *program)
179          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
180          fprintf(stderr,          fprintf(stderr,
181                  "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");                  "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
182          fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");  #ifdef WITH_RDPSND
183            fprintf(stderr,
184                    "         '-r sound:[local[:driver[:device]]|off|remote]': enable sound redirection\n");
185          fprintf(stderr, "                     remote would leave sound on server\n");          fprintf(stderr, "                     remote would leave sound on server\n");
186            fprintf(stderr, "                     available drivers for 'local':\n");
187            rdpsnd_show_help();
188    #endif
189            fprintf(stderr,
190                    "         '-r clipboard:[off|PRIMARYCLIPBOARD|CLIPBOARD]': enable clipboard\n");
191            fprintf(stderr, "                      redirection.\n");
192            fprintf(stderr,
193                    "                      'PRIMARYCLIPBOARD' looks at both PRIMARY and CLIPBOARD\n");
194            fprintf(stderr, "                      when sending data to server.\n");
195            fprintf(stderr, "                      'CLIPBOARD' looks at only CLIPBOARD.\n");
196          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
197          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
198          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          fprintf(stderr, "   -5: use RDP version 5 (default)\n");
# Line 380  main(int argc, char *argv[]) Line 396  main(int argc, char *argv[])
396          char fullhostname[64];          char fullhostname[64];
397          char domain[16];          char domain[16];
398          char password[64];          char password[64];
399          char shell[128];          char shell[256];
400          char directory[32];          char directory[256];
401          BOOL prompt_password, deactivated;          BOOL prompt_password, deactivated;
402          struct passwd *pw;          struct passwd *pw;
403          uint32 flags, ext_disc_reason = 0;          uint32 flags, ext_disc_reason = 0;
# Line 389  main(int argc, char *argv[]) Line 405  main(int argc, char *argv[])
405          int c;          int c;
406          char *locale = NULL;          char *locale = NULL;
407          int username_option = 0;          int username_option = 0;
408            BOOL geometry_option = False;
409          int run_count = 0;      /* Session Directory support */          int run_count = 0;      /* Session Directory support */
410          BOOL continue_connect = True;   /* Session Directory support */          BOOL continue_connect = True;   /* Session Directory support */
411    
# Line 415  main(int argc, char *argv[]) Line 432  main(int argc, char *argv[])
432  #endif  #endif
433    
434          while ((c = getopt(argc, argv,          while ((c = getopt(argc, argv,
435                             VNCOPT "u:L:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1)                             VNCOPT "Au:L:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1)
436          {          {
437                  switch (c)                  switch (c)
438                  {                  {
# Line 433  main(int argc, char *argv[]) Line 450  main(int argc, char *argv[])
450                                  break;                                  break;
451  #endif  #endif
452    
453                            case 'A':
454                                    g_seamless_rdp = True;
455                                    break;
456    
457                          case 'u':                          case 'u':
458                                  STRNCPY(g_username, optarg, sizeof(g_username));                                  STRNCPY(g_username, optarg, sizeof(g_username));
459                                  username_option = 1;                                  username_option = 1;
# Line 483  main(int argc, char *argv[]) Line 504  main(int argc, char *argv[])
504                                  break;                                  break;
505    
506                          case 'g':                          case 'g':
507                                    geometry_option = True;
508                                  g_fullscreen = False;                                  g_fullscreen = False;
509                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
510                                  {                                  {
# Line 590  main(int argc, char *argv[]) Line 612  main(int argc, char *argv[])
612                                  break;                                  break;
613    
614                          case 'a':                          case 'a':
615                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_depth = strtol(optarg, NULL, 10);
616                                  if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15                                  if (g_server_depth != 8 &&
617                                      && g_server_bpp != 24)                                      g_server_depth != 16 &&
618                                        g_server_depth != 15 && g_server_depth != 24)
619                                  {                                  {
620                                          error("invalid server bpp\n");                                          error("Invalid server colour depth.\n");
621                                          return 1;                                          return 1;
622                                  }                                  }
623                                  break;                                  break;
# Line 637  main(int argc, char *argv[]) Line 660  main(int argc, char *argv[])
660    
661                                          if (*optarg == ':')                                          if (*optarg == ':')
662                                          {                                          {
663                                                  *optarg++;                                                  optarg++;
664                                                  while ((p = next_arg(optarg, ',')))                                                  while ((p = next_arg(optarg, ',')))
665                                                  {                                                  {
666                                                          if (str_startswith(optarg, "remote"))                                                          if (str_startswith(optarg, "remote"))
# Line 645  main(int argc, char *argv[]) Line 668  main(int argc, char *argv[])
668    
669                                                          if (str_startswith(optarg, "local"))                                                          if (str_startswith(optarg, "local"))
670  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
671                                                            {
672                                                                    char *driver = NULL, *options =
673                                                                            NULL;
674    
675                                                                    if ((driver =
676                                                                         next_arg(optarg, ':')))
677                                                                    {
678                                                                            if (!strlen(driver))
679                                                                            {
680                                                                                    driver = NULL;
681                                                                            }
682                                                                            else if ((options =
683                                                                                      next_arg(driver,
684                                                                                               ':')))
685                                                                            {
686                                                                                    if (!strlen
687                                                                                        (options))
688                                                                                            options =
689                                                                                                    NULL;
690                                                                            }
691                                                                    }
692    
693                                                                  g_rdpsnd = True;                                                                  g_rdpsnd = True;
694                                                                    if (!rdpsnd_select_driver
695                                                                        (driver, options))
696                                                                    {
697                                                                            warning("Driver not available\n");
698                                                                    }
699                                                            }
700    
701  #else  #else
702                                                                  warning("Not compiled with sound support\n");                                                                  warning("Not compiled with sound support\n");
703  #endif  #endif
# Line 664  main(int argc, char *argv[]) Line 716  main(int argc, char *argv[])
716                                          {                                          {
717  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
718                                                  g_rdpsnd = True;                                                  g_rdpsnd = True;
719                                                    if (!rdpsnd_select_driver(NULL, NULL))
720                                                    {
721                                                            warning("No sound-driver available\n");
722                                                    }
723  #else  #else
724                                                  warning("Not compiled with sound support\n");                                                  warning("Not compiled with sound support\n");
725  #endif  #endif
# Line 678  main(int argc, char *argv[]) Line 734  main(int argc, char *argv[])
734                                  {                                  {
735                                          serial_enum_devices(&g_num_devices, optarg + 7);                                          serial_enum_devices(&g_num_devices, optarg + 7);
736                                  }                                  }
737                                    else if (str_startswith(optarg, "lspci"))
738                                    {
739                                            lspci_enabled = True;
740                                    }
741                                  else if (str_startswith(optarg, "lptport"))                                  else if (str_startswith(optarg, "lptport"))
742                                  {                                  {
743                                          parallel_enum_devices(&g_num_devices, optarg + 7);                                          parallel_enum_devices(&g_num_devices, optarg + 7);
# Line 691  main(int argc, char *argv[]) Line 751  main(int argc, char *argv[])
751                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
752                                          strcpy(g_rdpdr_clientname, optarg + 11);                                          strcpy(g_rdpdr_clientname, optarg + 11);
753                                  }                                  }
754                                    else if (str_startswith(optarg, "clipboard"))
755                                    {
756                                            optarg += 9;
757    
758                                            if (*optarg == ':')
759                                            {
760                                                    optarg++;
761    
762                                                    if (str_startswith(optarg, "off"))
763                                                            g_rdpclip = False;
764                                                    else
765                                                            cliprdr_set_mode(optarg);
766                                            }
767                                            else
768                                                    g_rdpclip = True;
769                                    }
770                                  else                                  else
771                                  {                                  {
772                                          warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");                                          warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound, clipboard\n");
773                                  }                                  }
774                                  break;                                  break;
775    
# Line 726  main(int argc, char *argv[]) Line 802  main(int argc, char *argv[])
802          STRNCPY(server, argv[optind], sizeof(server));          STRNCPY(server, argv[optind], sizeof(server));
803          parse_server_and_port(server);          parse_server_and_port(server);
804    
805            if (g_seamless_rdp)
806            {
807                    if (g_win_button_size)
808                    {
809                            error("You cannot use -S and -A at the same time\n");
810                            return 1;
811                    }
812                    g_rdp5_performanceflags &= ~RDP5_NO_FULLWINDOWDRAG;
813                    if (geometry_option)
814                    {
815                            error("You cannot use -g and -A at the same time\n");
816                            return 1;
817                    }
818                    if (g_fullscreen)
819                    {
820                            error("You cannot use -f and -A at the same time\n");
821                            return 1;
822                    }
823                    if (g_hide_decorations)
824                    {
825                            error("You cannot use -D and -A at the same time\n");
826                            return 1;
827                    }
828                    if (g_embed_wnd)
829                    {
830                            error("You cannot use -X and -A at the same time\n");
831                            return 1;
832                    }
833                    if (!g_use_rdp5)
834                    {
835                            error("You cannot use -4 and -A at the same time\n");
836                            return 1;
837                    }
838                    g_width = -100;
839                    g_grab_keyboard = False;
840            }
841    
842          if (!username_option)          if (!username_option)
843          {          {
844                  pw = getpwuid(getuid());                  pw = getpwuid(getuid());
# Line 803  main(int argc, char *argv[]) Line 916  main(int argc, char *argv[])
916          if (g_rdpsnd)          if (g_rdpsnd)
917                  rdpsnd_init();                  rdpsnd_init();
918  #endif  #endif
919    
920            if (lspci_enabled)
921                    lspci_init();
922    
923          rdpdr_init();          rdpdr_init();
924    
925          while (run_count < 2 && continue_connect)       /* add support for Session Directory; only reconnect once */          while (run_count < 2 && continue_connect)       /* add support for Session Directory; only reconnect once */
# Line 1132  next_arg(char *src, char needle) Line 1249  next_arg(char *src, char needle)
1249                          while (*(mvp + 1) != (char) 0x00)                          while (*(mvp + 1) != (char) 0x00)
1250                          {                          {
1251                                  *mvp = *(mvp + 1);                                  *mvp = *(mvp + 1);
1252                                  *mvp++;                                  mvp++;
1253                          }                          }
1254                          *mvp = (char) 0x00;                          *mvp = (char) 0x00;
1255                          p = nextval;                          p = nextval;
# Line 1177  str_startswith(const char *s, const char Line 1294  str_startswith(const char *s, const char
1294  }  }
1295    
1296    
1297    /* Split input into lines, and call linehandler for each
1298       line. Incomplete lines are saved in the rest variable, which should
1299       initially point to NULL. When linehandler returns False, stop and
1300       return False. Otherwise, return True.  */
1301    BOOL
1302    str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data)
1303    {
1304            char *buf, *p;
1305            char *oldrest;
1306            size_t inputlen;
1307            size_t buflen;
1308            size_t restlen = 0;
1309            BOOL ret = True;
1310    
1311            /* Copy data to buffer */
1312            inputlen = strlen(input);
1313            if (*rest)
1314                    restlen = strlen(*rest);
1315            buflen = restlen + inputlen + 1;
1316            buf = (char *) xmalloc(buflen);
1317            buf[0] = '\0';
1318            if (*rest)
1319                    STRNCPY(buf, *rest, buflen);
1320            strncat(buf, input, inputlen);
1321            p = buf;
1322    
1323            while (1)
1324            {
1325                    char *newline = strchr(p, '\n');
1326                    if (newline)
1327                    {
1328                            *newline = '\0';
1329                            if (!linehandler(p, data))
1330                            {
1331                                    p = newline + 1;
1332                                    ret = False;
1333                                    break;
1334                            }
1335                            p = newline + 1;
1336                    }
1337                    else
1338                    {
1339                            break;
1340    
1341                    }
1342            }
1343    
1344            /* Save in rest */
1345            oldrest = *rest;
1346            restlen = buf + buflen - p;
1347            *rest = (char *) xmalloc(restlen);
1348            STRNCPY((*rest), p, restlen);
1349            xfree(oldrest);
1350    
1351            xfree(buf);
1352            return ret;
1353    }
1354    
1355    /* Execute the program specified by argv. For each line in
1356       stdout/stderr output, call linehandler. Returns false on failure. */
1357    BOOL
1358    subprocess(char *const argv[], str_handle_lines_t linehandler, void *data)
1359    {
1360            pid_t child;
1361            int fd[2];
1362            int n = 1;
1363            char output[256];
1364            char *rest = NULL;
1365    
1366            if (pipe(fd) < 0)
1367            {
1368                    perror("pipe");
1369                    return False;
1370            }
1371    
1372            if ((child = fork()) < 0)
1373            {
1374                    perror("fork");
1375                    return False;
1376            }
1377    
1378            /* Child */
1379            if (child == 0)
1380            {
1381                    /* Close read end */
1382                    close(fd[0]);
1383    
1384                    /* Redirect stdout and stderr to pipe */
1385                    dup2(fd[1], 1);
1386                    dup2(fd[1], 2);
1387    
1388                    /* Execute */
1389                    execvp(argv[0], argv);
1390                    perror("Error executing child");
1391                    _exit(128);
1392            }
1393    
1394            /* Parent. Close write end. */
1395            close(fd[1]);
1396            while (n > 0)
1397            {
1398                    n = read(fd[0], output, 255);
1399                    output[n] = '\0';
1400                    str_handle_lines(output, &rest, linehandler, data);
1401            }
1402            xfree(rest);
1403    
1404            return True;
1405    }
1406    
1407    
1408  /* not all clibs got ltoa */  /* not all clibs got ltoa */
1409  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1410    

Legend:
Removed from v.1035  
changed lines
  Added in v.1255

  ViewVC Help
Powered by ViewVC 1.1.26