Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 6582 → Rev 6581

/programs/network/ftpc/login_gui.inc
File deleted
\ No newline at end of file
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/programs/network/ftpc/README.txt
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/programs/network/ftpc/console.inc
File deleted
\ No newline at end of file
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/programs/network/ftpc/gui.inc
File deleted
\ No newline at end of file
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/programs/network/ftpc/parser.inc
1,88 → 1,126
;;================================================================================================;;
parse_args: ;/////////////////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? parses command line arguments of type ;;
;? ftp://user:password@server:port/folder/subfolder type urls and attempts to connect ;;
;? automatically ;;
;;------------------------------------------------------------------------------------------------;;
;> buf_cmd = pointer to command line arguments ;;
;;------------------------------------------------------------------------------------------------;;
;< none ;;
;;================================================================================================;;
resolve:
 
cmp dword[buf_cmd], 'ftp:'
jne @f
; parse command line parameters of type
; ftp://user:password@server.com:port/folder/subfolder type urls
 
; check ftp://
xor edx, edx
mov esi, buf_cmd
jmp .start
mov edi, str_ftp
xor ecx, ecx
@@:
mov esi, buf_cmd+5
mov al, byte [esi+edx]
mov bl, byte [edi+edx]
inc edx
cmp al, bl
jne main
cmp byte [edi+edx], '/'
jne @b
inc ecx
cmp ecx, 2
jne @b
 
.start:
; check ftp://
cmp dword[esi], 'ftp:'
jne .error
cmp word[esi+4], '//'
jne .error
 
; parse user
lea edi, [param_user]
@@:
mov dword[param_user], "USER"
mov byte[param_user+4], " "
inc edx
add esi, edx
lea edi, [param_user+5]
.user:
lodsb
test al, al
jz .error
stosb
cmp al, 0
jne @f
mov eax, str_err_params
jmp error
@@: stosb
cmp byte [esi], ':'
jne @b
mov byte [edi], 0
jne .user
mov word [edi], 0x0a0d
mov byte [edi+2], 0
 
; parse password
inc esi
lea edi, [param_password]
@@:
mov dword[param_password], "PASS"
mov byte[param_password+4], " "
lea edi, [param_password+5]
.pass:
lodsb
test al, al
jz .error
stosb
cmp al, 0
jne @f
mov eax, str_err_params
jmp error
@@: stosb
cmp byte [esi], '@'
jne @b
mov byte [edi], 0
jne .pass
mov word [edi], 0x0a0d
mov byte [edi+2], 0
; parse server address
inc esi
mov edi, param_server_addr
@@:
.addr:
lodsb
test al, al
jz .error
stosb
cmp al, 0
jne @f
mov eax, str_err_params
jmp error
@@: stosb
cmp byte [esi], ':'
jne @b
jne .addr
mov byte [edi], 0
 
; parse port
inc esi
lea edi, [param_port]
@@:
xor eax, eax
xor ebx, ebx
mov [sockaddr1.port], 21 shl 8
.port:
lodsb
test al, al
jz .error
stosb
cmp byte [esi], '/'
jne @b
mov byte [edi], 0
cmp al, 0
jne @f
mov eax, str_err_params
jmp error
@@: cmp al, '/'
jbe .port_done
sub al, '0'
jnb @f
mov eax, str_err_host
jmp error
@@: cmp al, 9
jna @f
mov eax, str_err_host
jmp error
@@: lea ebx, [ebx*4 + ebx]
shl ebx, 1
add ebx, eax
jmp .port
.port_done:
xchg bl, bh
mov [sockaddr1.port], bx
 
; parse path
inc esi
lea edi, [param_path]
@@:
movsb
mov dword[param_path], "CWD "
lea edi, [param_path+4]
.path:
lodsb
stosb
cmp byte [esi], 0
jne @b
mov byte [edi], 0
jne .path
mov word [edi], 0x0a0d
mov byte [edi+2], 0
 
; parameters parsed successfully
jmp arg_handler.connect
; parameters resolved successfully
mov [use_params], 1
 
.error:
mov eax, str_err_params
jmp error
; copy server address to buf_cmd
mov esi, param_server_addr
mov edi, buf_cmd
.copy:
lodsb
stosb
cmp byte [edi], 0
jne .copy
mov byte [esi], 0
 
jmp no_resolve.done
 
/programs/network/ftpc/servercommands.inc
5,14 → 5,11
; first lines will have a dash instead of space after numbers,
; thus they are simply ignored in this simple command parser.
 
cmp dword[buf_cmd+4], "Open"
je init_download_count
 
cmp dword[buf_cmd], "150 "
je data_loop
 
cmp dword[buf_cmd], "220 "
je connect_ok
je welcome
 
; cmp dword[buf_cmd], "226 "
; je transfer_ok
36,6 → 33,7
je welcome
 
cmp dword[buf_cmd], "530 " ; password incorrect
mov [use_params], 0
je welcome
 
cmp dword[buf_cmd], "550 "
52,11 → 50,6
jmp wait_for_usercommand
 
 
connect_ok:
 
mov [status], STATUS_CONNECTED
jmp arg_handler.copy_user
 
pass:
 
mov [status], STATUS_NEEDPASSWORD
66,14 → 59,21
login_ok:
 
mov [status], STATUS_LOGGED_IN
cmp [use_params], 0
je wait_for_usercommand
 
cmp [param_path], 0x20 ; no path specified
jbe wait_for_usercommand
cmp [param_path+4], 0
je wait_for_usercommand
; copy path to buf_cmd and execute CWD
jmp arg_handler.get_path
mov edi, buf_cmd
mov esi, param_path
@@:
lodsb
stosb
cmp byte[esi-1], 0
jne @b
jmp cmd_cwd
 
 
pasv_ok:
 
sub ecx, 4
104,7 → 104,7
call ascii_dec
mov byte[sockaddr2.port+1], bl
 
icall eax, interface_addr, interface.print, str_open
invoke con_write_asciiz, str_open
mcall connect, [datasocket], sockaddr2, 18
cmp eax, -1
jne @f
113,56 → 113,19
@@: jmp wait_for_servercommand
 
.fail:
icall eax, interface_addr, interface.print, str_unknown
invoke con_write_asciiz, str_unknown
jmp wait_for_servercommand
 
 
; get file size, initialize count for number of bytes downloaded
init_download_count:
data_loop:
 
mov edx, 0
; search for 'Open' in buf_cmd
lea esi, [buf_cmd+3]
@@:
inc esi
cmp dword[esi], 'Open'
je @f
cmp byte[esi], 0
jne @b
jmp data_loop
invoke con_write_asciiz, str_dot
 
@@:
; get file size
mov al, '('
mov ecx, -1
mov edi, buf_cmd
repne scasb
xor eax, eax
mov ebx, 10
xor ecx, ecx
mov esi, edi
@@:
push eax
lodsb
sub al, '0'
mov cl, al
pop eax
mul ebx
add eax, ecx
cmp byte[esi], ' '
jne @b
mov [file_size], eax
 
data_loop:
 
cmp [operation], OPERATION_STOR
je .stor
 
push edx
; we are receiving data
mcall recv, [datasocket], buf_buffer2, BUFFERSIZE, 0
pop edx ; get byte count
add edx, eax
test ebx, ebx
jnz .done
mov byte[buf_buffer2 + eax], 0
173,18 → 136,10
cmp [operation], OPERATION_RDIR
je .rdir
 
cmp [operation], OPERATION_LIST
je .list
; not retreiving, just print to console
icall eax, interface_addr, interface.print, buf_buffer2
invoke con_write_asciiz, buf_buffer2
jmp data_loop
 
; for console, simply print. for gui, add name to tree list
.list:
ijmp ebx, interface_addr, interface.list
 
 
; retreiving, save to file
.retr:
mov [filestruct.ptr], buf_buffer2
191,15 → 146,8
mov [filestruct.size], eax
push eax
mcall 70, filestruct
test eax, eax
jz @f
call error_fs
jmp close_datacon
@@:
pop eax
add [filestruct.offset], eax
 
icall eax, interface_addr, interface.progress
jmp data_loop
 
; storing, send all data
208,25 → 156,18
cmp eax, 6 ; end of file
je .last_call
test eax, eax ; error
jz @f
call error_fs
jmp close_datacon
@@:
; jne .fileerror
add [filestruct.offset], ebx
mov esi, ebx
mcall send, [datasocket], buf_buffer2, , 0
mov edx, [filestruct.offset]
icall eax, interface_addr, interface.progress
jmp .stor
 
.last_call:
mov esi, ebx
mcall send, [datasocket], buf_buffer2, , 0
mov edx, [filestruct.offset]
icall eax, interface_addr, interface.progress
 
.done:
icall eax, interface_addr, interface.print, str_close
invoke con_write_asciiz, str_close
mcall close, [datasocket]
mov [operation], OPERATION_NONE
jmp wait_for_servercommand
268,7 → 209,7
close_datacon:
cmp [operation], OPERATION_NONE
je wait_for_usercommand
icall eax, interface_addr, interface.print, str_close
invoke con_write_asciiz, str_close
mcall close, [datasocket]
jmp wait_for_usercommand
 
/programs/network/ftpc/ftpc.asm
6,7 → 6,6
;; ftpc.asm - FTP client for KolibriOS ;;
;; ;;
;; Written by hidnplayr@kolibrios.org ;;
;; Modified by nisargshah323@gmail.com (2016) ;;
;; ;;
;; GNU GENERAL PUBLIC LICENSE ;;
;; Version 2, June 1991 ;;
42,49 → 41,16
dd path ; path
 
include '../../macros.inc'
macro ijmp reg, addr, method
{
mov reg, [addr]
add reg, [method]
jmp dword[reg]
}
macro icall reg, addr, method, [arg]
{
mov reg, [addr]
add reg, [method]
if ~ arg eq
pushd arg
end if
call dword[reg]
}
 
purge mov,add,sub
 
include '../../proc32.inc'
include '../../dll.inc'
include '../../network.inc'
 
include '../../develop/libraries/box_lib/trunk/box_lib.mac'
include '../../develop/libraries/box_lib/load_lib.mac'
 
include 'console.inc'
include 'gui.inc'
include 'login_gui.inc'
include 'usercommands.inc'
include 'servercommands.inc'
include 'parser.inc'
 
; TODO: Add Pasta support to FTPC
 
;;================================================================================================;;
start: ;//////////////////////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Program entry point - initialize heap, load libraries and settings ;;
;;------------------------------------------------------------------------------------------------;;
;> ;;
;;------------------------------------------------------------------------------------------------;;
;< none ;;
;;================================================================================================;;
start:
; initialize heap for using dynamic blocks
mcall 68,11
test eax,eax
96,6 → 62,9
stdcall dll.Load, @IMPORT
test eax, eax
jnz exit
; initialize console
invoke con_start, 1
invoke con_init, 80, 25, 80, 250, str_title
; find path to main settings file (ftpc.ini)
mov edi, path ; Calculate the length of zero-terminated string
xor al, al
130,144 → 99,48
invoke ini.get_str, path, str_general, str_dir, buf_buffer1, BUFFERSIZE, 0
mcall 30, 1, buf_buffer1 ; set working directory
 
; initialize log file
invoke ini.get_str, path, str_general, str_logfile, log_file, 512, 0
mov [filestruct2.subfn], 2
mov [filestruct2.offset], 0
mov [filestruct2.size], 0
mov [filestruct2.ptr], 0
mov [filestruct2.name], log_file
mcall 70, filestruct2
 
; Usage: ftpc [-cli] [ftp://username:password@server:port/path]
 
; mov dword[buf_cmd], '-cli' ;;;; to test CLI ;;;;;
 
; Check for parameters, if there are some, resolve the address right away
; TODO: parse ftp://user:password@server.com:port/folder/subfolder type urls.
cmp byte[buf_cmd], 0
jne @f
mov [interface_addr], gui
jmp .args_ok
@@: cmp dword[buf_cmd], '-cli'
jne .error
mov [interface_addr], console
jmp .args_ok
jne resolve
 
.args_ok:
main:
; Clear screen
invoke con_cls
; Welcome user
invoke con_write_asciiz, str_welcome
; write prompt (in green color)
invoke con_set_flags, 0x0a
invoke con_write_asciiz, str_prompt
; read string
invoke con_gets, buf_cmd, 256
; check for exit
test eax, eax
jz done
cmp byte [buf_cmd], 10
jz done
; reset color back to grey and print newline
invoke con_set_flags, 0x07
invoke con_write_asciiz, str_newline
 
icall eax, interface_addr, interface.init
; check for ftp://username:pass@server:port/path urls
cmp dword[buf_cmd], 'ftp:'
je parse_args
cmp dword[buf_cmd+5], 'ftp:'
je parse_args
ijmp eax, interface_addr, interface.server_addr
no_resolve:
mov [sockaddr1.port], 21 shl 8
 
.error:
call console.init
invoke con_write_asciiz, str_args_err
invoke con_getch2
call console.exit
jmp exit
 
;;================================================================================================;;
arg_handler: ;////////////////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Passes initial connection info from console/GUI to FTP core and the other way around ;;
;;------------------------------------------------------------------------------------------------;;
;> esp+4 = pointer to the argument passed to the function ;;
;;------------------------------------------------------------------------------------------------;;
;< none ;;
;;================================================================================================;;
 
.get_username:
; request username
ijmp eax, interface_addr, interface.get_username
 
.copy_user:
mov dword[buf_cmd], "USER"
mov byte[buf_cmd+4], " "
; copy user name to buf_cmd (for command line args)
mov edi, buf_cmd+5
mov esi, param_user
; delete terminating '\n'
mov esi, buf_cmd
@@:
movsb
cmp byte [esi-1], 0
jne @b
mov word[edi-1], 0x0a0d
 
lea esi, [edi+1-buf_cmd]
jmp server_connect.send
 
.get_pass:
mov dword[buf_cmd], "PASS"
mov byte[buf_cmd+4], " "
; copy password to buf_cmd (for command line args)
mov edi, buf_cmd+5
mov esi, param_password
@@:
movsb
cmp byte[esi-1], 0
jne @b
mov word[edi-1], 0x0a0d
 
lea esi, [edi+1-buf_cmd]
jmp server_connect.send
 
.get_path:
; copy path from param_path to buf_cmd
mov dword[buf_cmd], "CWD "
mov edi, buf_cmd+4
mov esi, param_path
@@:
lodsb
stosb
cmp al, ':'
je .do_port
cmp al, 0x20
ja @b
mov word[edi-1], 0x0a0d
 
lea esi, [edi+1-buf_cmd]
jmp server_connect.send
 
.connect:
; copy server address to buf_cmd
mov esi, param_server_addr
mov edi, buf_cmd
@@:
lodsb
stosb
cmp al, 0x20
ja @r
mov byte[edi-1], 0 ; delete terminating '\n'
mov byte [esi-1], 0
jmp .done
 
cmp [param_port], 0x20
jbe server_connect.default_port
mov esi, param_port
jmp server_connect.do_port
 
 
;;================================================================================================;;
server_connect: ;/////////////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Establishes a connection to the FTP server (common block for all interfaces) ;;
;? .do_port - Port is specified by the user and needs to be converted from ASCII ;;
;;------------------------------------------------------------------------------------------------;;
;> esi = pointer to port no. ;;
;;------------------------------------------------------------------------------------------------;;
;< none ;;
;;================================================================================================;;
 
.send:
; send username/password/path to the server
mcall send, [controlsocket], buf_cmd, , 0
icall eax, interface_addr, interface.print, str_newline
icall eax, interface_addr, interface.set_flags, 0x07 ; reset color
jmp wait_for_servercommand
 
; resolve port if specified
.do_port:
xor eax, eax
xor ebx, ebx
mov byte [esi-1], 0
.portloop:
lodsb
cmp al, 0x20
288,15 → 161,11
.port_done:
xchg bl, bh
mov [sockaddr1.port], bx
jmp .done
 
.default_port:
mov [sockaddr1.port], 21 shl 8
 
.done:
; Say to the user that we're resolving
icall eax, interface_addr, interface.set_flags, 0x07 ; reset color
icall eax, interface_addr, interface.print, str_resolve, buf_cmd
invoke con_write_asciiz, str_resolve
invoke con_write_asciiz, buf_cmd
; resolve name
push esp ; reserve stack place
invoke getaddrinfo, buf_cmd, 0, 0, esp
308,13 → 177,14
jmp error
@@:
; write results
icall eax, interface_addr, interface.print, str8 ; ' (',0
invoke con_write_asciiz, str8 ; ' (',0
mov eax, [esi+addrinfo.ai_addr] ; convert IP address to decimal notation
mov eax, [eax+sockaddr_in.sin_addr] ;
mov [sockaddr1.ip], eax ;
invoke inet_ntoa, eax ;
icall ebx, interface_addr, interface.print, eax, str9 ; <ip>,')',10,0
invoke con_write_asciiz, eax ; print ip
invoke freeaddrinfo, esi ; free allocated memory
invoke con_write_asciiz, str9 ; ')',10,0
; open the socket
mcall socket, AF_INET4, SOCK_STREAM, 0
cmp eax, -1
323,7 → 193,7
jmp error
@@: mov [controlsocket], eax
; connect to the server
icall eax, interface_addr, interface.print, str_connect
invoke con_write_asciiz, str_connect
mcall connect, [controlsocket], sockaddr1, 18
cmp eax, -1
jne @f
331,22 → 201,12
jmp error
@@: mov [status], STATUS_CONNECTING
; Tell the user we're waiting for the server now.
icall eax, interface_addr, interface.print, str_waiting
invoke con_write_asciiz, str_waiting
 
; Reset 'offset' variable, it's used by the data receiver
mov [offset], 0
 
 
;;================================================================================================;;
wait_for_servercommand: ;/////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Checks if any data received from the server is present in buffer. ;;
;? If not, receives and processes it ;;
;;----------------------