forked from KolibriOS/kolibrios
Added RDIR command to FTPC
git-svn-id: svn://kolibrios.org@4922 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
7315bb05c0
commit
5386a3ea58
@ -27,7 +27,8 @@ OPERATION_NONE = 0
|
|||||||
OPERATION_LIST = 1
|
OPERATION_LIST = 1
|
||||||
OPERATION_RETR = 2
|
OPERATION_RETR = 2
|
||||||
OPERATION_STOR = 3
|
OPERATION_STOR = 3
|
||||||
|
OPERATION_RDIR = 4
|
||||||
|
|
||||||
use32
|
use32
|
||||||
; standard header
|
; standard header
|
||||||
db 'MENUET01' ; signature
|
db 'MENUET01' ; signature
|
||||||
@ -36,7 +37,7 @@ use32
|
|||||||
dd i_end ; initialized size
|
dd i_end ; initialized size
|
||||||
dd mem+0x1000 ; required memory
|
dd mem+0x1000 ; required memory
|
||||||
dd mem+0x1000 ; stack pointer
|
dd mem+0x1000 ; stack pointer
|
||||||
dd s ; parameters
|
dd buf_cmd ; parameters
|
||||||
dd 0 ; path
|
dd 0 ; path
|
||||||
|
|
||||||
include '../../macros.inc'
|
include '../../macros.inc'
|
||||||
@ -49,6 +50,11 @@ include 'usercommands.inc'
|
|||||||
include 'servercommands.inc'
|
include 'servercommands.inc'
|
||||||
|
|
||||||
start:
|
start:
|
||||||
|
; initialize heap for using dynamic blocks
|
||||||
|
mcall 68,11
|
||||||
|
test eax,eax
|
||||||
|
je exit2
|
||||||
|
|
||||||
; disable all events except network event
|
; disable all events except network event
|
||||||
mcall 40, EV_STACK
|
mcall 40, EV_STACK
|
||||||
; load libraries
|
; load libraries
|
||||||
@ -59,7 +65,7 @@ start:
|
|||||||
invoke con_start, 1
|
invoke con_start, 1
|
||||||
invoke con_init, 80, 25, 80, 250, str_title
|
invoke con_init, 80, 25, 80, 250, str_title
|
||||||
; Check for parameters, if there are some, resolve the address right away
|
; Check for parameters, if there are some, resolve the address right away
|
||||||
cmp byte [s], 0
|
cmp byte [buf_cmd], 0
|
||||||
jne resolve
|
jne resolve
|
||||||
|
|
||||||
main:
|
main:
|
||||||
@ -71,11 +77,11 @@ main:
|
|||||||
invoke con_set_flags, 0x0a
|
invoke con_set_flags, 0x0a
|
||||||
invoke con_write_asciiz, str_prompt
|
invoke con_write_asciiz, str_prompt
|
||||||
; read string
|
; read string
|
||||||
invoke con_gets, s, 256
|
invoke con_gets, buf_cmd, 256
|
||||||
; check for exit
|
; check for exit
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz done
|
jz done
|
||||||
cmp byte [s], 10
|
cmp byte [buf_cmd], 10
|
||||||
jz done
|
jz done
|
||||||
; reset color back to grey and print newline
|
; reset color back to grey and print newline
|
||||||
invoke con_set_flags, 0x07
|
invoke con_set_flags, 0x07
|
||||||
@ -83,7 +89,7 @@ main:
|
|||||||
|
|
||||||
resolve:
|
resolve:
|
||||||
; delete terminating '\n'
|
; delete terminating '\n'
|
||||||
mov esi, s
|
mov esi, buf_cmd
|
||||||
@@:
|
@@:
|
||||||
lodsb
|
lodsb
|
||||||
cmp al, 0x20
|
cmp al, 0x20
|
||||||
@ -91,10 +97,10 @@ resolve:
|
|||||||
mov byte [esi-1], 0
|
mov byte [esi-1], 0
|
||||||
; Say to the user that we're resolving
|
; Say to the user that we're resolving
|
||||||
invoke con_write_asciiz, str_resolve
|
invoke con_write_asciiz, str_resolve
|
||||||
invoke con_write_asciiz, s
|
invoke con_write_asciiz, buf_cmd
|
||||||
; resolve name
|
; resolve name
|
||||||
push esp ; reserve stack place
|
push esp ; reserve stack place
|
||||||
invoke getaddrinfo, s, 0, 0, esp
|
invoke getaddrinfo, buf_cmd, 0, 0, esp
|
||||||
pop esi
|
pop esi
|
||||||
; test for error
|
; test for error
|
||||||
test eax, eax
|
test eax, eax
|
||||||
@ -130,7 +136,7 @@ wait_for_servercommand:
|
|||||||
cmp [offset], 0
|
cmp [offset], 0
|
||||||
je .receive ; nope, receive some more
|
je .receive ; nope, receive some more
|
||||||
mov esi, [offset]
|
mov esi, [offset]
|
||||||
mov edi, s
|
mov edi, buf_cmd
|
||||||
mov ecx, [size]
|
mov ecx, [size]
|
||||||
add ecx, esi
|
add ecx, esi
|
||||||
jmp .byteloop
|
jmp .byteloop
|
||||||
@ -145,7 +151,7 @@ wait_for_servercommand:
|
|||||||
mcall 26, 9
|
mcall 26, 9
|
||||||
cmp eax, [timeout]
|
cmp eax, [timeout]
|
||||||
jge error_timeout
|
jge error_timeout
|
||||||
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT
|
mcall recv, [socketnum], buf_buffer1, BUFFERSIZE, MSG_DONTWAIT
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jnz .got_data
|
jnz .got_data
|
||||||
cmp ebx, EWOULDBLOCK
|
cmp ebx, EWOULDBLOCK
|
||||||
@ -155,10 +161,10 @@ wait_for_servercommand:
|
|||||||
.got_data:
|
.got_data:
|
||||||
mov [offset], 0
|
mov [offset], 0
|
||||||
|
|
||||||
; extract commands, copy them to "s" buffer
|
; extract commands, copy them to "buf_cmd" buffer
|
||||||
lea ecx, [eax + buffer_ptr] ; ecx = end pointer
|
lea ecx, [eax + buf_buffer1] ; ecx = end pointer
|
||||||
mov esi, buffer_ptr ; esi = current pointer
|
mov esi, buf_buffer1 ; esi = current pointer
|
||||||
mov edi, s
|
mov edi, buf_cmd
|
||||||
.byteloop:
|
.byteloop:
|
||||||
cmp esi, ecx
|
cmp esi, ecx
|
||||||
jae wait_for_servercommand
|
jae wait_for_servercommand
|
||||||
@ -179,12 +185,12 @@ wait_for_servercommand:
|
|||||||
.no_more_data:
|
.no_more_data:
|
||||||
mov [offset], 0
|
mov [offset], 0
|
||||||
.go_cmd:
|
.go_cmd:
|
||||||
lea ecx, [edi - s] ; length of command
|
lea ecx, [edi - buf_cmd] ; length of command
|
||||||
xor al, al
|
xor al, al
|
||||||
stosb
|
stosb
|
||||||
|
|
||||||
invoke con_set_flags, 0x03 ; change color
|
invoke con_set_flags, 0x03 ; change color
|
||||||
invoke con_write_asciiz, s ; print servercommand
|
invoke con_write_asciiz, buf_cmd ; print servercommand
|
||||||
invoke con_write_asciiz, str_newline
|
invoke con_write_asciiz, str_newline
|
||||||
invoke con_set_flags, 0x07 ; reset color
|
invoke con_set_flags, 0x07 ; reset color
|
||||||
|
|
||||||
@ -194,6 +200,11 @@ wait_for_servercommand:
|
|||||||
|
|
||||||
wait_for_usercommand:
|
wait_for_usercommand:
|
||||||
|
|
||||||
|
; Are there any files in the transfer queue?
|
||||||
|
|
||||||
|
cmp [queued], 0
|
||||||
|
ja transfer_queued ; Yes, transfer those first.
|
||||||
|
|
||||||
; change color to green for user input
|
; change color to green for user input
|
||||||
invoke con_set_flags, 0x0a
|
invoke con_set_flags, 0x0a
|
||||||
|
|
||||||
@ -207,53 +218,56 @@ wait_for_usercommand:
|
|||||||
; write prompt
|
; write prompt
|
||||||
invoke con_write_asciiz, str_prompt
|
invoke con_write_asciiz, str_prompt
|
||||||
; read string
|
; read string
|
||||||
invoke con_gets, s, 256
|
invoke con_gets, buf_cmd, 256
|
||||||
|
|
||||||
; print a newline and reset the color back to grey
|
; print a newline and reset the color back to grey
|
||||||
invoke con_write_asciiz, str_newline
|
invoke con_write_asciiz, str_newline
|
||||||
invoke con_set_flags, 0x07
|
invoke con_set_flags, 0x07
|
||||||
|
|
||||||
cmp dword[s], "cwd "
|
cmp dword[buf_cmd], "cwd "
|
||||||
je cmd_cwd
|
je cmd_cwd
|
||||||
|
|
||||||
cmp dword[s], "mkd "
|
cmp dword[buf_cmd], "mkd "
|
||||||
je cmd_mkd
|
je cmd_mkd
|
||||||
|
|
||||||
cmp dword[s], "rmd "
|
cmp dword[buf_cmd], "rmd "
|
||||||
je cmd_rmd
|
je cmd_rmd
|
||||||
|
|
||||||
cmp dword[s], "pwd" + 10 shl 24
|
cmp dword[buf_cmd], "pwd" + 10 shl 24
|
||||||
je cmd_pwd
|
je cmd_pwd
|
||||||
|
|
||||||
cmp dword[s], "bye" + 10 shl 24
|
cmp dword[buf_cmd], "bye" + 10 shl 24
|
||||||
je cmd_bye
|
je cmd_bye
|
||||||
|
|
||||||
cmp byte[s+4], " "
|
cmp dword[buf_cmd], "rdir"
|
||||||
|
je cmd_rdir
|
||||||
|
|
||||||
|
cmp byte[buf_cmd+4], " "
|
||||||
jne @f
|
jne @f
|
||||||
|
|
||||||
cmp dword[s], "lcwd"
|
cmp dword[buf_cmd], "lcwd"
|
||||||
je cmd_lcwd
|
je cmd_lcwd
|
||||||
|
|
||||||
cmp dword[s], "retr"
|
cmp dword[buf_cmd], "retr"
|
||||||
je cmd_retr
|
je cmd_retr
|
||||||
|
|
||||||
cmp dword[s], "stor"
|
cmp dword[buf_cmd], "stor"
|
||||||
je cmd_stor
|
je cmd_stor
|
||||||
|
|
||||||
cmp dword[s], "dele"
|
cmp dword[buf_cmd], "dele"
|
||||||
je cmd_dele
|
je cmd_dele
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
cmp byte[s+4], 10
|
cmp byte[buf_cmd+4], 10
|
||||||
jne @f
|
jne @f
|
||||||
|
|
||||||
cmp dword[s], "list"
|
cmp dword[buf_cmd], "list"
|
||||||
je cmd_list
|
je cmd_list
|
||||||
|
|
||||||
cmp dword[s], "help"
|
cmp dword[buf_cmd], "help"
|
||||||
je cmd_help
|
je cmd_help
|
||||||
|
|
||||||
cmp dword[s], "cdup"
|
cmp dword[buf_cmd], "cdup"
|
||||||
je cmd_cdup
|
je cmd_cdup
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
@ -265,32 +279,32 @@ wait_for_usercommand:
|
|||||||
.connected:
|
.connected:
|
||||||
; request username
|
; request username
|
||||||
invoke con_write_asciiz, str_user
|
invoke con_write_asciiz, str_user
|
||||||
mov dword[s], "USER"
|
mov dword[buf_cmd], "USER"
|
||||||
mov byte[s+4], " "
|
mov byte[buf_cmd+4], " "
|
||||||
jmp .send
|
jmp .send
|
||||||
|
|
||||||
|
|
||||||
.needpass:
|
.needpass:
|
||||||
; request password
|
; request password
|
||||||
invoke con_write_asciiz, str_pass
|
invoke con_write_asciiz, str_pass
|
||||||
mov dword[s], "PASS"
|
mov dword[buf_cmd], "PASS"
|
||||||
mov byte[s+4], " "
|
mov byte[buf_cmd+4], " "
|
||||||
invoke con_set_flags, 0x00 ; black text on black background for password
|
invoke con_set_flags, 0x00 ; black text on black background for password
|
||||||
|
|
||||||
.send:
|
.send:
|
||||||
; read string
|
; read string
|
||||||
mov esi, s+5
|
mov esi, buf_cmd+5
|
||||||
invoke con_gets, esi, 256
|
invoke con_gets, esi, 256
|
||||||
|
|
||||||
; find end of string
|
; find end of string
|
||||||
mov edi, s+5
|
mov edi, buf_cmd+5
|
||||||
mov ecx, 256
|
mov ecx, 256
|
||||||
xor al, al
|
xor al, al
|
||||||
repne scasb
|
repne scasb
|
||||||
lea esi, [edi-s]
|
lea esi, [edi-buf_cmd]
|
||||||
mov word[edi-2], 0x0a0d
|
mov word[edi-2], 0x0a0d
|
||||||
; and send it to the server
|
; and send it to the server
|
||||||
mcall send, [socketnum], s, , 0
|
mcall send, [socketnum], buf_cmd, , 0
|
||||||
|
|
||||||
invoke con_write_asciiz, str_newline
|
invoke con_write_asciiz, str_newline
|
||||||
invoke con_set_flags, 0x07 ; reset color
|
invoke con_set_flags, 0x07 ; reset color
|
||||||
@ -332,6 +346,10 @@ error_resolve:
|
|||||||
invoke con_set_flags, 0x0c ; print errors in red
|
invoke con_set_flags, 0x0c ; print errors in red
|
||||||
invoke con_write_asciiz, str_err_resolve
|
invoke con_write_asciiz, str_err_resolve
|
||||||
|
|
||||||
|
error_heap:
|
||||||
|
invoke con_set_flags, 0x0c ; print errors in red
|
||||||
|
invoke con_write_asciiz, str_err_heap
|
||||||
|
|
||||||
wait_for_keypress:
|
wait_for_keypress:
|
||||||
invoke con_set_flags, 0x07 ; reset color to grey
|
invoke con_set_flags, 0x07 ; reset color to grey
|
||||||
invoke con_write_asciiz, str_push
|
invoke con_write_asciiz, str_push
|
||||||
@ -344,6 +362,7 @@ done:
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
mcall close, [socketnum]
|
mcall close, [socketnum]
|
||||||
|
exit2:
|
||||||
mcall -1
|
mcall -1
|
||||||
|
|
||||||
|
|
||||||
@ -359,6 +378,7 @@ str_resolve db 'Resolving ',0
|
|||||||
str_newline db 10,0
|
str_newline db 10,0
|
||||||
str_err_resolve db 10,'Name resolution failed.',10,0
|
str_err_resolve db 10,'Name resolution failed.',10,0
|
||||||
str_err_socket db 10,'Socket error.',10,0
|
str_err_socket db 10,'Socket error.',10,0
|
||||||
|
str_err_heap db 10,'Cannot allocate memory from heap.',10,0
|
||||||
str_err_timeout db 10,'Timeout - no response from server.',10,0
|
str_err_timeout db 10,'Timeout - no response from server.',10,0
|
||||||
str_err_connect db 10,'Cannot connect to the server.',10,0
|
str_err_connect db 10,'Cannot connect to the server.',10,0
|
||||||
str8 db ' (',0
|
str8 db ' (',0
|
||||||
@ -372,8 +392,8 @@ str_unknown db "Unknown command or insufficient parameters - type help for m
|
|||||||
str_lcwd db "Local working directory is now: ",0
|
str_lcwd db "Local working directory is now: ",0
|
||||||
|
|
||||||
str_open db "opening data socket",10,0
|
str_open db "opening data socket",10,0
|
||||||
str_close db "closing data socket",10,0
|
str_close db 10,"closing data socket",10,0
|
||||||
str2b db '.',0
|
str_dot db '.',0
|
||||||
|
|
||||||
str_help db "available commands:",10
|
str_help db "available commands:",10
|
||||||
db 10
|
db 10
|
||||||
@ -388,8 +408,10 @@ str_help db "available commands:",10
|
|||||||
db "retr <file> - retreive file from the server",10
|
db "retr <file> - retreive file from the server",10
|
||||||
db "rmd <directory> - remove directory from the server",10
|
db "rmd <directory> - remove directory from the server",10
|
||||||
db "stor <file> - store file on the server",10
|
db "stor <file> - store file on the server",10
|
||||||
|
db "rdir - retreive all files from current server dir",10
|
||||||
db 10,0
|
db 10,0
|
||||||
|
|
||||||
|
queued dd 0
|
||||||
|
|
||||||
; FTP strings
|
; FTP strings
|
||||||
|
|
||||||
@ -446,7 +468,10 @@ offset dd ?
|
|||||||
size dd ?
|
size dd ?
|
||||||
operation dd ?
|
operation dd ?
|
||||||
|
|
||||||
|
size_fname dd ?
|
||||||
|
ptr_queue dd ?
|
||||||
timeout dd ?
|
timeout dd ?
|
||||||
|
ptr_fname_start dd ?
|
||||||
|
|
||||||
filestruct:
|
filestruct:
|
||||||
.subfn dd ?
|
.subfn dd ?
|
||||||
@ -456,9 +481,8 @@ filestruct:
|
|||||||
.ptr dd ?
|
.ptr dd ?
|
||||||
.name rb 1024
|
.name rb 1024
|
||||||
|
|
||||||
buffer_ptr rb BUFFERSIZE+1
|
buf_buffer1 rb BUFFERSIZE+1
|
||||||
buffer_ptr2 rb BUFFERSIZE+1
|
buf_buffer2 rb BUFFERSIZE+1
|
||||||
|
buf_cmd rb 1024 ; buffer for holding command string
|
||||||
s rb 1024
|
|
||||||
|
|
||||||
mem:
|
mem:
|
||||||
|
@ -5,40 +5,40 @@ server_parser:
|
|||||||
; first lines will have a dash instead of space after numbers,
|
; first lines will have a dash instead of space after numbers,
|
||||||
; thus they are simply ignored in this simple command parser.
|
; thus they are simply ignored in this simple command parser.
|
||||||
|
|
||||||
cmp dword[s], "150 "
|
cmp dword[buf_cmd], "150 "
|
||||||
je data_loop
|
je data_loop
|
||||||
|
|
||||||
cmp dword[s], "220 "
|
cmp dword[buf_cmd], "220 "
|
||||||
je welcome
|
je welcome
|
||||||
|
|
||||||
; cmp dword[s], "226 "
|
; cmp dword[buf_cmd], "226 "
|
||||||
; je transfer_ok
|
; je transfer_ok
|
||||||
|
|
||||||
cmp dword[s], "227 "
|
cmp dword[buf_cmd], "227 "
|
||||||
je pasv_ok
|
je pasv_ok
|
||||||
|
|
||||||
cmp dword[s], "230 "
|
cmp dword[buf_cmd], "230 "
|
||||||
je login_ok
|
je login_ok
|
||||||
|
|
||||||
; cmp dword[s], "250"
|
; cmp dword[buf_cmd], "250"
|
||||||
; je op_ok
|
; je op_ok
|
||||||
|
|
||||||
cmp dword[s], "331 "
|
cmp dword[buf_cmd], "331 "
|
||||||
je pass
|
je pass
|
||||||
|
|
||||||
; cmp dword[s], "421 "
|
; cmp dword[buf_cmd], "421 "
|
||||||
; je timeout
|
; je timeout
|
||||||
|
|
||||||
cmp dword[s], "503 " ; login first
|
cmp dword[buf_cmd], "503 " ; login first
|
||||||
je welcome
|
je welcome
|
||||||
|
|
||||||
cmp dword[s], "530 " ; password incorrect
|
cmp dword[buf_cmd], "530 " ; password incorrect
|
||||||
je welcome
|
je welcome
|
||||||
|
|
||||||
cmp dword[s], "550 "
|
cmp dword[buf_cmd], "550 "
|
||||||
je close_datacon
|
je close_datacon
|
||||||
|
|
||||||
cmp byte[s+3], "-"
|
cmp byte[buf_cmd+3], "-"
|
||||||
je wait_for_servercommand
|
je wait_for_servercommand
|
||||||
jmp wait_for_usercommand
|
jmp wait_for_usercommand
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ pasv_ok:
|
|||||||
sub ecx, 4
|
sub ecx, 4
|
||||||
jb .fail
|
jb .fail
|
||||||
mov al, "("
|
mov al, "("
|
||||||
mov edi, s + 4
|
mov edi, buf_cmd + 4
|
||||||
repne scasb
|
repne scasb
|
||||||
|
|
||||||
mcall socket, AF_INET4, SOCK_STREAM, 0
|
mcall socket, AF_INET4, SOCK_STREAM, 0
|
||||||
@ -102,27 +102,30 @@ pasv_ok:
|
|||||||
|
|
||||||
data_loop:
|
data_loop:
|
||||||
|
|
||||||
invoke con_write_asciiz, str2b
|
invoke con_write_asciiz, str_dot
|
||||||
|
|
||||||
cmp [operation], OPERATION_STOR
|
cmp [operation], OPERATION_STOR
|
||||||
je .stor
|
je .stor
|
||||||
|
|
||||||
; we are receiving data
|
; we are receiving data
|
||||||
mcall recv, [datasocket], buffer_ptr2, BUFFERSIZE, 0
|
mcall recv, [datasocket], buf_buffer2, BUFFERSIZE, 0
|
||||||
test ebx, ebx
|
test ebx, ebx
|
||||||
jnz .done
|
jnz .done
|
||||||
mov byte[buffer_ptr2 + eax], 0
|
mov byte[buf_buffer2 + eax], 0
|
||||||
|
|
||||||
cmp [operation], OPERATION_RETR
|
cmp [operation], OPERATION_RETR
|
||||||
je .retr
|
je .retr
|
||||||
|
|
||||||
|
cmp [operation], OPERATION_RDIR
|
||||||
|
je .rdir
|
||||||
|
|
||||||
; not retreiving, just print to console
|
; not retreiving, just print to console
|
||||||
invoke con_write_asciiz, buffer_ptr2
|
invoke con_write_asciiz, buf_buffer2
|
||||||
jmp data_loop
|
jmp data_loop
|
||||||
|
|
||||||
; retreiving, save to file
|
; retreiving, save to file
|
||||||
.retr:
|
.retr:
|
||||||
mov [filestruct.ptr], buffer_ptr2
|
mov [filestruct.ptr], buf_buffer2
|
||||||
mov [filestruct.size], eax
|
mov [filestruct.size], eax
|
||||||
push eax
|
push eax
|
||||||
mcall 70, filestruct
|
mcall 70, filestruct
|
||||||
@ -139,12 +142,12 @@ data_loop:
|
|||||||
; jne .fileerror
|
; jne .fileerror
|
||||||
add [filestruct.offset], ebx
|
add [filestruct.offset], ebx
|
||||||
mov esi, ebx
|
mov esi, ebx
|
||||||
mcall send, [datasocket], buffer_ptr2, , 0
|
mcall send, [datasocket], buf_buffer2, , 0
|
||||||
jmp .stor
|
jmp .stor
|
||||||
|
|
||||||
.last_call:
|
.last_call:
|
||||||
mov esi, ebx
|
mov esi, ebx
|
||||||
mcall send, [datasocket], buffer_ptr2, , 0
|
mcall send, [datasocket], buf_buffer2, , 0
|
||||||
|
|
||||||
.done:
|
.done:
|
||||||
invoke con_write_asciiz, str_close
|
invoke con_write_asciiz, str_close
|
||||||
@ -153,6 +156,108 @@ data_loop:
|
|||||||
jmp wait_for_servercommand
|
jmp wait_for_servercommand
|
||||||
|
|
||||||
|
|
||||||
|
.rdir:
|
||||||
|
cmp [size_fname], 0
|
||||||
|
jne .realloc
|
||||||
|
|
||||||
|
.malloc: ; create a new dynamic block
|
||||||
|
mov ecx, eax
|
||||||
|
inc ecx
|
||||||
|
|
||||||
|
mcall 68,12 ; eax now points to new buffer
|
||||||
|
|
||||||
|
test eax,eax
|
||||||
|
je error_heap
|
||||||
|
|
||||||
|
mov [ptr_fname_start], eax
|
||||||
|
|
||||||
|
jmp .rdir_init
|
||||||
|
|
||||||
|
.realloc: ; expand block created with .malloc
|
||||||
|
|
||||||
|
mov ecx, eax ; eax is size of buffer received
|
||||||
|
inc ecx
|
||||||
|
|
||||||
|
add ecx, [size_fname] ; added old size to form new required size
|
||||||
|
|
||||||
|
mcall 68,20,,[ptr_fname_start]
|
||||||
|
|
||||||
|
test eax, eax
|
||||||
|
je error_heap
|
||||||
|
|
||||||
|
mov [ptr_fname_start], eax ; eax contains the new block now
|
||||||
|
add eax, [size_fname]
|
||||||
|
|
||||||
|
.rdir_init: ; copies filenames into our buffer
|
||||||
|
|
||||||
|
mov esi, buf_buffer2
|
||||||
|
mov edi, eax
|
||||||
|
|
||||||
|
.copy_buf:
|
||||||
|
lodsb
|
||||||
|
cmp al,13 ; ignore any \r character
|
||||||
|
je .copy_buf
|
||||||
|
stosb
|
||||||
|
|
||||||
|
cmp al, 10
|
||||||
|
jne .not_end
|
||||||
|
inc [queued]
|
||||||
|
|
||||||
|
.not_end:
|
||||||
|
test al,al
|
||||||
|
jne .copy_buf
|
||||||
|
|
||||||
|
dec edi
|
||||||
|
dec edi
|
||||||
|
|
||||||
|
mov eax, [ptr_fname_start]
|
||||||
|
mov [ptr_queue], eax
|
||||||
|
|
||||||
|
sub edi, eax ; edi contains the current size now
|
||||||
|
mov [size_fname], edi
|
||||||
|
|
||||||
|
jmp data_loop
|
||||||
|
|
||||||
|
|
||||||
|
; files for rdir operation are queued
|
||||||
|
transfer_queued:
|
||||||
|
|
||||||
|
mov esi, [ptr_queue] ; always pointing to current part of ptr_fname_start
|
||||||
|
mov edi, buf_cmd+5 ; always point to filename for retr command
|
||||||
|
|
||||||
|
.build_filename:
|
||||||
|
lodsb
|
||||||
|
stosb
|
||||||
|
|
||||||
|
cmp al,10
|
||||||
|
je .get_file ; filename ends with character 10
|
||||||
|
test al,al
|
||||||
|
jz .null_found ; this should be end of buffer
|
||||||
|
jmp .build_filename
|
||||||
|
|
||||||
|
.null_found:
|
||||||
|
|
||||||
|
mov [queued],0
|
||||||
|
jmp .free
|
||||||
|
|
||||||
|
.get_file:
|
||||||
|
dec [queued]
|
||||||
|
jnz .after_free
|
||||||
|
|
||||||
|
.free:
|
||||||
|
mcall 68,13,[ptr_fname_start] ; freeing the buffer
|
||||||
|
test eax,eax
|
||||||
|
jz error_heap
|
||||||
|
jmp wait_for_usercommand
|
||||||
|
|
||||||
|
.after_free:
|
||||||
|
xor al,al ; appending 0 after retr command
|
||||||
|
stosb
|
||||||
|
mov eax, esi
|
||||||
|
mov [ptr_queue], eax
|
||||||
|
|
||||||
|
jmp cmd_retr
|
||||||
|
|
||||||
close_datacon:
|
close_datacon:
|
||||||
cmp [operation], OPERATION_NONE
|
cmp [operation], OPERATION_NONE
|
||||||
je wait_for_usercommand
|
je wait_for_usercommand
|
||||||
|
@ -9,9 +9,9 @@ cmd_help:
|
|||||||
cmd_bye:
|
cmd_bye:
|
||||||
|
|
||||||
; Send BYE message to the server
|
; Send BYE message to the server
|
||||||
mov dword[s], "BYE" + 13 shl 24
|
mov dword[buf_cmd], "BYE" + 13 shl 24
|
||||||
mov byte[s+4], 10
|
mov byte[buf_cmd+4], 10
|
||||||
mcall send, [socketnum], s, 5, 0
|
mcall send, [socketnum], buf_cmd, 5, 0
|
||||||
|
|
||||||
; Close the control connection
|
; Close the control connection
|
||||||
mcall close, [socketnum]
|
mcall close, [socketnum]
|
||||||
@ -20,42 +20,42 @@ cmd_bye:
|
|||||||
|
|
||||||
cmd_pwd:
|
cmd_pwd:
|
||||||
|
|
||||||
mov dword[s], "PWD" + 13 shl 24
|
mov dword[buf_cmd], "PWD" + 13 shl 24
|
||||||
mov byte[s+4], 10
|
mov byte[buf_cmd+4], 10
|
||||||
mcall send, [socketnum], s, 5, 0
|
mcall send, [socketnum], buf_cmd, 5, 0
|
||||||
|
|
||||||
jmp wait_for_servercommand
|
jmp wait_for_servercommand
|
||||||
|
|
||||||
|
|
||||||
cmd_cwd:
|
cmd_cwd:
|
||||||
|
|
||||||
mov dword[s], "CWD "
|
mov dword[buf_cmd], "CWD "
|
||||||
|
|
||||||
mov ecx, 256
|
mov ecx, 256
|
||||||
xor al, al
|
xor al, al
|
||||||
mov edi, s
|
mov edi, buf_cmd
|
||||||
repne scasb
|
repne scasb
|
||||||
lea esi, [edi - s]
|
lea esi, [edi - buf_cmd]
|
||||||
mov word [edi - 2], 0x0a0d
|
mov word [edi - 2], 0x0a0d
|
||||||
|
|
||||||
mcall send, [socketnum], s, , 0
|
mcall send, [socketnum], buf_cmd, , 0
|
||||||
|
|
||||||
jmp wait_for_servercommand
|
jmp wait_for_servercommand
|
||||||
|
|
||||||
|
|
||||||
cmd_dele:
|
cmd_dele:
|
||||||
|
|
||||||
mov dword[s], "DELE"
|
mov dword[buf_cmd], "DELE"
|
||||||
mov byte[s], " "
|
mov byte[buf_cmd], " "
|
||||||
|
|
||||||
mov ecx, 256
|
mov ecx, 256
|
||||||
xor al, al
|
xor al, al
|
||||||
mov edi, s
|
mov edi, buf_cmd
|
||||||
repne scasb
|
repne scasb
|
||||||
lea esi, [edi - s]
|
lea esi, [edi - buf_cmd]
|
||||||
mov word [edi - 2], 0x0a0d
|
mov word [edi - 2], 0x0a0d
|
||||||
|
|
||||||
mcall send, [socketnum], s, , 0
|
mcall send, [socketnum], buf_cmd, , 0
|
||||||
|
|
||||||
jmp wait_for_servercommand
|
jmp wait_for_servercommand
|
||||||
|
|
||||||
@ -65,9 +65,9 @@ cmd_list:
|
|||||||
|
|
||||||
mov [operation], OPERATION_LIST
|
mov [operation], OPERATION_LIST
|
||||||
|
|
||||||
mov dword[s], "LIST"
|
mov dword[buf_cmd], "LIST"
|
||||||
mov word[s+4], 0x0a0d
|
mov word[buf_cmd+4], 0x0a0d
|
||||||
mcall send, [socketnum], s, 6, 0
|
mcall send, [socketnum], buf_cmd, 6, 0
|
||||||
|
|
||||||
jmp wait_for_servercommand
|
jmp wait_for_servercommand
|
||||||
|
|
||||||
@ -77,7 +77,9 @@ cmd_retr:
|
|||||||
|
|
||||||
; Create/open the file
|
; Create/open the file
|
||||||
|
|
||||||
mov esi, s+5
|
; Create/open the file
|
||||||
|
|
||||||
|
mov esi, buf_cmd+5
|
||||||
mov ecx, 256-5
|
mov ecx, 256-5
|
||||||
call set_filename
|
call set_filename
|
||||||
|
|
||||||
@ -97,22 +99,36 @@ cmd_retr:
|
|||||||
mov [operation], OPERATION_RETR
|
mov [operation], OPERATION_RETR
|
||||||
|
|
||||||
; Request the file from server
|
; Request the file from server
|
||||||
|
|
||||||
mov dword[s], "RETR"
|
mov dword[buf_cmd], "RETR"
|
||||||
mov byte[s+4], " "
|
mov byte[buf_cmd+4], " "
|
||||||
|
|
||||||
mov ecx, 256
|
mov ecx, 256
|
||||||
xor al, al
|
xor al, al
|
||||||
mov edi, s
|
mov edi, buf_cmd
|
||||||
repne scasb
|
repne scasb
|
||||||
lea esi, [edi - s]
|
lea esi, [edi - buf_cmd]
|
||||||
mov dword[edi - 2], 0x0a0d
|
mov dword[edi - 2], 0x0a0d
|
||||||
mcall send, [socketnum], s, , 0
|
mcall send, [socketnum], buf_cmd, , 0
|
||||||
|
|
||||||
invoke con_write_asciiz, s ; print command
|
invoke con_write_asciiz, buf_cmd ; print command
|
||||||
jmp wait_for_servercommand
|
jmp wait_for_servercommand
|
||||||
|
|
||||||
|
cmd_rdir:
|
||||||
|
|
||||||
|
mov [operation], OPERATION_RDIR
|
||||||
|
|
||||||
|
; Request filename list from the server
|
||||||
|
|
||||||
|
call open_dataconnection
|
||||||
|
|
||||||
|
mov [size_fname], 0
|
||||||
|
mov dword[buf_cmd], "NLST"
|
||||||
|
mov word[buf_cmd+4], 0x0a0d
|
||||||
|
mcall send, [socketnum], buf_cmd, 6, 0
|
||||||
|
|
||||||
|
jmp wait_for_servercommand
|
||||||
|
|
||||||
cmd_stor:
|
cmd_stor:
|
||||||
|
|
||||||
call open_dataconnection
|
call open_dataconnection
|
||||||
@ -123,29 +139,29 @@ cmd_stor:
|
|||||||
mov [filestruct.offset], 0
|
mov [filestruct.offset], 0
|
||||||
mov [filestruct.offset+4], 0
|
mov [filestruct.offset+4], 0
|
||||||
mov [filestruct.size], BUFFERSIZE
|
mov [filestruct.size], BUFFERSIZE
|
||||||
mov [filestruct.ptr], buffer_ptr2
|
mov [filestruct.ptr], buf_buffer2
|
||||||
|
|
||||||
mov esi, s+5
|
mov esi, buf_cmd+5
|
||||||
mov ecx, 256-5
|
mov ecx, 256-5
|
||||||
call set_filename
|
call set_filename
|
||||||
|
|
||||||
mov dword[s], "STOR"
|
mov dword[buf_cmd], "STOR"
|
||||||
mov byte[s+4], " "
|
mov byte[buf_cmd+4], " "
|
||||||
|
|
||||||
mov ecx, 256
|
mov ecx, 256
|
||||||
xor al, al
|
xor al, al
|
||||||
mov edi, s
|
mov edi, buf_cmd
|
||||||
repne scasb
|
repne scasb
|
||||||
lea esi, [edi - s]
|
lea esi, [edi - buf_cmd]
|
||||||
mov word [edi - 2], 0x0a0d
|
mov word [edi - 2], 0x0a0d
|
||||||
mcall send, [socketnum], s, , 0
|
mcall send, [socketnum], buf_cmd, , 0
|
||||||
|
|
||||||
jmp wait_for_servercommand
|
jmp wait_for_servercommand
|
||||||
|
|
||||||
|
|
||||||
cmd_lcwd:
|
cmd_lcwd:
|
||||||
|
|
||||||
mov esi, s+5
|
mov esi, buf_cmd+5
|
||||||
mov ecx, 256-5
|
mov ecx, 256-5
|
||||||
.loop:
|
.loop:
|
||||||
lodsb
|
lodsb
|
||||||
@ -156,11 +172,11 @@ cmd_lcwd:
|
|||||||
loop .loop
|
loop .loop
|
||||||
.done:
|
.done:
|
||||||
mov byte[esi-1], 0
|
mov byte[esi-1], 0
|
||||||
mcall 30, 1, s+5 ; set working directory
|
mcall 30, 1, buf_cmd+5 ; set working directory
|
||||||
mcall 30, 2, s, 256 ; and read it again
|
mcall 30, 2, buf_cmd, 256 ; and read it again
|
||||||
|
|
||||||
invoke con_write_asciiz, str_lcwd
|
invoke con_write_asciiz, str_lcwd
|
||||||
invoke con_write_asciiz, s
|
invoke con_write_asciiz, buf_cmd
|
||||||
invoke con_write_asciiz, str_newline
|
invoke con_write_asciiz, str_newline
|
||||||
|
|
||||||
jmp wait_for_usercommand
|
jmp wait_for_usercommand
|
||||||
@ -168,41 +184,41 @@ cmd_lcwd:
|
|||||||
|
|
||||||
cmd_cdup:
|
cmd_cdup:
|
||||||
|
|
||||||
mov dword[s], "CDUP"
|
mov dword[buf_cmd], "CDUP"
|
||||||
mov word[s+4], 0x0d0a
|
mov word[buf_cmd+4], 0x0d0a
|
||||||
mcall send, [socketnum], s, 6, 0
|
mcall send, [socketnum], buf_cmd, 6, 0
|
||||||
|
|
||||||
jmp wait_for_servercommand
|
jmp wait_for_servercommand
|
||||||
|
|
||||||
|
|
||||||
cmd_rmd:
|
cmd_rmd:
|
||||||
|
|
||||||
mov dword[s], "RMD "
|
mov dword[buf_cmd], "RMD "
|
||||||
|
|
||||||
mov ecx, 256
|
mov ecx, 256
|
||||||
xor al, al
|
xor al, al
|
||||||
mov edi, s
|
mov edi, buf_cmd
|
||||||
repne scasb
|
repne scasb
|
||||||
lea esi, [edi - s]
|
lea esi, [edi - buf_cmd]
|
||||||
mov word [edi - 2], 0x0a0d
|
mov word [edi - 2], 0x0a0d
|
||||||
|
|
||||||
mcall send, [socketnum], s, , 0
|
mcall send, [socketnum], buf_cmd, , 0
|
||||||
|
|
||||||
jmp wait_for_servercommand
|
jmp wait_for_servercommand
|
||||||
|
|
||||||
|
|
||||||
cmd_mkd:
|
cmd_mkd:
|
||||||
|
|
||||||
mov dword[s], "MKD "
|
mov dword[buf_cmd], "MKD "
|
||||||
|
|
||||||
mov ecx, 256
|
mov ecx, 256
|
||||||
xor al, al
|
xor al, al
|
||||||
mov edi, s
|
mov edi, buf_cmd
|
||||||
repne scasb
|
repne scasb
|
||||||
lea esi, [edi - s]
|
lea esi, [edi - buf_cmd]
|
||||||
mov word [edi - 2], 0x0a0d
|
mov word [edi - 2], 0x0a0d
|
||||||
|
|
||||||
mcall send, [socketnum], s, , 0
|
mcall send, [socketnum], buf_cmd, , 0
|
||||||
|
|
||||||
jmp wait_for_servercommand
|
jmp wait_for_servercommand
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user