/[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 678 by jsorg71, Mon Apr 26 22:31:22 2004 UTC revision 740 by astrand, Sat Jul 31 13:07:41 2004 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;  extern int g_tcp_port_rdp;
53  int g_server_bpp = 8;  int g_server_bpp = 8;
54  int g_win_button_size = 0;      /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
55  BOOL g_bitmap_compression = True;  BOOL g_bitmap_compression = True;
56  BOOL g_sendmotion = True;  BOOL g_sendmotion = True;
57  BOOL g_bitmap_cache = True;  BOOL g_bitmap_cache = True;
58    BOOL g_bitmap_cache_persist_enable = False;
59    BOOL g_bitmap_cache_precache = True;
60  BOOL g_encryption = True;  BOOL g_encryption = True;
61  BOOL packet_encryption = True;  BOOL packet_encryption = True;
62  BOOL g_desktop_save = True;  BOOL g_desktop_save = True;
# Line 124  usage(char *program) Line 122  usage(char *program)
122          fprintf(stderr, "   -N: enable numlock syncronization\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
123          fprintf(stderr, "   -X: embed into another window with a given id.\n");          fprintf(stderr, "   -X: embed into another window with a given id.\n");
124          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\n");
125          fprintf(stderr,          fprintf(stderr, "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n");
126                  "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex number)\n");          fprintf(stderr, "   -P: use persistent bitmap caching\n");
127          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");
128          fprintf(stderr,          fprintf(stderr,
129                  "         '-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");
# Line 305  parse_server_and_port(char *server) Line 303  parse_server_and_port(char *server)
303                  if (*server == '[' && p != NULL)                  if (*server == '[' && p != NULL)
304                  {                  {
305                          if (*(p + 1) == ':' && *(p + 2) != '\0')                          if (*(p + 1) == ':' && *(p + 2) != '\0')
306                                  tcp_port_rdp = strtol(p + 2, NULL, 10);                                  g_tcp_port_rdp = strtol(p + 2, NULL, 10);
307                          /* remove the port number and brackets from the address */                          /* remove the port number and brackets from the address */
308                          *p = '\0';                          *p = '\0';
309                          strncpy(server, server + 1, strlen(server));                          strncpy(server, server + 1, strlen(server));
# Line 317  parse_server_and_port(char *server) Line 315  parse_server_and_port(char *server)
315                  p = strchr(server, ':');                  p = strchr(server, ':');
316                  if (p != NULL)                  if (p != NULL)
317                  {                  {
318                          tcp_port_rdp = strtol(p + 1, NULL, 10);                          g_tcp_port_rdp = strtol(p + 1, NULL, 10);
319                          *p = 0;                          *p = 0;
320                  }                  }
321          }          }
# Line 325  parse_server_and_port(char *server) Line 323  parse_server_and_port(char *server)
323          p = strchr(server, ':');          p = strchr(server, ':');
324          if (p != NULL)          if (p != NULL)
325          {          {
326                  tcp_port_rdp = strtol(p + 1, NULL, 10);                  g_tcp_port_rdp = strtol(p + 1, NULL, 10);
327                  *p = 0;                  *p = 0;
328          }          }
329  #endif /* IPv6 */  #endif /* IPv6 */
# Line 364  main(int argc, char *argv[]) Line 362  main(int argc, char *argv[])
362  #define VNCOPT  #define VNCOPT
363  #endif  #endif
364    
365          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,
366                               VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:Pr:045h?")) != -1)
367          {          {
368                  switch (c)                  switch (c)
369                  {                  {
# Line 416  main(int argc, char *argv[]) Line 415  main(int argc, char *argv[])
415                                  break;                                  break;
416    
417                          case 'n':                          case 'n':
418                                  STRNCPY(hostname, optarg, sizeof(hostname));                                  STRNCPY(g_hostname, optarg, sizeof(g_hostname));
419                                  break;                                  break;
420    
421                          case 'k':                          case 'k':
# Line 547  main(int argc, char *argv[]) Line 546  main(int argc, char *argv[])
546                                  }                                  }
547                                  break;                                  break;
548    
549                            case 'P':
550                                    g_bitmap_cache_persist_enable = True;
551                                    break;
552    
553                          case 'r':                          case 'r':
554    
555                                  if (strncmp("sound", optarg, 5) == 0)                                  if (strncmp("sound", optarg, 5) == 0)
# Line 565  main(int argc, char *argv[]) Line 568  main(int argc, char *argv[])
568  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
569                                                                  g_rdpsnd = True;                                                                  g_rdpsnd = True;
570  #else  #else
571                                                                  warning("Not compiled with sound support");                                                                  warning("Not compiled with sound support\n");
572  #endif  #endif
573    
574                                                          if (strncmp("off", optarg, 3) == 0)                                                          if (strncmp("off", optarg, 3) == 0)
575    #ifdef WITH_RDPSND
576                                                                  g_rdpsnd = False;                                                                  g_rdpsnd = False;
577    #else
578                                                                    warning("Not compiled with sound support\n");
579    #endif
580    
581                                                          optarg = p;                                                          optarg = p;
582                                                  }                                                  }
# Line 579  main(int argc, char *argv[]) Line 586  main(int argc, char *argv[])
586  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
587                                                  g_rdpsnd = True;                                                  g_rdpsnd = True;
588  #else  #else
589                                                  warning("Not compiled with sound support");                                                  warning("Not compiled with sound support\n");
590  #endif  #endif
591                                          }                                          }
592                                  }                                  }
# Line 652  main(int argc, char *argv[]) Line 659  main(int argc, char *argv[])
659                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
660          }          }
661    
662          if (hostname[0] == 0)          if (g_hostname[0] == 0)
663          {          {
664                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
665                  {                  {
# Line 664  main(int argc, char *argv[]) Line 671  main(int argc, char *argv[])
671                  if (p != NULL)                  if (p != NULL)
672                          *p = 0;                          *p = 0;
673    
674                  STRNCPY(hostname, fullhostname, sizeof(hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
675          }          }
676    
677          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
# Line 710  main(int argc, char *argv[]) Line 717  main(int argc, char *argv[])
717    
718          DEBUG(("Disconnecting...\n"));          DEBUG(("Disconnecting...\n"));
719          rdp_disconnect();          rdp_disconnect();
720            cache_save_state();
721          ui_deinit();          ui_deinit();
722    
723          if (ext_disc_reason >= 2)          if (ext_disc_reason >= 2)
# Line 1052  load_licence(unsigned char **data) Line 1060  load_licence(unsigned char **data)
1060          if (home == NULL)          if (home == NULL)
1061                  return -1;                  return -1;
1062    
1063          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1064          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1065    
1066          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
1067          if (fd == -1)          if (fd == -1)
# Line 1079  save_licence(unsigned char *data, int le Line 1087  save_licence(unsigned char *data, int le
1087          if (home == NULL)          if (home == NULL)
1088                  return;                  return;
1089    
1090          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1091    
1092          sprintf(path, "%s/.rdesktop", home);          sprintf(path, "%s/.rdesktop", home);
1093          if ((mkdir(path, 0700) == -1) && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
# Line 1090  save_licence(unsigned char *data, int le Line 1098  save_licence(unsigned char *data, int le
1098    
1099          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
1100    
1101          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1102          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
1103          strcpy(tmppath, path);          strcpy(tmppath, path);
1104          strcat(tmppath, ".new");          strcat(tmppath, ".new");
# Line 1117  save_licence(unsigned char *data, int le Line 1125  save_licence(unsigned char *data, int le
1125          xfree(tmppath);          xfree(tmppath);
1126          xfree(path);          xfree(path);
1127  }  }
1128    
1129    /* Create the bitmap cache directory */
1130    BOOL
1131    rd_pstcache_mkdir(void)
1132    {
1133            char *home;
1134            char bmpcache_dir[256];
1135    
1136            home = getenv("HOME");
1137    
1138            if (home == NULL)
1139                    return False;
1140    
1141            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop");
1142    
1143            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1144            {
1145                    perror(bmpcache_dir);
1146                    return False;
1147            }
1148    
1149            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache");
1150    
1151            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1152            {
1153                    perror(bmpcache_dir);
1154                    return False;
1155            }
1156    
1157            return True;
1158    }
1159    
1160    /* open a file in the .rdesktop directory */
1161    int
1162    rd_open_file(char *filename)
1163    {
1164            char *home;
1165            char fn[256];
1166            int fd;
1167    
1168            home = getenv("HOME");
1169            if (home == NULL)
1170                    return -1;
1171            sprintf(fn, "%s/.rdesktop/%s", home, filename);
1172            fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
1173            if (fd == -1)
1174                    perror(fn);
1175            return fd;
1176    }
1177    
1178    /* close file */
1179    void
1180    rd_close_file(int fd)
1181    {
1182            close(fd);
1183    }
1184    
1185    /* read from file*/
1186    int
1187    rd_read_file(int fd, void *ptr, int len)
1188    {
1189            return read(fd, ptr, len);
1190    }
1191    
1192    /* write to file */
1193    int
1194    rd_write_file(int fd, void *ptr, int len)
1195    {
1196            return write(fd, ptr, len);
1197    }
1198    
1199    /* move file pointer */
1200    int
1201    rd_lseek_file(int fd, int offset)
1202    {
1203            return lseek(fd, offset, SEEK_SET);
1204    }
1205    
1206    /* do a write lock on a file */
1207    BOOL
1208    rd_lock_file(int fd, int start, int len)
1209    {
1210            struct flock lock;
1211    
1212            lock.l_type = F_WRLCK;
1213            lock.l_whence = SEEK_SET;
1214            lock.l_start = start;
1215            lock.l_len = len;
1216            if (fcntl(fd, F_SETLK, &lock) == -1)
1217                    return False;
1218            return True;
1219    }

Legend:
Removed from v.678  
changed lines
  Added in v.740

  ViewVC Help
Powered by ViewVC 1.1.26