/[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 501 by stargo, Fri Oct 17 08:23:47 2003 UTC revision 651 by astrand, Thu Apr 15 20:12:42 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 66  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  extern BOOL g_owncolmap;  BOOL g_numlock_sync = False;
71    BOOL g_owncolmap = False;
72    BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
73    uint32 g_embed_wnd;
74    uint32 g_rdp5_performanceflags =
75            RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
76    
77  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
78  BOOL g_rdpsnd = True;  BOOL g_rdpsnd = False;
79  #endif  #endif
80    
81    extern RDPDR_DEVICE g_rdpdr_device[];
82    extern uint32 g_num_devices;
83    extern char *g_rdpdr_clientname;
84    
85  #ifdef RDP2VNC  #ifdef RDP2VNC
86  extern int rfb_port;  extern int rfb_port;
87  extern int defer_time;  extern int defer_time;
# Line 95  usage(char *program) Line 105  usage(char *program)
105          fprintf(stderr, "   -u: user name\n");          fprintf(stderr, "   -u: user name\n");
106          fprintf(stderr, "   -d: domain\n");          fprintf(stderr, "   -d: domain\n");
107          fprintf(stderr, "   -s: shell\n");          fprintf(stderr, "   -s: shell\n");
         fprintf(stderr, "   -S: caption button size (single application mode)\n");  
108          fprintf(stderr, "   -c: working directory\n");          fprintf(stderr, "   -c: working directory\n");
109          fprintf(stderr, "   -p: password (- to prompt)\n");          fprintf(stderr, "   -p: password (- to prompt)\n");
110          fprintf(stderr, "   -n: client hostname\n");          fprintf(stderr, "   -n: client hostname\n");
111          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");
112          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
113          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
114          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
115            fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
116          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
117          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
118          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
119          fprintf(stderr, "   -C: use private colour map\n");          fprintf(stderr, "   -C: use private colour map\n");
120            fprintf(stderr, "   -D: hide window manager decorations\n");
121          fprintf(stderr, "   -K: keep window manager key bindings\n");          fprintf(stderr, "   -K: keep window manager key bindings\n");
122            fprintf(stderr, "   -S: caption button size (single application mode)\n");
123          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
124          fprintf(stderr, "   -D: hide window manager decorations\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
125  #ifdef WITH_RDPSND          fprintf(stderr, "   -X: embed into another window with a given id.\n");
126          fprintf(stderr, "   -A: disable audio-redirection\n");          fprintf(stderr, "   -a: connection colour depth\n");
127  #endif          fprintf(stderr,
128          fprintf(stderr, "   -a: server bpp\n");                  "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex number)\n");
129            fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");
130            fprintf(stderr,
131                    "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");
132            fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
133            fprintf(stderr,
134                    "         '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n");
135            fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");
136            fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");
137            fprintf(stderr, "             for redirected disks\n");
138            fprintf(stderr,
139                    "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");
140            fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");
141            fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
142            fprintf(stderr,
143                    "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
144            fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");
145            fprintf(stderr, "                     remote would leave sound on server\n");
146          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
147          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
148          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          fprintf(stderr, "   -5: use RDP version 5 (default)\n");
# Line 218  main(int argc, char *argv[]) Line 247  main(int argc, char *argv[])
247          uint32 flags;          uint32 flags;
248          char *p;          char *p;
249          int c;          int c;
250    
251          int username_option = 0;          int username_option = 0;
252    
253          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
254          prompt_password = False;          prompt_password = False;
255          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
256          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
257            g_embed_wnd = 0;
258    
259            g_num_devices = 0;
260    
261  #ifdef RDP2VNC  #ifdef RDP2VNC
262  #define VNCOPT "V:Q:"  #define VNCOPT "V:Q:"
# Line 231  main(int argc, char *argv[]) Line 264  main(int argc, char *argv[])
264  #define VNCOPT  #define VNCOPT
265  #endif  #endif
266    
267          while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbeEmCKT:AD045h?")) != -1)          while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:r:045h?")) != -1)
268          {          {
269                  switch (c)                  switch (c)
270                  {                  {
# Line 262  main(int argc, char *argv[]) Line 295  main(int argc, char *argv[])
295                                  STRNCPY(shell, optarg, sizeof(shell));                                  STRNCPY(shell, optarg, sizeof(shell));
296                                  break;                                  break;
297    
                         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;  
   
298                          case 'c':                          case 'c':
299                                  STRNCPY(directory, optarg, sizeof(directory));                                  STRNCPY(directory, optarg, sizeof(directory));
300                                  break;                                  break;
# Line 308  main(int argc, char *argv[]) Line 324  main(int argc, char *argv[])
324                                  break;                                  break;
325    
326                          case 'g':                          case 'g':
327                                    g_fullscreen = False;
328                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
329                                  {                                  {
330                                          g_width = g_height = 0;                                          g_width = g_height = 0;
# Line 343  main(int argc, char *argv[]) Line 360  main(int argc, char *argv[])
360                                  g_orders = False;                                  g_orders = False;
361                                  break;                                  break;
362    
363                            case 'B':
364                                    g_ownbackstore = False;
365                                    break;
366    
367                          case 'e':                          case 'e':
368                                  g_encryption = False;                                  g_encryption = False;
369                                  break;                                  break;
# Line 357  main(int argc, char *argv[]) Line 378  main(int argc, char *argv[])
378                                  g_owncolmap = True;                                  g_owncolmap = True;
379                                  break;                                  break;
380    
381                            case 'D':
382                                    g_hide_decorations = True;
383                                    break;
384    
385                          case 'K':                          case 'K':
386                                  g_grab_keyboard = False;                                  g_grab_keyboard = False;
387                                  break;                                  break;
388    
389                            case 'S':
390                                    if (!strcmp(optarg, "standard"))
391                                    {
392                                            g_win_button_size = 18;
393                                            break;
394                                    }
395    
396                                    g_win_button_size = strtol(optarg, &p, 10);
397    
398                                    if (*p)
399                                    {
400                                            error("invalid button size\n");
401                                            return 1;
402                                    }
403    
404                                    break;
405    
406                          case 'T':                          case 'T':
407                                  STRNCPY(g_title, optarg, sizeof(g_title));                                  STRNCPY(g_title, optarg, sizeof(g_title));
408                                  break;                                  break;
409    
410                          case 'D':                          case 'N':
411                                  g_hide_decorations = True;                                  g_numlock_sync = True;
412                                    break;
413    
414                            case 'X':
415                                    g_embed_wnd = strtol(optarg, NULL, 10);
416                                  break;                                  break;
417    
418                          case 'a':                          case 'a':
# Line 379  main(int argc, char *argv[]) Line 425  main(int argc, char *argv[])
425                                  }                                  }
426                                  break;                                  break;
427    
428  #ifdef WITH_RDPSND                          case 'x':
429                          case 'A':  
430                                  g_rdpsnd = False;                                  if (strncmp("modem", optarg, 1) == 0)
431                                    {
432                                            g_rdp5_performanceflags =
433                                                    RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
434                                                    RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
435                                    }
436                                    else if (strncmp("broadband", optarg, 1) == 0)
437                                    {
438                                            g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
439                                    }
440                                    else if (strncmp("lan", optarg, 1) == 0)
441                                    {
442                                            g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
443                                    }
444                                    else
445                                    {
446                                            g_rdp5_performanceflags = strtol(optarg, NULL, 16);
447                                    }
448                                  break;                                  break;
449    
450                            case 'r':
451    
452                                    if (strncmp("sound", optarg, 5) == 0)
453                                    {
454                                            optarg += 5;
455    
456                                            if (*optarg == ':')
457                                            {
458                                                    *optarg++;
459                                                    while ((p = next_arg(optarg, ',')))
460                                                    {
461                                                            if (strncmp("remote", optarg, 6) == 0)
462                                                                    flags |= RDP_LOGON_LEAVE_AUDIO;
463    
464                                                            if (strncmp("local", optarg, 5) == 0)
465    #ifdef WITH_RDPSND
466                                                                    g_rdpsnd = True;
467    #else
468                                                                    warning("Not compiled with sound support");
469  #endif  #endif
470    
471                                                            if (strncmp("off", optarg, 3) == 0)
472                                                                    g_rdpsnd = False;
473    
474                                                            optarg = p;
475                                                    }
476                                            }
477                                            else
478                                            {
479    #ifdef WITH_RDPSND
480                                                    g_rdpsnd = True;
481    #else
482                                                    warning("Not compiled with sound support");
483    #endif
484                                            }
485                                    }
486                                    else if (strncmp("disk", optarg, 4) == 0)
487                                    {
488                                            /* -r disk:h:=/mnt/floppy */
489                                            disk_enum_devices(&g_num_devices, optarg + 4);
490                                    }
491                                    else if (strncmp("comport", optarg, 7) == 0)
492                                    {
493                                            serial_enum_devices(&g_num_devices, optarg + 7);
494                                    }
495                                    else if (strncmp("lptport", optarg, 7) == 0)
496                                    {
497                                            parallel_enum_devices(&g_num_devices, optarg + 7);
498                                    }
499                                    else if (strncmp("printer", optarg, 7) == 0)
500                                    {
501                                            printer_enum_devices(&g_num_devices, optarg + 7);
502                                    }
503                                    else if (strncmp("clientname", optarg, 7) == 0)
504                                    {
505                                            g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
506                                            strcpy(g_rdpdr_clientname, optarg + 11);
507                                    }
508                                    else
509                                    {
510                                            warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");
511                                    }
512                                    break;
513    
514                          case '0':                          case '0':
515                                  g_console_session = True;                                  g_console_session = True;
516                                  break;                                  break;
# Line 404  main(int argc, char *argv[]) Line 531  main(int argc, char *argv[])
531                  }                  }
532          }          }
533    
534          if (argc - optind < 1)          if (argc - optind != 1)
535          {          {
536                  usage(argv[0]);                  usage(argv[0]);
537                  return 1;                  return 1;
# Line 459  main(int argc, char *argv[]) Line 586  main(int argc, char *argv[])
586    
587  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
588          if (g_rdpsnd)          if (g_rdpsnd)
         {  
589                  rdpsnd_init();                  rdpsnd_init();
         }  
590  #endif  #endif
591          /* rdpdr_init(); */          rdpdr_init();
592    
593          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
594                  return 1;                  return 1;
# Line 653  unimpl(char *format, ...) Line 778  unimpl(char *format, ...)
778    
779  /* produce a hex dump */  /* produce a hex dump */
780  void  void
781  hexdump(unsigned char *p, int len)  hexdump(unsigned char *p, unsigned int len)
782  {  {
783          unsigned char *line = p;          unsigned char *line = p;
784          int i, thisline, offset = 0;          int i, thisline, offset = 0;
# Line 680  hexdump(unsigned char *p, int len) Line 805  hexdump(unsigned char *p, int len)
805          }          }
806  }  }
807    
808    /*
809      input: src is the string we look in for needle.
810             Needle may be escaped by a backslash, in
811             that case we ignore that particular needle.
812      return value: returns next src pointer, for
813            succesive executions, like in a while loop
814            if retval is 0, then there are no more args.
815      pitfalls:
816            src is modified. 0x00 chars are inserted to
817            terminate strings.
818            return val, points on the next val chr after ins
819            0x00
820    
821            example usage:
822            while( (pos = next_arg( optarg, ',')) ){
823                    printf("%s\n",optarg);
824                    optarg=pos;
825            }
826    
827    */
828    char *
829    next_arg(char *src, char needle)
830    {
831            char *nextval;
832            char *p;
833            char *mvp = 0;
834    
835            /* EOS */
836            if (*src == (char) 0x00)
837                    return 0;
838    
839            p = src;
840            /*  skip escaped needles */
841            while ((nextval = strchr(p, needle)))
842            {
843                    mvp = nextval - 1;
844                    /* found backslashed needle */
845                    if (*mvp == '\\' && (mvp > src))
846                    {
847                            /* move string one to the left */
848                            while (*(mvp + 1) != (char) 0x00)
849                            {
850                                    *mvp = *(mvp + 1);
851                                    *mvp++;
852                            }
853                            *mvp = (char) 0x00;
854                            p = nextval;
855                    }
856                    else
857                    {
858                            p = nextval + 1;
859                            break;
860                    }
861    
862            }
863    
864            /* more args available */
865            if (nextval)
866            {
867                    *nextval = (char) 0x00;
868                    return ++nextval;
869            }
870    
871            /* no more args after this, jump to EOS */
872            nextval = src + strlen(src);
873            return nextval;
874    }
875    
876    
877    void
878    toupper_str(char *p)
879    {
880            while (*p)
881            {
882                    if ((*p >= 'a') && (*p <= 'z'))
883                            *p = toupper((int) *p);
884                    p++;
885            }
886    }
887    
888    
889    /* not all clibs got ltoa */
890    #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
891    
892    char *
893    l_to_a(long N, int base)
894    {
895            static char ret[LTOA_BUFSIZE];
896    
897            char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
898    
899            register int divrem;
900    
901            if (base < 36 || 2 > base)
902                    base = 10;
903    
904            if (N < 0)
905            {
906                    *head++ = '-';
907                    N = -N;
908            }
909    
910            tail = buf + sizeof(buf);
911            *--tail = 0;
912    
913            do
914            {
915                    divrem = N % base;
916                    *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
917                    N /= base;
918            }
919            while (N);
920    
921            strcpy(head, tail);
922            return ret;
923    }
924    
925    
926  int  int
927  load_licence(unsigned char **data)  load_licence(unsigned char **data)

Legend:
Removed from v.501  
changed lines
  Added in v.651

  ViewVC Help
Powered by ViewVC 1.1.26