Subversion Repositories Kolibri OS

Rev

Rev 3566 | Rev 3618 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3561 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2009-2013. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  downloader.asm - HTTP client for KolibriOS                     ;;
7
;;                                                                 ;;
8
;;  Based on HTTPC.asm for menuetos by ville turjanmaa             ;;
9
;;                                                                 ;;
10
;;  Programmers: Barsuk, Clevermouse, Marat Zakiyanov,             ;;
11
;;      Kirill Lipatov, dunkaist, HidnPlayr                        ;;
12
;;                                                                 ;;
13
;;          GNU GENERAL PUBLIC LICENSE                             ;;
14
;;             Version 2, June 1991                                ;;
15
;;                                                                 ;;
16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17
 
18
URLMAXLEN               = 1024
3566 hidnplayr 19
BUFFERSIZE              = 4096
3561 hidnplayr 20
 
21
__DEBUG__       = 1
3564 hidnplayr 22
__DEBUG_LEVEL__ = 2
3561 hidnplayr 23
 
24
format binary as ""
25
 
26
use32
27
        org     0x0
28
 
29
        db      'MENUET01'      ; header
30
        dd      0x01            ; header version
31
        dd      START           ; entry point
32
        dd      IM_END          ; image size
3566 hidnplayr 33
        dd      I_END+0x100     ; required memory
34
        dd      I_END+0x100     ; esp
3561 hidnplayr 35
        dd      params          ; I_PARAM
36
        dd      0x0             ; I_Path
37
 
38
include '../macros.inc'
39
include '../proc32.inc'
40
include '../network.inc'
41
include '../../develop/libraries/box_lib/trunk/box_lib.mac'
42
include '../dll.inc'
43
include '../debug-fdo.inc'
44
 
45
START:
46
 
47
        mcall   68, 11                  ; init heap so we can allocate memory dynamically
48
 
49
        mcall   40, EV_STACK
50
 
51
; load libraries
52
        stdcall dll.Load, @IMPORT
53
        test    eax, eax
54
        jnz     exit
55
 
3566 hidnplayr 56
; prepare webAddr area
3561 hidnplayr 57
        mov     al, ' '
58
        mov     edi, webAddr
59
        mov     ecx, URLMAXLEN
60
        rep     stosb
61
        xor     eax, eax
62
        stosb
63
 
64
; prepare document area
65
        mov     al, '/'
66
        mov     edi, document
67
        stosb
68
        mov     al, ' '
69
        mov     ecx, URLMAXLEN-1
70
        rep     stosb
71
 
72
        call    load_settings
73
        cmp     byte[params], 0
74
        je      prepare_event   ;red
75
 
76
; we have an url
77
        mov     edi, document_user
78
        mov     al, ' '
79
        mov     ecx, URLMAXLEN
80
        rep     stosb
81
 
82
        mov     esi, params
83
        mov     edi, document_user
84
 
85
; copy untill space or 0
86
  .copy_param:
87
        mov     al, [esi]
88
        test    al, al
89
        jz      .done
90
 
91
        cmp     al, ' '
92
        jz      .done_inc
93
 
94
        mov     [edi], al
95
        inc     esi
96
        inc     edi
97
        jmp     .copy_param
98
 
99
  .done_inc:
100
 
101
; url is followed by shared memory name.
102
        inc     esi
103
  .done:
104
        mov     [shared_name], esi
3572 hidnplayr 105
        jmp     download
3561 hidnplayr 106
 
107
prepare_event:
108
; Report events
109
; Stack 8 + defaults
110
        mcall   40, 10100111b
111
 
112
red:    ; redraw
113
        call    draw_window
114
 
115
still:
3572 hidnplayr 116
        cmp     byte [params], 0
117
        jne     exit
118
 
3566 hidnplayr 119
        mcall   10      ; wait here for event
3561 hidnplayr 120
        cmp     eax, 1  ; redraw request ?
121
        je      red
122
 
123
        cmp     eax, 2  ; key in buffer ?
124
        je      key
125
 
126
        cmp     eax, 3  ; button in buffer ?
127
        je      button
128
 
129
        cmp     eax, 6  ; mouse in buffer ?
130
        je      mouse
131
 
3566 hidnplayr 132
        jmp     still
3561 hidnplayr 133
 
134
 
135
key:
136
        mcall   2       ; read key
137
 
138
        stdcall [edit_box_key], dword edit1
139
 
3566 hidnplayr 140
        cmp     ax, 13 shl 8
141
        je      download
3561 hidnplayr 142
 
143
        jmp     still
144
 
145
button:
146
 
147
        mcall   17      ; get id
148
        cmp     ah, 26
3566 hidnplayr 149
        jne     @f
150
        call    save_to_file
151
        jmp     still
152
  @@:
3561 hidnplayr 153
        cmp     ah, 1   ; button id=1 ?
3566 hidnplayr 154
        je      exit
3561 hidnplayr 155
 
3566 hidnplayr 156
        jmp     download
3561 hidnplayr 157
 
3566 hidnplayr 158
mouse:
159
        stdcall [edit_box_mouse], edit1
160
        jmp     still
161
 
3561 hidnplayr 162
exit:
163
        or      eax, -1  ; close this program
164
        mcall
3566 hidnplayr 165
 
166
download:
167
 
168
        DEBUGF  1, "Starting download\n"
169
 
170
        call    parse_url
171
        call    open_socket
172
        call    send_request
173
 
174
        mcall   68, 12, BUFFERSIZE
175
        mov     [buf_ptr], eax
176
        mov     [buf_size], 0
177
 
178
        call    read_incoming_data
179
 
180
        mcall   close, [socketnum]
181
 
182
        call    parse_result
183
        call    save
184
 
185
        mcall   68, 13, [final_buffer]
186
 
3561 hidnplayr 187
        jmp     still
188
 
3566 hidnplayr 189
 
3561 hidnplayr 190
save:
191
 
3566 hidnplayr 192
        mov     ecx, [shared_name]
193
        test    ecx, ecx
194
        jz      @f
195
        cmp     [ecx], byte 0
196
        jnz     save_in_shared
197
    @@:
3561 hidnplayr 198
 
3566 hidnplayr 199
        call    save_to_file
3561 hidnplayr 200
 
3566 hidnplayr 201
; if called from command line, then exit
202
        cmp     byte[params], 0
203
        jne     exit
3561 hidnplayr 204
 
3566 hidnplayr 205
        ret
3561 hidnplayr 206
 
3566 hidnplayr 207
save_in_shared:
3561 hidnplayr 208
 
3566 hidnplayr 209
        mov     esi, 1   ; SHM_OPEN+SHM_WRITE
210
        mcall   68, 22
211
        test    eax, eax
212
        jz      exit
3561 hidnplayr 213
 
3566 hidnplayr 214
        sub     edx, 4
215
        jbe     exit
3561 hidnplayr 216
 
3566 hidnplayr 217
        mov     ecx, [final_size]
218
        cmp     ecx, edx
219
        jb      @f
3561 hidnplayr 220
 
3566 hidnplayr 221
        mov     ecx, edx
222
    @@:
223
        mov     [eax], ecx
224
        lea     edi, [eax+4]
225
        mov     esi, [final_buffer]
226
        mov     edx, ecx
227
        shr     ecx, 2
228
        rep     movsd
229
        mov     ecx, edx
230
        and     ecx, 3
231
        rep     movsb
232
 
233
        jmp     exit