blob: 3813f22cf6cc13cb154eefd1dd8fb372dbc716c1 [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 +000028#define strcasecmp _stricmp
29
30using namespace winvnc;
31using namespace rfb;
32
33
34static rfb::LogWriter vlog("JavaViewerServer");
35
36JavaViewerServer::JavaViewerServer(rfb::VNCServerST* svr) : server(svr) {
37}
38
39JavaViewerServer::~JavaViewerServer() {
40}
41
42rdr::InStream* JavaViewerServer::getFile(const char* name,
43 const char** contentType,
44 int* contentLength,
45 time_t* lastModified)
46{
47 if (strcmp(name, "/") == 0)
48 name = "/index.vnc";
DRC11278c52011-10-12 21:30:18 +000049 if (strcmp(name, "/VncViewer.jar") == 0)
50 name = "VncViewer.jar";
51 if (strcmp(name, "/index.vnc") == 0)
52 name = "index.vnc";
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000053
54 HRSRC resource = FindResource(0, TStr(name), _T("HTTPFILE"));
55 if (!resource) return 0;
56 HGLOBAL handle = LoadResource(0, resource);
57 if (!handle) return 0;
58 void* buf = LockResource(handle);
59 int len = SizeofResource(0, resource);
60
61 rdr::InStream* is = new rdr::MemInStream(buf, len);
62 if (strlen(name) > 4 && strcasecmp(&name[strlen(name)-4], ".vnc") == 0) {
63 is = new rdr::SubstitutingInStream(is, this, 20);
64 *contentType = "text/html";
65 }
66 return is;
67}
68
69char* JavaViewerServer::substitute(const char* varName)
70{
71 if (strcmp(varName, "$$") == 0) {
72 return rfb::strDup("$");
73 }
74 if (strcmp(varName, "$PORT") == 0) {
75 char* str = new char[10];
76 sprintf(str, "%d", rfbPort);
77 return str;
78 }
79 if (strcmp(varName, "$WIDTH") == 0) {
80 char* str = new char[10];
81 sprintf(str, "%d", server->getDesktopSize().x);
82 return str;
83 }
84 if (strcmp(varName, "$HEIGHT") == 0) {
85 char* str = new char[10];
86 sprintf(str, "%d", server->getDesktopSize().y);
87 return str;
88 }
89 if (strcmp(varName, "$APPLETWIDTH") == 0) {
90 char* str = new char[10];
91 sprintf(str, "%d", server->getDesktopSize().x);
92 return str;
93 }
94 if (strcmp(varName, "$APPLETHEIGHT") == 0) {
95 char* str = new char[10];
96 sprintf(str, "%d", server->getDesktopSize().y + 32);
97 return str;
98 }
99 if (strcmp(varName, "$DESKTOP") == 0) {
100 return rfb::strDup(server->getName());
101 }
DRCf50ec7c2011-10-05 09:29:21 +0000102 if (strcmp(varName, "$USER") == 0) {
103 char tempStr[256]; DWORD tempStrLen = 256;
104 GetUserName(tempStr, &tempStrLen);
105 return rfb::strDup(tempStr);
106 }
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000107 return 0;
108}