Rev 6394 | Rev 6582 | 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 |
||
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 | |||
3789 | hidnplayr | 107 | invoke con_write_asciiz, 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: |
||
3818 | hidnplayr | 116 | invoke con_write_asciiz, str_unknown |
3789 | hidnplayr | 117 | jmp wait_for_servercommand |
3701 | hidnplayr | 118 | |
119 | |||
4920 | hidnplayr | 120 | data_loop: |
3701 | hidnplayr | 121 | |
4922 | ashmew2 | 122 | invoke con_write_asciiz, str_dot |
3967 | hidnplayr | 123 | |
3800 | hidnplayr | 124 | cmp [operation], OPERATION_STOR |
125 | je .stor |
||
126 | |||
127 | ; we are receiving data |
||
4922 | ashmew2 | 128 | mcall recv, [datasocket], buf_buffer2, BUFFERSIZE, 0 |
3792 | hidnplayr | 129 | test ebx, ebx |
3800 | hidnplayr | 130 | jnz .done |
4922 | ashmew2 | 131 | mov byte[buf_buffer2 + eax], 0 |
3701 | hidnplayr | 132 | |
3800 | hidnplayr | 133 | cmp [operation], OPERATION_RETR |
134 | je .retr |
||
135 | |||
5011 | hidnplayr | 136 | cmp [operation], OPERATION_RDIR |
137 | je .rdir |
||
138 | |||
3800 | hidnplayr | 139 | ; not retreiving, just print to console |
4922 | ashmew2 | 140 | invoke con_write_asciiz, buf_buffer2 |
4920 | hidnplayr | 141 | jmp data_loop |
3789 | hidnplayr | 142 | |
3800 | hidnplayr | 143 | ; retreiving, save to file |
144 | .retr: |
||
4922 | ashmew2 | 145 | mov [filestruct.ptr], buf_buffer2 |
3800 | hidnplayr | 146 | mov [filestruct.size], eax |
147 | push eax |
||
148 | mcall 70, filestruct |
||
149 | pop eax |
||
150 | add [filestruct.offset], eax |
||
4920 | hidnplayr | 151 | jmp data_loop |
3792 | hidnplayr | 152 | |
3800 | hidnplayr | 153 | ; storing, send all data |
154 | .stor: |
||
155 | mcall 70, filestruct |
||
156 | cmp eax, 6 ; end of file |
||
157 | je .last_call |
||
158 | test eax, eax ; error |
||
159 | ; jne .fileerror |
||
160 | add [filestruct.offset], ebx |
||
161 | mov esi, ebx |
||
4922 | ashmew2 | 162 | mcall send, [datasocket], buf_buffer2, , 0 |
3800 | hidnplayr | 163 | jmp .stor |
164 | |||
165 | .last_call: |
||
166 | mov esi, ebx |
||
4922 | ashmew2 | 167 | mcall send, [datasocket], buf_buffer2, , 0 |
3800 | hidnplayr | 168 | |
169 | .done: |
||
3967 | hidnplayr | 170 | invoke con_write_asciiz, str_close |
3789 | hidnplayr | 171 | mcall close, [datasocket] |
4920 | hidnplayr | 172 | mov [operation], OPERATION_NONE |
3789 | hidnplayr | 173 | jmp wait_for_servercommand |
3701 | hidnplayr | 174 | |
4922 | ashmew2 | 175 | .rdir: |
5011 | hidnplayr | 176 | ; alloc/realloc memory block to store filenames |
177 | mov ecx, eax ; eax is size of buffer received |
||
178 | inc ecx |
||
179 | add ecx, [size_fname] ; added old size to form new required size |
||
180 | mcall 68, 20, , [ptr_fname] ; realloc |
||
181 | test eax, eax |
||
182 | je error_heap |
||
183 | mov [ptr_fname], eax ; eax contains the new block now |
||
184 | mov [ptr_queue], eax |
||
4922 | ashmew2 | 185 | |
5011 | hidnplayr | 186 | ; copy filenames into fname buffer |
187 | mov esi, buf_buffer2 |
||
188 | mov edi, eax |
||
189 | add edi, [size_fname] |
||
4922 | ashmew2 | 190 | .copy_buf: |
5011 | hidnplayr | 191 | lodsb |
192 | cmp al, 13 ; ignore any carriage return character |
||
193 | je .copy_buf |
||
194 | stosb |
||
195 | cmp al, 10 ; linefeed marks end of filename |
||
196 | je @f |
||
197 | inc [queued] |
||
198 | @@: |
||
199 | test al, al ; 0 marks end of buffer |
||
200 | jne .copy_buf |
||
4922 | ashmew2 | 201 | |
5011 | hidnplayr | 202 | ; All received filenames have been copied, calculate new size of fname buffer |
203 | dec edi ; dont count the trailing 0 byte |
||
204 | sub edi, [ptr_fname] |
||
205 | mov [size_fname], edi |
||
206 | jmp data_loop |
||
4922 | ashmew2 | 207 | |
208 | |||
3800 | hidnplayr | 209 | close_datacon: |
4920 | hidnplayr | 210 | cmp [operation], OPERATION_NONE |
211 | je wait_for_usercommand |
||
3967 | hidnplayr | 212 | invoke con_write_asciiz, str_close |
3800 | hidnplayr | 213 | mcall close, [datasocket] |
214 | jmp wait_for_usercommand |
||
215 | |||
216 | |||
3701 | hidnplayr | 217 | ascii_dec: |
218 | |||
219 | xor ebx, ebx |
||
3789 | hidnplayr | 220 | mov cl, 4 ; max length is 3 digits + 1 separator |
3701 | hidnplayr | 221 | .loop: |
222 | lodsb |
||
223 | sub al, '0' |
||
224 | jb .done |
||
225 | cmp al, 9 |
||
226 | ja .done |
||
3789 | hidnplayr | 227 | lea ebx, [ebx*4+ebx] ; ebx *5 |
228 | shl ebx, 1 ; ebx *2 |
||
3701 | hidnplayr | 229 | add bl, al |
230 | dec cl |
||
231 | jnz .loop |
||
232 | |||
233 | .done: |
||
234 | ret |