/[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 685 by stargo, Thu Apr 29 19:40:40 2004 UTC revision 738 by astrand, Mon Jul 12 21:07:39 2004 UTC
# Line 43  Line 43 
43    
44  char g_title[64] = "";  char g_title[64] = "";
45  char g_username[64];  char g_username[64];
46  char hostname[16];  char g_hostname[16];
47  char keymapname[16];  char keymapname[16];
48  int keylayout = 0x409;          /* Defaults to US keyboard layout */  int g_keylayout = 0x409;        /* Defaults to US keyboard layout */
49    
50  int g_width = 800;              /* width is special: If 0, the  int g_width = 800;              /* width is special: If 0, the
51                                     geometry will be fetched from                                     geometry will be fetched from
# Line 53  int g_width = 800;             /* width is special: Line 53  int g_width = 800;             /* width is special:
53                                     absolute value specifies the                                     absolute value specifies the
54                                     percent of the whole screen. */                                     percent of the whole screen. */
55  int g_height = 600;  int g_height = 600;
56  int tcp_port_rdp = TCP_PORT_RDP;  extern int g_tcp_port_rdp;
57  int g_server_bpp = 8;  int g_server_bpp = 8;
58  int g_win_button_size = 0;      /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
59  BOOL g_bitmap_compression = True;  BOOL g_bitmap_compression = True;
60  BOOL g_sendmotion = True;  BOOL g_sendmotion = True;
61  BOOL g_bitmap_cache = True;  BOOL g_bitmap_cache = True;
62    BOOL g_bitmap_cache_persist_enable = False;
63    BOOL g_bitmap_cache_precache = True;
64  BOOL g_encryption = True;  BOOL g_encryption = True;
65  BOOL packet_encryption = True;  BOOL packet_encryption = True;
66  BOOL g_desktop_save = True;  BOOL g_desktop_save = True;
# Line 124  usage(char *program) Line 126  usage(char *program)
126          fprintf(stderr, "   -N: enable numlock syncronization\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
127          fprintf(stderr, "   -X: embed into another window with a given id.\n");          fprintf(stderr, "   -X: embed into another window with a given id.\n");
128          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\n");
129          fprintf(stderr,          fprintf(stderr, "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n");
130                  "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex number)\n");          fprintf(stderr, "   -P: use persistent bitmap caching\n");
131          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");
132          fprintf(stderr,          fprintf(stderr,
133                  "         '-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 307  parse_server_and_port(char *server)
307                  if (*server == '[' && p != NULL)                  if (*server == '[' && p != NULL)
308                  {                  {
309                          if (*(p + 1) == ':' && *(p + 2) != '\0')                          if (*(p + 1) == ':' && *(p + 2) != '\0')
310                                  tcp_port_rdp = strtol(p + 2, NULL, 10);                                  g_tcp_port_rdp = strtol(p + 2, NULL, 10);
311                          /* remove the port number and brackets from the address */                          /* remove the port number and brackets from the address */
312                          *p = '\0';                          *p = '\0';
313                          strncpy(server, server + 1, strlen(server));                          strncpy(server, server + 1, strlen(server));
# Line 317  parse_server_and_port(char *server) Line 319  parse_server_and_port(char *server)
319                  p = strchr(server, ':');                  p = strchr(server, ':');
320                  if (p != NULL)                  if (p != NULL)
321                  {                  {
322                          tcp_port_rdp = strtol(p + 1, NULL, 10);                          g_tcp_port_rdp = strtol(p + 1, NULL, 10);
323                          *p = 0;                          *p = 0;
324                  }                  }
325          }          }
# Line 325  parse_server_and_port(char *server) Line 327  parse_server_and_port(char *server)
327          p = strchr(server, ':');          p = strchr(server, ':');
328          if (p != NULL)          if (p != NULL)
329          {          {
330                  tcp_port_rdp = strtol(p + 1, NULL, 10);                  g_tcp_port_rdp = strtol(p + 1, NULL, 10);
331                  *p = 0;                  *p = 0;
332          }          }
333  #endif /* IPv6 */  #endif /* IPv6 */
# Line 364  main(int argc, char *argv[]) Line 366  main(int argc, char *argv[])
366  #define VNCOPT  #define VNCOPT
367  #endif  #endif
368    
369          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,
370                               VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:Pr:045h?")) != -1)
371          {          {
372                  switch (c)                  switch (c)
373                  {                  {
# Line 416  main(int argc, char *argv[]) Line 419  main(int argc, char *argv[])
419                                  break;                                  break;
420    
421                          case 'n':                          case 'n':
422                                  STRNCPY(hostname, optarg, sizeof(hostname));                                  STRNCPY(g_hostname, optarg, sizeof(g_hostname));
423                                  break;                                  break;
424    
425                          case 'k':                          case 'k':
# Line 547  main(int argc, char *argv[]) Line 550  main(int argc, char *argv[])
550                                  }                                  }
551                                  break;                                  break;
552    
553                            case 'P':
554                                    g_bitmap_cache_persist_enable = True;
555                                    break;
556    
557                          case 'r':                          case 'r':
558    
559                                  if (strncmp("sound", optarg, 5) == 0)                                  if (strncmp("sound", optarg, 5) == 0)
# Line 656  main(int argc, char *argv[]) Line 663  main(int argc, char *argv[])
663                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
664          }          }
665    
666          if (hostname[0] == 0)          if (g_hostname[0] == 0)
667          {          {
668                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
669                  {                  {
# Line 668  main(int argc, char *argv[]) Line 675  main(int argc, char *argv[])
675                  if (p != NULL)                  if (p != NULL)
676                          *p = 0;                          *p = 0;
677    
678                  STRNCPY(hostname, fullhostname, sizeof(hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
679          }          }
680    
681          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
# Line 714  main(int argc, char *argv[]) Line 721  main(int argc, char *argv[])
721    
722          DEBUG(("Disconnecting...\n"));          DEBUG(("Disconnecting...\n"));
723          rdp_disconnect();          rdp_disconnect();
724            cache_save_state();
725          ui_deinit();          ui_deinit();
726    
727          if (ext_disc_reason >= 2)          if (ext_disc_reason >= 2)
# Line 1056  load_licence(unsigned char **data) Line 1064  load_licence(unsigned char **data)
1064          if (home == NULL)          if (home == NULL)
1065                  return -1;                  return -1;
1066    
1067          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1068          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1069    
1070          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
1071          if (fd == -1)          if (fd == -1)
# Line 1083  save_licence(unsigned char *data, int le Line 1091  save_licence(unsigned char *data, int le
1091          if (home == NULL)          if (home == NULL)
1092                  return;                  return;
1093    
1094          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1095    
1096          sprintf(path, "%s/.rdesktop", home);          sprintf(path, "%s/.rdesktop", home);
1097          if ((mkdir(path, 0700) == -1) && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
# Line 1094  save_licence(unsigned char *data, int le Line 1102  save_licence(unsigned char *data, int le
1102    
1103          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
1104    
1105          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1106          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
1107          strcpy(tmppath, path);          strcpy(tmppath, path);
1108          strcat(tmppath, ".new");          strcat(tmppath, ".new");
# Line 1121  save_licence(unsigned char *data, int le Line 1129  save_licence(unsigned char *data, int le
1129          xfree(tmppath);          xfree(tmppath);
1130          xfree(path);          xfree(path);
1131  }  }
1132    
1133    /* Create the bitmap cache directory */
1134    BOOL
1135    rd_pstcache_mkdir(void)
1136    {
1137            char *home;
1138            char bmpcache_dir[256];
1139    
1140            home = getenv("HOME");
1141    
1142            if (home == NULL)
1143                    return False;
1144    
1145            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop");
1146    
1147            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1148            {
1149                    perror(bmpcache_dir);
1150                    return False;
1151            }
1152    
1153            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache");
1154    
1155            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1156            {
1157                    perror(bmpcache_dir);
1158                    return False;
1159            }
1160    
1161            return True;
1162    }
1163    
1164    /* open a file in the .rdesktop directory */
1165    int
1166    rd_open_file(char *filename)
1167    {
1168            char *home;
1169            char fn[256];
1170            int fd;
1171    
1172            home = getenv("HOME");
1173            if (home == NULL)
1174                    return -1;
1175            sprintf(fn, "%s/.rdesktop/%s", home, filename);
1176            fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
1177            if (fd == -1)
1178                    perror(fn);
1179            return fd;
1180    }
1181    
1182    /* close file */
1183    void
1184    rd_close_file(int fd)
1185    {
1186            close(fd);
1187    }
1188    
1189    /* read from file*/
1190    int
1191    rd_read_file(int fd, void *ptr, int len)
1192    {
1193            return read(fd, ptr, len);
1194    }
1195    
1196    /* write to file */
1197    int
1198    rd_write_file(int fd, void *ptr, int len)
1199    {
1200            return write(fd, ptr, len);
1201    }
1202    
1203    /* move file pointer */
1204    int
1205    rd_lseek_file(int fd, int offset)
1206    {
1207            return lseek(fd, offset, SEEK_SET);
1208    }
1209    
1210    /* do a write lock on a file */
1211    BOOL
1212    rd_lock_file(int fd, int start, int len)
1213    {
1214            struct flock lock;
1215    
1216            lock.l_type = F_WRLCK;
1217            lock.l_whence = SEEK_SET;
1218            lock.l_start = start;
1219            lock.l_len = len;
1220            if (fcntl(fd, F_SETLK, &lock) == -1)
1221                    return False;
1222            return True;
1223    }

Legend:
Removed from v.685  
changed lines
  Added in v.738

  ViewVC Help
Powered by ViewVC 1.1.26