/[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 1042 by astrand, Tue Jan 24 12:40:24 2006 UTC revision 1306 by astrand, Fri Oct 27 12:59:38 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 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            char *rdpsnd_optarg = NULL;
412    
413  #ifdef HAVE_LOCALE_H  #ifdef HAVE_LOCALE_H
414          /* Set locale according to environment */          /* Set locale according to environment */
# Line 415  main(int argc, char *argv[]) Line 433  main(int argc, char *argv[])
433  #endif  #endif
434    
435          while ((c = getopt(argc, argv,          while ((c = getopt(argc, argv,
436                             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)
437          {          {
438                  switch (c)                  switch (c)
439                  {                  {
# Line 433  main(int argc, char *argv[]) Line 451  main(int argc, char *argv[])
451                                  break;                                  break;
452  #endif  #endif
453    
454                            case 'A':
455                                    g_seamless_rdp = True;
456                                    break;
457    
458                          case 'u':                          case 'u':
459                                  STRNCPY(g_username, optarg, sizeof(g_username));                                  STRNCPY(g_username, optarg, sizeof(g_username));
460                                  username_option = 1;                                  username_option = 1;
# Line 483  main(int argc, char *argv[]) Line 505  main(int argc, char *argv[])
505                                  break;                                  break;
506    
507                          case 'g':                          case 'g':
508                                    geometry_option = True;
509                                  g_fullscreen = False;                                  g_fullscreen = False;
510                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
511                                  {                                  {
# Line 638  main(int argc, char *argv[]) Line 661  main(int argc, char *argv[])
661    
662                                          if (*optarg == ':')                                          if (*optarg == ':')
663                                          {                                          {
664                                                  *optarg++;                                                  optarg++;
665                                                  while ((p = next_arg(optarg, ',')))                                                  while ((p = next_arg(optarg, ',')))
666                                                  {                                                  {
667                                                          if (str_startswith(optarg, "remote"))                                                          if (str_startswith(optarg, "remote"))
# Line 646  main(int argc, char *argv[]) Line 669  main(int argc, char *argv[])
669    
670                                                          if (str_startswith(optarg, "local"))                                                          if (str_startswith(optarg, "local"))
671  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
672                                                            {
673                                                                    rdpsnd_optarg =
674                                                                            next_arg(optarg, ':');
675                                                                  g_rdpsnd = True;                                                                  g_rdpsnd = True;
676                                                            }
677    
678  #else  #else
679                                                                  warning("Not compiled with sound support\n");                                                                  warning("Not compiled with sound support\n");
680  #endif  #endif
# Line 679  main(int argc, char *argv[]) Line 707  main(int argc, char *argv[])
707                                  {                                  {
708                                          serial_enum_devices(&g_num_devices, optarg + 7);                                          serial_enum_devices(&g_num_devices, optarg + 7);
709                                  }                                  }
710                                    else if (str_startswith(optarg, "lspci"))
711                                    {
712                                            lspci_enabled = True;
713                                    }
714                                  else if (str_startswith(optarg, "lptport"))                                  else if (str_startswith(optarg, "lptport"))
715                                  {                                  {
716                                          parallel_enum_devices(&g_num_devices, optarg + 7);                                          parallel_enum_devices(&g_num_devices, optarg + 7);
# Line 692  main(int argc, char *argv[]) Line 724  main(int argc, char *argv[])
724                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
725                                          strcpy(g_rdpdr_clientname, optarg + 11);                                          strcpy(g_rdpdr_clientname, optarg + 11);
726                                  }                                  }
727                                    else if (str_startswith(optarg, "clipboard"))
728                                    {
729                                            optarg += 9;
730    
731                                            if (*optarg == ':')
732                                            {
733                                                    optarg++;
734    
735                                                    if (str_startswith(optarg, "off"))
736                                                            g_rdpclip = False;
737                                                    else
738                                                            cliprdr_set_mode(optarg);
739                                            }
740                                            else
741                                                    g_rdpclip = True;
742                                    }
743                                  else                                  else
744                                  {                                  {
745                                          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");
746                                  }                                  }
747                                  break;                                  break;
748    
# Line 727  main(int argc, char *argv[]) Line 775  main(int argc, char *argv[])
775          STRNCPY(server, argv[optind], sizeof(server));          STRNCPY(server, argv[optind], sizeof(server));
776          parse_server_and_port(server);          parse_server_and_port(server);
777    
778            if (g_seamless_rdp)
779            {
780                    if (g_win_button_size)
781                    {
782                            error("You cannot use -S and -A at the same time\n");
783                            return 1;
784                    }
785                    g_rdp5_performanceflags &= ~RDP5_NO_FULLWINDOWDRAG;
786                    if (geometry_option)
787                    {
788                            error("You cannot use -g and -A at the same time\n");
789                            return 1;
790                    }
791                    if (g_fullscreen)
792                    {
793                            error("You cannot use -f and -A at the same time\n");
794                            return 1;
795                    }
796                    if (g_hide_decorations)
797                    {
798                            error("You cannot use -D and -A at the same time\n");
799                            return 1;
800                    }
801                    if (g_embed_wnd)
802                    {
803                            error("You cannot use -X and -A at the same time\n");
804                            return 1;
805                    }
806                    if (!g_use_rdp5)
807                    {
808                            error("You cannot use -4 and -A at the same time\n");
809                            return 1;
810                    }
811                    g_width = -100;
812                    g_grab_keyboard = False;
813            }
814    
815          if (!username_option)          if (!username_option)
816          {          {
817                  pw = getpwuid(getuid());                  pw = getpwuid(getuid());
# Line 802  main(int argc, char *argv[]) Line 887  main(int argc, char *argv[])
887    
888  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
889          if (g_rdpsnd)          if (g_rdpsnd)
890                  rdpsnd_init();          {
891                    if (!rdpsnd_init(rdpsnd_optarg))
892                    {
893                            warning("Initializing sound-support failed!\n");
894                    }
895            }
896  #endif  #endif
897    
898            if (lspci_enabled)
899                    lspci_init();
900    
901          rdpdr_init();          rdpdr_init();
902    
903          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 985  xmalloc(int size) Line 1079  xmalloc(int size)
1079          return mem;          return mem;
1080  }  }
1081    
1082    /* Exit on NULL pointer. Use to verify result from XGetImage etc */
1083    void
1084    exit_if_null(void *ptr)
1085    {
1086            if (ptr == NULL)
1087            {
1088                    error("unexpected null pointer. Out of memory?\n");
1089                    exit(1);
1090            }
1091    }
1092    
1093  /* strdup */  /* strdup */
1094  char *  char *
1095  xstrdup(const char *s)  xstrdup(const char *s)
# Line 1133  next_arg(char *src, char needle) Line 1238  next_arg(char *src, char needle)
1238                          while (*(mvp + 1) != (char) 0x00)                          while (*(mvp + 1) != (char) 0x00)
1239                          {                          {
1240                                  *mvp = *(mvp + 1);                                  *mvp = *(mvp + 1);
1241                                  *mvp++;                                  mvp++;
1242                          }                          }
1243                          *mvp = (char) 0x00;                          *mvp = (char) 0x00;
1244                          p = nextval;                          p = nextval;
# Line 1178  str_startswith(const char *s, const char Line 1283  str_startswith(const char *s, const char
1283  }  }
1284    
1285    
1286    /* Split input into lines, and call linehandler for each
1287       line. Incomplete lines are saved in the rest variable, which should
1288       initially point to NULL. When linehandler returns False, stop and
1289       return False. Otherwise, return True.  */
1290    BOOL
1291    str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data)
1292    {
1293            char *buf, *p;
1294            char *oldrest;
1295            size_t inputlen;
1296            size_t buflen;
1297            size_t restlen = 0;
1298            BOOL ret = True;
1299    
1300            /* Copy data to buffer */
1301            inputlen = strlen(input);
1302            if (*rest)
1303                    restlen = strlen(*rest);
1304            buflen = restlen + inputlen + 1;
1305            buf = (char *) xmalloc(buflen);
1306            buf[0] = '\0';
1307            if (*rest)
1308                    STRNCPY(buf, *rest, buflen);
1309            strncat(buf, input, inputlen);
1310            p = buf;
1311    
1312            while (1)
1313            {
1314                    char *newline = strchr(p, '\n');
1315                    if (newline)
1316                    {
1317                            *newline = '\0';
1318                            if (!linehandler(p, data))
1319                            {
1320                                    p = newline + 1;
1321                                    ret = False;
1322                                    break;
1323                            }
1324                            p = newline + 1;
1325                    }
1326                    else
1327                    {
1328                            break;
1329    
1330                    }
1331            }
1332    
1333            /* Save in rest */
1334            oldrest = *rest;
1335            restlen = buf + buflen - p;
1336            *rest = (char *) xmalloc(restlen);
1337            STRNCPY((*rest), p, restlen);
1338            xfree(oldrest);
1339    
1340            xfree(buf);
1341            return ret;
1342    }
1343    
1344    /* Execute the program specified by argv. For each line in
1345       stdout/stderr output, call linehandler. Returns false on failure. */
1346    BOOL
1347    subprocess(char *const argv[], str_handle_lines_t linehandler, void *data)
1348    {
1349            pid_t child;
1350            int fd[2];
1351            int n = 1;
1352            char output[256];
1353            char *rest = NULL;
1354    
1355            if (pipe(fd) < 0)
1356            {
1357                    perror("pipe");
1358                    return False;
1359            }
1360    
1361            if ((child = fork()) < 0)
1362            {
1363                    perror("fork");
1364                    return False;
1365            }
1366    
1367            /* Child */
1368            if (child == 0)
1369            {
1370                    /* Close read end */
1371                    close(fd[0]);
1372    
1373                    /* Redirect stdout and stderr to pipe */
1374                    dup2(fd[1], 1);
1375                    dup2(fd[1], 2);
1376    
1377                    /* Execute */
1378                    execvp(argv[0], argv);
1379                    perror("Error executing child");
1380                    _exit(128);
1381            }
1382    
1383            /* Parent. Close write end. */
1384            close(fd[1]);
1385            while (n > 0)
1386            {
1387                    n = read(fd[0], output, 255);
1388                    output[n] = '\0';
1389                    str_handle_lines(output, &rest, linehandler, data);
1390            }
1391            xfree(rest);
1392    
1393            return True;
1394    }
1395    
1396    
1397  /* not all clibs got ltoa */  /* not all clibs got ltoa */
1398  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1399    

Legend:
Removed from v.1042  
changed lines
  Added in v.1306

  ViewVC Help
Powered by ViewVC 1.1.26