Subversion Repositories Kolibri OS

Rev

Rev 3800 | Rev 3818 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. server_parser:
  2.  
  3. ; Commands are always 3 numbers and followed by a space
  4. ; If a server decides it needs multiline output,
  5. ; first lines will have a dash instead of space after numbers,
  6. ; thus they are simply ignored in this simple command parser.
  7.  
  8.         cmp     dword[s], "150 "
  9.         je      data_ok
  10.  
  11.         cmp     dword[s], "220 "
  12.         je      welcome
  13.  
  14. ;        cmp     dword[s], "226 "
  15. ;        je      list_ok
  16.  
  17.         cmp     dword[s], "227 "
  18.         je      pasv_ok
  19.  
  20.         cmp     dword[s], "230 "
  21.         je      login_ok
  22.  
  23. ;        cmp     dword[s], "250"
  24. ;        je      op_ok
  25.  
  26.         cmp     dword[s], "331 "
  27.         je      pass
  28.  
  29. ;        cmp     dword[s], "421 "
  30. ;        je      timeout
  31.  
  32.         cmp     dword[s], "530 "         ; password incorrect
  33.         je      welcome
  34.  
  35.         cmp     dword[s], "550 "
  36.         je      close_datacon
  37.  
  38.         jmp     wait_for_usercommand
  39.  
  40.  
  41. welcome:
  42.  
  43.         mov     [status], STATUS_CONNECTED
  44.         jmp     wait_for_usercommand
  45.  
  46.  
  47. pass:
  48.  
  49.         mov     [status], STATUS_NEEDPASSWORD
  50.         jmp     wait_for_usercommand
  51.  
  52.  
  53. login_ok:
  54.  
  55.         mov     [status], STATUS_LOGGED_IN
  56.         jmp     wait_for_usercommand
  57.  
  58.  
  59. pasv_ok:
  60.  
  61.         sub     ecx, 5
  62.         jb      .fail
  63.         mov     al, "("
  64.         mov     edi, s + 5
  65.         repne   scasb
  66.  
  67.         mcall   socket, AF_INET4, SOCK_STREAM, 0
  68.         cmp     eax, -1
  69.         je      error_socket
  70.         mov     [datasocket], eax
  71.  
  72.         mov     esi, edi
  73.         call    ascii_dec
  74.         mov     byte[sockaddr2.ip+0], bl
  75.         call    ascii_dec
  76.         mov     byte[sockaddr2.ip+1], bl
  77.         call    ascii_dec
  78.         mov     byte[sockaddr2.ip+2], bl
  79.         call    ascii_dec
  80.         mov     byte[sockaddr2.ip+3], bl
  81.  
  82.         call    ascii_dec
  83.         mov     byte[sockaddr2.port+0], bl
  84.         call    ascii_dec
  85.         mov     byte[sockaddr2.port+1], bl
  86.  
  87.         invoke  con_write_asciiz, str_open
  88.         mcall   connect, [datasocket], sockaddr2, 18
  89.  
  90.   .fail:
  91.         jmp     wait_for_servercommand
  92.  
  93.  
  94. data_ok:
  95.  
  96.         cmp     [operation], OPERATION_STOR
  97.         je      .stor
  98.  
  99. ; we are receiving data
  100.         mcall   recv, [datasocket], buffer_ptr2, BUFFERSIZE, 0
  101.         test    ebx, ebx
  102.         jnz     .done
  103.         mov     byte[buffer_ptr2 + eax], 0
  104.  
  105.         cmp     [operation], OPERATION_RETR
  106.         je      .retr
  107.  
  108. ; not retreiving, just print to console
  109.         invoke  con_write_asciiz, buffer_ptr2
  110.         jmp     data_ok
  111.  
  112. ; retreiving, save to file
  113.   .retr:
  114.         mov     [filestruct.ptr], buffer_ptr2
  115.         mov     [filestruct.size], eax
  116.         push    eax
  117.         mcall   70, filestruct
  118.         pop     eax
  119.         add     [filestruct.offset], eax
  120.         jmp     data_ok
  121.  
  122. ; storing, send all data
  123.   .stor:
  124.         mcall   70, filestruct
  125.         cmp     eax, 6          ; end of file
  126.         je      .last_call
  127.         test    eax, eax        ; error
  128. ;        jne     .fileerror
  129.         add     [filestruct.offset], ebx
  130.         mov     esi, ebx
  131.         mcall   send, [datasocket], buffer_ptr2, , 0
  132.         jmp     .stor
  133.  
  134.   .last_call:
  135.         mov     esi, ebx
  136.         mcall   send, [datasocket], buffer_ptr2, , 0
  137.  
  138.   .done:
  139.         mcall   close, [datasocket]
  140.         jmp     wait_for_servercommand
  141.  
  142.  
  143.  
  144. close_datacon:
  145.         mcall   close, [datasocket]
  146.         jmp     wait_for_usercommand
  147.  
  148.  
  149.  
  150. ascii_dec:
  151.  
  152.         xor     ebx, ebx
  153.         mov     cl, 4                   ; max length is 3 digits + 1 separator
  154.   .loop:
  155.         lodsb
  156.         sub     al, '0'
  157.         jb      .done
  158.         cmp     al, 9
  159.         ja      .done
  160.         lea     ebx, [ebx*4+ebx]        ; ebx *5
  161.         shl     ebx, 1                  ; ebx *2
  162.         add     bl, al
  163.         dec     cl
  164.         jnz     .loop
  165.  
  166.   .done:
  167.         ret