Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 3622 → Rev 3623

/programs/network/downloader/downloader.asm
30,8 → 30,8
dd 0x01 ; header version
dd START ; entry point
dd IM_END ; image size
dd I_END+0x100 ; required memory
dd I_END+0x100 ; esp
dd I_END+0x1000 ; required memory
dd I_END+0x1000 ; esp
dd params ; I_PARAM
dd 0x0 ; I_Path
 
46,8 → 46,6
 
mcall 68, 11 ; init heap so we can allocate memory dynamically
 
mcall 40, EV_STACK
 
; load libraries
stdcall dll.Load, @IMPORT
test eax, eax
69,69 → 67,97
mov ecx, URLMAXLEN-1
rep stosb
 
call load_settings
cmp byte[params], 0
je prepare_event ;red
; load proxy 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
 
; we have an url
mov edi, document_user
mov al, ' '
mov ecx, URLMAXLEN
rep stosb
; check parameters
cmp byte[params], 0 ; no parameters ?
je reset_events ; load the GUI
; we have an url, copy untill space or 0
mov esi, params
mov edi, document_user
 
; copy untill space or 0
mov ecx, 1024 ; max parameter size
mov [shared_name], 0
.copy_param:
mov al, [esi]
lodsb
test al, al
jz .done
 
cmp al, ' '
jz .done_inc
jz .done_with_shared
 
mov [edi], al
inc esi
inc edi
jmp .copy_param
stosb
dec ecx
jnz .copy_param
DEBUGF 2, "Invalid parameters\n"
jmp exit
 
.done_inc:
 
; url is followed by shared memory name.
inc esi
.done_with_shared:
mov [shared_name], esi
.done:
mov [shared_name], esi
jmp download
xor al, al
stosb
 
prepare_event:
 
download:
 
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
 
cmp byte [params], 0
jne exit
 
reset_events:
 
DEBUGF 1, "resetting events\n"
 
; Report events
; Stack 8 + defaults
mcall 40, 10100111b
; defaults + mouse
mcall 40, EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE
 
red: ; redraw
redraw:
call draw_window
 
still:
cmp byte [params], 0
jne exit
DEBUGF 1, "waiting for events\n"
 
mcall 10 ; wait here for event
cmp eax, 1 ; redraw request ?
je red
 
cmp eax, 2 ; key in buffer ?
cmp eax, EV_REDRAW
je redraw
 
cmp eax, EV_KEY
je key
 
cmp eax, 3 ; button in buffer ?
cmp eax, EV_BUTTON
je button
cmp eax, 6 ; mouse in buffer ?
cmp eax, EV_MOUSE
je mouse
 
jmp still
 
 
key:
mcall 2 ; read key
 
145,6 → 171,7
button:
 
mcall 17 ; get id
 
cmp ah, 26
jne @f
call save_to_file
163,41 → 190,20
or eax, -1 ; close this program
mcall
 
download:
 
DEBUGF 1, "Starting download\n"
save:
cmp [shared_name], 0
je .use_file
 
call parse_url
call open_socket
call send_request
call save_in_shared
jmp .done
 
mcall 68, 12, BUFFERSIZE
mov [buf_ptr], eax
mov [buf_size], 0
.use_file:
 
call read_incoming_data
call save_to_file
 
mcall close, [socketnum]
.done:
 
call parse_result
call save
 
mcall 68, 13, [final_buffer]
 
jmp still
 
 
save:
 
mov ecx, [shared_name]
test ecx, ecx
jz @f
cmp [ecx], byte 0
jnz save_in_shared
@@:
 
call save_to_file
 
; if called from command line, then exit
cmp byte[params], 0
jne exit
206,31 → 212,27
 
save_in_shared:
 
mov esi, 1 ; SHM_OPEN+SHM_WRITE
mcall 68, 22
; open the shared memory area
mov esi, 1
mcall 68, 22, [shared_name], , 1 ; SHM_OPEN+SHM_WRITE
test eax, eax
jz exit
 
sub edx, 4
jbe exit
 
mov ecx, [final_size]
cmp ecx, edx
jb @f
; store the size
mov [eax], ecx
 
mov ecx, edx
@@:
mov [eax], ecx
; now copy the data
lea edi, [eax+4]
mov esi, [final_buffer]
mov edx, ecx
mov eax, ecx
shr ecx, 2
rep movsd
mov ecx, edx
mov ecx, eax
and ecx, 3
rep movsb
 
jmp exit
ret
 
 
;****************************************************************************
341,6 → 343,7
sub esi, request ; length
xor edi, edi ; flags
mcall send, [socketnum], request ;' HTTP/1.1 .. '
 
ret
 
;****************************************************************************
355,6 → 358,8
 
DEBUGF 1, "Reading incoming data\n"
 
mcall 40, EVM_STACK ; we only want stack events now
 
mov eax, [buf_ptr]
mov [pos], eax
 
628,8 → 633,6
.adding:
shl eax, 4
or eax, ecx
; jmp .not_number
;.bad:
.bad:
jmp .next
.done:
806,8 → 809,9
inc edi
cmp edi, server_ip+3
jbe ip1
jmp pu_011
 
ret
 
pu_010:
DEBUGF 1, "Resolving %s\n", webAddr
 
830,30 → 834,10
 
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
 
;***************************************************************************
; Function
; append_proxy_auth_header
;
; Description
960,6 → 944,7
mcall 4, <102, 59>, , button_text
 
mcall 12, 2 ; end window redraw
 
ret