blob: c9631229a7b58f9046aada81ce51c46f30213bc2 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* 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 Kaplinsky729598c2006-05-25 05:12:25 +000019#include <winvnc/JavaViewer.h>
20#include <winvnc/resource.h>
21#include <rdr/MemInStream.h>
22#include <rfb/LogWriter.h>
Adam Tkac934f63c2009-10-12 15:54:59 +000023#include <rfb/VNCServerST.h>
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000024#include <rfb_win32/TCharArray.h>
25
Pierre Ossman7f4fc692012-04-26 09:18:19 +000026#include <windows.h>
27
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000028using namespace winvnc;
29using namespace rfb;
30
31
32static rfb::LogWriter vlog("JavaViewerServer");
33
34JavaViewerServer::JavaViewerServer(rfb::VNCServerST* svr) : server(svr) {
35}
36
37JavaViewerServer::~JavaViewerServer() {
38}
39
40rdr::InStream* JavaViewerServer::getFile(const char* name,
41 const char** contentType,
42 int* contentLength,
43 time_t* lastModified)
44{
45 if (strcmp(name, "/") == 0)
46 name = "/index.vnc";
DRC11278c52011-10-12 21:30:18 +000047 if (strcmp(name, "/VncViewer.jar") == 0)
48 name = "VncViewer.jar";
49 if (strcmp(name, "/index.vnc") == 0)
50 name = "index.vnc";
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000051
52 HRSRC resource = FindResource(0, TStr(name), _T("HTTPFILE"));
53 if (!resource) return 0;
54 HGLOBAL handle = LoadResource(0, resource);
55 if (!handle) return 0;
56 void* buf = LockResource(handle);
57 int len = SizeofResource(0, resource);
58
59 rdr::InStream* is = new rdr::MemInStream(buf, len);
60 if (strlen(name) > 4 && strcasecmp(&name[strlen(name)-4], ".vnc") == 0) {
61 is = new rdr::SubstitutingInStream(is, this, 20);
62 *contentType = "text/html";
63 }
64 return is;
65}
66
67char* JavaViewerServer::substitute(const char* varName)
68{
69 if (strcmp(varName, "$$") == 0) {
70 return rfb::strDup("$");
71 }
72 if (strcmp(varName, "$PORT") == 0) {
73 char* str = new char[10];
74 sprintf(str, "%d", rfbPort);
75 return str;
76 }
77 if (strcmp(varName, "$WIDTH") == 0) {
78 char* str = new char[10];
79 sprintf(str, "%d", server->getDesktopSize().x);
80 return str;
81 }
82 if (strcmp(varName, "$HEIGHT") == 0) {
83 char* str = new char[10];
84 sprintf(str, "%d", server->getDesktopSize().y);
85 return str;
86 }
87 if (strcmp(varName, "$APPLETWIDTH") == 0) {
88 char* str = new char[10];
89 sprintf(str, "%d", server->getDesktopSize().x);
90 return str;
91 }
92 if (strcmp(varName, "$APPLETHEIGHT") == 0) {
93 char* str = new char[10];
Brian Hinzdc6af372014-01-12 13:46:17 +000094 sprintf(str, "%d", server->getDesktopSize().y);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000095 return str;
96 }
97 if (strcmp(varName, "$DESKTOP") == 0) {
98 return rfb::strDup(server->getName());
99 }
DRCf50ec7c2011-10-05 09:29:21 +0000100 if (strcmp(varName, "$USER") == 0) {
101 char tempStr[256]; DWORD tempStrLen = 256;
102 GetUserName(tempStr, &tempStrLen);
103 return rfb::strDup(tempStr);
104 }
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000105 return 0;
106}