/[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 552 by astrand, Mon Dec 8 12:01:25 2003 UTC revision 646 by forsberg, Fri Apr 2 15:34:38 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 68  BOOL g_use_rdp5 = True; Line 69  BOOL g_use_rdp5 = True;
69  BOOL g_console_session = False;  BOOL g_console_session = False;
70  BOOL g_numlock_sync = False;  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  #ifdef WITH_RDPSND
77  BOOL g_rdpsnd = False;  BOOL g_rdpsnd = False;
78  #endif  #endif
79    
80    extern RDPDR_DEVICE g_rdpdr_device[];
81    extern uint32 g_num_devices;
82    extern char * g_rdpdr_clientname;
83    
84  #ifdef RDP2VNC  #ifdef RDP2VNC
85  extern int rfb_port;  extern int rfb_port;
86  extern int defer_time;  extern int defer_time;
# Line 103  usage(char *program) Line 111  usage(char *program)
111          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
112          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
113          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
114            fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
115          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
116          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
117          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
# Line 112  usage(char *program) Line 121  usage(char *program)
121          fprintf(stderr, "   -S: caption button size (single application mode)\n");          fprintf(stderr, "   -S: caption button size (single application mode)\n");
122          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
123          fprintf(stderr, "   -N: enable numlock syncronization\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
124            fprintf(stderr, "   -X: embed into another window with a given id.\n");
125          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\n");
126          fprintf(stderr, "   -r: enable specified device redirection (currently: sound)\n");          fprintf(stderr, "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex number)\n");
127            fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");
128            fprintf(stderr,
129                    "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");
130            fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
131            fprintf(stderr,
132                    "         '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n");
133            fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");
134            fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");
135            fprintf(stderr, "             for redirected disks\n");
136            fprintf(stderr,
137                    "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");
138            fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");
139            fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
140            fprintf(stderr,
141                    "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
142            fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");
143            fprintf(stderr, "                     remote would leave sound on server\n");
144          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
145          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
146          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 245  main(int argc, char *argv[])
245          uint32 flags;          uint32 flags;
246          char *p;          char *p;
247          int c;          int c;
248    
249          int username_option = 0;          int username_option = 0;
250    
251          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
252          prompt_password = False;          prompt_password = False;
253          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
254          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
255            g_embed_wnd = 0;
256    
257            g_num_devices = 0;
258    
259  #ifdef RDP2VNC  #ifdef RDP2VNC
260  #define VNCOPT "V:Q:"  #define VNCOPT "V:Q:"
# Line 231  main(int argc, char *argv[]) Line 262  main(int argc, char *argv[])
262  #define VNCOPT  #define VNCOPT
263  #endif  #endif
264    
265          while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbeEmCDKS:T:Na:r:045h?")) != -1)          while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:r:045h?")) != -1)
266          {          {
267                  switch (c)                  switch (c)
268                  {                  {
# Line 327  main(int argc, char *argv[]) Line 358  main(int argc, char *argv[])
358                                  g_orders = False;                                  g_orders = False;
359                                  break;                                  break;
360    
361                            case 'B':
362                                    g_ownbackstore = False;
363                                    break;
364    
365                          case 'e':                          case 'e':
366                                  g_encryption = False;                                  g_encryption = False;
367                                  break;                                  break;
# Line 374  main(int argc, char *argv[]) Line 409  main(int argc, char *argv[])
409                                  g_numlock_sync = True;                                  g_numlock_sync = True;
410                                  break;                                  break;
411    
412                            case 'X':
413                                    g_embed_wnd = strtol(optarg, NULL, 10);
414                                    break;
415                                    
416                          case 'a':                          case 'a':
417                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_bpp = strtol(optarg, NULL, 10);
418                                  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 384  main(int argc, char *argv[]) Line 423  main(int argc, char *argv[])
423                                  }                                  }
424                                  break;                                  break;
425    
426                            case 'x':
427                                    
428                                    if (strncmp("modem", optarg, 1) == 0)
429                                    {
430                                            g_rdp5_performanceflags = RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
431                                    }
432                                    else if (strncmp("broadband", optarg, 1) == 0)
433                                    {
434                                            g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
435                                    }
436                                    else if (strncmp("lan", optarg, 1) == 0)
437                                    {
438                                            g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
439                                    }
440                                    else
441                                    {
442                                            g_rdp5_performanceflags = strtol(optarg, NULL, 16);
443                                    }
444                                    break;
445                                    
446                          case 'r':                          case 'r':
447                                  if (!strcmp(optarg, "sound"))  
448                                    if (strncmp("sound", optarg, 5) == 0)
449                                    {
450                                            optarg += 5;
451    
452                                            if (*optarg == ':')
453                                            {
454                                                    *optarg++;
455                                                    while ((p = next_arg(optarg, ',')))
456                                                    {
457                                                            if (strncmp("remote", optarg, 6) == 0)
458                                                                    flags |= RDP_LOGON_LEAVE_AUDIO;
459    
460                                                            if (strncmp("local", optarg, 5) == 0)
461    #ifdef WITH_RDPSND
462                                                                    g_rdpsnd = True;
463    #else
464                                                                    warning("Not compiled with sound support");
465    #endif
466    
467                                                            if (strncmp("off", optarg, 3) == 0)
468                                                                    g_rdpsnd = False;
469    
470                                                            optarg = p;
471                                                    }
472                                            }
473                                            else
474                                            {
475  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
476                                          g_rdpsnd = True;                                                  g_rdpsnd = True;
477  #else  #else
478                                          warning("Not compiled with sound support");                                                  warning("Not compiled with sound support");
479  #endif  #endif
480                                            }
481                                    }
482                                    else if (strncmp("disk", optarg, 4) == 0)
483                                    {
484                                            /* -r disk:h:=/mnt/floppy */
485                                            disk_enum_devices(&g_num_devices, optarg + 4);
486                                    }
487                                    else if (strncmp("comport", optarg, 7) == 0)
488                                    {
489                                            serial_enum_devices(&g_num_devices, optarg + 7);
490                                    }
491                                    else if (strncmp("lptport", optarg, 7) == 0)
492                                    {
493                                            parallel_enum_devices(&g_num_devices, optarg + 7);
494                                    }
495                                    else if (strncmp("printer", optarg, 7) == 0)
496                                    {
497                                            printer_enum_devices(&g_num_devices, optarg + 7);
498                                    }
499                                    else if (strncmp("clientname", optarg, 7) == 0)
500                                    {
501                                            g_rdpdr_clientname = xmalloc(strlen(optarg+11)+1);
502                                            strcpy(g_rdpdr_clientname, optarg + 11);
503                                    }
504                                    else
505                                    {
506                                            warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");
507                                    }
508                                  break;                                  break;
509    
510                          case '0':                          case '0':
# Line 413  main(int argc, char *argv[]) Line 527  main(int argc, char *argv[])
527                  }                  }
528          }          }
529    
530          if (argc - optind < 1)          if (argc - optind != 1)
531          {          {
532                  usage(argv[0]);                  usage(argv[0]);
533                  return 1;                  return 1;
# Line 470  main(int argc, char *argv[]) Line 584  main(int argc, char *argv[])
584          if (g_rdpsnd)          if (g_rdpsnd)
585                  rdpsnd_init();                  rdpsnd_init();
586  #endif  #endif
587          /* rdpdr_init(); */          rdpdr_init();
588    
589          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
590                  return 1;                  return 1;
# Line 660  unimpl(char *format, ...) Line 774  unimpl(char *format, ...)
774    
775  /* produce a hex dump */  /* produce a hex dump */
776  void  void
777  hexdump(unsigned char *p, int len)  hexdump(unsigned char *p, unsigned int len)
778  {  {
779          unsigned char *line = p;          unsigned char *line = p;
780          int i, thisline, offset = 0;          int i, thisline, offset = 0;
# Line 687  hexdump(unsigned char *p, int len) Line 801  hexdump(unsigned char *p, int len)
801          }          }
802  }  }
803    
804    /*
805      input: src is the string we look in for needle.
806             Needle may be escaped by a backslash, in
807             that case we ignore that particular needle.
808      return value: returns next src pointer, for
809            succesive executions, like in a while loop
810            if retval is 0, then there are no more args.
811      pitfalls:
812            src is modified. 0x00 chars are inserted to
813            terminate strings.
814            return val, points on the next val chr after ins
815            0x00
816    
817            example usage:
818            while( (pos = next_arg( optarg, ',')) ){
819                    printf("%s\n",optarg);
820                    optarg=pos;
821            }
822    
823    */
824    char *
825    next_arg(char *src, char needle)
826    {
827            char *nextval;
828            char *p;
829            char *mvp = 0;
830    
831            /* EOS */
832            if (*src == (char) 0x00)
833                    return 0;
834    
835            p = src;
836            /*  skip escaped needles */
837            while ((nextval = strchr(p, needle)))
838            {
839                    mvp = nextval - 1;
840                    /* found backslashed needle */
841                    if (*mvp == '\\' && (mvp > src))
842                    {
843                            /* move string one to the left */
844                            while (*(mvp + 1) != (char) 0x00)
845                            {
846                                    *mvp = *(mvp + 1);
847                                    *mvp++;
848                            }
849                            *mvp = (char) 0x00;
850                            p = nextval;
851                    }
852                    else
853                    {
854                            p = nextval + 1;
855                            break;
856                    }
857    
858            }
859    
860            /* more args available */
861            if (nextval)
862            {
863                    *nextval = (char) 0x00;
864                    return ++nextval;
865            }
866    
867            /* no more args after this, jump to EOS */
868            nextval = src + strlen(src);
869            return nextval;
870    }
871    
872    
873    void
874    toupper_str(char *p)
875    {
876            while (*p)
877            {
878                    if ((*p >= 'a') && (*p <= 'z'))
879                            *p = toupper((int) *p);
880                    p++;
881            }
882    }
883    
884    
885    /* not all clibs got ltoa */
886    #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
887    
888    char *
889    l_to_a(long N, int base)
890    {
891            static char ret[LTOA_BUFSIZE];
892    
893            char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
894    
895            register int divrem;
896    
897            if (base < 36 || 2 > base)
898                    base = 10;
899    
900            if (N < 0)
901            {
902                    *head++ = '-';
903                    N = -N;
904            }
905    
906            tail = buf + sizeof(buf);
907            *--tail = 0;
908    
909            do
910            {
911                    divrem = N % base;
912                    *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
913                    N /= base;
914            }
915            while (N);
916    
917            strcpy(head, tail);
918            return ret;
919    }
920    
921    
922  int  int
923  load_licence(unsigned char **data)  load_licence(unsigned char **data)

Legend:
Removed from v.552  
changed lines
  Added in v.646

  ViewVC Help
Powered by ViewVC 1.1.26