Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* 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 | #include <stdio.h> |
| 19 | #include <string.h> |
| 20 | #include <rfb/Exception.h> |
Adam Tkac | 5a0caed | 2010-04-23 13:58:10 +0000 | [diff] [blame] | 21 | #include <rfb/Security.h> |
Constantin Kaplinsky | dafbb01 | 2007-04-05 08:43:25 +0000 | [diff] [blame] | 22 | #include <rfb/msgTypes.h> |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 23 | #include <rfb/CapsList.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 24 | #include <rfb/SMsgReaderV3.h> |
| 25 | #include <rfb/SMsgWriterV3.h> |
| 26 | #include <rfb/SConnection.h> |
| 27 | #include <rfb/ServerCore.h> |
| 28 | |
| 29 | #include <rfb/LogWriter.h> |
| 30 | |
| 31 | using namespace rfb; |
| 32 | |
| 33 | static LogWriter vlog("SConnection"); |
| 34 | |
| 35 | // AccessRights values |
| 36 | const SConnection::AccessRights SConnection::AccessView = 0x0001; |
| 37 | const SConnection::AccessRights SConnection::AccessKeyEvents = 0x0002; |
| 38 | const SConnection::AccessRights SConnection::AccessPtrEvents = 0x0004; |
| 39 | const SConnection::AccessRights SConnection::AccessCutText = 0x0008; |
| 40 | const SConnection::AccessRights SConnection::AccessDefault = 0x03ff; |
| 41 | const SConnection::AccessRights SConnection::AccessNoQuery = 0x0400; |
| 42 | const SConnection::AccessRights SConnection::AccessFull = 0xffff; |
| 43 | |
| 44 | |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame^] | 45 | SConnection::SConnection(bool reverseConnection_) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 46 | : readyForSetColourMapEntries(false), |
| 47 | is(0), os(0), reader_(0), writer_(0), |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame^] | 48 | security(0), ssecurity(0), state_(RFBSTATE_UNINITIALISED), |
Pierre Ossman | 02e43d7 | 2009-03-05 11:57:11 +0000 | [diff] [blame] | 49 | reverseConnection(reverseConnection_) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 50 | { |
| 51 | defaultMajorVersion = 3; |
| 52 | defaultMinorVersion = 8; |
| 53 | if (rfb::Server::protocol3_3) |
| 54 | defaultMinorVersion = 3; |
| 55 | |
| 56 | cp.setVersion(defaultMajorVersion, defaultMinorVersion); |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame^] | 57 | |
| 58 | security = new Security(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | SConnection::~SConnection() |
| 62 | { |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame^] | 63 | if (ssecurity) ssecurity->destroy(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 64 | deleteReaderAndWriter(); |
| 65 | } |
| 66 | |
| 67 | void SConnection::deleteReaderAndWriter() |
| 68 | { |
| 69 | delete reader_; |
| 70 | reader_ = 0; |
| 71 | delete writer_; |
| 72 | writer_ = 0; |
| 73 | } |
| 74 | |
| 75 | void SConnection::setStreams(rdr::InStream* is_, rdr::OutStream* os_) |
| 76 | { |
| 77 | is = is_; |
| 78 | os = os_; |
| 79 | } |
| 80 | |
| 81 | void SConnection::initialiseProtocol() |
| 82 | { |
| 83 | cp.writeVersion(os); |
| 84 | state_ = RFBSTATE_PROTOCOL_VERSION; |
| 85 | } |
| 86 | |
| 87 | void SConnection::processMsg() |
| 88 | { |
| 89 | switch (state_) { |
| 90 | case RFBSTATE_PROTOCOL_VERSION: processVersionMsg(); break; |
| 91 | case RFBSTATE_SECURITY_TYPE: processSecurityTypeMsg(); break; |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 92 | case RFBSTATE_TIGHT_TUNN_TYPE: processTunnelTypeMsg(); break; |
| 93 | case RFBSTATE_TIGHT_AUTH_TYPE: processAuthTypeMsg(); break; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 94 | case RFBSTATE_SECURITY: processSecurityMsg(); break; |
| 95 | case RFBSTATE_INITIALISATION: processInitMsg(); break; |
| 96 | case RFBSTATE_NORMAL: reader_->readMsg(); break; |
| 97 | case RFBSTATE_QUERYING: |
| 98 | throw Exception("SConnection::processMsg: bogus data from client while " |
| 99 | "querying"); |
| 100 | case RFBSTATE_UNINITIALISED: |
| 101 | throw Exception("SConnection::processMsg: not initialised yet?"); |
| 102 | default: |
| 103 | throw Exception("SConnection::processMsg: invalid state"); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | void SConnection::processVersionMsg() |
| 108 | { |
| 109 | vlog.debug("reading protocol version"); |
| 110 | bool done; |
| 111 | if (!cp.readVersion(is, &done)) { |
| 112 | state_ = RFBSTATE_INVALID; |
| 113 | throw Exception("reading version failed: not an RFB client?"); |
| 114 | } |
| 115 | if (!done) return; |
| 116 | |
| 117 | vlog.info("Client needs protocol version %d.%d", |
| 118 | cp.majorVersion, cp.minorVersion); |
| 119 | |
| 120 | if (cp.majorVersion != 3) { |
| 121 | // unknown protocol version |
| 122 | char msg[256]; |
| 123 | sprintf(msg,"Error: client needs protocol version %d.%d, server has %d.%d", |
| 124 | cp.majorVersion, cp.minorVersion, |
| 125 | defaultMajorVersion, defaultMinorVersion); |
| 126 | throwConnFailedException(msg); |
| 127 | } |
| 128 | |
| 129 | if (cp.minorVersion != 3 && cp.minorVersion != 7 && cp.minorVersion != 8) { |
| 130 | vlog.error("Client uses unofficial protocol version %d.%d", |
| 131 | cp.majorVersion,cp.minorVersion); |
| 132 | if (cp.minorVersion >= 8) |
| 133 | cp.minorVersion = 8; |
| 134 | else if (cp.minorVersion == 7) |
| 135 | cp.minorVersion = 7; |
| 136 | else |
| 137 | cp.minorVersion = 3; |
| 138 | vlog.error("Assuming compatibility with version %d.%d", |
| 139 | cp.majorVersion,cp.minorVersion); |
| 140 | } |
| 141 | |
| 142 | versionReceived(); |
| 143 | |
| 144 | std::list<rdr::U8> secTypes; |
| 145 | std::list<rdr::U8>::iterator i; |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame^] | 146 | secTypes = security->GetEnabledSecTypes(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 147 | |
| 148 | if (cp.isVersion(3,3)) { |
| 149 | |
| 150 | // cope with legacy 3.3 client only if "no authentication" or "vnc |
| 151 | // authentication" is supported. |
| 152 | for (i=secTypes.begin(); i!=secTypes.end(); i++) { |
| 153 | if (*i == secTypeNone || *i == secTypeVncAuth) break; |
| 154 | } |
| 155 | if (i == secTypes.end()) { |
| 156 | char msg[256]; |
| 157 | sprintf(msg,"No supported security type for %d.%d client", |
| 158 | cp.majorVersion, cp.minorVersion); |
| 159 | throwConnFailedException(msg); |
| 160 | } |
| 161 | |
| 162 | os->writeU32(*i); |
| 163 | if (*i == secTypeNone) os->flush(); |
| 164 | state_ = RFBSTATE_SECURITY; |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame^] | 165 | ssecurity = security->GetSSecurity(*i); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 166 | processSecurityMsg(); |
| 167 | return; |
| 168 | } |
| 169 | |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 170 | // Add a special security type to advertise TightVNC protocol extensions. |
| 171 | secTypes.push_back(secTypeTight); |
| 172 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 173 | // list supported security types for >=3.7 clients |
| 174 | |
| 175 | if (secTypes.empty()) |
| 176 | throwConnFailedException("No supported security types"); |
| 177 | |
| 178 | os->writeU8(secTypes.size()); |
| 179 | for (i=secTypes.begin(); i!=secTypes.end(); i++) |
| 180 | os->writeU8(*i); |
| 181 | os->flush(); |
| 182 | state_ = RFBSTATE_SECURITY_TYPE; |
| 183 | } |
| 184 | |
| 185 | |
| 186 | void SConnection::processSecurityTypeMsg() |
| 187 | { |
| 188 | vlog.debug("processing security type message"); |
| 189 | int secType = is->readU8(); |
| 190 | |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 191 | if (secType == secTypeTight) { |
| 192 | vlog.info("Enabling TightVNC protocol extensions"); |
| 193 | cp.tightExtensionsEnabled = true; |
| 194 | offerTunneling(); |
| 195 | } else { |
| 196 | processSecurityType(secType); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | // |
| 201 | // TightVNC-specific protocol initialization (tunneling, authentication) |
| 202 | // |
| 203 | |
| 204 | void SConnection::offerTunneling() |
| 205 | { |
| 206 | vlog.debug("offering list of tunneling methods"); |
| 207 | int nTypes = 0; |
| 208 | |
| 209 | // Advertise our tunneling capabilities (currently, nothing to advertise). |
| 210 | os->writeU32(nTypes); |
Constantin Kaplinsky | 4140d91 | 2006-09-12 14:10:14 +0000 | [diff] [blame] | 211 | os->flush(); |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 212 | |
| 213 | if (nTypes) { |
Constantin Kaplinsky | 4ad04c1 | 2006-09-12 06:37:33 +0000 | [diff] [blame] | 214 | // NOTE: Never executed in current version. |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 215 | state_ = RFBSTATE_TIGHT_TUNN_TYPE; |
| 216 | } else { |
| 217 | offerAuthentication(); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | // NOTE: This function is never called in current version. |
| 222 | void SConnection::processTunnelTypeMsg() |
| 223 | { |
| 224 | vlog.debug("processing tunneling type message (TightVNC extension)"); |
| 225 | int tunnelType = is->readU32(); |
| 226 | vlog.error("unsupported tunneling type %d requested, ignoring", tunnelType); |
| 227 | offerAuthentication(); |
| 228 | } |
| 229 | |
| 230 | void SConnection::offerAuthentication() |
| 231 | { |
| 232 | vlog.debug("offering list of authentication methods"); |
| 233 | |
Constantin Kaplinsky | ee6ec19 | 2006-09-12 09:55:51 +0000 | [diff] [blame] | 234 | // See processVersionMsg(), the code below is similar. |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 235 | |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 236 | std::list<rdr::U8> secTypes; |
| 237 | std::list<rdr::U8>::iterator i; |
Constantin Kaplinsky | ee6ec19 | 2006-09-12 09:55:51 +0000 | [diff] [blame] | 238 | |
| 239 | // NOTE: In addition to standard security types, we might want to offer |
| 240 | // TightVNC-specific authentication types. But currently we support |
| 241 | // only the standard security types: secTypeNone and secTypeVncAuth. |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame^] | 242 | secTypes = security->GetEnabledSecTypes(); |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 243 | |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 244 | CapsList caps; |
| 245 | for (i = secTypes.begin(); i != secTypes.end(); i++) { |
Constantin Kaplinsky | ee6ec19 | 2006-09-12 09:55:51 +0000 | [diff] [blame] | 246 | // FIXME: Capability info should be provided by SSecurity objects. |
| 247 | switch (*i) { |
| 248 | case secTypeNone: caps.addStandard(*i, "NOAUTH__"); break; |
| 249 | case secTypeVncAuth: caps.addStandard(*i, "VNCAUTH_"); break; |
Constantin Kaplinsky | 4140d91 | 2006-09-12 14:10:14 +0000 | [diff] [blame] | 250 | default: |
| 251 | // This should not ever happen. |
| 252 | vlog.error("not offering unknown security type %d", (int)*i); |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 253 | } |
| 254 | } |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 255 | |
Constantin Kaplinsky | 4140d91 | 2006-09-12 14:10:14 +0000 | [diff] [blame] | 256 | if (caps.getSize() < 1) |
| 257 | throwConnFailedException("No supported security types"); |
| 258 | |
Constantin Kaplinsky | c22746d | 2006-12-08 04:19:48 +0000 | [diff] [blame] | 259 | if (caps.includesOnly(secTypeNone)) { |
| 260 | // Special case - if caps includes nothing else than secTypeNone, we send |
| 261 | // an empty capability list and do not expect security type selection from |
| 262 | // the client. Then, continue the protocol like if the client has selected |
| 263 | // secTypeNone (starting at base protocol version 3.8, "security result" |
| 264 | // will follow). |
| 265 | os->writeU32(0); |
| 266 | os->flush(); |
| 267 | processSecurityType(secTypeNone); |
| 268 | } else { |
| 269 | // Normal case - sending the list of authentication capabilities. |
| 270 | os->writeU32(caps.getSize()); |
| 271 | caps.write(os); |
| 272 | os->flush(); |
| 273 | state_ = RFBSTATE_TIGHT_AUTH_TYPE; |
| 274 | } |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | void SConnection::processAuthTypeMsg() |
| 278 | { |
| 279 | vlog.debug("processing authentication type message (TightVNC extension)"); |
| 280 | |
Constantin Kaplinsky | 4140d91 | 2006-09-12 14:10:14 +0000 | [diff] [blame] | 281 | // NOTE: Currently, we support only the standard security types, so we |
| 282 | // just pass TightVNC authentication type for standard processing, |
| 283 | // just as it was usual RFB security type. |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 284 | int secType = is->readU32(); |
Constantin Kaplinsky | 5fa9d22 | 2006-09-06 10:32:06 +0000 | [diff] [blame] | 285 | processSecurityType(secType); |
| 286 | } |
| 287 | |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 288 | // |
| 289 | // End of TightVNC-specific code |
| 290 | // |
| 291 | |
Constantin Kaplinsky | 5fa9d22 | 2006-09-06 10:32:06 +0000 | [diff] [blame] | 292 | void SConnection::processSecurityType(int secType) |
| 293 | { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 294 | // Verify that the requested security type should be offered |
| 295 | std::list<rdr::U8> secTypes; |
| 296 | std::list<rdr::U8>::iterator i; |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame^] | 297 | |
| 298 | secTypes = security->GetEnabledSecTypes(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 299 | for (i=secTypes.begin(); i!=secTypes.end(); i++) |
| 300 | if (*i == secType) break; |
| 301 | if (i == secTypes.end()) |
| 302 | throw Exception("Requested security type not available"); |
| 303 | |
| 304 | vlog.info("Client requests security type %s(%d)", |
| 305 | secTypeName(secType),secType); |
| 306 | |
| 307 | try { |
| 308 | state_ = RFBSTATE_SECURITY; |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame^] | 309 | ssecurity = security->GetSSecurity(secType); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 310 | } catch (rdr::Exception& e) { |
| 311 | throwConnFailedException(e.str()); |
| 312 | } |
| 313 | |
| 314 | processSecurityMsg(); |
| 315 | } |
| 316 | |
| 317 | void SConnection::processSecurityMsg() |
| 318 | { |
| 319 | vlog.debug("processing security message"); |
| 320 | try { |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame^] | 321 | bool done = ssecurity->processMsg(this); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 322 | if (done) { |
| 323 | state_ = RFBSTATE_QUERYING; |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame^] | 324 | queryConnection(ssecurity->getUserName()); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 325 | } |
| 326 | } catch (AuthFailureException& e) { |
| 327 | vlog.error("AuthFailureException: %s", e.str()); |
| 328 | os->writeU32(secResultFailed); |
| 329 | if (!cp.beforeVersion(3,8)) // 3.8 onwards have failure message |
| 330 | os->writeString(e.str()); |
| 331 | os->flush(); |
| 332 | throw; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | void SConnection::processInitMsg() |
| 337 | { |
| 338 | vlog.debug("reading client initialisation"); |
| 339 | reader_->readClientInit(); |
| 340 | } |
| 341 | |
| 342 | void SConnection::throwConnFailedException(const char* msg) |
| 343 | { |
| 344 | vlog.info(msg); |
| 345 | if (state_ == RFBSTATE_PROTOCOL_VERSION) { |
| 346 | if (cp.majorVersion == 3 && cp.minorVersion == 3) { |
| 347 | os->writeU32(0); |
| 348 | os->writeString(msg); |
| 349 | os->flush(); |
| 350 | } else { |
| 351 | os->writeU8(0); |
| 352 | os->writeString(msg); |
| 353 | os->flush(); |
| 354 | } |
| 355 | } |
| 356 | state_ = RFBSTATE_INVALID; |
| 357 | throw ConnFailedException(msg); |
| 358 | } |
| 359 | |
| 360 | void SConnection::writeConnFailedFromScratch(const char* msg, |
| 361 | rdr::OutStream* os) |
| 362 | { |
| 363 | os->writeBytes("RFB 003.003\n", 12); |
| 364 | os->writeU32(0); |
| 365 | os->writeString(msg); |
| 366 | os->flush(); |
| 367 | } |
| 368 | |
| 369 | void SConnection::versionReceived() |
| 370 | { |
| 371 | } |
| 372 | |
| 373 | void SConnection::authSuccess() |
| 374 | { |
| 375 | } |
| 376 | |
| 377 | void SConnection::queryConnection(const char* userName) |
| 378 | { |
| 379 | approveConnection(true); |
| 380 | } |
| 381 | |
| 382 | void SConnection::approveConnection(bool accept, const char* reason) |
| 383 | { |
| 384 | if (state_ != RFBSTATE_QUERYING) |
| 385 | throw Exception("SConnection::approveConnection: invalid state"); |
| 386 | |
| 387 | if (!reason) reason = "Authentication failure"; |
| 388 | |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame^] | 389 | if (!cp.beforeVersion(3,8) || ssecurity->getType() != secTypeNone) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 390 | if (accept) { |
| 391 | os->writeU32(secResultOK); |
| 392 | } else { |
| 393 | os->writeU32(secResultFailed); |
| 394 | if (!cp.beforeVersion(3,8)) // 3.8 onwards have failure message |
| 395 | os->writeString(reason); |
| 396 | } |
| 397 | os->flush(); |
| 398 | } |
| 399 | |
| 400 | if (accept) { |
| 401 | state_ = RFBSTATE_INITIALISATION; |
| 402 | reader_ = new SMsgReaderV3(this, is); |
| 403 | writer_ = new SMsgWriterV3(&cp, os); |
| 404 | authSuccess(); |
| 405 | } else { |
| 406 | state_ = RFBSTATE_INVALID; |
| 407 | throw AuthFailureException(reason); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | void SConnection::setInitialColourMap() |
| 412 | { |
| 413 | } |
| 414 | |
| 415 | void SConnection::clientInit(bool shared) |
| 416 | { |
| 417 | writer_->writeServerInit(); |
Constantin Kaplinsky | ee6ec19 | 2006-09-12 09:55:51 +0000 | [diff] [blame] | 418 | |
| 419 | // FIXME: Send interaction capabilities via writer_? |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 420 | if (cp.tightExtensionsEnabled) |
| 421 | sendInteractionCaps(); |
| 422 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 423 | state_ = RFBSTATE_NORMAL; |
| 424 | } |
| 425 | |
Constantin Kaplinsky | ee6ec19 | 2006-09-12 09:55:51 +0000 | [diff] [blame] | 426 | // FIXME: Move sendInteractionCaps() to a class derived from SMsgWriterV3? |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 427 | void SConnection::sendInteractionCaps() |
| 428 | { |
Constantin Kaplinsky | dafbb01 | 2007-04-05 08:43:25 +0000 | [diff] [blame] | 429 | // |
Constantin Kaplinsky | adc4537 | 2006-09-13 15:44:15 +0000 | [diff] [blame] | 430 | // Advertise support for non-standard server-to-client messages |
Constantin Kaplinsky | dafbb01 | 2007-04-05 08:43:25 +0000 | [diff] [blame] | 431 | // |
| 432 | |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 433 | CapsList scaps; |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 434 | |
Constantin Kaplinsky | dafbb01 | 2007-04-05 08:43:25 +0000 | [diff] [blame] | 435 | // |
Constantin Kaplinsky | adc4537 | 2006-09-13 15:44:15 +0000 | [diff] [blame] | 436 | // Advertise support for non-standard client-to-server messages |
Constantin Kaplinsky | dafbb01 | 2007-04-05 08:43:25 +0000 | [diff] [blame] | 437 | // |
| 438 | |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 439 | CapsList ccaps; |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 440 | |
Constantin Kaplinsky | 8232831 | 2008-04-24 08:44:24 +0000 | [diff] [blame] | 441 | // |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 442 | // Advertise all supported encoding types (except raw encoding). |
Constantin Kaplinsky | 8232831 | 2008-04-24 08:44:24 +0000 | [diff] [blame] | 443 | // |
| 444 | |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 445 | CapsList ecaps; |
Constantin Kaplinsky | 4ad04c1 | 2006-09-12 06:37:33 +0000 | [diff] [blame] | 446 | |
| 447 | // First, add true encodings. |
Peter Åstrand | 98fe98c | 2010-02-10 07:43:02 +0000 | [diff] [blame] | 448 | for (int i = 1; i <= encodingMax; i++) { |
Constantin Kaplinsky | 4ad04c1 | 2006-09-12 06:37:33 +0000 | [diff] [blame] | 449 | if (Encoder::supported(i)) { |
Constantin Kaplinsky | ee6ec19 | 2006-09-12 09:55:51 +0000 | [diff] [blame] | 450 | // FIXME: Capability info should be provided by Encoder objects. |
| 451 | switch (i) { |
| 452 | case encodingRRE: ecaps.addStandard(i, "RRE_____"); break; |
| 453 | case encodingCoRRE: ecaps.addStandard(i, "CORRE___"); break; |
| 454 | case encodingHextile: ecaps.addStandard(i, "HEXTILE_"); break; |
| 455 | case encodingZRLE: ecaps.addStandard(i, "ZRLE____"); break; |
| 456 | case encodingTight: ecaps.addTightExt(i, "TIGHT___"); break; |
Constantin Kaplinsky | 4140d91 | 2006-09-12 14:10:14 +0000 | [diff] [blame] | 457 | default: |
| 458 | // This should not ever happen. |
| 459 | vlog.error("not advertising unknown encoding type %d", (int)i); |
Constantin Kaplinsky | 4ad04c1 | 2006-09-12 06:37:33 +0000 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | // CopyRect is special - Encoder::supported() returns 0 for it, |
| 465 | // that's why we add it here explicitly. |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 466 | ecaps.addStandard(encodingCopyRect, "COPYRECT"); |
Constantin Kaplinsky | 4ad04c1 | 2006-09-12 06:37:33 +0000 | [diff] [blame] | 467 | |
| 468 | // Add supported pseudo encodings as well. |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 469 | ecaps.addTightExt(pseudoEncodingCompressLevel0, "COMPRLVL"); |
| 470 | ecaps.addTightExt(pseudoEncodingQualityLevel0, "JPEGQLVL"); |
| 471 | ecaps.addTightExt(pseudoEncodingXCursor, "X11CURSR"); |
| 472 | ecaps.addTightExt(pseudoEncodingCursor, "RCHCURSR"); |
| 473 | ecaps.addTightExt(pseudoEncodingLastRect, "LASTRECT"); |
| 474 | ecaps.addStandard(pseudoEncodingDesktopSize, "NEWFBSIZ"); |
| 475 | |
| 476 | os->writeU16(scaps.getSize()); |
| 477 | os->writeU16(ccaps.getSize()); |
| 478 | os->writeU16(ecaps.getSize()); |
| 479 | os->writeU16(0); |
| 480 | if (scaps.getSize()) |
| 481 | scaps.write(os); |
| 482 | if (ccaps.getSize()) |
| 483 | ccaps.write(os); |
| 484 | if (ecaps.getSize()) |
| 485 | ecaps.write(os); |
| 486 | os->flush(); |
| 487 | } |
| 488 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 489 | void SConnection::setPixelFormat(const PixelFormat& pf) |
| 490 | { |
| 491 | SMsgHandler::setPixelFormat(pf); |
| 492 | readyForSetColourMapEntries = true; |
| 493 | } |
| 494 | |
| 495 | void SConnection::framebufferUpdateRequest(const Rect& r, bool incremental) |
| 496 | { |
| 497 | if (!readyForSetColourMapEntries) { |
| 498 | readyForSetColourMapEntries = true; |
| 499 | if (!cp.pf().trueColour) { |
| 500 | setInitialColourMap(); |
| 501 | } |
| 502 | } |
| 503 | } |