aboutsummaryrefslogtreecommitdiffstats
path: root/unix/xserver/hw/vnc/RFBGlue.cc
blob: 2fbc27ee06847354c5470f34a7e0dddee4070b88 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reser
/* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
 * Copyright 2011-2019 Pierre Ossman for Cendio AB
 * 
 * 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.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>

#include <network/TcpSocket.h>
#include <rfb/Configuration.h>
#include <rfb/LogWriter.h>
#include <rfb/Logger_stdio.h>
#include <rfb/Logger_syslog.h>
#include <rfb/util.h>

#include "RFBGlue.h"

using namespace rfb;

// Loggers used by C code must be created here
static LogWriter inputLog("Input");
static LogWriter selectionLog("Selection");

void vncInitRFB(void)
{
  rfb::initStdIOLoggers();
  rfb::initSyslogLogger();
  rfb::LogWriter::setLogParams("*:stderr:30");
  rfb::Configuration::enableServerParams();
}

void vncLogError(const char *name, const char *format, ...)
{
  LogWriter *vlog;
  va_list ap;
  v
pan class="k">if (vlog == NULL) return; va_start(ap, format); vlog->verror(format, ap); va_end(ap); } void vncLogStatus(const char *name, const char *format, ...) { LogWriter *vlog; va_list ap; vlog = LogWriter::getLogWriter(name); if (vlog == NULL) return; va_start(ap, format); vlog->vstatus(format, ap); va_end(ap); } void vncLogInfo(const char *name, const char *format, ...) { LogWriter *vlog; va_list ap; vlog = LogWriter::getLogWriter(name); if (vlog == NULL) return; va_start(ap, format); vlog->vinfo(format, ap); va_end(ap); } void vncLogDebug(const char *name, const char *format, ...) { LogWriter *vlog; va_list ap; vlog = LogWriter::getLogWriter(name); if (vlog == NULL) return; va_start(ap, format); vlog->vdebug(format, ap); va_end(ap); } int vncSetParam(const char *name, const char *value) { if (value != NULL) return rfb::Configuration::setParam(name, value); else { VoidParameter *param; param = rfb::Configuration::getParam(name); if (param == NULL) return false; return param->setParam(); } } int vncSetParamSimple(const char *nameAndValue) { return rfb::Configuration::setParam(nameAndValue); } char* vncGetParam(const char *name) { VoidParameter *param; // Hack to avoid exposing password! if (strcasecmp(name, "Password") == 0) return NULL; param = rfb::Configuration::getParam(name); if (param == NULL) return NULL; return strdup(param->getValueStr().c_str()); } const char* vncGetParamDesc(const char *name) { rfb::VoidParameter *param; param = rfb::Configuration::getParam(name); if (param == NULL) return NULL; return param->getDescription(); } int vncIsParamBool(const char *name) { VoidParameter *param; BoolParameter *bparam; param = rfb::Configuration::getParam(name); if (param == NULL) return false; bparam = dynamic_cast<BoolParameter*>(param); if (bparam == NULL) return false; return true; } int vncGetParamCount(void) { int count; count = 0; for (ParameterIterator i; i.param; i.next()) count++; return count; } char *vncGetParamList(void) { int len; char *data, *ptr; len = 0; for (ParameterIterator i; i.param; i.next()) { int l = strlen(i.param->getName()); if (l <= 255) len += l + 1; } data = (char*)malloc(len + 1); if (data == NULL) return NULL; ptr = data; for (ParameterIterator i; i.param; i.next()) { int l = strlen(i.param->getName()); if (l <= 255) { *ptr++ = l; memcpy(ptr, i.param->getName(), l); ptr += l; } } *ptr = '\0'; return data; } void vncListParams(int width, int nameWidth) { rfb::Configuration::listParams(width, nameWidth); } int vncGetSocketPort(int fd) { return network::getSockPort(fd); } int vncIsTCPPortUsed(int port) { try { // Attempt to create TCPListeners on that port. std::list<network::SocketListener*> dummy; network::createTcpListeners (&dummy, 0, port); while (!dummy.empty()) { delete dummy.back(); dummy.pop_back(); } } catch (rdr::Exception& e) { return 1; } return 0; } char* vncConvertLF(const char* src, size_t bytes) { try { return strdup(convertLF(src, bytes).c_str()); } catch (...) { return NULL; } } char* vncLatin1ToUTF8(const char* src, size_t bytes) { try { return strdup(latin1ToUTF8(src, bytes).c_str()); } catch (...) { return NULL; } } char* vncUTF8ToLatin1(const char* src, size_t bytes) { try { return strdup(utf8ToLatin1(src, bytes).c_str()); } catch (...) { return NULL; } }