forked from KolibriOS/kolibrios
Some bugfixes and improvements for downloader.
git-svn-id: svn://kolibrios.org@3623 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
c64b6b486f
commit
b003b0826c
@ -30,8 +30,8 @@ use32
|
|||||||
dd 0x01 ; header version
|
dd 0x01 ; header version
|
||||||
dd START ; entry point
|
dd START ; entry point
|
||||||
dd IM_END ; image size
|
dd IM_END ; image size
|
||||||
dd I_END+0x100 ; required memory
|
dd I_END+0x1000 ; required memory
|
||||||
dd I_END+0x100 ; esp
|
dd I_END+0x1000 ; esp
|
||||||
dd params ; I_PARAM
|
dd params ; I_PARAM
|
||||||
dd 0x0 ; I_Path
|
dd 0x0 ; I_Path
|
||||||
|
|
||||||
@ -46,8 +46,6 @@ START:
|
|||||||
|
|
||||||
mcall 68, 11 ; init heap so we can allocate memory dynamically
|
mcall 68, 11 ; init heap so we can allocate memory dynamically
|
||||||
|
|
||||||
mcall 40, EV_STACK
|
|
||||||
|
|
||||||
; load libraries
|
; load libraries
|
||||||
stdcall dll.Load, @IMPORT
|
stdcall dll.Load, @IMPORT
|
||||||
test eax, eax
|
test eax, eax
|
||||||
@ -69,69 +67,97 @@ START:
|
|||||||
mov ecx, URLMAXLEN-1
|
mov ecx, URLMAXLEN-1
|
||||||
rep stosb
|
rep stosb
|
||||||
|
|
||||||
call load_settings
|
; load proxy settings
|
||||||
cmp byte[params], 0
|
invoke ini.get_str, inifile, sec_proxy, key_proxy, proxyAddr, 256, proxyAddr
|
||||||
je prepare_event ;red
|
invoke ini.get_int, inifile, sec_proxy, key_proxyport, 80
|
||||||
|
mov [proxyPort], eax
|
||||||
|
invoke ini.get_str, inifile, sec_proxy, key_user, proxyUser, 256, proxyUser
|
||||||
|
invoke ini.get_str, inifile, sec_proxy, key_password, proxyPassword, 256, proxyPassword
|
||||||
|
|
||||||
; we have an url
|
; check parameters
|
||||||
mov edi, document_user
|
cmp byte[params], 0 ; no parameters ?
|
||||||
mov al, ' '
|
je reset_events ; load the GUI
|
||||||
mov ecx, URLMAXLEN
|
|
||||||
rep stosb
|
; we have an url, copy untill space or 0
|
||||||
|
|
||||||
mov esi, params
|
mov esi, params
|
||||||
mov edi, document_user
|
mov edi, document_user
|
||||||
|
mov ecx, 1024 ; max parameter size
|
||||||
; copy untill space or 0
|
mov [shared_name], 0
|
||||||
.copy_param:
|
.copy_param:
|
||||||
mov al, [esi]
|
lodsb
|
||||||
test al, al
|
test al, al
|
||||||
jz .done
|
jz .done
|
||||||
|
|
||||||
cmp al, ' '
|
cmp al, ' '
|
||||||
jz .done_inc
|
jz .done_with_shared
|
||||||
|
|
||||||
mov [edi], al
|
stosb
|
||||||
inc esi
|
dec ecx
|
||||||
inc edi
|
jnz .copy_param
|
||||||
jmp .copy_param
|
DEBUGF 2, "Invalid parameters\n"
|
||||||
|
jmp exit
|
||||||
|
|
||||||
.done_inc:
|
.done_with_shared:
|
||||||
|
|
||||||
; url is followed by shared memory name.
|
|
||||||
inc esi
|
|
||||||
.done:
|
|
||||||
mov [shared_name], esi
|
mov [shared_name], esi
|
||||||
jmp download
|
.done:
|
||||||
|
xor al, al
|
||||||
|
stosb
|
||||||
|
|
||||||
prepare_event:
|
|
||||||
; Report events
|
|
||||||
; Stack 8 + defaults
|
|
||||||
mcall 40, 10100111b
|
|
||||||
|
|
||||||
red: ; redraw
|
download:
|
||||||
call draw_window
|
|
||||||
|
DEBUGF 1, "Starting download\n"
|
||||||
|
|
||||||
|
call parse_url
|
||||||
|
call open_socket
|
||||||
|
call send_request
|
||||||
|
|
||||||
|
mcall 68, 12, BUFFERSIZE ; create buffer, we'll resize it later if needed..
|
||||||
|
mov [buf_ptr], eax
|
||||||
|
mov [buf_size], 0
|
||||||
|
|
||||||
|
call read_incoming_data
|
||||||
|
|
||||||
|
mcall close, [socketnum]
|
||||||
|
|
||||||
|
call parse_result
|
||||||
|
call save
|
||||||
|
|
||||||
|
mcall 68, 13, [final_buffer] ; free buffer
|
||||||
|
|
||||||
still:
|
|
||||||
cmp byte [params], 0
|
cmp byte [params], 0
|
||||||
jne exit
|
jne exit
|
||||||
|
|
||||||
mcall 10 ; wait here for event
|
reset_events:
|
||||||
cmp eax, 1 ; redraw request ?
|
|
||||||
je red
|
|
||||||
|
|
||||||
cmp eax, 2 ; key in buffer ?
|
DEBUGF 1, "resetting events\n"
|
||||||
|
|
||||||
|
; Report events
|
||||||
|
; defaults + mouse
|
||||||
|
mcall 40, EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE
|
||||||
|
|
||||||
|
redraw:
|
||||||
|
call draw_window
|
||||||
|
|
||||||
|
still:
|
||||||
|
DEBUGF 1, "waiting for events\n"
|
||||||
|
|
||||||
|
mcall 10 ; wait here for event
|
||||||
|
|
||||||
|
cmp eax, EV_REDRAW
|
||||||
|
je redraw
|
||||||
|
|
||||||
|
cmp eax, EV_KEY
|
||||||
je key
|
je key
|
||||||
|
|
||||||
cmp eax, 3 ; button in buffer ?
|
cmp eax, EV_BUTTON
|
||||||
je button
|
je button
|
||||||
|
|
||||||
cmp eax, 6 ; mouse in buffer ?
|
cmp eax, EV_MOUSE
|
||||||
je mouse
|
je mouse
|
||||||
|
|
||||||
jmp still
|
jmp still
|
||||||
|
|
||||||
|
|
||||||
key:
|
key:
|
||||||
mcall 2 ; read key
|
mcall 2 ; read key
|
||||||
|
|
||||||
@ -145,6 +171,7 @@ key:
|
|||||||
button:
|
button:
|
||||||
|
|
||||||
mcall 17 ; get id
|
mcall 17 ; get id
|
||||||
|
|
||||||
cmp ah, 26
|
cmp ah, 26
|
||||||
jne @f
|
jne @f
|
||||||
call save_to_file
|
call save_to_file
|
||||||
@ -163,41 +190,20 @@ exit:
|
|||||||
or eax, -1 ; close this program
|
or eax, -1 ; close this program
|
||||||
mcall
|
mcall
|
||||||
|
|
||||||
download:
|
|
||||||
|
|
||||||
DEBUGF 1, "Starting download\n"
|
|
||||||
|
|
||||||
call parse_url
|
|
||||||
call open_socket
|
|
||||||
call send_request
|
|
||||||
|
|
||||||
mcall 68, 12, BUFFERSIZE
|
|
||||||
mov [buf_ptr], eax
|
|
||||||
mov [buf_size], 0
|
|
||||||
|
|
||||||
call read_incoming_data
|
|
||||||
|
|
||||||
mcall close, [socketnum]
|
|
||||||
|
|
||||||
call parse_result
|
|
||||||
call save
|
|
||||||
|
|
||||||
mcall 68, 13, [final_buffer]
|
|
||||||
|
|
||||||
jmp still
|
|
||||||
|
|
||||||
|
|
||||||
save:
|
save:
|
||||||
|
cmp [shared_name], 0
|
||||||
|
je .use_file
|
||||||
|
|
||||||
mov ecx, [shared_name]
|
call save_in_shared
|
||||||
test ecx, ecx
|
jmp .done
|
||||||
jz @f
|
|
||||||
cmp [ecx], byte 0
|
.use_file:
|
||||||
jnz save_in_shared
|
|
||||||
@@:
|
|
||||||
|
|
||||||
call save_to_file
|
call save_to_file
|
||||||
|
|
||||||
|
.done:
|
||||||
|
|
||||||
; if called from command line, then exit
|
; if called from command line, then exit
|
||||||
cmp byte[params], 0
|
cmp byte[params], 0
|
||||||
jne exit
|
jne exit
|
||||||
@ -206,31 +212,27 @@ save:
|
|||||||
|
|
||||||
save_in_shared:
|
save_in_shared:
|
||||||
|
|
||||||
mov esi, 1 ; SHM_OPEN+SHM_WRITE
|
; open the shared memory area
|
||||||
mcall 68, 22
|
mov esi, 1
|
||||||
|
mcall 68, 22, [shared_name], , 1 ; SHM_OPEN+SHM_WRITE
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz exit
|
jz exit
|
||||||
|
|
||||||
sub edx, 4
|
|
||||||
jbe exit
|
|
||||||
|
|
||||||
mov ecx, [final_size]
|
mov ecx, [final_size]
|
||||||
cmp ecx, edx
|
; store the size
|
||||||
jb @f
|
|
||||||
|
|
||||||
mov ecx, edx
|
|
||||||
@@:
|
|
||||||
mov [eax], ecx
|
mov [eax], ecx
|
||||||
|
|
||||||
|
; now copy the data
|
||||||
lea edi, [eax+4]
|
lea edi, [eax+4]
|
||||||
mov esi, [final_buffer]
|
mov esi, [final_buffer]
|
||||||
mov edx, ecx
|
mov eax, ecx
|
||||||
shr ecx, 2
|
shr ecx, 2
|
||||||
rep movsd
|
rep movsd
|
||||||
mov ecx, edx
|
mov ecx, eax
|
||||||
and ecx, 3
|
and ecx, 3
|
||||||
rep movsb
|
rep movsb
|
||||||
|
|
||||||
jmp exit
|
ret
|
||||||
|
|
||||||
|
|
||||||
;****************************************************************************
|
;****************************************************************************
|
||||||
@ -341,6 +343,7 @@ send_request:
|
|||||||
sub esi, request ; length
|
sub esi, request ; length
|
||||||
xor edi, edi ; flags
|
xor edi, edi ; flags
|
||||||
mcall send, [socketnum], request ;' HTTP/1.1 .. '
|
mcall send, [socketnum], request ;' HTTP/1.1 .. '
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
;****************************************************************************
|
;****************************************************************************
|
||||||
@ -355,6 +358,8 @@ read_incoming_data:
|
|||||||
|
|
||||||
DEBUGF 1, "Reading incoming data\n"
|
DEBUGF 1, "Reading incoming data\n"
|
||||||
|
|
||||||
|
mcall 40, EVM_STACK ; we only want stack events now
|
||||||
|
|
||||||
mov eax, [buf_ptr]
|
mov eax, [buf_ptr]
|
||||||
mov [pos], eax
|
mov [pos], eax
|
||||||
|
|
||||||
@ -604,7 +609,7 @@ read_hex:
|
|||||||
|
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
xor ecx, ecx
|
xor ecx, ecx
|
||||||
.next:
|
.next:
|
||||||
mov cl, [ebx]
|
mov cl, [ebx]
|
||||||
inc ebx
|
inc ebx
|
||||||
|
|
||||||
@ -625,14 +630,12 @@ read_hex:
|
|||||||
cmp cl, 0x0f
|
cmp cl, 0x0f
|
||||||
ja .bad
|
ja .bad
|
||||||
|
|
||||||
.adding:
|
.adding:
|
||||||
shl eax, 4
|
shl eax, 4
|
||||||
or eax, ecx
|
or eax, ecx
|
||||||
; jmp .not_number
|
.bad:
|
||||||
;.bad:
|
|
||||||
.bad:
|
|
||||||
jmp .next
|
jmp .next
|
||||||
.done:
|
.done:
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -806,7 +809,8 @@ ip2:
|
|||||||
inc edi
|
inc edi
|
||||||
cmp edi, server_ip+3
|
cmp edi, server_ip+3
|
||||||
jbe ip1
|
jbe ip1
|
||||||
jmp pu_011
|
|
||||||
|
ret
|
||||||
|
|
||||||
pu_010:
|
pu_010:
|
||||||
DEBUGF 1, "Resolving %s\n", webAddr
|
DEBUGF 1, "Resolving %s\n", webAddr
|
||||||
@ -830,26 +834,6 @@ pu_010:
|
|||||||
|
|
||||||
DEBUGF 1, "Resolved to %u.%u.%u.%u\n", [server_ip]:1, [server_ip + 1]:1, [server_ip + 2]:1, [server_ip + 3]:1
|
DEBUGF 1, "Resolved to %u.%u.%u.%u\n", [server_ip]:1, [server_ip + 1]:1, [server_ip + 2]:1, [server_ip + 3]:1
|
||||||
|
|
||||||
pu_011:
|
|
||||||
|
|
||||||
ret
|
|
||||||
|
|
||||||
;***************************************************************************
|
|
||||||
; Function
|
|
||||||
; load_settings
|
|
||||||
;
|
|
||||||
; Description
|
|
||||||
; Load settings from configuration file network.ini
|
|
||||||
;
|
|
||||||
;***************************************************************************
|
|
||||||
load_settings:
|
|
||||||
|
|
||||||
invoke ini.get_str, inifile, sec_proxy, key_proxy, proxyAddr, 256, proxyAddr
|
|
||||||
invoke ini.get_int, inifile, sec_proxy, key_proxyport, 80
|
|
||||||
mov [proxyPort], eax
|
|
||||||
invoke ini.get_str, inifile, sec_proxy, key_user, proxyUser, 256, proxyUser
|
|
||||||
invoke ini.get_str, inifile, sec_proxy, key_password, proxyPassword, 256, proxyPassword
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
@ -960,6 +944,7 @@ draw_window:
|
|||||||
mcall 4, <102, 59>, , button_text
|
mcall 4, <102, 59>, , button_text
|
||||||
|
|
||||||
mcall 12, 2 ; end window redraw
|
mcall 12, 2 ; end window redraw
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user