add support to parse parameters

git-svn-id: svn://kolibrios.org@6394 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
nisargshah95 2016-04-12 12:24:28 +00:00
parent 7ea16e0e19
commit b4322cddd9
3 changed files with 170 additions and 2 deletions

View File

@ -48,6 +48,7 @@ include '../../network.inc'
include 'usercommands.inc'
include 'servercommands.inc'
include 'parser.inc'
start:
; initialize heap for using dynamic blocks
@ -122,7 +123,7 @@ main:
invoke con_set_flags, 0x07
invoke con_write_asciiz, str_newline
resolve:
no_resolve:
mov [sockaddr1.port], 21 shl 8
; delete terminating '\n'
@ -341,24 +342,54 @@ wait_for_usercommand:
.connected:
; request username
cmp [use_params], 1
je .copy_user
invoke con_write_asciiz, str_user
mov dword[buf_cmd], "USER"
mov byte[buf_cmd+4], " "
jmp .send
.copy_user:
; copy user name to buf_cmd
mov edi, buf_cmd
mov esi, param_user
@@:
lodsb
stosb
cmp byte [esi-1], 0
jne @b
jmp .send
.needpass:
; request password
cmp [use_params], 1
je .copy_password
invoke con_write_asciiz, str_pass
mov dword[buf_cmd], "PASS"
mov byte[buf_cmd+4], " "
invoke con_set_flags, 0x00 ; black text on black background for password
jmp .send
.copy_password:
; copy password to buf_cmd
mov edi, buf_cmd
mov esi, param_password
@@:
lodsb
stosb
cmp byte [esi-1], 0
jne @b
.send:
; read string
cmp [use_params], 1
je @f
mov esi, buf_cmd+5
invoke con_gets, esi, 256
@@:
; find end of string
mov edi, buf_cmd+5
mov ecx, 256
@ -547,6 +578,8 @@ str_welcome db 'FTP client for KolibriOS v0.12',10
db 10
db 'Please enter ftp server address.',10,0
str_ftp db 'ftp://',0
str_prompt db '> ',0
str_resolve db 'Resolving ',0
str_newline db 10,0
@ -680,4 +713,10 @@ buf_cmd rb 1024 ; buffer for holding command string
path rb 1024
use_params db 0
param_user rb 1024
param_password rb 1024
param_server_addr rb 1024
param_path rb 1024
mem:

View File

@ -0,0 +1,116 @@
resolve:
; 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
mov edi, str_ftp
xor ecx, ecx
@@:
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
; parse user
mov dword[param_user], "USER"
mov byte[param_user+4], " "
inc edx
add esi, edx
lea edi, [param_user+5]
.user:
lodsb
cmp al, 0
je .error
stosb
cmp byte [esi], ':'
jne .user
mov word [edi], 0x0a0d
mov byte [edi+2], 0
; parse password
inc esi
mov dword[param_password], "PASS"
mov byte[param_password+4], " "
lea edi, [param_password+5]
.pass:
lodsb
cmp al, 0
je .error
stosb
cmp byte [esi], '@'
jne .pass
mov word [edi], 0x0a0d
mov byte [edi+2], 0
; parse server address
inc esi
mov edi, param_server_addr
.addr:
lodsb
cmp al, 0
je .error
stosb
cmp byte [esi], ':'
jne .addr
mov byte [edi], 0
; parse port
inc esi
xor eax, eax
xor ebx, ebx
mov [sockaddr1.port], 21 shl 8
.port:
lodsb
cmp al, 0
je .error
cmp al, '/'
jbe @f
sub al, '0'
jb error_hostname
cmp al, 9
ja error_hostname
lea ebx, [ebx*4 + ebx]
shl ebx, 1
add ebx, eax
jmp .port
@@: ; port done
xchg bl, bh
mov [sockaddr1.port], bx
; parse path
mov dword[param_path], "CWD "
lea edi, [param_path+4]
.path:
lodsb
stosb
cmp byte [esi], 0
jne .path
mov word [edi], 0x0a0d
mov byte [edi+2], 0
; parameters resolved successfully
mov [use_params], 1
; 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
.error:
jmp main ; parameter resolution failed. get input from user

View File

@ -33,6 +33,7 @@ server_parser:
je welcome
cmp dword[buf_cmd], "530 " ; password incorrect
mov [use_params], 0
je welcome
cmp dword[buf_cmd], "550 "
@ -58,8 +59,20 @@ pass:
login_ok:
mov [status], STATUS_LOGGED_IN
jmp wait_for_usercommand
cmp [use_params], 0
je wait_for_usercommand
cmp [param_path+4], 0
je wait_for_usercommand
; copy path to buf_cmd and execute CWD
mov edi, buf_cmd
mov esi, param_path
@@:
lodsb
stosb
cmp byte[esi-1], 0
jne @b
jmp cmd_cwd
pasv_ok: