blob: 2d90730add8c4a6a7b8a35b0da8a33ea7285bbf3 [file] [log] [blame]
Constantin Kaplinskyac306682006-05-16 08:48:31 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19#include <windows.h>
20#include <winsock2.h>
21#include <vncviewer/UserPasswdDialog.h>
22#include <vncviewer/CConn.h>
23#include <vncviewer/CConnThread.h>
24#include <vncviewer/resource.h>
25#include <rfb/encodings.h>
26#include <rfb/secTypes.h>
27#include <rfb/CSecurityNone.h>
28#include <rfb/CSecurityVncAuth.h>
29#include <rfb/CMsgWriter.h>
30#include <rfb/Configuration.h>
31#include <rfb/LogWriter.h>
32#include <rfb_win32/AboutDialog.h>
33
34using namespace rfb;
35using namespace rfb::win32;
36using namespace rdr;
37
38// - Statics & consts
39
40static LogWriter vlog("CConn");
41
42
43const int IDM_FULLSCREEN = ID_FULLSCREEN;
44const int IDM_SEND_MENU_KEY = ID_SEND_MENU_KEY;
45const int IDM_SEND_CAD = ID_SEND_CAD;
46const int IDM_SEND_CTLESC = ID_SEND_CTLESC;
47const int IDM_ABOUT = ID_ABOUT;
48const int IDM_OPTIONS = ID_OPTIONS;
49const int IDM_INFO = ID_INFO;
50const int IDM_NEWCONN = ID_NEW_CONNECTION;
51const int IDM_REQUEST_REFRESH = ID_REQUEST_REFRESH;
52const int IDM_CTRL_KEY = ID_CTRL_KEY;
53const int IDM_ALT_KEY = ID_ALT_KEY;
54const int IDM_FILE_TRANSFER = ID_FILE_TRANSFER;
55const int IDM_CONN_SAVE_AS = ID_CONN_SAVE_AS;
56
57
58static IntParameter debugDelay("DebugDelay","Milliseconds to display inverted "
59 "pixel data - a debugging feature", 0);
60
61
62//
63// -=- CConn implementation
64//
65
66RegKey CConn::userConfigKey;
67
68
69CConn::CConn()
70 : window(0), sock(0), sockEvent(CreateEvent(0, TRUE, FALSE, 0)), requestUpdate(false),
71 sameMachine(false), encodingChange(false), formatChange(false),
72 reverseConnection(false), lastUsedEncoding_(encodingRaw), isClosed_(false) {
73}
74
75CConn::~CConn() {
76 delete window;
77}
78
79bool CConn::initialise(network::Socket* s, bool reverse) {
80 // Set the server's name for MRU purposes
81 CharArray endpoint(s->getPeerEndpoint());
82 setServerName(endpoint.buf);
83 if (!options.host.buf)
84 options.setHost(endpoint.buf);
85
86 // Initialise the underlying CConnection
87 setStreams(&s->inStream(), &s->outStream());
88
89 // Enable processing of window messages while blocked on I/O
90 s->inStream().setBlockCallback(this);
91
92 // Initialise the viewer options
93 applyOptions(options);
94
95 // - Set which auth schemes we support, in order of preference
96 addSecType(secTypeVncAuth);
97 addSecType(secTypeNone);
98
99 // Start the RFB protocol
100 sock = s;
101 reverseConnection = reverse;
102 initialiseProtocol();
103
104 m_fileTransfer.initialize(&s->inStream(), &s->outStream());
105
106 return true;
107}
108
109
110void
111CConn::applyOptions(CConnOptions& opt) {
112 // - If any encoding-related settings have changed then we must
113 // notify the server of the new settings
114 encodingChange |= ((options.useLocalCursor != opt.useLocalCursor) ||
115 (options.useDesktopResize != opt.useDesktopResize) ||
116 (options.customCompressLevel != opt.customCompressLevel) ||
117 (options.compressLevel != opt.compressLevel) ||
118 (options.noJpeg != opt.noJpeg) ||
119 (options.qualityLevel != opt.qualityLevel) ||
120 (options.preferredEncoding != opt.preferredEncoding));
121
122 // - If the preferred pixel format has changed then notify the server
123 formatChange |= (options.fullColour != opt.fullColour);
124 if (!opt.fullColour)
125 formatChange |= (options.lowColourLevel != opt.lowColourLevel);
126
127 // - Save the new set of options
128 options = opt;
129
130 // - Set optional features in ConnParams
131 cp.supportsLocalCursor = options.useLocalCursor;
132 cp.supportsDesktopResize = options.useDesktopResize;
133 cp.customCompressLevel = options.customCompressLevel;
134 cp.compressLevel = options.compressLevel;
135 cp.noJpeg = options.noJpeg;
136 cp.qualityLevel = options.qualityLevel;
137
138 // - Configure connection sharing on/off
139 setShared(options.shared);
140
141 // - Whether to use protocol 3.3 for legacy compatibility
142 setProtocol3_3(options.protocol3_3);
143
144 // - Apply settings that affect the window, if it is visible
145 if (window) {
146 window->setMonitor(options.monitor.buf);
147 window->setFullscreen(options.fullScreen);
148 window->setEmulate3(options.emulate3);
149 window->setPointerEventInterval(options.pointerEventInterval);
150 window->setMenuKey(options.menuKey);
151 window->setDisableWinKeys(options.disableWinKeys);
152 window->setShowToolbar(options.showToolbar);
153 if (!options.useLocalCursor)
154 window->setCursor(0, 0, Point(), 0, 0);
155 }
156}
157
158
159void
160CConn::displayChanged() {
161 // Display format has changed - recalculate the full-colour pixel format
162 calculateFullColourPF();
163}
164
165void
166CConn::paintCompleted() {
167 // A repaint message has just completed - request next update if necessary
168 requestNewUpdate();
169}
170
171bool
172CConn::sysCommand(WPARAM wParam, LPARAM lParam) {
173 // - If it's one of our (F8 Menu) messages
174 switch (wParam) {
175 case IDM_FULLSCREEN:
176 options.fullScreen = !window->isFullscreen();
177 window->setFullscreen(options.fullScreen);
178 return true;
179 case IDM_SHOW_TOOLBAR:
180 options.showToolbar = !options.showToolbar;
181 window->setShowToolbar(options.showToolbar);
182 // FIXME: Update menu in DesktopWindow?
183 // FIXME: Actually show or hide the toolbar?
184 return true;
185 case IDM_CTRL_KEY:
186 window->kbd.keyEvent(this, VK_CONTROL, 0, !window->kbd.keyPressed(VK_CONTROL));
187 return true;
188 case IDM_ALT_KEY:
189 window->kbd.keyEvent(this, VK_MENU, 0, !window->kbd.keyPressed(VK_MENU));
190 return true;
191 case IDM_SEND_MENU_KEY:
192 window->kbd.keyEvent(this, options.menuKey, 0, true);
193 window->kbd.keyEvent(this, options.menuKey, 0, false);
194 return true;
195 case IDM_SEND_CAD:
196 window->kbd.keyEvent(this, VK_CONTROL, 0, true);
197 window->kbd.keyEvent(this, VK_MENU, 0, true);
198 window->kbd.keyEvent(this, VK_DELETE, 0x1000000, true);
199 window->kbd.keyEvent(this, VK_DELETE, 0x1000000, false);
200 window->kbd.keyEvent(this, VK_MENU, 0, false);
201 window->kbd.keyEvent(this, VK_CONTROL, 0, false);
202 return true;
203 case IDM_SEND_CTLESC:
204 window->kbd.keyEvent(this, VK_CONTROL, 0, true);
205 window->kbd.keyEvent(this, VK_ESCAPE, 0, true);
206 window->kbd.keyEvent(this, VK_ESCAPE, 0, false);
207 window->kbd.keyEvent(this, VK_CONTROL, 0, false);
208 return true;
209 case IDM_REQUEST_REFRESH:
210 try {
211 writer()->writeFramebufferUpdateRequest(Rect(0,0,cp.width,cp.height), false);
212 requestUpdate = false;
213 } catch (rdr::Exception& e) {
214 close(e.str());
215 }
216 return true;
217 case IDM_NEWCONN:
218 {
219 Thread* newThread = new CConnThread;
220 }
221 return true;
222 case IDM_OPTIONS:
223 // Update the monitor device name in the CConnOptions instance
224 options.monitor.replaceBuf(window->getMonitor());
225 showOptionsDialog();
226 return true;
227 case IDM_INFO:
228 infoDialog.showDialog(this);
229 return true;
230 case IDM_ABOUT:
231 AboutDialog::instance.showDialog();
232 return true;
233 case IDM_FILE_TRANSFER:
234 m_fileTransfer.show(window->getHandle());
235 return true;
236 case IDM_CONN_SAVE_AS:
237 return true;
238 case ID_CLOSE:
239 // FIXME: Remove the corresponding toolbar button.
240 return true;
241 };
242 return false;
243}
244
245
246void
247CConn::closeWindow() {
248 vlog.info("window closed");
249 close();
250}
251
252
253void
254CConn::refreshMenu(bool enableSysItems) {
255 HMENU menu = GetSystemMenu(window->getHandle(), FALSE);
256
257 if (!enableSysItems) {
258 // Gray out menu items that might cause a World Of Pain
259 EnableMenuItem(menu, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
260 EnableMenuItem(menu, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
261 EnableMenuItem(menu, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
262 EnableMenuItem(menu, SC_MINIMIZE, MF_BYCOMMAND | MF_ENABLED);
263 EnableMenuItem(menu, SC_MAXIMIZE, MF_BYCOMMAND | MF_ENABLED);
264 }
265
266 // Update the modifier key menu items
267 UINT ctrlCheckFlags = window->kbd.keyPressed(VK_CONTROL) ? MF_CHECKED : MF_UNCHECKED;
268 UINT altCheckFlags = window->kbd.keyPressed(VK_MENU) ? MF_CHECKED : MF_UNCHECKED;
269 CheckMenuItem(menu, IDM_CTRL_KEY, MF_BYCOMMAND | ctrlCheckFlags);
270 CheckMenuItem(menu, IDM_ALT_KEY, MF_BYCOMMAND | altCheckFlags);
271
272 // Ensure that the Send <MenuKey> menu item has the correct text
273 if (options.menuKey) {
274 TCharArray menuKeyStr(options.menuKeyName());
275 TCharArray tmp(_tcslen(menuKeyStr.buf) + 6);
276 _stprintf(tmp.buf, _T("Send %s"), menuKeyStr.buf);
277 if (!ModifyMenu(menu, IDM_SEND_MENU_KEY, MF_BYCOMMAND | MF_STRING, IDM_SEND_MENU_KEY, tmp.buf))
278 InsertMenu(menu, IDM_SEND_CAD, MF_BYCOMMAND | MF_STRING, IDM_SEND_MENU_KEY, tmp.buf);
279 } else {
280 RemoveMenu(menu, IDM_SEND_MENU_KEY, MF_BYCOMMAND);
281 }
282
283 // Set the menu fullscreen option tick
284 CheckMenuItem(menu, IDM_FULLSCREEN, (window->isFullscreen() ? MF_CHECKED : 0) | MF_BYCOMMAND);
285
286 // In the full-screen mode, "Show toolbar" should be grayed.
287 int toolbarFlags = options.fullScreen ? MF_GRAYED : MF_ENABLED;
288 EnableMenuItem(menu, IDM_SHOW_TOOLBAR, MF_BYCOMMAND | toolbarFlags);
289}
290
291
292void
293CConn::blockCallback() {
294 // - An InStream has blocked on I/O while processing an RFB message
295 // We re-enable socket event notifications, so we'll know when more
296 // data is available, then we sit and dispatch window events until
297 // the notification arrives.
298 if (!isClosed()) {
299 if (WSAEventSelect(sock->getFd(), sockEvent, FD_READ | FD_CLOSE) == SOCKET_ERROR)
300 throw rdr::SystemException("Unable to wait for sokcet data", WSAGetLastError());
301 }
302 while (true) {
303 // If we have closed then we can't block waiting for data
304 if (isClosed())
305 throw rdr::EndOfStream();
306
307 // Wait for socket data, or a message to process
308 DWORD result = MsgWaitForMultipleObjects(1, &sockEvent.h, FALSE, INFINITE, QS_ALLINPUT);
309 if (result == WAIT_OBJECT_0) {
310 // - Network event notification. Return control to I/O routine.
311 break;
312 } else if (result == WAIT_FAILED) {
313 // - The wait operation failed - raise an exception
314 throw rdr::SystemException("blockCallback wait error", GetLastError());
315 }
316
317 // - There should be a message in the message queue
318 MSG msg;
319 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
320 // IMPORTANT: We mustn't call TranslateMessage() here, because instead we
321 // call ToAscii() in CKeyboard::keyEvent(). ToAscii() stores dead key
322 // state from one call to the next, which would be messed up by calls to
323 // TranslateMessage() (actually it looks like TranslateMessage() calls
324 // ToAscii() internally).
325 DispatchMessage(&msg);
326 }
327 }
328
329 // Before we return control to the InStream, reset the network event
330 WSAEventSelect(sock->getFd(), sockEvent, 0);
331 ResetEvent(sockEvent);
332}
333
334
335void CConn::keyEvent(rdr::U32 key, bool down) {
336 if (!options.sendKeyEvents) return;
337 try {
338 writer()->keyEvent(key, down);
339 } catch (rdr::Exception& e) {
340 close(e.str());
341 }
342}
343void CConn::pointerEvent(const Point& pos, int buttonMask) {
344 if (!options.sendPtrEvents) return;
345 try {
346 writer()->pointerEvent(pos, buttonMask);
347 } catch (rdr::Exception& e) {
348 close(e.str());
349 }
350}
351void CConn::clientCutText(const char* str, int len) {
352 if (!options.clientCutText) return;
353 if (state() != RFBSTATE_NORMAL) return;
354 try {
355 writer()->clientCutText(str, len);
356 } catch (rdr::Exception& e) {
357 close(e.str());
358 }
359}
360
361
362CSecurity* CConn::getCSecurity(int secType)
363{
364 switch (secType) {
365 case secTypeNone:
366 return new CSecurityNone();
367 case secTypeVncAuth:
368 return new CSecurityVncAuth(this);
369 default:
370 throw Exception("Unsupported secType?");
371 }
372}
373
374
375void
376CConn::setColourMapEntries(int first, int count, U16* rgbs) {
377 vlog.debug("setColourMapEntries: first=%d, count=%d", first, count);
378 int i;
379 for (i=0;i<count;i++)
380 window->setColour(i+first, rgbs[i*3], rgbs[i*3+1], rgbs[i*3+2]);
381 // *** change to 0, 256?
382 window->refreshWindowPalette(first, count);
383}
384
385void
386CConn::bell() {
387 if (options.acceptBell)
388 MessageBeep(-1);
389}
390
391
392void
393CConn::setDesktopSize(int w, int h) {
394 vlog.debug("setDesktopSize %dx%d", w, h);
395
396 // Resize the window's buffer
397 if (window)
398 window->setSize(w, h);
399
400 // Tell the underlying CConnection
401 CConnection::setDesktopSize(w, h);
402}
403
404void
405CConn::setCursor(int w, int h, const Point& hotspot, void* data, void* mask) {
406 if (!options.useLocalCursor) return;
407
408 // Set the window to use the new cursor
409 window->setCursor(w, h, hotspot, data, mask);
410}
411
412
413void
414CConn::close(const char* reason) {
415 // If already closed then ignore this
416 if (isClosed())
417 return;
418
419 // Hide the window, if it exists
420 if (window)
421 ShowWindow(window->getHandle(), SW_HIDE);
422
423 // Save the reason & flag that we're closed & shutdown the socket
424 isClosed_ = true;
425 closeReason_.replaceBuf(strDup(reason));
426 sock->shutdown();
427}
428
429
430void
431CConn::showOptionsDialog() {
432 optionsDialog.showDialog(this);
433}
434
435
436void
437CConn::framebufferUpdateEnd() {
438 if (debugDelay != 0) {
439 vlog.debug("debug delay %d",(int)debugDelay);
440 UpdateWindow(window->getHandle());
441 Sleep(debugDelay);
442 std::list<rfb::Rect>::iterator i;
443 for (i = debugRects.begin(); i != debugRects.end(); i++) {
444 window->invertRect(*i);
445 }
446 debugRects.clear();
447 }
448 if (options.autoSelect)
449 autoSelectFormatAndEncoding();
450
451 // Always request the next update
452 requestUpdate = true;
453
454 // Check that at least part of the window has changed
455 if (!GetUpdateRect(window->getHandle(), 0, FALSE)) {
456 if (!(GetWindowLong(window->getHandle(), GWL_STYLE) & WS_MINIMIZE))
457 requestNewUpdate();
458 }
459
460 // Make sure the local cursor is shown
461 window->showCursor();
462}
463
464
465// Note: The method below is duplicated in vncviewer_unix/CConn.cxx!
466
467// autoSelectFormatAndEncoding() chooses the format and encoding appropriate
468// to the connection speed:
469//
470// Above 16Mbps (timing for at least a second), switch to hextile
471// Otherwise, switch to ZRLE
472//
473// Above 256Kbps, use full colour mode
474//
475void
476CConn::autoSelectFormatAndEncoding() {
477 int kbitsPerSecond = sock->inStream().kbitsPerSecond();
478 unsigned int newEncoding = options.preferredEncoding;
479
480 bool newFullColour = options.fullColour;
481 unsigned int timeWaited = sock->inStream().timeWaited();
482
483 // Select best encoding
484 if (kbitsPerSecond > 16000 && timeWaited >= 10000) {
485 newEncoding = encodingHextile;
486 } else {
487 newEncoding = encodingZRLE;
488 }
489
490 if (newEncoding != options.preferredEncoding) {
491 vlog.info("Throughput %d kbit/s - changing to %s encoding",
492 kbitsPerSecond, encodingName(newEncoding));
493 options.preferredEncoding = newEncoding;
494 encodingChange = true;
495 }
496
497 if (kbitsPerSecond == 0) {
498 return;
499 }
500
501 if (cp.beforeVersion(3, 8)) {
502 // Xvnc from TightVNC 1.2.9 sends out FramebufferUpdates with
503 // cursors "asynchronously". If this happens in the middle of a
504 // pixel format change, the server will encode the cursor with
505 // the old format, but the client will try to decode it
506 // according to the new format. This will lead to a
507 // crash. Therefore, we do not allow automatic format change for
508 // old servers.
509 return;
510 }
511
512 // Select best color level
513 newFullColour = (kbitsPerSecond > 256);
514 if (newFullColour != options.fullColour) {
515 vlog.info("Throughput %d kbit/s - full color is now %s",
516 kbitsPerSecond,
517 newFullColour ? "enabled" : "disabled");
518 options.fullColour = newFullColour;
519 formatChange = true;
520 }
521}
522
523void
524CConn::requestNewUpdate() {
525 if (!requestUpdate) return;
526
527 if (formatChange) {
528 // Select the required pixel format
529 if (options.fullColour) {
530 window->setPF(fullColourPF);
531 } else {
532 switch (options.lowColourLevel) {
533 case 0:
534 window->setPF(PixelFormat(8,3,0,1,1,1,1,2,1,0));
535 break;
536 case 1:
537 window->setPF(PixelFormat(8,6,0,1,3,3,3,4,2,0));
538 break;
539 case 2:
540 window->setPF(PixelFormat(8,8,0,0,0,0,0,0,0,0));
541 break;
542 }
543 }
544
545 // Print the current pixel format
546 char str[256];
547 window->getPF().print(str, 256);
548 vlog.info("Using pixel format %s",str);
549
550 // Save the connection pixel format and tell server to use it
551 cp.setPF(window->getPF());
552 writer()->writeSetPixelFormat(cp.pf());
553
554 // Correct the local window's palette
555 if (!window->getNativePF().trueColour)
556 window->refreshWindowPalette(0, 1 << cp.pf().depth);
557 }
558
559 if (encodingChange) {
560 vlog.info("Using %s encoding",encodingName(options.preferredEncoding));
561 writer()->writeSetEncodings(options.preferredEncoding, true);
562 }
563
564 writer()->writeFramebufferUpdateRequest(Rect(0, 0, cp.width, cp.height),
565 !formatChange);
566
567 encodingChange = formatChange = requestUpdate = false;
568}
569
570
571void
572CConn::calculateFullColourPF() {
573 // If the server is palette based then use palette locally
574 // Also, don't bother doing bgr222
575 if (!serverDefaultPF.trueColour || (serverDefaultPF.depth < 6)) {
576 fullColourPF = serverDefaultPF;
577 options.fullColour = true;
578 } else {
579 // If server is trueColour, use lowest depth PF
580 PixelFormat native = window->getNativePF();
581 if ((serverDefaultPF.bpp < native.bpp) ||
582 ((serverDefaultPF.bpp == native.bpp) &&
583 (serverDefaultPF.depth < native.depth)))
584 fullColourPF = serverDefaultPF;
585 else
586 fullColourPF = window->getNativePF();
587 }
588 formatChange = true;
589}
590
591
592void
593CConn::setName(const char* name) {
594 if (window)
595 window->setName(name);
596 CConnection::setName(name);
597}
598
599
600void CConn::serverInit() {
601 CConnection::serverInit();
602
603 // If using AutoSelect with old servers, start in FullColor
604 // mode. See comment in autoSelectFormatAndEncoding.
605 if (cp.beforeVersion(3, 8) && options.autoSelect) {
606 options.fullColour = true;
607 }
608
609 // Show the window
610 window = new DesktopWindow(this);
611 window->setName(cp.name());
612 window->setSize(cp.width, cp.height);
613 applyOptions(options);
614
615 // Save the server's current format
616 serverDefaultPF = cp.pf();
617
618 // Calculate the full-colour format to use
619 calculateFullColourPF();
620
621 // Request the initial update
622 vlog.info("requesting initial update");
623 formatChange = encodingChange = requestUpdate = true;
624 requestNewUpdate();
625
626 // Update the window menu
627 HMENU wndmenu = GetSystemMenu(window->getHandle(), FALSE);
628 int toolbarChecked = options.showToolbar ? MF_CHECKED : 0;
629
630 AppendMenu(wndmenu, MF_SEPARATOR, 0, 0);
631 AppendMenu(wndmenu, MF_STRING, IDM_FULLSCREEN, _T("&Full screen"));
632 AppendMenu(wndmenu, MF_STRING | toolbarChecked, IDM_SHOW_TOOLBAR,
633 _T("Show tool&bar"));
634 AppendMenu(wndmenu, MF_SEPARATOR, 0, 0);
635 AppendMenu(wndmenu, MF_STRING, IDM_CTRL_KEY, _T("Ctr&l"));
636 AppendMenu(wndmenu, MF_STRING, IDM_ALT_KEY, _T("Al&t"));
637 AppendMenu(wndmenu, MF_STRING, IDM_SEND_CAD, _T("Send Ctrl-Alt-&Del"));
638 AppendMenu(wndmenu, MF_STRING, IDM_SEND_CTLESC, _T("Send Ctrl-&Esc"));
639 AppendMenu(wndmenu, MF_STRING, IDM_REQUEST_REFRESH, _T("Refres&h Screen"));
640 AppendMenu(wndmenu, MF_SEPARATOR, 0, 0);
641 AppendMenu(wndmenu, MF_STRING, IDM_NEWCONN, _T("Ne&w Connection..."));
642 AppendMenu(wndmenu, MF_STRING, IDM_OPTIONS, _T("&Options..."));
643 AppendMenu(wndmenu, MF_STRING, IDM_INFO, _T("Connection &Info..."));
644 AppendMenu(wndmenu, MF_STRING, IDM_ABOUT, _T("&About..."));
645}
646
647void
648CConn::serverCutText(const char* str, int len) {
649 if (!options.serverCutText) return;
650 window->serverCutText(str, len);
651}
652
653
654void CConn::beginRect(const Rect& r, unsigned int encoding) {
655 sock->inStream().startTiming();
656}
657
658void CConn::endRect(const Rect& r, unsigned int encoding) {
659 sock->inStream().stopTiming();
660 lastUsedEncoding_ = encoding;
661 if (debugDelay != 0) {
662 window->invertRect(r);
663 debugRects.push_back(r);
664 }
665}
666
667void CConn::fillRect(const Rect& r, Pixel pix) {
668 window->fillRect(r, pix);
669}
670void CConn::imageRect(const Rect& r, void* pixels) {
671 window->imageRect(r, pixels);
672}
673void CConn::copyRect(const Rect& r, int srcX, int srcY) {
674 window->copyRect(r, srcX, srcY);
675}
676
677void CConn::getUserPasswd(char** user, char** password) {
678/*
679 if (!user && options.passwordFile.buf[0]) {
680 FILE* fp = fopen(options.passwordFile.buf, "rb");
681 if (!fp) return false;
682 char data[256];
683 int datalen = fread(data, 1, 256, fp);
684 fclose(fp);
685 if (datalen != 8) return false;
686 vncAuthUnobfuscatePasswd(data);
687 *password = strDup(data);
688 memset(data, 0, strlen(data));
689 return true;
690 }
691*/
692 if (user && options.userName.buf)
693 *user = strDup(options.userName.buf);
694 if (password && options.password.buf)
695 *password = strDup(options.password.buf);
696 if ((user && !*user) || (password && !*password)) {
697 // Missing username or password - prompt the user
698 UserPasswdDialog userPasswdDialog;
699 userPasswdDialog.setCSecurity(getCurrentCSecurity());
700 userPasswdDialog.getUserPasswd(user, password);
701 }
702 if (user) options.setUserName(*user);
703 if (password) options.setPassword(*password);
704}
705
706bool CConn::processFTMsg(int type) {
707 return m_fileTransfer.processFTMsg(type);
708}