/[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 710 by jsorg71, Tue Jun 15 22:17:08 2004 UTC revision 886 by stargo, Sat Apr 16 11:42:34 2005 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-2003     Copyright (C) Matthew Chapman 1999-2005
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 30  Line 30 
30  #include <errno.h>  #include <errno.h>
31  #include "rdesktop.h"  #include "rdesktop.h"
32    
33    #ifdef HAVE_ICONV
34    #ifdef HAVE_LOCALE_H
35    #include <locale.h>
36    #endif
37    #ifdef HAVE_LANGINFO_H
38    #include <langinfo.h>
39    #endif
40    #endif
41    
42  #ifdef EGD_SOCKET  #ifdef EGD_SOCKET
43    #include <sys/types.h>
44  #include <sys/socket.h>         /* socket connect */  #include <sys/socket.h>         /* socket connect */
45  #include <sys/un.h>             /* sockaddr_un */  #include <sys/un.h>             /* sockaddr_un */
46  #endif  #endif
47    
 #ifdef WITH_OPENSSL  
48  #include <openssl/md5.h>  #include <openssl/md5.h>
 #else  
 #include "crypto/md5.h"  
 #endif  
49    
50  char g_title[64] = "";  char g_title[64] = "";
51  char g_username[64];  char g_username[64];
# Line 53  int g_width = 800;             /* width is special: Line 59  int g_width = 800;             /* width is special:
59                                     absolute value specifies the                                     absolute value specifies the
60                                     percent of the whole screen. */                                     percent of the whole screen. */
61  int g_height = 600;  int g_height = 600;
62    int g_xpos = 0;
63    int g_ypos = 0;
64    int g_pos = 0;                  /* 0 position unspecified,
65                                       1 specified,
66                                       2 xpos neg,
67                                       4 ypos neg  */
68  extern int g_tcp_port_rdp;  extern int g_tcp_port_rdp;
69  int g_server_bpp = 8;  int g_server_bpp = 8;
70  int g_win_button_size = 0;      /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
71  BOOL g_bitmap_compression = True;  BOOL g_bitmap_compression = True;
72  BOOL g_sendmotion = True;  BOOL g_sendmotion = True;
73  BOOL g_bitmap_cache = True;  BOOL g_bitmap_cache = True;
74    BOOL g_bitmap_cache_persist_enable = False;
75    BOOL g_bitmap_cache_precache = True;
76  BOOL g_encryption = True;  BOOL g_encryption = True;
77  BOOL packet_encryption = True;  BOOL packet_encryption = True;
78  BOOL g_desktop_save = True;  BOOL g_desktop_save = True;     /* desktop save order */
79    BOOL g_polygon_ellipse_orders = True;   /* polygon / ellipse orders */
80  BOOL g_fullscreen = False;  BOOL g_fullscreen = False;
81  BOOL g_grab_keyboard = True;  BOOL g_grab_keyboard = True;
82  BOOL g_hide_decorations = False;  BOOL g_hide_decorations = False;
# Line 70  BOOL g_console_session = False; Line 85  BOOL g_console_session = False;
85  BOOL g_numlock_sync = False;  BOOL g_numlock_sync = False;
86  BOOL g_owncolmap = False;  BOOL g_owncolmap = False;
87  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
88    BOOL g_rdp_compression = False;
89  uint32 g_embed_wnd;  uint32 g_embed_wnd;
90  uint32 g_rdp5_performanceflags =  uint32 g_rdp5_performanceflags =
91          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
# Line 78  uint32 g_rdp5_performanceflags = Line 94  uint32 g_rdp5_performanceflags =
94  BOOL g_rdpsnd = False;  BOOL g_rdpsnd = False;
95  #endif  #endif
96    
97    #ifdef HAVE_ICONV
98    char g_codepage[16] = "";
99    #endif
100    
101  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
102  extern uint32 g_num_devices;  extern uint32 g_num_devices;
103  extern char *g_rdpdr_clientname;  extern char *g_rdpdr_clientname;
# Line 94  static void Line 114  static void
114  usage(char *program)  usage(char *program)
115  {  {
116          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
117          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2003 Matt Chapman.\n");          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n");
118          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
119    
120          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
# Line 112  usage(char *program) Line 132  usage(char *program)
132          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
133          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
134          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
135    #ifdef HAVE_ICONV
136            fprintf(stderr, "   -L: local codepage\n");
137    #endif
138          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
139          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
140          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
# Line 124  usage(char *program) Line 147  usage(char *program)
147          fprintf(stderr, "   -N: enable numlock syncronization\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
148          fprintf(stderr, "   -X: embed into another window with a given id.\n");          fprintf(stderr, "   -X: embed into another window with a given id.\n");
149          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\n");
150          fprintf(stderr,          fprintf(stderr, "   -z: enable rdp compression\n");
151                  "   -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");
152            fprintf(stderr, "   -P: use persistent bitmap caching\n");
153          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");
154          fprintf(stderr,          fprintf(stderr,
155                  "         '-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");
156          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
157          fprintf(stderr,          fprintf(stderr,
158                  "         '-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");
159          fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");          fprintf(stderr, "             or   'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n");
160          fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");          fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");
161          fprintf(stderr, "             for redirected disks\n");          fprintf(stderr, "             for redirected disks\n");
162          fprintf(stderr,          fprintf(stderr,
# Line 364  main(int argc, char *argv[]) Line 388  main(int argc, char *argv[])
388  #define VNCOPT  #define VNCOPT
389  #endif  #endif
390    
391          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,
392                               VNCOPT "u:L:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1)
393          {          {
394                  switch (c)                  switch (c)
395                  {                  {
# Line 387  main(int argc, char *argv[]) Line 412  main(int argc, char *argv[])
412                                  username_option = 1;                                  username_option = 1;
413                                  break;                                  break;
414    
415                            case 'L':
416    #ifdef HAVE_ICONV
417                                    STRNCPY(g_codepage, optarg, sizeof(g_codepage));
418    #else
419                                    error("iconv support not available\n");
420    #endif
421                                    break;
422    
423                          case 'd':                          case 'd':
424                                  STRNCPY(domain, optarg, sizeof(domain));                                  STRNCPY(domain, optarg, sizeof(domain));
425                                  break;                                  break;
# Line 439  main(int argc, char *argv[]) Line 472  main(int argc, char *argv[])
472                                  }                                  }
473    
474                                  if (*p == 'x')                                  if (*p == 'x')
475                                          g_height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, &p, 10);
476    
477                                  if (g_height <= 0)                                  if (g_height <= 0)
478                                  {                                  {
# Line 448  main(int argc, char *argv[]) Line 481  main(int argc, char *argv[])
481                                  }                                  }
482    
483                                  if (*p == '%')                                  if (*p == '%')
484                                    {
485                                          g_width = -g_width;                                          g_width = -g_width;
486                                            p++;
487                                    }
488    
489                                    if (*p == '+' || *p == '-')
490                                    {
491                                            g_pos |= (*p == '-') ? 2 : 1;
492                                            g_xpos = strtol(p, &p, 10);
493    
494                                    }
495                                    if (*p == '+' || *p == '-')
496                                    {
497                                            g_pos |= (*p == '-') ? 4 : 1;
498                                            g_ypos = strtol(p, NULL, 10);
499                                    }
500    
501                                  break;                                  break;
502    
# Line 512  main(int argc, char *argv[]) Line 560  main(int argc, char *argv[])
560                                  break;                                  break;
561    
562                          case 'X':                          case 'X':
563                                  g_embed_wnd = strtol(optarg, NULL, 10);                                  g_embed_wnd = strtol(optarg, NULL, 0);
564                                  break;                                  break;
565    
566                          case 'a':                          case 'a':
# Line 525  main(int argc, char *argv[]) Line 573  main(int argc, char *argv[])
573                                  }                                  }
574                                  break;                                  break;
575    
576                          case 'x':                          case 'z':
577                                    DEBUG(("rdp compression enabled\n"));
578                                    flags |= RDP_COMPRESSION;
579                                    g_rdp_compression = True;
580                                    break;
581    
582                            case 'x':
583                                  if (strncmp("modem", optarg, 1) == 0)                                  if (strncmp("modem", optarg, 1) == 0)
584                                  {                                  {
585                                          g_rdp5_performanceflags =                                          g_rdp5_performanceflags =
# Line 547  main(int argc, char *argv[]) Line 600  main(int argc, char *argv[])
600                                  }                                  }
601                                  break;                                  break;
602    
603                            case 'P':
604                                    g_bitmap_cache_persist_enable = True;
605                                    break;
606    
607                          case 'r':                          case 'r':
608    
609                                  if (strncmp("sound", optarg, 5) == 0)                                  if (strncmp("sound", optarg, 5) == 0)
# Line 565  main(int argc, char *argv[]) Line 622  main(int argc, char *argv[])
622  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
623                                                                  g_rdpsnd = True;                                                                  g_rdpsnd = True;
624  #else  #else
625                                                                  warning("Not compiled with sound support");                                                                  warning("Not compiled with sound support\n");
626  #endif  #endif
627    
628                                                          if (strncmp("off", optarg, 3) == 0)                                                          if (strncmp("off", optarg, 3) == 0)
629  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
630                                                                  g_rdpsnd = False;                                                                  g_rdpsnd = False;
631  #else  #else
632                                                                  warning("Not compiled with sound support");                                                                  warning("Not compiled with sound support\n");
633  #endif  #endif
634    
635                                                          optarg = p;                                                          optarg = p;
# Line 583  main(int argc, char *argv[]) Line 640  main(int argc, char *argv[])
640  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
641                                                  g_rdpsnd = True;                                                  g_rdpsnd = True;
642  #else  #else
643                                                  warning("Not compiled with sound support");                                                  warning("Not compiled with sound support\n");
644  #endif  #endif
645                                          }                                          }
646                                  }                                  }
# Line 656  main(int argc, char *argv[]) Line 713  main(int argc, char *argv[])
713                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
714          }          }
715    
716    #ifdef HAVE_ICONV
717            if (g_codepage[0] == 0)
718            {
719                    if (setlocale(LC_CTYPE, ""))
720                    {
721                            STRNCPY(g_codepage, nl_langinfo(CODESET), sizeof(g_codepage));
722                    }
723                    else
724                    {
725                            STRNCPY(g_codepage, DEFAULT_CODEPAGE, sizeof(g_codepage));
726                    }
727            }
728    #endif
729    
730          if (g_hostname[0] == 0)          if (g_hostname[0] == 0)
731          {          {
732                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
# Line 714  main(int argc, char *argv[]) Line 785  main(int argc, char *argv[])
785    
786          DEBUG(("Disconnecting...\n"));          DEBUG(("Disconnecting...\n"));
787          rdp_disconnect();          rdp_disconnect();
788            cache_save_state();
789          ui_deinit();          ui_deinit();
790    
791          if (ext_disc_reason >= 2)          if (ext_disc_reason >= 2)
# Line 843  xmalloc(int size) Line 915  xmalloc(int size)
915  void *  void *
916  xrealloc(void *oldmem, int size)  xrealloc(void *oldmem, int size)
917  {  {
918          void *mem = realloc(oldmem, size);          void *mem;
919    
920            if (size < 1)
921                    size = 1;
922            mem = realloc(oldmem, size);
923          if (mem == NULL)          if (mem == NULL)
924          {          {
925                  error("xrealloc %d\n", size);                  error("xrealloc %d\n", size);
# Line 1121  save_licence(unsigned char *data, int le Line 1197  save_licence(unsigned char *data, int le
1197          xfree(tmppath);          xfree(tmppath);
1198          xfree(path);          xfree(path);
1199  }  }
1200    
1201    /* Create the bitmap cache directory */
1202    BOOL
1203    rd_pstcache_mkdir(void)
1204    {
1205            char *home;
1206            char bmpcache_dir[256];
1207    
1208            home = getenv("HOME");
1209    
1210            if (home == NULL)
1211                    return False;
1212    
1213            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop");
1214    
1215            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1216            {
1217                    perror(bmpcache_dir);
1218                    return False;
1219            }
1220    
1221            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache");
1222    
1223            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1224            {
1225                    perror(bmpcache_dir);
1226                    return False;
1227            }
1228    
1229            return True;
1230    }
1231    
1232    /* open a file in the .rdesktop directory */
1233    int
1234    rd_open_file(char *filename)
1235    {
1236            char *home;
1237            char fn[256];
1238            int fd;
1239    
1240            home = getenv("HOME");
1241            if (home == NULL)
1242                    return -1;
1243            sprintf(fn, "%s/.rdesktop/%s", home, filename);
1244            fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
1245            if (fd == -1)
1246                    perror(fn);
1247            return fd;
1248    }
1249    
1250    /* close file */
1251    void
1252    rd_close_file(int fd)
1253    {
1254            close(fd);
1255    }
1256    
1257    /* read from file*/
1258    int
1259    rd_read_file(int fd, void *ptr, int len)
1260    {
1261            return read(fd, ptr, len);
1262    }
1263    
1264    /* write to file */
1265    int
1266    rd_write_file(int fd, void *ptr, int len)
1267    {
1268            return write(fd, ptr, len);
1269    }
1270    
1271    /* move file pointer */
1272    int
1273    rd_lseek_file(int fd, int offset)
1274    {
1275            return lseek(fd, offset, SEEK_SET);
1276    }
1277    
1278    /* do a write lock on a file */
1279    BOOL
1280    rd_lock_file(int fd, int start, int len)
1281    {
1282            struct flock lock;
1283    
1284            lock.l_type = F_WRLCK;
1285            lock.l_whence = SEEK_SET;
1286            lock.l_start = start;
1287            lock.l_len = len;
1288            if (fcntl(fd, F_SETLK, &lock) == -1)
1289                    return False;
1290            return True;
1291    }

Legend:
Removed from v.710  
changed lines
  Added in v.886

  ViewVC Help
Powered by ViewVC 1.1.26