/[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 427 by forsberg, Thu Jun 19 11:51:18 2003 UTC revision 567 by matthewc, Wed Jan 21 11:08:39 2004 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-2004
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 40  Line 40 
40  #include "crypto/md5.h"  #include "crypto/md5.h"
41  #endif  #endif
42    
43  char title[32] = "";  char g_title[64] = "";
44  char username[16];  char g_username[64];
45  char hostname[16];  char hostname[16];
46  char keymapname[16];  char keymapname[16];
47  int keylayout = 0x409;          /* Defaults to US keyboard layout */  int keylayout = 0x409;          /* Defaults to US keyboard layout */
48  int width = 800;                /* If width or height are reset to zero, the geometry will  
49                                     be fetched from _NET_WORKAREA */  int g_width = 800;              /* width is special: If 0, the
50  int height = 600;                                     geometry will be fetched from
51                                       _NET_WORKAREA. If negative,
52                                       absolute value specifies the
53                                       percent of the whole screen. */
54    int g_height = 600;
55  int tcp_port_rdp = TCP_PORT_RDP;  int tcp_port_rdp = TCP_PORT_RDP;
56  int server_bpp = 8;  int g_server_bpp = 8;
57  int win_button_size = 0;        /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
58  BOOL bitmap_compression = True;  BOOL g_bitmap_compression = True;
59  BOOL sendmotion = True;  BOOL g_sendmotion = True;
60  BOOL orders = True;  BOOL g_orders = True;
61  BOOL encryption = True;  BOOL g_encryption = True;
62  BOOL packet_encryption = True;  BOOL packet_encryption = True;
63  BOOL desktop_save = True;  BOOL g_desktop_save = True;
64  BOOL fullscreen = False;  BOOL g_fullscreen = False;
65  BOOL grab_keyboard = True;  BOOL g_grab_keyboard = True;
66  BOOL hide_decorations = False;  BOOL g_hide_decorations = False;
67  BOOL use_rdp5 = False;  BOOL g_use_rdp5 = True;
68  extern BOOL owncolmap;  BOOL g_console_session = False;
69    BOOL g_numlock_sync = False;
70    extern BOOL g_owncolmap;
71    
72    #ifdef WITH_RDPSND
73    BOOL g_rdpsnd = False;
74    #endif
75    
76  #ifdef RDP2VNC  #ifdef RDP2VNC
77  extern int rfb_port;  extern int rfb_port;
# Line 81  usage(char *program) Line 91  usage(char *program)
91          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
92  #ifdef RDP2VNC  #ifdef RDP2VNC
93          fprintf(stderr, "   -V: vnc port\n");          fprintf(stderr, "   -V: vnc port\n");
94          fprintf(stderr, "   -E: defer time (ms)\n");          fprintf(stderr, "   -Q: defer time (ms)\n");
95  #endif  #endif
96          fprintf(stderr, "   -u: user name\n");          fprintf(stderr, "   -u: user name\n");
97          fprintf(stderr, "   -d: domain\n");          fprintf(stderr, "   -d: domain\n");
98          fprintf(stderr, "   -s: shell\n");          fprintf(stderr, "   -s: shell\n");
         fprintf(stderr, "   -S: caption button size (single application mode)\n");  
99          fprintf(stderr, "   -c: working directory\n");          fprintf(stderr, "   -c: working directory\n");
100          fprintf(stderr, "   -p: password (- to prompt)\n");          fprintf(stderr, "   -p: password (- to prompt)\n");
101          fprintf(stderr, "   -n: client hostname\n");          fprintf(stderr, "   -n: client hostname\n");
102          fprintf(stderr, "   -k: keyboard layout on terminal server (us,sv,gr,etc.)\n");          fprintf(stderr, "   -k: keyboard layout on server (en-us, de, sv, etc.)\n");
103          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
104          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
105          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
106          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
107          fprintf(stderr, "   -E: disable encryption of everything but the logon packet\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
108          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
109          fprintf(stderr, "   -C: use private colour map\n");          fprintf(stderr, "   -C: use private colour map\n");
110            fprintf(stderr, "   -D: hide window manager decorations\n");
111          fprintf(stderr, "   -K: keep window manager key bindings\n");          fprintf(stderr, "   -K: keep window manager key bindings\n");
112            fprintf(stderr, "   -S: caption button size (single application mode)\n");
113          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
114          fprintf(stderr, "   -D: hide window manager decorations\n");          fprintf(stderr, "   -N: enable numlock synchronisation\n");
115          fprintf(stderr, "   -a: server bpp\n");          fprintf(stderr, "   -a: connection colour depth\n");
116          fprintf(stderr, "   -5: Use RDP5 (EXPERIMENTAL!)\n");          fprintf(stderr, "   -r: enable specified device redirection (currently: sound)\n");
117            fprintf(stderr, "   -0: attach to console\n");
118            fprintf(stderr, "   -4: use RDP version 4\n");
119            fprintf(stderr, "   -5: use RDP version 5 (default)\n");
120  }  }
121    
122  static BOOL  static BOOL
# Line 141  read_password(char *password, int size) Line 155  read_password(char *password, int size)
155          return ret;          return ret;
156  }  }
157    
158    static void
159    parse_server_and_port(char *server)
160    {
161            char *p;
162    #ifdef IPv6
163            int addr_colons;
164    #endif
165    
166    #ifdef IPv6
167            p = server;
168            addr_colons = 0;
169            while (*p)
170                    if (*p++ == ':')
171                            addr_colons++;
172            if (addr_colons >= 2)
173            {
174                    /* numeric IPv6 style address format - [1:2:3::4]:port */
175                    p = strchr(server, ']');
176                    if (*server == '[' && p != NULL)
177                    {
178                            if (*(p + 1) == ':' && *(p + 2) != '\0')
179                                    tcp_port_rdp = strtol(p + 2, NULL, 10);
180                            /* remove the port number and brackets from the address */
181                            *p = '\0';
182                            strncpy(server, server + 1, strlen(server));
183                    }
184            }
185            else
186            {
187                    /* dns name or IPv4 style address format - server.example.com:port or 1.2.3.4:port */
188                    p = strchr(server, ':');
189                    if (p != NULL)
190                    {
191                            tcp_port_rdp = strtol(p + 1, NULL, 10);
192                            *p = 0;
193                    }
194            }
195    #else /* no IPv6 support */
196            p = strchr(server, ':');
197            if (p != NULL)
198            {
199                    tcp_port_rdp = strtol(p + 1, NULL, 10);
200                    *p = 0;
201            }
202    #endif /* IPv6 */
203    
204    }
205    
206  /* Client program */  /* Client program */
207  int  int
208  main(int argc, char *argv[])  main(int argc, char *argv[])
# Line 148  main(int argc, char *argv[]) Line 210  main(int argc, char *argv[])
210          char server[64];          char server[64];
211          char fullhostname[64];          char fullhostname[64];
212          char domain[16];          char domain[16];
213          char password[16];          char password[64];
214          char shell[128];          char shell[128];
215          char directory[32];          char directory[32];
216          BOOL prompt_password, rdp_retval = False;          BOOL prompt_password, rdp_retval = False;
# Line 164  main(int argc, char *argv[]) Line 226  main(int argc, char *argv[])
226          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
227    
228  #ifdef RDP2VNC  #ifdef RDP2VNC
229  #define VNCOPT "V:E:"  #define VNCOPT "V:Q:"
230  #else  #else
231  #define VNCOPT  #define VNCOPT
232  #endif  #endif
233    
234          while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbeEmCKT:Dh?54")) != -1)          while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbeEmCDKS:T:Na:r:045h?")) != -1)
235          {          {
236                  switch (c)                  switch (c)
237                  {                  {
# Line 180  main(int argc, char *argv[]) Line 242  main(int argc, char *argv[])
242                                          rfb_port += 5900;                                          rfb_port += 5900;
243                                  break;                                  break;
244    
245                          case 'E':                          case 'Q':
246                                  defer_time = strtol(optarg, NULL, 10);                                  defer_time = strtol(optarg, NULL, 10);
247                                  if (defer_time < 0)                                  if (defer_time < 0)
248                                          defer_time = 0;                                          defer_time = 0;
# Line 188  main(int argc, char *argv[]) Line 250  main(int argc, char *argv[])
250  #endif  #endif
251    
252                          case 'u':                          case 'u':
253                                  STRNCPY(username, optarg, sizeof(username));                                  STRNCPY(g_username, optarg, sizeof(g_username));
254                                  username_option = 1;                                  username_option = 1;
255                                  break;                                  break;
256    
# Line 200  main(int argc, char *argv[]) Line 262  main(int argc, char *argv[])
262                                  STRNCPY(shell, optarg, sizeof(shell));                                  STRNCPY(shell, optarg, sizeof(shell));
263                                  break;                                  break;
264    
                         case 'S':  
                                 if (!strcmp(optarg, "standard"))  
                                 {  
                                         win_button_size = 18;  
                                         break;  
                                 }  
   
                                 win_button_size = strtol(optarg, &p, 10);  
   
                                 if (*p)  
                                 {  
                                         error("invalid button size\n");  
                                         return 1;  
                                 }  
   
                                 break;  
   
265                          case 'c':                          case 'c':
266                                  STRNCPY(directory, optarg, sizeof(directory));                                  STRNCPY(directory, optarg, sizeof(directory));
267                                  break;                                  break;
# Line 246  main(int argc, char *argv[]) Line 291  main(int argc, char *argv[])
291                                  break;                                  break;
292    
293                          case 'g':                          case 'g':
294                                    g_fullscreen = False;
295                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
296                                  {                                  {
297                                          width = height = 0;                                          g_width = g_height = 0;
298                                          break;                                          break;
299                                  }                                  }
300    
301                                  width = strtol(optarg, &p, 10);                                  g_width = strtol(optarg, &p, 10);
302                                    if (g_width <= 0)
303                                    {
304                                            error("invalid geometry\n");
305                                            return 1;
306                                    }
307    
308                                  if (*p == 'x')                                  if (*p == 'x')
309                                          height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, NULL, 10);
310    
311                                  if ((width == 0) || (height == 0))                                  if (g_height <= 0)
312                                  {                                  {
313                                          error("invalid geometry\n");                                          error("invalid geometry\n");
314                                          return 1;                                          return 1;
315                                  }                                  }
316    
317                                    if (*p == '%')
318                                            g_width = -g_width;
319    
320                                  break;                                  break;
321    
322                          case 'f':                          case 'f':
323                                  fullscreen = True;                                  g_fullscreen = True;
324                                  break;                                  break;
325    
326                          case 'b':                          case 'b':
327                                  orders = False;                                  g_orders = False;
328                                  break;                                  break;
329    
330                          case 'e':                          case 'e':
331                                  encryption = False;                                  g_encryption = False;
332                                  break;                                  break;
333                          case 'E':                          case 'E':
334                                  packet_encryption = False;                                  packet_encryption = False;
335                                  break;                                  break;
336                          case 'm':                          case 'm':
337                                  sendmotion = False;                                  g_sendmotion = False;
338                                  break;                                  break;
339    
340                          case 'C':                          case 'C':
341                                  owncolmap = True;                                  g_owncolmap = True;
342                                    break;
343    
344                            case 'D':
345                                    g_hide_decorations = True;
346                                  break;                                  break;
347    
348                          case 'K':                          case 'K':
349                                  grab_keyboard = False;                                  g_grab_keyboard = False;
350                                    break;
351    
352                            case 'S':
353                                    if (!strcmp(optarg, "standard"))
354                                    {
355                                            g_win_button_size = 18;
356                                            break;
357                                    }
358    
359                                    g_win_button_size = strtol(optarg, &p, 10);
360    
361                                    if (*p)
362                                    {
363                                            error("invalid button size\n");
364                                            return 1;
365                                    }
366    
367                                  break;                                  break;
368    
369                          case 'T':                          case 'T':
370                                  STRNCPY(title, optarg, sizeof(title));                                  STRNCPY(g_title, optarg, sizeof(g_title));
371                                  break;                                  break;
372    
373                          case 'D':                          case 'N':
374                                  hide_decorations = True;                                  g_numlock_sync = True;
375                                  break;                                  break;
376    
377                          case 'a':                          case 'a':
378                                  server_bpp = strtol(optarg, NULL, 10);                                  g_server_bpp = strtol(optarg, NULL, 10);
379                                  if (server_bpp != 8 && server_bpp != 16 && server_bpp != 15                                  if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15
380                                      && server_bpp != 24)                                      && g_server_bpp != 24)
381                                  {                                  {
382                                          error("invalid server bpp\n");                                          error("invalid server bpp\n");
383                                          return 1;                                          return 1;
384                                  }                                  }
385                                  break;                                  break;
386    
387                            case 'r':
388                                    if (!strcmp(optarg, "sound"))
389    #ifdef WITH_RDPSND
390                                            g_rdpsnd = True;
391    #else
392                                            warning("Not compiled with sound support");
393    #endif
394                                    break;
395    
396                            case '0':
397                                    g_console_session = True;
398                                    break;
399    
400                            case '4':
401                                    g_use_rdp5 = False;
402                                    break;
403    
404                          case '5':                          case '5':
405                                  use_rdp5 = True;                                  g_use_rdp5 = True;
406                                  break;                                  break;
407    
408                          case 'h':                          case 'h':
409                          case '?':                          case '?':
410                          default:                          default:
# Line 325  main(int argc, char *argv[]) Line 420  main(int argc, char *argv[])
420          }          }
421    
422          STRNCPY(server, argv[optind], sizeof(server));          STRNCPY(server, argv[optind], sizeof(server));
423          p = strchr(server, ':');          parse_server_and_port(server);
         if (p != NULL)  
         {  
                 tcp_port_rdp = strtol(p + 1, NULL, 10);  
                 *p = 0;  
         }  
424    
425          if (!username_option)          if (!username_option)
426          {          {
# Line 341  main(int argc, char *argv[]) Line 431  main(int argc, char *argv[])
431                          return 1;                          return 1;
432                  }                  }
433    
434                  STRNCPY(username, pw->pw_name, sizeof(username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
435          }          }
436    
437          if (hostname[0] == 0)          if (hostname[0] == 0)
# Line 362  main(int argc, char *argv[]) Line 452  main(int argc, char *argv[])
452          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
453                  flags |= RDP_LOGON_AUTO;                  flags |= RDP_LOGON_AUTO;
454    
455          if (title[0] == 0)          if (g_title[0] == 0)
456          {          {
457                  strcpy(title, "rdesktop - ");                  strcpy(g_title, "rdesktop - ");
458                  strncat(title, server, sizeof(title) - sizeof("rdesktop - "));                  strncat(g_title, server, sizeof(g_title) - sizeof("rdesktop - "));
459          }          }
460    
461  #ifdef RDP2VNC  #ifdef RDP2VNC
# Line 376  main(int argc, char *argv[]) Line 466  main(int argc, char *argv[])
466          if (!ui_init())          if (!ui_init())
467                  return 1;                  return 1;
468    
469          ipc_init();             // Must be run after ui_init, we need X to be setup.  #ifdef WITH_RDPSND
470            if (g_rdpsnd)
471          if (use_rdp5)                  rdpsnd_init();
472                  cliprdr_init(); // FIXME: Should perhaps be integrated into the channel management code?  #endif
473            /* rdpdr_init(); */
474    
475          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
476                  return 1;                  return 1;
477    
478          /* By setting encryption to False here, we have an encrypted login          /* By setting encryption to False here, we have an encrypted login
479             packet but unencrypted transfer of other packets */             packet but unencrypted transfer of other packets */
480          if (!packet_encryption)          if (!packet_encryption)
481                  encryption = False;                  g_encryption = False;
482    
483    
484          DEBUG(("Connection successful.\n"));          DEBUG(("Connection successful.\n"));
# Line 403  main(int argc, char *argv[]) Line 494  main(int argc, char *argv[])
494          rdp_disconnect();          rdp_disconnect();
495          ui_deinit();          ui_deinit();
496    
497          if (True == rdp_retval)          if (True == rdp_retval)
498                  return 0;                  return 0;
499          else          else
500                  return 2;                  return 2;

Legend:
Removed from v.427  
changed lines
  Added in v.567

  ViewVC Help
Powered by ViewVC 1.1.26