Subversion Repositories Kolibri OS

Rev

Rev 3813 | Rev 3967 | 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], "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.         cmp     [operation], OPERATION_STOR
  104.         je      .stor
  105.  
  106. ; we are receiving data
  107.         mcall   recv, [datasocket], buffer_ptr2, BUFFERSIZE, 0
  108.         test    ebx, ebx
  109.         jnz     .done
  110.         mov     byte[buffer_ptr2 + eax], 0
  111.  
  112.         cmp     [operation], OPERATION_RETR
  113.         je      .retr
  114.  
  115. ; not retreiving, just print to console
  116.         invoke  con_write_asciiz, buffer_ptr2
  117.         jmp     data_ok
  118.  
  119. ; retreiving, save to file
  120.   .retr:
  121.         mov     [filestruct.ptr], buffer_ptr2
  122.         mov     [filestruct.size], eax
  123.         push    eax
  124.         mcall   70, filestruct
  125.         pop     eax
  126.         add     [filestruct.offset], eax
  127.         jmp     data_ok
  128.  
  129. ; storing, send all data
  130.   .stor:
  131.         mcall   70, filestruct
  132.         cmp     eax, 6          ; end of file
  133.         je      .last_call
  134.         test    eax, eax        ; error
  135. ;        jne     .fileerror
  136.         add     [filestruct.offset], ebx
  137.         mov     esi, ebx
  138.         mcall   send, [datasocket], buffer_ptr2, , 0
  139.         jmp     .stor
  140.  
  141.   .last_call:
  142.         mov     esi, ebx
  143.         mcall   send, [datasocket], buffer_ptr2, , 0
  144.  
  145.   .done:
  146.         mcall   close, [datasocket]
  147.         jmp     wait_for_servercommand
  148.  
  149.  
  150.  
  151. close_datacon:
  152.         mcall   close, [datasocket]
  153.         jmp     wait_for_usercommand
  154.  
  155.  
  156.  
  157. ascii_dec:
  158.  
  159.         xor     ebx, ebx
  160.         mov     cl, 4                   ; max length is 3 digits + 1 separator
  161.   .loop:
  162.         lodsb
  163.         sub     al, '0'
  164.         jb      .done
  165.         cmp     al, 9
  166.         ja      .done
  167.         lea     ebx, [ebx*4+ebx]        ; ebx *5
  168.         shl     ebx, 1                  ; ebx *2
  169.         add     bl, al
  170.         dec     cl
  171.         jnz     .loop
  172.  
  173.   .done:
  174.         ret