/[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 582 by n-ki, Fri Jan 23 14:37:51 2004 UTC revision 857 by stargo, Sun Mar 13 13:36:04 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/socket.h>         /* socket connect */  #include <sys/socket.h>         /* socket connect */
44  #include <sys/un.h>             /* sockaddr_un */  #include <sys/un.h>             /* sockaddr_un */
45  #endif  #endif
46    
 #ifdef WITH_OPENSSL  
47  #include <openssl/md5.h>  #include <openssl/md5.h>
 #else  
 #include "crypto/md5.h"  
 #endif  
48    
49  char g_title[64] = "";  char g_title[64] = "";
50  char g_username[64];  char g_username[64];
51  char hostname[16];  char g_hostname[16];
52  char keymapname[16];  char keymapname[16];
53  int keylayout = 0x409;          /* Defaults to US keyboard layout */  int g_keylayout = 0x409;        /* Defaults to US keyboard layout */
54    
55  int g_width = 800;              /* width is special: If 0, the  int g_width = 800;              /* width is special: If 0, the
56                                     geometry will be fetched from                                     geometry will be fetched from
# Line 53  int g_width = 800;             /* width is special: Line 58  int g_width = 800;             /* width is special:
58                                     absolute value specifies the                                     absolute value specifies the
59                                     percent of the whole screen. */                                     percent of the whole screen. */
60  int g_height = 600;  int g_height = 600;
61  int tcp_port_rdp = TCP_PORT_RDP;  int g_xpos = 0;
62    int g_ypos = 0;
63    extern int g_tcp_port_rdp;
64  int g_server_bpp = 8;  int g_server_bpp = 8;
65  int g_win_button_size = 0;      /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
66  BOOL g_bitmap_compression = True;  BOOL g_bitmap_compression = True;
67  BOOL g_sendmotion = True;  BOOL g_sendmotion = True;
68  BOOL g_orders = True;  BOOL g_bitmap_cache = True;
69    BOOL g_bitmap_cache_persist_enable = False;
70    BOOL g_bitmap_cache_precache = True;
71  BOOL g_encryption = True;  BOOL g_encryption = True;
72  BOOL packet_encryption = True;  BOOL packet_encryption = True;
73  BOOL g_desktop_save = True;  BOOL g_desktop_save = True;     /* desktop save order */
74    BOOL g_polygon_ellipse_orders = True;   /* polygon / ellipse orders */
75  BOOL g_fullscreen = False;  BOOL g_fullscreen = False;
76  BOOL g_grab_keyboard = True;  BOOL g_grab_keyboard = True;
77  BOOL g_hide_decorations = False;  BOOL g_hide_decorations = False;
78  BOOL g_use_rdp5 = True;  BOOL g_use_rdp5 = True;
79  BOOL g_console_session = False;  BOOL g_console_session = False;
80  BOOL g_numlock_sync = False;  BOOL g_numlock_sync = False;
81  extern BOOL g_owncolmap;  BOOL g_owncolmap = False;
82    BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
83    uint32 g_embed_wnd;
84    uint32 g_rdp5_performanceflags =
85            RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
86    
87  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
88  BOOL g_rdpsnd = False;  BOOL g_rdpsnd = False;
89  #endif  #endif
90    
91    #ifdef HAVE_ICONV
92    char g_codepage[16] = "";
93    #endif
94    
95  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
96  extern uint32 g_num_devices;  extern uint32 g_num_devices;
97    extern char *g_rdpdr_clientname;
98    
99  #ifdef RDP2VNC  #ifdef RDP2VNC
100  extern int rfb_port;  extern int rfb_port;
# Line 89  static void Line 108  static void
108  usage(char *program)  usage(char *program)
109  {  {
110          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
111          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2003 Matt Chapman.\n");          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n");
112          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
113    
114          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
# Line 107  usage(char *program) Line 126  usage(char *program)
126          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
127          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
128          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
129    #ifdef HAVE_ICONV
130            fprintf(stderr, "   -L: local codepage\n");
131    #endif
132            fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
133          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
134          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
135          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
# Line 116  usage(char *program) Line 139  usage(char *program)
139          fprintf(stderr, "   -S: caption button size (single application mode)\n");          fprintf(stderr, "   -S: caption button size (single application mode)\n");
140          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
141          fprintf(stderr, "   -N: enable numlock syncronization\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
142            fprintf(stderr, "   -X: embed into another window with a given id.\n");
143          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\n");
144            fprintf(stderr, "   -z: enable rdp compression\n");
145            fprintf(stderr, "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n");
146            fprintf(stderr, "   -P: use persistent bitmap caching\n");
147          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");
148          fprintf(stderr,          fprintf(stderr,
149                  "         '-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");
150          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
151          fprintf(stderr,          fprintf(stderr,
152                  "         '-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");
153          fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");          fprintf(stderr, "             or   'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n");
154            fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");
155            fprintf(stderr, "             for redirected disks\n");
156          fprintf(stderr,          fprintf(stderr,
157                  "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");                  "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");
158          fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");          fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");
159          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
160          fprintf(stderr,          fprintf(stderr,
161                  "             or       mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");                  "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
162          fprintf(stderr, "         '-r sound': enable sound redirection\n");          fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");
163            fprintf(stderr, "                     remote would leave sound on server\n");
164          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
165          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
166          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          fprintf(stderr, "   -5: use RDP version 5 (default)\n");
167  }  }
168    
169    void
170    print_disconnect_reason(uint16 reason)
171    {
172            char *text;
173    
174            switch (reason)
175            {
176                    case exDiscReasonNoInfo:
177                            text = "No information available";
178                            break;
179    
180                    case exDiscReasonAPIInitiatedDisconnect:
181                            text = "Server initiated disconnect";
182                            break;
183    
184                    case exDiscReasonAPIInitiatedLogoff:
185                            text = "Server initiated logoff";
186                            break;
187    
188                    case exDiscReasonServerIdleTimeout:
189                            text = "Server idle timeout reached";
190                            break;
191    
192                    case exDiscReasonServerLogonTimeout:
193                            text = "Server logon timeout reached";
194                            break;
195    
196                    case exDiscReasonReplacedByOtherConnection:
197                            text = "The session was replaced";
198                            break;
199    
200                    case exDiscReasonOutOfMemory:
201                            text = "The server is out of memory";
202                            break;
203    
204                    case exDiscReasonServerDeniedConnection:
205                            text = "The server denied the connection";
206                            break;
207    
208                    case exDiscReasonServerDeniedConnectionFips:
209                            text = "The server denied the connection for security reason";
210                            break;
211    
212                    case exDiscReasonLicenseInternal:
213                            text = "Internal licensing error";
214                            break;
215    
216                    case exDiscReasonLicenseNoLicenseServer:
217                            text = "No license server available";
218                            break;
219    
220                    case exDiscReasonLicenseNoLicense:
221                            text = "No valid license available";
222                            break;
223    
224                    case exDiscReasonLicenseErrClientMsg:
225                            text = "Invalid licensing message";
226                            break;
227    
228                    case exDiscReasonLicenseHwidDoesntMatchLicense:
229                            text = "Hardware id doesn't match software license";
230                            break;
231    
232                    case exDiscReasonLicenseErrClientLicense:
233                            text = "Client license error";
234                            break;
235    
236                    case exDiscReasonLicenseCantFinishProtocol:
237                            text = "Network error during licensing protocol";
238                            break;
239    
240                    case exDiscReasonLicenseClientEndedProtocol:
241                            text = "Licensing protocol was not completed";
242                            break;
243    
244                    case exDiscReasonLicenseErrClientEncryption:
245                            text = "Incorrect client license enryption";
246                            break;
247    
248                    case exDiscReasonLicenseCantUpgradeLicense:
249                            text = "Can't upgrade license";
250                            break;
251    
252                    case exDiscReasonLicenseNoRemoteConnections:
253                            text = "The server is not licensed to accept remote connections";
254                            break;
255    
256                    default:
257                            if (reason > 0x1000 && reason < 0x7fff)
258                            {
259                                    text = "Internal protocol error";
260                            }
261                            else
262                            {
263                                    text = "Unknown reason";
264                            }
265            }
266            fprintf(stderr, "disconnect: %s.\n", text);
267    }
268    
269  static BOOL  static BOOL
270  read_password(char *password, int size)  read_password(char *password, int size)
271  {  {
# Line 193  parse_server_and_port(char *server) Line 323  parse_server_and_port(char *server)
323                  if (*server == '[' && p != NULL)                  if (*server == '[' && p != NULL)
324                  {                  {
325                          if (*(p + 1) == ':' && *(p + 2) != '\0')                          if (*(p + 1) == ':' && *(p + 2) != '\0')
326                                  tcp_port_rdp = strtol(p + 2, NULL, 10);                                  g_tcp_port_rdp = strtol(p + 2, NULL, 10);
327                          /* remove the port number and brackets from the address */                          /* remove the port number and brackets from the address */
328                          *p = '\0';                          *p = '\0';
329                          strncpy(server, server + 1, strlen(server));                          strncpy(server, server + 1, strlen(server));
# Line 205  parse_server_and_port(char *server) Line 335  parse_server_and_port(char *server)
335                  p = strchr(server, ':');                  p = strchr(server, ':');
336                  if (p != NULL)                  if (p != NULL)
337                  {                  {
338                          tcp_port_rdp = strtol(p + 1, NULL, 10);                          g_tcp_port_rdp = strtol(p + 1, NULL, 10);
339                          *p = 0;                          *p = 0;
340                  }                  }
341          }          }
# Line 213  parse_server_and_port(char *server) Line 343  parse_server_and_port(char *server)
343          p = strchr(server, ':');          p = strchr(server, ':');
344          if (p != NULL)          if (p != NULL)
345          {          {
346                  tcp_port_rdp = strtol(p + 1, NULL, 10);                  g_tcp_port_rdp = strtol(p + 1, NULL, 10);
347                  *p = 0;                  *p = 0;
348          }          }
349  #endif /* IPv6 */  #endif /* IPv6 */
# Line 230  main(int argc, char *argv[]) Line 360  main(int argc, char *argv[])
360          char password[64];          char password[64];
361          char shell[128];          char shell[128];
362          char directory[32];          char directory[32];
363          BOOL prompt_password, rdp_retval = False;          BOOL prompt_password, deactivated;
364          struct passwd *pw;          struct passwd *pw;
365          uint32 flags;          uint32 flags, ext_disc_reason = 0;
366          char *p;          char *p;
367          int c;          int c;
368    
# Line 242  main(int argc, char *argv[]) Line 372  main(int argc, char *argv[])
372          prompt_password = False;          prompt_password = False;
373          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
374          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
375            g_embed_wnd = 0;
376    
377          g_num_devices = 0;          g_num_devices = 0;
378    
# Line 251  main(int argc, char *argv[]) Line 382  main(int argc, char *argv[])
382  #define VNCOPT  #define VNCOPT
383  #endif  #endif
384    
385          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,
386                               VNCOPT "u:L:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1)
387          {          {
388                  switch (c)                  switch (c)
389                  {                  {
# Line 274  main(int argc, char *argv[]) Line 406  main(int argc, char *argv[])
406                                  username_option = 1;                                  username_option = 1;
407                                  break;                                  break;
408    
409                            case 'L':
410    #ifdef HAVE_ICONV
411                                    STRNCPY(g_codepage, optarg, sizeof(g_codepage));
412    #else
413                                    error("iconv support not available\n");
414    #endif
415                                    break;
416    
417                          case 'd':                          case 'd':
418                                  STRNCPY(domain, optarg, sizeof(domain));                                  STRNCPY(domain, optarg, sizeof(domain));
419                                  break;                                  break;
# Line 303  main(int argc, char *argv[]) Line 443  main(int argc, char *argv[])
443                                  break;                                  break;
444    
445                          case 'n':                          case 'n':
446                                  STRNCPY(hostname, optarg, sizeof(hostname));                                  STRNCPY(g_hostname, optarg, sizeof(g_hostname));
447                                  break;                                  break;
448    
449                          case 'k':                          case 'k':
# Line 326  main(int argc, char *argv[]) Line 466  main(int argc, char *argv[])
466                                  }                                  }
467    
468                                  if (*p == 'x')                                  if (*p == 'x')
469                                          g_height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, &p, 10);
470    
471                                  if (g_height <= 0)                                  if (g_height <= 0)
472                                  {                                  {
# Line 335  main(int argc, char *argv[]) Line 475  main(int argc, char *argv[])
475                                  }                                  }
476    
477                                  if (*p == '%')                                  if (*p == '%')
478                                    {
479                                          g_width = -g_width;                                          g_width = -g_width;
480                                            p++;
481                                    }
482    
483                                    if (*p == '+' || *p == '-')
484                                            g_xpos = strtol(p, &p, 10);
485    
486                                    if (*p == '+' || *p == '-')
487                                            g_ypos = strtol(p, NULL, 10);
488    
489                                  break;                                  break;
490    
# Line 344  main(int argc, char *argv[]) Line 493  main(int argc, char *argv[])
493                                  break;                                  break;
494    
495                          case 'b':                          case 'b':
496                                  g_orders = False;                                  g_bitmap_cache = False;
497                                    break;
498    
499                            case 'B':
500                                    g_ownbackstore = False;
501                                  break;                                  break;
502    
503                          case 'e':                          case 'e':
# Line 394  main(int argc, char *argv[]) Line 547  main(int argc, char *argv[])
547                                  g_numlock_sync = True;                                  g_numlock_sync = True;
548                                  break;                                  break;
549    
550                            case 'X':
551                                    g_embed_wnd = strtol(optarg, NULL, 10);
552                                    break;
553    
554                          case 'a':                          case 'a':
555                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_bpp = strtol(optarg, NULL, 10);
556                                  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 404  main(int argc, char *argv[]) Line 561  main(int argc, char *argv[])
561                                  }                                  }
562                                  break;                                  break;
563    
564                            case 'z':
565                                    DEBUG(("rdp compression enabled\n"));
566                                    flags |= RDP_COMPRESSION;
567                                    break;
568    
569                            case 'x':
570                                    if (strncmp("modem", optarg, 1) == 0)
571                                    {
572                                            g_rdp5_performanceflags =
573                                                    RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
574                                                    RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
575                                    }
576                                    else if (strncmp("broadband", optarg, 1) == 0)
577                                    {
578                                            g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
579                                    }
580                                    else if (strncmp("lan", optarg, 1) == 0)
581                                    {
582                                            g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
583                                    }
584                                    else
585                                    {
586                                            g_rdp5_performanceflags = strtol(optarg, NULL, 16);
587                                    }
588                                    break;
589    
590                            case 'P':
591                                    g_bitmap_cache_persist_enable = True;
592                                    break;
593    
594                          case 'r':                          case 'r':
595    
596                                  if (strncmp("sound", optarg, 5) == 0)                                  if (strncmp("sound", optarg, 5) == 0)
597                                  {                                  {
598                                            optarg += 5;
599    
600                                            if (*optarg == ':')
601                                            {
602                                                    *optarg++;
603                                                    while ((p = next_arg(optarg, ',')))
604                                                    {
605                                                            if (strncmp("remote", optarg, 6) == 0)
606                                                                    flags |= RDP_LOGON_LEAVE_AUDIO;
607    
608                                                            if (strncmp("local", optarg, 5) == 0)
609    #ifdef WITH_RDPSND
610                                                                    g_rdpsnd = True;
611    #else
612                                                                    warning("Not compiled with sound support\n");
613    #endif
614    
615                                                            if (strncmp("off", optarg, 3) == 0)
616    #ifdef WITH_RDPSND
617                                                                    g_rdpsnd = False;
618    #else
619                                                                    warning("Not compiled with sound support\n");
620    #endif
621    
622                                                            optarg = p;
623                                                    }
624                                            }
625                                            else
626                                            {
627  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
628                                          g_rdpsnd = True;                                                  g_rdpsnd = True;
629  #else  #else
630                                          warning("Not compiled with sound support");                                                  warning("Not compiled with sound support\n");
631  #endif  #endif
632                                            }
633                                  }                                  }
634                                  else if (strncmp("disk", optarg, 4) == 0)                                  else if (strncmp("disk", optarg, 4) == 0)
635                                  {                                  {
# Line 431  main(int argc, char *argv[]) Line 648  main(int argc, char *argv[])
648                                  {                                  {
649                                          printer_enum_devices(&g_num_devices, optarg + 7);                                          printer_enum_devices(&g_num_devices, optarg + 7);
650                                  }                                  }
651                                    else if (strncmp("clientname", optarg, 7) == 0)
652                                    {
653                                            g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
654                                            strcpy(g_rdpdr_clientname, optarg + 11);
655                                    }
656                                  else                                  else
657                                  {                                  {
658                                          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 457  main(int argc, char *argv[]) Line 679  main(int argc, char *argv[])
679                  }                  }
680          }          }
681    
682          if (argc - optind < 1)          if (argc - optind != 1)
683          {          {
684                  usage(argv[0]);                  usage(argv[0]);
685                  return 1;                  return 1;
# Line 478  main(int argc, char *argv[]) Line 700  main(int argc, char *argv[])
700                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
701          }          }
702    
703          if (hostname[0] == 0)  #ifdef HAVE_ICONV
704            if (g_codepage[0] == 0)
705            {
706                    if (setlocale(LC_CTYPE, ""))
707                    {
708                            STRNCPY(g_codepage, nl_langinfo(CODESET), sizeof(g_codepage));
709                    }
710                    else
711                    {
712                            STRNCPY(g_codepage, DEFAULT_CODEPAGE, sizeof(g_codepage));
713                    }
714            }
715    #endif
716    
717            if (g_hostname[0] == 0)
718          {          {
719                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
720                  {                  {
# Line 490  main(int argc, char *argv[]) Line 726  main(int argc, char *argv[])
726                  if (p != NULL)                  if (p != NULL)
727                          *p = 0;                          *p = 0;
728    
729                  STRNCPY(hostname, fullhostname, sizeof(hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
730            }
731    
732            if ((flags & RDP_COMPRESSION) && (g_server_bpp > 8))
733            {
734                    warning("rdp compression not supported for bpp > 8, compression disabled\n");
735                    flags ^= RDP_COMPRESSION;
736          }          }
737    
738          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
# Line 530  main(int argc, char *argv[]) Line 772  main(int argc, char *argv[])
772    
773          if (ui_create_window())          if (ui_create_window())
774          {          {
775                  rdp_retval = rdp_main_loop();                  rdp_main_loop(&deactivated, &ext_disc_reason);
776                  ui_destroy_window();                  ui_destroy_window();
777          }          }
778    
779          DEBUG(("Disconnecting...\n"));          DEBUG(("Disconnecting...\n"));
780          rdp_disconnect();          rdp_disconnect();
781            cache_save_state();
782          ui_deinit();          ui_deinit();
783    
784          if (True == rdp_retval)          if (ext_disc_reason >= 2)
785                    print_disconnect_reason(ext_disc_reason);
786    
787            if (deactivated)
788            {
789                    /* clean disconnect */
790                  return 0;                  return 0;
791            }
792          else          else
793                  return 2;          {
794                    if (ext_disc_reason == exDiscReasonAPIInitiatedDisconnect
795                        || ext_disc_reason == exDiscReasonAPIInitiatedLogoff)
796                    {
797                            /* not so clean disconnect, but nothing to worry about */
798                            return 0;
799                    }
800                    else
801                    {
802                            /* return error */
803                            return 2;
804                    }
805            }
806    
807  #endif  #endif
808    
# Line 647  xmalloc(int size) Line 908  xmalloc(int size)
908  void *  void *
909  xrealloc(void *oldmem, int size)  xrealloc(void *oldmem, int size)
910  {  {
911          void *mem = realloc(oldmem, size);          void *mem;
912    
913            if (size < 1)
914                    size = 1;
915            mem = realloc(oldmem, size);
916          if (mem == NULL)          if (mem == NULL)
917          {          {
918                  error("xrealloc %d\n", size);                  error("xrealloc %d\n", size);
# Line 732  hexdump(unsigned char *p, unsigned int l Line 997  hexdump(unsigned char *p, unsigned int l
997  }  }
998    
999  /*  /*
1000    input: src is the string we look in for needle    input: src is the string we look in for needle.
1001             Needle may be escaped by a backslash, in
1002             that case we ignore that particular needle.
1003    return value: returns next src pointer, for    return value: returns next src pointer, for
1004          succesive executions, like in a while loop          succesive executions, like in a while loop
1005          if retval is 0, then there are no more args.          if retval is 0, then there are no more args.
# Line 814  toupper_str(char *p) Line 1081  toupper_str(char *p)
1081  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1082    
1083  char *  char *
1084  ltoa(long N, int base)  l_to_a(long N, int base)
1085  {  {
1086          static char ret[LTOA_BUFSIZE];          static char ret[LTOA_BUFSIZE];
1087    
1088          register int i = 2;          char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
         long uarg;  
         char *tail, *head = ret, buf[LTOA_BUFSIZE];  
1089    
1090          if (36 < base || 2 > base)          register int divrem;
                 base = 10;  
1091    
1092          tail = &buf[LTOA_BUFSIZE - 1];          if (base < 36 || 2 > base)
1093          *tail-- = '\0';                  base = 10;
1094    
1095          if (10 == base && N < 0L)          if (N < 0)
1096          {          {
1097                  *head++ = '-';                  *head++ = '-';
1098                  uarg = -N;                  N = -N;
1099          }          }
         else  
                 uarg = N;  
1100    
1101          if (uarg)          tail = buf + sizeof(buf);
1102          {          *--tail = 0;
                 for (i = 1; uarg; ++i)  
                 {  
                         register ldiv_t r;  
1103    
1104                          r = ldiv(uarg, base);          do
1105                          *tail-- = (char) (r.rem + ((9L < r.rem) ? ('A' - 10L) : '0'));          {
1106                          uarg = r.quot;                  divrem = N % base;
1107                  }                  *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
1108                    N /= base;
1109          }          }
1110          else          while (N);
                 *tail-- = '0';  
1111    
1112          memcpy(head, ++tail, i);          strcpy(head, tail);
1113          return ret;          return ret;
1114  }  }
1115    
# Line 866  load_licence(unsigned char **data) Line 1125  load_licence(unsigned char **data)
1125          if (home == NULL)          if (home == NULL)
1126                  return -1;                  return -1;
1127    
1128          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1129          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1130    
1131          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
1132          if (fd == -1)          if (fd == -1)
# Line 893  save_licence(unsigned char *data, int le Line 1152  save_licence(unsigned char *data, int le
1152          if (home == NULL)          if (home == NULL)
1153                  return;                  return;
1154    
1155          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1156    
1157          sprintf(path, "%s/.rdesktop", home);          sprintf(path, "%s/.rdesktop", home);
1158          if ((mkdir(path, 0700) == -1) && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
# Line 904  save_licence(unsigned char *data, int le Line 1163  save_licence(unsigned char *data, int le
1163    
1164          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
1165    
1166          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1167          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
1168          strcpy(tmppath, path);          strcpy(tmppath, path);
1169          strcat(tmppath, ".new");          strcat(tmppath, ".new");
# Line 931  save_licence(unsigned char *data, int le Line 1190  save_licence(unsigned char *data, int le
1190          xfree(tmppath);          xfree(tmppath);
1191          xfree(path);          xfree(path);
1192  }  }
1193    
1194    /* Create the bitmap cache directory */
1195    BOOL
1196    rd_pstcache_mkdir(void)
1197    {
1198            char *home;
1199            char bmpcache_dir[256];
1200    
1201            home = getenv("HOME");
1202    
1203            if (home == NULL)
1204                    return False;
1205    
1206            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop");
1207    
1208            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1209            {
1210                    perror(bmpcache_dir);
1211                    return False;
1212            }
1213    
1214            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache");
1215    
1216            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1217            {
1218                    perror(bmpcache_dir);
1219                    return False;
1220            }
1221    
1222            return True;
1223    }
1224    
1225    /* open a file in the .rdesktop directory */
1226    int
1227    rd_open_file(char *filename)
1228    {
1229            char *home;
1230            char fn[256];
1231            int fd;
1232    
1233            home = getenv("HOME");
1234            if (home == NULL)
1235                    return -1;
1236            sprintf(fn, "%s/.rdesktop/%s", home, filename);
1237            fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
1238            if (fd == -1)
1239                    perror(fn);
1240            return fd;
1241    }
1242    
1243    /* close file */
1244    void
1245    rd_close_file(int fd)
1246    {
1247            close(fd);
1248    }
1249    
1250    /* read from file*/
1251    int
1252    rd_read_file(int fd, void *ptr, int len)
1253    {
1254            return read(fd, ptr, len);
1255    }
1256    
1257    /* write to file */
1258    int
1259    rd_write_file(int fd, void *ptr, int len)
1260    {
1261            return write(fd, ptr, len);
1262    }
1263    
1264    /* move file pointer */
1265    int
1266    rd_lseek_file(int fd, int offset)
1267    {
1268            return lseek(fd, offset, SEEK_SET);
1269    }
1270    
1271    /* do a write lock on a file */
1272    BOOL
1273    rd_lock_file(int fd, int start, int len)
1274    {
1275            struct flock lock;
1276    
1277            lock.l_type = F_WRLCK;
1278            lock.l_whence = SEEK_SET;
1279            lock.l_start = start;
1280            lock.l_len = len;
1281            if (fcntl(fd, F_SETLK, &lock) == -1)
1282                    return False;
1283            return True;
1284    }

Legend:
Removed from v.582  
changed lines
  Added in v.857

  ViewVC Help
Powered by ViewVC 1.1.26