blob: 73597f52a2d15b282432f4fc61a08058ab12f9d3 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +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 = !window->isToolbarEnabled();
181 window->setShowToolbar(options.showToolbar);
182 return true;
183 case IDM_CTRL_KEY:
184 window->kbd.keyEvent(this, VK_CONTROL, 0, !window->kbd.keyPressed(VK_CONTROL));
185 return true;
186 case IDM_ALT_KEY:
187 window->kbd.keyEvent(this, VK_MENU, 0, !window->kbd.keyPressed(VK_MENU));
188 return true;
189 case IDM_SEND_MENU_KEY:
190 window->kbd.keyEvent(this, options.menuKey, 0, true);
191 window->kbd.keyEvent(this, options.menuKey, 0, false);
192 return true;
193 case IDM_SEND_CAD:
194 window->kbd.keyEvent(this, VK_CONTROL, 0, true);
195 window->kbd.keyEvent(this, VK_MENU, 0, true);
196 window->kbd.keyEvent(this, VK_DELETE, 0x1000000, true);
197 window->kbd.keyEvent(this, VK_DELETE, 0x1000000, false);
198 window->kbd.keyEvent(this, VK_MENU, 0, false);
199 window->kbd.keyEvent(this, VK_CONTROL, 0, false);
200 return true;
201 case IDM_SEND_CTLESC:
202 window->kbd.keyEvent(this, VK_CONTROL, 0, true);
203 window->kbd.keyEvent(this, VK_ESCAPE, 0, true);
204 window->kbd.keyEvent(this, VK_ESCAPE, 0, false);
205 window->kbd.keyEvent(this, VK_CONTROL, 0, false);
206 return true;
207 case IDM_REQUEST_REFRESH:
208 try {
209 writer()->writeFramebufferUpdateRequest(Rect(0,0,cp.width,cp.height), false);
210 requestUpdate = false;
211 } catch (rdr::Exception& e) {
212 close(e.str());
213 }
214 return true;
215 case IDM_NEWCONN:
216 {
217 Thread* newThread = new CConnThread;
218 }
219 return true;
220 case IDM_OPTIONS:
221 // Update the monitor device name in the CConnOptions instance
222 options.monitor.replaceBuf(window->getMonitor());
223 showOptionsDialog();
224 return true;
225 case IDM_INFO:
226 infoDialog.showDialog(this);
227 return true;
228 case IDM_ABOUT:
229 AboutDialog::instance.showDialog();
230 return true;
231 case IDM_FILE_TRANSFER:
232 m_fileTransfer.show(window->getHandle());
233 return true;
234 case IDM_CONN_SAVE_AS:
235 return true;
236 case ID_CLOSE:
237 // FIXME: Remove the corresponding toolbar button.
238 return true;
239 };
240 return false;
241}
242
243
244void
245CConn::closeWindow() {
246 vlog.info("window closed");
247 close();
248}
249
250
251void
252CConn::refreshMenu(bool enableSysItems) {
253 HMENU menu = GetSystemMenu(window->getHandle(), FALSE);
254
255 if (!enableSysItems) {
256 // Gray out menu items that might cause a World Of Pain
257 EnableMenuItem(menu, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
258 EnableMenuItem(menu, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
259 EnableMenuItem(menu, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
260 EnableMenuItem(menu, SC_MINIMIZE, MF_BYCOMMAND | MF_ENABLED);
261 EnableMenuItem(menu, SC_MAXIMIZE, MF_BYCOMMAND | MF_ENABLED);
262 }
263
264 // Update the modifier key menu items
265 UINT ctrlCheckFlags = window->kbd.keyPressed(VK_CONTROL) ? MF_CHECKED : MF_UNCHECKED;
266 UINT altCheckFlags = window->kbd.keyPressed(VK_MENU) ? MF_CHECKED : MF_UNCHECKED;
267 CheckMenuItem(menu, IDM_CTRL_KEY, MF_BYCOMMAND | ctrlCheckFlags);
268 CheckMenuItem(menu, IDM_ALT_KEY, MF_BYCOMMAND | altCheckFlags);
269
270 // Ensure that the Send <MenuKey> menu item has the correct text
271 if (options.menuKey) {
272 TCharArray menuKeyStr(options.menuKeyName());
273 TCharArray tmp(_tcslen(menuKeyStr.buf) + 6);
274 _stprintf(tmp.buf, _T("Send %s"), menuKeyStr.buf);
275 if (!ModifyMenu(menu, IDM_SEND_MENU_KEY, MF_BYCOMMAND | MF_STRING, IDM_SEND_MENU_KEY, tmp.buf))
276 InsertMenu(menu, IDM_SEND_CAD, MF_BYCOMMAND | MF_STRING, IDM_SEND_MENU_KEY, tmp.buf);
277 } else {
278 RemoveMenu(menu, IDM_SEND_MENU_KEY, MF_BYCOMMAND);
279 }
280
281 // Set the menu fullscreen option tick
282 CheckMenuItem(menu, IDM_FULLSCREEN, (window->isFullscreen() ? MF_CHECKED : 0) | MF_BYCOMMAND);
283
284 // Set the menu toolbar option tick
285 int toolbarFlags = window->isToolbarEnabled() ? MF_CHECKED : 0;
286 CheckMenuItem(menu, IDM_SHOW_TOOLBAR, MF_BYCOMMAND | toolbarFlags);
287
288 // In the full-screen mode, "Show toolbar" should be grayed.
289 toolbarFlags = window->isFullscreen() ? MF_GRAYED : MF_ENABLED;
290 EnableMenuItem(menu, IDM_SHOW_TOOLBAR, MF_BYCOMMAND | toolbarFlags);
291}
292
293
294void
295CConn::blockCallback() {
296 // - An InStream has blocked on I/O while processing an RFB message
297 // We re-enable socket event notifications, so we'll know when more
298 // data is available, then we sit and dispatch window events until
299 // the notification arrives.
300 if (!isClosed()) {
301 if (WSAEventSelect(sock->getFd(), sockEvent, FD_READ | FD_CLOSE) == SOCKET_ERROR)
302 throw rdr::SystemException("Unable to wait for sokcet data", WSAGetLastError());
303 }
304 while (true) {
305 // If we have closed then we can't block waiting for data
306 if (isClosed())
307 throw rdr::EndOfStream();
308
309 // Wait for socket data, or a message to process
310 DWORD result = MsgWaitForMultipleObjects(1, &sockEvent.h, FALSE, INFINITE, QS_ALLINPUT);
311 if (result == WAIT_OBJECT_0) {
312 // - Network event notification. Return control to I/O routine.
313 break;
314 } else if (result == WAIT_FAILED) {
315 // - The wait operation failed - raise an exception
316 throw rdr::SystemException("blockCallback wait error", GetLastError());
317 }
318
319 // - There should be a message in the message queue
320 MSG msg;
321 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
322 // IMPORTANT: We mustn't call TranslateMessage() here, because instead we
323 // call ToAscii() in CKeyboard::keyEvent(). ToAscii() stores dead key
324 // state from one call to the next, which would be messed up by calls to
325 // TranslateMessage() (actually it looks like TranslateMessage() calls
326 // ToAscii() internally).
327 DispatchMessage(&msg);
328 }
329 }
330
331 // Before we return control to the InStream, reset the network event
332 WSAEventSelect(sock->getFd(), sockEvent, 0);
333 ResetEvent(sockEvent);
334}
335
336
337void CConn::keyEvent(rdr::U32 key, bool down) {
338 if (!options.sendKeyEvents) return;
339 try {
340 writer()->keyEvent(key, down);
341 } catch (rdr::Exception& e) {
342 close(e.str());
343 }
344}
345void CConn::pointerEvent(const Point& pos, int buttonMask) {
346 if (!options.sendPtrEvents) return;
347 try {
348 writer()->pointerEvent(pos, buttonMask);
349 } catch (rdr::Exception& e) {
350 close(e.str());
351 }
352}
353void CConn::clientCutText(const char* str, int len) {
354 if (!options.clientCutText) return;
355 if (state() != RFBSTATE_NORMAL) return;
356 try {
357 writer()->clientCutText(str, len);
358 } catch (rdr::Exception& e) {
359 close(e.str());
360 }
361}
362
363
364CSecurity* CConn::getCSecurity(int secType)
365{
366 switch (secType) {
367 case secTypeNone:
368 return new CSecurityNone();
369 case secTypeVncAuth:
370 return new CSecurityVncAuth(this);
371 default:
372 throw Exception("Unsupported secType?");
373 }
374}
375
376
377void
378CConn::setColourMapEntries(int first, int count, U16* rgbs) {
379 vlog.debug("setColourMapEntries: first=%d, count=%d", first, count);
380 int i;
381 for (i=0;i<count;i++)
382 window->setColour(i+first, rgbs[i*3], rgbs[i*3+1], rgbs[i*3+2]);
383 // *** change to 0, 256?
384 window->refreshWindowPalette(first, count);
385}
386
387void
388CConn::bell() {
389 if (options.acceptBell)
390 MessageBeep(-1);
391}
392
393
394void
395CConn::setDesktopSize(int w, int h) {
396 vlog.debug("setDesktopSize %dx%d", w, h);
397
398 // Resize the window's buffer
399 if (window)
400 window->setSize(w, h);
401
402 // Tell the underlying CConnection
403 CConnection::setDesktopSize(w, h);
404}
405
406void
407CConn::setCursor(int w, int h, const Point& hotspot, void* data, void* mask) {
408 if (!options.useLocalCursor) return;
409
410 // Set the window to use the new cursor
411 window->setCursor(w, h, hotspot, data, mask);
412}
413
414
415void
416CConn::close(const char* reason) {
417 // If already closed then ignore this
418 if (isClosed())
419 return;
420
421 // Hide the window, if it exists
422 if (window)
423 ShowWindow(window->getHandle(), SW_HIDE);
424
425 // Save the reason & flag that we're closed & shutdown the socket
426 isClosed_ = true;
427 closeReason_.replaceBuf(strDup(reason));
428 sock->shutdown();
429}
430
431
432void
433CConn::showOptionsDialog() {
434 optionsDialog.showDialog(this);
435}
436
437
438void
439CConn::framebufferUpdateEnd() {
440 if (debugDelay != 0) {
441 vlog.debug("debug delay %d",(int)debugDelay);
442 UpdateWindow(window->getHandle());
443 Sleep(debugDelay);
444 std::list<rfb::Rect>::iterator i;
445 for (i = debugRects.begin(); i != debugRects.end(); i++) {
446 window->invertRect(*i);
447 }
448 debugRects.clear();
449 }
450 if (options.autoSelect)
451 autoSelectFormatAndEncoding();
452
453 // Always request the next update
454 requestUpdate = true;
455
456 // Check that at least part of the window has changed
457 if (!GetUpdateRect(window->getHandle(), 0, FALSE)) {
458 if (!(GetWindowLong(window->getHandle(), GWL_STYLE) & WS_MINIMIZE))
459 requestNewUpdate();
460 }
461
462 // Make sure the local cursor is shown
463 window->showCursor();
464}
465
466
467// Note: The method below is duplicated in vncviewer_unix/CConn.cxx!
468
469// autoSelectFormatAndEncoding() chooses the format and encoding appropriate
470// to the connection speed:
471//
472// Above 16Mbps (timing for at least a second), switch to hextile
473// Otherwise, switch to ZRLE
474//
475// Above 256Kbps, use full colour mode
476//
477void
478CConn::autoSelectFormatAndEncoding() {
479 int kbitsPerSecond = sock->inStream().kbitsPerSecond();
480 unsigned int newEncoding = options.preferredEncoding;
481
482 bool newFullColour = options.fullColour;
483 unsigned int timeWaited = sock->inStream().timeWaited();
484
485 // Select best encoding
486 if (kbitsPerSecond > 16000 && timeWaited >= 10000) {
487 newEncoding = encodingHextile;
488 } else {
489 newEncoding = encodingZRLE;
490 }
491
492 if (newEncoding != options.preferredEncoding) {
493 vlog.info("Throughput %d kbit/s - changing to %s encoding",
494 kbitsPerSecond, encodingName(newEncoding));
495 options.preferredEncoding = newEncoding;
496 encodingChange = true;
497 }
498
499 if (kbitsPerSecond == 0) {
500 return;
501 }
502
503 if (cp.beforeVersion(3, 8)) {
504 // Xvnc from TightVNC 1.2.9 sends out FramebufferUpdates with
505 // cursors "asynchronously". If this happens in the middle of a
506 // pixel format change, the server will encode the cursor with
507 // the old format, but the client will try to decode it
508 // according to the new format. This will lead to a
509 // crash. Therefore, we do not allow automatic format change for
510 // old servers.
511 return;
512 }
513
514 // Select best color level
515 newFullColour = (kbitsPerSecond > 256);
516 if (newFullColour != options.fullColour) {
517 vlog.info("Throughput %d kbit/s - full color is now %s",
518 kbitsPerSecond,
519 newFullColour ? "enabled" : "disabled");
520 options.fullColour = newFullColour;
521 formatChange = true;
522 }
523}
524
525void
526CConn::requestNewUpdate() {
527 if (!requestUpdate) return;
528
529 if (formatChange) {
530 // Select the required pixel format
531 if (options.fullColour) {
532 window->setPF(fullColourPF);
533 } else {
534 switch (options.lowColourLevel) {
535 case 0:
536 window->setPF(PixelFormat(8,3,0,1,1,1,1,2,1,0));
537 break;
538 case 1:
539 window->setPF(PixelFormat(8,6,0,1,3,3,3,4,2,0));
540 break;
541 case 2:
542 window->setPF(PixelFormat(8,8,0,0,0,0,0,0,0,0));
543 break;
544 }
545 }
546
547 // Print the current pixel format
548 char str[256];
549 window->getPF().print(str, 256);
550 vlog.info("Using pixel format %s",str);
551
552 // Save the connection pixel format and tell server to use it
553 cp.setPF(window->getPF());
554 writer()->writeSetPixelFormat(cp.pf());
555
556 // Correct the local window's palette
557 if (!window->getNativePF().trueColour)
558 window->refreshWindowPalette(0, 1 << cp.pf().depth);
559 }
560
561 if (encodingChange) {
562 vlog.info("Using %s encoding",encodingName(options.preferredEncoding));
563 writer()->writeSetEncodings(options.preferredEncoding, true);
564 }
565
566 writer()->writeFramebufferUpdateRequest(Rect(0, 0, cp.width, cp.height),
567 !formatChange);
568
569 encodingChange = formatChange = requestUpdate = false;
570}
571
572
573void
574CConn::calculateFullColourPF() {
575 // If the server is palette based then use palette locally
576 // Also, don't bother doing bgr222
577 if (!serverDefaultPF.trueColour || (serverDefaultPF.depth < 6)) {
578 fullColourPF = serverDefaultPF;
579 options.fullColour = true;
580 } else {
581 // If server is trueColour, use lowest depth PF
582 PixelFormat native = window->getNativePF();
583 if ((serverDefaultPF.bpp < native.bpp) ||
584 ((serverDefaultPF.bpp == native.bpp) &&
585 (serverDefaultPF.depth < native.depth)))
586 fullColourPF = serverDefaultPF;
587 else
588 fullColourPF = window->getNativePF();
589 }
590 formatChange = true;
591}
592
593
594void
595CConn::setName(const char* name) {
596 if (window)
597 window->setName(name);
598 CConnection::setName(name);
599}
600
601
602void CConn::serverInit() {
603 CConnection::serverInit();
604
605 // If using AutoSelect with old servers, start in FullColor
606 // mode. See comment in autoSelectFormatAndEncoding.
607 if (cp.beforeVersion(3, 8) && options.autoSelect) {
608 options.fullColour = true;
609 }
610
611 // Show the window
612 window = new DesktopWindow(this);
613 window->setName(cp.name());
614 window->setSize(cp.width, cp.height);
615 applyOptions(options);
616
617 // Save the server's current format
618 serverDefaultPF = cp.pf();
619
620 // Calculate the full-colour format to use
621 calculateFullColourPF();
622
623 // Request the initial update
624 vlog.info("requesting initial update");
625 formatChange = encodingChange = requestUpdate = true;
626 requestNewUpdate();
627
628 // Update the window menu
629 HMENU wndmenu = GetSystemMenu(window->getHandle(), FALSE);
630 int toolbarChecked = options.showToolbar ? MF_CHECKED : 0;
631
632 AppendMenu(wndmenu, MF_SEPARATOR, 0, 0);
633 AppendMenu(wndmenu, MF_STRING, IDM_FULLSCREEN, _T("&Full screen"));
634 AppendMenu(wndmenu, MF_STRING | toolbarChecked, IDM_SHOW_TOOLBAR,
635 _T("Show tool&bar"));
636 AppendMenu(wndmenu, MF_SEPARATOR, 0, 0);
637 AppendMenu(wndmenu, MF_STRING, IDM_CTRL_KEY, _T("Ctr&l"));
638 AppendMenu(wndmenu, MF_STRING, IDM_ALT_KEY, _T("Al&t"));
639 AppendMenu(wndmenu, MF_STRING, IDM_SEND_CAD, _T("Send Ctrl-Alt-&Del"));
640 AppendMenu(wndmenu, MF_STRING, IDM_SEND_CTLESC, _T("Send Ctrl-&Esc"));
641 AppendMenu(wndmenu, MF_STRING, IDM_REQUEST_REFRESH, _T("Refres&h Screen"));
642 AppendMenu(wndmenu, MF_SEPARATOR, 0, 0);
643 AppendMenu(wndmenu, MF_STRING, IDM_NEWCONN, _T("Ne&w Connection..."));
644 AppendMenu(wndmenu, MF_STRING, IDM_OPTIONS, _T("&Options..."));
645 AppendMenu(wndmenu, MF_STRING, IDM_INFO, _T("Connection &Info..."));
646 AppendMenu(wndmenu, MF_STRING, IDM_ABOUT, _T("&About..."));
647}
648
649void
650CConn::serverCutText(const char* str, int len) {
651 if (!options.serverCutText) return;
652 window->serverCutText(str, len);
653}
654
655
656void CConn::beginRect(const Rect& r, unsigned int encoding) {
657 sock->inStream().startTiming();
658}
659
660void CConn::endRect(const Rect& r, unsigned int encoding) {
661 sock->inStream().stopTiming();
662 lastUsedEncoding_ = encoding;
663 if (debugDelay != 0) {
664 window->invertRect(r);
665 debugRects.push_back(r);
666 }
667}
668
669void CConn::fillRect(const Rect& r, Pixel pix) {
670 window->fillRect(r, pix);
671}
672void CConn::imageRect(const Rect& r, void* pixels) {
673 window->imageRect(r, pixels);
674}
675void CConn::copyRect(const Rect& r, int srcX, int srcY) {
676 window->copyRect(r, srcX, srcY);
677}
678
679void CConn::getUserPasswd(char** user, char** password) {
680 if (!user && options.passwordFile.buf[0]) {
681 FILE* fp = fopen(options.passwordFile.buf, "rb");
682 if (fp) {
683 char data[256];
684 int datalen = fread(data, 1, 256, fp);
685 fclose(fp);
686 if (datalen == 8) {
687 ObfuscatedPasswd obfPwd;
688 obfPwd.buf = data;
689 obfPwd.length = datalen;
690 PlainPasswd passwd(obfPwd);
691 *password = strDup(passwd.buf);
692 memset(data, 0, strlen(data));
693 }
694 }
695 }
696 if (user && options.userName.buf)
697 *user = strDup(options.userName.buf);
698 if (password && options.password.buf)
699 *password = strDup(options.password.buf);
700 if ((user && !*user) || (password && !*password)) {
701 // Missing username or password - prompt the user
702 UserPasswdDialog userPasswdDialog;
703 userPasswdDialog.setCSecurity(getCurrentCSecurity());
704 userPasswdDialog.getUserPasswd(user, password);
705 }
706 if (user) options.setUserName(*user);
707 if (password) options.setPassword(*password);
708}
709
710bool CConn::processFTMsg(int type) {
711 return m_fileTransfer.processFTMsg(type);
712}