Subversion Repositories Kolibri OS

Rev

Rev 5666 | Rev 5670 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5663 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2010-2015. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  VNC client for KolibriOS                                       ;;
7
;;                                                                 ;;
8
;;  Written by hidnplayr@kolibrios.org                             ;;
9
;;                                                                 ;;
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
11
;;             Version 2, June 1991                                ;;
12
;;                                                                 ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3545 hidnplayr 14
 
15
thread_start:
16
 
5668 hidnplayr 17
        mcall   40, 0                   ; disable all events for this thread
3545 hidnplayr 18
 
19
; resolve name
5668 hidnplayr 20
        push    esp                     ; reserve stack place
5663 hidnplayr 21
        invoke  getaddrinfo, serveraddr, 0, 0, esp
3545 hidnplayr 22
        pop     esi
23
; test for error
24
        test    eax, eax
5668 hidnplayr 25
        jnz     err_dns
3545 hidnplayr 26
 
27
        mov     eax, [esi+addrinfo.ai_addr]
28
        mov     eax, [eax+sockaddr_in.sin_addr]
29
        mov     [sockaddr1.ip], eax
30
 
5663 hidnplayr 31
        DEBUGF  1, "Connecting to %u.%u.%u.%u:%u\n", \
32
                [sockaddr1.ip]:1, [sockaddr1.ip+1]:1, \
33
                [sockaddr1.ip+2]:1, [sockaddr1.ip+3]:1, \
34
                [sockaddr1.port]:2
3545 hidnplayr 35
 
5668 hidnplayr 36
        invoke  freeaddrinfo, esi
37
 
3545 hidnplayr 38
        mcall   socket, AF_INET4, SOCK_STREAM, 0
5668 hidnplayr 39
        cmp     eax, -1
40
        je      err_sock
41
 
3545 hidnplayr 42
        mov     [socketnum], eax
43
        mcall   connect, [socketnum], sockaddr1, 18
5668 hidnplayr 44
        cmp     eax, -1
45
        je      err_connect
3545 hidnplayr 46
 
5663 hidnplayr 47
        ; TODO: implement timeout
3545 hidnplayr 48
        call    wait_for_data
49
 
5663 hidnplayr 50
        cmp     dword[receive_buffer], "RFB "
5668 hidnplayr 51
        jne     err_proto
5663 hidnplayr 52
        DEBUGF  1, "received: %s\n", receive_buffer
5668 hidnplayr 53
        mcall   send, [socketnum], HandShake, 12, 0
5663 hidnplayr 54
        DEBUGF  1, "Sending handshake: protocol version\n"
3545 hidnplayr 55
 
56
        call    wait_for_data
57
 
5663 hidnplayr 58
        cmp     dword[receive_buffer], 0x01000000
3545 hidnplayr 59
        je      no_security
5663 hidnplayr 60
        cmp     dword[receive_buffer], 0x02000000
3545 hidnplayr 61
        je      vnc_security
5668 hidnplayr 62
        jmp     err_security
3545 hidnplayr 63
 
64
vnc_security:
5668 hidnplayr 65
        mov     [status], STATUS_LOGIN
66
        call    draw_gui
3545 hidnplayr 67
 
68
no_security:
5663 hidnplayr 69
        mcall   send, [socketnum], ClientInit, 1, 0
70
        DEBUGF  1, "ClientInit sent\n"
3545 hidnplayr 71
 
72
        call    wait_for_data       ; now the server should send init message
73
 
5663 hidnplayr 74
        DEBUGF  1, "Serverinit: bpp: %u depth: %u bigendian: %u truecolor: %u\n", \
75
        [receive_buffer+framebuffer.pixelformat.bpp]:1, \
76
        [receive_buffer+framebuffer.pixelformat.depth]:1, \
77
        [receive_buffer+framebuffer.pixelformat.big_endian]:1, \
78
        [receive_buffer+framebuffer.pixelformat.true_color]:1
3545 hidnplayr 79
 
5663 hidnplayr 80
        mov     eax, dword[receive_buffer+framebuffer.width]
5668 hidnplayr 81
        mov     dword[FramebufferUpdateRequest.width], eax
3545 hidnplayr 82
        bswap   eax
5663 hidnplayr 83
        mov     dword[screen], eax
84
        DEBUGF  1, "Screen width=%u, height=%u\n", [screen.width]:2, [screen.height]:2
3545 hidnplayr 85
 
5668 hidnplayr 86
        mcall   send, [socketnum], SetPixelFormat8, 20, 0
5663 hidnplayr 87
        DEBUGF  1, "Sending pixel format\n"
3545 hidnplayr 88
 
5668 hidnplayr 89
        mcall   send, [socketnum], SetEncodings, 12, 0
5663 hidnplayr 90
        DEBUGF  1, "Sending encoding info\n"
3545 hidnplayr 91
 
5668 hidnplayr 92
; Set main window caption to servername
93
        mov     ecx, dword[receive_buffer+framebuffer.name_length]
94
        bswap   ecx
95
        cmp     ecx, 64
96
        jbe     @f
97
        mov     ecx, 64
98
  @@:
99
        lea     esi, [receive_buffer+framebuffer.name]
100
        mov     edi, servername
101
        rep movsb
102
        mov     byte[edi], 0
103
        mov     [name.dash], "-"
3545 hidnplayr 104
 
5668 hidnplayr 105
; Tell the main thread we are ready for business!
106
        mov     [status], STATUS_CONNECTED
107
 
5663 hidnplayr 108
; Request initial update
5668 hidnplayr 109
        mov     [FramebufferUpdateRequest.inc], 0
5663 hidnplayr 110
 
111
request_fbu:
112
        DEBUGF  1, "Requesting framebuffer update\n"
5668 hidnplayr 113
        mcall   send, [socketnum], FramebufferUpdateRequest, 10, 0
114
        mov     [FramebufferUpdateRequest.inc], 1
3545 hidnplayr 115
 
116
thread_loop:
117
        call    read_data              ; Read the data into the buffer
118
 
5663 hidnplayr 119
        lodsb
120
        cmp     al, 0
3545 hidnplayr 121
        je      framebufferupdate
5663 hidnplayr 122
        cmp     al, 1
3545 hidnplayr 123
        je      setcolourmapentries
5663 hidnplayr 124
        cmp     al, 2
3545 hidnplayr 125
        je      bell
5663 hidnplayr 126
        cmp     al, 3
3545 hidnplayr 127
        je      servercuttext
128
 
5663 hidnplayr 129
 
130
        DEBUGF  1, "Unknown server command: %u\n", al
3545 hidnplayr 131
        jmp     thread_loop
132
 
133
framebufferupdate:
134
 
5663 hidnplayr 135
  @@:
136
        lea     eax, [esi+6]
137
        cmp     [datapointer], eax
138
        jae     @f
139
        call    read_data.more
140
        jmp     @b
141
  @@:
142
 
143
        inc     esi     ; padding
144
        lodsw
3545 hidnplayr 145
        xchg    al, ah
5663 hidnplayr 146
        mov     [rectangles], ax
147
        DEBUGF  1, "Framebufferupdate: %u rectangles\n", ax
3545 hidnplayr 148
 
5663 hidnplayr 149
rectangle_loop:
3545 hidnplayr 150
 
5663 hidnplayr 151
  @@:
152
        lea     eax, [esi+12]
153
        cmp     [datapointer], eax
154
        jae     @f
155
        call    read_data.more
156
        jmp     @b
157
  @@:
3545 hidnplayr 158
 
5668 hidnplayr 159
        xor     eax, eax
160
        lodsw
161
        xchg    al, ah
162
        mov     [rectangle.x], eax
163
        lodsw
164
        xchg    al, ah
165
        mov     [rectangle.y], eax
166
        lodsw
167
        xchg    al, ah
168
        mov     [rectangle.width], eax
169
        lodsw
170
        xchg    al, ah
171
        mov     [rectangle.height], eax
3545 hidnplayr 172
 
5663 hidnplayr 173
        lodsd                           ; encoding
174
        DEBUGF  1, "rectangle: width=%u height=%u x=%u y=%u encoding: ",\
175
        [rectangle.width]:2, [rectangle.height]:2, [rectangle.x]:2, [rectangle.y]:2
3545 hidnplayr 176
 
177
        cmp     eax, 0
178
        je      encoding_raw
5666 hidnplayr 179
        cmp     eax, 1
5668 hidnplayr 180
        je      encoding_CopyRect
181
        cmp     eax, 2
182
        je      encoding_RRE
5663 hidnplayr 183
;        cmp     eax, 5
184
;        je      encoding_hextile
185
;        cmp     eax, 15
186
;        je      encoding_TRLE
187
;        cmp     eax, 16
188
;        je      encoding_ZRLE
3545 hidnplayr 189
 
5663 hidnplayr 190
        DEBUGF  1, "\nunknown encoding: %u\n", eax
3545 hidnplayr 191
        jmp     thread_loop
192
 
5663 hidnplayr 193
next_rectangle:
194
        push    esi
195
        call    drawbuffer
196
        pop     esi
3545 hidnplayr 197
 
5663 hidnplayr 198
        dec     [rectangles]
199
        jnz     rectangle_loop
200
        jmp     request_fbu
3545 hidnplayr 201
 
202
 
5663 hidnplayr 203
setcolourmapentries:
3545 hidnplayr 204
 
5663 hidnplayr 205
        DEBUGF  1, "Server sent SetColourMapEntries message\n"
3545 hidnplayr 206
 
5663 hidnplayr 207
        ; TODO
3545 hidnplayr 208
 
209
        jmp     thread_loop
210
 
211
 
212
bell:
213
        mcall   55, 55, , , beep
214
        jmp     thread_loop
215
 
216
 
217
servercuttext:
218
 
5663 hidnplayr 219
        DEBUGF  1, "Server cut text\n"
3545 hidnplayr 220
 
5663 hidnplayr 221
  @@:
222
        lea     eax, [esi+7]
223
        cmp     [datapointer], eax
224
        jae     @f
225
        call    read_data.more
226
        jmp     @b
227
  @@:
228
 
229
        add     esi, 3
230
        lodsd
231
        bswap   eax
232
        mov     ecx, eax
233
 
234
  @@:
235
        lea     eax, [esi+ecx]
236
        cmp     [datapointer], eax
237
        jae     @f
238
        call    read_data.more
239
        jmp     @b
240
  @@:
241
 
242
        ; TODO: paste text to clipboard
243
 
244
        DEBUGF  1, "%u bytes of text\n", ecx
245
        add     esi, ecx
3545 hidnplayr 246
        jmp     thread_loop
247
 
248
 
249
read_data:
250
        mov     [datapointer], receive_buffer
5663 hidnplayr 251
        mov     esi, receive_buffer
252
  .more:
253
        push    ebx ecx edx esi edi
3545 hidnplayr 254
        mcall   recv, [socketnum], [datapointer], 4096, 0
5663 hidnplayr 255
        pop     edi esi edx ecx ebx
3545 hidnplayr 256
        cmp     eax, -1
5668 hidnplayr 257
        je      err_disconnected
258
        add     [datapointer], eax
259
; Check for buffer overflow
260
        cmp     [datapointer], receive_buffer + RECEIVE_BUFFER_SIZE
261
        jbe     @f
262
        ; Buffer is full, first needed data by program is pointed to by esi.
263
        ; Move all remaining data, starting from esi, to begin of buffer
264
        cmp     esi, receive_buffer
265
        je      err_proto
266
        mov     ecx, [datapointer]
267
        sub     ecx, esi
268
        mov     edi, receive_buffer
269
        rep movsb
270
        mov     [datapointer], edi
271
        mov     esi, receive_buffer
272
  @@:
3545 hidnplayr 273
        cmp     eax, 4096
5663 hidnplayr 274
        je      .more
275
        ret
3545 hidnplayr 276
 
277
 
5663 hidnplayr 278
wait_for_data:  ; FIXME: add timeout
3545 hidnplayr 279
        mcall   recv, [socketnum], receive_buffer, 4096, 0
280
        cmp     eax, -1
5668 hidnplayr 281
        je      err_disconnected
3545 hidnplayr 282
        test    eax, eax
283
        jz      wait_for_data
5668 hidnplayr 284
        ret
3545 hidnplayr 285
 
5668 hidnplayr 286
 
287
err_disconnected:
288
        mov     [status], STATUS_DISCONNECTED
289
        inc     [update_gui]
290
        mcall   -1
291
 
292
err_dns:
293
        mov     [status], STATUS_DNS_ERR
294
        inc     [update_gui]
295
        mcall   -1
296
 
297
err_sock:
298
        mov     [status], STATUS_SOCK_ERR
299
        inc     [update_gui]
300
        mcall   -1
301
 
302
err_connect:
303
        mov     [status], STATUS_CONNECT_ERR
304
        inc     [update_gui]
305
        mcall   -1
3545 hidnplayr 306
        ret
307
 
5668 hidnplayr 308
err_proto:
309
        mov     [status], STATUS_PROTO_ERR
310
        inc     [update_gui]
5663 hidnplayr 311
        mcall   -1
312
        ret
313
 
5668 hidnplayr 314
err_security:
315
        mov     [status], STATUS_SECURITY_ERR
316
        inc     [update_gui]
317
        mcall   -1
318
        ret