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