Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +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 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 19 | #include <winvnc/JavaViewer.h> |
Pierre Ossman | b000ff1 | 2017-09-22 16:43:50 +0200 | [diff] [blame] | 20 | #include <winvnc/VNCServerWin32.h> |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 21 | #include <winvnc/resource.h> |
| 22 | #include <rdr/MemInStream.h> |
| 23 | #include <rfb/LogWriter.h> |
Adam Tkac | 934f63c | 2009-10-12 15:54:59 +0000 | [diff] [blame] | 24 | #include <rfb/VNCServerST.h> |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 25 | #include <rfb_win32/TCharArray.h> |
| 26 | |
Pierre Ossman | 7f4fc69 | 2012-04-26 09:18:19 +0000 | [diff] [blame] | 27 | #include <windows.h> |
| 28 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 29 | using namespace winvnc; |
| 30 | using namespace rfb; |
| 31 | |
| 32 | |
| 33 | static rfb::LogWriter vlog("JavaViewerServer"); |
| 34 | |
Pierre Ossman | b000ff1 | 2017-09-22 16:43:50 +0200 | [diff] [blame] | 35 | JavaViewerServer::JavaViewerServer(VNCServerWin32* svr) : server(svr) { |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | JavaViewerServer::~JavaViewerServer() { |
| 39 | } |
| 40 | |
| 41 | rdr::InStream* JavaViewerServer::getFile(const char* name, |
| 42 | const char** contentType, |
| 43 | int* contentLength, |
| 44 | time_t* lastModified) |
| 45 | { |
| 46 | if (strcmp(name, "/") == 0) |
| 47 | name = "/index.vnc"; |
DRC | 11278c5 | 2011-10-12 21:30:18 +0000 | [diff] [blame] | 48 | if (strcmp(name, "/VncViewer.jar") == 0) |
| 49 | name = "VncViewer.jar"; |
| 50 | if (strcmp(name, "/index.vnc") == 0) |
| 51 | name = "index.vnc"; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 52 | |
| 53 | HRSRC resource = FindResource(0, TStr(name), _T("HTTPFILE")); |
| 54 | if (!resource) return 0; |
| 55 | HGLOBAL handle = LoadResource(0, resource); |
| 56 | if (!handle) return 0; |
| 57 | void* buf = LockResource(handle); |
| 58 | int len = SizeofResource(0, resource); |
| 59 | |
| 60 | rdr::InStream* is = new rdr::MemInStream(buf, len); |
| 61 | if (strlen(name) > 4 && strcasecmp(&name[strlen(name)-4], ".vnc") == 0) { |
| 62 | is = new rdr::SubstitutingInStream(is, this, 20); |
| 63 | *contentType = "text/html"; |
| 64 | } |
| 65 | return is; |
| 66 | } |
| 67 | |
| 68 | char* JavaViewerServer::substitute(const char* varName) |
| 69 | { |
| 70 | if (strcmp(varName, "$$") == 0) { |
| 71 | return rfb::strDup("$"); |
| 72 | } |
| 73 | if (strcmp(varName, "$PORT") == 0) { |
| 74 | char* str = new char[10]; |
| 75 | sprintf(str, "%d", rfbPort); |
| 76 | return str; |
| 77 | } |
| 78 | if (strcmp(varName, "$WIDTH") == 0) { |
| 79 | char* str = new char[10]; |
| 80 | sprintf(str, "%d", server->getDesktopSize().x); |
| 81 | return str; |
| 82 | } |
| 83 | if (strcmp(varName, "$HEIGHT") == 0) { |
| 84 | char* str = new char[10]; |
| 85 | sprintf(str, "%d", server->getDesktopSize().y); |
| 86 | return str; |
| 87 | } |
| 88 | if (strcmp(varName, "$APPLETWIDTH") == 0) { |
| 89 | char* str = new char[10]; |
| 90 | sprintf(str, "%d", server->getDesktopSize().x); |
| 91 | return str; |
| 92 | } |
| 93 | if (strcmp(varName, "$APPLETHEIGHT") == 0) { |
| 94 | char* str = new char[10]; |
Brian Hinz | dc6af37 | 2014-01-12 13:46:17 +0000 | [diff] [blame] | 95 | sprintf(str, "%d", server->getDesktopSize().y); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 96 | return str; |
| 97 | } |
| 98 | if (strcmp(varName, "$DESKTOP") == 0) { |
| 99 | return rfb::strDup(server->getName()); |
| 100 | } |
DRC | f50ec7c | 2011-10-05 09:29:21 +0000 | [diff] [blame] | 101 | if (strcmp(varName, "$USER") == 0) { |
| 102 | char tempStr[256]; DWORD tempStrLen = 256; |
| 103 | GetUserName(tempStr, &tempStrLen); |
| 104 | return rfb::strDup(tempStr); |
| 105 | } |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 106 | return 0; |
| 107 | } |