/[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 1365 by jsorg71, Thu Jan 4 05:39:39 2007 UTC
# Line 1  Line 1 
1  /* -*- c-basic-offset: 8 -*-  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Entrypoint and utility functions     Entrypoint and utility functions
4     Copyright (C) Matthew Chapman 1999-2005     Copyright (C) Matthew Chapman 1999-2007
5    
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# 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    #ifdef WITH_SCARD
197            fprintf(stderr, "         '-r scard[:\"Scard Name\"=\"Alias Name[;Vendor Name]\"[,...]]\n");
198            fprintf(stderr, "          example: -r scard:\"eToken PRO 00 00\"=\"AKS ifdh 0\"\n");
199            fprintf(stderr,
200                    "                   \"eToken PRO 00 00\" -> Device in Linux/Unix enviroment\n");
201            fprintf(stderr,
202                    "                   \"AKS ifdh 0\"       -> Device shown in Windows enviroment \n");
203            fprintf(stderr, "          example: -r scard:\"eToken PRO 00 00\"=\"AKS ifdh 0;AKS\"\n");
204            fprintf(stderr,
205                    "                   \"eToken PRO 00 00\" -> Device in Linux/Unix enviroment\n");
206            fprintf(stderr,
207                    "                   \"AKS ifdh 0\"       -> Device shown in Windows enviroment \n");
208            fprintf(stderr,
209                    "                   \"AKS\"              -> Device vendor name                 \n");
210    #endif
211          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
212          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
213          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 411  main(int argc, char *argv[])
411          char fullhostname[64];          char fullhostname[64];
412          char domain[16];          char domain[16];
413          char password[64];          char password[64];
414          char shell[128];          char shell[256];
415          char directory[32];          char directory[256];
416          BOOL prompt_password, deactivated;          BOOL prompt_password, deactivated;
417          struct passwd *pw;          struct passwd *pw;
418          uint32 flags, ext_disc_reason = 0;          uint32 flags, ext_disc_reason = 0;
# Line 389  main(int argc, char *argv[]) Line 420  main(int argc, char *argv[])
420          int c;          int c;
421          char *locale = NULL;          char *locale = NULL;
422          int username_option = 0;          int username_option = 0;
423            BOOL geometry_option = False;
424          int run_count = 0;      /* Session Directory support */          int run_count = 0;      /* Session Directory support */
425          BOOL continue_connect = True;   /* Session Directory support */          BOOL continue_connect = True;   /* Session Directory support */
426    #ifdef WITH_RDPSND
427            char *rdpsnd_optarg = NULL;
428    #endif
429    
430  #ifdef HAVE_LOCALE_H  #ifdef HAVE_LOCALE_H
431          /* Set locale according to environment */          /* Set locale according to environment */
# Line 415  main(int argc, char *argv[]) Line 450  main(int argc, char *argv[])
450  #endif  #endif
451    
452          while ((c = getopt(argc, argv,          while ((c = getopt(argc, argv,
453                             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)
454          {          {
455                  switch (c)                  switch (c)
456                  {                  {
# Line 433  main(int argc, char *argv[]) Line 468  main(int argc, char *argv[])
468                                  break;                                  break;
469  #endif  #endif
470    
471                            case 'A':
472                                    g_seamless_rdp = True;
473                                    break;
474    
475                          case 'u':                          case 'u':
476                                  STRNCPY(g_username, optarg, sizeof(g_username));                                  STRNCPY(g_username, optarg, sizeof(g_username));
477                                  username_option = 1;                                  username_option = 1;
# Line 483  main(int argc, char *argv[]) Line 522  main(int argc, char *argv[])
522                                  break;                                  break;
523    
524                          case 'g':                          case 'g':
525                                    geometry_option = True;
526                                  g_fullscreen = False;                                  g_fullscreen = False;
527                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
528                                  {                                  {
# Line 638  main(int argc, char *argv[]) Line 678  main(int argc, char *argv[])
678    
679                                          if (*optarg == ':')                                          if (*optarg == ':')
680                                          {                                          {
681                                                  *optarg++;                                                  optarg++;
682                                                  while ((p = next_arg(optarg, ',')))                                                  while ((p = next_arg(optarg, ',')))
683                                                  {                                                  {
684                                                          if (str_startswith(optarg, "remote"))                                                          if (str_startswith(optarg, "remote"))
# Line 646  main(int argc, char *argv[]) Line 686  main(int argc, char *argv[])
686    
687                                                          if (str_startswith(optarg, "local"))                                                          if (str_startswith(optarg, "local"))
688  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
689                                                            {
690                                                                    rdpsnd_optarg =
691                                                                            next_arg(optarg, ':');
692                                                                  g_rdpsnd = True;                                                                  g_rdpsnd = True;
693                                                            }
694    
695  #else  #else
696                                                                  warning("Not compiled with sound support\n");                                                                  warning("Not compiled with sound support\n");
697  #endif  #endif
# Line 679  main(int argc, char *argv[]) Line 724  main(int argc, char *argv[])
724                                  {                                  {
725                                          serial_enum_devices(&g_num_devices, optarg + 7);                                          serial_enum_devices(&g_num_devices, optarg + 7);
726                                  }                                  }
727                                    else if (str_startswith(optarg, "lspci"))
728                                    {
729                                            lspci_enabled = True;
730                                    }
731                                  else if (str_startswith(optarg, "lptport"))                                  else if (str_startswith(optarg, "lptport"))
732                                  {                                  {
733                                          parallel_enum_devices(&g_num_devices, optarg + 7);                                          parallel_enum_devices(&g_num_devices, optarg + 7);
# Line 692  main(int argc, char *argv[]) Line 741  main(int argc, char *argv[])
741                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
742                                          strcpy(g_rdpdr_clientname, optarg + 11);                                          strcpy(g_rdpdr_clientname, optarg + 11);
743                                  }                                  }
744                                    else if (str_startswith(optarg, "clipboard"))
745                                    {
746                                            optarg += 9;
747    
748                                            if (*optarg == ':')
749                                            {
750                                                    optarg++;
751    
752                                                    if (str_startswith(optarg, "off"))
753                                                            g_rdpclip = False;
754                                                    else
755                                                            cliprdr_set_mode(optarg);
756                                            }
757                                            else
758                                                    g_rdpclip = True;
759                                    }
760                                    else if (strncmp("scard", optarg, 5) == 0)
761                                    {
762    #ifdef WITH_SCARD
763                                            scard_enum_devices(&g_num_devices, optarg + 5);
764    #else
765                                            warning("Not compiled with smartcard support\n");
766    #endif
767                                    }
768                                  else                                  else
769                                  {                                  {
770                                          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, scard\n");
771                                  }                                  }
772                                  break;                                  break;
773    
# Line 727  main(int argc, char *argv[]) Line 800  main(int argc, char *argv[])
800          STRNCPY(server, argv[optind], sizeof(server));          STRNCPY(server, argv[optind], sizeof(server));
801          parse_server_and_port(server);          parse_server_and_port(server);
802    
803            if (g_seamless_rdp)
804            {
805                    if (g_win_button_size)
806                    {
807                            error("You cannot use -S and -A at the same time\n");
808                            return 1;
809                    }
810                    g_rdp5_performanceflags &= ~RDP5_NO_FULLWINDOWDRAG;
811                    if (geometry_option)
812                    {
813                            error("You cannot use -g and -A at the same time\n");
814                            return 1;
815                    }
816                    if (g_fullscreen)
817                    {
818                            error("You cannot use -f and -A at the same time\n");
819                            return 1;
820                    }
821                    if (g_hide_decorations)
822                    {
823                            error("You cannot use -D and -A at the same time\n");
824                            return 1;
825                    }
826                    if (g_embed_wnd)
827                    {
828                            error("You cannot use -X and -A at the same time\n");
829                            return 1;
830                    }
831                    if (!g_use_rdp5)
832                    {
833                            error("You cannot use -4 and -A at the same time\n");
834                            return 1;
835                    }
836                    g_width = -100;
837                    g_grab_keyboard = False;
838            }
839    
840          if (!username_option)          if (!username_option)
841          {          {
842                  pw = getpwuid(getuid());                  pw = getpwuid(getuid());
# Line 802  main(int argc, char *argv[]) Line 912  main(int argc, char *argv[])
912    
913  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
914          if (g_rdpsnd)          if (g_rdpsnd)
915                  rdpsnd_init();          {
916                    if (!rdpsnd_init(rdpsnd_optarg))
917                    {
918                            warning("Initializing sound-support failed!\n");
919                    }
920            }
921  #endif  #endif
922    
923            if (lspci_enabled)
924                    lspci_init();
925    
926          rdpdr_init();          rdpdr_init();
927    
928          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 1104  xmalloc(int size)
1104          return mem;          return mem;
1105  }  }
1106    
1107    /* Exit on NULL pointer. Use to verify result from XGetImage etc */
1108    void
1109    exit_if_null(void *ptr)
1110    {
1111            if (ptr == NULL)
1112            {
1113                    error("unexpected null pointer. Out of memory?\n");
1114                    exit(1);
1115            }
1116    }
1117    
1118  /* strdup */  /* strdup */
1119  char *  char *
1120  xstrdup(const char *s)  xstrdup(const char *s)
# Line 1133  next_arg(char *src, char needle) Line 1263  next_arg(char *src, char needle)
1263                          while (*(mvp + 1) != (char) 0x00)                          while (*(mvp + 1) != (char) 0x00)
1264                          {                          {
1265                                  *mvp = *(mvp + 1);                                  *mvp = *(mvp + 1);
1266                                  *mvp++;                                  mvp++;
1267                          }                          }
1268                          *mvp = (char) 0x00;                          *mvp = (char) 0x00;
1269                          p = nextval;                          p = nextval;
# Line 1178  str_startswith(const char *s, const char Line 1308  str_startswith(const char *s, const char
1308  }  }
1309    
1310    
1311    /* Split input into lines, and call linehandler for each
1312       line. Incomplete lines are saved in the rest variable, which should
1313       initially point to NULL. When linehandler returns False, stop and
1314       return False. Otherwise, return True.  */
1315    BOOL
1316    str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data)
1317    {
1318            char *buf, *p;
1319            char *oldrest;
1320            size_t inputlen;
1321            size_t buflen;
1322            size_t restlen = 0;
1323            BOOL ret = True;
1324    
1325            /* Copy data to buffer */
1326            inputlen = strlen(input);
1327            if (*rest)
1328                    restlen = strlen(*rest);
1329            buflen = restlen + inputlen + 1;
1330            buf = (char *) xmalloc(buflen);
1331            buf[0] = '\0';
1332            if (*rest)
1333                    STRNCPY(buf, *rest, buflen);
1334            strncat(buf, input, inputlen);
1335            p = buf;
1336    
1337            while (1)
1338            {
1339                    char *newline = strchr(p, '\n');
1340                    if (newline)
1341                    {
1342                            *newline = '\0';
1343                            if (!linehandler(p, data))
1344                            {
1345                                    p = newline + 1;
1346                                    ret = False;
1347                                    break;
1348                            }
1349                            p = newline + 1;
1350                    }
1351                    else
1352                    {
1353                            break;
1354    
1355                    }
1356            }
1357    
1358            /* Save in rest */
1359            oldrest = *rest;
1360            restlen = buf + buflen - p;
1361            *rest = (char *) xmalloc(restlen);
1362            STRNCPY((*rest), p, restlen);
1363            xfree(oldrest);
1364    
1365            xfree(buf);
1366            return ret;
1367    }
1368    
1369    /* Execute the program specified by argv. For each line in
1370       stdout/stderr output, call linehandler. Returns false on failure. */
1371    BOOL
1372    subprocess(char *const argv[], str_handle_lines_t linehandler, void *data)
1373    {
1374            pid_t child;
1375            int fd[2];
1376            int n = 1;
1377            char output[256];
1378            char *rest = NULL;
1379    
1380            if (pipe(fd) < 0)
1381            {
1382                    perror("pipe");
1383                    return False;
1384            }
1385    
1386            if ((child = fork()) < 0)
1387            {
1388                    perror("fork");
1389                    return False;
1390            }
1391    
1392            /* Child */
1393            if (child == 0)
1394            {
1395                    /* Close read end */
1396                    close(fd[0]);
1397    
1398                    /* Redirect stdout and stderr to pipe */
1399                    dup2(fd[1], 1);
1400                    dup2(fd[1], 2);
1401    
1402                    /* Execute */
1403                    execvp(argv[0], argv);
1404                    perror("Error executing child");
1405                    _exit(128);
1406            }
1407    
1408            /* Parent. Close write end. */
1409            close(fd[1]);
1410            while (n > 0)
1411            {
1412                    n = read(fd[0], output, 255);
1413                    output[n] = '\0';
1414                    str_handle_lines(output, &rest, linehandler, data);
1415            }
1416            xfree(rest);
1417    
1418            return True;
1419    }
1420    
1421    
1422  /* not all clibs got ltoa */  /* not all clibs got ltoa */
1423  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1424    

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

  ViewVC Help
Powered by ViewVC 1.1.26