Subversion Repositories Kolibri OS

Rev

Rev 3818 | Rev 4729 | 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      transfer_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], "503 "         ; login first
  33.         je      welcome
  34.  
  35.         cmp     dword[s], "530 "         ; password incorrect
  36.         je      welcome
  37.  
  38.         cmp     dword[s], "550 "
  39.         je      close_datacon
  40.  
  41.         jmp     wait_for_usercommand
  42.  
  43.  
  44. welcome:
  45.  
  46.         mov     [status], STATUS_CONNECTED
  47.         jmp     wait_for_usercommand
  48.  
  49.  
  50. pass:
  51.  
  52.         mov     [status], STATUS_NEEDPASSWORD
  53.         jmp     wait_for_usercommand
  54.  
  55.  
  56. login_ok:
  57.  
  58.         mov     [status], STATUS_LOGGED_IN
  59.         jmp     wait_for_usercommand
  60.  
  61.  
  62. pasv_ok:
  63.  
  64.         sub     ecx, 4
  65.         jb      .fail
  66.         mov     al, "("
  67.         mov     edi, s + 4
  68.         repne   scasb
  69.  
  70.         mcall   socket, AF_INET4, SOCK_STREAM, 0
  71.         cmp     eax, -1
  72.         je      error_socket
  73.         mov     [datasocket], eax
  74.  
  75.         mov     esi, edi
  76.         call    ascii_dec
  77.         mov     byte[sockaddr2.ip+0], bl
  78.         call    ascii_dec
  79.         mov     byte[sockaddr2.ip+1], bl
  80.         call    ascii_dec
  81.         mov     byte[sockaddr2.ip+2], bl
  82.         call    ascii_dec
  83.         mov     byte[sockaddr2.ip+3], bl
  84.  
  85.         call    ascii_dec
  86.         mov     byte[sockaddr2.port+0], bl
  87.         call    ascii_dec
  88.         mov     byte[sockaddr2.port+1], bl
  89.  
  90.         invoke  con_write_asciiz, str_open
  91.         mcall   connect, [datasocket], sockaddr2, 18
  92. ;        cmp     eax, -1
  93. ;        je      error_socket
  94.         jmp     wait_for_servercommand
  95.  
  96.   .fail:
  97.         invoke  con_write_asciiz, str_unknown
  98.         jmp     wait_for_servercommand
  99.  
  100.  
  101. data_ok:
  102.  
  103.         invoke  con_write_asciiz, str2b
  104.  
  105.         cmp     [operation], OPERATION_STOR
  106.         je      .stor
  107.  
  108. ; we are receiving data
  109.         mcall   recv, [datasocket], buffer_ptr2, BUFFERSIZE, 0
  110.         test    ebx, ebx
  111.         jnz     .done
  112.         mov     byte[buffer_ptr2 + eax], 0
  113.  
  114.         cmp     [operation], OPERATION_RETR
  115.         je      .retr
  116.  
  117. ; not retreiving, just print to console
  118.         invoke  con_write_asciiz, buffer_ptr2
  119.         jmp     data_ok
  120.  
  121. ; retreiving, save to file
  122.   .retr:
  123.         mov     [filestruct.ptr], buffer_ptr2
  124.         mov     [filestruct.size], eax
  125.         push    eax
  126.         mcall   70, filestruct
  127.         pop     eax
  128.         add     [filestruct.offset], eax
  129.         jmp     data_ok
  130.  
  131. ; storing, send all data
  132.   .stor:
  133.         mcall   70, filestruct
  134.         cmp     eax, 6          ; end of file
  135.         je      .last_call
  136.         test    eax, eax        ; error
  137. ;        jne     .fileerror
  138.         add     [filestruct.offset], ebx
  139.         mov     esi, ebx
  140.         mcall   send, [datasocket], buffer_ptr2, , 0
  141.         jmp     .stor
  142.  
  143.   .last_call:
  144.         mov     esi, ebx
  145.         mcall   send, [datasocket], buffer_ptr2, , 0
  146.  
  147.   .done:
  148.         invoke  con_write_asciiz, str_close
  149.         mcall   close, [datasocket]
  150.         jmp     wait_for_servercommand
  151.  
  152.  
  153.  
  154. close_datacon:
  155.         invoke  con_write_asciiz, str_close
  156.         mcall   close, [datasocket]
  157.         jmp     wait_for_usercommand
  158.  
  159.  
  160.  
  161. ascii_dec:
  162.  
  163.         xor     ebx, ebx
  164.         mov     cl, 4                   ; max length is 3 digits + 1 separator
  165.   .loop:
  166.         lodsb
  167.         sub     al, '0'
  168.         jb      .done
  169.         cmp     al, 9
  170.         ja      .done
  171.         lea     ebx, [ebx*4+ebx]        ; ebx *5
  172.         shl     ebx, 1                  ; ebx *2
  173.         add     bl, al
  174.         dec     cl
  175.         jnz     .loop
  176.  
  177.   .done:
  178.         ret