/[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 318 by astrand, Mon Feb 10 12:58:51 2003 UTC revision 424 by forsberg, Thu Jun 19 07:29:53 2003 UTC
# Line 1  Line 1 
1  /*  /* -*- 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-2003     Copyright (C) Matthew Chapman 1999-2003
# 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 <errno.h>
30  #include "rdesktop.h"  #include "rdesktop.h"
31    
32  #ifdef EGD_SOCKET  #ifdef EGD_SOCKET
# Line 49  int width = 800;               /* If width or height Line 50  int width = 800;               /* If width or height
50  int height = 600;  int height = 600;
51  int tcp_port_rdp = TCP_PORT_RDP;  int tcp_port_rdp = TCP_PORT_RDP;
52  int server_bpp = 8;  int server_bpp = 8;
53    int win_button_size = 0;        /* If zero, disable single app mode */
54  BOOL bitmap_compression = True;  BOOL bitmap_compression = True;
55  BOOL sendmotion = True;  BOOL sendmotion = True;
56  BOOL orders = True;  BOOL orders = True;
# Line 57  BOOL desktop_save = True; Line 59  BOOL desktop_save = True;
59  BOOL fullscreen = False;  BOOL fullscreen = False;
60  BOOL grab_keyboard = True;  BOOL grab_keyboard = True;
61  BOOL hide_decorations = False;  BOOL hide_decorations = False;
62    BOOL use_rdp5 = False;
63  extern BOOL owncolmap;  extern BOOL owncolmap;
64    
65    #ifdef RDP2VNC
66    extern int rfb_port;
67    extern int defer_time;
68    void
69    rdp2vnc_connect(char *server, uint32 flags, char *domain, char *password,
70                    char *shell, char *directory);
71    #endif
72  /* Display usage information */  /* Display usage information */
73  static void  static void
74  usage(char *program)  usage(char *program)
# Line 68  usage(char *program) Line 78  usage(char *program)
78          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
79    
80          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
81    #ifdef RDP2VNC
82            fprintf(stderr, "   -V: vnc port\n");
83            fprintf(stderr, "   -E: defer time (ms)\n");
84    #endif
85          fprintf(stderr, "   -u: user name\n");          fprintf(stderr, "   -u: user name\n");
86          fprintf(stderr, "   -d: domain\n");          fprintf(stderr, "   -d: domain\n");
87          fprintf(stderr, "   -s: shell\n");          fprintf(stderr, "   -s: shell\n");
88            fprintf(stderr, "   -S: caption button size (single application mode)\n");
89          fprintf(stderr, "   -c: working directory\n");          fprintf(stderr, "   -c: working directory\n");
90          fprintf(stderr, "   -p: password (- to prompt)\n");          fprintf(stderr, "   -p: password (- to prompt)\n");
91          fprintf(stderr, "   -n: client hostname\n");          fprintf(stderr, "   -n: client hostname\n");
# Line 85  usage(char *program) Line 100  usage(char *program)
100          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
101          fprintf(stderr, "   -D: hide window manager decorations\n");          fprintf(stderr, "   -D: hide window manager decorations\n");
102          fprintf(stderr, "   -a: server bpp\n");          fprintf(stderr, "   -a: server bpp\n");
103            fprintf(stderr, "   -5: Use RDP5 (EXPERIMENTAL!)\n");
104  }  }
105    
106  static BOOL  static BOOL
# Line 133  main(int argc, char *argv[]) Line 149  main(int argc, char *argv[])
149          char password[16];          char password[16];
150          char shell[128];          char shell[128];
151          char directory[32];          char directory[32];
152          BOOL prompt_password;          BOOL prompt_password, rdp_retval = False;
153          struct passwd *pw;          struct passwd *pw;
154          uint32 flags;          uint32 flags;
155          char *p;          char *p;
# Line 145  main(int argc, char *argv[]) Line 161  main(int argc, char *argv[])
161          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
162          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
163    
164          while ((c = getopt(argc, argv, "u:d:s:c:p:n:k:g:a:fbemCKT:Dh?")) != -1)  #ifdef RDP2VNC
165    #define VNCOPT "V:E:"
166    #else
167    #define VNCOPT
168    #endif
169    
170            while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbemCKT:Dh?54")) != -1)
171          {          {
172                  switch (c)                  switch (c)
173                  {                  {
174    #ifdef RDP2VNC
175                            case 'V':
176                                    rfb_port = strtol(optarg, NULL, 10);
177                                    if (rfb_port < 100)
178                                            rfb_port += 5900;
179                                    break;
180    
181                            case 'E':
182                                    defer_time = strtol(optarg, NULL, 10);
183                                    if (defer_time < 0)
184                                            defer_time = 0;
185                                    break;
186    #endif
187    
188                          case 'u':                          case 'u':
189                                  STRNCPY(username, optarg, sizeof(username));                                  STRNCPY(username, optarg, sizeof(username));
190                                  username_option = 1;                                  username_option = 1;
# Line 162  main(int argc, char *argv[]) Line 198  main(int argc, char *argv[])
198                                  STRNCPY(shell, optarg, sizeof(shell));                                  STRNCPY(shell, optarg, sizeof(shell));
199                                  break;                                  break;
200    
201                            case 'S':
202                                    if (!strcmp(optarg, "standard"))
203                                    {
204                                            win_button_size = 18;
205                                            break;
206                                    }
207    
208                                    win_button_size = strtol(optarg, &p, 10);
209    
210                                    if (*p)
211                                    {
212                                            error("invalid button size\n");
213                                            return 1;
214                                    }
215    
216                                    break;
217    
218                          case 'c':                          case 'c':
219                                  STRNCPY(directory, optarg, sizeof(directory));                                  STRNCPY(directory, optarg, sizeof(directory));
220                                  break;                                  break;
# Line 250  main(int argc, char *argv[]) Line 303  main(int argc, char *argv[])
303                                  }                                  }
304                                  break;                                  break;
305    
306                            case '5':
307                                    use_rdp5 = True;
308                                    break;
309                          case 'h':                          case 'h':
310                          case '?':                          case '?':
311                          default:                          default:
# Line 308  main(int argc, char *argv[]) Line 364  main(int argc, char *argv[])
364                  strncat(title, server, sizeof(title) - sizeof("rdesktop - "));                  strncat(title, server, sizeof(title) - sizeof("rdesktop - "));
365          }          }
366    
367    #ifdef RDP2VNC
368            rdp2vnc_connect(server, flags, domain, password, shell, directory);
369            return 0;
370    #else
371    
372          if (!ui_init())          if (!ui_init())
373                  return 1;                  return 1;
374    
375            ipc_init();             // Must be run after ui_init, we need X to be setup.
376    
377            if (use_rdp5)
378                    cliprdr_init(); // FIXME: Should perhaps be integrated into the channel management code?
379    
380          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
381                  return 1;                  return 1;
382    
# Line 319  main(int argc, char *argv[]) Line 385  main(int argc, char *argv[])
385    
386          if (ui_create_window())          if (ui_create_window())
387          {          {
388                  rdp_main_loop();                  rdp_retval = rdp_main_loop();
389                  ui_destroy_window();                  ui_destroy_window();
390          }          }
391    
392          DEBUG(("Disconnecting...\n"));          DEBUG(("Disconnecting...\n"));
393          rdp_disconnect();          rdp_disconnect();
394          ui_deinit();          ui_deinit();
395          return 0;  
396            if (True == rdp_retval)
397                    return 0;
398            else
399                    return 2;
400    
401    #endif
402    
403  }  }
404    
405  #ifdef EGD_SOCKET  #ifdef EGD_SOCKET
# Line 486  unimpl(char *format, ...) Line 559  unimpl(char *format, ...)
559    
560  /* produce a hex dump */  /* produce a hex dump */
561  void  void
562  hexdump(unsigned char *p, unsigned int len)  hexdump(unsigned char *p, int len)
563  {  {
564          unsigned char *line = p;          unsigned char *line = p;
565          unsigned int thisline, offset = 0;          int i, thisline, offset = 0;
         int i;  
566    
567          while (offset < len)          while (offset < len)
568          {          {
# Line 513  hexdump(unsigned char *p, unsigned int l Line 585  hexdump(unsigned char *p, unsigned int l
585                  line += thisline;                  line += thisline;
586          }          }
587  }  }
588    
589    
590    int
591    load_licence(unsigned char **data)
592    {
593            char *home, *path;
594            struct stat st;
595            int fd, length;
596    
597            home = getenv("HOME");
598            if (home == NULL)
599                    return -1;
600    
601            path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));
602            sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
603    
604            fd = open(path, O_RDONLY);
605            if (fd == -1)
606                    return -1;
607    
608            if (fstat(fd, &st))
609                    return -1;
610    
611            *data = (uint8 *) xmalloc(st.st_size);
612            length = read(fd, *data, st.st_size);
613            close(fd);
614            xfree(path);
615            return length;
616    }
617    
618    void
619    save_licence(unsigned char *data, int length)
620    {
621            char *home, *path, *tmppath;
622            int fd;
623    
624            home = getenv("HOME");
625            if (home == NULL)
626                    return;
627    
628            path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));
629    
630            sprintf(path, "%s/.rdesktop", home);
631            if ((mkdir(path, 0700) == -1) && errno != EEXIST)
632            {
633                    perror(path);
634                    return;
635            }
636    
637            /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
638    
639            sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
640            tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
641            strcpy(tmppath, path);
642            strcat(tmppath, ".new");
643    
644            fd = open(tmppath, O_WRONLY | O_CREAT | O_TRUNC, 0600);
645            if (fd == -1)
646            {
647                    perror(tmppath);
648                    return;
649            }
650    
651            if (write(fd, data, length) != length)
652            {
653                    perror(tmppath);
654                    unlink(tmppath);
655            }
656            else if (rename(tmppath, path) == -1)
657            {
658                    perror(path);
659                    unlink(tmppath);
660            }
661    
662            close(fd);
663            xfree(tmppath);
664            xfree(path);
665    }

Legend:
Removed from v.318  
changed lines
  Added in v.424

  ViewVC Help
Powered by ViewVC 1.1.26