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

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

revision 482 by matthewc, Thu Oct 9 04:21:19 2003 UTC revision 637 by stargo, Mon Mar 15 14:49:12 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 45  char g_username[64]; Line 46  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 62  BOOL g_grab_keyboard = True; Line 67  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;  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    uint32 g_rdp5_performanceflags = RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
75    
76    #ifdef WITH_RDPSND
77    BOOL g_rdpsnd = False;
78    #endif
79    
80    extern RDPDR_DEVICE g_rdpdr_device[];
81    extern uint32 g_num_devices;
82    
83  #ifdef RDP2VNC  #ifdef RDP2VNC
84  extern int rfb_port;  extern int rfb_port;
# Line 87  usage(char *program) Line 103  usage(char *program)
103          fprintf(stderr, "   -u: user name\n");          fprintf(stderr, "   -u: user name\n");
104          fprintf(stderr, "   -d: domain\n");          fprintf(stderr, "   -d: domain\n");
105          fprintf(stderr, "   -s: shell\n");          fprintf(stderr, "   -s: shell\n");
         fprintf(stderr, "   -S: caption button size (single application mode)\n");  
106          fprintf(stderr, "   -c: working directory\n");          fprintf(stderr, "   -c: working directory\n");
107          fprintf(stderr, "   -p: password (- to prompt)\n");          fprintf(stderr, "   -p: password (- to prompt)\n");
108          fprintf(stderr, "   -n: client hostname\n");          fprintf(stderr, "   -n: client hostname\n");
109          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");
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");
117          fprintf(stderr, "   -C: use private colour map\n");          fprintf(stderr, "   -C: use private colour map\n");
118            fprintf(stderr, "   -D: hide window manager decorations\n");
119          fprintf(stderr, "   -K: keep window manager key bindings\n");          fprintf(stderr, "   -K: keep window manager key bindings\n");
120            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, "   -D: hide window manager decorations\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
123          fprintf(stderr, "   -a: server bpp\n");          fprintf(stderr, "   -X: embed into another window with a given id.\n");
124            fprintf(stderr, "   -a: connection colour depth\n");
125            fprintf(stderr, "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex number)\n");
126            fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");
127            fprintf(stderr,
128                    "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");
129            fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
130            fprintf(stderr,
131                    "         '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n");
132            fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");
133            fprintf(stderr,
134                    "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");
135            fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");
136            fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
137            fprintf(stderr,
138                    "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
139            fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");
140            fprintf(stderr, "                     remote would leave sound on server\n");
141          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
142          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
143          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          fprintf(stderr, "   -5: use RDP version 5 (default)\n");
# Line 207  main(int argc, char *argv[]) Line 242  main(int argc, char *argv[])
242          uint32 flags;          uint32 flags;
243          char *p;          char *p;
244          int c;          int c;
245    
246          int username_option = 0;          int username_option = 0;
247    
248          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
249          prompt_password = False;          prompt_password = False;
250          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
251          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
252            g_embed_wnd = 0;
253    
254            g_num_devices = 0;
255    
256  #ifdef RDP2VNC  #ifdef RDP2VNC
257  #define VNCOPT "V:Q:"  #define VNCOPT "V:Q:"
# Line 220  main(int argc, char *argv[]) Line 259  main(int argc, char *argv[])
259  #define VNCOPT  #define VNCOPT
260  #endif  #endif
261    
262          while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbeEmCKT:D045h?")) != -1)          while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:r:045h?")) != -1)
263          {          {
264                  switch (c)                  switch (c)
265                  {                  {
# Line 251  main(int argc, char *argv[]) Line 290  main(int argc, char *argv[])
290                                  STRNCPY(shell, optarg, sizeof(shell));                                  STRNCPY(shell, optarg, sizeof(shell));
291                                  break;                                  break;
292    
                         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;  
   
293                          case 'c':                          case 'c':
294                                  STRNCPY(directory, optarg, sizeof(directory));                                  STRNCPY(directory, optarg, sizeof(directory));
295                                  break;                                  break;
# Line 297  main(int argc, char *argv[]) Line 319  main(int argc, char *argv[])
319                                  break;                                  break;
320    
321                          case 'g':                          case 'g':
322                                    g_fullscreen = False;
323                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
324                                  {                                  {
325                                          g_width = g_height = 0;                                          g_width = g_height = 0;
# Line 304  main(int argc, char *argv[]) Line 327  main(int argc, char *argv[])
327                                  }                                  }
328    
329                                  g_width = strtol(optarg, &p, 10);                                  g_width = strtol(optarg, &p, 10);
330                                    if (g_width <= 0)
331                                    {
332                                            error("invalid geometry\n");
333                                            return 1;
334                                    }
335    
336                                  if (*p == 'x')                                  if (*p == 'x')
337                                          g_height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, NULL, 10);
338    
339                                  if ((g_width == 0) || (g_height == 0))                                  if (g_height <= 0)
340                                  {                                  {
341                                          error("invalid geometry\n");                                          error("invalid geometry\n");
342                                          return 1;                                          return 1;
343                                  }                                  }
344    
345                                    if (*p == '%')
346                                            g_width = -g_width;
347    
348                                  break;                                  break;
349    
350                          case 'f':                          case 'f':
# Line 322  main(int argc, char *argv[]) Line 355  main(int argc, char *argv[])
355                                  g_orders = False;                                  g_orders = False;
356                                  break;                                  break;
357    
358                            case 'B':
359                                    g_ownbackstore = False;
360                                    break;
361    
362                          case 'e':                          case 'e':
363                                  g_encryption = False;                                  g_encryption = False;
364                                  break;                                  break;
# Line 336  main(int argc, char *argv[]) Line 373  main(int argc, char *argv[])
373                                  g_owncolmap = True;                                  g_owncolmap = True;
374                                  break;                                  break;
375    
376                            case 'D':
377                                    g_hide_decorations = True;
378                                    break;
379    
380                          case 'K':                          case 'K':
381                                  g_grab_keyboard = False;                                  g_grab_keyboard = False;
382                                  break;                                  break;
383    
384                            case 'S':
385                                    if (!strcmp(optarg, "standard"))
386                                    {
387                                            g_win_button_size = 18;
388                                            break;
389                                    }
390    
391                                    g_win_button_size = strtol(optarg, &p, 10);
392    
393                                    if (*p)
394                                    {
395                                            error("invalid button size\n");
396                                            return 1;
397                                    }
398    
399                                    break;
400    
401                          case 'T':                          case 'T':
402                                  STRNCPY(g_title, optarg, sizeof(g_title));                                  STRNCPY(g_title, optarg, sizeof(g_title));
403                                  break;                                  break;
404    
405                          case 'D':                          case 'N':
406                                  g_hide_decorations = True;                                  g_numlock_sync = True;
407                                  break;                                  break;
408    
409                            case 'X':
410                                    g_embed_wnd = strtol(optarg, NULL, 10);
411                                    break;
412                                    
413                          case 'a':                          case 'a':
414                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_bpp = strtol(optarg, NULL, 10);
415                                  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 358  main(int argc, char *argv[]) Line 420  main(int argc, char *argv[])
420                                  }                                  }
421                                  break;                                  break;
422    
423                            case 'x':
424                                    
425                                    if (strncmp("modem", optarg, 1) == 0)
426                                    {
427                                            g_rdp5_performanceflags = RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
428                                    }
429                                    else if (strncmp("broadband", optarg, 1) == 0)
430                                    {
431                                            g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
432                                    }
433                                    else if (strncmp("lan", optarg, 1) == 0)
434                                    {
435                                            g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
436                                    }
437                                    else
438                                    {
439                                            g_rdp5_performanceflags = strtol(optarg, NULL, 16);
440                                    }
441                                    break;
442                                    
443                            case 'r':
444    
445                                    if (strncmp("sound", optarg, 5) == 0)
446                                    {
447                                            optarg += 5;
448    
449                                            if (*optarg == ':')
450                                            {
451                                                    *optarg++;
452                                                    while ((p = next_arg(optarg, ',')))
453                                                    {
454                                                            if (strncmp("remote", optarg, 6) == 0)
455                                                                    flags |= RDP_LOGON_LEAVE_AUDIO;
456    
457                                                            if (strncmp("local", optarg, 5) == 0)
458    #ifdef WITH_RDPSND
459                                                                    g_rdpsnd = True;
460    #else
461                                                                    warning("Not compiled with sound support");
462    #endif
463    
464                                                            if (strncmp("off", optarg, 3) == 0)
465                                                                    g_rdpsnd = False;
466    
467                                                            optarg = p;
468                                                    }
469                                            }
470                                            else
471                                            {
472    #ifdef WITH_RDPSND
473                                                    g_rdpsnd = True;
474    #else
475                                                    warning("Not compiled with sound support");
476    #endif
477                                            }
478                                    }
479                                    else if (strncmp("disk", optarg, 4) == 0)
480                                    {
481                                            /* -r disk:h:=/mnt/floppy */
482                                            disk_enum_devices(&g_num_devices, optarg + 4);
483                                    }
484                                    else if (strncmp("comport", optarg, 7) == 0)
485                                    {
486                                            serial_enum_devices(&g_num_devices, optarg + 7);
487                                    }
488                                    else if (strncmp("lptport", optarg, 7) == 0)
489                                    {
490                                            parallel_enum_devices(&g_num_devices, optarg + 7);
491                                    }
492                                    else if (strncmp("printer", optarg, 7) == 0)
493                                    {
494                                            printer_enum_devices(&g_num_devices, optarg + 7);
495                                    }
496                                    else
497                                    {
498                                            warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");
499                                    }
500                                    break;
501    
502                          case '0':                          case '0':
503                                  g_console_session = True;                                  g_console_session = True;
504                                  break;                                  break;
# Line 378  main(int argc, char *argv[]) Line 519  main(int argc, char *argv[])
519                  }                  }
520          }          }
521    
522          if (argc - optind < 1)          if (argc - optind != 1)
523          {          {
524                  usage(argv[0]);                  usage(argv[0]);
525                  return 1;                  return 1;
# Line 432  main(int argc, char *argv[]) Line 573  main(int argc, char *argv[])
573                  return 1;                  return 1;
574    
575  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
576          rdpsnd_init();          if (g_rdpsnd)
577                    rdpsnd_init();
578  #endif  #endif
579          /* rdpdr_init(); */          rdpdr_init();
580    
581          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
582                  return 1;                  return 1;
# Line 624  unimpl(char *format, ...) Line 766  unimpl(char *format, ...)
766    
767  /* produce a hex dump */  /* produce a hex dump */
768  void  void
769  hexdump(unsigned char *p, int len)  hexdump(unsigned char *p, unsigned int len)
770  {  {
771          unsigned char *line = p;          unsigned char *line = p;
772          int i, thisline, offset = 0;          int i, thisline, offset = 0;
# Line 651  hexdump(unsigned char *p, int len) Line 793  hexdump(unsigned char *p, int len)
793          }          }
794  }  }
795    
796    /*
797      input: src is the string we look in for needle.
798             Needle may be escaped by a backslash, in
799             that case we ignore that particular needle.
800      return value: returns next src pointer, for
801            succesive executions, like in a while loop
802            if retval is 0, then there are no more args.
803      pitfalls:
804            src is modified. 0x00 chars are inserted to
805            terminate strings.
806            return val, points on the next val chr after ins
807            0x00
808    
809            example usage:
810            while( (pos = next_arg( optarg, ',')) ){
811                    printf("%s\n",optarg);
812                    optarg=pos;
813            }
814    
815    */
816    char *
817    next_arg(char *src, char needle)
818    {
819            char *nextval;
820            char *p;
821            char *mvp = 0;
822    
823            /* EOS */
824            if (*src == (char) 0x00)
825                    return 0;
826    
827            p = src;
828            /*  skip escaped needles */
829            while ((nextval = strchr(p, needle)))
830            {
831                    mvp = nextval - 1;
832                    /* found backslashed needle */
833                    if (*mvp == '\\' && (mvp > src))
834                    {
835                            /* move string one to the left */
836                            while (*(mvp + 1) != (char) 0x00)
837                            {
838                                    *mvp = *(mvp + 1);
839                                    *mvp++;
840                            }
841                            *mvp = (char) 0x00;
842                            p = nextval;
843                    }
844                    else
845                    {
846                            p = nextval + 1;
847                            break;
848                    }
849    
850            }
851    
852            /* more args available */
853            if (nextval)
854            {
855                    *nextval = (char) 0x00;
856                    return ++nextval;
857            }
858    
859            /* no more args after this, jump to EOS */
860            nextval = src + strlen(src);
861            return nextval;
862    }
863    
864    
865    void
866    toupper_str(char *p)
867    {
868            while (*p)
869            {
870                    if ((*p >= 'a') && (*p <= 'z'))
871                            *p = toupper((int) *p);
872                    p++;
873            }
874    }
875    
876    
877    /* not all clibs got ltoa */
878    #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
879    
880    char *
881    l_to_a(long N, int base)
882    {
883            static char ret[LTOA_BUFSIZE];
884    
885            char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
886    
887            register int divrem;
888    
889            if (base < 36 || 2 > base)
890                    base = 10;
891    
892            if (N < 0)
893            {
894                    *head++ = '-';
895                    N = -N;
896            }
897    
898            tail = buf + sizeof(buf);
899            *--tail = 0;
900    
901            do
902            {
903                    divrem = N % base;
904                    *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
905                    N /= base;
906            }
907            while (N);
908    
909            strcpy(head, tail);
910            return ret;
911    }
912    
913    
914  int  int
915  load_licence(unsigned char **data)  load_licence(unsigned char **data)

Legend:
Removed from v.482  
changed lines
  Added in v.637

  ViewVC Help
Powered by ViewVC 1.1.26