Subversion Repositories Kolibri OS

Rev

Rev 5663 | 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
 
5663 hidnplayr 17
        DEBUGF  1, "I am the thread!\n"
3545 hidnplayr 18
 
5663 hidnplayr 19
        mcall   40, 0                   ; disable all events
3545 hidnplayr 20
 
21
; resolve name
22
        push    esp     ; reserve stack place
5663 hidnplayr 23
        invoke  getaddrinfo, serveraddr, 0, 0, esp
3545 hidnplayr 24
        pop     esi
25
; test for error
26
        test    eax, eax
27
        jnz     exit
28
 
29
        mov     eax, [esi+addrinfo.ai_addr]
30
        mov     eax, [eax+sockaddr_in.sin_addr]
31
        mov     [sockaddr1.ip], eax
32
 
5663 hidnplayr 33
        DEBUGF  1, "Connecting to %u.%u.%u.%u:%u\n", \
34
                [sockaddr1.ip]:1, [sockaddr1.ip+1]:1, \
35
                [sockaddr1.ip+2]:1, [sockaddr1.ip+3]:1, \
36
                [sockaddr1.port]:2
3545 hidnplayr 37
 
38
        mcall   socket, AF_INET4, SOCK_STREAM, 0
5663 hidnplayr 39
        test    eax, eax
40
        jz      exit
41
;;;        invoke  freeaddrinfo, ??
3545 hidnplayr 42
        mov     [socketnum], eax
43
        mcall   connect, [socketnum], sockaddr1, 18
5663 hidnplayr 44
;;;        test    eax, eax
3545 hidnplayr 45
 
5663 hidnplayr 46
        ; TODO: implement timeout
3545 hidnplayr 47
        call    wait_for_data
48
 
5663 hidnplayr 49
        cmp     dword[receive_buffer], "RFB "
3545 hidnplayr 50
        jne     no_rfb
5663 hidnplayr 51
        DEBUGF  1, "received: %s\n", receive_buffer
3545 hidnplayr 52
        mcall   send, [socketnum], handshake, 12, 0
5663 hidnplayr 53
        DEBUGF  1, "Sending handshake: protocol version\n"
3545 hidnplayr 54
 
55
        call    wait_for_data
56
 
5663 hidnplayr 57
        cmp     dword[receive_buffer], 0x00000000
3545 hidnplayr 58
        je      invalid_security
59
 
5663 hidnplayr 60
        cmp     dword[receive_buffer], 0x01000000
3545 hidnplayr 61
        je      no_security
62
 
5663 hidnplayr 63
        cmp     dword[receive_buffer], 0x02000000
3545 hidnplayr 64
        je      vnc_security
65
 
5663 hidnplayr 66
        DEBUGF  1, "Unknown security type\n"
3545 hidnplayr 67
        jmp     exit
68
 
69
vnc_security:
70
        mov     byte[mode], 1
5663 hidnplayr 71
        call    logon
3545 hidnplayr 72
 
73
no_security:
5663 hidnplayr 74
        mcall   send, [socketnum], ClientInit, 1, 0
75
        DEBUGF  1, "ClientInit sent\n"
3545 hidnplayr 76
 
77
        call    wait_for_data       ; now the server should send init message
78
 
5663 hidnplayr 79
        DEBUGF  1, "Serverinit: bpp: %u depth: %u bigendian: %u truecolor: %u\n", \
80
        [receive_buffer+framebuffer.pixelformat.bpp]:1, \
81
        [receive_buffer+framebuffer.pixelformat.depth]:1, \
82
        [receive_buffer+framebuffer.pixelformat.big_endian]:1, \
83
        [receive_buffer+framebuffer.pixelformat.true_color]:1
3545 hidnplayr 84
 
5663 hidnplayr 85
        mov     eax, dword[receive_buffer+framebuffer.width]
86
        mov     dword[fbur.width], eax
3545 hidnplayr 87
        bswap   eax
5663 hidnplayr 88
        mov     dword[screen], eax
89
        DEBUGF  1, "Screen width=%u, height=%u\n", [screen.width]:2, [screen.height]:2
3545 hidnplayr 90
 
91
        mcall   send, [socketnum], pixel_format8, 20, 0
5663 hidnplayr 92
        DEBUGF  1, "Sending pixel format\n"
3545 hidnplayr 93
 
5666 hidnplayr 94
        mcall   send, [socketnum], encodings, 12, 0
5663 hidnplayr 95
        DEBUGF  1, "Sending encoding info\n"
3545 hidnplayr 96
 
5663 hidnplayr 97
        mov     [thread_ready], 1
3545 hidnplayr 98
 
5663 hidnplayr 99
; Request initial update
100
        mov     [fbur.inc], 0
101
 
102
request_fbu:
103
        DEBUGF  1, "Requesting framebuffer update\n"
3545 hidnplayr 104
        mcall   send, [socketnum], fbur, 10, 0
5663 hidnplayr 105
        mov     [fbur.inc], 1
3545 hidnplayr 106
 
107
thread_loop:
108
        call    read_data              ; Read the data into the buffer
109
 
5663 hidnplayr 110
        lodsb
111
        cmp     al, 0
3545 hidnplayr 112
        je      framebufferupdate
5663 hidnplayr 113
        cmp     al, 1
3545 hidnplayr 114
        je      setcolourmapentries
5663 hidnplayr 115
        cmp     al, 2
3545 hidnplayr 116
        je      bell
5663 hidnplayr 117
        cmp     al, 3
3545 hidnplayr 118
        je      servercuttext
119
 
5663 hidnplayr 120
 
121
        DEBUGF  1, "Unknown server command: %u\n", al
3545 hidnplayr 122
        jmp     thread_loop
123
 
124
framebufferupdate:
125
 
5663 hidnplayr 126
  @@:
127
        lea     eax, [esi+6]
128
        cmp     [datapointer], eax
129
        jae     @f
130
        call    read_data.more
131
        jmp     @b
132
  @@:
133
 
134
        inc     esi     ; padding
135
        lodsw
3545 hidnplayr 136
        xchg    al, ah
5663 hidnplayr 137
        mov     [rectangles], ax
138
        DEBUGF  1, "Framebufferupdate: %u rectangles\n", ax
3545 hidnplayr 139
 
5663 hidnplayr 140
rectangle_loop:
3545 hidnplayr 141
 
5663 hidnplayr 142
  @@:
143
        lea     eax, [esi+12]
144
        cmp     [datapointer], eax
145
        jae     @f
146
        call    read_data.more
147
        jmp     @b
148
  @@:
3545 hidnplayr 149
 
5663 hidnplayr 150
        lodsd                           ; position
151
        bswap   eax
152
        mov     [rectangle.y], ax
153
        shr     eax, 16
154
        mov     [rectangle.x], ax
3545 hidnplayr 155
 
5663 hidnplayr 156
        lodsd                           ; size
157
        bswap   eax
158
        mov     [rectangle.height], ax
159
        shr     eax, 16
160
        mov     [rectangle.width], ax
3545 hidnplayr 161
 
5663 hidnplayr 162
        lodsd                           ; encoding
163
        DEBUGF  1, "rectangle: width=%u height=%u x=%u y=%u encoding: ",\
164
        [rectangle.width]:2, [rectangle.height]:2, [rectangle.x]:2, [rectangle.y]:2
3545 hidnplayr 165
 
166
        cmp     eax, 0
167
        je      encoding_raw
5666 hidnplayr 168
        cmp     eax, 1
169
        je      encoding_copyrect
5663 hidnplayr 170
;        cmp     eax, 2
171
;        je      encoding_RRE
172
;        cmp     eax, 5
173
;        je      encoding_hextile
174
;        cmp     eax, 15
175
;        je      encoding_TRLE
176
;        cmp     eax, 16
177
;        je      encoding_ZRLE
3545 hidnplayr 178
 
5663 hidnplayr 179
        DEBUGF  1, "\nunknown encoding: %u\n", eax
3545 hidnplayr 180
        jmp     thread_loop
181
 
5663 hidnplayr 182
;;        jmp     rectangle_loop
3545 hidnplayr 183
 
5663 hidnplayr 184
next_rectangle:
185
        push    esi
186
        call    drawbuffer
187
        pop     esi
3545 hidnplayr 188
 
5663 hidnplayr 189
        dec     [rectangles]
190
        jnz     rectangle_loop
191
        jmp     request_fbu
3545 hidnplayr 192
 
193
 
5663 hidnplayr 194
setcolourmapentries:
3545 hidnplayr 195
 
5663 hidnplayr 196
        DEBUGF  1, "Server sent SetColourMapEntries message\n"
3545 hidnplayr 197
 
5663 hidnplayr 198
        ; TODO
3545 hidnplayr 199
 
200
        jmp     thread_loop
201
 
202
 
203
bell:
204
        mcall   55, 55, , , beep
205
        jmp     thread_loop
206
 
207
 
208
servercuttext:
209
 
5663 hidnplayr 210
        DEBUGF  1, "Server cut text\n"
3545 hidnplayr 211
 
5663 hidnplayr 212
  @@:
213
        lea     eax, [esi+7]
214
        cmp     [datapointer], eax
215
        jae     @f
216
        call    read_data.more
217
        jmp     @b
218
  @@:
219
 
220
        add     esi, 3
221
        lodsd
222
        bswap   eax
223
        mov     ecx, eax
224
 
225
  @@:
226
        lea     eax, [esi+ecx]
227
        cmp     [datapointer], eax
228
        jae     @f
229
        call    read_data.more
230
        jmp     @b
231
  @@:
232
 
233
        ; TODO: paste text to clipboard
234
 
235
        DEBUGF  1, "%u bytes of text\n", ecx
236
        add     esi, ecx
3545 hidnplayr 237
        jmp     thread_loop
238
 
239
 
240
read_data:
241
        mov     [datapointer], receive_buffer
5663 hidnplayr 242
        mov     esi, receive_buffer
243
  .more:
244
        push    ebx ecx edx esi edi
3545 hidnplayr 245
        mcall   recv, [socketnum], [datapointer], 4096, 0
5663 hidnplayr 246
        pop     edi esi edx ecx ebx
3545 hidnplayr 247
        cmp     eax, -1
5663 hidnplayr 248
        je      .error
249
        add     [datapointer], eax      ; TODO: check for buffer overflow
3545 hidnplayr 250
        cmp     eax, 4096
5663 hidnplayr 251
        je      .more
252
        ret
3545 hidnplayr 253
 
5663 hidnplayr 254
  .error:
255
        DEBUGF  1, "Socket error!\n"
256
        mcall   -1
3545 hidnplayr 257
        ret
258
 
259
 
260
 
5663 hidnplayr 261
wait_for_data:  ; FIXME: add timeout
3545 hidnplayr 262
        mcall   recv, [socketnum], receive_buffer, 4096, 0
263
        cmp     eax, -1
5663 hidnplayr 264
        je      .error
3545 hidnplayr 265
        test    eax, eax
266
        jz      wait_for_data
267
 
268
        ret
269
 
5663 hidnplayr 270
  .error:
271
        DEBUGF  1, "Socket error!\n"
272
        mcall   -1
273
        ret
274