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