Subversion Repositories Kolibri OS

Rev

Rev 3818 | Rev 4729 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3701 hidnplayr 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,
3789 hidnplayr 6
; thus they are simply ignored in this simple command parser.
3701 hidnplayr 7
 
8
        cmp     dword[s], "150 "
9
        je      data_ok
10
 
11
        cmp     dword[s], "220 "
12
        je      welcome
13
 
3790 hidnplayr 14
;        cmp     dword[s], "226 "
3967 hidnplayr 15
;        je      transfer_ok
3789 hidnplayr 16
 
3701 hidnplayr 17
        cmp     dword[s], "227 "
18
        je      pasv_ok
19
 
20
        cmp     dword[s], "230 "
21
        je      login_ok
22
 
3790 hidnplayr 23
;        cmp     dword[s], "250"
3800 hidnplayr 24
;        je      op_ok
3790 hidnplayr 25
 
3701 hidnplayr 26
        cmp     dword[s], "331 "
27
        je      pass
28
 
3790 hidnplayr 29
;        cmp     dword[s], "421 "
3789 hidnplayr 30
;        je      timeout
3701 hidnplayr 31
 
3818 hidnplayr 32
        cmp     dword[s], "503 "         ; login first
33
        je      welcome
34
 
3800 hidnplayr 35
        cmp     dword[s], "530 "         ; password incorrect
3789 hidnplayr 36
        je      welcome
3701 hidnplayr 37
 
3800 hidnplayr 38
        cmp     dword[s], "550 "
39
        je      close_datacon
40
 
3789 hidnplayr 41
        jmp     wait_for_usercommand
42
 
43
 
3701 hidnplayr 44
welcome:
45
 
46
        mov     [status], STATUS_CONNECTED
3789 hidnplayr 47
        jmp     wait_for_usercommand
3701 hidnplayr 48
 
49
 
50
pass:
51
 
52
        mov     [status], STATUS_NEEDPASSWORD
3789 hidnplayr 53
        jmp     wait_for_usercommand
3701 hidnplayr 54
 
55
 
56
login_ok:
57
 
58
        mov     [status], STATUS_LOGGED_IN
3789 hidnplayr 59
        jmp     wait_for_usercommand
3701 hidnplayr 60
 
61
 
62
pasv_ok:
63
 
3818 hidnplayr 64
        sub     ecx, 4
3701 hidnplayr 65
        jb      .fail
66
        mov     al, "("
3818 hidnplayr 67
        mov     edi, s + 4
3701 hidnplayr 68
        repne   scasb
69
 
70
        mcall   socket, AF_INET4, SOCK_STREAM, 0
71
        cmp     eax, -1
3813 hidnplayr 72
        je      error_socket
3701 hidnplayr 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
3789 hidnplayr 86
        mov     byte[sockaddr2.port+0], bl
87
        call    ascii_dec
3701 hidnplayr 88
        mov     byte[sockaddr2.port+1], bl
89
 
3789 hidnplayr 90
        invoke  con_write_asciiz, str_open
3701 hidnplayr 91
        mcall   connect, [datasocket], sockaddr2, 18
3818 hidnplayr 92
;        cmp     eax, -1
93
;        je      error_socket
94
        jmp     wait_for_servercommand
3701 hidnplayr 95
 
96
  .fail:
3818 hidnplayr 97
        invoke  con_write_asciiz, str_unknown
3789 hidnplayr 98
        jmp     wait_for_servercommand
3701 hidnplayr 99
 
100
 
101
data_ok:
102
 
3967 hidnplayr 103
        invoke  con_write_asciiz, str2b
104
 
3800 hidnplayr 105
        cmp     [operation], OPERATION_STOR
106
        je      .stor
107
 
108
; we are receiving data
3792 hidnplayr 109
        mcall   recv, [datasocket], buffer_ptr2, BUFFERSIZE, 0
110
        test    ebx, ebx
3800 hidnplayr 111
        jnz     .done
3790 hidnplayr 112
        mov     byte[buffer_ptr2 + eax], 0
3701 hidnplayr 113
 
3800 hidnplayr 114
        cmp     [operation], OPERATION_RETR
115
        je      .retr
116
 
117
; not retreiving, just print to console
3790 hidnplayr 118
        invoke  con_write_asciiz, buffer_ptr2
3800 hidnplayr 119
        jmp     data_ok
3789 hidnplayr 120
 
3800 hidnplayr 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
3792 hidnplayr 129
        jmp     data_ok
130
 
3800 hidnplayr 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:
3967 hidnplayr 148
        invoke  con_write_asciiz, str_close
3789 hidnplayr 149
        mcall   close, [datasocket]
150
        jmp     wait_for_servercommand
3701 hidnplayr 151
 
152
 
3800 hidnplayr 153
 
154
close_datacon:
3967 hidnplayr 155
        invoke  con_write_asciiz, str_close
3800 hidnplayr 156
        mcall   close, [datasocket]
157
        jmp     wait_for_usercommand
158
 
159
 
160
 
3701 hidnplayr 161
ascii_dec:
162
 
163
        xor     ebx, ebx
3789 hidnplayr 164
        mov     cl, 4                   ; max length is 3 digits + 1 separator
3701 hidnplayr 165
  .loop:
166
        lodsb
167
        sub     al, '0'
168
        jb      .done
169
        cmp     al, 9
170
        ja      .done
3789 hidnplayr 171
        lea     ebx, [ebx*4+ebx]        ; ebx *5
172
        shl     ebx, 1                  ; ebx *2
3701 hidnplayr 173
        add     bl, al
174
        dec     cl
175
        jnz     .loop
176
 
177
  .done:
178
        ret