/[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 567 by matthewc, Wed Jan 21 11:08:39 2004 UTC revision 636 by stargo, Sat Mar 13 12:08:18 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    
75  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
76  BOOL g_rdpsnd = False;  BOOL g_rdpsnd = False;
77  #endif  #endif
78    
79    extern RDPDR_DEVICE g_rdpdr_device[];
80    extern uint32 g_num_devices;
81    
82  #ifdef RDP2VNC  #ifdef RDP2VNC
83  extern int rfb_port;  extern int rfb_port;
84  extern int defer_time;  extern int defer_time;
# Line 103  usage(char *program) Line 109  usage(char *program)
109          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
110          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
111          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
112            fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
113          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
114          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
115          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
# Line 111  usage(char *program) Line 118  usage(char *program)
118          fprintf(stderr, "   -K: keep window manager key bindings\n");          fprintf(stderr, "   -K: keep window manager key bindings\n");
119          fprintf(stderr, "   -S: caption button size (single application mode)\n");          fprintf(stderr, "   -S: caption button size (single application mode)\n");
120          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
121          fprintf(stderr, "   -N: enable numlock synchronisation\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
122            fprintf(stderr, "   -X: embed into another window with a given id.\n");
123          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\n");
124          fprintf(stderr, "   -r: enable specified device redirection (currently: sound)\n");          fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");
125            fprintf(stderr,
126                    "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");
127            fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
128            fprintf(stderr,
129                    "         '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n");
130            fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");
131            fprintf(stderr,
132                    "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");
133            fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");
134            fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
135            fprintf(stderr,
136                    "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
137            fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");
138            fprintf(stderr, "                     remote would leave sound on server\n");
139          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
140          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
141          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 240  main(int argc, char *argv[])
240          uint32 flags;          uint32 flags;
241          char *p;          char *p;
242          int c;          int c;
243    
244          int username_option = 0;          int username_option = 0;
245    
246          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
247          prompt_password = False;          prompt_password = False;
248          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
249          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
250            g_embed_wnd = 0;
251    
252            g_num_devices = 0;
253    
254  #ifdef RDP2VNC  #ifdef RDP2VNC
255  #define VNCOPT "V:Q:"  #define VNCOPT "V:Q:"
# Line 231  main(int argc, char *argv[]) Line 257  main(int argc, char *argv[])
257  #define VNCOPT  #define VNCOPT
258  #endif  #endif
259    
260          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:r:045h?")) != -1)
261          {          {
262                  switch (c)                  switch (c)
263                  {                  {
# Line 327  main(int argc, char *argv[]) Line 353  main(int argc, char *argv[])
353                                  g_orders = False;                                  g_orders = False;
354                                  break;                                  break;
355    
356                            case 'B':
357                                    g_ownbackstore = False;
358                                    break;
359    
360                          case 'e':                          case 'e':
361                                  g_encryption = False;                                  g_encryption = False;
362                                  break;                                  break;
# Line 374  main(int argc, char *argv[]) Line 404  main(int argc, char *argv[])
404                                  g_numlock_sync = True;                                  g_numlock_sync = True;
405                                  break;                                  break;
406    
407                            case 'X':
408                                    g_embed_wnd = strtol(optarg, NULL, 10);
409                                    break;
410                                    
411                          case 'a':                          case 'a':
412                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_bpp = strtol(optarg, NULL, 10);
413                                  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 385  main(int argc, char *argv[]) Line 419  main(int argc, char *argv[])
419                                  break;                                  break;
420    
421                          case 'r':                          case 'r':
422                                  if (!strcmp(optarg, "sound"))  
423                                    if (strncmp("sound", optarg, 5) == 0)
424                                    {
425                                            optarg += 5;
426    
427                                            if (*optarg == ':')
428                                            {
429                                                    *optarg++;
430                                                    while ((p = next_arg(optarg, ',')))
431                                                    {
432                                                            if (strncmp("remote", optarg, 6) == 0)
433                                                                    flags |= RDP_LOGON_LEAVE_AUDIO;
434    
435                                                            if (strncmp("local", optarg, 5) == 0)
436  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
437                                          g_rdpsnd = True;                                                                  g_rdpsnd = True;
438  #else  #else
439                                          warning("Not compiled with sound support");                                                                  warning("Not compiled with sound support");
440  #endif  #endif
441    
442                                                            if (strncmp("off", optarg, 3) == 0)
443                                                                    g_rdpsnd = False;
444    
445                                                            optarg = p;
446                                                    }
447                                            }
448                                            else
449                                            {
450    #ifdef WITH_RDPSND
451                                                    g_rdpsnd = True;
452    #else
453                                                    warning("Not compiled with sound support");
454    #endif
455                                            }
456                                    }
457                                    else if (strncmp("disk", optarg, 4) == 0)
458                                    {
459                                            /* -r disk:h:=/mnt/floppy */
460                                            disk_enum_devices(&g_num_devices, optarg + 4);
461                                    }
462                                    else if (strncmp("comport", optarg, 7) == 0)
463                                    {
464                                            serial_enum_devices(&g_num_devices, optarg + 7);
465                                    }
466                                    else if (strncmp("lptport", optarg, 7) == 0)
467                                    {
468                                            parallel_enum_devices(&g_num_devices, optarg + 7);
469                                    }
470                                    else if (strncmp("printer", optarg, 7) == 0)
471                                    {
472                                            printer_enum_devices(&g_num_devices, optarg + 7);
473                                    }
474                                    else
475                                    {
476                                            warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");
477                                    }
478                                  break;                                  break;
479    
480                          case '0':                          case '0':
# Line 413  main(int argc, char *argv[]) Line 497  main(int argc, char *argv[])
497                  }                  }
498          }          }
499    
500          if (argc - optind < 1)          if (argc - optind != 1)
501          {          {
502                  usage(argv[0]);                  usage(argv[0]);
503                  return 1;                  return 1;
# Line 470  main(int argc, char *argv[]) Line 554  main(int argc, char *argv[])
554          if (g_rdpsnd)          if (g_rdpsnd)
555                  rdpsnd_init();                  rdpsnd_init();
556  #endif  #endif
557          /* rdpdr_init(); */          rdpdr_init();
558    
559          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
560                  return 1;                  return 1;
# Line 660  unimpl(char *format, ...) Line 744  unimpl(char *format, ...)
744    
745  /* produce a hex dump */  /* produce a hex dump */
746  void  void
747  hexdump(unsigned char *p, int len)  hexdump(unsigned char *p, unsigned int len)
748  {  {
749          unsigned char *line = p;          unsigned char *line = p;
750          int i, thisline, offset = 0;          int i, thisline, offset = 0;
# Line 687  hexdump(unsigned char *p, int len) Line 771  hexdump(unsigned char *p, int len)
771          }          }
772  }  }
773    
774    /*
775      input: src is the string we look in for needle.
776             Needle may be escaped by a backslash, in
777             that case we ignore that particular needle.
778      return value: returns next src pointer, for
779            succesive executions, like in a while loop
780            if retval is 0, then there are no more args.
781      pitfalls:
782            src is modified. 0x00 chars are inserted to
783            terminate strings.
784            return val, points on the next val chr after ins
785            0x00
786    
787            example usage:
788            while( (pos = next_arg( optarg, ',')) ){
789                    printf("%s\n",optarg);
790                    optarg=pos;
791            }
792    
793    */
794    char *
795    next_arg(char *src, char needle)
796    {
797            char *nextval;
798            char *p;
799            char *mvp = 0;
800    
801            /* EOS */
802            if (*src == (char) 0x00)
803                    return 0;
804    
805            p = src;
806            /*  skip escaped needles */
807            while ((nextval = strchr(p, needle)))
808            {
809                    mvp = nextval - 1;
810                    /* found backslashed needle */
811                    if (*mvp == '\\' && (mvp > src))
812                    {
813                            /* move string one to the left */
814                            while (*(mvp + 1) != (char) 0x00)
815                            {
816                                    *mvp = *(mvp + 1);
817                                    *mvp++;
818                            }
819                            *mvp = (char) 0x00;
820                            p = nextval;
821                    }
822                    else
823                    {
824                            p = nextval + 1;
825                            break;
826                    }
827    
828            }
829    
830            /* more args available */
831            if (nextval)
832            {
833                    *nextval = (char) 0x00;
834                    return ++nextval;
835            }
836    
837            /* no more args after this, jump to EOS */
838            nextval = src + strlen(src);
839            return nextval;
840    }
841    
842    
843    void
844    toupper_str(char *p)
845    {
846            while (*p)
847            {
848                    if ((*p >= 'a') && (*p <= 'z'))
849                            *p = toupper((int) *p);
850                    p++;
851            }
852    }
853    
854    
855    /* not all clibs got ltoa */
856    #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
857    
858    char *
859    l_to_a(long N, int base)
860    {
861            static char ret[LTOA_BUFSIZE];
862    
863            char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
864    
865            register int divrem;
866    
867            if (base < 36 || 2 > base)
868                    base = 10;
869    
870            if (N < 0)
871            {
872                    *head++ = '-';
873                    N = -N;
874            }
875    
876            tail = buf + sizeof(buf);
877            *--tail = 0;
878    
879            do
880            {
881                    divrem = N % base;
882                    *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
883                    N /= base;
884            }
885            while (N);
886    
887            strcpy(head, tail);
888            return ret;
889    }
890    
891    
892  int  int
893  load_licence(unsigned char **data)  load_licence(unsigned char **data)

Legend:
Removed from v.567  
changed lines
  Added in v.636

  ViewVC Help
Powered by ViewVC 1.1.26