--- sourceforge.net/trunk/rdesktop/rdesktop.c 2003/02/10 12:58:51 318 +++ sourceforge.net/trunk/rdesktop/rdesktop.c 2003/05/19 21:36:33 376 @@ -1,4 +1,4 @@ -/* +/* -*- c-basic-offset: 8 -*- rdesktop: A Remote Desktop Protocol client. Entrypoint and utility functions Copyright (C) Matthew Chapman 1999-2003 @@ -26,6 +26,7 @@ #include /* stat */ #include /* gettimeofday */ #include /* times */ +#include #include "rdesktop.h" #ifdef EGD_SOCKET @@ -49,6 +50,7 @@ int height = 600; int tcp_port_rdp = TCP_PORT_RDP; int server_bpp = 8; +int win_button_size = 0; /* If zero, disable single app mode */ BOOL bitmap_compression = True; BOOL sendmotion = True; BOOL orders = True; @@ -57,8 +59,16 @@ BOOL fullscreen = False; BOOL grab_keyboard = True; BOOL hide_decorations = False; +BOOL use_rdp5 = False; extern BOOL owncolmap; +#ifdef RDP2VNC +extern int rfb_port; +extern int defer_time; +void +rdp2vnc_connect(char *server, uint32 flags, char *domain, char *password, + char *shell, char *directory); +#endif /* Display usage information */ static void usage(char *program) @@ -68,9 +78,14 @@ fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); fprintf(stderr, "Usage: %s [options] server[:port]\n", program); +#ifdef RDP2VNC + fprintf(stderr, " -V: vnc port\n"); + fprintf(stderr, " -E: defer time (ms)\n"); +#endif fprintf(stderr, " -u: user name\n"); fprintf(stderr, " -d: domain\n"); fprintf(stderr, " -s: shell\n"); + fprintf(stderr, " -S: caption button size (single application mode)\n"); fprintf(stderr, " -c: working directory\n"); fprintf(stderr, " -p: password (- to prompt)\n"); fprintf(stderr, " -n: client hostname\n"); @@ -85,6 +100,7 @@ fprintf(stderr, " -T: window title\n"); fprintf(stderr, " -D: hide window manager decorations\n"); fprintf(stderr, " -a: server bpp\n"); + fprintf(stderr, " -5: Use RDP5 (EXPERIMENTAL!)\n"); } static BOOL @@ -145,10 +161,30 @@ domain[0] = password[0] = shell[0] = directory[0] = 0; strcpy(keymapname, "en-us"); - while ((c = getopt(argc, argv, "u:d:s:c:p:n:k:g:a:fbemCKT:Dh?")) != -1) +#ifdef RDP2VNC +#define VNCOPT "V:E:" +#else +#define VNCOPT +#endif + + while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbemCKT:Dh?54")) != -1) { switch (c) { +#ifdef RDP2VNC + case 'V': + rfb_port = strtol(optarg, NULL, 10); + if (rfb_port < 100) + rfb_port += 5900; + break; + + case 'E': + defer_time = strtol(optarg, NULL, 10); + if (defer_time < 0) + defer_time = 0; + break; +#endif + case 'u': STRNCPY(username, optarg, sizeof(username)); username_option = 1; @@ -162,6 +198,23 @@ STRNCPY(shell, optarg, sizeof(shell)); break; + case 'S': + if (!strcmp(optarg, "standard")) + { + win_button_size = 18; + break; + } + + win_button_size = strtol(optarg, &p, 10); + + if (*p) + { + error("invalid button size\n"); + return 1; + } + + break; + case 'c': STRNCPY(directory, optarg, sizeof(directory)); break; @@ -250,6 +303,9 @@ } break; + case '5': + use_rdp5 = True; + break; case 'h': case '?': default: @@ -308,6 +364,10 @@ strncat(title, server, sizeof(title) - sizeof("rdesktop - ")); } +#ifdef RDP2VNC + rdp2vnc_connect(server, flags, domain, password, shell, directory); +#else + if (!ui_init()) return 1; @@ -326,6 +386,9 @@ DEBUG(("Disconnecting...\n")); rdp_disconnect(); ui_deinit(); + +#endif + return 0; } @@ -486,11 +549,10 @@ /* produce a hex dump */ void -hexdump(unsigned char *p, unsigned int len) +hexdump(unsigned char *p, int len) { unsigned char *line = p; - unsigned int thisline, offset = 0; - int i; + int i, thisline, offset = 0; while (offset < len) { @@ -513,3 +575,81 @@ line += thisline; } } + + +int +load_licence(unsigned char **data) +{ + char *home, *path; + struct stat st; + int fd, length; + + home = getenv("HOME"); + if (home == NULL) + return -1; + + path = (char*)xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); + sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); + + fd = open(path, O_RDONLY); + if (fd == -1) + return -1; + + if (fstat(fd, &st)) + return -1; + + *data = (uint8*)xmalloc(st.st_size); + length = read(fd, *data, st.st_size); + close(fd); + xfree(path); + return length; +} + +void +save_licence(unsigned char *data, int length) +{ + char *home, *path, *tmppath; + int fd; + + home = getenv("HOME"); + if (home == NULL) + return; + + path = (char*)xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); + + sprintf(path, "%s/.rdesktop", home); + if ((mkdir(path, 0700) == -1) && errno != EEXIST) + { + perror(path); + return; + } + + /* write licence to licence.hostname.new, then atomically rename to licence.hostname */ + + sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); + tmppath = (char*)xmalloc(strlen(path) + sizeof(".new")); + strcpy(tmppath, path); + strcat(tmppath, ".new"); + + fd = open(tmppath, O_WRONLY|O_CREAT|O_TRUNC, 0600); + if (fd == -1) + { + perror(tmppath); + return; + } + + if (write(fd, data, length) != length) + { + perror(tmppath); + unlink(tmppath); + } + else if (rename(tmppath, path) == -1) + { + perror(path); + unlink(tmppath); + } + + close(fd); + xfree(tmppath); + xfree(path); +}