You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JavaViewer.cxx 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <winvnc/JavaViewer.h>
  19. #include <winvnc/VNCServerWin32.h>
  20. #include <winvnc/resource.h>
  21. #include <rdr/MemInStream.h>
  22. #include <rfb/LogWriter.h>
  23. #include <rfb/VNCServerST.h>
  24. #include <rfb_win32/TCharArray.h>
  25. #include <windows.h>
  26. using namespace winvnc;
  27. using namespace rfb;
  28. static rfb::LogWriter vlog("JavaViewerServer");
  29. JavaViewerServer::JavaViewerServer(VNCServerWin32* svr) : server(svr) {
  30. }
  31. JavaViewerServer::~JavaViewerServer() {
  32. }
  33. rdr::InStream* JavaViewerServer::getFile(const char* name,
  34. const char** contentType,
  35. int* contentLength,
  36. time_t* lastModified)
  37. {
  38. if (strcmp(name, "/") == 0)
  39. name = "/index.vnc";
  40. if (strcmp(name, "/VncViewer.jar") == 0)
  41. name = "VncViewer.jar";
  42. if (strcmp(name, "/index.vnc") == 0)
  43. name = "index.vnc";
  44. HRSRC resource = FindResource(0, TStr(name), _T("HTTPFILE"));
  45. if (!resource) return 0;
  46. HGLOBAL handle = LoadResource(0, resource);
  47. if (!handle) return 0;
  48. void* buf = LockResource(handle);
  49. int len = SizeofResource(0, resource);
  50. rdr::InStream* is = new rdr::MemInStream(buf, len);
  51. if (strlen(name) > 4 && strcasecmp(&name[strlen(name)-4], ".vnc") == 0) {
  52. is = new rdr::SubstitutingInStream(is, this, 20);
  53. *contentType = "text/html";
  54. }
  55. return is;
  56. }
  57. char* JavaViewerServer::substitute(const char* varName)
  58. {
  59. if (strcmp(varName, "$$") == 0) {
  60. return rfb::strDup("$");
  61. }
  62. if (strcmp(varName, "$PORT") == 0) {
  63. char* str = new char[10];
  64. sprintf(str, "%d", rfbPort);
  65. return str;
  66. }
  67. if (strcmp(varName, "$WIDTH") == 0) {
  68. char* str = new char[10];
  69. sprintf(str, "%d", server->getDesktopSize().x);
  70. return str;
  71. }
  72. if (strcmp(varName, "$HEIGHT") == 0) {
  73. char* str = new char[10];
  74. sprintf(str, "%d", server->getDesktopSize().y);
  75. return str;
  76. }
  77. if (strcmp(varName, "$APPLETWIDTH") == 0) {
  78. char* str = new char[10];
  79. sprintf(str, "%d", server->getDesktopSize().x);
  80. return str;
  81. }
  82. if (strcmp(varName, "$APPLETHEIGHT") == 0) {
  83. char* str = new char[10];
  84. sprintf(str, "%d", server->getDesktopSize().y);
  85. return str;
  86. }
  87. if (strcmp(varName, "$DESKTOP") == 0) {
  88. return rfb::strDup(server->getName());
  89. }
  90. if (strcmp(varName, "$USER") == 0) {
  91. char tempStr[256]; DWORD tempStrLen = 256;
  92. GetUserName(tempStr, &tempStrLen);
  93. return rfb::strDup(tempStr);
  94. }
  95. return 0;
  96. }