Subversion Repositories Kolibri OS

Rev

Rev 4920 | Rev 5011 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4920 Rev 4922
Line 3... Line 3...
3
; Commands are always 3 numbers and followed by a space
3
; Commands are always 3 numbers and followed by a space
4
; If a server decides it needs multiline output,
4
; If a server decides it needs multiline output,
5
; first lines will have a dash instead of space after numbers,
5
; first lines will have a dash instead of space after numbers,
6
; thus they are simply ignored in this simple command parser.
6
; thus they are simply ignored in this simple command parser.
Line 7... Line 7...
7
 
7
 
8
        cmp     dword[s], "150 "
8
        cmp     dword[buf_cmd], "150 "
Line 9... Line 9...
9
        je      data_loop
9
        je      data_loop
10
 
10
 
Line 11... Line 11...
11
        cmp     dword[s], "220 "
11
        cmp     dword[buf_cmd], "220 "
12
        je      welcome
12
        je      welcome
Line 13... Line 13...
13
 
13
 
14
;        cmp     dword[s], "226 "
14
;        cmp     dword[buf_cmd], "226 "
Line 15... Line 15...
15
;        je      transfer_ok
15
;        je      transfer_ok
16
 
16
 
Line 17... Line 17...
17
        cmp     dword[s], "227 "
17
        cmp     dword[buf_cmd], "227 "
18
        je      pasv_ok
18
        je      pasv_ok
Line 19... Line 19...
19
 
19
 
20
        cmp     dword[s], "230 "
20
        cmp     dword[buf_cmd], "230 "
Line 21... Line 21...
21
        je      login_ok
21
        je      login_ok
22
 
22
 
Line 23... Line 23...
23
;        cmp     dword[s], "250"
23
;        cmp     dword[buf_cmd], "250"
24
;        je      op_ok
24
;        je      op_ok
Line 25... Line 25...
25
 
25
 
26
        cmp     dword[s], "331 "
26
        cmp     dword[buf_cmd], "331 "
Line 27... Line 27...
27
        je      pass
27
        je      pass
28
 
28
 
Line 29... Line 29...
29
;        cmp     dword[s], "421 "
29
;        cmp     dword[buf_cmd], "421 "
30
;        je      timeout
30
;        je      timeout
31
 
31
 
Line 32... Line 32...
32
        cmp     dword[s], "503 "         ; login first
32
        cmp     dword[buf_cmd], "503 "         ; login first
Line 64... Line 64...
64
pasv_ok:
64
pasv_ok:
Line 65... Line 65...
65
 
65
 
66
        sub     ecx, 4
66
        sub     ecx, 4
67
        jb      .fail
67
        jb      .fail
68
        mov     al, "("
68
        mov     al, "("
69
        mov     edi, s + 4
69
        mov     edi, buf_cmd + 4
Line 70... Line 70...
70
        repne   scasb
70
        repne   scasb
71
 
71
 
72
        mcall   socket, AF_INET4, SOCK_STREAM, 0
72
        mcall   socket, AF_INET4, SOCK_STREAM, 0
Line 100... Line 100...
100
        jmp     wait_for_servercommand
100
        jmp     wait_for_servercommand
Line 101... Line 101...
101
 
101
 
Line 102... Line 102...
102
 
102
 
Line 103... Line 103...
103
data_loop:
103
data_loop:
104
 
104
 
Line 105... Line 105...
105
        invoke  con_write_asciiz, str2b
105
        invoke  con_write_asciiz, str_dot
106
 
106
 
107
        cmp     [operation], OPERATION_STOR
107
        cmp     [operation], OPERATION_STOR
108
        je      .stor
108
        je      .stor
109
 
109
 
Line 110... Line 110...
110
; we are receiving data
110
; we are receiving data
111
        mcall   recv, [datasocket], buffer_ptr2, BUFFERSIZE, 0
111
        mcall   recv, [datasocket], buf_buffer2, BUFFERSIZE, 0
Line -... Line 112...
-
 
112
        test    ebx, ebx
-
 
113
        jnz     .done
-
 
114
        mov     byte[buf_buffer2 + eax], 0
112
        test    ebx, ebx
115
 
113
        jnz     .done
116
        cmp     [operation], OPERATION_RETR
114
        mov     byte[buffer_ptr2 + eax], 0
117
        je      .retr
Line 115... Line 118...
115
 
118
 
116
        cmp     [operation], OPERATION_RETR
119
	    cmp 	[operation], OPERATION_RDIR
117
        je      .retr
120
	    je 	    .rdir
118
 
121
	
119
; not retreiving, just print to console
122
; not retreiving, just print to console
120
        invoke  con_write_asciiz, buffer_ptr2
123
        invoke  con_write_asciiz, buf_buffer2
121
        jmp     data_loop
124
        jmp     data_loop
122
 
125
 
Line 137... Line 140...
137
        je      .last_call
140
        je      .last_call
138
        test    eax, eax        ; error
141
        test    eax, eax        ; error
139
;        jne     .fileerror
142
;        jne     .fileerror
140
        add     [filestruct.offset], ebx
143
        add     [filestruct.offset], ebx
141
        mov     esi, ebx
144
        mov     esi, ebx
142
        mcall   send, [datasocket], buffer_ptr2, , 0
145
        mcall   send, [datasocket], buf_buffer2, , 0
143
        jmp     .stor
146
        jmp     .stor
Line 144... Line 147...
144
 
147
 
145
  .last_call:
148
  .last_call:
146
        mov     esi, ebx
149
        mov     esi, ebx
Line 147... Line 150...
147
        mcall   send, [datasocket], buffer_ptr2, , 0
150
        mcall   send, [datasocket], buf_buffer2, , 0
148
 
151
 
149
  .done:
152
  .done:
150
        invoke  con_write_asciiz, str_close
153
        invoke  con_write_asciiz, str_close
151
        mcall   close, [datasocket]
154
        mcall   close, [datasocket]
Line -... Line 155...
-
 
155
        mov     [operation], OPERATION_NONE
-
 
156
        jmp     wait_for_servercommand
-
 
157
 
-
 
158
 
-
 
159
  .rdir:
-
 
160
	cmp	[size_fname], 0
-
 
161
	jne	.realloc
-
 
162
 
-
 
163
  .malloc:					; create a new dynamic block
-
 
164
  	mov 	ecx, eax
-
 
165
	inc 	ecx	
-
 
166
 
-
 
167
	mcall	68,12	      			; eax now points to new buffer	
-
 
168
	
-
 
169
	test 	eax,eax
-
 
170
	je 	error_heap
-
 
171
 
-
 
172
	mov 	[ptr_fname_start], eax
-
 
173
 
-
 
174
	jmp 	.rdir_init
-
 
175
 
-
 
176
  .realloc:					; expand block created with .malloc
-
 
177
 
-
 
178
  	mov 	ecx, eax			; eax is size of buffer received
-
 
179
	inc	ecx
-
 
180
 
-
 
181
	add	ecx, [size_fname]		; added old size to form new required size
-
 
182
 
-
 
183
	mcall 	68,20,,[ptr_fname_start]
-
 
184
 
-
 
185
    	test	eax, eax
-
 
186
	je	error_heap
-
 
187
 
-
 
188
	mov	[ptr_fname_start], eax		; eax contains the new block now
-
 
189
	add	eax, [size_fname]
-
 
190
 
-
 
191
  .rdir_init:					; copies filenames into our buffer
-
 
192
 
-
 
193
	mov	esi, buf_buffer2
-
 
194
	mov	edi, eax
-
 
195
	
-
 
196
  .copy_buf:
-
 
197
  	lodsb
-
 
198
	cmp	al,13				; ignore any \r character
-
 
199
	je 	.copy_buf
-
 
200
	stosb
-
 
201
 
-
 
202
	cmp	al, 10
-
 
203
	jne 	.not_end
-
 
204
	inc 	[queued]
-
 
205
 
-
 
206
  .not_end:
-
 
207
	test	al,al
-
 
208
	jne 	.copy_buf
-
 
209
	
-
 
210
	dec 	edi
-
 
211
	dec 	edi
-
 
212
 
-
 
213
	mov	eax, [ptr_fname_start]
-
 
214
	mov 	[ptr_queue], eax
-
 
215
 
-
 
216
	sub 	edi, eax		; edi contains the current size now
-
 
217
	mov	[size_fname], edi	
-
 
218
 
-
 
219
	jmp	data_loop
-
 
220
	
-
 
221
 
-
 
222
; files for rdir operation are queued
-
 
223
transfer_queued:
-
 
224
 
-
 
225
	mov	esi, [ptr_queue]		; always pointing to current part of ptr_fname_start
-
 
226
	mov 	edi, buf_cmd+5	   		; always point to filename for retr command
-
 
227
 
-
 
228
  .build_filename:
-
 
229
	lodsb	
-
 
230
	stosb
-
 
231
 
-
 
232
	cmp 	al,10
-
 
233
	je 	.get_file			; filename ends with character 10
-
 
234
	test	al,al
-
 
235
	jz	.null_found			; this should be end of buffer
-
 
236
	jmp	.build_filename
-
 
237
 
-
 
238
  .null_found:					
-
 
239
 
-
 
240
	mov	[queued],0
-
 
241
	jmp 	.free
-
 
242
 
-
 
243
  .get_file:
-
 
244
	dec	[queued]
-
 
245
	jnz	.after_free	
-
 
246
	
-
 
247
  .free:
-
 
248
	mcall	68,13,[ptr_fname_start]		; freeing the buffer
-
 
249
	test	eax,eax
-
 
250
	jz 	error_heap
-
 
251
	jmp	wait_for_usercommand
-
 
252
 
-
 
253
  .after_free:
-
 
254
	xor	al,al				; appending 0 after retr command
-
 
255
	stosb
-
 
256
	mov	eax, esi
152
        mov     [operation], OPERATION_NONE
257
	mov	[ptr_queue], eax
153
        jmp     wait_for_servercommand
258
	
154
 
259
	jmp	cmd_retr
155
 
260
		
156
close_datacon:
261
close_datacon: