summaryrefslogtreecommitdiffstats
path: root/libvncserver/tightvnc-filetransfer/rfbtightproto.h
blob: 30fc5f5413aa1d4251402177dabe7c872e31ca3c (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
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/*
 * Copyright (c) 2005 Novell, Inc.
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program 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 program; if not, contact Novell, Inc.
 *
 * To contact Novell about this file by physical or electronic mail,
 * you may find current contact information at www.novell.com 
 *
 * Author		: Rohit Kumar
 * Email ID	: rokumar@novell.com
 * Date		: 25th August 2005
 */

#ifndef RFBTIGHTPROTO_H
#define RFBTIGHTPROTO_H

#include <rfb/rfb.h>
#include <limits.h>

/* PATH_MAX is not defined in limits.h on some platforms */
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif


#define rfbSecTypeTight 16

void rfbTightUsage(void);
int rfbTightProcessArgs(int argc, char *argv[]);

/*-----------------------------------------------------------------------------
 * Negotiation of Tunneling Capabilities (protocol version 3.7t)
 *
 * If the chosen security type is rfbSecTypeTight, the server sends a list of
 * supported tunneling methods ("tunneling" refers to any additional layer of
 * data transformation, such as encryption or external compression.)
 *
 * nTunnelTypes specifies the number of following rfbCapabilityInfo structures
 * that list all supported tunneling methods in the order of preference.
 *
 * NOTE: If nTunnelTypes is 0, that tells the client that no tunneling can be
 * used, and the client should not send a response requesting a tunneling
 * method.
 */

typedef struct _rfbTunnelingCapsMsg {
    uint32_t nTunnelTypes;
    /* followed by nTunnelTypes * rfbCapabilityInfo structures */
} rfbTunnelingCapsMsg;

#define sz_rfbTunnelingCapsMsg 4

/*-----------------------------------------------------------------------------
 * Tunneling Method Request (protocol version 3.7t)
 *
 * If the list of tunneling capabilities sent by the server was not empty, the
 * client should reply with a 32-bit code specifying a particular tunneling
 * method.  The following code should be used for no tunneling.
 */

#define rfbNoTunneling 0
#define sig_rfbNoTunneling "NOTUNNEL"


/*-----------------------------------------------------------------------------
 * Negotiation of Authentication Capabilities (protocol version 3.7t)
 *
 * After setting up tunneling, the server sends a list of supported
 * authentication schemes.
 *
 * nAuthTypes specifies the number of following rfbCapabilityInfo structures
 * that list all supported authentication schemes in the order of preference.
 *
 * NOTE: If nAuthTypes is 0, that tells the client that no authentication is
 * necessary, and the client should not send a response requesting an
 * authentication scheme.
 */

typedef struct _rfbAuthenticationCapsMsg {
    uint32_t nAuthTypes;
    /* followed by nAuthTypes * rfbCapabilityInfo structures */
} rfbAuthenticationCapsMsg;

#define sz_rfbAuthenticationCapsMsg 4

/*-----------------------------------------------------------------------------
 * Authentication Scheme Request (protocol version 3.7t)
 *
 * If the list of authentication capabilities sent by the server was not empty,
 * the client should reply with a 32-bit code specifying a particular
 * authentication scheme.  The following codes are supported.
 */

#define rfbAuthNone 1
#define rfbAuthVNC 2
#define rfbAuthUnixLogin 129
#define rfbAuthExternal 130

#define sig_rfbAuthNone "NOAUTH__"
#define sig_rfbAuthVNC "VNCAUTH_"
#define sig_rfbAuthUnixLogin "ULGNAUTH"
#define sig_rfbAuthExternal "XTRNAUTH"

/*-----------------------------------------------------------------------------
 * Structure used to describe protocol options such as tunneling methods,
 * authentication schemes and message types (protocol version 3.7t).
 */

typedef struct _rfbCapabilityInfo {

    uint32_t  code;		/* numeric identifier */
    uint8_t    vendorSignature[4];	/* vendor identification */
    uint8_t    nameSignature[8];	/* abbreviated option name */

} rfbCapabilityInfo;

#define sz_rfbCapabilityInfoVendor 4
#define sz_rfbCapabilityInfoName 8
#define sz_rfbCapabilityInfo 16

/*
 * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC.
 */

#define rfbStandardVendor "STDV"
#define rfbTridiaVncVendor "TRDV"
#define rfbTightVncVendor "TGHT"


/* It's a good idea to keep these values a bit greater than required. */
#define MAX_TIGHT_ENCODINGS 10
#define MAX_TUNNELING_CAPS 16
#define MAX_AUTH_CAPS 16

typedef struct _rfbClientFileDownload {
	char fName[PATH_MAX];
	int downloadInProgress;
	unsigned long mTime;
	int downloadFD;
	pthread_t downloadThread;
} rfbClientFileDownload ;

typedef struct _rfbClientFileUpload {
	char fName[PATH_MAX];
	int uploadInProgress;
	unsigned long mTime;
	unsigned long fSize;
	int uploadFD;
} rfbClientFileUpload ;

typedef struct _rfbClientFileTransfer {
	rfbClientFileDownload rcfd;
	rfbClientFileUpload rcfu;
} rfbClientFileTransfer;


typedef struct _rfbTightClientRec {

    /* Lists of capability codes sent to clients. We remember these
       lists to restrict clients from choosing those tunneling and
       authentication types that were not advertised. */

    int nAuthCaps;
    uint32_t authCaps[MAX_AUTH_CAPS];

    /* This is not useful while we don't support tunneling:
    int nTunnelingCaps;
    uint32_t tunnelingCaps[MAX_TUNNELING_CAPS]; */

    rfbClientFileTransfer rcft;

} rfbTightClientRec, *rfbTightClientPtr;

/*
 * Macro to fill in an rfbCapabilityInfo structure (protocol 3.7t).
 * Normally, using macros is no good, but this macro saves us from
 * writing constants twice -- it constructs signature names from codes.
 * Note that "code_sym" argument should be a single symbol, not an expression.
 */

#define SetCapInfo(cap_ptr, code_sym, vendor)		\
{							\
    rfbCapabilityInfo *pcap;				\
    pcap = (cap_ptr);					\
    pcap->code = Swap32IfLE(code_sym);			\
    memcpy(pcap->vendorSignature, (vendor),		\
	   sz_rfbCapabilityInfoVendor);			\
    memcpy(pcap->nameSignature, sig_##code_sym,		\
	   sz_rfbCapabilityInfoName);			\
}

void rfbHandleSecTypeTight(rfbClientPtr cl);


/*-----------------------------------------------------------------------------
 * Server Interaction Capabilities Message (protocol version 3.7t)
 *
 * In the protocol version 3.7t, the server informs the client what message
 * types it supports in addition to ones defined in the protocol version 3.7.
 * Also, the server sends the list of all supported encodings (note that it's
 * not necessary to advertise the "raw" encoding since it MUST be supported in
 * RFB 3.x protocols).
 *
 * This data immediately follows the server initialisation message.
 */

typedef struct _rfbInteractionCapsMsg {
    uint16_t nServerMessageTypes;
    uint16_t nClientMessageTypes;
    uint16_t nEncodingTypes;
    uint16_t pad;			/* reserved, must be 0 */
    /* followed by nServerMessageTypes * rfbCapabilityInfo structures */
    /* followed by nClientMessageTypes * rfbCapabilityInfo structures */
} rfbInteractionCapsMsg;

#define sz_rfbInteractionCapsMsg 8

#define rfbFileListData 130
#define rfbFileDownloadData 131
#define rfbFileUploadCancel 132
#define rfbFileDownloadFailed 133

/* signatures for non-standard messages */
#define sig_rfbFileListData "FTS_LSDT"
#define sig_rfbFileDownloadData "FTS_DNDT"
#define sig_rfbFileUploadCancel "FTS_UPCN"
#define sig_rfbFileDownloadFailed "FTS_DNFL"



#define rfbFileListRequest 130
#define rfbFileDownloadRequest 131
#define rfbFileUploadRequest 132
#define rfbFileUploadData 133
#define rfbFileDownloadCancel 134
#define rfbFileUploadFailed 135
#define rfbFileCreateDirRequest 136

/* signatures for non-standard messages */
#define sig_rfbFileListRequest "FTC_LSRQ"
#define sig_rfbFileDownloadRequest "FTC_DNRQ"
#define sig_rfbFileUploadRequest "FTC_UPRQ"
#define sig_rfbFileUploadData "FTC_UPDT"
#define sig_rfbFileDownloadCancel "FTC_DNCN"
#define sig_rfbFileUploadFailed "FTC_UPFL"
#define sig_rfbFileCreateDirRequest "FTC_FCDR"


/* signatures for basic encoding types */
#define sig_rfbEncodingRaw       "RAW_____"
#define sig_rfbEncodingCopyRect  "COPYRECT"
#define sig_rfbEncodingRRE       "RRE_____"
#define sig_rfbEncodingCoRRE     "CORRE___"
#define sig_rfbEncodingHextile   "HEXTILE_"
#define sig_rfbEncodingZlib      "ZLIB____"
#define sig_rfbEncodingTight     "TIGHT___"
#define sig_rfbEncodingZlibHex   "ZLIBHEX_"


/* signatures for "fake" encoding types */
#define sig_rfbEncodingCompressLevel0  "COMPRLVL"
#define sig_rfbEncodingXCursor         "X11CURSR"
#define sig_rfbEncodingRichCursor      "RCHCURSR"
#define sig_rfbEncodingPointerPos      "POINTPOS"
#define sig_rfbEncodingLastRect        "LASTRECT"
#define sig_rfbEncodingNewFBSize       "NEWFBSIZ"
#define sig_rfbEncodingQualityLevel0   "JPEGQLVL"


/*-----------------------------------------------------------------------------
 * FileListRequest
 */

typedef struct _rfbFileListRequestMsg {
    uint8_t type;
    uint8_t flags;
    uint16_t dirNameSize;
    /* Followed by char Dirname[dirNameSize] */
} rfbFileListRequestMsg;

#define sz_rfbFileListRequestMsg 4

/*-----------------------------------------------------------------------------
 * FileDownloadRequest
 */

typedef struct _rfbFileDownloadRequestMsg {
    uint8_t type;
    uint8_t compressedLevel;
    uint16_t fNameSize;
    uint32_t position;
    /* Followed by char Filename[fNameSize] */
} rfbFileDownloadRequestMsg;

#define sz_rfbFileDownloadRequestMsg 8

/*-----------------------------------------------------------------------------
 * FileUploadRequest
 */

typedef struct _rfbFileUploadRequestMsg {
    uint8_t type;
    uint8_t compressedLevel;
    uint16_t fNameSize;
    uint32_t position;
    /* Followed by char Filename[fNameSize] */
} rfbFileUploadRequestMsg;

#define sz_rfbFileUploadRequestMsg 8


/*-----------------------------------------------------------------------------
 * FileUploadData
 */

typedef struct _rfbFileUploadDataMsg {
    uint8_t type;
    uint8_t compressedLevel;
    uint16_t realSize;
    uint16_t compressedSize;
    /* Followed by File[compressedSize], 
       but if (realSize = compressedSize = 0) followed by uint32_t modTime  */
} rfbFileUploadDataMsg;

#define sz_rfbFileUploadDataMsg 6

/*-----------------------------------------------------------------------------
 * FileDownloadCancel
 */

typedef struct _rfbFileDownloadCancelMsg {
    uint8_t type;
    uint8_t unused;
    uint16_t reasonLen;
    /* Followed by reason[reasonLen] */
} rfbFileDownloadCancelMsg;

#define sz_rfbFileDownloadCancelMsg 4

/*-----------------------------------------------------------------------------
 * FileUploadFailed
 */

typedef struct _rfbFileUploadFailedMsg {
    uint8_t type;
    uint8_t unused;
    uint16_t reasonLen;
    /* Followed by reason[reasonLen] */
} rfbFileUploadFailedMsg;

#define sz_rfbFileUploadFailedMsg 4

/*-----------------------------------------------------------------------------
 * FileCreateDirRequest
 */

typedef struct _rfbFileCreateDirRequestMsg {
    uint8_t type;
    uint8_t unused;
    uint16_t dNameLen;
    /* Followed by dName[dNameLen] */
} rfbFileCreateDirRequestMsg;

#define sz_rfbFileCreateDirRequestMsg 4


/*-----------------------------------------------------------------------------
 * Union of all client->server messages.
 */

typedef union _rfbClientToServerTightMsg {
    rfbFileListRequestMsg flr;
    rfbFileDownloadRequestMsg fdr;
    rfbFileUploadRequestMsg fupr;
    rfbFileUploadDataMsg fud;
    rfbFileDownloadCancelMsg fdc;
    rfbFileUploadFailedMsg fuf;
    rfbFileCreateDirRequestMsg fcdr;
} rfbClientToServerTightMsg;



/*-----------------------------------------------------------------------------
 * FileListData
 */

typedef struct _rfbFileListDataMsg {
    uint8_t type;
    uint8_t flags;
    uint16_t numFiles;
    uint16_t dataSize;
    uint16_t compressedSize;
    /* Followed by SizeData[numFiles] */
    /* Followed by Filenames[compressedSize] */
} rfbFileListDataMsg;

#define sz_rfbFileListDataMsg 8

/*-----------------------------------------------------------------------------
 * FileDownloadData
 */

typedef struct _rfbFileDownloadDataMsg {
    uint8_t type;
    uint8_t compressLevel;
    uint16_t realSize;
    uint16_t compressedSize;
    /* Followed by File[copressedSize], 
       but if (realSize = compressedSize = 0) followed by uint32_t modTime  */
} rfbFileDownloadDataMsg;

#define sz_rfbFileDownloadDataMsg 6


/*-----------------------------------------------------------------------------
 * FileUploadCancel
 */

typedef struct _rfbFileUploadCancelMsg {
    uint8_t type;
    uint8_t unused;
    uint16_t reasonLen;
    /* Followed by reason[reasonLen] */
} rfbFileUploadCancelMsg;

#define sz_rfbFileUploadCancelMsg 4

/*-----------------------------------------------------------------------------
 * FileDownloadFailed
 */

typedef struct _rfbFileDownloadFailedMsg {
    uint8_t type;
    uint8_t unused;
    uint16_t reasonLen;
    /* Followed by reason[reasonLen] */
} rfbFileDownloadFailedMsg;

#define sz_rfbFileDownloadFailedMsg 4




#endif