Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 2563 → Rev 2562

/kernel/branches/net/applications/ftpd/commands.inc
49,7 → 49,7
dd cmdPASS
db 'PASV'
dd cmdPASV
db 'PWD', 0
db 'PWD', 0 ; Print Working Directory
dd cmdPWD
db 'PORT'
dd cmdPORT
76,42 → 76,10
ret
 
align 4
cmdCWD: ; Change Working Directory
cmdCWD:
 
sub ecx, 4
jb .err
add esi, 4
mov edi, work_dir + 1
 
cmp byte [esi], '/'
jne @f
inc esi
dec ecx
jz .done
@@:
 
.loop:
lodsb
cmp al, 0x20
jb .done
stosb
loop .loop
.done:
cmp byte [edi-1], '/'
je @f
mov byte [edi], '/'
inc edi
@@:
mov byte [edi], 0
 
mcall send, [socketnum2], str250, str250.length, 0
 
ret
 
.err:
 
ret
 
align 4
cmdDELE:
 
120,7 → 88,6
align 4
cmdLIST:
 
; If we are in active mode, it's time to open a data socket..
cmp [mode], MODE_ACTIVE
jne @f
mcall connect, [datasocketnum], datasock, datasock.length
128,30 → 95,31
je .err
@@:
 
; Warn the client we're about to send the data
mcall send, [socketnum2], str150, str150.length, 0 ; here it comes..
 
; Create fpath from home_dir and work_dir
call create_path
 
; Start the search
push FA_READONLY + FA_FOLDER
push str_mask
push fpath
push home_dir
call [file.find.first]
 
mov edi, buffer
jmp .parse_file
 
.checknextfile:
push edx
call [file.find.next]
 
.parse_file:
test eax, eax ; did we find a file?
test eax, eax
jz .done
 
mov edx, eax ; yes, save the descripter
mov edx, eax
 
; first, convert the attributes
test [edx + FileInfoA.Attributes], FA_FOLDER
test [eax + FileInfoA.Attributes], FA_FOLDER
jnz .folder
 
test [edx + FileInfoA.Attributes], FA_READONLY
test [eax + FileInfoA.Attributes], FA_READONLY
jnz .readonly
 
mov eax, '-rw-'
160,7 → 128,7
 
.folder:
mov eax, 'drwx'
stosd
stosb
jmp .attr
 
.readonly:
185,7 → 153,7
stosd
 
; now the filesize in ascii
mov ebx, [edx + FileInfoA.FileSizeLow]
mov ebx, dword [edx + FileInfoA.FileSize]
call dword_to_ascii
 
mov al, ' '
218,34 → 186,24
stosb
loop .nameloop
 
; insert a cr lf
.namedone:
mov ax, 0x0d0a
stosw
jmp .checknextfile
 
; check next file
push edx
call [file.find.next]
jmp .parse_file
 
; close file desc
.done:
push edx
call [file.find.close]
 
; append the string with a 0
xor al, al
stosb
 
; print everything on the console
push buffer
call [con_write_asciiz]
 
; and send it to the client
lea esi, [edi - buffer]
mcall send, [datasocketnum], buffer, , 0
 
; close the data socket..
mcall close, [datasocketnum]
 
cmp [mode], MODE_PASSIVE_OK
253,8 → 211,7
mov [mode], MODE_PASSIVE_WAIT
@@:
 
; And send "transfer ok" on the base connection
mcall send, [socketnum2], str226, str226.length, 0
mcall send, [socketnum2], str226, str226.length, 0 ; transfer ok
 
ret
 
339,7 → 296,7
ret
 
align 4
cmdPWD: ; Print Working Directory
cmdPWD:
 
mov dword[buffer], '257 '
mov byte[buffer+4], '"'
426,52 → 383,23
align 4
cmdRETR:
 
cmp [mode], MODE_ACTIVE
jne @f
mcall connect, [datasocketnum], datasock, datasock.length
; mcall connect, [datasocketnum], datasock, datasock.length
; cmp eax, -1
; je .err
@@:
 
mcall send, [socketnum2], str150, str150.length, 0 ; here it comes..
 
push O_READ
push home_dir
call [file.open]
; push O_READ
; push home_dir
; call [file.open]
; test eax, eax
; jz .cannot_open
 
mov ebx, eax
 
.read_more:
push BUFFERSIZE
push buffer
push ebx
call [file.read]
;
; push BUFFERSIZE
; push buffer
; push eax
; call [file.read]
; cmp eax, -1
; je .cannot_open
; jz .cannot_open
 
push eax
push ebx
mov esi, eax
mcall send, [datasocketnum], buffer, , 0
pop ebx
pop ecx
; cmp eax, -1
; je .socketerr
 
cmp ecx, BUFFERSIZE
je .read_more
 
mcall close, [datasocketnum]
 
cmp [mode], MODE_PASSIVE_OK
jne @f
mov [mode], MODE_PASSIVE_WAIT
@@:
 
mcall send, [socketnum2], str226, str226.length, 0 ; transfer ok
 
ret
 
align 4
614,45 → 542,10
 
ret
 
align 4
create_path: ; combine home_dir and work_dir strings into fpath
mov edi, fpath
mov esi, home_dir
mov ecx, 1024
 
.loop1:
lodsb
or al, al
jz .next
stosb
loop .loop1
.next:
 
cmp byte[edi-1], '/'
jne @f
dec edi
@@:
 
mov esi, work_dir
mov ecx, 1024
 
.loop2:
lodsb
or al, al
jz .done
stosb
loop .loop2
 
.done:
stosb
 
ret
 
 
 
 
 
 
str150 db '150 Here it comes...', 13, 10
.length = $ - str150
str200 db '200 Command OK.', 13, 10
670,7 → 563,10
str230 db '230 You are now logged in.', 13, 10
.length = $ - str230
str250 db '250 command successful', 13, 10
.length = $ - str250
;str257 db '257 "'
;.length = $ - str257
;str257b db '"', 13, 10
;.length = $ - str257b
str331 db '331 Please specify the password.', 13, 10
.length = $ - str331
str421 db '421 Timeout!', 13, 10
679,5 → 575,4
.length = $ - str425
str500 db '500 Unsupported command', 13, 10
.length = $ - str500
str550 db '550 No such file', 13, 10
.length = $ - str550
str550 db '550 No such file', 13, 10
/kernel/branches/net/applications/ftpd/ftpd.asm
157,8 → 157,10
 
pushd 0x0a
call [con_set_flags]
 
push buffer
call [con_write_asciiz]
 
pushd 0x07
call [con_set_flags]
 
296,10 → 298,7
socketnum2 dd ?
state dd ?
home_dir db '/rd/1/', 0
rb 1024
work_dir rb 1024
fpath rb 2048
 
type db ?
mode db ? ; active/passive
 
/kernel/branches/net/applications/struct.inc
2,79 → 2,53
; Macroinstructions for defining data structures
 
macro struct name
{ virtual at 0
fields@struct equ name
{ fields@struct equ name
match child parent, name \{ fields@struct equ child,fields@\#parent \}
sub@struct equ
struc db [val] \{ \common define field@struct .,db,<val>
fields@struct equ fields@struct,field@struct \}
struc dw [val] \{ \common define field@struct .,dw,<val>
fields@struct equ fields@struct,field@struct \}
struc du [val] \{ \common define field@struct .,du,<val>
fields@struct equ fields@struct,field@struct \}
struc dd [val] \{ \common define field@struct .,dd,<val>
fields@struct equ fields@struct,field@struct \}
struc dp [val] \{ \common define field@struct .,dp,<val>
fields@struct equ fields@struct,field@struct \}
struc dq [val] \{ \common define field@struct .,dq,<val>
fields@struct equ fields@struct,field@struct \}
struc dt [val] \{ \common define field@struct .,dt,<val>
fields@struct equ fields@struct,field@struct \}
struc rb count \{ define field@struct .,db,count dup (?)
fields@struct equ fields@struct,field@struct \}
struc rw count \{ define field@struct .,dw,count dup (?)
fields@struct equ fields@struct,field@struct \}
struc rd count \{ define field@struct .,dd,count dup (?)
fields@struct equ fields@struct,field@struct \}
struc rp count \{ define field@struct .,dp,count dup (?)
fields@struct equ fields@struct,field@struct \}
struc rq count \{ define field@struct .,dq,count dup (?)
fields@struct equ fields@struct,field@struct \}
struc rt count \{ define field@struct .,dt,count dup (?)
fields@struct equ fields@struct,field@struct \}
struc db [val] \{ \common fields@struct equ fields@struct,.,db,<val> \}
struc dw [val] \{ \common fields@struct equ fields@struct,.,dw,<val> \}
struc du [val] \{ \common fields@struct equ fields@struct,.,du,<val> \}
struc dd [val] \{ \common fields@struct equ fields@struct,.,dd,<val> \}
struc dp [val] \{ \common fields@struct equ fields@struct,.,dp,<val> \}
struc dq [val] \{ \common fields@struct equ fields@struct,.,dq,<val> \}
struc dt [val] \{ \common fields@struct equ fields@struct,.,dt,<val> \}
struc rb count \{ fields@struct equ fields@struct,.,db,count dup (?) \}
struc rw count \{ fields@struct equ fields@struct,.,dw,count dup (?) \}
struc rd count \{ fields@struct equ fields@struct,.,dd,count dup (?) \}
struc rp count \{ fields@struct equ fields@struct,.,dp,count dup (?) \}
struc rq count \{ fields@struct equ fields@struct,.,dq,count dup (?) \}
struc rt count \{ fields@struct equ fields@struct,.,dt,count dup (?) \}
macro db [val] \{ \common \local anonymous
define field@struct anonymous,db,<val>
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,db,<val> \}
macro dw [val] \{ \common \local anonymous
define field@struct anonymous,dw,<val>
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,dw,<val> \}
macro du [val] \{ \common \local anonymous
define field@struct anonymous,du,<val>
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,du,<val> \}
macro dd [val] \{ \common \local anonymous
define field@struct anonymous,dd,<val>
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,dd,<val> \}
macro dp [val] \{ \common \local anonymous
define field@struct anonymous,dp,<val>
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,dp,<val> \}
macro dq [val] \{ \common \local anonymous
define field@struct anonymous,dq,<val>
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,dq,<val> \}
macro dt [val] \{ \common \local anonymous
define field@struct anonymous,dt,<val>
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,dt,<val> \}
macro rb count \{ \local anonymous
define field@struct anonymous,db,count dup (?)
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,db,count dup (?) \}
macro rw count \{ \local anonymous
define field@struct anonymous,dw,count dup (?)
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,dw,count dup (?) \}
macro rd count \{ \local anonymous
define field@struct anonymous,dd,count dup (?)
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,dd,count dup (?) \}
macro rp count \{ \local anonymous
define field@struct anonymous,dp,count dup (?)
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,dp,count dup (?) \}
macro rq count \{ \local anonymous
define field@struct anonymous,dq,count dup (?)
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,dq,count dup (?) \}
macro rt count \{ \local anonymous
define field@struct anonymous,dt,count dup (?)
fields@struct equ fields@struct,field@struct \}
fields@struct equ fields@struct,anonymous,dt,count dup (?) \}
macro union \{ fields@struct equ fields@struct,,union,<
sub@struct equ union \}
macro struct \{ fields@struct equ fields@struct,,substruct,<
sub@struct equ substruct \} }
sub@struct equ substruct \}
virtual at 0 }
 
macro ends
{ match , sub@struct \{ restruc db,dw,du,dd,dp,dq,dt
82,13 → 56,9
purge db,dw,du,dd,dp,dq,dt
purge rb,rw,rd,rp,rq,rt
purge union,struct
match name tail,fields@struct, \\{ if $
display 'Error: definition of ',\\`name,' contains illegal instructions.',0Dh,0Ah
err
end if \\}
match name=,fields,fields@struct \\{ fields@struct equ
make@struct name,fields
define fields@\\#name fields \\}
fields@\\#name equ fields \\}
end virtual \}
match any, sub@struct \{ fields@struct equ fields@struct> \}
restore sub@struct }
95,6 → 65,10
 
macro make@struct name,[field,type,def]
{ common
if $
display 'Error: definition of ',`name,' contains illegal instructions.',0Dh,0Ah
err
end if
local define
define equ name
forward
107,14 → 81,6
 
macro define@struct name,[field,type,def]
{ common
virtual
db `name
load initial@struct byte from 0
if initial@struct = '.'
display 'Error: name of structure should not begin with a dot.',0Dh,0Ah
err
end if
end virtual
local list
list equ
forward
122,7 → 88,6
name#field type def
sizeof.#name#field = $ - name#field
else
label name#.#type
rb sizeof.#type
end if
local value
132,9 → 97,9
sizeof.#name = $
restruc name
match values, list \{
struc name value \\{ \\local \\..base
struc name value \\{
match any, fields@struct \\\{ fields@struct equ fields@struct,.,name,<values> \\\}
match , fields@struct \\\{ label \\..base
match , fields@struct \\\{ label .
forward
match , value \\\\{ field type def \\\\}
match any, value \\\\{ field type value
141,20 → 106,6
if ~ field eq .
rb sizeof.#name#field - ($-field)
end if \\\\}
common label . at \\..base \\\}
\\}
macro name value \\{
match any, fields@struct \\\{ \\\local anonymous
fields@struct equ fields@struct,anonymous,name,<values> \\\}
match , fields@struct \\\{
forward
match , value \\\\{ type def \\\\}
match any, value \\\\{ \\\\local ..field
..field = $
type value
if ~ field eq .
rb sizeof.#name#field - ($-..field)
end if \\\\}
common \\\} \\} \} }
 
macro enable@substruct
165,7 → 116,7
\forward
\local sub
match , field \\{ match any, type \\\{ enable@substruct
make@substruct type,parent,sub def
make@substruct type,name,sub def
purge make@substruct
define equ define,.,sub, \\\} \\}
match any, field \\{ define equ define,.\#field,type,<def> \\}
176,28 → 127,21
 
macro define@union parent,name,[field,type,def]
{ common
virtual at parent#.#name
virtual at 0
forward
if ~ field eq .
virtual at parent#.#name
virtual at 0
parent#field type def
sizeof.#parent#field = $ - parent#field
end virtual
if sizeof.#parent#field > $ - parent#.#name
rb sizeof.#parent#field - ($ - parent#.#name)
if sizeof.#parent#field > $
rb sizeof.#parent#field - $
end if
else
virtual at parent#.#name
label parent#.#type
type def
end virtual
label name#.#type at parent#.#name
if sizeof.#type > $ - parent#.#name
rb sizeof.#type - ($ - parent#.#name)
else if sizeof.#type > $
rb sizeof.#type - $
end if
end if
common
sizeof.#name = $ - parent#.#name
sizeof.#name = $
end virtual
struc name [value] \{ \common
label .\#name
209,23 → 153,21
match , last@union \\{ match , value \\\{ field type def \\\}
match any, value \\\{ field type value \\\} \\}
last@union equ field
common rb sizeof.#name - ($ - .\#name) \}
macro name [value] \{ \common \local ..anonymous
..anonymous name value \} }
common rb sizeof.#name - ($ - .\#name) \} }
 
macro define@substruct parent,name,[field,type,def]
{ common
virtual at parent#.#name
virtual at 0
forward
if ~ field eq .
parent#field type def
sizeof.#parent#field = $ - parent#field
else
label parent#.#type
rb sizeof.#type
end if
local value
common
sizeof.#name = $ - parent#.#name
sizeof.#name = $
end virtual
struc name value \{
label .\#name
235,6 → 177,4
if ~ field eq .
rb sizeof.#parent#field - ($-field)
end if \\}
common \}
macro name value \{ \local ..anonymous
..anonymous name \} }
common \} }