/[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 628 by n-ki, Thu Mar 4 12:43:10 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    
74    #ifdef WITH_RDPSND
75    BOOL g_rdpsnd = False;
76    #endif
77    
78    extern RDPDR_DEVICE g_rdpdr_device[];
79    extern uint32 g_num_devices;
80    
81  #ifdef RDP2VNC  #ifdef RDP2VNC
82  extern int rfb_port;  extern int rfb_port;
# Line 86  usage(char *program) Line 101  usage(char *program)
101          fprintf(stderr, "   -u: user name\n");          fprintf(stderr, "   -u: user name\n");
102          fprintf(stderr, "   -d: domain\n");          fprintf(stderr, "   -d: domain\n");
103          fprintf(stderr, "   -s: shell\n");          fprintf(stderr, "   -s: shell\n");
         fprintf(stderr, "   -S: caption button size (single application mode)\n");  
104          fprintf(stderr, "   -c: working directory\n");          fprintf(stderr, "   -c: working directory\n");
105          fprintf(stderr, "   -p: password (- to prompt)\n");          fprintf(stderr, "   -p: password (- to prompt)\n");
106          fprintf(stderr, "   -n: client hostname\n");          fprintf(stderr, "   -n: client hostname\n");
107          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");
108          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
109          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
110          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
111            fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
112          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
113          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
114          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
115          fprintf(stderr, "   -C: use private colour map\n");          fprintf(stderr, "   -C: use private colour map\n");
116            fprintf(stderr, "   -D: hide window manager decorations\n");
117          fprintf(stderr, "   -K: keep window manager key bindings\n");          fprintf(stderr, "   -K: keep window manager key bindings\n");
118            fprintf(stderr, "   -S: caption button size (single application mode)\n");
119          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
120          fprintf(stderr, "   -D: hide window manager decorations\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
121          fprintf(stderr, "   -a: server bpp\n");          fprintf(stderr, "   -a: connection colour depth\n");
122          fprintf(stderr, "   -4: Use RDP version 4\n");          fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");
123          fprintf(stderr, "   -5: Use RDP version 5 (default)\n");          fprintf(stderr,
124                    "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");
125            fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
126            fprintf(stderr,
127                    "         '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n");
128            fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");
129            fprintf(stderr,
130                    "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");
131            fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");
132            fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
133            fprintf(stderr,
134                    "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
135            fprintf(stderr, "         '-r sound:[on|off|remote]': enable sound redirection\n");
136            fprintf(stderr, "                     remote would leave sound on server\n");
137            fprintf(stderr, "   -0: attach to console\n");
138            fprintf(stderr, "   -4: use RDP version 4\n");
139            fprintf(stderr, "   -5: use RDP version 5 (default)\n");
140  }  }
141    
142  static BOOL  static BOOL
# Line 197  main(int argc, char *argv[]) Line 230  main(int argc, char *argv[])
230          char server[64];          char server[64];
231          char fullhostname[64];          char fullhostname[64];
232          char domain[16];          char domain[16];
233          char password[16];          char password[64];
234          char shell[128];          char shell[128];
235          char directory[32];          char directory[32];
236          BOOL prompt_password, rdp_retval = False;          BOOL prompt_password, rdp_retval = False;
# Line 205  main(int argc, char *argv[]) Line 238  main(int argc, char *argv[])
238          uint32 flags;          uint32 flags;
239          char *p;          char *p;
240          int c;          int c;
241    
242          int username_option = 0;          int username_option = 0;
243    
244          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
# Line 212  main(int argc, char *argv[]) Line 246  main(int argc, char *argv[])
246          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
247          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
248    
249            g_num_devices = 0;
250    
251  #ifdef RDP2VNC  #ifdef RDP2VNC
252  #define VNCOPT "V:Q:"  #define VNCOPT "V:Q:"
253  #else  #else
254  #define VNCOPT  #define VNCOPT
255  #endif  #endif
256    
257          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:Na:r:045h?")) != -1)
258          {          {
259                  switch (c)                  switch (c)
260                  {                  {
# Line 249  main(int argc, char *argv[]) Line 285  main(int argc, char *argv[])
285                                  STRNCPY(shell, optarg, sizeof(shell));                                  STRNCPY(shell, optarg, sizeof(shell));
286                                  break;                                  break;
287    
                         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;  
   
288                          case 'c':                          case 'c':
289                                  STRNCPY(directory, optarg, sizeof(directory));                                  STRNCPY(directory, optarg, sizeof(directory));
290                                  break;                                  break;
# Line 295  main(int argc, char *argv[]) Line 314  main(int argc, char *argv[])
314                                  break;                                  break;
315    
316                          case 'g':                          case 'g':
317                                    g_fullscreen = False;
318                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
319                                  {                                  {
320                                          g_width = g_height = 0;                                          g_width = g_height = 0;
# Line 302  main(int argc, char *argv[]) Line 322  main(int argc, char *argv[])
322                                  }                                  }
323    
324                                  g_width = strtol(optarg, &p, 10);                                  g_width = strtol(optarg, &p, 10);
325                                    if (g_width <= 0)
326                                    {
327                                            error("invalid geometry\n");
328                                            return 1;
329                                    }
330    
331                                  if (*p == 'x')                                  if (*p == 'x')
332                                          g_height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, NULL, 10);
333    
334                                  if ((g_width == 0) || (g_height == 0))                                  if (g_height <= 0)
335                                  {                                  {
336                                          error("invalid geometry\n");                                          error("invalid geometry\n");
337                                          return 1;                                          return 1;
338                                  }                                  }
339    
340                                    if (*p == '%')
341                                            g_width = -g_width;
342    
343                                  break;                                  break;
344    
345                          case 'f':                          case 'f':
# Line 320  main(int argc, char *argv[]) Line 350  main(int argc, char *argv[])
350                                  g_orders = False;                                  g_orders = False;
351                                  break;                                  break;
352    
353                            case 'B':
354                                    g_ownbackstore = False;
355                                    break;
356    
357                          case 'e':                          case 'e':
358                                  g_encryption = False;                                  g_encryption = False;
359                                  break;                                  break;
# Line 334  main(int argc, char *argv[]) Line 368  main(int argc, char *argv[])
368                                  g_owncolmap = True;                                  g_owncolmap = True;
369                                  break;                                  break;
370    
371                            case 'D':
372                                    g_hide_decorations = True;
373                                    break;
374    
375                          case 'K':                          case 'K':
376                                  g_grab_keyboard = False;                                  g_grab_keyboard = False;
377                                  break;                                  break;
378    
379                            case 'S':
380                                    if (!strcmp(optarg, "standard"))
381                                    {
382                                            g_win_button_size = 18;
383                                            break;
384                                    }
385    
386                                    g_win_button_size = strtol(optarg, &p, 10);
387    
388                                    if (*p)
389                                    {
390                                            error("invalid button size\n");
391                                            return 1;
392                                    }
393    
394                                    break;
395    
396                          case 'T':                          case 'T':
397                                  STRNCPY(g_title, optarg, sizeof(g_title));                                  STRNCPY(g_title, optarg, sizeof(g_title));
398                                  break;                                  break;
399    
400                          case 'D':                          case 'N':
401                                  g_hide_decorations = True;                                  g_numlock_sync = True;
402                                  break;                                  break;
403    
404                          case 'a':                          case 'a':
# Line 356  main(int argc, char *argv[]) Line 411  main(int argc, char *argv[])
411                                  }                                  }
412                                  break;                                  break;
413    
414                            case 'r':
415    
416                                    if (strncmp("sound", optarg, 5) == 0)
417                                    {
418                                            if (*(optarg + 6) == ':')
419                                            {
420    
421                                                    if (strncmp("remote", optarg + 7, 6) == 0)
422                                                            flags |= RDP_LOGON_LEAVE_AUDIO;
423                                                    else if (strncmp("on", optarg + 7, 2) == 0)
424                                                    {
425    #ifdef WITH_RDPSND
426                                                            g_rdpsnd = True;
427    #else
428                                                            warning("Not compiled with sound support");
429    #endif
430                                                    }
431                                            }
432                                            else
433                                            {
434    #ifdef WITH_RDPSND
435                                                    g_rdpsnd = True;
436    #else
437                                                    warning("Not compiled with sound support");
438    #endif
439                                            }
440                                    }
441                                    else if (strncmp("disk", optarg, 4) == 0)
442                                    {
443                                            /* -r disk:h:=/mnt/floppy */
444                                            disk_enum_devices(&g_num_devices, optarg + 4);
445                                    }
446                                    else if (strncmp("comport", optarg, 7) == 0)
447                                    {
448                                            serial_enum_devices(&g_num_devices, optarg + 7);
449                                    }
450                                    else if (strncmp("lptport", optarg, 7) == 0)
451                                    {
452                                            parallel_enum_devices(&g_num_devices, optarg + 7);
453                                    }
454                                    else if (strncmp("printer", optarg, 7) == 0)
455                                    {
456                                            printer_enum_devices(&g_num_devices, optarg + 7);
457                                    }
458                                    else
459                                    {
460                                            warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");
461                                    }
462                                    break;
463    
464                            case '0':
465                                    g_console_session = True;
466                                    break;
467    
468                          case '4':                          case '4':
469                                  g_use_rdp5 = False;                                  g_use_rdp5 = False;
470                                  break;                                  break;
# Line 372  main(int argc, char *argv[]) Line 481  main(int argc, char *argv[])
481                  }                  }
482          }          }
483    
484          if (argc - optind < 1)          if (argc - optind != 1)
485          {          {
486                  usage(argv[0]);                  usage(argv[0]);
487                  return 1;                  return 1;
# Line 426  main(int argc, char *argv[]) Line 535  main(int argc, char *argv[])
535                  return 1;                  return 1;
536    
537  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
538          rdpsnd_init();          if (g_rdpsnd)
539                    rdpsnd_init();
540  #endif  #endif
541          /* rdpdr_init(); */          rdpdr_init();
542    
543          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
544                  return 1;                  return 1;
# Line 618  unimpl(char *format, ...) Line 728  unimpl(char *format, ...)
728    
729  /* produce a hex dump */  /* produce a hex dump */
730  void  void
731  hexdump(unsigned char *p, int len)  hexdump(unsigned char *p, unsigned int len)
732  {  {
733          unsigned char *line = p;          unsigned char *line = p;
734          int i, thisline, offset = 0;          int i, thisline, offset = 0;
# Line 645  hexdump(unsigned char *p, int len) Line 755  hexdump(unsigned char *p, int len)
755          }          }
756  }  }
757    
758    /*
759      input: src is the string we look in for needle.
760             Needle may be escaped by a backslash, in
761             that case we ignore that particular needle.
762      return value: returns next src pointer, for
763            succesive executions, like in a while loop
764            if retval is 0, then there are no more args.
765      pitfalls:
766            src is modified. 0x00 chars are inserted to
767            terminate strings.
768            return val, points on the next val chr after ins
769            0x00
770    
771            example usage:
772            while( (pos = next_arg( optarg, ',')) ){
773                    printf("%s\n",optarg);
774                    optarg=pos;
775            }
776    
777    */
778    char *
779    next_arg(char *src, char needle)
780    {
781            char *nextval;
782            char *p;
783            char *mvp = 0;
784    
785            /* EOS */
786            if (*src == (char) 0x00)
787                    return 0;
788    
789            p = src;
790            /*  skip escaped needles */
791            while ((nextval = strchr(p, needle)))
792            {
793                    mvp = nextval - 1;
794                    /* found backslashed needle */
795                    if (*mvp == '\\' && (mvp > src))
796                    {
797                            /* move string one to the left */
798                            while (*(mvp + 1) != (char) 0x00)
799                            {
800                                    *mvp = *(mvp + 1);
801                                    *mvp++;
802                            }
803                            *mvp = (char) 0x00;
804                            p = nextval;
805                    }
806                    else
807                    {
808                            p = nextval + 1;
809                            break;
810                    }
811    
812            }
813    
814            /* more args available */
815            if (nextval)
816            {
817                    *nextval = (char) 0x00;
818                    return ++nextval;
819            }
820    
821            /* no more args after this, jump to EOS */
822            nextval = src + strlen(src);
823            return nextval;
824    }
825    
826    
827    void
828    toupper_str(char *p)
829    {
830            while (*p)
831            {
832                    if ((*p >= 'a') && (*p <= 'z'))
833                            *p = toupper((int) *p);
834                    p++;
835            }
836    }
837    
838    
839    /* not all clibs got ltoa */
840    #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
841    
842    char *
843    l_to_a(long N, int base)
844    {
845            static char ret[LTOA_BUFSIZE];
846    
847            char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
848    
849            register int divrem;
850    
851            if (base < 36 || 2 > base)
852                    base = 10;
853    
854            if (N < 0)
855            {
856                    *head++ = '-';
857                    N = -N;
858            }
859    
860            tail = buf + sizeof(buf);
861            *--tail = 0;
862    
863            do
864            {
865                    divrem = N % base;
866                    *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
867                    N /= base;
868            }
869            while (N);
870    
871            strcpy(head, tail);
872            return ret;
873    }
874    
875    
876  int  int
877  load_licence(unsigned char **data)  load_licence(unsigned char **data)

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

  ViewVC Help
Powered by ViewVC 1.1.26