Subversion Repositories Kolibri OS

Rev

Rev 5663 | Blame | Last modification | View Log | Download | RSS feed

  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. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14.  
  15. thread_start:
  16.  
  17.         DEBUGF  1, "I am the thread!\n"
  18.  
  19.         mcall   40, 0                   ; disable all events
  20.  
  21. ; resolve name
  22.         push    esp     ; reserve stack place
  23.         invoke  getaddrinfo, serveraddr, 0, 0, esp
  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.  
  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
  37.  
  38.         mcall   socket, AF_INET4, SOCK_STREAM, 0
  39.         test    eax, eax
  40.         jz      exit
  41. ;;;        invoke  freeaddrinfo, ??
  42.         mov     [socketnum], eax
  43.         mcall   connect, [socketnum], sockaddr1, 18
  44. ;;;        test    eax, eax
  45.  
  46.         ; TODO: implement timeout
  47.         call    wait_for_data
  48.  
  49.         cmp     dword[receive_buffer], "RFB "
  50.         jne     no_rfb
  51.         DEBUGF  1, "received: %s\n", receive_buffer
  52.         mcall   send, [socketnum], handshake, 12, 0
  53.         DEBUGF  1, "Sending handshake: protocol version\n"
  54.  
  55.         call    wait_for_data
  56.  
  57.         cmp     dword[receive_buffer], 0x00000000
  58.         je      invalid_security
  59.  
  60.         cmp     dword[receive_buffer], 0x01000000
  61.         je      no_security
  62.  
  63.         cmp     dword[receive_buffer], 0x02000000
  64.         je      vnc_security
  65.  
  66.         DEBUGF  1, "Unknown security type\n"
  67.         jmp     exit
  68.  
  69. vnc_security:
  70.         mov     byte[mode], 1
  71.         call    logon
  72.  
  73. no_security:
  74.         mcall   send, [socketnum], ClientInit, 1, 0
  75.         DEBUGF  1, "ClientInit sent\n"
  76.  
  77.         call    wait_for_data       ; now the server should send init message
  78.  
  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
  84.  
  85.         mov     eax, dword[receive_buffer+framebuffer.width]
  86.         mov     dword[fbur.width], eax
  87.         bswap   eax
  88.         mov     dword[screen], eax
  89.         DEBUGF  1, "Screen width=%u, height=%u\n", [screen.width]:2, [screen.height]:2
  90.  
  91.         mcall   send, [socketnum], pixel_format8, 20, 0
  92.         DEBUGF  1, "Sending pixel format\n"
  93.  
  94.         mcall   send, [socketnum], encodings, 12, 0
  95.         DEBUGF  1, "Sending encoding info\n"
  96.  
  97.         mov     [thread_ready], 1
  98.  
  99. ; Request initial update
  100.         mov     [fbur.inc], 0
  101.  
  102. request_fbu:
  103.         DEBUGF  1, "Requesting framebuffer update\n"
  104.         mcall   send, [socketnum], fbur, 10, 0
  105.         mov     [fbur.inc], 1
  106.  
  107. thread_loop:
  108.         call    read_data              ; Read the data into the buffer
  109.  
  110.         lodsb
  111.         cmp     al, 0
  112.         je      framebufferupdate
  113.         cmp     al, 1
  114.         je      setcolourmapentries
  115.         cmp     al, 2
  116.         je      bell
  117.         cmp     al, 3
  118.         je      servercuttext
  119.  
  120.  
  121.         DEBUGF  1, "Unknown server command: %u\n", al
  122.         jmp     thread_loop
  123.  
  124. framebufferupdate:
  125.  
  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
  136.         xchg    al, ah
  137.         mov     [rectangles], ax
  138.         DEBUGF  1, "Framebufferupdate: %u rectangles\n", ax
  139.  
  140. rectangle_loop:
  141.  
  142.   @@:
  143.         lea     eax, [esi+12]
  144.         cmp     [datapointer], eax
  145.         jae     @f
  146.         call    read_data.more
  147.         jmp     @b
  148.   @@:
  149.  
  150.         lodsd                           ; position
  151.         bswap   eax
  152.         mov     [rectangle.y], ax
  153.         shr     eax, 16
  154.         mov     [rectangle.x], ax
  155.  
  156.         lodsd                           ; size
  157.         bswap   eax
  158.         mov     [rectangle.height], ax
  159.         shr     eax, 16
  160.         mov     [rectangle.width], ax
  161.  
  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
  165.  
  166.         cmp     eax, 0
  167.         je      encoding_raw
  168.         cmp     eax, 1
  169.         je      encoding_copyrect
  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
  178.  
  179.         DEBUGF  1, "\nunknown encoding: %u\n", eax
  180.         jmp     thread_loop
  181.  
  182. ;;        jmp     rectangle_loop
  183.  
  184. next_rectangle:
  185.         push    esi
  186.         call    drawbuffer
  187.         pop     esi
  188.  
  189.         dec     [rectangles]
  190.         jnz     rectangle_loop
  191.         jmp     request_fbu
  192.  
  193.  
  194. setcolourmapentries:
  195.  
  196.         DEBUGF  1, "Server sent SetColourMapEntries message\n"
  197.  
  198.         ; TODO
  199.  
  200.         jmp     thread_loop
  201.  
  202.  
  203. bell:
  204.         mcall   55, 55, , , beep
  205.         jmp     thread_loop
  206.  
  207.  
  208. servercuttext:
  209.  
  210.         DEBUGF  1, "Server cut text\n"
  211.  
  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
  237.         jmp     thread_loop
  238.  
  239.  
  240. read_data:
  241.         mov     [datapointer], receive_buffer
  242.         mov     esi, receive_buffer
  243.   .more:
  244.         push    ebx ecx edx esi edi
  245.         mcall   recv, [socketnum], [datapointer], 4096, 0
  246.         pop     edi esi edx ecx ebx
  247.         cmp     eax, -1
  248.         je      .error
  249.         add     [datapointer], eax      ; TODO: check for buffer overflow
  250.         cmp     eax, 4096
  251.         je      .more
  252.         ret
  253.  
  254.   .error:
  255.         DEBUGF  1, "Socket error!\n"
  256.         mcall   -1
  257.         ret
  258.  
  259.  
  260.  
  261. wait_for_data:  ; FIXME: add timeout
  262.         mcall   recv, [socketnum], receive_buffer, 4096, 0
  263.         cmp     eax, -1
  264.         je      .error
  265.         test    eax, eax
  266.         jz      wait_for_data
  267.  
  268.         ret
  269.  
  270.   .error:
  271.         DEBUGF  1, "Socket error!\n"
  272.         mcall   -1
  273.         ret
  274.  
  275.