Rev 6437 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6437 | Rev 6582 | ||
---|---|---|---|
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 -... | Line 7... | ||
- | 7 | ||
- | 8 | cmp dword[buf_cmd+4], "Open" |
|
- | 9 | je init_download_count |
|
7 | 10 | ||
8 | cmp dword[buf_cmd], "150 " |
11 | cmp dword[buf_cmd], "150 " |
Line 9... | Line 12... | ||
9 | je data_loop |
12 | je data_loop |
10 | 13 | ||
Line 11... | Line 14... | ||
11 | cmp dword[buf_cmd], "220 " |
14 | cmp dword[buf_cmd], "220 " |
12 | je welcome |
15 | je connect_ok |
Line 13... | Line 16... | ||
13 | 16 | ||
Line 31... | Line 34... | ||
31 | 34 | ||
32 | cmp dword[buf_cmd], "503 " ; login first |
35 | cmp dword[buf_cmd], "503 " ; login first |
Line 33... | Line 36... | ||
33 | je welcome |
36 | je welcome |
34 | - | ||
35 | cmp dword[buf_cmd], "530 " ; password incorrect |
37 | |
Line 36... | Line 38... | ||
36 | mov [use_params], 0 |
38 | cmp dword[buf_cmd], "530 " ; password incorrect |
37 | je welcome |
39 | je welcome |
Line 48... | Line 50... | ||
48 | 50 | ||
49 | mov [status], STATUS_CONNECTED |
51 | mov [status], STATUS_CONNECTED |
Line -... | Line 52... | ||
- | 52 | jmp wait_for_usercommand |
|
- | 53 | ||
- | 54 | ||
- | 55 | connect_ok: |
|
- | 56 | ||
50 | jmp wait_for_usercommand |
57 | mov [status], STATUS_CONNECTED |
Line 51... | Line 58... | ||
51 | 58 | jmp arg_handler.copy_user |
|
52 | 59 | ||
Line 53... | Line 60... | ||
53 | pass: |
60 | pass: |
Line 54... | Line 61... | ||
54 | 61 | ||
55 | mov [status], STATUS_NEEDPASSWORD |
- | |
56 | jmp wait_for_usercommand |
- | |
Line 57... | Line 62... | ||
57 | 62 | mov [status], STATUS_NEEDPASSWORD |
|
58 | 63 | jmp wait_for_usercommand |
|
- | 64 | ||
59 | login_ok: |
65 | |
60 | - | ||
61 | mov [status], STATUS_LOGGED_IN |
66 | login_ok: |
62 | cmp [use_params], 0 |
67 | |
63 | je wait_for_usercommand |
- | |
64 | - | ||
65 | cmp [param_path+4], 0 |
- | |
66 | je wait_for_usercommand |
- | |
67 | ; copy path to buf_cmd and execute CWD |
- | |
Line 68... | Line 68... | ||
68 | mov edi, buf_cmd |
68 | mov [status], STATUS_LOGGED_IN |
Line 69... | Line 69... | ||
69 | mov esi, param_path |
69 | |
70 | @@: |
70 | cmp [param_path], 0x20 ; no path specified |
Line 102... | Line 102... | ||
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 |
Line 106... | Line 106... | ||
106 | 106 | ||
107 | invoke con_write_asciiz, 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 |
Line 113... | Line 113... | ||
113 | @@: jmp wait_for_servercommand |
113 | @@: jmp wait_for_servercommand |
114 | 114 | ||
115 | .fail: |
115 | .fail: |
Line -... | Line 116... | ||
- | 116 | icall eax, interface_addr, interface.print, str_unknown |
|
- | 117 | jmp wait_for_servercommand |
|
- | 118 | ||
- | 119 | ||
- | 120 | ; get file size, initialize count for number of bytes downloaded |
|
- | 121 | init_download_count: |
|
116 | invoke con_write_asciiz, str_unknown |
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' |
|
Line -... | Line 129... | ||
- | 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 |
|
117 | jmp wait_for_servercommand |
149 | pop eax |
- | 150 | mul ebx |
|
- | 151 | add eax, ecx |
|
Line 118... | Line 152... | ||
118 | 152 | cmp byte[esi], ' ' |
|
119 | 153 | jne @b |
|
Line -... | Line 154... | ||
- | 154 | mov [file_size], eax |
|
120 | data_loop: |
155 | |
121 | 156 | data_loop: |
|
- | 157 | ||
- | 158 | cmp [operation], OPERATION_STOR |
|
122 | invoke con_write_asciiz, str_dot |
159 | je .stor |
123 | 160 | ||
124 | cmp [operation], OPERATION_STOR |
161 | push edx |
Line 125... | Line 162... | ||
125 | je .stor |
162 | ; we are receiving data |
126 | 163 | mcall recv, [datasocket], buf_buffer2, BUFFERSIZE, 0 |
|
Line 127... | Line 164... | ||
127 | ; we are receiving data |
164 | pop edx ; get byte count |
128 | mcall recv, [datasocket], buf_buffer2, BUFFERSIZE, 0 |
165 | add edx, eax |
Line -... | Line 166... | ||
- | 166 | test ebx, ebx |
|
- | 167 | jnz .done |
|
- | 168 | mov byte[buf_buffer2 + eax], 0 |
|
129 | test ebx, ebx |
169 | |
130 | jnz .done |
170 | cmp [operation], OPERATION_RETR |
131 | mov byte[buf_buffer2 + eax], 0 |
171 | je .retr |
Line -... | Line 172... | ||
- | 172 | ||
- | 173 | cmp [operation], OPERATION_RDIR |
|
- | 174 | je .rdir |
|
- | 175 | ||
- | 176 | cmp [operation], OPERATION_LIST |
|
132 | 177 | je .list |
|
133 | cmp [operation], OPERATION_RETR |
178 | |
134 | je .retr |
179 | ; not retreiving, just print to console |
135 | 180 | icall eax, interface_addr, interface.print, buf_buffer2 |
|
136 | cmp [operation], OPERATION_RDIR |
181 | jmp data_loop |
137 | je .rdir |
182 | |
- | 183 | ; for console, simply print. for gui, add name to tree list |
|
- | 184 | .list: |
|
- | 185 | ijmp ebx, interface_addr, interface.list |
|
- | 186 | ||
- | 187 | ||
138 | 188 | ; retreiving, save to file |
|
139 | ; not retreiving, just print to console |
189 | .retr: |
- | 190 | mov [filestruct.ptr], buf_buffer2 |
|
- | 191 | mov [filestruct.size], eax |
|
140 | invoke con_write_asciiz, buf_buffer2 |
192 | push eax |
Line 141... | Line 193... | ||
141 | jmp data_loop |
193 | mcall 70, filestruct |
142 | 194 | test eax, eax |
|
143 | ; retreiving, save to file |
195 | jz @f |
144 | .retr: |
196 | call error_fs |
145 | mov [filestruct.ptr], buf_buffer2 |
197 | jmp close_datacon |
146 | mov [filestruct.size], eax |
198 | @@: |
- | 199 | pop eax |
|
- | 200 | add [filestruct.offset], eax |
|
147 | push eax |
201 | |
- | 202 | icall eax, interface_addr, interface.progress |
|
148 | mcall 70, filestruct |
203 | jmp data_loop |
149 | pop eax |
204 | |
150 | add [filestruct.offset], eax |
205 | ; storing, send all data |
- | 206 | .stor: |
|
- | 207 | mcall 70, filestruct |
|
151 | jmp data_loop |
208 | cmp eax, 6 ; end of file |
Line 152... | Line 209... | ||
152 | 209 | je .last_call |
|
153 | ; storing, send all data |
210 | test eax, eax ; error |
154 | .stor: |
211 | jz @f |
- | 212 | call error_fs |
|
- | 213 | jmp close_datacon |
|
Line 155... | Line 214... | ||
155 | mcall 70, filestruct |
214 | @@: |
156 | cmp eax, 6 ; end of file |
215 | add [filestruct.offset], ebx |
157 | je .last_call |
216 | mov esi, ebx |
158 | test eax, eax ; error |
217 | mcall send, [datasocket], buf_buffer2, , 0 |
159 | ; jne .fileerror |
218 | mov edx, [filestruct.offset] |
Line 160... | Line 219... | ||
160 | add [filestruct.offset], ebx |
219 | icall eax, interface_addr, interface.progress |
Line 207... | Line 266... | ||
207 | 266 | ||
208 | 267 | ||
209 | close_datacon: |
268 | close_datacon: |
210 | cmp [operation], OPERATION_NONE |
269 | cmp [operation], OPERATION_NONE |
211 | je wait_for_usercommand |
270 | je wait_for_usercommand |
212 | invoke con_write_asciiz, str_close |
271 | icall eax, interface_addr, interface.print, str_close |
Line 213... | Line 272... | ||
213 | mcall close, [datasocket] |
272 | mcall close, [datasocket] |