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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
|
diff --git a/libvncclient/rfbproto.c b/libvncclient/rfbproto.c
index 6e87f69..35aab36 100644
--- a/libvncclient/rfbproto.c
+++ b/libvncclient/rfbproto.c
@@ -136,6 +136,7 @@ static void FillRectangle(rfbClient* client, int x, int y, int w, int h, uint32_
case 32: FILL_RECT(32); break;
default:
rfbClientLog("Unsupported bitsPerPixel: %d\n",client->format.bitsPerPixel);
+ client->ClientLogger(client, "Unsupported bitsPerPixel: %d\n",client->format.bitsPerPixel);
}
}
@@ -157,6 +158,7 @@ static void CopyRectangle(rfbClient* client, uint8_t* buffer, int x, int y, int
case 32: COPY_RECT(32); break;
default:
rfbClientLog("Unsupported bitsPerPixel: %d\n",client->format.bitsPerPixel);
+ client->ClientLogger(client, "Unsupported bitsPerPixel: %d\n",client->format.bitsPerPixel);
}
}
@@ -200,6 +202,7 @@ static void CopyRectangleFromRectangle(rfbClient* client, int src_x, int src_y,
case 32: COPY_RECT_FROM_RECT(32); break;
default:
rfbClientLog("Unsupported bitsPerPixel: %d\n",client->format.bitsPerPixel);
+ client->ClientLogger(client, "Unsupported bitsPerPixel: %d\n",client->format.bitsPerPixel);
}
}
@@ -360,12 +363,14 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port)
if (!rec->file) {
rfbClientLog("Could not open %s.\n",client->serverHost);
+ client->ClientLogger(client, "Could not open %s.\n",client->serverHost);
return FALSE;
}
setbuf(rec->file,NULL);
fread(buffer,1,strlen(magic),rec->file);
if (strncmp(buffer,magic,strlen(magic))) {
- rfbClientLog("File %s was not recorded by vncrec.\n",client->serverHost);
+ rfbClientLog(client, "File %s was not recorded by vncrec.\n",client->serverHost);
+ client->ClientLogger(client, "File %s was not recorded by vncrec.\n",client->serverHost);
fclose(rec->file);
return FALSE;
}
@@ -375,6 +380,7 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port)
if (!StringToIPAddr(hostname, &host)) {
rfbClientLog("Couldn't convert '%s' to host address\n", hostname);
+ client->ClientLogger(client, "Couldn't convert '%s' to host address\n", hostname);
return FALSE;
}
@@ -382,6 +388,7 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port)
if (client->sock < 0) {
rfbClientLog("Unable to connect to VNC server\n");
+ client->ClientLogger(client, "Unable to connect to VNC server\n");
return FALSE;
}
@@ -403,6 +410,7 @@ rfbHandleAuthResult(rfbClient* client)
switch (authResult) {
case rfbVncAuthOK:
rfbClientLog("VNC authentication succeeded\n");
+ client->ClientLogger(client, "VNC authentication succeeded\n");
return TRUE;
break;
case rfbVncAuthFailed:
@@ -415,18 +423,23 @@ rfbHandleAuthResult(rfbClient* client)
if (!ReadFromRFBServer(client, reason, reasonLen)) { free(reason); return FALSE; }
reason[reasonLen]=0;
rfbClientLog("VNC connection failed: %s\n",reason);
+ client->ClientLogger(client, "VNC connection failed: %s\n",reason);
free(reason);
return FALSE;
}
rfbClientLog("VNC authentication failed\n");
+ client->ClientLogger(client, "VNC authentication failed\n");
return FALSE;
case rfbVncAuthTooMany:
rfbClientLog("VNC authentication failed - too many tries\n");
+ client->ClientLogger(client, "VNC authentication failed - too many tries\n");
return FALSE;
}
rfbClientLog("Unknown VNC authentication result: %d\n",
(int)authResult);
+ client->ClientLogger(client, "Unknown VNC authentication result: %d\n",
+ (int)authResult);
return FALSE;
}
@@ -462,6 +475,7 @@ InitialiseRFBConnection(rfbClient* client)
if (sscanf(pv,rfbProtocolVersionFormat,&major,&minor) != 2) {
rfbClientLog("Not a valid VNC server (%s)\n",pv);
+ client->ClientLogger(client, "Not a valid VNC server (%s)\n",pv);
return FALSE;
}
@@ -477,12 +491,14 @@ InitialiseRFBConnection(rfbClient* client)
/* UltraVNC uses minor codes 4 and 6 for the server */
if (major==3 && (minor==4 || minor==6)) {
rfbClientLog("UltraVNC server detected, enabling UltraVNC specific messages\n",pv);
+ client->ClientLogger(client, "UltraVNC server detected, enabling UltraVNC specific messages\n",pv);
DefaultSupportedMessagesUltraVNC(client);
}
/* TightVNC uses minor codes 5 for the server */
if (major==3 && minor==5) {
rfbClientLog("TightVNC server detected, enabling TightVNC specific messages\n",pv);
+ client->ClientLogger(client, "TightVNC server detected, enabling TightVNC specific messages\n",pv);
DefaultSupportedMessagesTightVNC(client);
}
@@ -492,6 +508,8 @@ InitialiseRFBConnection(rfbClient* client)
rfbClientLog("VNC server supports protocol version %d.%d (viewer %d.%d)\n",
major, minor, rfbProtocolMajorVersion, rfbProtocolMinorVersion);
+ client->ClientLogger(client, "VNC server supports protocol version %d.%d (viewer %d.%d)\n",
+ major, minor, rfbProtocolMajorVersion, rfbProtocolMinorVersion);
sprintf(pv,rfbProtocolVersionFormat,client->major,client->minor);
@@ -511,6 +529,7 @@ InitialiseRFBConnection(rfbClient* client)
if (count==0)
{
rfbClientLog("List of security types is ZERO, expecting an error to follow\n");
+ client->ClientLogger(client, "List of security types is ZERO, expecting an error to follow\n");
/* we have an error following */
if (!ReadFromRFBServer(client, (char *)&reasonLen, 4)) return FALSE;
@@ -519,21 +538,25 @@ InitialiseRFBConnection(rfbClient* client)
if (!ReadFromRFBServer(client, reason, reasonLen)) { free(reason); return FALSE; }
reason[reasonLen]=0;
rfbClientLog("VNC connection failed: %s\n",reason);
+ client->ClientLogger(client, "VNC connection failed: %s\n",reason);
free(reason);
return FALSE;
}
rfbClientLog("We have %d security types to read\n", count);
+ client->ClientLogger(client, "We have %d security types to read\n", count);
/* now, we have a list of available security types to read ( uint8_t[] ) */
for (loop=0;loop<count;loop++)
{
if (!ReadFromRFBServer(client, (char *)&tAuth, 1)) return FALSE;
rfbClientLog("%d) Received security type %d\n", loop, tAuth);
+ client->ClientLogger(client, "%d) Received security type %d\n", loop, tAuth);
if ((flag==0) && ((tAuth==rfbVncAuth) || (tAuth==rfbNoAuth)))
{
flag++;
authScheme=tAuth;
rfbClientLog("Selecting security type %d (%d/%d in the list)\n", authScheme, loop, count);
+ client->ClientLogger(client, "Selecting security type %d (%d/%d in the list)\n", authScheme, loop, count);
/* send back a single byte indicating which security type to use */
if (!WriteToRFBServer(client, (char *)&tAuth, 1)) return FALSE;
@@ -547,6 +570,7 @@ InitialiseRFBConnection(rfbClient* client)
}
rfbClientLog("Selected Security Scheme %d\n", authScheme);
+ client->ClientLogger(client, "Selected Security Scheme %d\n", authScheme);
switch (authScheme) {
@@ -559,11 +583,13 @@ InitialiseRFBConnection(rfbClient* client)
if (!ReadFromRFBServer(client, reason, reasonLen)) { free(reason); return FALSE; }
reason[reasonLen]=0;
rfbClientLog("VNC connection failed: %s\n", reason);
+ client->ClientLogger(client, "VNC connection failed: %s\n", reason);
free(reason);
return FALSE;
case rfbNoAuth:
rfbClientLog("No authentication needed\n");
+ client->ClientLogger(client, "No authentication needed\n");
/* 3.8 and upwards sends a Security Result for rfbNoAuth */
if (client->major==3 && client->minor > 7)
@@ -580,6 +606,7 @@ InitialiseRFBConnection(rfbClient* client)
if ((!passwd) || (strlen(passwd) == 0)) {
rfbClientLog("Reading password failed\n");
+ client->ClientLogger(client, "Reading password failed\n");
return FALSE;
}
if (strlen(passwd) > 8) {
@@ -604,6 +631,8 @@ InitialiseRFBConnection(rfbClient* client)
default:
rfbClientLog("Unknown authentication scheme from VNC server: %d\n",
(int)authScheme);
+ client->ClientLogger(client, "Unknown authentication scheme from VNC server: %d\n",
+ (int)authScheme);
return FALSE;
}
@@ -624,6 +653,8 @@ InitialiseRFBConnection(rfbClient* client)
if (!client->desktopName) {
rfbClientLog("Error allocating memory for desktop name, %lu bytes\n",
(unsigned long)client->si.nameLength);
+ client->ClientLogger(client, "Error allocating memory for desktop name, %lu bytes\n",
+ (unsigned long)client->si.nameLength);
return FALSE;
}
@@ -632,11 +663,15 @@ InitialiseRFBConnection(rfbClient* client)
client->desktopName[client->si.nameLength] = 0;
rfbClientLog("Desktop name \"%s\"\n",client->desktopName);
+ client->ClientLogger(client, "Desktop name \"%s\"\n",client->desktopName);
rfbClientLog("Connected to VNC server, using protocol version %d.%d\n",
client->major, client->minor);
+ client->ClientLogger(client, "Connected to VNC server, using protocol version %d.%d\n",
+ client->major, client->minor);
rfbClientLog("VNC server default format:\n");
+ client->ClientLogger(client, "VNC server default format:\n");
PrintPixelFormat(&client->si.format);
return TRUE;
@@ -729,6 +764,7 @@ SetFormatAndEncodings(rfbClient* client)
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingRRE);
} else {
rfbClientLog("Unknown encoding '%.*s'\n",encStrLen,encStr);
+ client->ClientLogger(client, "Unknown encoding '%.*s'\n",encStrLen,encStr);
}
encStr = nextEncStr;
@@ -752,6 +788,7 @@ SetFormatAndEncodings(rfbClient* client)
if (!tunnelSpecified) {
*/
rfbClientLog("Same machine: preferring raw encoding\n");
+ client->ClientLogger(client, "Same machine: preferring raw encoding\n");
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingRaw);
/*
} else {
@@ -1157,6 +1194,7 @@ HandleRFBServerMessage(rfbClient* client)
client->MallocFrameBuffer(client);
SendFramebufferUpdateRequest(client, 0, 0, rect.r.w, rect.r.h, FALSE);
rfbClientLog("Got new framebuffer size: %dx%d\n", rect.r.w, rect.r.h);
+ client->ClientLogger(client, "Got new framebuffer size: %dx%d\n", rect.r.w, rect.r.h);
continue;
}
@@ -1170,12 +1208,18 @@ HandleRFBServerMessage(rfbClient* client)
/* currently ignored by this library */
rfbClientLog("client2server supported messages (bit flags)\n");
+ client->ClientLogger(client, "client2server supported messages (bit flags)\n");
for (loop=0;loop<32;loop+=8)
rfbClientLog("%02X: %04x %04x %04x %04x - %04x %04x %04x %04x\n", loop,
client->supportedMessages.client2server[loop], client->supportedMessages.client2server[loop+1],
client->supportedMessages.client2server[loop+2], client->supportedMessages.client2server[loop+3],
client->supportedMessages.client2server[loop+4], client->supportedMessages.client2server[loop+5],
client->supportedMessages.client2server[loop+6], client->supportedMessages.client2server[loop+7]);
+ client->ClientLogger(client, "%02X: %04x %04x %04x %04x - %04x %04x %04x %04x\n", loop,
+ client->supportedMessages.client2server[loop], client->supportedMessages.client2server[loop+1],
+ client->supportedMessages.client2server[loop+2], client->supportedMessages.client2server[loop+3],
+ client->supportedMessages.client2server[loop+4], client->supportedMessages.client2server[loop+5],
+ client->supportedMessages.client2server[loop+6], client->supportedMessages.client2server[loop+7]);
rfbClientLog("server2client supported messages (bit flags)\n");
for (loop=0;loop<32;loop+=8)
@@ -1184,6 +1228,11 @@ HandleRFBServerMessage(rfbClient* client)
client->supportedMessages.server2client[loop+2], client->supportedMessages.server2client[loop+3],
client->supportedMessages.server2client[loop+4], client->supportedMessages.server2client[loop+5],
client->supportedMessages.server2client[loop+6], client->supportedMessages.server2client[loop+7]);
+ client->ClientLogger(client, "%02X: %04x %04x %04x %04x - %04x %04x %04x %04x\n", loop,
+ client->supportedMessages.server2client[loop], client->supportedMessages.server2client[loop+1],
+ client->supportedMessages.server2client[loop+2], client->supportedMessages.server2client[loop+3],
+ client->supportedMessages.server2client[loop+4], client->supportedMessages.server2client[loop+5],
+ client->supportedMessages.server2client[loop+6], client->supportedMessages.server2client[loop+7]);
continue;
}
@@ -1214,6 +1263,7 @@ HandleRFBServerMessage(rfbClient* client)
}
buffer[rect.r.w]=0; /* null terminate, just in case */
rfbClientLog("Connected to Server \"%s\"\n", buffer);
+ client->ClientLogger(client, "Connected to Server \"%s\"\n", buffer);
free(buffer);
continue;
}
@@ -1226,6 +1276,8 @@ HandleRFBServerMessage(rfbClient* client)
{
rfbClientLog("Rect too large: %dx%d at (%d, %d)\n",
rect.r.w, rect.r.h, rect.r.x, rect.r.y);
+ client->ClientLogger(client, "Rect too large: %dx%d at (%d, %d)\n",
+ rect.r.w, rect.r.h, rect.r.x, rect.r.y);
return FALSE;
}
@@ -1477,6 +1529,8 @@ HandleRFBServerMessage(rfbClient* client)
if(!handled) {
rfbClientLog("Unknown rect encoding %d\n",
(int)rect.encoding);
+ client->ClientLogger(client, "Unknown rect encoding %d\n",
+ (int)rect.encoding);
return FALSE;
}
}
@@ -1536,16 +1590,19 @@ HandleRFBServerMessage(rfbClient* client)
switch(msg.tc.length) {
case rfbTextChatOpen:
rfbClientLog("Received TextChat Open\n");
+ client->ClientLogger(client, "Received TextChat Open\n");
if (client->HandleTextChat!=NULL)
client->HandleTextChat(client, (int)rfbTextChatOpen, NULL);
break;
case rfbTextChatClose:
rfbClientLog("Received TextChat Close\n");
+ client->ClientLogger(client, "Received TextChat Close\n");
if (client->HandleTextChat!=NULL)
client->HandleTextChat(client, (int)rfbTextChatClose, NULL);
break;
case rfbTextChatFinished:
rfbClientLog("Received TextChat Finished\n");
+ client->ClientLogger(client, "Received TextChat Finished\n");
if (client->HandleTextChat!=NULL)
client->HandleTextChat(client, (int)rfbTextChatFinished, NULL);
break;
@@ -1559,6 +1616,7 @@ HandleRFBServerMessage(rfbClient* client)
/* Null Terminate <just in case> */
buffer[msg.tc.length]=0;
rfbClientLog("Received TextChat \"%s\"\n", buffer);
+ client->ClientLogger(client, "Received TextChat \"%s\"\n", buffer);
if (client->HandleTextChat!=NULL)
client->HandleTextChat(client, (int)msg.tc.length, buffer);
free(buffer);
@@ -1577,6 +1635,7 @@ HandleRFBServerMessage(rfbClient* client)
client->MallocFrameBuffer(client);
SendFramebufferUpdateRequest(client, 0, 0, client->width, client->height, FALSE);
rfbClientLog("Got new framebuffer size: %dx%d\n", client->width, client->height);
+ client->ClientLogger(client, "Got new framebuffer size: %dx%d\n", client->width, client->height);
break;
}
@@ -1590,6 +1649,7 @@ HandleRFBServerMessage(rfbClient* client)
client->MallocFrameBuffer(client);
SendFramebufferUpdateRequest(client, 0, 0, client->width, client->height, FALSE);
rfbClientLog("Got new framebuffer size: %dx%d\n", client->width, client->height);
+ client->ClientLogger(client, "Got new framebuffer size: %dx%d\n", client->width, client->height);
break;
}
@@ -1606,6 +1666,8 @@ HandleRFBServerMessage(rfbClient* client)
char buffer[256];
rfbClientLog("Unknown message type %d from VNC server\n",msg.type);
ReadFromRFBServer(client, buffer, 256);
+ client->ClientLogger(client, "Unknown message type %d from VNC server\n",msg.type);
+ ReadFromRFBServer(client, buffer, 256);
return FALSE;
}
}
diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c
index 7f350e2..43823ce 100644
--- a/libvncclient/sockets.c
+++ b/libvncclient/sockets.c
@@ -144,6 +144,7 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
} else {
if (errorMessageOnReadFailure) {
rfbClientLog("VNC server closed connection\n");
+ client->ClientLogger(client, "VNC server closed connection\n");
}
return FALSE;
}
@@ -176,6 +177,7 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
} else {
if (errorMessageOnReadFailure) {
rfbClientLog("VNC server closed connection\n");
+ client->ClientLogger(client, "VNC server closed connection\n");
}
return FALSE;
}
diff --git a/rfb/rfbclient.h b/rfb/rfbclient.h
index 975a66a..ee3bdc8 100644
--- a/rfb/rfbclient.h
+++ b/rfb/rfbclient.h
@@ -115,6 +115,8 @@ typedef void (*BellProc)(struct _rfbClient* client);
typedef void (*GotCursorShapeProc)(struct _rfbClient* client, int xhot, int yhot, int width, int height, int bytesPerPixel);
typedef void (*GotCopyRectProc)(struct _rfbClient* client, int src_x, int src_y, int w, int h, int dest_x, int dest_y);
+typedef void (*ClientLoggerProc)(struct _rfbClient* client, const char *format, ...);
+
typedef struct _rfbClient {
uint8_t* frameBuffer;
int width, height;
@@ -237,6 +239,8 @@ typedef struct _rfbClient {
GotCursorShapeProc GotCursorShape;
GotCopyRectProc GotCopyRect;
+ ClientLoggerProc ClientLogger;
+
/* Which messages are supported by the server
* This is a *guess* for most servers.
* (If we can even detect the type of server)
|