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