/[rdesktop]/sourceforge.net/trunk/rdesktop/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 /sourceforge.net/trunk/rdesktop/rdesktop.c

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

revision 1046 by forsberg, Fri Feb 24 08:21:31 2006 UTC revision 1226 by astrand, Wed Apr 12 06:47:24 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_depth = 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 177  usage(char *program) Line 181  usage(char *program)
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");          fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");
183          fprintf(stderr, "                     remote would leave sound on server\n");          fprintf(stderr, "                     remote would leave sound on server\n");
184            fprintf(stderr,
185                    "         '-r clipboard:[off|PRIMARYCLIPBOARD|CLIPBOARD]': enable clipboard\n");
186            fprintf(stderr, "                      redirection.\n");
187            fprintf(stderr,
188                    "                      'PRIMARYCLIPBOARD' looks at both PRIMARY and CLIPBOARD\n");
189            fprintf(stderr, "                      when sending data to server.\n");
190            fprintf(stderr, "                      'CLIPBOARD' looks at only CLIPBOARD.\n");
191          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
192          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
193          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          fprintf(stderr, "   -5: use RDP version 5 (default)\n");
# Line 381  main(int argc, char *argv[]) Line 392  main(int argc, char *argv[])
392          char domain[16];          char domain[16];
393          char password[64];          char password[64];
394          char shell[256];          char shell[256];
395          char directory[32];          char directory[256];
396          BOOL prompt_password, deactivated;          BOOL prompt_password, deactivated;
397          struct passwd *pw;          struct passwd *pw;
398          uint32 flags, ext_disc_reason = 0;          uint32 flags, ext_disc_reason = 0;
# Line 389  main(int argc, char *argv[]) Line 400  main(int argc, char *argv[])
400          int c;          int c;
401          char *locale = NULL;          char *locale = NULL;
402          int username_option = 0;          int username_option = 0;
403            BOOL geometry_option = False;
404          int run_count = 0;      /* Session Directory support */          int run_count = 0;      /* Session Directory support */
405          BOOL continue_connect = True;   /* Session Directory support */          BOOL continue_connect = True;   /* Session Directory support */
406    
# Line 415  main(int argc, char *argv[]) Line 427  main(int argc, char *argv[])
427  #endif  #endif
428    
429          while ((c = getopt(argc, argv,          while ((c = getopt(argc, argv,
430                             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)
431          {          {
432                  switch (c)                  switch (c)
433                  {                  {
# Line 433  main(int argc, char *argv[]) Line 445  main(int argc, char *argv[])
445                                  break;                                  break;
446  #endif  #endif
447    
448                            case 'A':
449                                    g_seamless_rdp = True;
450                                    break;
451    
452                          case 'u':                          case 'u':
453                                  STRNCPY(g_username, optarg, sizeof(g_username));                                  STRNCPY(g_username, optarg, sizeof(g_username));
454                                  username_option = 1;                                  username_option = 1;
# Line 483  main(int argc, char *argv[]) Line 499  main(int argc, char *argv[])
499                                  break;                                  break;
500    
501                          case 'g':                          case 'g':
502                                    geometry_option = True;
503                                  g_fullscreen = False;                                  g_fullscreen = False;
504                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
505                                  {                                  {
# Line 638  main(int argc, char *argv[]) Line 655  main(int argc, char *argv[])
655    
656                                          if (*optarg == ':')                                          if (*optarg == ':')
657                                          {                                          {
658                                                  *optarg++;                                                  optarg++;
659                                                  while ((p = next_arg(optarg, ',')))                                                  while ((p = next_arg(optarg, ',')))
660                                                  {                                                  {
661                                                          if (str_startswith(optarg, "remote"))                                                          if (str_startswith(optarg, "remote"))
# Line 679  main(int argc, char *argv[]) Line 696  main(int argc, char *argv[])
696                                  {                                  {
697                                          serial_enum_devices(&g_num_devices, optarg + 7);                                          serial_enum_devices(&g_num_devices, optarg + 7);
698                                  }                                  }
699                                    else if (str_startswith(optarg, "lspci"))
700                                    {
701                                            lspci_enabled = True;
702                                    }
703                                  else if (str_startswith(optarg, "lptport"))                                  else if (str_startswith(optarg, "lptport"))
704                                  {                                  {
705                                          parallel_enum_devices(&g_num_devices, optarg + 7);                                          parallel_enum_devices(&g_num_devices, optarg + 7);
# Line 692  main(int argc, char *argv[]) Line 713  main(int argc, char *argv[])
713                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
714                                          strcpy(g_rdpdr_clientname, optarg + 11);                                          strcpy(g_rdpdr_clientname, optarg + 11);
715                                  }                                  }
716                                    else if (str_startswith(optarg, "clipboard"))
717                                    {
718                                            optarg += 9;
719    
720                                            if (*optarg == ':')
721                                            {
722                                                    optarg++;
723    
724                                                    if (str_startswith(optarg, "off"))
725                                                            g_rdpclip = False;
726                                                    else
727                                                            cliprdr_set_mode(optarg);
728                                            }
729                                            else
730                                                    g_rdpclip = True;
731                                    }
732                                  else                                  else
733                                  {                                  {
734                                          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");
735                                  }                                  }
736                                  break;                                  break;
737    
# Line 727  main(int argc, char *argv[]) Line 764  main(int argc, char *argv[])
764          STRNCPY(server, argv[optind], sizeof(server));          STRNCPY(server, argv[optind], sizeof(server));
765          parse_server_and_port(server);          parse_server_and_port(server);
766    
767            if (g_seamless_rdp)
768            {
769                    if (g_win_button_size)
770                    {
771                            error("You cannot use -S and -A at the same time\n");
772                            return 1;
773                    }
774                    g_rdp5_performanceflags &= ~RDP5_NO_FULLWINDOWDRAG;
775                    if (geometry_option)
776                    {
777                            error("You cannot use -g and -A at the same time\n");
778                            return 1;
779                    }
780                    if (g_fullscreen)
781                    {
782                            error("You cannot use -f and -A at the same time\n");
783                            return 1;
784                    }
785                    if (g_hide_decorations)
786                    {
787                            error("You cannot use -D and -A at the same time\n");
788                            return 1;
789                    }
790                    if (g_embed_wnd)
791                    {
792                            error("You cannot use -X and -A at the same time\n");
793                            return 1;
794                    }
795                    if (!g_use_rdp5)
796                    {
797                            error("You cannot use -4 and -A at the same time\n");
798                            return 1;
799                    }
800                    g_width = -100;
801                    g_grab_keyboard = False;
802            }
803    
804          if (!username_option)          if (!username_option)
805          {          {
806                  pw = getpwuid(getuid());                  pw = getpwuid(getuid());
# Line 804  main(int argc, char *argv[]) Line 878  main(int argc, char *argv[])
878          if (g_rdpsnd)          if (g_rdpsnd)
879                  rdpsnd_init();                  rdpsnd_init();
880  #endif  #endif
881    
882            if (lspci_enabled)
883                    lspci_init();
884    
885          rdpdr_init();          rdpdr_init();
886    
887          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 1133  next_arg(char *src, char needle) Line 1211  next_arg(char *src, char needle)
1211                          while (*(mvp + 1) != (char) 0x00)                          while (*(mvp + 1) != (char) 0x00)
1212                          {                          {
1213                                  *mvp = *(mvp + 1);                                  *mvp = *(mvp + 1);
1214                                  *mvp++;                                  mvp++;
1215                          }                          }
1216                          *mvp = (char) 0x00;                          *mvp = (char) 0x00;
1217                          p = nextval;                          p = nextval;
# Line 1178  str_startswith(const char *s, const char Line 1256  str_startswith(const char *s, const char
1256  }  }
1257    
1258    
1259    /* Split input into lines, and call linehandler for each
1260       line. Incomplete lines are saved in the rest variable, which should
1261       initially point to NULL. When linehandler returns False, stop and
1262       return False. Otherwise, return True.  */
1263    BOOL
1264    str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data)
1265    {
1266            char *buf, *p;
1267            char *oldrest;
1268            size_t inputlen;
1269            size_t buflen;
1270            size_t restlen = 0;
1271            BOOL ret = True;
1272    
1273            /* Copy data to buffer */
1274            inputlen = strlen(input);
1275            if (*rest)
1276                    restlen = strlen(*rest);
1277            buflen = restlen + inputlen + 1;
1278            buf = (char *) xmalloc(buflen);
1279            buf[0] = '\0';
1280            if (*rest)
1281                    STRNCPY(buf, *rest, buflen);
1282            strncat(buf, input, inputlen);
1283            p = buf;
1284    
1285            while (1)
1286            {
1287                    char *newline = strchr(p, '\n');
1288                    if (newline)
1289                    {
1290                            *newline = '\0';
1291                            if (!linehandler(p, data))
1292                            {
1293                                    p = newline + 1;
1294                                    ret = False;
1295                                    break;
1296                            }
1297                            p = newline + 1;
1298                    }
1299                    else
1300                    {
1301                            break;
1302    
1303                    }
1304            }
1305    
1306            /* Save in rest */
1307            oldrest = *rest;
1308            restlen = buf + buflen - p;
1309            *rest = (char *) xmalloc(restlen);
1310            STRNCPY((*rest), p, restlen);
1311            xfree(oldrest);
1312    
1313            xfree(buf);
1314            return ret;
1315    }
1316    
1317    /* Execute the program specified by argv. For each line in
1318       stdout/stderr output, call linehandler. Returns false on failure. */
1319    BOOL
1320    subprocess(char *const argv[], str_handle_lines_t linehandler, void *data)
1321    {
1322            pid_t child;
1323            int fd[2];
1324            int n = 1;
1325            char output[256];
1326            char *rest = NULL;
1327    
1328            if (pipe(fd) < 0)
1329            {
1330                    perror("pipe");
1331                    return False;
1332            }
1333    
1334            if ((child = fork()) < 0)
1335            {
1336                    perror("fork");
1337                    return False;
1338            }
1339    
1340            /* Child */
1341            if (child == 0)
1342            {
1343                    /* Close read end */
1344                    close(fd[0]);
1345    
1346                    /* Redirect stdout and stderr to pipe */
1347                    dup2(fd[1], 1);
1348                    dup2(fd[1], 2);
1349    
1350                    /* Execute */
1351                    execvp(argv[0], argv);
1352                    perror("Error executing child");
1353                    _exit(128);
1354            }
1355    
1356            /* Parent. Close write end. */
1357            close(fd[1]);
1358            while (n > 0)
1359            {
1360                    n = read(fd[0], output, 255);
1361                    output[n] = '\0';
1362                    str_handle_lines(output, &rest, linehandler, data);
1363            }
1364            xfree(rest);
1365    
1366            return True;
1367    }
1368    
1369    
1370  /* not all clibs got ltoa */  /* not all clibs got ltoa */
1371  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1372    

Legend:
Removed from v.1046  
changed lines
  Added in v.1226

  ViewVC Help
Powered by ViewVC 1.1.26