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