Changeset 43219 in vbox for trunk/src/VBox/ExtPacks
- Timestamp:
- Sep 6, 2012 10:06:51 AM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 80609
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ExtPacks/VNC/VBoxVNC.cpp
r43214 r43219 19 19 */ 20 20 21 /******************************************************************************* 22 * Header Files * 23 *******************************************************************************/ 21 24 #define LOG_GROUP LOG_GROUP_VRDE 22 25 #include <VBox/log.h> … … 40 43 #include <rfb/rfb.h> 41 44 42 #define VNC_SIZEOFRGBA 4 43 #define VNC_PASSWORDSIZE 20 44 #define VNC_ADDRESSSIZE 60 45 #define VNC_PORTSSIZE 20 46 #define VNC_ADDRESS_OPTION_MAX 500 47 45 46 /******************************************************************************* 47 * Defined Constants And Macros * 48 *******************************************************************************/ 49 #define VNC_SIZEOFRGBA 4 50 #define VNC_PASSWORDSIZE 20 51 #define VNC_ADDRESSSIZE 60 52 #define VNC_PORTSSIZE 20 53 #define VNC_ADDRESS_OPTION_MAX 500 54 55 56 /******************************************************************************* 57 * Structures and Typedefs * 58 *******************************************************************************/ 48 59 class VNCServerImpl 49 60 { … … 98 109 } 99 110 111 int queryVrdeFeature(const char *pszName, char *pszValue, size_t cbValue); 112 100 113 static VRDEENTRYPOINTS_4 Entries; 101 114 VRDECALLBACKS_4 *mCallbacks; 102 115 103 104 116 static DECLCALLBACK(void) VRDEDestroy(HVRDESERVER hServer); 105 static DECLCALLBACK(int) VRDEEnableConnections(HVRDESERVER hServer, bool fEnable);117 static DECLCALLBACK(int) VRDEEnableConnections(HVRDESERVER hServer, bool fEnable); 106 118 static DECLCALLBACK(void) VRDEDisconnect(HVRDESERVER hServer, uint32_t u32ClientId, bool fReconnect); 107 119 static DECLCALLBACK(void) VRDEResize(HVRDESERVER hServer); … … 182 194 183 195 196 /** 197 * Query a feature and store it's value in a user supplied buffer. 198 * 199 * @returns VBox status code. 200 * @param pszName The feature name. 201 * @param pszValue The value buffer. The buffer is not touched at 202 * all on failure. 203 * @param cbValue The size of the output buffer. 204 */ 205 int VNCServerImpl::queryVrdeFeature(const char *pszName, char *pszValue, size_t cbValue) 206 { 207 union 208 { 209 VRDEFEATURE Feat; 210 uint8_t abBuf[VNC_ADDRESS_OPTION_MAX + sizeof(VRDEFEATURE)]; 211 } u; 212 213 u.Feat.u32ClientId = 0; 214 int rc = RTStrCopy(u.Feat.achInfo, VNC_ADDRESS_OPTION_MAX, pszName); AssertRC(rc); 215 if (RT_SUCCESS(rc)) 216 { 217 uint32_t cbOut = 0; 218 rc = mCallbacks->VRDECallbackProperty(mCallback, 219 VRDE_QP_FEATURE, 220 &u.Feat, 221 VNC_ADDRESS_OPTION_MAX, 222 &cbOut); 223 if (RT_SUCCESS(rc)) 224 { 225 size_t cbRet = strlen(u.Feat.achInfo) + 1; 226 if (cbRet <= cbValue) 227 memcpy(pszValue, u.Feat.achInfo, cbRet); 228 else 229 rc = VERR_BUFFER_OVERFLOW; 230 } 231 } 232 233 return rc; 234 } 235 236 184 237 /** The server should start to accept clients connections. 185 238 * … … 333 386 char szIPv4ListenAll[] = "0.0.0.0"; 334 387 335 uint32_t u lServerPort4 = 0;336 uint32_t u lServerPort6 = 0;388 uint32_t uServerPort4 = 0; 389 uint32_t uServerPort6 = 0; 337 390 uint32_t cbOut = 0; 338 391 size_t resSize = 0; 339 392 RTNETADDRTYPE enmAddrType; 340 char *pszTCPAddress = NULL;341 char *pszTCPPort = NULL;342 char *pszVNCAddress4 = NULL;343 char *pszVNCPort4 = NULL;344 393 char *pszVNCAddress6 = NULL; 345 394 char *pszVNCPort6 = NULL; … … 350 399 351 400 // get address 352 rc = -1; 353 pszTCPAddress = (char *) RTMemTmpAlloc(VNC_ADDRESS_OPTION_MAX); 354 memset(pszTCPAddress, '\0', VNC_ADDRESS_OPTION_MAX); 355 401 char *pszTCPAddress = (char *)RTMemTmpAllocZ(VNC_ADDRESS_OPTION_MAX); 356 402 rc = instance->mCallbacks->VRDECallbackProperty(instance->mCallback, 357 403 VRDE_QP_NETWORK_ADDRESS, … … 361 407 362 408 // get port (range) 363 rc = -1; 364 pszTCPPort = (char *) RTMemTmpAlloc(VNC_ADDRESS_OPTION_MAX); 365 memset(pszTCPPort,'\0',VNC_ADDRESS_OPTION_MAX); 366 409 char *pszTCPPort = (char *)RTMemTmpAllocZ(VNC_ADDRESS_OPTION_MAX); 367 410 rc = instance->mCallbacks->VRDECallbackProperty(instance->mCallback, 368 411 VRDE_QP_NETWORK_PORT_RANGE, … … 370 413 VNC_ADDRESS_OPTION_MAX, 371 414 &cbOut); 372 373 415 Assert(cbOut < VNC_ADDRESS_OPTION_MAX); 374 416 375 // get tcp ports option from vrde 376 377 rc = -1; 378 379 pszTCPPort = (char *) RTMemTmpAlloc(6); 380 memset(pszTCPPort,'\0',6); 381 382 VRDEFEATURE *pVRDEFeature = (VRDEFEATURE *) RTMemTmpAlloc(VNC_ADDRESS_OPTION_MAX); 383 pVRDEFeature->u32ClientId = 0; 384 385 /** @todo r=bird: I believe this code is more than a little of confused 386 * about how to use RTStrCopy... The 2nd parameter is the size of the 387 * destination buffer, not the size of the source string!! */ 388 RTStrCopy(pVRDEFeature->achInfo, 19, "Property/TCP/Ports"); 389 390 cbOut = 1; 391 392 rc = instance->mCallbacks->VRDECallbackProperty(instance->mCallback, 393 VRDE_QP_FEATURE, 394 pVRDEFeature, 395 VNC_ADDRESS_OPTION_MAX, 396 &cbOut); 397 398 Assert(cbOut < VNC_ADDRESS_OPTION_MAX); 399 400 if (RT_SUCCESS(rc)) 401 { 402 RTStrCopy(pszTCPPort, cbOut, pVRDEFeature->achInfo); 403 } 417 // get tcp ports option from vrde. 418 /** @todo r=bird: Is this intentionally overriding VRDE_QP_NETWORK_PORT_RANGE? */ 419 instance->queryVrdeFeature("Property/TCP/Ports", pszTCPPort, VNC_ADDRESS_OPTION_MAX); 404 420 405 421 // get VNCAddress4 406 rc = -1; 407 const uint32_t lVNCAddress4FeatureSize = sizeof(VRDEFEATURE) + 24; 408 409 pszVNCAddress4 = (char *) RTMemTmpAllocZ(24); 410 411 pVRDEFeature->u32ClientId = 0; 412 413 RTStrCopy(pVRDEFeature->achInfo, 21, "Property/VNCAddress4"); 414 415 cbOut = 1; 416 417 rc = instance->mCallbacks->VRDECallbackProperty(instance->mCallback, 418 VRDE_QP_FEATURE, 419 pVRDEFeature, 420 VNC_ADDRESS_OPTION_MAX, 421 &cbOut); 422 423 Assert(cbOut <= 24); 424 425 if (RT_SUCCESS(rc)) 426 { 427 RTStrCopy(pszVNCAddress4,cbOut,pVRDEFeature->achInfo); 428 } 422 char *pszVNCAddress4 = (char *)RTMemTmpAllocZ(24); 423 instance->queryVrdeFeature("Property/VNCAddress4", pszVNCAddress4, 24); 429 424 430 425 // VNCPort4 431 rc = -1; 432 pszVNCPort4 = (char *) RTMemTmpAlloc(6); 433 434 pVRDEFeature->u32ClientId = 0; 435 RTStrCopy(pVRDEFeature->achInfo, VNC_ADDRESS_OPTION_MAX, "Property/VNCPort4"); 436 437 cbOut = VNC_ADDRESS_OPTION_MAX; 438 rc = instance->mCallbacks->VRDECallbackProperty(instance->mCallback, 439 VRDE_QP_FEATURE, 440 pVRDEFeature, 441 VNC_ADDRESS_OPTION_MAX, 442 &cbOut); 443 444 445 Assert(cbOut <= VNC_ADDRESS_OPTION_MAX); 446 if (RT_SUCCESS(rc)) 447 { 448 if (cbOut < 6) 449 { 450 RTStrCopy(pszVNCPort4, cbOut, pVRDEFeature->achInfo); 451 } 452 453 } 426 char *pszVNCPort4 = (char *)RTMemTmpAlloc(6); 427 instance->queryVrdeFeature("Property/VNCPort4", pszVNCPort4, 6); 454 428 455 429 // VNCAddress6 456 rc = -1;457 458 430 pszVNCAddress6 = (char *) RTMemTmpAllocZ(VNC_ADDRESS_OPTION_MAX); 459 460 pVRDEFeature->u32ClientId = 0; 461 RTStrCopy(pVRDEFeature->achInfo, 21,"Property/VNCAddress6"); 462 463 cbOut = VNC_ADDRESS_OPTION_MAX; 464 465 rc = instance->mCallbacks->VRDECallbackProperty(instance->mCallback, 466 VRDE_QP_FEATURE, 467 pVRDEFeature, 468 VNC_ADDRESS_OPTION_MAX, 469 &cbOut); 470 471 Assert(cbOut <= VNC_ADDRESS_OPTION_MAX); 472 473 if (RT_SUCCESS(rc)) 474 { 475 RTStrCopy(pszVNCAddress6, cbOut, pVRDEFeature->achInfo); 476 } 431 instance->queryVrdeFeature("Property/VNCAddress6", pszVNCAddress6, VNC_ADDRESS_OPTION_MAX); 477 432 478 433 // VNCPort6 479 pszVNCPort6 = (char *) RTMemTmpAllocZ(6); 480 481 pVRDEFeature->u32ClientId = 0; 482 RTStrCopy(pVRDEFeature->achInfo, 18 , "Property/VNCPort6"); 483 484 cbOut = 5; 485 486 rc = instance->mCallbacks->VRDECallbackProperty(instance->mCallback, 487 VRDE_QP_FEATURE, 488 pVRDEFeature, 489 VNC_ADDRESS_OPTION_MAX, 490 &cbOut); 491 492 Assert(cbOut <= 6); 493 494 if (RT_SUCCESS(rc)) 495 { 496 RTStrCopy(pszVNCPort6, cbOut, pVRDEFeature->achInfo); 497 } 434 pszVNCPort6 = (char *)RTMemTmpAllocZ(6); 435 instance->queryVrdeFeature("Property/VNCPort6", pszVNCPort6, 6); 436 498 437 499 438 if (RTNetIsIPv4AddrStr(pszTCPAddress)) … … 503 442 if (strlen(pszTCPPort) > 0) 504 443 { 505 rc = RTStrToUInt32Ex(pszTCPPort, NULL, 10, &ulServerPort4); 506 507 if (!RT_SUCCESS(rc) || ulServerPort4 > 65535) 508 ulServerPort4 = 0; 444 rc = RTStrToUInt32Ex(pszTCPPort, NULL, 10, &uServerPort4); 445 if (!RT_SUCCESS(rc) || uServerPort4 > 65535) 446 uServerPort4 = 0; 509 447 } 510 448 … … 516 454 if (strlen(pszVNCPort6) > 0) 517 455 { 518 rc = RTStrToUInt32Ex(pszVNCPort6, NULL, 10, &ulServerPort6); 519 520 if (!RT_SUCCESS(rc) || ulServerPort6 > 65535) 521 ulServerPort6 = 0; 456 rc = RTStrToUInt32Ex(pszVNCPort6, NULL, 10, &uServerPort6); 457 if (!RT_SUCCESS(rc) || uServerPort6 > 65535) 458 uServerPort6 = 0; 522 459 523 460 } … … 531 468 if (strlen(pszTCPPort) > 0) 532 469 { 533 rc = RTStrToUInt32Ex(pszTCPPort, NULL, 10, &ulServerPort6); 534 535 if (!RT_SUCCESS(rc) || ulServerPort6 > 65535) 536 ulServerPort6 = 0; 470 rc = RTStrToUInt32Ex(pszTCPPort, NULL, 10, &uServerPort6); 471 if (!RT_SUCCESS(rc) || uServerPort6 > 65535) 472 uServerPort6 = 0; 537 473 } 538 474 … … 544 480 if (strlen(pszVNCPort4) > 0) 545 481 { 546 rc = RTStrToUInt32Ex(pszVNCPort4, NULL, 10, &ulServerPort4); 547 548 if (!RT_SUCCESS(rc) || ulServerPort4 > 65535) 549 ulServerPort4 = 0; 482 rc = RTStrToUInt32Ex(pszVNCPort4, NULL, 10, &uServerPort4); 483 if (!RT_SUCCESS(rc) || uServerPort4 > 65535) 484 uServerPort4 = 0; 550 485 551 486 } … … 560 495 561 496 rc = RTSocketQueryAddressStr(pszTCPAddress, pszGetAddrInfo6, &resSize, &enmAddrType); 562 563 497 if (RT_SUCCESS(rc)) 564 {565 498 pszServerAddress6 = pszGetAddrInfo6; 566 567 }568 499 else 569 500 { … … 581 512 582 513 if (RT_SUCCESS(rc)) 583 {584 514 pszServerAddress4 = pszGetAddrInfo4; 585 }586 515 else 587 516 { … … 632 561 } 633 562 634 if (pszVNCPort4 && ulServerPort4 == 0) 635 { 636 rc = RTStrToUInt32Ex(pszVNCPort4, NULL, 10, &ulServerPort4); 637 638 if (!RT_SUCCESS(rc) || ulServerPort4 > 65535) 639 ulServerPort4 = 0; 640 } 641 if (pszVNCPort6 && ulServerPort6 == 0) 642 { 643 rc = RTStrToUInt32Ex(pszVNCPort6, NULL, 10, &ulServerPort6); 644 645 if (!RT_SUCCESS(rc) || ulServerPort6 > 65535) 646 ulServerPort6 = 0; 647 } 648 if (ulServerPort4 == 0 || ulServerPort6 == 0) 649 { 563 if (pszVNCPort4 && uServerPort4 == 0) 564 { 565 rc = RTStrToUInt32Ex(pszVNCPort4, NULL, 10, &uServerPort4); 566 if (!RT_SUCCESS(rc) || uServerPort4 > 65535) 567 uServerPort4 = 0; 568 } 569 570 if (pszVNCPort6 && uServerPort6 == 0) 571 { 572 rc = RTStrToUInt32Ex(pszVNCPort6, NULL, 10, &uServerPort6); 573 if (!RT_SUCCESS(rc) || uServerPort6 > 65535) 574 uServerPort6 = 0; 575 } 576 577 if (uServerPort4 == 0 || uServerPort6 == 0) 650 578 vncServer->autoPort = 1; 651 }652 579 else 653 580 { 654 vncServer->port = u lServerPort4;655 vncServer->ipv6port = u lServerPort6;581 vncServer->port = uServerPort4; 582 vncServer->ipv6port = uServerPort6; 656 583 } 657 584 … … 683 610 LogRel(("VNC: port6 = %u\n", port)); 684 611 685 if (pVRDEFeature)686 RTMemTmpFree(pVRDEFeature);687 612 688 613 if (pszTCPAddress) … … 697 622 } 698 623 699 if (pszTCPPort) 700 RTMemTmpFree(pszTCPPort); 701 702 if (pszVNCAddress4) 703 RTMemTmpFree(pszVNCAddress4); 704 705 if (pszVNCPort4) 706 RTMemTmpFree(pszVNCPort4); 707 708 if (pszGetAddrInfo4) 709 RTMemTmpFree(pszGetAddrInfo4); 710 711 if (pszVNCAddress6) 712 RTMemTmpFree(pszVNCAddress6); 713 714 if (pszGetAddrInfo6) 715 RTMemTmpFree(pszGetAddrInfo6); 624 RTMemTmpFree(pszTCPPort); 625 RTMemTmpFree(pszVNCAddress4); 626 RTMemTmpFree(pszVNCPort4); 627 RTMemTmpFree(pszGetAddrInfo4); 628 RTMemTmpFree(pszVNCAddress6); 629 RTMemTmpFree(pszGetAddrInfo6); 716 630 717 631 // with ipv6 to here
Note:
See TracChangeset
for help on using the changeset viewer.