Subversion Repositories Kolibri OS

Rev

Rev 5011 | Rev 6437 | 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
 
4922 ashmew2 8
        cmp     dword[buf_cmd], "150 "
4920 hidnplayr 9
        je      data_loop
3701 hidnplayr 10
 
4922 ashmew2 11
        cmp     dword[buf_cmd], "220 "
3701 hidnplayr 12
        je      welcome
13
 
4922 ashmew2 14
;        cmp     dword[buf_cmd], "226 "
3967 hidnplayr 15
;        je      transfer_ok
3789 hidnplayr 16
 
4922 ashmew2 17
        cmp     dword[buf_cmd], "227 "
3701 hidnplayr 18
        je      pasv_ok
19
 
4922 ashmew2 20
        cmp     dword[buf_cmd], "230 "
3701 hidnplayr 21
        je      login_ok
22
 
4922 ashmew2 23
;        cmp     dword[buf_cmd], "250"
3800 hidnplayr 24
;        je      op_ok
3790 hidnplayr 25
 
4922 ashmew2 26
        cmp     dword[buf_cmd], "331 "
3701 hidnplayr 27
        je      pass
28
 
4922 ashmew2 29
;        cmp     dword[buf_cmd], "421 "
3789 hidnplayr 30
;        je      timeout
3701 hidnplayr 31
 
4922 ashmew2 32
        cmp     dword[buf_cmd], "503 "         ; login first
3818 hidnplayr 33
        je      welcome
34
 
4922 ashmew2 35
        cmp     dword[buf_cmd], "530 "         ; password incorrect
6394 nisargshah 36
        mov     [use_params], 0
3789 hidnplayr 37
        je      welcome
3701 hidnplayr 38
 
4922 ashmew2 39
        cmp     dword[buf_cmd], "550 "
3800 hidnplayr 40
        je      close_datacon
41
 
4922 ashmew2 42
        cmp     byte[buf_cmd+3], "-"
4729 hidnplayr 43
        je      wait_for_servercommand
3789 hidnplayr 44
        jmp     wait_for_usercommand
45
 
46
 
3701 hidnplayr 47
welcome:
48
 
49
        mov     [status], STATUS_CONNECTED
3789 hidnplayr 50
        jmp     wait_for_usercommand
3701 hidnplayr 51
 
52
 
53
pass:
54
 
55
        mov     [status], STATUS_NEEDPASSWORD
3789 hidnplayr 56
        jmp     wait_for_usercommand
3701 hidnplayr 57
 
58
 
59
login_ok:
60
 
61
        mov     [status], STATUS_LOGGED_IN
6394 nisargshah 62
        cmp     [use_params], 0
63
        je      wait_for_usercommand
3701 hidnplayr 64
 
6394 nisargshah 65
        cmp     [param_path+4], 0
66
        je      wait_for_usercommand
67
        ; copy path to buf_cmd and execute CWD
68
        mov     edi, buf_cmd
69
        mov     esi, param_path
70
  @@:
71
        lodsb
72
        stosb
73
        cmp     byte[esi-1], 0
74
        jne     @b
75
        jmp     cmd_cwd
3701 hidnplayr 76
 
77
pasv_ok:
78
 
3818 hidnplayr 79
        sub     ecx, 4
3701 hidnplayr 80
        jb      .fail
81
        mov     al, "("
4922 ashmew2 82
        mov     edi, buf_cmd + 4
3701 hidnplayr 83
        repne   scasb
84
 
85
        mcall   socket, AF_INET4, SOCK_STREAM, 0
86
        cmp     eax, -1
3813 hidnplayr 87
        je      error_socket
3701 hidnplayr 88
        mov     [datasocket], eax
89
 
90
        mov     esi, edi
91
        call    ascii_dec
92
        mov     byte[sockaddr2.ip+0], bl
93
        call    ascii_dec
94
        mov     byte[sockaddr2.ip+1], bl
95
        call    ascii_dec
96
        mov     byte[sockaddr2.ip+2], bl
97
        call    ascii_dec
98
        mov     byte[sockaddr2.ip+3], bl
99
 
100
        call    ascii_dec
3789 hidnplayr 101
        mov     byte[sockaddr2.port+0], bl
102
        call    ascii_dec
3701 hidnplayr 103
        mov     byte[sockaddr2.port+1], bl
104
 
3789 hidnplayr 105
        invoke  con_write_asciiz, str_open
3701 hidnplayr 106
        mcall   connect, [datasocket], sockaddr2, 18
5011 hidnplayr 107
        cmp     eax, -1
108
        je      error_socket
3818 hidnplayr 109
        jmp     wait_for_servercommand
3701 hidnplayr 110
 
111
  .fail:
3818 hidnplayr 112
        invoke  con_write_asciiz, str_unknown
3789 hidnplayr 113
        jmp     wait_for_servercommand
3701 hidnplayr 114
 
115
 
4920 hidnplayr 116
data_loop:
3701 hidnplayr 117
 
4922 ashmew2 118
        invoke  con_write_asciiz, str_dot
3967 hidnplayr 119
 
3800 hidnplayr 120
        cmp     [operation], OPERATION_STOR
121
        je      .stor
122
 
123
; we are receiving data
4922 ashmew2 124
        mcall   recv, [datasocket], buf_buffer2, BUFFERSIZE, 0
3792 hidnplayr 125
        test    ebx, ebx
3800 hidnplayr 126
        jnz     .done
4922 ashmew2 127
        mov     byte[buf_buffer2 + eax], 0
3701 hidnplayr 128
 
3800 hidnplayr 129
        cmp     [operation], OPERATION_RETR
130
        je      .retr
131
 
5011 hidnplayr 132
        cmp     [operation], OPERATION_RDIR
133
        je      .rdir
134
 
3800 hidnplayr 135
; not retreiving, just print to console
4922 ashmew2 136
        invoke  con_write_asciiz, buf_buffer2
4920 hidnplayr 137
        jmp     data_loop
3789 hidnplayr 138
 
3800 hidnplayr 139
; retreiving, save to file
140
  .retr:
4922 ashmew2 141
        mov     [filestruct.ptr], buf_buffer2
3800 hidnplayr 142
        mov     [filestruct.size], eax
143
        push    eax
144
        mcall   70, filestruct
145
        pop     eax
146
        add     [filestruct.offset], eax
4920 hidnplayr 147
        jmp     data_loop
3792 hidnplayr 148
 
3800 hidnplayr 149
; storing, send all data
150
  .stor:
151
        mcall   70, filestruct
152
        cmp     eax, 6          ; end of file
153
        je      .last_call
154
        test    eax, eax        ; error
155
;        jne     .fileerror
156
        add     [filestruct.offset], ebx
157
        mov     esi, ebx
4922 ashmew2 158
        mcall   send, [datasocket], buf_buffer2, , 0
3800 hidnplayr 159
        jmp     .stor
160
 
161
  .last_call:
162
        mov     esi, ebx
4922 ashmew2 163
        mcall   send, [datasocket], buf_buffer2, , 0
3800 hidnplayr 164
 
165
  .done:
3967 hidnplayr 166
        invoke  con_write_asciiz, str_close
3789 hidnplayr 167
        mcall   close, [datasocket]
4920 hidnplayr 168
        mov     [operation], OPERATION_NONE
3789 hidnplayr 169
        jmp     wait_for_servercommand
3701 hidnplayr 170
 
4922 ashmew2 171
  .rdir:
5011 hidnplayr 172
        ; alloc/realloc memory block to store filenames
173
        mov     ecx, eax                        ; eax is size of buffer received
174
        inc     ecx
175
        add     ecx, [size_fname]               ; added old size to form new required size
176
        mcall   68, 20, , [ptr_fname]           ; realloc
177
        test    eax, eax
178
        je      error_heap
179
        mov     [ptr_fname], eax                ; eax contains the new block now
180
        mov     [ptr_queue], eax
4922 ashmew2 181
 
5011 hidnplayr 182
        ; copy filenames into fname buffer
183
        mov     esi, buf_buffer2
184
        mov     edi, eax
185
        add     edi, [size_fname]
4922 ashmew2 186
  .copy_buf:
5011 hidnplayr 187
        lodsb
188
        cmp     al, 13                          ; ignore any carriage return character
189
        je      .copy_buf
190
        stosb
191
        cmp     al, 10                          ; linefeed marks end of filename
192
        je      @f
193
        inc     [queued]
194
  @@:
195
        test    al, al                          ; 0 marks end of buffer
196
        jne     .copy_buf
4922 ashmew2 197
 
5011 hidnplayr 198
        ; All received filenames have been copied, calculate new size of fname buffer
199
        dec     edi                             ; dont count the trailing 0 byte
200
        sub     edi, [ptr_fname]
201
        mov     [size_fname], edi
202
        jmp     data_loop
4922 ashmew2 203
 
204
 
3800 hidnplayr 205
close_datacon:
4920 hidnplayr 206
        cmp     [operation], OPERATION_NONE
207
        je      wait_for_usercommand
3967 hidnplayr 208
        invoke  con_write_asciiz, str_close
3800 hidnplayr 209
        mcall   close, [datasocket]
210
        jmp     wait_for_usercommand
211
 
212
 
3701 hidnplayr 213
ascii_dec:
214
 
215
        xor     ebx, ebx
3789 hidnplayr 216
        mov     cl, 4                   ; max length is 3 digits + 1 separator
3701 hidnplayr 217
  .loop:
218
        lodsb
219
        sub     al, '0'
220
        jb      .done
221
        cmp     al, 9
222
        ja      .done
3789 hidnplayr 223
        lea     ebx, [ebx*4+ebx]        ; ebx *5
224
        shl     ebx, 1                  ; ebx *2
3701 hidnplayr 225
        add     bl, al
226
        dec     cl
227
        jnz     .loop
228
 
229
  .done:
230
        ret