Rev 6582 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6582 | Rev 7487 | ||
---|---|---|---|
1 | server_parser: |
1 | server_parser: |
2 | 2 | ||
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. |
7 | 7 | ||
8 | cmp dword[buf_cmd+4], "Open" |
8 | cmp dword[buf_cmd+4], "Open" |
9 | je init_download_count |
9 | je init_download_count |
10 | 10 | ||
11 | cmp dword[buf_cmd], "150 " |
11 | cmp dword[buf_cmd], "150 " |
12 | je data_loop |
12 | je data_loop |
13 | 13 | ||
14 | cmp dword[buf_cmd], "220 " |
14 | cmp dword[buf_cmd], "220 " |
15 | je connect_ok |
15 | je connect_ok |
16 | 16 | ||
17 | ; cmp dword[buf_cmd], "226 " |
17 | ; cmp dword[buf_cmd], "226 " |
18 | ; je transfer_ok |
18 | ; je transfer_ok |
19 | 19 | ||
20 | cmp dword[buf_cmd], "227 " |
20 | cmp dword[buf_cmd], "227 " |
21 | je pasv_ok |
21 | je pasv_ok |
22 | 22 | ||
23 | cmp dword[buf_cmd], "230 " |
23 | cmp dword[buf_cmd], "230 " |
24 | je login_ok |
24 | je login_ok |
25 | 25 | ||
26 | ; cmp dword[buf_cmd], "250" |
26 | ; cmp dword[buf_cmd], "250" |
27 | ; je op_ok |
27 | ; je op_ok |
28 | 28 | ||
29 | cmp dword[buf_cmd], "331 " |
29 | cmp dword[buf_cmd], "331 " |
30 | je pass |
30 | je pass |
31 | 31 | ||
32 | ; cmp dword[buf_cmd], "421 " |
32 | ; cmp dword[buf_cmd], "421 " |
33 | ; je timeout |
33 | ; je timeout |
34 | 34 | ||
35 | cmp dword[buf_cmd], "503 " ; login first |
35 | cmp dword[buf_cmd], "503 " ; login first |
36 | je welcome |
36 | je welcome |
37 | 37 | ||
38 | cmp dword[buf_cmd], "530 " ; password incorrect |
38 | cmp dword[buf_cmd], "530 " ; password incorrect |
39 | je welcome |
39 | je welcome |
40 | 40 | ||
41 | cmp dword[buf_cmd], "550 " |
41 | cmp dword[buf_cmd], "550 " |
42 | je close_datacon |
42 | je close_datacon |
43 | 43 | ||
44 | cmp byte[buf_cmd+3], "-" |
44 | cmp byte[buf_cmd+3], "-" |
45 | je wait_for_servercommand |
45 | je wait_for_servercommand |
46 | jmp wait_for_usercommand |
46 | jmp wait_for_usercommand |
47 | 47 | ||
48 | 48 | ||
49 | welcome: |
49 | welcome: |
50 | 50 | ||
51 | mov [status], STATUS_CONNECTED |
51 | mov [status], STATUS_CONNECTED |
52 | jmp wait_for_usercommand |
52 | jmp wait_for_usercommand |
53 | 53 | ||
54 | 54 | ||
55 | connect_ok: |
55 | connect_ok: |
56 | 56 | ||
57 | mov [status], STATUS_CONNECTED |
57 | mov [status], STATUS_CONNECTED |
58 | jmp arg_handler.copy_user |
58 | jmp arg_handler.copy_user |
59 | 59 | ||
60 | pass: |
60 | pass: |
61 | 61 | ||
62 | mov [status], STATUS_NEEDPASSWORD |
62 | mov [status], STATUS_NEEDPASSWORD |
63 | jmp wait_for_usercommand |
63 | jmp wait_for_usercommand |
64 | 64 | ||
65 | 65 | ||
66 | login_ok: |
66 | login_ok: |
67 | 67 | ||
68 | mov [status], STATUS_LOGGED_IN |
68 | mov [status], STATUS_LOGGED_IN |
69 | 69 | ||
70 | cmp [param_path], 0x20 ; no path specified |
70 | cmp [param_path], 0x20 ; no path specified |
71 | jbe wait_for_usercommand |
71 | jbe wait_for_usercommand |
72 | 72 | ||
73 | ; copy path to buf_cmd and execute CWD |
73 | ; copy path to buf_cmd and execute CWD |
74 | jmp arg_handler.get_path |
74 | jmp arg_handler.get_path |
75 | 75 | ||
76 | 76 | ||
77 | pasv_ok: |
77 | pasv_ok: |
78 | 78 | ||
79 | sub ecx, 4 |
79 | sub ecx, 4 |
80 | jb .fail |
80 | jb .fail |
81 | mov al, "(" |
81 | mov al, "(" |
82 | mov edi, buf_cmd + 4 |
82 | mov edi, buf_cmd + 4 |
83 | repne scasb |
83 | repne scasb |
84 | 84 | ||
85 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
85 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
86 | cmp eax, -1 |
86 | cmp eax, -1 |
87 | jne @f |
87 | jne @f |
88 | mov eax, str_err_socket |
88 | mov eax, str_err_socket |
89 | jmp error |
89 | jmp error |
90 | @@: mov [datasocket], eax |
90 | @@: mov [datasocket], eax |
91 | 91 | ||
92 | mov esi, edi |
92 | mov esi, edi |
93 | call ascii_dec |
93 | call ascii_dec |
94 | mov byte[sockaddr2.ip+0], bl |
94 | mov byte[sockaddr2.ip+0], bl |
95 | call ascii_dec |
95 | call ascii_dec |
96 | mov byte[sockaddr2.ip+1], bl |
96 | mov byte[sockaddr2.ip+1], bl |
97 | call ascii_dec |
97 | call ascii_dec |
98 | mov byte[sockaddr2.ip+2], bl |
98 | mov byte[sockaddr2.ip+2], bl |
99 | call ascii_dec |
99 | call ascii_dec |
100 | mov byte[sockaddr2.ip+3], bl |
100 | mov byte[sockaddr2.ip+3], bl |
101 | 101 | ||
102 | call ascii_dec |
102 | call ascii_dec |
103 | mov byte[sockaddr2.port+0], bl |
103 | mov byte[sockaddr2.port+0], bl |
104 | call ascii_dec |
104 | call ascii_dec |
105 | mov byte[sockaddr2.port+1], bl |
105 | mov byte[sockaddr2.port+1], bl |
106 | 106 | ||
107 | icall eax, interface_addr, interface.print, str_open |
107 | icall eax, interface_addr, interface.print, str_open |
108 | mcall connect, [datasocket], sockaddr2, 18 |
108 | mcall connect, [datasocket], sockaddr2, 18 |
109 | cmp eax, -1 |
109 | cmp eax, -1 |
110 | jne @f |
110 | jne @f |
111 | mov eax, str_err_connect |
111 | mov eax, str_err_connect |
112 | jmp error |
112 | jmp error |
113 | @@: jmp wait_for_servercommand |
113 | @@: jmp wait_for_servercommand |
114 | 114 | ||
115 | .fail: |
115 | .fail: |
116 | icall eax, interface_addr, interface.print, str_unknown |
116 | icall eax, interface_addr, interface.print, str_unknown |
117 | jmp wait_for_servercommand |
117 | jmp wait_for_servercommand |
118 | 118 | ||
119 | 119 | ||
120 | ; get file size, initialize count for number of bytes downloaded |
120 | ; get file size, initialize count for number of bytes downloaded |
121 | init_download_count: |
121 | init_download_count: |
122 | 122 | ||
123 | mov edx, 0 |
123 | mov edx, 0 |
124 | ; search for 'Open' in buf_cmd |
124 | ; search for 'Open' in buf_cmd |
125 | lea esi, [buf_cmd+3] |
125 | lea esi, [buf_cmd+3] |
126 | @@: |
126 | @@: |
127 | inc esi |
127 | inc esi |
128 | cmp dword[esi], 'Open' |
128 | cmp dword[esi], 'Open' |
129 | je @f |
129 | je @f |
130 | cmp byte[esi], 0 |
130 | cmp byte[esi], 0 |
131 | jne @b |
131 | jne @b |
132 | jmp data_loop |
132 | jmp data_loop |
133 | 133 | ||
134 | @@: |
134 | @@: |
135 | ; get file size |
135 | ; get file size |
136 | mov al, '(' |
136 | mov al, '(' |
137 | mov ecx, -1 |
137 | mov ecx, -1 |
138 | mov edi, buf_cmd |
138 | mov edi, buf_cmd |
139 | repne scasb |
139 | repne scasb |
140 | xor eax, eax |
140 | xor eax, eax |
141 | mov ebx, 10 |
141 | mov ebx, 10 |
142 | xor ecx, ecx |
142 | xor ecx, ecx |
143 | mov esi, edi |
143 | mov esi, edi |
144 | @@: |
144 | @@: |
145 | push eax |
145 | push eax |
146 | lodsb |
146 | lodsb |
147 | sub al, '0' |
147 | sub al, '0' |
148 | mov cl, al |
148 | mov cl, al |
149 | pop eax |
149 | pop eax |
150 | mul ebx |
150 | mul ebx |
151 | add eax, ecx |
151 | add eax, ecx |
152 | cmp byte[esi], ' ' |
152 | cmp byte[esi], ' ' |
153 | jne @b |
153 | jne @b |
154 | mov [file_size], eax |
154 | mov [file_size], eax |
155 | 155 | ||
156 | data_loop: |
156 | data_loop: |
157 | 157 | ||
158 | cmp [operation], OPERATION_STOR |
158 | cmp [operation], OPERATION_STOR |
159 | je .stor |
159 | je .stor |
160 | 160 | ||
161 | push edx |
161 | push edx |
162 | ; we are receiving data |
162 | ; we are receiving data |
163 | mcall recv, [datasocket], buf_buffer2, BUFFERSIZE, 0 |
163 | mcall recv, [datasocket], buf_buffer2, BUFFERSIZE, 0 |
164 | pop edx ; get byte count |
164 | pop edx ; get byte count |
165 | add edx, eax |
165 | add edx, eax |
166 | test ebx, ebx |
166 | test ebx, ebx |
167 | jnz .done |
167 | jnz .done |
168 | mov byte[buf_buffer2 + eax], 0 |
168 | mov byte[buf_buffer2 + eax], 0 |
169 | 169 | ||
170 | cmp [operation], OPERATION_RETR |
170 | cmp [operation], OPERATION_RETR |
171 | je .retr |
171 | je .retr |
172 | 172 | ||
173 | cmp [operation], OPERATION_RDIR |
173 | cmp [operation], OPERATION_RDIR |
174 | je .rdir |
174 | je .rdir |
175 | 175 | ||
176 | cmp [operation], OPERATION_LIST |
176 | cmp [operation], OPERATION_LIST |
177 | je .list |
177 | je .list |
178 | 178 | ||
179 | ; not retreiving, just print to console |
179 | ; not retreiving, just print to console |
180 | icall eax, interface_addr, interface.print, buf_buffer2 |
180 | icall eax, interface_addr, interface.print, buf_buffer2 |
181 | jmp data_loop |
181 | jmp data_loop |
182 | 182 | ||
183 | ; for console, simply print. for gui, add name to tree list |
183 | ; for console, simply print. for gui, add name to tree list |
184 | .list: |
184 | .list: |
185 | ijmp ebx, interface_addr, interface.list |
185 | ijmp ebx, interface_addr, interface.list |
186 | 186 | ||
187 | 187 | ||
188 | ; retreiving, save to file |
188 | ; retreiving, save to file |
189 | .retr: |
189 | .retr: |
190 | mov [filestruct.ptr], buf_buffer2 |
190 | mov [filestruct.ptr], buf_buffer2 |
191 | mov [filestruct.size], eax |
191 | mov [filestruct.size], eax |
192 | push eax |
192 | push eax |
193 | mcall 70, filestruct |
193 | mcall 70, filestruct |
194 | test eax, eax |
194 | test eax, eax |
195 | jz @f |
195 | jz @f |
196 | call error_fs |
196 | call error_fs |
197 | jmp close_datacon |
197 | jmp close_datacon |
198 | @@: |
198 | @@: |
199 | pop eax |
199 | pop eax |
200 | add [filestruct.offset], eax |
200 | add [filestruct.offset], eax |
201 | 201 | ||
202 | icall eax, interface_addr, interface.progress |
202 | icall eax, interface_addr, interface.progress |
203 | jmp data_loop |
203 | jmp data_loop |
204 | 204 | ||
205 | ; storing, send all data |
205 | ; storing, send all data |
206 | .stor: |
206 | .stor: |
207 | mcall 70, filestruct |
207 | mcall 70, filestruct |
208 | cmp eax, 6 ; end of file |
208 | cmp eax, 6 ; end of file |
209 | je .last_call |
209 | je .last_call |
210 | test eax, eax ; error |
210 | test eax, eax ; error |
211 | jz @f |
211 | jz @f |
212 | call error_fs |
212 | call error_fs |
213 | jmp close_datacon |
213 | jmp close_datacon |
214 | @@: |
214 | @@: |
215 | add [filestruct.offset], ebx |
215 | add [filestruct.offset], ebx |
216 | mov esi, ebx |
216 | mov esi, ebx |
217 | mcall send, [datasocket], buf_buffer2, , 0 |
217 | mcall send, [datasocket], buf_buffer2, , 0 |
218 | mov edx, [filestruct.offset] |
218 | mov edx, [filestruct.offset] |
219 | icall eax, interface_addr, interface.progress |
219 | icall eax, interface_addr, interface.progress |
220 | jmp .stor |
220 | jmp .stor |
221 | 221 | ||
222 | .last_call: |
222 | .last_call: |
223 | mov esi, ebx |
223 | mov esi, ebx |
224 | mcall send, [datasocket], buf_buffer2, , 0 |
224 | mcall send, [datasocket], buf_buffer2, , 0 |
225 | mov edx, [filestruct.offset] |
225 | mov edx, [filestruct.offset] |
226 | icall eax, interface_addr, interface.progress |
226 | icall eax, interface_addr, interface.progress |
227 | 227 | ||
228 | .done: |
228 | .done: |
229 | icall eax, interface_addr, interface.print, str_close |
229 | icall eax, interface_addr, interface.print, str_close |
230 | mcall close, [datasocket] |
230 | mcall close, [datasocket] |
- | 231 | ||
- | 232 | ; refresh local directory list if in gui |
|
- | 233 | cmp [operation], OPERATION_RETR |
|
- | 234 | jne @f |
|
- | 235 | cmp [interface_addr], gui |
|
- | 236 | jne @f |
|
- | 237 | call populate_local_tree_list |
|
- | 238 | @@: |
|
231 | mov [operation], OPERATION_NONE |
239 | mov [operation], OPERATION_NONE |
232 | jmp wait_for_servercommand |
240 | jmp wait_for_servercommand |
233 | 241 | ||
234 | .rdir: |
242 | .rdir: |
235 | ; alloc/realloc memory block to store filenames |
243 | ; alloc/realloc memory block to store filenames |
236 | mov ecx, eax ; eax is size of buffer received |
244 | mov ecx, eax ; eax is size of buffer received |
237 | inc ecx |
245 | inc ecx |
238 | add ecx, [size_fname] ; added old size to form new required size |
246 | add ecx, [size_fname] ; added old size to form new required size |
239 | mcall 68, 20, , [ptr_fname] ; realloc |
247 | mcall 68, 20, , [ptr_fname] ; realloc |
240 | test eax, eax |
248 | test eax, eax |
241 | je error_heap |
249 | je error_heap |
242 | mov [ptr_fname], eax ; eax contains the new block now |
250 | mov [ptr_fname], eax ; eax contains the new block now |
243 | mov [ptr_queue], eax |
251 | mov [ptr_queue], eax |
244 | 252 | ||
245 | ; copy filenames into fname buffer |
253 | ; copy filenames into fname buffer |
246 | mov esi, buf_buffer2 |
254 | mov esi, buf_buffer2 |
247 | mov edi, eax |
255 | mov edi, eax |
248 | add edi, [size_fname] |
256 | add edi, [size_fname] |
249 | .copy_buf: |
257 | .copy_buf: |
250 | lodsb |
258 | lodsb |
251 | cmp al, 13 ; ignore any carriage return character |
259 | cmp al, 13 ; ignore any carriage return character |
252 | je .copy_buf |
260 | je .copy_buf |
253 | stosb |
261 | stosb |
254 | cmp al, 10 ; linefeed marks end of filename |
262 | cmp al, 10 ; linefeed marks end of filename |
255 | je @f |
263 | je @f |
256 | inc [queued] |
264 | inc [queued] |
257 | @@: |
265 | @@: |
258 | test al, al ; 0 marks end of buffer |
266 | test al, al ; 0 marks end of buffer |
259 | jne .copy_buf |
267 | jne .copy_buf |
260 | 268 | ||
261 | ; All received filenames have been copied, calculate new size of fname buffer |
269 | ; All received filenames have been copied, calculate new size of fname buffer |
262 | dec edi ; dont count the trailing 0 byte |
270 | dec edi ; dont count the trailing 0 byte |
263 | sub edi, [ptr_fname] |
271 | sub edi, [ptr_fname] |
264 | mov [size_fname], edi |
272 | mov [size_fname], edi |
265 | jmp data_loop |
273 | jmp data_loop |
266 | 274 | ||
267 | 275 | ||
268 | close_datacon: |
276 | close_datacon: |
269 | cmp [operation], OPERATION_NONE |
277 | cmp [operation], OPERATION_NONE |
270 | je wait_for_usercommand |
278 | je wait_for_usercommand |
271 | icall eax, interface_addr, interface.print, str_close |
279 | icall eax, interface_addr, interface.print, str_close |
272 | mcall close, [datasocket] |
280 | mcall close, [datasocket] |
273 | jmp wait_for_usercommand |
281 | jmp wait_for_usercommand |
274 | 282 | ||
275 | 283 | ||
276 | ascii_dec: |
284 | ascii_dec: |
277 | 285 | ||
278 | xor ebx, ebx |
286 | xor ebx, ebx |
279 | mov cl, 4 ; max length is 3 digits + 1 separator |
287 | mov cl, 4 ; max length is 3 digits + 1 separator |
280 | .loop: |
288 | .loop: |
281 | lodsb |
289 | lodsb |
282 | sub al, '0' |
290 | sub al, '0' |
283 | jb .done |
291 | jb .done |
284 | cmp al, 9 |
292 | cmp al, 9 |
285 | ja .done |
293 | ja .done |
286 | lea ebx, [ebx*4+ebx] ; ebx *5 |
294 | lea ebx, [ebx*4+ebx] ; ebx *5 |
287 | shl ebx, 1 ; ebx *2 |
295 | shl ebx, 1 ; ebx *2 |
288 | add bl, al |
296 | add bl, al |
289 | dec cl |
297 | dec cl |
290 | jnz .loop |
298 | jnz .loop |
291 | 299 | ||
292 | .done: |
300 | .done: |
293 | ret |
301 | ret |