/[rdesktop]/sourceforge.net/trunk/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/trunk/rdesktop/rdesktop.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 570 by stargo, Wed Jan 21 18:02:38 2004 UTC revision 782 by astrand, Thu Oct 7 13:00:29 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_orders = 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 68  BOOL g_hide_decorations = False; Line 66  BOOL g_hide_decorations = False;
66  BOOL g_use_rdp5 = True;  BOOL g_use_rdp5 = True;
67  BOOL g_console_session = False;  BOOL g_console_session = False;
68  BOOL g_numlock_sync = False;  BOOL g_numlock_sync = False;
69  extern BOOL g_owncolmap;  BOOL g_owncolmap = False;
70    BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
71    uint32 g_embed_wnd;
72    uint32 g_rdp5_performanceflags =
73            RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
74    
75  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
76  BOOL g_rdpsnd = False;  BOOL g_rdpsnd = False;
# Line 76  BOOL g_rdpsnd = False; Line 78  BOOL g_rdpsnd = False;
78    
79  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
80  extern uint32 g_num_devices;  extern uint32 g_num_devices;
81    extern char *g_rdpdr_clientname;
82    
83  #ifdef RDP2VNC  #ifdef RDP2VNC
84  extern int rfb_port;  extern int rfb_port;
# Line 107  usage(char *program) Line 110  usage(char *program)
110          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
111          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
112          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
113            fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
114          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
115          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
116          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
# Line 116  usage(char *program) Line 120  usage(char *program)
120          fprintf(stderr, "   -S: caption button size (single application mode)\n");          fprintf(stderr, "   -S: caption button size (single application mode)\n");
121          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
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");
124          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\n");
125            fprintf(stderr, "   -z: enable rdp compression\n");
126            fprintf(stderr, "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n");
127            fprintf(stderr, "   -P: use persistent bitmap caching\n");
128          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");
129          fprintf(stderr, "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");          fprintf(stderr,
130          fprintf(stderr, "             or    :COM1=/dev/ttyS0:9600,0|1|2,0|2,5|6|7|8:dtr \n");                  "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");
131          fprintf(stderr, "         '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n");          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
132          fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");          fprintf(stderr,
133          fprintf(stderr, "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");                  "         '-r disk:floppy=/mnt/floppy': enable redirection of /mnt/floppy to 'floppy' share\n");
134          fprintf(stderr, "             or       LPT1=/dev/lp0,LPT2=/dev/lp1\n");          fprintf(stderr, "             or   'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n");
135            fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");
136            fprintf(stderr, "             for redirected disks\n");
137            fprintf(stderr,
138                    "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");
139            fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");
140          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
141          fprintf(stderr, "             or       mydeskjet:\"HP Laserjet IIIP\" to enter server driver as well\n");          fprintf(stderr,
142          fprintf(stderr, "         '-r sound': enable sound redirection\n");                  "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
143            fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");
144            fprintf(stderr, "                     remote would leave sound on server\n");
145          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
146          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
147          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          fprintf(stderr, "   -5: use RDP version 5 (default)\n");
148  }  }
149    
150    void
151    print_disconnect_reason(uint16 reason)
152    {
153            char *text;
154    
155            switch (reason)
156            {
157                    case exDiscReasonNoInfo:
158                            text = "No information available";
159                            break;
160    
161                    case exDiscReasonAPIInitiatedDisconnect:
162                            text = "Server initiated disconnect";
163                            break;
164    
165                    case exDiscReasonAPIInitiatedLogoff:
166                            text = "Server initiated logoff";
167                            break;
168    
169                    case exDiscReasonServerIdleTimeout:
170                            text = "Server idle timeout reached";
171                            break;
172    
173                    case exDiscReasonServerLogonTimeout:
174                            text = "Server logon timeout reached";
175                            break;
176    
177                    case exDiscReasonReplacedByOtherConnection:
178                            text = "The session was replaced";
179                            break;
180    
181                    case exDiscReasonOutOfMemory:
182                            text = "The server is out of memory";
183                            break;
184    
185                    case exDiscReasonServerDeniedConnection:
186                            text = "The server denied the connection";
187                            break;
188    
189                    case exDiscReasonServerDeniedConnectionFips:
190                            text = "The server denied the connection for security reason";
191                            break;
192    
193                    case exDiscReasonLicenseInternal:
194                            text = "Internal licensing error";
195                            break;
196    
197                    case exDiscReasonLicenseNoLicenseServer:
198                            text = "No license server available";
199                            break;
200    
201                    case exDiscReasonLicenseNoLicense:
202                            text = "No valid license available";
203                            break;
204    
205                    case exDiscReasonLicenseErrClientMsg:
206                            text = "Invalid licensing message";
207                            break;
208    
209                    case exDiscReasonLicenseHwidDoesntMatchLicense:
210                            text = "Hardware id doesn't match software license";
211                            break;
212    
213                    case exDiscReasonLicenseErrClientLicense:
214                            text = "Client license error";
215                            break;
216    
217                    case exDiscReasonLicenseCantFinishProtocol:
218                            text = "Network error during licensing protocol";
219                            break;
220    
221                    case exDiscReasonLicenseClientEndedProtocol:
222                            text = "Licensing protocol was not completed";
223                            break;
224    
225                    case exDiscReasonLicenseErrClientEncryption:
226                            text = "Incorrect client license enryption";
227                            break;
228    
229                    case exDiscReasonLicenseCantUpgradeLicense:
230                            text = "Can't upgrade license";
231                            break;
232    
233                    case exDiscReasonLicenseNoRemoteConnections:
234                            text = "The server is not licensed to accept remote connections";
235                            break;
236    
237                    default:
238                            if (reason > 0x1000 && reason < 0x7fff)
239                            {
240                                    text = "Internal protocol error";
241                            }
242                            else
243                            {
244                                    text = "Unknown reason";
245                            }
246            }
247            fprintf(stderr, "disconnect: %s.\n", text);
248    }
249    
250  static BOOL  static BOOL
251  read_password(char *password, int size)  read_password(char *password, int size)
252  {  {
# Line 189  parse_server_and_port(char *server) Line 304  parse_server_and_port(char *server)
304                  if (*server == '[' && p != NULL)                  if (*server == '[' && p != NULL)
305                  {                  {
306                          if (*(p + 1) == ':' && *(p + 2) != '\0')                          if (*(p + 1) == ':' && *(p + 2) != '\0')
307                                  tcp_port_rdp = strtol(p + 2, NULL, 10);                                  g_tcp_port_rdp = strtol(p + 2, NULL, 10);
308                          /* remove the port number and brackets from the address */                          /* remove the port number and brackets from the address */
309                          *p = '\0';                          *p = '\0';
310                          strncpy(server, server + 1, strlen(server));                          strncpy(server, server + 1, strlen(server));
# Line 201  parse_server_and_port(char *server) Line 316  parse_server_and_port(char *server)
316                  p = strchr(server, ':');                  p = strchr(server, ':');
317                  if (p != NULL)                  if (p != NULL)
318                  {                  {
319                          tcp_port_rdp = strtol(p + 1, NULL, 10);                          g_tcp_port_rdp = strtol(p + 1, NULL, 10);
320                          *p = 0;                          *p = 0;
321                  }                  }
322          }          }
# Line 209  parse_server_and_port(char *server) Line 324  parse_server_and_port(char *server)
324          p = strchr(server, ':');          p = strchr(server, ':');
325          if (p != NULL)          if (p != NULL)
326          {          {
327                  tcp_port_rdp = strtol(p + 1, NULL, 10);                  g_tcp_port_rdp = strtol(p + 1, NULL, 10);
328                  *p = 0;                  *p = 0;
329          }          }
330  #endif /* IPv6 */  #endif /* IPv6 */
# Line 226  main(int argc, char *argv[]) Line 341  main(int argc, char *argv[])
341          char password[64];          char password[64];
342          char shell[128];          char shell[128];
343          char directory[32];          char directory[32];
344          BOOL prompt_password, rdp_retval = False;          BOOL prompt_password, deactivated;
345          struct passwd *pw;          struct passwd *pw;
346          uint32 flags;          uint32 flags, ext_disc_reason = 0;
347          char *p;          char *p;
348          int c;          int c;
349    
# Line 238  main(int argc, char *argv[]) Line 353  main(int argc, char *argv[])
353          prompt_password = False;          prompt_password = False;
354          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
355          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
356            g_embed_wnd = 0;
357    
358          g_num_devices = 0;          g_num_devices = 0;
359    
# Line 247  main(int argc, char *argv[]) Line 363  main(int argc, char *argv[])
363  #define VNCOPT  #define VNCOPT
364  #endif  #endif
365    
366          while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbeEmCDKS:T:Na:r:045h?")) != -1)          while ((c = getopt(argc, argv,
367                               VNCOPT "u:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1)
368          {          {
369                  switch (c)                  switch (c)
370                  {                  {
# Line 299  main(int argc, char *argv[]) Line 416  main(int argc, char *argv[])
416                                  break;                                  break;
417    
418                          case 'n':                          case 'n':
419                                  STRNCPY(hostname, optarg, sizeof(hostname));                                  STRNCPY(g_hostname, optarg, sizeof(g_hostname));
420                                  break;                                  break;
421    
422                          case 'k':                          case 'k':
# Line 340  main(int argc, char *argv[]) Line 457  main(int argc, char *argv[])
457                                  break;                                  break;
458    
459                          case 'b':                          case 'b':
460                                  g_orders = False;                                  g_bitmap_cache = False;
461                                    break;
462    
463                            case 'B':
464                                    g_ownbackstore = False;
465                                  break;                                  break;
466    
467                          case 'e':                          case 'e':
# Line 390  main(int argc, char *argv[]) Line 511  main(int argc, char *argv[])
511                                  g_numlock_sync = True;                                  g_numlock_sync = True;
512                                  break;                                  break;
513    
514                            case 'X':
515                                    g_embed_wnd = strtol(optarg, NULL, 10);
516                                    break;
517    
518                          case 'a':                          case 'a':
519                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_bpp = strtol(optarg, NULL, 10);
520                                  if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15                                  if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15
# Line 400  main(int argc, char *argv[]) Line 525  main(int argc, char *argv[])
525                                  }                                  }
526                                  break;                                  break;
527    
528                            case 'z':
529                                    DEBUG(("rdp compression enabled\n"));
530                                    flags |= RDP_COMPRESSION;
531                                    break;
532    
533                            case 'x':
534                                    if (strncmp("modem", optarg, 1) == 0)
535                                    {
536                                            g_rdp5_performanceflags =
537                                                    RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
538                                                    RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
539                                    }
540                                    else if (strncmp("broadband", optarg, 1) == 0)
541                                    {
542                                            g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
543                                    }
544                                    else if (strncmp("lan", optarg, 1) == 0)
545                                    {
546                                            g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
547                                    }
548                                    else
549                                    {
550                                            g_rdp5_performanceflags = strtol(optarg, NULL, 16);
551                                    }
552                                    break;
553    
554                            case 'P':
555                                    g_bitmap_cache_persist_enable = True;
556                                    break;
557    
558                          case 'r':                          case 'r':
559    
560                                  if (strncmp("sound", optarg, 5) == 0)                                  if (strncmp("sound", optarg, 5) == 0)
561                                  {                                  {
562                                            optarg += 5;
563    
564                                            if (*optarg == ':')
565                                            {
566                                                    *optarg++;
567                                                    while ((p = next_arg(optarg, ',')))
568                                                    {
569                                                            if (strncmp("remote", optarg, 6) == 0)
570                                                                    flags |= RDP_LOGON_LEAVE_AUDIO;
571    
572                                                            if (strncmp("local", optarg, 5) == 0)
573  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
574                                          g_rdpsnd = True;                                                                  g_rdpsnd = True;
575  #else  #else
576                                          warning("Not compiled with sound support");                                                                  warning("Not compiled with sound support\n");
577  #endif  #endif
578    
579                                                            if (strncmp("off", optarg, 3) == 0)
580    #ifdef WITH_RDPSND
581                                                                    g_rdpsnd = False;
582    #else
583                                                                    warning("Not compiled with sound support\n");
584    #endif
585    
586                                                            optarg = p;
587                                                    }
588                                            }
589                                            else
590                                            {
591    #ifdef WITH_RDPSND
592                                                    g_rdpsnd = True;
593    #else
594                                                    warning("Not compiled with sound support\n");
595    #endif
596                                            }
597                                  }                                  }
598                                  else if (strncmp("disk", optarg, 4) == 0)                                  else if (strncmp("disk", optarg, 4) == 0)
599                                  {                                  {
# Line 427  main(int argc, char *argv[]) Line 612  main(int argc, char *argv[])
612                                  {                                  {
613                                          printer_enum_devices(&g_num_devices, optarg + 7);                                          printer_enum_devices(&g_num_devices, optarg + 7);
614                                  }                                  }
615                                    else if (strncmp("clientname", optarg, 7) == 0)
616                                    {
617                                            g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
618                                            strcpy(g_rdpdr_clientname, optarg + 11);
619                                    }
620                                  else                                  else
621                                  {                                  {
622                                          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\n");
# Line 453  main(int argc, char *argv[]) Line 643  main(int argc, char *argv[])
643                  }                  }
644          }          }
645    
646          if (argc - optind < 1)          if (argc - optind != 1)
647          {          {
648                  usage(argv[0]);                  usage(argv[0]);
649                  return 1;                  return 1;
# Line 474  main(int argc, char *argv[]) Line 664  main(int argc, char *argv[])
664                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
665          }          }
666    
667          if (hostname[0] == 0)          if (g_hostname[0] == 0)
668          {          {
669                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
670                  {                  {
# Line 486  main(int argc, char *argv[]) Line 676  main(int argc, char *argv[])
676                  if (p != NULL)                  if (p != NULL)
677                          *p = 0;                          *p = 0;
678    
679                  STRNCPY(hostname, fullhostname, sizeof(hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
680          }          }
681    
682          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
# Line 526  main(int argc, char *argv[]) Line 716  main(int argc, char *argv[])
716    
717          if (ui_create_window())          if (ui_create_window())
718          {          {
719                  rdp_retval = rdp_main_loop();                  rdp_main_loop(&deactivated, &ext_disc_reason);
720                  ui_destroy_window();                  ui_destroy_window();
721          }          }
722    
723          DEBUG(("Disconnecting...\n"));          DEBUG(("Disconnecting...\n"));
724          rdp_disconnect();          rdp_disconnect();
725            cache_save_state();
726          ui_deinit();          ui_deinit();
727    
728          if (True == rdp_retval)          if (ext_disc_reason >= 2)
729                    print_disconnect_reason(ext_disc_reason);
730    
731            if (deactivated)
732            {
733                    /* clean disconnect */
734                  return 0;                  return 0;
735            }
736          else          else
737                  return 2;          {
738                    if (ext_disc_reason == exDiscReasonAPIInitiatedDisconnect
739                        || ext_disc_reason == exDiscReasonAPIInitiatedLogoff)
740                    {
741                            /* not so clean disconnect, but nothing to worry about */
742                            return 0;
743                    }
744                    else
745                    {
746                            /* return error */
747                            return 2;
748                    }
749            }
750    
751  #endif  #endif
752    
# Line 643  xmalloc(int size) Line 852  xmalloc(int size)
852  void *  void *
853  xrealloc(void *oldmem, int size)  xrealloc(void *oldmem, int size)
854  {  {
855          void *mem = realloc(oldmem, size);          void *mem;
856    
857            if (size < 1)
858                    size = 1;
859            mem = realloc(oldmem, size);
860          if (mem == NULL)          if (mem == NULL)
861          {          {
862                  error("xrealloc %d\n", size);                  error("xrealloc %d\n", size);
# Line 728  hexdump(unsigned char *p, unsigned int l Line 941  hexdump(unsigned char *p, unsigned int l
941  }  }
942    
943  /*  /*
944    input: src is the string we look in for needle    input: src is the string we look in for needle.
945             Needle may be escaped by a backslash, in
946             that case we ignore that particular needle.
947    return value: returns next src pointer, for    return value: returns next src pointer, for
948          succesive executions, like in a while loop          succesive executions, like in a while loop
949          if retval is 0, then there are no more args.          if retval is 0, then there are no more args.
# Line 749  char * Line 964  char *
964  next_arg(char *src, char needle)  next_arg(char *src, char needle)
965  {  {
966          char *nextval;          char *nextval;
967            char *p;
968            char *mvp = 0;
969    
970          // EOS          /* EOS */
971          if (*src == (char) 0x00)          if (*src == (char) 0x00)
972                  return 0;                  return 0;
973    
974          // more args available.          p = src;
975          nextval = strchr(src, needle);          /*  skip escaped needles */
976            while ((nextval = strchr(p, needle)))
977            {
978                    mvp = nextval - 1;
979                    /* found backslashed needle */
980                    if (*mvp == '\\' && (mvp > src))
981                    {
982                            /* move string one to the left */
983                            while (*(mvp + 1) != (char) 0x00)
984                            {
985                                    *mvp = *(mvp + 1);
986                                    *mvp++;
987                            }
988                            *mvp = (char) 0x00;
989                            p = nextval;
990                    }
991                    else
992                    {
993                            p = nextval + 1;
994                            break;
995                    }
996    
997            }
998    
999            /* more args available */
1000          if (nextval)          if (nextval)
1001          {          {
1002                  *nextval = (char) 0x00;                  *nextval = (char) 0x00;
1003                  return ++nextval;                  return ++nextval;
1004          }          }
1005    
1006          // no more args after this, jump to EOS          /* no more args after this, jump to EOS */
1007          nextval = src + strlen(src);          nextval = src + strlen(src);
1008          return nextval;          return nextval;
1009  }  }
1010    
1011    
1012  void  void
1013  toupper_str(char* p)  toupper_str(char *p)
1014  {  {
1015          while( *p ){          while (*p)
1016                  if( (*p >= 'a') && (*p <= 'z') )          {
1017                    if ((*p >= 'a') && (*p <= 'z'))
1018                          *p = toupper((int) *p);                          *p = toupper((int) *p);
1019                  p++;                  p++;
1020          }          }
# Line 783  toupper_str(char* p) Line 1025  toupper_str(char* p)
1025  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1026    
1027  char *  char *
1028  ltoa(long N, int base)  l_to_a(long N, int base)
1029  {  {
1030          static char ret[LTOA_BUFSIZE];          static char ret[LTOA_BUFSIZE];
1031    
1032          register int i = 2;          char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
         long uarg;  
         char *tail, *head = ret, buf[LTOA_BUFSIZE];  
1033    
1034          if (36 < base || 2 > base)          register int divrem;
                 base = 10;  
1035    
1036          tail = &buf[LTOA_BUFSIZE - 1];          if (base < 36 || 2 > base)
1037          *tail-- = '\0';                  base = 10;
1038    
1039          if (10 == base && N < 0L)          if (N < 0)
1040          {          {
1041                  *head++ = '-';                  *head++ = '-';
1042                  uarg = -N;                  N = -N;
1043          }          }
         else  
                 uarg = N;  
1044    
1045          if (uarg)          tail = buf + sizeof(buf);
1046          {          *--tail = 0;
                 for (i = 1; uarg; ++i)  
                 {  
                         register ldiv_t r;  
1047    
1048                          r = ldiv(uarg, base);          do
1049                          *tail-- = (char) (r.rem + ((9L < r.rem) ? ('A' - 10L) : '0'));          {
1050                          uarg = r.quot;                  divrem = N % base;
1051                  }                  *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
1052                    N /= base;
1053          }          }
1054          else          while (N);
                 *tail-- = '0';  
1055    
1056          memcpy(head, ++tail, i);          strcpy(head, tail);
1057          return ret;          return ret;
1058  }  }
1059    
# Line 835  load_licence(unsigned char **data) Line 1069  load_licence(unsigned char **data)
1069          if (home == NULL)          if (home == NULL)
1070                  return -1;                  return -1;
1071    
1072          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1073          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1074    
1075          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
1076          if (fd == -1)          if (fd == -1)
# Line 862  save_licence(unsigned char *data, int le Line 1096  save_licence(unsigned char *data, int le
1096          if (home == NULL)          if (home == NULL)
1097                  return;                  return;
1098    
1099          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1100    
1101          sprintf(path, "%s/.rdesktop", home);          sprintf(path, "%s/.rdesktop", home);
1102          if ((mkdir(path, 0700) == -1) && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
# Line 873  save_licence(unsigned char *data, int le Line 1107  save_licence(unsigned char *data, int le
1107    
1108          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
1109    
1110          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1111          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
1112          strcpy(tmppath, path);          strcpy(tmppath, path);
1113          strcat(tmppath, ".new");          strcat(tmppath, ".new");
# Line 900  save_licence(unsigned char *data, int le Line 1134  save_licence(unsigned char *data, int le
1134          xfree(tmppath);          xfree(tmppath);
1135          xfree(path);          xfree(path);
1136  }  }
1137    
1138    /* Create the bitmap cache directory */
1139    BOOL
1140    rd_pstcache_mkdir(void)
1141    {
1142            char *home;
1143            char bmpcache_dir[256];
1144    
1145            home = getenv("HOME");
1146    
1147            if (home == NULL)
1148                    return False;
1149    
1150            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop");
1151    
1152            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1153            {
1154                    perror(bmpcache_dir);
1155                    return False;
1156            }
1157    
1158            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache");
1159    
1160            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1161            {
1162                    perror(bmpcache_dir);
1163                    return False;
1164            }
1165    
1166            return True;
1167    }
1168    
1169    /* open a file in the .rdesktop directory */
1170    int
1171    rd_open_file(char *filename)
1172    {
1173            char *home;
1174            char fn[256];
1175            int fd;
1176    
1177            home = getenv("HOME");
1178            if (home == NULL)
1179                    return -1;
1180            sprintf(fn, "%s/.rdesktop/%s", home, filename);
1181            fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
1182            if (fd == -1)
1183                    perror(fn);
1184            return fd;
1185    }
1186    
1187    /* close file */
1188    void
1189    rd_close_file(int fd)
1190    {
1191            close(fd);
1192    }
1193    
1194    /* read from file*/
1195    int
1196    rd_read_file(int fd, void *ptr, int len)
1197    {
1198            return read(fd, ptr, len);
1199    }
1200    
1201    /* write to file */
1202    int
1203    rd_write_file(int fd, void *ptr, int len)
1204    {
1205            return write(fd, ptr, len);
1206    }
1207    
1208    /* move file pointer */
1209    int
1210    rd_lseek_file(int fd, int offset)
1211    {
1212            return lseek(fd, offset, SEEK_SET);
1213    }
1214    
1215    /* do a write lock on a file */
1216    BOOL
1217    rd_lock_file(int fd, int start, int len)
1218    {
1219            struct flock lock;
1220    
1221            lock.l_type = F_WRLCK;
1222            lock.l_whence = SEEK_SET;
1223            lock.l_start = start;
1224            lock.l_len = len;
1225            if (fcntl(fd, F_SETLK, &lock) == -1)
1226                    return False;
1227            return True;
1228    }

Legend:
Removed from v.570  
changed lines
  Added in v.782

  ViewVC Help
Powered by ViewVC 1.1.26