/[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 567 by matthewc, Wed Jan 21 11:08:39 2004 UTC revision 637 by stargo, Mon Mar 15 14:49:12 2004 UTC
# Line 1  Line 1 
1  /* -*- c-basic-offset: 8 -*-  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Entrypoint and utility functions     Entrypoint and utility functions
4     Copyright (C) Matthew Chapman 1999-2004     Copyright (C) Matthew Chapman 1999-2003
5    
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 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    
83  #ifdef RDP2VNC  #ifdef RDP2VNC
84  extern int rfb_port;  extern int rfb_port;
85  extern int defer_time;  extern int defer_time;
# Line 103  usage(char *program) Line 110  usage(char *program)
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");
# Line 111  usage(char *program) Line 119  usage(char *program)
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");          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, "   -N: enable numlock synchronisation\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
123            fprintf(stderr, "   -X: embed into another window with a given id.\n");
124          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\n");
125          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");
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 218  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 231  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: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)
263          {          {
264                  switch (c)                  switch (c)
265                  {                  {
# Line 327  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 374  main(int argc, char *argv[]) Line 406  main(int argc, char *argv[])
406                                  g_numlock_sync = 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 384  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':                          case 'r':
444                                  if (!strcmp(optarg, "sound"))  
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  #ifdef WITH_RDPSND
473                                          g_rdpsnd = True;                                                  g_rdpsnd = True;
474  #else  #else
475                                          warning("Not compiled with sound support");                                                  warning("Not compiled with sound support");
476  #endif  #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;                                  break;
501    
502                          case '0':                          case '0':
# Line 413  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 470  main(int argc, char *argv[]) Line 576  main(int argc, char *argv[])
576          if (g_rdpsnd)          if (g_rdpsnd)
577                  rdpsnd_init();                  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 660  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 687  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.567  
changed lines
  Added in v.637

  ViewVC Help
Powered by ViewVC 1.1.26