/[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 474 by matthewc, Tue Sep 30 09:11:08 2003 UTC revision 636 by stargo, Sat Mar 13 12:08:18 2004 UTC
# Line 26  Line 26 
26  #include <sys/stat.h>           /* stat */  #include <sys/stat.h>           /* stat */
27  #include <sys/time.h>           /* gettimeofday */  #include <sys/time.h>           /* gettimeofday */
28  #include <sys/times.h>          /* times */  #include <sys/times.h>          /* times */
29    #include <ctype.h>              /* toupper */
30  #include <errno.h>  #include <errno.h>
31  #include "rdesktop.h"  #include "rdesktop.h"
32    
# Line 40  Line 41 
41  #include "crypto/md5.h"  #include "crypto/md5.h"
42  #endif  #endif
43    
44  char g_title[32] = "";  char g_title[64] = "";
45  char g_username[16];  char g_username[64];
46  char hostname[16];  char hostname[16];
47  char keymapname[16];  char keymapname[16];
48  int keylayout = 0x409;          /* Defaults to US keyboard layout */  int keylayout = 0x409;          /* Defaults to US keyboard layout */
49  int g_width = 800;              /* If width or height are reset to zero, the geometry will  
50                                     be fetched from _NET_WORKAREA */  int g_width = 800;              /* width is special: If 0, the
51                                       geometry will be fetched from
52                                       _NET_WORKAREA. If negative,
53                                       absolute value specifies the
54                                       percent of the whole screen. */
55  int g_height = 600;  int g_height = 600;
56  int tcp_port_rdp = TCP_PORT_RDP;  int tcp_port_rdp = TCP_PORT_RDP;
57  int g_server_bpp = 8;  int g_server_bpp = 8;
# Line 61  BOOL g_fullscreen = False; Line 66  BOOL g_fullscreen = False;
66  BOOL g_grab_keyboard = True;  BOOL g_grab_keyboard = True;
67  BOOL g_hide_decorations = False;  BOOL g_hide_decorations = False;
68  BOOL g_use_rdp5 = True;  BOOL g_use_rdp5 = True;
69    BOOL g_console_session = False;
70    BOOL g_numlock_sync = False;
71  extern BOOL g_owncolmap;  extern BOOL g_owncolmap;
72    extern BOOL g_ownbackstore;
73    extern uint32 g_embed_wnd;
74    
75    #ifdef WITH_RDPSND
76    BOOL g_rdpsnd = False;
77    #endif
78    
79    extern RDPDR_DEVICE g_rdpdr_device[];
80    extern uint32 g_num_devices;
81    
82  #ifdef RDP2VNC  #ifdef RDP2VNC
83  extern int rfb_port;  extern int rfb_port;
# Line 86  usage(char *program) Line 102  usage(char *program)
102          fprintf(stderr, "   -u: user name\n");          fprintf(stderr, "   -u: user name\n");
103          fprintf(stderr, "   -d: domain\n");          fprintf(stderr, "   -d: domain\n");
104          fprintf(stderr, "   -s: shell\n");          fprintf(stderr, "   -s: shell\n");
         fprintf(stderr, "   -S: caption button size (single application mode)\n");  
105          fprintf(stderr, "   -c: working directory\n");          fprintf(stderr, "   -c: working directory\n");
106          fprintf(stderr, "   -p: password (- to prompt)\n");          fprintf(stderr, "   -p: password (- to prompt)\n");
107          fprintf(stderr, "   -n: client hostname\n");          fprintf(stderr, "   -n: client hostname\n");
108          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");
109          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
110          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
111          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
112            fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
113          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
114          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
115          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
116          fprintf(stderr, "   -C: use private colour map\n");          fprintf(stderr, "   -C: use private colour map\n");
117            fprintf(stderr, "   -D: hide window manager decorations\n");
118          fprintf(stderr, "   -K: keep window manager key bindings\n");          fprintf(stderr, "   -K: keep window manager key bindings\n");
119            fprintf(stderr, "   -S: caption button size (single application mode)\n");
120          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
121          fprintf(stderr, "   -D: hide window manager decorations\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
122          fprintf(stderr, "   -a: server bpp\n");          fprintf(stderr, "   -X: embed into another window with a given id.\n");
123          fprintf(stderr, "   -4: Use RDP version 4\n");          fprintf(stderr, "   -a: connection colour depth\n");
124          fprintf(stderr, "   -5: Use RDP version 5 (default)\n");          fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");
125            fprintf(stderr,
126                    "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");
127            fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
128            fprintf(stderr,
129                    "         '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n");
130            fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");
131            fprintf(stderr,
132                    "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");
133            fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");
134            fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
135            fprintf(stderr,
136                    "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
137            fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");
138            fprintf(stderr, "                     remote would leave sound on server\n");
139            fprintf(stderr, "   -0: attach to console\n");
140            fprintf(stderr, "   -4: use RDP version 4\n");
141            fprintf(stderr, "   -5: use RDP version 5 (default)\n");
142  }  }
143    
144  static BOOL  static BOOL
# Line 197  main(int argc, char *argv[]) Line 232  main(int argc, char *argv[])
232          char server[64];          char server[64];
233          char fullhostname[64];          char fullhostname[64];
234          char domain[16];          char domain[16];
235          char password[16];          char password[64];
236          char shell[128];          char shell[128];
237          char directory[32];          char directory[32];
238          BOOL prompt_password, rdp_retval = False;          BOOL prompt_password, rdp_retval = False;
# Line 205  main(int argc, char *argv[]) Line 240  main(int argc, char *argv[])
240          uint32 flags;          uint32 flags;
241          char *p;          char *p;
242          int c;          int c;
243    
244          int username_option = 0;          int username_option = 0;
245    
246          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
247          prompt_password = False;          prompt_password = False;
248          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
249          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
250            g_embed_wnd = 0;
251    
252            g_num_devices = 0;
253    
254  #ifdef RDP2VNC  #ifdef RDP2VNC
255  #define VNCOPT "V:Q:"  #define VNCOPT "V:Q:"
# Line 218  main(int argc, char *argv[]) Line 257  main(int argc, char *argv[])
257  #define VNCOPT  #define VNCOPT
258  #endif  #endif
259    
260          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:fbBeEmCDKS:T:NX:a:r:045h?")) != -1)
261          {          {
262                  switch (c)                  switch (c)
263                  {                  {
# Line 249  main(int argc, char *argv[]) Line 288  main(int argc, char *argv[])
288                                  STRNCPY(shell, optarg, sizeof(shell));                                  STRNCPY(shell, optarg, sizeof(shell));
289                                  break;                                  break;
290    
                         case 'S':  
                                 if (!strcmp(optarg, "standard"))  
                                 {  
                                         g_win_button_size = 18;  
                                         break;  
                                 }  
   
                                 g_win_button_size = strtol(optarg, &p, 10);  
   
                                 if (*p)  
                                 {  
                                         error("invalid button size\n");  
                                         return 1;  
                                 }  
   
                                 break;  
   
291                          case 'c':                          case 'c':
292                                  STRNCPY(directory, optarg, sizeof(directory));                                  STRNCPY(directory, optarg, sizeof(directory));
293                                  break;                                  break;
# Line 295  main(int argc, char *argv[]) Line 317  main(int argc, char *argv[])
317                                  break;                                  break;
318    
319                          case 'g':                          case 'g':
320                                    g_fullscreen = False;
321                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
322                                  {                                  {
323                                          g_width = g_height = 0;                                          g_width = g_height = 0;
# Line 302  main(int argc, char *argv[]) Line 325  main(int argc, char *argv[])
325                                  }                                  }
326    
327                                  g_width = strtol(optarg, &p, 10);                                  g_width = strtol(optarg, &p, 10);
328                                    if (g_width <= 0)
329                                    {
330                                            error("invalid geometry\n");
331                                            return 1;
332                                    }
333    
334                                  if (*p == 'x')                                  if (*p == 'x')
335                                          g_height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, NULL, 10);
336    
337                                  if ((g_width == 0) || (g_height == 0))                                  if (g_height <= 0)
338                                  {                                  {
339                                          error("invalid geometry\n");                                          error("invalid geometry\n");
340                                          return 1;                                          return 1;
341                                  }                                  }
342    
343                                    if (*p == '%')
344                                            g_width = -g_width;
345    
346                                  break;                                  break;
347    
348                          case 'f':                          case 'f':
# Line 320  main(int argc, char *argv[]) Line 353  main(int argc, char *argv[])
353                                  g_orders = False;                                  g_orders = False;
354                                  break;                                  break;
355    
356                            case 'B':
357                                    g_ownbackstore = False;
358                                    break;
359    
360                          case 'e':                          case 'e':
361                                  g_encryption = False;                                  g_encryption = False;
362                                  break;                                  break;
# Line 334  main(int argc, char *argv[]) Line 371  main(int argc, char *argv[])
371                                  g_owncolmap = True;                                  g_owncolmap = True;
372                                  break;                                  break;
373    
374                            case 'D':
375                                    g_hide_decorations = True;
376                                    break;
377    
378                          case 'K':                          case 'K':
379                                  g_grab_keyboard = False;                                  g_grab_keyboard = False;
380                                  break;                                  break;
381    
382                            case 'S':
383                                    if (!strcmp(optarg, "standard"))
384                                    {
385                                            g_win_button_size = 18;
386                                            break;
387                                    }
388    
389                                    g_win_button_size = strtol(optarg, &p, 10);
390    
391                                    if (*p)
392                                    {
393                                            error("invalid button size\n");
394                                            return 1;
395                                    }
396    
397                                    break;
398    
399                          case 'T':                          case 'T':
400                                  STRNCPY(g_title, optarg, sizeof(g_title));                                  STRNCPY(g_title, optarg, sizeof(g_title));
401                                  break;                                  break;
402    
403                          case 'D':                          case 'N':
404                                  g_hide_decorations = True;                                  g_numlock_sync = True;
405                                  break;                                  break;
406    
407                            case 'X':
408                                    g_embed_wnd = strtol(optarg, NULL, 10);
409                                    break;
410                                    
411                          case 'a':                          case 'a':
412                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_bpp = strtol(optarg, NULL, 10);
413                                  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 356  main(int argc, char *argv[]) Line 418  main(int argc, char *argv[])
418                                  }                                  }
419                                  break;                                  break;
420    
421                            case 'r':
422    
423                                    if (strncmp("sound", optarg, 5) == 0)
424                                    {
425                                            optarg += 5;
426    
427                                            if (*optarg == ':')
428                                            {
429                                                    *optarg++;
430                                                    while ((p = next_arg(optarg, ',')))
431                                                    {
432                                                            if (strncmp("remote", optarg, 6) == 0)
433                                                                    flags |= RDP_LOGON_LEAVE_AUDIO;
434    
435                                                            if (strncmp("local", optarg, 5) == 0)
436    #ifdef WITH_RDPSND
437                                                                    g_rdpsnd = True;
438    #else
439                                                                    warning("Not compiled with sound support");
440    #endif
441    
442                                                            if (strncmp("off", optarg, 3) == 0)
443                                                                    g_rdpsnd = False;
444    
445                                                            optarg = p;
446                                                    }
447                                            }
448                                            else
449                                            {
450    #ifdef WITH_RDPSND
451                                                    g_rdpsnd = True;
452    #else
453                                                    warning("Not compiled with sound support");
454    #endif
455                                            }
456                                    }
457                                    else if (strncmp("disk", optarg, 4) == 0)
458                                    {
459                                            /* -r disk:h:=/mnt/floppy */
460                                            disk_enum_devices(&g_num_devices, optarg + 4);
461                                    }
462                                    else if (strncmp("comport", optarg, 7) == 0)
463                                    {
464                                            serial_enum_devices(&g_num_devices, optarg + 7);
465                                    }
466                                    else if (strncmp("lptport", optarg, 7) == 0)
467                                    {
468                                            parallel_enum_devices(&g_num_devices, optarg + 7);
469                                    }
470                                    else if (strncmp("printer", optarg, 7) == 0)
471                                    {
472                                            printer_enum_devices(&g_num_devices, optarg + 7);
473                                    }
474                                    else
475                                    {
476                                            warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");
477                                    }
478                                    break;
479    
480                            case '0':
481                                    g_console_session = True;
482                                    break;
483    
484                          case '4':                          case '4':
485                                  g_use_rdp5 = False;                                  g_use_rdp5 = False;
486                                  break;                                  break;
# Line 372  main(int argc, char *argv[]) Line 497  main(int argc, char *argv[])
497                  }                  }
498          }          }
499    
500          if (argc - optind < 1)          if (argc - optind != 1)
501          {          {
502                  usage(argv[0]);                  usage(argv[0]);
503                  return 1;                  return 1;
# Line 426  main(int argc, char *argv[]) Line 551  main(int argc, char *argv[])
551                  return 1;                  return 1;
552    
553  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
554          rdpsnd_init();          if (g_rdpsnd)
555                    rdpsnd_init();
556  #endif  #endif
557          /* rdpdr_init(); */          rdpdr_init();
558    
559          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
560                  return 1;                  return 1;
# Line 618  unimpl(char *format, ...) Line 744  unimpl(char *format, ...)
744    
745  /* produce a hex dump */  /* produce a hex dump */
746  void  void
747  hexdump(unsigned char *p, int len)  hexdump(unsigned char *p, unsigned int len)
748  {  {
749          unsigned char *line = p;          unsigned char *line = p;
750          int i, thisline, offset = 0;          int i, thisline, offset = 0;
# Line 645  hexdump(unsigned char *p, int len) Line 771  hexdump(unsigned char *p, int len)
771          }          }
772  }  }
773    
774    /*
775      input: src is the string we look in for needle.
776             Needle may be escaped by a backslash, in
777             that case we ignore that particular needle.
778      return value: returns next src pointer, for
779            succesive executions, like in a while loop
780            if retval is 0, then there are no more args.
781      pitfalls:
782            src is modified. 0x00 chars are inserted to
783            terminate strings.
784            return val, points on the next val chr after ins
785            0x00
786    
787            example usage:
788            while( (pos = next_arg( optarg, ',')) ){
789                    printf("%s\n",optarg);
790                    optarg=pos;
791            }
792    
793    */
794    char *
795    next_arg(char *src, char needle)
796    {
797            char *nextval;
798            char *p;
799            char *mvp = 0;
800    
801            /* EOS */
802            if (*src == (char) 0x00)
803                    return 0;
804    
805            p = src;
806            /*  skip escaped needles */
807            while ((nextval = strchr(p, needle)))
808            {
809                    mvp = nextval - 1;
810                    /* found backslashed needle */
811                    if (*mvp == '\\' && (mvp > src))
812                    {
813                            /* move string one to the left */
814                            while (*(mvp + 1) != (char) 0x00)
815                            {
816                                    *mvp = *(mvp + 1);
817                                    *mvp++;
818                            }
819                            *mvp = (char) 0x00;
820                            p = nextval;
821                    }
822                    else
823                    {
824                            p = nextval + 1;
825                            break;
826                    }
827    
828            }
829    
830            /* more args available */
831            if (nextval)
832            {
833                    *nextval = (char) 0x00;
834                    return ++nextval;
835            }
836    
837            /* no more args after this, jump to EOS */
838            nextval = src + strlen(src);
839            return nextval;
840    }
841    
842    
843    void
844    toupper_str(char *p)
845    {
846            while (*p)
847            {
848                    if ((*p >= 'a') && (*p <= 'z'))
849                            *p = toupper((int) *p);
850                    p++;
851            }
852    }
853    
854    
855    /* not all clibs got ltoa */
856    #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
857    
858    char *
859    l_to_a(long N, int base)
860    {
861            static char ret[LTOA_BUFSIZE];
862    
863            char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
864    
865            register int divrem;
866    
867            if (base < 36 || 2 > base)
868                    base = 10;
869    
870            if (N < 0)
871            {
872                    *head++ = '-';
873                    N = -N;
874            }
875    
876            tail = buf + sizeof(buf);
877            *--tail = 0;
878    
879            do
880            {
881                    divrem = N % base;
882                    *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
883                    N /= base;
884            }
885            while (N);
886    
887            strcpy(head, tail);
888            return ret;
889    }
890    
891    
892  int  int
893  load_licence(unsigned char **data)  load_licence(unsigned char **data)

Legend:
Removed from v.474  
changed lines
  Added in v.636

  ViewVC Help
Powered by ViewVC 1.1.26