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