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

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

sourceforge.net/trunk/rdesktop/rdesktop.c revision 968 by astrand, Thu Aug 4 11:19:06 2005 UTC sourceforge.net/branches/seamlessrdp-branch/rdesktop/rdesktop.c revision 1089 by astrand, Fri Mar 10 08:50:43 2006 UTC
# Line 27  Line 27 
27  #include <sys/time.h>           /* gettimeofday */  #include <sys/time.h>           /* gettimeofday */
28  #include <sys/times.h>          /* times */  #include <sys/times.h>          /* times */
29  #include <ctype.h>              /* toupper */  #include <ctype.h>              /* toupper */
 #include <limits.h>             /* PATH_MAX */  
30  #include <errno.h>  #include <errno.h>
31  #include "rdesktop.h"  #include "rdesktop.h"
32    
# Line 51  Line 50 
50  char g_title[64] = "";  char g_title[64] = "";
51  char g_username[64];  char g_username[64];
52  char g_hostname[16];  char g_hostname[16];
53  char keymapname[PATH_MAX] = "en-us";  char g_keymapname[PATH_MAX] = "";
54  int g_keylayout = 0x409;        /* Defaults to US keyboard layout */  unsigned int g_keylayout = 0x409;       /* Defaults to US keyboard layout */
55  int g_keyboard_type = 0x4;      /* Defaults to US keyboard layout */  int g_keyboard_type = 0x4;      /* Defaults to US keyboard layout */
56  int g_keyboard_subtype = 0x0;   /* Defaults to US keyboard layout */  int g_keyboard_subtype = 0x0;   /* Defaults to US keyboard layout */
57  int g_keyboard_functionkeys = 0xc;      /* Defaults to US keyboard layout */  int g_keyboard_functionkeys = 0xc;      /* Defaults to US keyboard layout */
# Line 70  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 = 8;
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 87  BOOL g_hide_decorations = False; Line 86  BOOL g_hide_decorations = False;
86  BOOL g_use_rdp5 = True;  BOOL g_use_rdp5 = True;
87  BOOL g_console_session = False;  BOOL g_console_session = False;
88  BOOL g_numlock_sync = False;  BOOL g_numlock_sync = False;
89    BOOL lspci_enabled = False;
90  BOOL g_owncolmap = False;  BOOL g_owncolmap = False;
91  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
92    BOOL g_seamless_rdp = False;
93  uint32 g_embed_wnd;  uint32 g_embed_wnd;
94  uint32 g_rdp5_performanceflags =  uint32 g_rdp5_performanceflags =
95          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
96    /* Session Directory redirection */
97    BOOL g_redirect = False;
98    char g_redirect_server[64];
99    char g_redirect_domain[16];
100    char g_redirect_password[64];
101    char g_redirect_username[64];
102    char g_redirect_cookie[128];
103    uint32 g_redirect_flags = 0;
104    
105  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
106  BOOL g_rdpsnd = False;  BOOL g_rdpsnd = False;
# Line 138  usage(char *program) Line 147  usage(char *program)
147  #ifdef HAVE_ICONV  #ifdef HAVE_ICONV
148          fprintf(stderr, "   -L: local codepage\n");          fprintf(stderr, "   -L: local codepage\n");
149  #endif  #endif
150            fprintf(stderr, "   -A: enable SeamlessRDP mode\n");
151          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
152          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
153          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
# Line 275  print_disconnect_reason(uint16 reason) Line 285  print_disconnect_reason(uint16 reason)
285          fprintf(stderr, "disconnect: %s.\n", text);          fprintf(stderr, "disconnect: %s.\n", text);
286  }  }
287    
288    static void
289    rdesktop_reset_state(void)
290    {
291            rdp_reset_state();
292    }
293    
294  static BOOL  static BOOL
295  read_password(char *password, int size)  read_password(char *password, int size)
296  {  {
# Line 367  main(int argc, char *argv[]) Line 383  main(int argc, char *argv[])
383          char fullhostname[64];          char fullhostname[64];
384          char domain[16];          char domain[16];
385          char password[64];          char password[64];
386          char shell[128];          char shell[256];
387          char directory[32];          char directory[256];
388          BOOL prompt_password, deactivated;          BOOL prompt_password, deactivated;
389          struct passwd *pw;          struct passwd *pw;
390          uint32 flags, ext_disc_reason = 0;          uint32 flags, ext_disc_reason = 0;
391          char *p;          char *p;
392          int c;          int c;
393          char *locale;          char *locale = NULL;
394          int username_option = 0;          int username_option = 0;
395            BOOL geometry_option = False;
396            int run_count = 0;      /* Session Directory support */
397            BOOL continue_connect = True;   /* Session Directory support */
398    
399    #ifdef HAVE_LOCALE_H
400          /* Set locale according to environment */          /* Set locale according to environment */
401          locale = setlocale(LC_ALL, "");          locale = setlocale(LC_ALL, "");
402          if (locale)          if (locale)
403          {          {
404                  xkeymap_from_locale(locale);                  locale = xstrdup(locale);
405          }          }
406    
407    #endif
408          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
409          prompt_password = False;          prompt_password = False;
410          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
# Line 398  main(int argc, char *argv[]) Line 419  main(int argc, char *argv[])
419  #endif  #endif
420    
421          while ((c = getopt(argc, argv,          while ((c = getopt(argc, argv,
422                             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)
423          {          {
424                  switch (c)                  switch (c)
425                  {                  {
# Line 416  main(int argc, char *argv[]) Line 437  main(int argc, char *argv[])
437                                  break;                                  break;
438  #endif  #endif
439    
440                            case 'A':
441                                    g_seamless_rdp = True;
442                                    break;
443    
444                          case 'u':                          case 'u':
445                                  STRNCPY(g_username, optarg, sizeof(g_username));                                  STRNCPY(g_username, optarg, sizeof(g_username));
446                                  username_option = 1;                                  username_option = 1;
# Line 462  main(int argc, char *argv[]) Line 487  main(int argc, char *argv[])
487                                  break;                                  break;
488    
489                          case 'k':                          case 'k':
490                                  STRNCPY(keymapname, optarg, sizeof(keymapname));                                  STRNCPY(g_keymapname, optarg, sizeof(g_keymapname));
491                                  break;                                  break;
492    
493                          case 'g':                          case 'g':
494                                    geometry_option = True;
495                                  g_fullscreen = False;                                  g_fullscreen = False;
496                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
497                                  {                                  {
# Line 573  main(int argc, char *argv[]) Line 599  main(int argc, char *argv[])
599                                  break;                                  break;
600    
601                          case 'a':                          case 'a':
602                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_depth = strtol(optarg, NULL, 10);
603                                  if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15                                  if (g_server_depth != 8 &&
604                                      && g_server_bpp != 24)                                      g_server_depth != 16 &&
605                                        g_server_depth != 15 && g_server_depth != 24)
606                                  {                                  {
607                                          error("invalid server bpp\n");                                          error("Invalid server colour depth.\n");
608                                          return 1;                                          return 1;
609                                  }                                  }
610                                  break;                                  break;
# Line 588  main(int argc, char *argv[]) Line 615  main(int argc, char *argv[])
615                                  break;                                  break;
616    
617                          case 'x':                          case 'x':
618                                  if (strncmp("modem", optarg, 1) == 0)                                  if (str_startswith(optarg, "m"))        /* modem */
619                                  {                                  {
620                                          g_rdp5_performanceflags =                                          g_rdp5_performanceflags =
621                                                  RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |                                                  RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
622                                                  RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;                                                  RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
623                                  }                                  }
624                                  else if (strncmp("broadband", optarg, 1) == 0)                                  else if (str_startswith(optarg, "b"))   /* broadband */
625                                  {                                  {
626                                          g_rdp5_performanceflags = RDP5_NO_WALLPAPER;                                          g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
627                                  }                                  }
628                                  else if (strncmp("lan", optarg, 1) == 0)                                  else if (str_startswith(optarg, "l"))   /* lan */
629                                  {                                  {
630                                          g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;                                          g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
631                                  }                                  }
# Line 614  main(int argc, char *argv[]) Line 641  main(int argc, char *argv[])
641    
642                          case 'r':                          case 'r':
643    
644                                  if (strncmp("sound", optarg, 5) == 0)                                  if (str_startswith(optarg, "sound"))
645                                  {                                  {
646                                          optarg += 5;                                          optarg += 5;
647    
# Line 623  main(int argc, char *argv[]) Line 650  main(int argc, char *argv[])
650                                                  *optarg++;                                                  *optarg++;
651                                                  while ((p = next_arg(optarg, ',')))                                                  while ((p = next_arg(optarg, ',')))
652                                                  {                                                  {
653                                                          if (strncmp("remote", optarg, 6) == 0)                                                          if (str_startswith(optarg, "remote"))
654                                                                  flags |= RDP_LOGON_LEAVE_AUDIO;                                                                  flags |= RDP_LOGON_LEAVE_AUDIO;
655    
656                                                          if (strncmp("local", optarg, 5) == 0)                                                          if (str_startswith(optarg, "local"))
657  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
658                                                                  g_rdpsnd = True;                                                                  g_rdpsnd = True;
659  #else  #else
660                                                                  warning("Not compiled with sound support\n");                                                                  warning("Not compiled with sound support\n");
661  #endif  #endif
662    
663                                                          if (strncmp("off", optarg, 3) == 0)                                                          if (str_startswith(optarg, "off"))
664  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
665                                                                  g_rdpsnd = False;                                                                  g_rdpsnd = False;
666  #else  #else
# Line 652  main(int argc, char *argv[]) Line 679  main(int argc, char *argv[])
679  #endif  #endif
680                                          }                                          }
681                                  }                                  }
682                                  else if (strncmp("disk", optarg, 4) == 0)                                  else if (str_startswith(optarg, "disk"))
683                                  {                                  {
684                                          /* -r disk:h:=/mnt/floppy */                                          /* -r disk:h:=/mnt/floppy */
685                                          disk_enum_devices(&g_num_devices, optarg + 4);                                          disk_enum_devices(&g_num_devices, optarg + 4);
686                                  }                                  }
687                                  else if (strncmp("comport", optarg, 7) == 0)                                  else if (str_startswith(optarg, "comport"))
688                                  {                                  {
689                                          serial_enum_devices(&g_num_devices, optarg + 7);                                          serial_enum_devices(&g_num_devices, optarg + 7);
690                                  }                                  }
691                                  else if (strncmp("lptport", optarg, 7) == 0)                                  else if (str_startswith(optarg, "lspci"))
692                                    {
693                                            lspci_enabled = True;
694                                    }
695                                    else if (str_startswith(optarg, "lptport"))
696                                  {                                  {
697                                          parallel_enum_devices(&g_num_devices, optarg + 7);                                          parallel_enum_devices(&g_num_devices, optarg + 7);
698                                  }                                  }
699                                  else if (strncmp("printer", optarg, 7) == 0)                                  else if (str_startswith(optarg, "printer"))
700                                  {                                  {
701                                          printer_enum_devices(&g_num_devices, optarg + 7);                                          printer_enum_devices(&g_num_devices, optarg + 7);
702                                  }                                  }
703                                  else if (strncmp("clientname", optarg, 7) == 0)                                  else if (str_startswith(optarg, "clientname"))
704                                  {                                  {
705                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
706                                          strcpy(g_rdpdr_clientname, optarg + 11);                                          strcpy(g_rdpdr_clientname, optarg + 11);
# Line 709  main(int argc, char *argv[]) Line 740  main(int argc, char *argv[])
740          STRNCPY(server, argv[optind], sizeof(server));          STRNCPY(server, argv[optind], sizeof(server));
741          parse_server_and_port(server);          parse_server_and_port(server);
742    
743            if (g_seamless_rdp)
744            {
745                    if (g_win_button_size)
746                    {
747                            error("You cannot use -S and -A at the same time\n");
748                            return 1;
749                    }
750                    g_rdp5_performanceflags &= ~RDP5_NO_FULLWINDOWDRAG;
751                    if (geometry_option)
752                    {
753                            error("You cannot use -g and -A at the same time\n");
754                            return 1;
755                    }
756                    if (g_fullscreen)
757                    {
758                            error("You cannot use -f and -A at the same time\n");
759                            return 1;
760                    }
761                    if (g_hide_decorations)
762                    {
763                            error("You cannot use -D and -A at the same time\n");
764                            return 1;
765                    }
766                    if (g_embed_wnd)
767                    {
768                            error("You cannot use -X and -A at the same time\n");
769                            return 1;
770                    }
771                    if (!g_use_rdp5)
772                    {
773                            error("You cannot use -4 and -A at the same time\n");
774                            return 1;
775                    }
776                    g_width = -100;
777                    g_grab_keyboard = False;
778            }
779    
780          if (!username_option)          if (!username_option)
781          {          {
782                  pw = getpwuid(getuid());                  pw = getpwuid(getuid());
# Line 750  main(int argc, char *argv[]) Line 818  main(int argc, char *argv[])
818                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
819          }          }
820    
821            if (g_keymapname[0] == 0)
822            {
823                    if (locale && xkeymap_from_locale(locale))
824                    {
825                            fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname);
826                    }
827                    else
828                    {
829                            STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname));
830                    }
831            }
832            if (locale)
833                    xfree(locale);
834    
835    
836          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
837                  flags |= RDP_LOGON_AUTO;                  flags |= RDP_LOGON_AUTO;
838    
# Line 771  main(int argc, char *argv[]) Line 854  main(int argc, char *argv[])
854          if (g_rdpsnd)          if (g_rdpsnd)
855                  rdpsnd_init();                  rdpsnd_init();
856  #endif  #endif
857    
858            if (lspci_enabled)
859                    lspci_init();
860    
861          rdpdr_init();          rdpdr_init();
862    
863          if (!rdp_connect(server, flags, domain, password, shell, directory))          while (run_count < 2 && continue_connect)       /* add support for Session Directory; only reconnect once */
864                  return 1;          {
865                    if (run_count == 0)
866                    {
867                            if (!rdp_connect(server, flags, domain, password, shell, directory))
868                                    return 1;
869                    }
870                    else if (!rdp_reconnect
871                             (server, flags, domain, password, shell, directory, g_redirect_cookie))
872                            return 1;
873    
874          /* By setting encryption to False here, we have an encrypted login                  /* By setting encryption to False here, we have an encrypted login
875             packet but unencrypted transfer of other packets */                     packet but unencrypted transfer of other packets */
876          if (!packet_encryption)                  if (!packet_encryption)
877                  g_encryption = False;                          g_encryption = False;
878    
879    
880          DEBUG(("Connection successful.\n"));                  DEBUG(("Connection successful.\n"));
881          memset(password, 0, sizeof(password));                  memset(password, 0, sizeof(password));
882    
883          if (ui_create_window())                  if (run_count == 0)
884          {                          if (!ui_create_window())
885                  rdp_main_loop(&deactivated, &ext_disc_reason);                                  continue_connect = False;
886                  ui_destroy_window();  
887                    if (continue_connect)
888                            rdp_main_loop(&deactivated, &ext_disc_reason);
889    
890                    DEBUG(("Disconnecting...\n"));
891                    rdp_disconnect();
892    
893                    if ((g_redirect == True) && (run_count == 0))   /* Support for Session Directory */
894                    {
895                            /* reset state of major globals */
896                            rdesktop_reset_state();
897    
898                            STRNCPY(domain, g_redirect_domain, sizeof(domain));
899                            STRNCPY(g_username, g_redirect_username, sizeof(g_username));
900                            STRNCPY(password, g_redirect_password, sizeof(password));
901                            STRNCPY(server, g_redirect_server, sizeof(server));
902                            flags |= RDP_LOGON_AUTO;
903    
904                            g_redirect = False;
905                    }
906                    else
907                    {
908                            continue_connect = False;
909                            ui_destroy_window();
910                            break;
911                    }
912    
913                    run_count++;
914          }          }
915    
         DEBUG(("Disconnecting...\n"));  
         rdp_disconnect();  
916          cache_save_state();          cache_save_state();
917          ui_deinit();          ui_deinit();
918    
# Line 919  xmalloc(int size) Line 1039  xmalloc(int size)
1039          return mem;          return mem;
1040  }  }
1041    
1042    /* strdup */
1043    char *
1044    xstrdup(const char *s)
1045    {
1046            char *mem = strdup(s);
1047            if (mem == NULL)
1048            {
1049                    perror("strdup");
1050                    exit(1);
1051            }
1052            return mem;
1053    }
1054    
1055  /* realloc; exit if out of memory */  /* realloc; exit if out of memory */
1056  void *  void *
1057  xrealloc(void *oldmem, int size)  xrealloc(void *oldmem, int size)
# Line 1092  toupper_str(char *p) Line 1225  toupper_str(char *p)
1225  }  }
1226    
1227    
1228    BOOL
1229    str_startswith(const char *s, const char *prefix)
1230    {
1231            return (strncmp(s, prefix, strlen(prefix)) == 0);
1232    }
1233    
1234    
1235    /* Split input into lines, and call linehandler for each
1236       line. Incomplete lines are saved in the rest variable, which should
1237       initially point to NULL. When linehandler returns False, stop and
1238       return False. Otherwise, return True.  */
1239    BOOL
1240    str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data)
1241    {
1242            char *buf, *p;
1243            char *oldrest;
1244            size_t inputlen;
1245            size_t buflen;
1246            size_t restlen = 0;
1247            BOOL ret = True;
1248    
1249            /* Copy data to buffer */
1250            inputlen = strlen(input);
1251            if (*rest)
1252                    restlen = strlen(*rest);
1253            buflen = restlen + inputlen + 1;
1254            buf = (char *) xmalloc(buflen);
1255            buf[0] = '\0';
1256            if (*rest)
1257                    STRNCPY(buf, *rest, buflen);
1258            strncat(buf, input, inputlen);
1259            p = buf;
1260    
1261            while (1)
1262            {
1263                    char *newline = strchr(p, '\n');
1264                    if (newline)
1265                    {
1266                            *newline = '\0';
1267                            if (!linehandler(p, data))
1268                            {
1269                                    p = newline + 1;
1270                                    ret = False;
1271                                    break;
1272                            }
1273                            p = newline + 1;
1274                    }
1275                    else
1276                    {
1277                            break;
1278    
1279                    }
1280            }
1281    
1282            /* Save in rest */
1283            oldrest = *rest;
1284            restlen = buf + buflen - p;
1285            *rest = (char *) xmalloc(restlen);
1286            STRNCPY((*rest), p, restlen);
1287            xfree(oldrest);
1288    
1289            xfree(buf);
1290            return ret;
1291    }
1292    
1293    /* Execute the program specified by argv. For each line in
1294       stdout/stderr output, call linehandler. Returns false on failure. */
1295    BOOL
1296    subprocess(char *const argv[], str_handle_lines_t linehandler, void *data)
1297    {
1298            pid_t child;
1299            int fd[2];
1300            int n = 1;
1301            char output[256];
1302            char *rest = NULL;
1303    
1304            if (pipe(fd) < 0)
1305            {
1306                    perror("pipe");
1307                    return False;
1308            }
1309    
1310            if ((child = fork()) < 0)
1311            {
1312                    perror("fork");
1313                    return False;
1314            }
1315    
1316            /* Child */
1317            if (child == 0)
1318            {
1319                    /* Close read end */
1320                    close(fd[0]);
1321    
1322                    /* Redirect stdout and stderr to pipe */
1323                    dup2(fd[1], 1);
1324                    dup2(fd[1], 2);
1325    
1326                    /* Execute */
1327                    execvp(argv[0], argv);
1328                    perror("Error executing child");
1329                    _exit(128);
1330            }
1331    
1332            /* Parent. Close write end. */
1333            close(fd[1]);
1334            while (n > 0)
1335            {
1336                    n = read(fd[0], output, 255);
1337                    output[n] = '\0';
1338                    str_handle_lines(output, &rest, linehandler, data);
1339            }
1340            xfree(rest);
1341    
1342            return True;
1343    }
1344    
1345    
1346  /* not all clibs got ltoa */  /* not all clibs got ltoa */
1347  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1348    

Legend:
Removed from v.968  
changed lines
  Added in v.1089

  ViewVC Help
Powered by ViewVC 1.1.26