aboutsummaryrefslogtreecommitdiffstats
path: root/win/winvnc/JavaViewer.cxx
blob: 6f9f6de510fd1afb537ae6e6fa7c08d54f6ef559 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
 * 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */

#include <windows.h>
#include <winvnc/JavaViewer.h>
#include <winvnc/resource.h>
#include <rdr/MemInStream.h>
#include <rfb/LogWriter.h>
#include <rfb/VNCServerST.h>
#include <rfb_win32/TCharArray.h>

#define strcasecmp _stricmp

using namespace winvnc;
using namespace rfb;


static rfb::LogWriter vlog("JavaViewerServer");

JavaViewerServer::JavaViewerServer(rfb::VNCServerST* svr) : server(svr) {
}

JavaViewerServer::~JavaViewerServer() {
}

rdr::InStream* JavaViewerServer::getFile(const char* name,
                                         const char** contentType,
                                         int* contentLength,
                                         time_t* lastModified)
{
  if (strcmp(name, "/") == 0)
    name = "/index.vnc";
  if (strcmp(name, "/VncViewer.jar") == 0)
    name = "VncViewer.jar";
  if (strcmp(name, "/index.vnc") == 0)
    name = "index.vnc";

  HRSRC resource = FindResource(0, TStr(name), _T("HTTPFILE"));
  if (!resource) return 0;
  HGLOBAL handle = LoadResource(0, resource);
  if (!handle) return 0;
  void* buf = LockResource(handle);
  int len = SizeofResource(0, resource);

  rdr::InStream* is = new rdr::MemInStream(buf, len);
  if (strlen(name) > 4 && strcasecmp(&name[strlen(name)-4], ".vnc") == 0) {
    is = new rdr::SubstitutingInStream(is, this, 20);
    *contentType = "text/html";
  }
  return is;
}

char* JavaViewerServer::substitute(const char* varName)
{
  if (strcmp(varName, "$$") == 0) {
    return rfb::strDup("$");
  }
  if (strcmp(varName, "$PORT") == 0) {
    char* str = new char[10];
    sprintf(str, "%d", rfbPort);
    return str;
  }
  if (strcmp(varName, "$WIDTH") == 0) {
    char* str = new char[10];
    sprintf(str, "%d", server->getDesktopSize().x);
    return str;
  }
  if (strcmp(varName, "$HEIGHT") == 0) {
    char* str = new char[10];
    sprintf(str, "%d", server->getDesktopSize().y);
    return str;
  }
  if (strcmp(varName, "$APPLETWIDTH") == 0) {
    char* str = new char[10];
    sprintf(str, "%d", server->getDesktopSize().x);
    return str;
  }
  if (strcmp(varName, "$APPLETHEIGHT") == 0) {
    char* str = new char[10];
    sprintf(str, "%d", server->getDesktopSize().y + 32);
    return str;
  }
  if (strcmp(varName, "$DESKTOP") == 0) {
    return rfb::strDup(server->getName());
  }
  if (strcmp(varName, "$USER") == 0) {
    char tempStr[256];  DWORD tempStrLen = 256;
    GetUserName(tempStr, &tempStrLen);
    return rfb::strDup(tempStr);
  }
  return 0;
}