/[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

revision 676 by astrand, Tue Apr 20 07:01:21 2004 UTC revision 825 by stargo, Wed Mar 2 10:16:31 2005 UTC
# Line 35  Line 35 
35  #include <sys/un.h>             /* sockaddr_un */  #include <sys/un.h>             /* sockaddr_un */
36  #endif  #endif
37    
 #ifdef WITH_OPENSSL  
38  #include <openssl/md5.h>  #include <openssl/md5.h>
 #else  
 #include "crypto/md5.h"  
 #endif  
39    
40  char g_title[64] = "";  char g_title[64] = "";
41  char g_username[64];  char g_username[64];
42  char hostname[16];  char g_hostname[16];
43  char keymapname[16];  char keymapname[16];
44  int keylayout = 0x409;          /* Defaults to US keyboard layout */  int g_keylayout = 0x409;        /* Defaults to US keyboard layout */
45    
46  int g_width = 800;              /* width is special: If 0, the  int g_width = 800;              /* width is special: If 0, the
47                                     geometry will be fetched from                                     geometry will be fetched from
# Line 53  int g_width = 800;             /* width is special: Line 49  int g_width = 800;             /* width is special:
49                                     absolute value specifies the                                     absolute value specifies the
50                                     percent of the whole screen. */                                     percent of the whole screen. */
51  int g_height = 600;  int g_height = 600;
52  int tcp_port_rdp = TCP_PORT_RDP;  int g_xpos = 0;
53    int g_ypos = 0;
54    extern int g_tcp_port_rdp;
55  int g_server_bpp = 8;  int g_server_bpp = 8;
56  int g_win_button_size = 0;      /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
57  BOOL g_bitmap_compression = True;  BOOL g_bitmap_compression = True;
58  BOOL g_sendmotion = True;  BOOL g_sendmotion = True;
59  BOOL g_orders = True;  BOOL g_bitmap_cache = True;
60    BOOL g_bitmap_cache_persist_enable = False;
61    BOOL g_bitmap_cache_precache = True;
62  BOOL g_encryption = True;  BOOL g_encryption = True;
63  BOOL packet_encryption = True;  BOOL packet_encryption = True;
64  BOOL g_desktop_save = True;  BOOL g_desktop_save = True;
# Line 124  usage(char *program) Line 124  usage(char *program)
124          fprintf(stderr, "   -N: enable numlock syncronization\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
125          fprintf(stderr, "   -X: embed into another window with a given id.\n");          fprintf(stderr, "   -X: embed into another window with a given id.\n");
126          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\n");
127          fprintf(stderr,          fprintf(stderr, "   -z: enable rdp compression\n");
128                  "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex number)\n");          fprintf(stderr, "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n");
129            fprintf(stderr, "   -P: use persistent bitmap caching\n");
130          fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");          fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");
131          fprintf(stderr,          fprintf(stderr,
132                  "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");                  "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");
133          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
134          fprintf(stderr,          fprintf(stderr,
135                  "         '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n");                  "         '-r disk:floppy=/mnt/floppy': enable redirection of /mnt/floppy to 'floppy' share\n");
136          fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");          fprintf(stderr, "             or   'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n");
137          fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");          fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");
138          fprintf(stderr, "             for redirected disks\n");          fprintf(stderr, "             for redirected disks\n");
139          fprintf(stderr,          fprintf(stderr,
# Line 305  parse_server_and_port(char *server) Line 306  parse_server_and_port(char *server)
306                  if (*server == '[' && p != NULL)                  if (*server == '[' && p != NULL)
307                  {                  {
308                          if (*(p + 1) == ':' && *(p + 2) != '\0')                          if (*(p + 1) == ':' && *(p + 2) != '\0')
309                                  tcp_port_rdp = strtol(p + 2, NULL, 10);                                  g_tcp_port_rdp = strtol(p + 2, NULL, 10);
310                          /* remove the port number and brackets from the address */                          /* remove the port number and brackets from the address */
311                          *p = '\0';                          *p = '\0';
312                          strncpy(server, server + 1, strlen(server));                          strncpy(server, server + 1, strlen(server));
# Line 317  parse_server_and_port(char *server) Line 318  parse_server_and_port(char *server)
318                  p = strchr(server, ':');                  p = strchr(server, ':');
319                  if (p != NULL)                  if (p != NULL)
320                  {                  {
321                          tcp_port_rdp = strtol(p + 1, NULL, 10);                          g_tcp_port_rdp = strtol(p + 1, NULL, 10);
322                          *p = 0;                          *p = 0;
323                  }                  }
324          }          }
# Line 325  parse_server_and_port(char *server) Line 326  parse_server_and_port(char *server)
326          p = strchr(server, ':');          p = strchr(server, ':');
327          if (p != NULL)          if (p != NULL)
328          {          {
329                  tcp_port_rdp = strtol(p + 1, NULL, 10);                  g_tcp_port_rdp = strtol(p + 1, NULL, 10);
330                  *p = 0;                  *p = 0;
331          }          }
332  #endif /* IPv6 */  #endif /* IPv6 */
# Line 364  main(int argc, char *argv[]) Line 365  main(int argc, char *argv[])
365  #define VNCOPT  #define VNCOPT
366  #endif  #endif
367    
368          while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:r:045h?")) != -1)          while ((c = getopt(argc, argv,
369                               VNCOPT "u:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1)
370          {          {
371                  switch (c)                  switch (c)
372                  {                  {
# Line 416  main(int argc, char *argv[]) Line 418  main(int argc, char *argv[])
418                                  break;                                  break;
419    
420                          case 'n':                          case 'n':
421                                  STRNCPY(hostname, optarg, sizeof(hostname));                                  STRNCPY(g_hostname, optarg, sizeof(g_hostname));
422                                  break;                                  break;
423    
424                          case 'k':                          case 'k':
# Line 439  main(int argc, char *argv[]) Line 441  main(int argc, char *argv[])
441                                  }                                  }
442    
443                                  if (*p == 'x')                                  if (*p == 'x')
444                                          g_height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, &p, 10);
445    
446                                  if (g_height <= 0)                                  if (g_height <= 0)
447                                  {                                  {
# Line 448  main(int argc, char *argv[]) Line 450  main(int argc, char *argv[])
450                                  }                                  }
451    
452                                  if (*p == '%')                                  if (*p == '%')
453                                    {
454                                          g_width = -g_width;                                          g_width = -g_width;
455                                            p++;
456                                    }
457    
458                                    if (*p == '+' || *p == '-')
459                                            g_xpos = strtol(p, &p, 10);
460    
461                                    if (*p == '+' || *p == '-')
462                                            g_ypos = strtol(p, NULL, 10);
463    
464                                  break;                                  break;
465    
# Line 457  main(int argc, char *argv[]) Line 468  main(int argc, char *argv[])
468                                  break;                                  break;
469    
470                          case 'b':                          case 'b':
471                                  g_orders = False;                                  g_bitmap_cache = False;
472                                  break;                                  break;
473    
474                          case 'B':                          case 'B':
# Line 525  main(int argc, char *argv[]) Line 536  main(int argc, char *argv[])
536                                  }                                  }
537                                  break;                                  break;
538    
539                          case 'x':                          case 'z':
540                                    DEBUG(("rdp compression enabled\n"));
541                                    flags |= RDP_COMPRESSION;
542                                    break;
543    
544                            case 'x':
545                                  if (strncmp("modem", optarg, 1) == 0)                                  if (strncmp("modem", optarg, 1) == 0)
546                                  {                                  {
547                                          g_rdp5_performanceflags =                                          g_rdp5_performanceflags =
# Line 547  main(int argc, char *argv[]) Line 562  main(int argc, char *argv[])
562                                  }                                  }
563                                  break;                                  break;
564    
565                            case 'P':
566                                    g_bitmap_cache_persist_enable = True;
567                                    break;
568    
569                          case 'r':                          case 'r':
570    
571                                  if (strncmp("sound", optarg, 5) == 0)                                  if (strncmp("sound", optarg, 5) == 0)
# Line 565  main(int argc, char *argv[]) Line 584  main(int argc, char *argv[])
584  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
585                                                                  g_rdpsnd = True;                                                                  g_rdpsnd = True;
586  #else  #else
587                                                                  warning("Not compiled with sound support");                                                                  warning("Not compiled with sound support\n");
588  #endif  #endif
589    
590                                                          if (strncmp("off", optarg, 3) == 0)                                                          if (strncmp("off", optarg, 3) == 0)
591    #ifdef WITH_RDPSND
592                                                                  g_rdpsnd = False;                                                                  g_rdpsnd = False;
593    #else
594                                                                    warning("Not compiled with sound support\n");
595    #endif
596    
597                                                          optarg = p;                                                          optarg = p;
598                                                  }                                                  }
# Line 579  main(int argc, char *argv[]) Line 602  main(int argc, char *argv[])
602  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
603                                                  g_rdpsnd = True;                                                  g_rdpsnd = True;
604  #else  #else
605                                                  warning("Not compiled with sound support");                                                  warning("Not compiled with sound support\n");
606  #endif  #endif
607                                          }                                          }
608                                  }                                  }
# Line 652  main(int argc, char *argv[]) Line 675  main(int argc, char *argv[])
675                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
676          }          }
677    
678          if (hostname[0] == 0)          if (g_hostname[0] == 0)
679          {          {
680                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
681                  {                  {
# Line 664  main(int argc, char *argv[]) Line 687  main(int argc, char *argv[])
687                  if (p != NULL)                  if (p != NULL)
688                          *p = 0;                          *p = 0;
689    
690                  STRNCPY(hostname, fullhostname, sizeof(hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
691            }
692    
693            if ((flags & RDP_COMPRESSION) && (g_server_bpp > 8))
694            {
695                    warning("rdp compression not supported for bpp > 8, compression disabled\n");
696                    flags ^= RDP_COMPRESSION;
697          }          }
698    
699          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
# Line 710  main(int argc, char *argv[]) Line 739  main(int argc, char *argv[])
739    
740          DEBUG(("Disconnecting...\n"));          DEBUG(("Disconnecting...\n"));
741          rdp_disconnect();          rdp_disconnect();
742            cache_save_state();
743          ui_deinit();          ui_deinit();
744    
745          if (ext_disc_reason >= 2)          if (ext_disc_reason >= 2)
# Line 839  xmalloc(int size) Line 869  xmalloc(int size)
869  void *  void *
870  xrealloc(void *oldmem, int size)  xrealloc(void *oldmem, int size)
871  {  {
872          void *mem = realloc(oldmem, size);          void *mem;
873    
874            if (size < 1)
875                    size = 1;
876            mem = realloc(oldmem, size);
877          if (mem == NULL)          if (mem == NULL)
878          {          {
879                  error("xrealloc %d\n", size);                  error("xrealloc %d\n", size);
# Line 1052  load_licence(unsigned char **data) Line 1086  load_licence(unsigned char **data)
1086          if (home == NULL)          if (home == NULL)
1087                  return -1;                  return -1;
1088    
1089          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1090          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1091    
1092          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
1093          if (fd == -1)          if (fd == -1)
# Line 1079  save_licence(unsigned char *data, int le Line 1113  save_licence(unsigned char *data, int le
1113          if (home == NULL)          if (home == NULL)
1114                  return;                  return;
1115    
1116          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1117    
1118          sprintf(path, "%s/.rdesktop", home);          sprintf(path, "%s/.rdesktop", home);
1119          if ((mkdir(path, 0700) == -1) && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
# Line 1090  save_licence(unsigned char *data, int le Line 1124  save_licence(unsigned char *data, int le
1124    
1125          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
1126    
1127          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1128          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
1129          strcpy(tmppath, path);          strcpy(tmppath, path);
1130          strcat(tmppath, ".new");          strcat(tmppath, ".new");
# Line 1117  save_licence(unsigned char *data, int le Line 1151  save_licence(unsigned char *data, int le
1151          xfree(tmppath);          xfree(tmppath);
1152          xfree(path);          xfree(path);
1153  }  }
1154    
1155    /* Create the bitmap cache directory */
1156    BOOL
1157    rd_pstcache_mkdir(void)
1158    {
1159            char *home;
1160            char bmpcache_dir[256];
1161    
1162            home = getenv("HOME");
1163    
1164            if (home == NULL)
1165                    return False;
1166    
1167            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop");
1168    
1169            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1170            {
1171                    perror(bmpcache_dir);
1172                    return False;
1173            }
1174    
1175            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache");
1176    
1177            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1178            {
1179                    perror(bmpcache_dir);
1180                    return False;
1181            }
1182    
1183            return True;
1184    }
1185    
1186    /* open a file in the .rdesktop directory */
1187    int
1188    rd_open_file(char *filename)
1189    {
1190            char *home;
1191            char fn[256];
1192            int fd;
1193    
1194            home = getenv("HOME");
1195            if (home == NULL)
1196                    return -1;
1197            sprintf(fn, "%s/.rdesktop/%s", home, filename);
1198            fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
1199            if (fd == -1)
1200                    perror(fn);
1201            return fd;
1202    }
1203    
1204    /* close file */
1205    void
1206    rd_close_file(int fd)
1207    {
1208            close(fd);
1209    }
1210    
1211    /* read from file*/
1212    int
1213    rd_read_file(int fd, void *ptr, int len)
1214    {
1215            return read(fd, ptr, len);
1216    }
1217    
1218    /* write to file */
1219    int
1220    rd_write_file(int fd, void *ptr, int len)
1221    {
1222            return write(fd, ptr, len);
1223    }
1224    
1225    /* move file pointer */
1226    int
1227    rd_lseek_file(int fd, int offset)
1228    {
1229            return lseek(fd, offset, SEEK_SET);
1230    }
1231    
1232    /* do a write lock on a file */
1233    BOOL
1234    rd_lock_file(int fd, int start, int len)
1235    {
1236            struct flock lock;
1237    
1238            lock.l_type = F_WRLCK;
1239            lock.l_whence = SEEK_SET;
1240            lock.l_start = start;
1241            lock.l_len = len;
1242            if (fcntl(fd, F_SETLK, &lock) == -1)
1243                    return False;
1244            return True;
1245    }

Legend:
Removed from v.676  
changed lines
  Added in v.825

  ViewVC Help
Powered by ViewVC 1.1.26