Rev 6436 | Rev 6835 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6436 | Rev 6582 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; ftpc.asm - FTP client for KolibriOS ;; |
6 | ;; ftpc.asm - FTP client for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
- | 9 | ;; Modified by nisargshah323@gmail.com (2016) ;; |
|
9 | ;; ;; |
10 | ;; ;; |
10 | ;; GNU GENERAL PUBLIC LICENSE ;; |
11 | ;; GNU GENERAL PUBLIC LICENSE ;; |
11 | ;; Version 2, June 1991 ;; |
12 | ;; Version 2, June 1991 ;; |
12 | ;; ;; |
13 | ;; ;; |
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
14 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 39... | Line 40... | ||
39 | dd mem+0x1000 ; stack pointer |
40 | dd mem+0x1000 ; stack pointer |
40 | dd buf_cmd ; parameters |
41 | dd buf_cmd ; parameters |
41 | dd path ; path |
42 | dd path ; path |
Line 42... | Line 43... | ||
42 | 43 | ||
- | 44 | include '../../macros.inc' |
|
- | 45 | macro ijmp reg, addr, method |
|
- | 46 | { |
|
- | 47 | mov reg, [addr] |
|
- | 48 | add reg, [method] |
|
- | 49 | jmp dword[reg] |
|
- | 50 | } |
|
- | 51 | macro icall reg, addr, method, [arg] |
|
- | 52 | { |
|
- | 53 | mov reg, [addr] |
|
- | 54 | add reg, [method] |
|
- | 55 | if ~ arg eq |
|
- | 56 | pushd arg |
|
- | 57 | end if |
|
- | 58 | call dword[reg] |
|
- | 59 | } |
|
43 | include '../../macros.inc' |
60 | |
- | 61 | purge mov,add,sub |
|
44 | purge mov,add,sub |
62 | |
45 | include '../../proc32.inc' |
63 | include '../../proc32.inc' |
46 | include '../../dll.inc' |
64 | include '../../dll.inc' |
Line -... | Line 65... | ||
- | 65 | include '../../network.inc' |
|
- | 66 | ||
- | 67 | include '../../develop/libraries/box_lib/trunk/box_lib.mac' |
|
- | 68 | include '../../develop/libraries/box_lib/load_lib.mac' |
|
- | 69 | ||
- | 70 | include 'console.inc' |
|
47 | include '../../network.inc' |
71 | include 'gui.inc' |
48 | 72 | include 'login_gui.inc' |
|
49 | include 'usercommands.inc' |
73 | include 'usercommands.inc' |
Line -... | Line 74... | ||
- | 74 | include 'servercommands.inc' |
|
50 | include 'servercommands.inc' |
75 | include 'parser.inc' |
- | 76 | ||
- | 77 | ; TODO: Add Pasta support to FTPC |
|
- | 78 | ||
- | 79 | ;;================================================================================================;; |
|
- | 80 | start: ;//////////////////////////////////////////////////////////////////////////////////////////;; |
|
- | 81 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 82 | ;? Program entry point - initialize heap, load libraries and settings ;; |
|
- | 83 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 84 | ;> ;; |
|
51 | include 'parser.inc' |
85 | ;;------------------------------------------------------------------------------------------------;; |
52 | 86 | ;< none ;; |
|
53 | start: |
87 | ;;================================================================================================;; |
54 | ; initialize heap for using dynamic blocks |
88 | ; initialize heap for using dynamic blocks |
Line 60... | Line 94... | ||
60 | mcall 40, EV_STACK |
94 | mcall 40, EV_STACK |
61 | ; load libraries |
95 | ; load libraries |
62 | stdcall dll.Load, @IMPORT |
96 | stdcall dll.Load, @IMPORT |
63 | test eax, eax |
97 | test eax, eax |
64 | jnz exit |
98 | jnz exit |
65 | ; initialize console |
- | |
66 | invoke con_start, 1 |
- | |
67 | invoke con_init, 80, 25, 80, 250, str_title |
- | |
68 | ; find path to main settings file (ftpc.ini) |
99 | ; find path to main settings file (ftpc.ini) |
69 | mov edi, path ; Calculate the length of zero-terminated string |
100 | mov edi, path ; Calculate the length of zero-terminated string |
70 | xor al, al |
101 | xor al, al |
71 | mov ecx, 1024 |
102 | mov ecx, 1024 |
72 | repne scasb |
103 | repne scasb |
Line 97... | Line 128... | ||
97 | mov [acti_port_stop], ax |
128 | mov [acti_port_stop], ax |
Line 98... | Line 129... | ||
98 | 129 | ||
99 | invoke ini.get_str, path, str_general, str_dir, buf_buffer1, BUFFERSIZE, 0 |
130 | invoke ini.get_str, path, str_general, str_dir, buf_buffer1, BUFFERSIZE, 0 |
Line -... | Line 131... | ||
- | 131 | mcall 30, 1, buf_buffer1 ; set working directory |
|
100 | mcall 30, 1, buf_buffer1 ; set working directory |
132 | |
- | 133 | ; initialize log file |
|
- | 134 | invoke ini.get_str, path, str_general, str_logfile, log_file, 512, 0 |
|
- | 135 | mov [filestruct2.subfn], 2 |
|
- | 136 | mov [filestruct2.offset], 0 |
|
- | 137 | mov [filestruct2.size], 0 |
|
- | 138 | mov [filestruct2.ptr], 0 |
|
- | 139 | mov [filestruct2.name], log_file |
|
101 | 140 | mcall 70, filestruct2 |
|
- | 141 | ||
- | 142 | ; Usage: ftpc [-cli] [ftp://username:password@server:port/path] |
|
- | 143 | ||
102 | ; Check for parameters, if there are some, resolve the address right away |
144 | ; mov dword[buf_cmd], '-cli' ;;;; to test CLI ;;;;; |
- | 145 | ||
- | 146 | cmp byte[buf_cmd], 0 |
|
- | 147 | jne @f |
|
- | 148 | mov [interface_addr], gui |
|
103 | ; TODO: parse ftp://user:password@server.com:port/folder/subfolder type urls. |
149 | jmp .args_ok |
- | 150 | @@: cmp dword[buf_cmd], '-cli' |
|
- | 151 | jne .error |
|
- | 152 | mov [interface_addr], console |
|
- | 153 | jmp .args_ok |
|
- | 154 | ||
- | 155 | .args_ok: |
|
- | 156 | ||
- | 157 | icall eax, interface_addr, interface.init |
|
- | 158 | ; check for ftp://username:pass@server:port/path urls |
|
- | 159 | cmp dword[buf_cmd], 'ftp:' |
|
- | 160 | je parse_args |
|
- | 161 | cmp dword[buf_cmd+5], 'ftp:' |
|
- | 162 | je parse_args |
|
- | 163 | ijmp eax, interface_addr, interface.server_addr |
|
- | 164 | ||
- | 165 | .error: |
|
- | 166 | call console.init |
|
- | 167 | invoke con_write_asciiz, str_args_err |
|
- | 168 | invoke con_getch2 |
|
Line 104... | Line -... | ||
104 | cmp byte [buf_cmd], 0 |
- | |
105 | jne resolve |
- | |
106 | - | ||
107 | main: |
- | |
108 | ; Clear screen |
169 | call console.exit |
109 | invoke con_cls |
170 | jmp exit |
110 | ; Welcome user |
171 | |
111 | invoke con_write_asciiz, str_welcome |
172 | ;;================================================================================================;; |
112 | ; write prompt (in green color) |
- | |
113 | invoke con_set_flags, 0x0a |
173 | arg_handler: ;////////////////////////////////////////////////////////////////////////////////////;; |
114 | invoke con_write_asciiz, str_prompt |
- | |
115 | ; read string |
- | |
116 | invoke con_gets, buf_cmd, 256 |
- | |
117 | ; check for exit |
174 | ;;------------------------------------------------------------------------------------------------;; |
118 | test eax, eax |
- | |
119 | jz done |
175 | ;? Passes initial connection info from console/GUI to FTP core and the other way around ;; |
120 | cmp byte [buf_cmd], 10 |
176 | ;;------------------------------------------------------------------------------------------------;; |
121 | jz done |
177 | ;> esp+4 = pointer to the argument passed to the function ;; |
Line 122... | Line 178... | ||
122 | ; reset color back to grey and print newline |
178 | ;;------------------------------------------------------------------------------------------------;; |
- | 179 | ;< none ;; |
|
123 | invoke con_set_flags, 0x07 |
180 | ;;================================================================================================;; |
Line -... | Line 181... | ||
- | 181 | ||
- | 182 | .get_username: |
|
- | 183 | ; request username |
|
- | 184 | ijmp eax, interface_addr, interface.get_username |
|
- | 185 | ||
- | 186 | .copy_user: |
|
- | 187 | mov dword[buf_cmd], "USER" |
|
- | 188 | mov byte[buf_cmd+4], " " |
|
- | 189 | ; copy user name to buf_cmd (for command line args) |
|
- | 190 | mov edi, buf_cmd+5 |
|
- | 191 | mov esi, param_user |
|
- | 192 | @@: |
|
- | 193 | movsb |
|
- | 194 | cmp byte [esi-1], 0 |
|
- | 195 | jne @b |
|
- | 196 | mov word[edi-1], 0x0a0d |
|
- | 197 | ||
- | 198 | lea esi, [edi+1-buf_cmd] |
|
- | 199 | jmp server_connect.send |
|
- | 200 | ||
- | 201 | .get_pass: |
|
- | 202 | mov dword[buf_cmd], "PASS" |
|
- | 203 | mov byte[buf_cmd+4], " " |
|
- | 204 | ; copy password to buf_cmd (for command line args) |
|
- | 205 | mov edi, buf_cmd+5 |
|
- | 206 | mov esi, param_password |
|
- | 207 | @@: |
|
- | 208 | movsb |
|
- | 209 | cmp byte[esi-1], 0 |
|
- | 210 | jne @b |
|
- | 211 | mov word[edi-1], 0x0a0d |
|
124 | invoke con_write_asciiz, str_newline |
212 | |
- | 213 | lea esi, [edi+1-buf_cmd] |
|
125 | 214 | jmp server_connect.send |
|
- | 215 | ||
126 | no_resolve: |
216 | .get_path: |
127 | mov [sockaddr1.port], 21 shl 8 |
217 | ; copy path from param_path to buf_cmd |
- | 218 | mov dword[buf_cmd], "CWD " |
|
128 | 219 | mov edi, buf_cmd+4 |
|
129 | ; delete terminating '\n' |
220 | mov esi, param_path |
- | 221 | @@: |
|
- | 222 | lodsb |
|
- | 223 | stosb |
|
- | 224 | cmp al, 0x20 |
|
- | 225 | ja @b |
|
- | 226 | mov word[edi-1], 0x0a0d |
|
- | 227 | ||
- | 228 | lea esi, [edi+1-buf_cmd] |
|
- | 229 | jmp server_connect.send |
|
- | 230 | ||
- | 231 | .connect: |
|
- | 232 | ; copy server address to buf_cmd |
|
130 | mov esi, buf_cmd |
233 | mov esi, param_server_addr |
131 | @@: |
234 | mov edi, buf_cmd |
- | 235 | @@: |
|
- | 236 | lodsb |
|
- | 237 | stosb |
|
- | 238 | cmp al, 0x20 |
|
132 | lodsb |
239 | ja @r |
133 | cmp al, ':' |
240 | mov byte[edi-1], 0 ; delete terminating '\n' |
- | 241 | ||
- | 242 | cmp [param_port], 0x20 |
|
- | 243 | jbe server_connect.default_port |
|
- | 244 | mov esi, param_port |
|
- | 245 | jmp server_connect.do_port |
|
- | 246 | ||
- | 247 | ||
- | 248 | ;;================================================================================================;; |
|
- | 249 | server_connect: ;/////////////////////////////////////////////////////////////////////////////////;; |
|
- | 250 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 251 | ;? Establishes a connection to the FTP server (common block for all interfaces) ;; |
|
- | 252 | ;? .do_port - Port is specified by the user and needs to be converted from ASCII ;; |
|
- | 253 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 254 | ;> esi = pointer to port no. ;; |
|
- | 255 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 256 | ;< none ;; |
|
- | 257 | ;;================================================================================================;; |
|
- | 258 | ||
- | 259 | .send: |
|
- | 260 | ; send username/password/path to the server |
|
Line -... | Line 261... | ||
- | 261 | mcall send, [controlsocket], buf_cmd, , 0 |
|
134 | je .do_port |
262 | icall eax, interface_addr, interface.print, str_newline |
135 | cmp al, 0x20 |
263 | icall eax, interface_addr, interface.set_flags, 0x07 ; reset color |
136 | ja @r |
264 | |
137 | mov byte [esi-1], 0 |
- | |
138 | jmp .done |
265 | jmp wait_for_servercommand |
139 | 266 | ||
140 | .do_port: |
267 | ; resolve port if specified |
141 | xor eax, eax |
268 | .do_port: |
142 | xor ebx, ebx |
269 | xor eax, eax |
Line 159... | Line 286... | ||
159 | jmp .portloop |
286 | jmp .portloop |
Line 160... | Line 287... | ||
160 | 287 | ||
161 | .port_done: |
288 | .port_done: |
162 | xchg bl, bh |
289 | xchg bl, bh |
- | 290 | mov [sockaddr1.port], bx |
|
- | 291 | jmp .done |
|
- | 292 | ||
- | 293 | .default_port: |
|
Line 163... | Line 294... | ||
163 | mov [sockaddr1.port], bx |
294 | mov [sockaddr1.port], 21 shl 8 |
164 | 295 | ||
165 | .done: |
296 | .done: |
166 | ; Say to the user that we're resolving |
297 | ; Say to the user that we're resolving |
167 | invoke con_write_asciiz, str_resolve |
298 | icall eax, interface_addr, interface.set_flags, 0x07 ; reset color |
168 | invoke con_write_asciiz, buf_cmd |
299 | icall eax, interface_addr, interface.print, str_resolve, buf_cmd |
169 | ; resolve name |
300 | ; resolve name |
170 | push esp ; reserve stack place |
301 | push esp ; reserve stack place |
171 | invoke getaddrinfo, buf_cmd, 0, 0, esp |
302 | invoke getaddrinfo, buf_cmd, 0, 0, esp |
Line 175... | Line 306... | ||
175 | jz @f |
306 | jz @f |
176 | mov eax, str_err_resolve |
307 | mov eax, str_err_resolve |
177 | jmp error |
308 | jmp error |
178 | @@: |
309 | @@: |
179 | ; write results |
310 | ; write results |
180 | invoke con_write_asciiz, str8 ; ' (',0 |
311 | icall eax, interface_addr, interface.print, str8 ; ' (',0 |
181 | mov eax, [esi+addrinfo.ai_addr] ; convert IP address to decimal notation |
312 | mov eax, [esi+addrinfo.ai_addr] ; convert IP address to decimal notation |
182 | mov eax, [eax+sockaddr_in.sin_addr] ; |
313 | mov eax, [eax+sockaddr_in.sin_addr] ; |
183 | mov [sockaddr1.ip], eax ; |
314 | mov [sockaddr1.ip], eax ; |
184 | invoke inet_ntoa, eax ; |
315 | invoke inet_ntoa, eax ; |
185 | invoke con_write_asciiz, eax ; print ip |
316 | icall ebx, interface_addr, interface.print, eax, str9 ; |
186 | invoke freeaddrinfo, esi ; free allocated memory |
317 | invoke freeaddrinfo, esi ; free allocated memory |
187 | invoke con_write_asciiz, str9 ; ')',10,0 |
- | |
188 | ; open the socket |
318 | ; open the socket |
189 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
319 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
190 | cmp eax, -1 |
320 | cmp eax, -1 |
191 | jne @f |
321 | jne @f |
192 | mov eax, str_err_socket |
322 | mov eax, str_err_socket |
193 | jmp error |
323 | jmp error |
194 | @@: mov [controlsocket], eax |
324 | @@: mov [controlsocket], eax |
195 | ; connect to the server |
325 | ; connect to the server |
196 | invoke con_write_asciiz, str_connect |
326 | icall eax, interface_addr, interface.print, str_connect |
197 | mcall connect, [controlsocket], sockaddr1, 18 |
327 | mcall connect, [controlsocket], sockaddr1, 18 |
198 | cmp eax, -1 |
328 | cmp eax, -1 |
199 | jne @f |
329 | jne @f |
200 | mov eax, str_err_connect |
330 | mov eax, str_err_connect |
201 | jmp error |
331 | jmp error |
202 | @@: mov [status], STATUS_CONNECTING |
332 | @@: mov [status], STATUS_CONNECTING |
203 | ; Tell the user we're waiting for the server now. |
333 | ; Tell the user we're waiting for the server now. |
204 | invoke con_write_asciiz, str_waiting |
334 | icall eax, interface_addr, interface.print, str_waiting |
Line 205... | Line 335... | ||
205 | 335 | ||
206 | ; Reset 'offset' variable, it's used by the data receiver |
336 | ; Reset 'offset' variable, it's used by the data receiver |
Line -... | Line 337... | ||
- | 337 | mov [offset], 0 |
|
- | 338 | ||
207 | mov [offset], 0 |
339 | |
- | 340 | ;;================================================================================================;; |
|
- | 341 | wait_for_servercommand: ;/////////////////////////////////////////////////////////////////////////;; |
|
- | 342 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 343 | ;? Checks if any data received from the server is present in buffer. ;; |
|
- | 344 | ;? If not, receives and processes it ;; |
|
- | 345 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 346 | ;> ;; |
|
- | 347 | ;;------------------------------------------------------------------------------------------------;; |
|
208 | 348 | ;< none ;; |
|
209 | wait_for_servercommand: |
349 | ;;================================================================================================;; |
210 | ; Any commands still in our buffer? |
350 | ; Any commands still in our buffer? |
211 | cmp [offset], 0 |
351 | cmp [offset], 0 |
212 | je .receive ; nope, receive some more |
352 | je .receive ; nope, receive some more |
Line 266... | Line 406... | ||
266 | .go_cmd: |
406 | .go_cmd: |
267 | lea ecx, [edi - buf_cmd] ; length of command |
407 | lea ecx, [edi - buf_cmd] ; length of command |
268 | xor al, al |
408 | xor al, al |
269 | stosb |
409 | stosb |
Line 270... | Line 410... | ||
270 | 410 | ||
271 | invoke con_set_flags, 0x03 ; change color |
- | |
272 | invoke con_write_asciiz, buf_cmd ; print servercommand |
411 | icall eax, interface_addr, interface.set_flags, 0x03 ; change color |
273 | invoke con_write_asciiz, str_newline |
412 | icall eax, interface_addr, interface.print, buf_cmd, str_newline |
Line 274... | Line 413... | ||
274 | invoke con_set_flags, 0x07 ; reset color |
413 | icall eax, interface_addr, interface.set_flags, 0x07 ; reset color |
Line -... | Line 414... | ||
- | 414 | ||
275 | 415 | jmp server_parser ; parse command |
|
- | 416 | ||
- | 417 | ||
- | 418 | ||
- | 419 | ;;================================================================================================;; |
|
- | 420 | wait_for_usercommand: ;///////////////////////////////////////////////////////////////////////////;; |
|
- | 421 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 422 | ;? Reads the FTP command entered by the user and compares it with valid FTP commands. ;; |
|
- | 423 | ;? Jumps to appropriate handling routine in usercommands.inc ;; |
|
- | 424 | ;;------------------------------------------------------------------------------------------------;; |
|
Line 276... | Line 425... | ||
276 | jmp server_parser ; parse command |
425 | ;> status = socket connection status ;; |
Line 277... | Line 426... | ||
277 | 426 | ;> buf_cmd = command entered by the user ;; |
|
278 | 427 | ;;------------------------------------------------------------------------------------------------;; |
|
Line 279... | Line 428... | ||
279 | 428 | ;< none ;; |
|
280 | wait_for_usercommand: |
429 | ;;================================================================================================;; |
Line 281... | Line 430... | ||
281 | 430 | ||
- | 431 | ; Are there any files in the transfer queue? |
|
282 | ; Are there any files in the transfer queue? |
432 | |
283 | 433 | cmp [queued], 0 |
|
Line 284... | Line 434... | ||
284 | cmp [queued], 0 |
434 | ja transfer_queued ; Yes, transfer those first. |
285 | ja transfer_queued ; Yes, transfer those first. |
435 | |
Line 286... | Line -... | ||
286 | - | ||
287 | ; change color to green for user input |
- | |
288 | invoke con_set_flags, 0x0a |
- | |
289 | - | ||
290 | ; If we are not yet connected, request username/password |
- | |
291 | cmp [status], STATUS_CONNECTED |
- | |
292 | je .connected |
436 | ; change color to green for user input |
293 | - | ||
Line -... | Line 437... | ||
- | 437 | icall eax, interface_addr, interface.set_flags, 0x0a |
|
294 | cmp [status], STATUS_NEEDPASSWORD |
438 | |
295 | je .needpass |
439 | ; If we are not yet connected, request username/password |
Line 296... | Line 440... | ||
296 | 440 | ||
297 | ; write prompt |
441 | cmp [status], STATUS_CONNECTED |
Line 347... | Line 491... | ||
347 | je cmd_help |
491 | je cmd_help |
Line 348... | Line 492... | ||
348 | 492 | ||
349 | cmp dword[buf_cmd], "cdup" |
493 | cmp dword[buf_cmd], "cdup" |
Line -... | Line 494... | ||
- | 494 | je cmd_cdup |
|
- | 495 | ||
- | 496 | cmp dword[buf_cmd], "abor" |
|
350 | je cmd_cdup |
497 | je cmd_abor |
351 | 498 | ||
352 | @@: |
499 | @@: |
353 | ; Uh oh.. unknown command, tell the user and wait for new input |
500 | ; Uh oh.. unknown command, tell the user and wait for new input |
Line 354... | Line -... | ||
354 | invoke con_write_asciiz, str_unknown |
- | |
355 | jmp wait_for_usercommand |
- | |
356 | - | ||
357 | - | ||
358 | .connected: |
- | |
359 | ; request username |
- | |
360 | cmp [use_params], 1 |
- | |
361 | je .copy_user |
- | |
362 | - | ||
363 | invoke con_write_asciiz, str_user |
- | |
364 | mov dword[buf_cmd], "USER" |
- | |
365 | mov byte[buf_cmd+4], " " |
- | |
366 | jmp .send |
- | |
367 | - | ||
368 | .copy_user: |
- | |
369 | ; copy user name to buf_cmd |
- | |
370 | mov edi, buf_cmd |
- | |
371 | mov esi, param_user |
- | |
372 | @@: |
- | |
373 | lodsb |
- | |
374 | stosb |
- | |
375 | cmp byte [esi-1], 0 |
- | |
376 | jne @b |
- | |
377 | jmp .send |
- | |
378 | - | ||
379 | .needpass: |
- | |
380 | ; request password |
- | |
381 | cmp [use_params], 1 |
- | |
382 | je .copy_password |
- | |
383 | - | ||
384 | invoke con_write_asciiz, str_pass |
- | |
385 | mov dword[buf_cmd], "PASS" |
- | |
386 | mov byte[buf_cmd+4], " " |
- | |
387 | invoke con_set_flags, 0x00 ; black text on black background for password |
- | |
388 | jmp .send |
- | |
389 | - | ||
390 | .copy_password: |
- | |
391 | ; copy password to buf_cmd |
- | |
392 | mov edi, buf_cmd |
- | |
393 | mov esi, param_password |
- | |
394 | @@: |
- | |
395 | lodsb |
- | |
396 | stosb |
- | |
397 | cmp byte [esi-1], 0 |
- | |
398 | jne @b |
- | |
399 | - | ||
400 | .send: |
- | |
401 | ; read string |
- | |
402 | cmp [use_params], 1 |
- | |
403 | je @f |
- | |
404 | mov esi, buf_cmd+5 |
- | |
405 | invoke con_gets, esi, 256 |
- | |
406 | - | ||
407 | @@: |
- | |
408 | ; find end of string |
- | |
409 | mov edi, buf_cmd+5 |
- | |
410 | mov ecx, 256 |
- | |
411 | xor al, al |
- | |
412 | repne scasb |
- | |
413 | lea esi, [edi-buf_cmd] |
- | |
414 | mov word[edi-2], 0x0a0d |
- | |
415 | ; and send it to the server |
- | |
416 | mcall send, [controlsocket], buf_cmd, , 0 |
- | |
417 | - | ||
418 | invoke con_write_asciiz, str_newline |
- | |
419 | invoke con_set_flags, 0x07 ; reset color |
- | |
420 | jmp wait_for_servercommand |
501 | icall eax, interface_addr, interface.print, str_unknown |
421 | 502 | jmp wait_for_usercommand |
|
Line 422... | Line 503... | ||
422 | 503 | ||
423 | 504 | ||
Line 549... | Line 630... | ||
549 | jnz @r |
630 | jnz @r |
Line 550... | Line 631... | ||
550 | 631 | ||
551 | pop ecx ebx edx |
632 | pop ecx ebx edx |
Line -... | Line 633... | ||
- | 633 | ret |
|
- | 634 | ||
- | 635 | ||
- | 636 | ;;================================================================================================;; |
|
- | 637 | write_to_file: ;//////////////////////////////////////////////////////////////////////////////////;; |
|
- | 638 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 639 | ;? Writes input buffer to log file ;; |
|
- | 640 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 641 | ;> eax = pointer to buffer ;; |
|
- | 642 | ;> ecx = size of buffer ;; |
|
- | 643 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 644 | ;< eax = status of SF 70.3 ;; |
|
- | 645 | ;;================================================================================================;; |
|
- | 646 | mov [filestruct2.subfn], 3 |
|
- | 647 | m2m [filestruct2.offset], [logfile_offset] |
|
- | 648 | mov [filestruct2.size], ecx |
|
- | 649 | mov [filestruct2.ptr], eax |
|
- | 650 | mov [filestruct2.name], log_file |
|
- | 651 | mcall 70, filestruct2 |
|
- | 652 | test eax, eax |
|
- | 653 | jz @f |
|
- | 654 | mov [logfile_offset], -1 ; disable logging |
|
- | 655 | call error_fs |
|
552 | ret |
656 | icall ebx, interface_addr, interface.print, str_no_logging |
- | 657 | ret |
|
- | 658 | @@: |
|
- | 659 | mov eax, [logfile_offset] |
|
- | 660 | add eax, ecx |
|
- | 661 | mov [logfile_offset], eax |
|
- | 662 | ret |
|
- | 663 | ||
- | 664 | ;;================================================================================================;; |
|
- | 665 | error: ;//////////////////////////////////////////////////////////////////////////////////////////;; |
|
- | 666 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 667 | ;? Generic error routine. Prints the error string passed to it. ;; |
|
- | 668 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 669 | ;> eax = pointer to the error string ;; |
|
- | 670 | ;;------------------------------------------------------------------------------------------------;; |
|
553 | 671 | ;< none ;; |
|
554 | error: |
672 | ;;================================================================================================;; |
555 | push eax |
673 | push eax |
556 | invoke con_set_flags, 0x0c ; print errors in red |
674 | icall ebx, interface_addr, interface.set_flags, 0x0c ; print errors in red |
557 | pop eax |
675 | pop eax |
Line -... | Line 676... | ||
- | 676 | icall ebx, interface_addr, interface.print, eax |
|
- | 677 | jmp wait_for_keypress |
|
- | 678 | ||
- | 679 | ||
- | 680 | ; Error handling block for filesystem errors |
|
- | 681 | error_fs: |
|
- | 682 | ||
- | 683 | cmp eax, 12 |
|
- | 684 | jne @f |
|
- | 685 | mov ebx, str_fs_err_12 |
|
- | 686 | @@: |
|
- | 687 | cmp eax, 11 |
|
- | 688 | jne @f |
|
- | 689 | mov ebx, str_fs_err_11 |
|
- | 690 | @@: |
|
- | 691 | cmp eax, 10 |
|
- | 692 | jne @f |
|
- | 693 | mov ebx, str_fs_err_10 |
|
- | 694 | @@: |
|
- | 695 | cmp eax, 9 |
|
- | 696 | jne @f |
|
- | 697 | mov ebx, str_fs_err_9 |
|
- | 698 | @@: |
|
- | 699 | cmp eax, 8 |
|
- | 700 | jne @f |
|
- | 701 | mov ebx, str_fs_err_8 |
|
- | 702 | @@: |
|
- | 703 | cmp eax, 7 |
|
- | 704 | jne @f |
|
- | 705 | mov ebx, str_fs_err_7 |
|
- | 706 | @@: |
|
- | 707 | cmp eax, 6 |
|
- | 708 | jne @f |
|
- | 709 | mov ebx, str_fs_err_6 |
|
- | 710 | @@: |
|
- | 711 | cmp eax, 5 |
|
- | 712 | jne @f |
|
- | 713 | mov ebx, str_fs_err_5 |
|
- | 714 | @@: |
|
- | 715 | cmp eax, 3 |
|
- | 716 | jne @f |
|
- | 717 | mov ebx, str_fs_err_3 |
|
- | 718 | @@: |
|
- | 719 | cmp eax, 2 |
|
- | 720 | jne @f |
|
- | 721 | mov ebx, str_fs_err_2 |
|
- | 722 | @@: |
|
- | 723 | mov edi, fs_error_code |
|
- | 724 | call dword_ascii ; convert error code in eax to ascii |
|
- | 725 | icall eax, interface_addr, interface.set_flags, 0x0c ; print errors in red |
|
- | 726 | icall eax, interface_addr, interface.print, str_err_fs, fs_error_code, ebx |
|
- | 727 | mov word[fs_error_code], ' ' ; clear error code for next time |
|
- | 728 | icall eax, interface_addr, interface.set_flags, 0x0a |
|
558 | invoke con_write_asciiz, eax |
729 | |
559 | jmp wait_for_keypress |
730 | ret |
560 | 731 | ||
Line 561... | Line 732... | ||
561 | error_heap: |
732 | error_heap: |
562 | invoke con_set_flags, 0x0c ; print errors in red |
- | |
563 | invoke con_write_asciiz, str_err_heap |
- | |
564 | - | ||
565 | wait_for_keypress: |
733 | icall eax, interface_addr, interface.set_flags, 0x0c ; print errors in red |
- | 734 | icall eax, interface_addr, interface.print, str_err_heap |
|
566 | invoke con_set_flags, 0x07 ; reset color to grey |
735 | |
567 | invoke con_write_asciiz, str_push |
- | |
568 | invoke con_getch2 |
- | |
569 | mcall close, [controlsocket] |
736 | wait_for_keypress: |
Line 570... | Line 737... | ||
570 | jmp main |
737 | mcall close, [controlsocket] |
571 | 738 | icall eax, interface_addr, interface.set_flags, 0x07 ; reset color to grey |
|
572 | done: |
739 | icall eax, interface_addr, interface.print, str_push |
573 | invoke con_exit, 1 |
740 | ijmp eax, interface_addr, interface.error |
Line 580... | Line 747... | ||
580 | 747 | ||
581 | 748 | ||
582 | ; data |
749 | ; data |
583 | str_title db 'FTP client',0 |
750 | str_title db 'FTP client',0 |
584 | str_welcome db 'FTP client for KolibriOS v0.12',10 |
751 | str_welcome db 'FTP client for KolibriOS v0.12',10 |
585 | db 10 |
- | |
586 | db 'Please enter ftp server address.',10,0 |
- | |
Line 587... | Line 752... | ||
587 | 752 | db 10,0 |
|
588 | str_ftp db 'ftp://',0 |
753 | str_srv_addr db 'Please enter ftp server address.',10,0 |
589 | 754 | ||
590 | str_prompt db '> ',0 |
755 | str_prompt db '> ',0 |
Line 599... | Line 764... | ||
599 | str_err_heap db 10,'Cannot allocate memory from heap.',10,0 |
764 | str_err_heap db 10,'Cannot allocate memory from heap.',10,0 |
600 | str_err_timeout db 10,'Timeout - no response from server.',10,0 |
765 | str_err_timeout db 10,'Timeout - no response from server.',10,0 |
601 | str_err_connect db 10,'[75,4 connect]: Cannot connect to the server.',10,0 |
766 | str_err_connect db 10,'[75,4 connect]: Cannot connect to the server.',10,0 |
602 | str_err_host db 10,'Invalid hostname.',10,0 |
767 | str_err_host db 10,'Invalid hostname.',10,0 |
603 | str_err_params db 10,'Invalid parameters',10,0 |
768 | str_err_params db 10,'Invalid parameters',10,0 |
- | 769 | str_err_fs db 10,'File system error: code ',0 |
|
- | 770 | fs_error_code db ' ',0 ; file system error code |
|
- | 771 | str_fs_err_2 db ' [Function is not supported for the given file system]',10,0 |
|
- | 772 | str_fs_err_3 db ' [Unknown file system]',10,0 |
|
- | 773 | str_fs_err_5 db ' [File/Folder not found]',10,0 |
|
- | 774 | str_fs_err_6 db ' [End of file, EOF]',10,0 |
|
- | 775 | str_fs_err_7 db ' [Pointer lies outside of application memory]',10,0 |
|
- | 776 | str_fs_err_8 db ' [Disk is full]',10,0 |
|
- | 777 | str_fs_err_9 db ' [File system error]',10,0 |
|
- | 778 | str_fs_err_10 db ' [Access denied]',10,0 |
|
- | 779 | str_fs_err_11 db ' [Device error]',10,0 |
|
- | 780 | str_fs_err_12 db ' [File system requires more memory]',10,0 |
|
604 | str8 db ' (',0 |
781 | str8 db ' (',0 |
605 | str9 db ')',10,0 |
782 | str9 db ')',10,0 |
606 | str_push db 'Push any key to continue.',0 |
783 | str_push db 'Push any key to continue.',0 |
607 | str_connect db 'Connecting...',10,0 |
784 | str_connect db 'Connecting...',10,0 |
608 | str_waiting db 'Waiting for welcome message.',10,0 |
785 | str_waiting db 'Waiting for welcome message.',10,0 |
609 | str_user db "username: ",0 |
786 | str_user db "username: ",0 |
610 | str_pass db "password: ",0 |
787 | str_pass db "password: ",0 |
- | 788 | str_port db "port (default 21): ",0 |
|
- | 789 | str_path db "path (optional): ",0 |
|
611 | str_unknown db "Unknown command or insufficient parameters - type help for more information.",10,0 |
790 | str_unknown db "Unknown command or insufficient parameters - type help for more information.",10,0 |
612 | str_lcwd db "Local working directory is now: ",0 |
791 | str_lcwd db "Local working directory is now: ",0 |
- | 792 | str_bytes_done db ' ',0 |
|
- | 793 | str_downloaded db 'Downloaded ',0 |
|
- | 794 | str_bytes db ' bytes',13,0 |
|
- | 795 | str_args_err db 'Invalid arguments. USAGE: ftpc [-cli] [ftp://username:password@server:port/path]',10,0 |
|
Line 613... | Line 796... | ||
613 | 796 | ||
614 | str_open db "opening data socket",10,0 |
797 | str_open db "opening data socket",10,0 |
615 | str_close db 10,"closing data socket",10,0 |
798 | str_close db 10,"closing data socket",10,0 |
Line 636... | Line 819... | ||
636 | str_port_start db 'port_start', 0 |
819 | str_port_start db 'port_start', 0 |
637 | str_port_stop db 'port_stop', 0 |
820 | str_port_stop db 'port_stop', 0 |
638 | str_ip db 'ip', 0 |
821 | str_ip db 'ip', 0 |
639 | str_dir db 'dir', 0 |
822 | str_dir db 'dir', 0 |
640 | str_general db 'general', 0 |
823 | str_general db 'general', 0 |
- | 824 | str_logfile db 'logfile',0 |
|
- | 825 | str_no_logging db 'Error writing to log file. Logging disabled',0 |
|
Line 641... | Line 826... | ||
641 | 826 | ||
642 | queued dd 0 |
827 | queued dd 0 |
Line -... | Line 828... | ||
- | 828 | mode db 0 ; passive = 0, active = 1 |
|
643 | mode db 0 ; passive = 0, active = 1 |
829 | |
Line 644... | Line 830... | ||
644 | 830 | ||
645 | ; FTP strings |
831 | ; FTP strings |
Line 657... | Line 843... | ||
657 | dw AF_INET4 |
843 | dw AF_INET4 |
658 | .port dw ? |
844 | .port dw ? |
659 | .ip dd ? |
845 | .ip dd ? |
660 | rb 10 |
846 | rb 10 |
Line -... | Line 847... | ||
- | 847 | ||
- | 848 | struc interface |
|
- | 849 | { |
|
- | 850 | .init dd 0 |
|
- | 851 | .server_addr dd 4 |
|
- | 852 | .get_username dd 8 |
|
- | 853 | .get_cmd dd 12 |
|
- | 854 | .print dd 16 |
|
- | 855 | .set_flags dd 20 |
|
- | 856 | .list dd 24 |
|
- | 857 | .progress dd 28 |
|
- | 858 | .error dd 32 |
|
- | 859 | } |
|
- | 860 | interface interface |
|
661 | 861 | ||
662 | ; import |
862 | ; import |
663 | align 4 |
863 | align 4 |
Line 664... | Line 864... | ||
664 | @IMPORT: |
864 | @IMPORT: |
Line 665... | Line 865... | ||
665 | 865 | ||
666 | library network, 'network.obj', console, 'console.obj', libini, 'libini.obj' |
866 | library network, 'network.obj', libini, 'libini.obj' |
667 | 867 | ||
668 | import network, \ |
868 | import network, \ |
Line 669... | Line -... | ||
669 | getaddrinfo, 'getaddrinfo', \ |
- | |
670 | freeaddrinfo, 'freeaddrinfo', \ |
- | |
671 | inet_ntoa, 'inet_ntoa' |
- | |
672 | - | ||
673 | import console, \ |
- | |
674 | con_start, 'START', \ |
- | |
675 | con_init, 'con_init', \ |
- | |
676 | con_write_asciiz,'con_write_asciiz', \ |
- | |
677 | con_exit, 'con_exit', \ |
- | |
678 | con_gets, 'con_gets',\ |
- | |
679 | con_cls, 'con_cls',\ |
- | |
680 | con_getch2, 'con_getch2',\ |
- | |
681 | con_set_cursor_pos, 'con_set_cursor_pos',\ |
- | |
682 | con_write_string, 'con_write_string',\ |
869 | getaddrinfo, 'getaddrinfo', \ |
683 | con_get_flags, 'con_get_flags', \ |
870 | freeaddrinfo, 'freeaddrinfo', \ |
684 | con_set_flags, 'con_set_flags' |
871 | inet_ntoa, 'inet_ntoa' |
Line 685... | Line 872... | ||
685 | 872 | ||
Line 686... | Line 873... | ||
686 | import libini, \ |
873 | import libini, \ |
Line -... | Line 874... | ||
- | 874 | ini.get_str, 'ini_get_str', \ |
|
- | 875 | ini.get_int, 'ini_get_int' |
|
687 | ini.get_str, 'ini_get_str',\ |
876 | |
Line -... | Line 877... | ||
- | 877 | ||
- | 878 | i_end: |
|
688 | ini.get_int, 'ini_get_int' |
879 | |
689 | 880 | ; uninitialised data |
|
690 | 881 | ||
691 | i_end: |
882 | interface_addr rd 1 |
692 | 883 | ||
Line 717... | Line 908... | ||
717 | dd ? |
908 | dd ? |
718 | .size dd ? |
909 | .size dd ? |
719 | .ptr dd ? |
910 | .ptr dd ? |
720 | .name rb 1024 |
911 | .name rb 1024 |
Line -... | Line 912... | ||
- | 912 | ||
- | 913 | filestruct2: |
|
- | 914 | .subfn dd ? |
|
- | 915 | .offset dd ? |
|
- | 916 | dd 0 |
|
- | 917 | .size dd ? |
|
- | 918 | .ptr dd ? |
|
- | 919 | db 0 |
|
- | 920 | .name dd ? |
|
- | 921 | ||
- | 922 | folder_buf rb 40 |
|
- | 923 | ||
721 | 924 | ||
722 | buf_buffer1 rb BUFFERSIZE+1 |
925 | buf_buffer1 rb BUFFERSIZE+1 |
723 | buf_buffer2 rb BUFFERSIZE+1 |
926 | buf_buffer2 rb BUFFERSIZE+1 |
- | 927 | buf_cmd rb 1024 ; buffer for holding command string |
|
- | 928 | log_file rb 512 ; holds log file path |
|
Line 724... | Line 929... | ||
724 | buf_cmd rb 1024 ; buffer for holding command string |
929 | logfile_offset rd 1 |
Line 725... | Line 930... | ||
725 | 930 | ||
726 | path rb 1024 |
931 | path rb 1024 |
727 | 932 | ||
728 | use_params db 0 |
933 | initial_login rb 1 |
729 | param_user rb 1024 |
934 | param_user rb 1024 |
- | 935 | param_password rb 1024 |
|
- | 936 | param_server_addr rb 1024 |
|
- | 937 | param_path rb 1024 |
|
- | 938 | param_port rb 6 |
|
Line 730... | Line 939... | ||
730 | param_password rb 1024 |
939 |