Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB |
DRC | b65bb93 | 2011-06-24 03:17:00 +0000 | [diff] [blame] | 3 | * Copyright (C) 2011 D. R. Commander. All Rights Reserved. |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 4 | * |
| 5 | * This is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This software is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this software; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 18 | * USA. |
| 19 | */ |
| 20 | |
Peter Åstrand | c359f36 | 2011-08-23 12:04:46 +0000 | [diff] [blame] | 21 | #ifdef HAVE_CONFIG_H |
| 22 | #include <config.h> |
| 23 | #endif |
| 24 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 25 | #include <string.h> |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <errno.h> |
| 29 | #include <signal.h> |
| 30 | #include <locale.h> |
| 31 | #include <sys/stat.h> |
| 32 | |
| 33 | #ifdef WIN32 |
| 34 | #include <direct.h> |
| 35 | #define mkdir(path, mode) _mkdir(path) |
| 36 | #endif |
| 37 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 38 | #include <rfb/Logger_stdio.h> |
| 39 | #include <rfb/SecurityClient.h> |
| 40 | #include <rfb/Security.h> |
| 41 | #ifdef HAVE_GNUTLS |
| 42 | #include <rfb/CSecurityTLS.h> |
| 43 | #endif |
| 44 | #include <rfb/LogWriter.h> |
| 45 | #include <rfb/Timer.h> |
Peter Åstrand | 8a2b081 | 2012-08-08 11:49:01 +0000 | [diff] [blame] | 46 | #include <rfb/Exception.h> |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 47 | #include <network/TcpSocket.h> |
DRC | 4426f00 | 2011-10-12 20:02:55 +0000 | [diff] [blame] | 48 | #include <os/os.h> |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 49 | |
| 50 | #include <FL/Fl.H> |
| 51 | #include <FL/Fl_Widget.H> |
Pierre Ossman | 8eb3508 | 2012-03-27 12:50:54 +0000 | [diff] [blame] | 52 | #include <FL/Fl_PNG_Image.H> |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 53 | #include <FL/fl_ask.H> |
Pierre Ossman | b885822 | 2011-04-29 11:51:38 +0000 | [diff] [blame] | 54 | #include <FL/x.H> |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 55 | |
| 56 | #include "i18n.h" |
| 57 | #include "parameters.h" |
| 58 | #include "CConn.h" |
Pierre Ossman | 561ff0c | 2011-05-13 14:04:59 +0000 | [diff] [blame] | 59 | #include "ServerDialog.h" |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 60 | #include "UserDialog.h" |
Adam Tkac | 8ac4b30 | 2013-01-23 13:55:46 +0000 | [diff] [blame^] | 61 | #include "vncviewer.h" |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 62 | |
DRC | b65bb93 | 2011-06-24 03:17:00 +0000 | [diff] [blame] | 63 | #ifdef WIN32 |
Pierre Ossman | 8eb3508 | 2012-03-27 12:50:54 +0000 | [diff] [blame] | 64 | #include "resource.h" |
DRC | b65bb93 | 2011-06-24 03:17:00 +0000 | [diff] [blame] | 65 | #include "win32.h" |
| 66 | #endif |
| 67 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 68 | rfb::LogWriter vlog("main"); |
| 69 | |
| 70 | using namespace network; |
| 71 | using namespace rfb; |
| 72 | using namespace std; |
| 73 | |
Pierre Ossman | f52740e | 2012-04-25 15:43:56 +0000 | [diff] [blame] | 74 | static const char aboutText[] = N_("TigerVNC Viewer %d-bit v%s (%s)\n" |
| 75 | "%s\n" |
| 76 | "Copyright (C) 1999-2011 TigerVNC Team and many others (see README.txt)\n" |
| 77 | "See http://www.tigervnc.org for information on TigerVNC."); |
DRC | d8e93dc | 2011-07-28 22:13:40 +0000 | [diff] [blame] | 78 | extern const char* buildTime; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 79 | |
Adam Tkac | 8ac4b30 | 2013-01-23 13:55:46 +0000 | [diff] [blame^] | 80 | char vncServerName[VNCSERVERNAMELEN] = { '\0' }; |
| 81 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 82 | static bool exitMainloop = false; |
Pierre Ossman | e2ef5c1 | 2011-07-12 16:56:34 +0000 | [diff] [blame] | 83 | static const char *exitError = NULL; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 84 | |
Pierre Ossman | e2ef5c1 | 2011-07-12 16:56:34 +0000 | [diff] [blame] | 85 | void exit_vncviewer(const char *error) |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 86 | { |
Pierre Ossman | e2ef5c1 | 2011-07-12 16:56:34 +0000 | [diff] [blame] | 87 | // Prioritise the first error we get as that is probably the most |
| 88 | // relevant one. |
| 89 | if ((error != NULL) && (exitError == NULL)) |
| 90 | exitError = strdup(error); |
| 91 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 92 | exitMainloop = true; |
| 93 | } |
| 94 | |
Pierre Ossman | b885822 | 2011-04-29 11:51:38 +0000 | [diff] [blame] | 95 | void about_vncviewer() |
| 96 | { |
| 97 | fl_message_title(_("About TigerVNC Viewer")); |
Pierre Ossman | f52740e | 2012-04-25 15:43:56 +0000 | [diff] [blame] | 98 | fl_message(gettext(aboutText), (int)sizeof(size_t)*8, |
| 99 | PACKAGE_VERSION, __BUILD__, buildTime); |
Pierre Ossman | b885822 | 2011-04-29 11:51:38 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | static void about_callback(Fl_Widget *widget, void *data) |
| 103 | { |
| 104 | about_vncviewer(); |
| 105 | } |
| 106 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 107 | static void CleanupSignalHandler(int sig) |
| 108 | { |
| 109 | // CleanupSignalHandler allows C++ object cleanup to happen because it calls |
| 110 | // exit() rather than the default which is to abort. |
| 111 | vlog.info("CleanupSignalHandler called"); |
| 112 | exit(1); |
| 113 | } |
| 114 | |
| 115 | static void init_fltk() |
| 116 | { |
| 117 | // Basic text size (10pt @ 96 dpi => 13px) |
| 118 | FL_NORMAL_SIZE = 13; |
| 119 | |
| 120 | #ifndef __APPLE__ |
| 121 | // Select a FLTK scheme and background color that looks somewhat |
| 122 | // close to modern Linux and Windows. |
| 123 | Fl::scheme("gtk+"); |
| 124 | Fl::background(220, 220, 220); |
| 125 | #else |
| 126 | // On Mac OS X there is another scheme that fits better though. |
| 127 | Fl::scheme("plastic"); |
| 128 | #endif |
| 129 | |
Henrik Andersson | 3b83703 | 2011-09-19 13:46:55 +0000 | [diff] [blame] | 130 | // Proper Gnome Shell integration requires that we set a sensible |
| 131 | // WM_CLASS for the window. |
| 132 | Fl_Window::default_xclass("vncviewer"); |
| 133 | |
Pierre Ossman | 8eb3508 | 2012-03-27 12:50:54 +0000 | [diff] [blame] | 134 | // Set the default icon for all windows. |
| 135 | #ifdef HAVE_FLTK_ICONS |
| 136 | #ifdef WIN32 |
| 137 | HICON lg, sm; |
| 138 | |
| 139 | lg = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), |
| 140 | IMAGE_ICON, GetSystemMetrics(SM_CXICON), |
| 141 | GetSystemMetrics(SM_CYICON), |
| 142 | LR_DEFAULTCOLOR | LR_SHARED); |
| 143 | sm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), |
| 144 | IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), |
| 145 | GetSystemMetrics(SM_CYSMICON), |
| 146 | LR_DEFAULTCOLOR | LR_SHARED); |
| 147 | |
| 148 | Fl_Window::default_icons(lg, sm); |
| 149 | #elif ! defined(__APPLE__) |
| 150 | const int icon_sizes[] = {48, 32, 24, 16}; |
| 151 | |
| 152 | Fl_PNG_Image *icons[4]; |
| 153 | int count; |
| 154 | |
| 155 | count = 0; |
| 156 | |
| 157 | // FIXME: Follow icon theme specification |
| 158 | for (size_t i = 0;i < sizeof(icon_sizes)/sizeof(icon_sizes[0]);i++) { |
| 159 | char icon_path[PATH_MAX]; |
| 160 | bool exists; |
| 161 | |
Pierre Ossman | 6a007bd | 2012-09-11 10:56:21 +0000 | [diff] [blame] | 162 | sprintf(icon_path, "%s/icons/hicolor/%dx%d/apps/tigervnc.png", |
Pierre Ossman | 8eb3508 | 2012-03-27 12:50:54 +0000 | [diff] [blame] | 163 | DATA_DIR, icon_sizes[i], icon_sizes[i]); |
| 164 | |
| 165 | #ifndef WIN32 |
| 166 | struct stat st; |
| 167 | if (stat(icon_path, &st) != 0) |
| 168 | #else |
| 169 | struct _stat st; |
| 170 | if (_stat(icon_path, &st) != 0) |
| 171 | return(false); |
| 172 | #endif |
| 173 | exists = false; |
| 174 | else |
| 175 | exists = true; |
| 176 | |
| 177 | if (exists) { |
| 178 | icons[count] = new Fl_PNG_Image(icon_path); |
| 179 | if (icons[count]->w() == 0 || |
| 180 | icons[count]->h() == 0 || |
| 181 | icons[count]->d() != 4) { |
| 182 | delete icons[count]; |
| 183 | continue; |
| 184 | } |
| 185 | |
| 186 | count++; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | Fl_Window::default_icons((const Fl_RGB_Image**)icons, count); |
| 191 | |
| 192 | for (int i = 0;i < count;i++) |
| 193 | delete icons[i]; |
| 194 | #endif |
| 195 | #endif // FLTK_HAVE_ICONS |
| 196 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 197 | // This makes the "icon" in dialogs rounded, which fits better |
| 198 | // with the above schemes. |
| 199 | fl_message_icon()->box(FL_UP_BOX); |
| 200 | |
| 201 | // Turn off the annoying behaviour where popups track the mouse. |
| 202 | fl_message_hotspot(false); |
| 203 | |
| 204 | // Avoid empty titles for popups |
| 205 | fl_message_title_default(_("TigerVNC Viewer")); |
| 206 | |
| 207 | #ifdef WIN32 |
| 208 | // Most "normal" Windows apps use this font for UI elements. |
| 209 | Fl::set_font(FL_HELVETICA, "Tahoma"); |
| 210 | #endif |
| 211 | |
| 212 | // FLTK exposes these so that we can translate them. |
| 213 | fl_no = _("No"); |
| 214 | fl_yes = _("Yes"); |
| 215 | fl_ok = _("OK"); |
| 216 | fl_cancel = _("Cancel"); |
| 217 | fl_close = _("Close"); |
Pierre Ossman | b885822 | 2011-04-29 11:51:38 +0000 | [diff] [blame] | 218 | |
| 219 | #ifdef __APPLE__ |
Peter Åstrand | b7c5524 | 2011-08-29 13:14:51 +0000 | [diff] [blame] | 220 | /* Needs trailing space */ |
| 221 | static char fltk_about[16]; |
| 222 | snprintf(fltk_about, sizeof(fltk_about), "%s ", _("About")); |
| 223 | Fl_Mac_App_Menu::about = fltk_about; |
| 224 | static char fltk_hide[16]; |
| 225 | snprintf(fltk_hide, sizeof(fltk_hide), "%s ", _("Hide")); |
| 226 | Fl_Mac_App_Menu::hide = fltk_hide; |
| 227 | static char fltk_quit[16]; |
| 228 | snprintf(fltk_quit, sizeof(fltk_quit), "%s ", _("Quit")); |
| 229 | Fl_Mac_App_Menu::quit = fltk_quit; |
| 230 | |
Pierre Ossman | 41ba603 | 2011-06-16 11:09:31 +0000 | [diff] [blame] | 231 | Fl_Mac_App_Menu::print = ""; // Don't want the print item |
| 232 | Fl_Mac_App_Menu::services = _("Services"); |
Pierre Ossman | 41ba603 | 2011-06-16 11:09:31 +0000 | [diff] [blame] | 233 | Fl_Mac_App_Menu::hide_others = _("Hide Others"); |
| 234 | Fl_Mac_App_Menu::show = _("Show All"); |
Pierre Ossman | 41ba603 | 2011-06-16 11:09:31 +0000 | [diff] [blame] | 235 | |
Pierre Ossman | b885822 | 2011-04-29 11:51:38 +0000 | [diff] [blame] | 236 | fl_mac_set_about(about_callback, NULL); |
| 237 | #endif |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static void mkvnchomedir() |
| 241 | { |
| 242 | // Create .vnc in the user's home directory if it doesn't already exist |
| 243 | char* homeDir = NULL; |
| 244 | |
| 245 | if (getvnchomedir(&homeDir) == -1) { |
| 246 | vlog.error(_("Could not create VNC home directory: can't obtain home " |
| 247 | "directory path.")); |
| 248 | } else { |
| 249 | int result = mkdir(homeDir, 0755); |
| 250 | if (result == -1 && errno != EEXIST) |
| 251 | vlog.error(_("Could not create VNC home directory: %s."), strerror(errno)); |
| 252 | delete [] homeDir; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | static void usage(const char *programName) |
| 257 | { |
| 258 | fprintf(stderr, |
| 259 | "\nusage: %s [parameters] [host:displayNum] [parameters]\n" |
| 260 | " %s [parameters] -listen [port] [parameters]\n", |
| 261 | programName, programName); |
| 262 | fprintf(stderr,"\n" |
| 263 | "Parameters can be turned on with -<param> or off with -<param>=0\n" |
| 264 | "Parameters which take a value can be specified as " |
| 265 | "-<param> <value>\n" |
| 266 | "Other valid forms are <param>=<value> -<param>=<value> " |
| 267 | "--<param>=<value>\n" |
| 268 | "Parameter names are case-insensitive. The parameters are:\n\n"); |
| 269 | Configuration::listParams(79, 14); |
| 270 | exit(1); |
| 271 | } |
| 272 | |
Adam Tkac | 8ac4b30 | 2013-01-23 13:55:46 +0000 | [diff] [blame^] | 273 | #ifndef WIN32 |
| 274 | static int |
| 275 | interpretViaParam(char *remoteHost, int *remotePort, int localPort) |
| 276 | { |
| 277 | const int SERVER_PORT_OFFSET = 5900; |
| 278 | char *pos = strchr(vncServerName, ':'); |
| 279 | if (pos == NULL) |
| 280 | *remotePort = SERVER_PORT_OFFSET; |
| 281 | else { |
| 282 | int portOffset = SERVER_PORT_OFFSET; |
| 283 | size_t len; |
| 284 | *pos++ = '\0'; |
| 285 | len = strlen(pos); |
| 286 | if (*pos == ':') { |
| 287 | /* Two colons is an absolute port number, not an offset. */ |
| 288 | pos++; |
| 289 | len--; |
| 290 | portOffset = 0; |
| 291 | } |
| 292 | if (!len || strspn (pos, "-0123456789") != len ) |
| 293 | return 1; |
| 294 | *remotePort = atoi(pos) + portOffset; |
| 295 | } |
| 296 | |
| 297 | if (*vncServerName != '\0') |
| 298 | strncpy(remoteHost, vncServerName, VNCSERVERNAMELEN); |
| 299 | else |
| 300 | strncpy(remoteHost, "localhost", VNCSERVERNAMELEN); |
| 301 | |
| 302 | remoteHost[VNCSERVERNAMELEN - 1] = '\0'; |
| 303 | |
| 304 | snprintf(vncServerName, VNCSERVERNAMELEN, "localhost::%d", localPort); |
| 305 | vncServerName[VNCSERVERNAMELEN - 1] = '\0'; |
| 306 | vlog.error(vncServerName); |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static void |
| 312 | createTunnel(const char *gatewayHost, const char *remoteHost, |
| 313 | int remotePort, int localPort) |
| 314 | { |
| 315 | char *cmd = getenv("VNC_VIA_CMD"); |
| 316 | char *percent; |
| 317 | char lport[10], rport[10]; |
| 318 | sprintf(lport, "%d", localPort); |
| 319 | sprintf(rport, "%d", remotePort); |
| 320 | setenv("G", gatewayHost, 1); |
| 321 | setenv("H", remoteHost, 1); |
| 322 | setenv("R", rport, 1); |
| 323 | setenv("L", lport, 1); |
| 324 | vlog.error("%s, %s, %d, %d", gatewayHost, remoteHost, rport, lport); |
| 325 | if (!cmd) |
| 326 | cmd = "/usr/bin/ssh -f -L \"$L\":\"$H\":\"$R\" \"$G\" sleep 20"; |
| 327 | /* Compatibility with TigerVNC's method. */ |
| 328 | while ((percent = strchr(cmd, '%')) != NULL) |
| 329 | *percent = '$'; |
| 330 | system(cmd); |
| 331 | } |
| 332 | |
| 333 | static int mktunnel() |
| 334 | { |
| 335 | const char *gatewayHost; |
| 336 | char remoteHost[VNCSERVERNAMELEN]; |
| 337 | int localPort = findFreeTcpPort(); |
| 338 | int remotePort; |
| 339 | |
| 340 | gatewayHost = strDup(via.getValueStr()); |
| 341 | if (interpretViaParam(remoteHost, &remotePort, localPort) != 0) |
| 342 | return 1; |
| 343 | createTunnel(gatewayHost, remoteHost, remotePort, localPort); |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | #endif /* !WIN32 */ |
| 348 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 349 | int main(int argc, char** argv) |
| 350 | { |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 351 | UserDialog dlg; |
| 352 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 353 | setlocale(LC_ALL, ""); |
Pierre Ossman | 0878eca | 2012-03-27 13:03:22 +0000 | [diff] [blame] | 354 | bindtextdomain(PACKAGE_NAME, LOCALE_DIR); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 355 | textdomain(PACKAGE_NAME); |
| 356 | |
| 357 | rfb::SecurityClient::setDefaults(); |
| 358 | |
| 359 | // Write about text to console, still using normal locale codeset |
Pierre Ossman | f52740e | 2012-04-25 15:43:56 +0000 | [diff] [blame] | 360 | fprintf(stderr,"\n"); |
| 361 | fprintf(stderr, gettext(aboutText), (int)sizeof(size_t)*8, |
| 362 | PACKAGE_VERSION, __BUILD__, buildTime); |
| 363 | fprintf(stderr,"\n"); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 364 | |
| 365 | // Set gettext codeset to what our GUI toolkit uses. Since we are |
| 366 | // passing strings from strerror/gai_strerror to the GUI, these must |
| 367 | // be in GUI codeset as well. |
| 368 | bind_textdomain_codeset(PACKAGE_NAME, "UTF-8"); |
| 369 | bind_textdomain_codeset("libc", "UTF-8"); |
| 370 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 371 | rfb::initStdIOLoggers(); |
Pierre Ossman | c8719ad | 2012-04-26 14:27:52 +0000 | [diff] [blame] | 372 | #ifdef WIN32 |
| 373 | rfb::initFileLogger("C:\\temp\\vncviewer.log"); |
| 374 | #else |
| 375 | rfb::initFileLogger("/tmp/vncviewer.log"); |
| 376 | #endif |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 377 | rfb::LogWriter::setLogParams("*:stderr:30"); |
| 378 | |
| 379 | #ifdef SIGHUP |
| 380 | signal(SIGHUP, CleanupSignalHandler); |
| 381 | #endif |
| 382 | signal(SIGINT, CleanupSignalHandler); |
| 383 | signal(SIGTERM, CleanupSignalHandler); |
| 384 | |
| 385 | init_fltk(); |
| 386 | |
| 387 | Configuration::enableViewerParams(); |
| 388 | |
Peter Åstrand | 8a2b081 | 2012-08-08 11:49:01 +0000 | [diff] [blame] | 389 | /* Load the default parameter settings */ |
| 390 | const char* defaultServerName; |
| 391 | try { |
| 392 | defaultServerName = loadViewerParameters(NULL); |
| 393 | } catch (rfb::Exception& e) { |
| 394 | fl_alert("%s", e.str()); |
| 395 | } |
| 396 | |
DRC | 5aa0650 | 2011-06-23 22:04:46 +0000 | [diff] [blame] | 397 | int i = 1; |
| 398 | if (!Fl::args(argc, argv, i) || i < argc) |
| 399 | for (; i < argc; i++) { |
| 400 | if (Configuration::setParam(argv[i])) |
| 401 | continue; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 402 | |
DRC | 5aa0650 | 2011-06-23 22:04:46 +0000 | [diff] [blame] | 403 | if (argv[i][0] == '-') { |
| 404 | if (i+1 < argc) { |
| 405 | if (Configuration::setParam(&argv[i][1], argv[i+1])) { |
| 406 | i++; |
| 407 | continue; |
| 408 | } |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 409 | } |
DRC | 5aa0650 | 2011-06-23 22:04:46 +0000 | [diff] [blame] | 410 | usage(argv[0]); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 411 | } |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 412 | |
Adam Tkac | 8ac4b30 | 2013-01-23 13:55:46 +0000 | [diff] [blame^] | 413 | strncpy(vncServerName, argv[i], VNCSERVERNAMELEN); |
| 414 | vncServerName[VNCSERVERNAMELEN - 1] = '\0'; |
DRC | 5aa0650 | 2011-06-23 22:04:46 +0000 | [diff] [blame] | 415 | } |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 416 | |
| 417 | if (!::autoSelect.hasBeenSet()) { |
| 418 | // Default to AutoSelect=0 if -PreferredEncoding or -FullColor is used |
Peter Åstrand | 8a2b081 | 2012-08-08 11:49:01 +0000 | [diff] [blame] | 419 | if (::preferredEncoding.hasBeenSet() || ::fullColour.hasBeenSet() || |
| 420 | ::fullColourAlias.hasBeenSet()) { |
| 421 | ::autoSelect.setParam(false); |
| 422 | } |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 423 | } |
| 424 | if (!::fullColour.hasBeenSet() && !::fullColourAlias.hasBeenSet()) { |
| 425 | // Default to FullColor=0 if AutoSelect=0 && LowColorLevel is set |
| 426 | if (!::autoSelect && (::lowColourLevel.hasBeenSet() || |
| 427 | ::lowColourLevelAlias.hasBeenSet())) { |
| 428 | ::fullColour.setParam(false); |
| 429 | } |
| 430 | } |
| 431 | if (!::customCompressLevel.hasBeenSet()) { |
| 432 | // Default to CustomCompressLevel=1 if CompressLevel is used. |
Peter Åstrand | 8a2b081 | 2012-08-08 11:49:01 +0000 | [diff] [blame] | 433 | if(::compressLevel.hasBeenSet()) { |
| 434 | ::customCompressLevel.setParam(true); |
| 435 | } |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | mkvnchomedir(); |
| 439 | |
| 440 | CSecurity::upg = &dlg; |
| 441 | #ifdef HAVE_GNUTLS |
| 442 | CSecurityTLS::msg = &dlg; |
| 443 | #endif |
| 444 | |
Adam Tkac | 8ac4b30 | 2013-01-23 13:55:46 +0000 | [diff] [blame^] | 445 | if (vncServerName[0] == '\0') { |
| 446 | ServerDialog::run(defaultServerName, vncServerName); |
| 447 | if (vncServerName[0] == '\0') |
Pierre Ossman | 561ff0c | 2011-05-13 14:04:59 +0000 | [diff] [blame] | 448 | return 1; |
| 449 | } |
| 450 | |
Adam Tkac | 8ac4b30 | 2013-01-23 13:55:46 +0000 | [diff] [blame^] | 451 | #ifndef WIN32 |
| 452 | if (strlen (via.getValueStr()) > 0 && mktunnel() != 0) |
| 453 | usage(argv[0]); |
| 454 | #endif |
| 455 | |
Pierre Ossman | e2ef5c1 | 2011-07-12 16:56:34 +0000 | [diff] [blame] | 456 | CConn *cc = new CConn(vncServerName); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 457 | |
| 458 | while (!exitMainloop) { |
| 459 | int next_timer; |
| 460 | |
| 461 | next_timer = Timer::checkTimeouts(); |
| 462 | if (next_timer == 0) |
| 463 | next_timer = INT_MAX; |
| 464 | |
| 465 | if (Fl::wait((double)next_timer / 1000.0) < 0.0) { |
| 466 | vlog.error(_("Internal FLTK error. Exiting.")); |
| 467 | break; |
| 468 | } |
| 469 | } |
| 470 | |
Pierre Ossman | e2ef5c1 | 2011-07-12 16:56:34 +0000 | [diff] [blame] | 471 | delete cc; |
| 472 | |
| 473 | if (exitError != NULL) |
Pierre Ossman | f52740e | 2012-04-25 15:43:56 +0000 | [diff] [blame] | 474 | fl_alert("%s", exitError); |
Pierre Ossman | e2ef5c1 | 2011-07-12 16:56:34 +0000 | [diff] [blame] | 475 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 476 | return 0; |
| 477 | } |