Subversion Repositories Kolibri OS

Rev

Rev 4160 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4160 Rev 4205
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2009-2013. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2009-2013. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;  downloader.asm - HTTP client for KolibriOS                     ;;
6
;;  downloader.asm - HTTP client for KolibriOS                     ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;                                                                 ;;
8
;;                                                                 ;;
9
;;          GNU GENERAL PUBLIC LICENSE                             ;;
9
;;          GNU GENERAL PUBLIC LICENSE                             ;;
10
;;             Version 2, June 1991                                ;;
10
;;             Version 2, June 1991                                ;;
11
;;                                                                 ;;
11
;;                                                                 ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
 
13
 
14
URLMAXLEN       = 1024
14
URLMAXLEN       = 1024
15
BUFFERSIZE      = 4096
15
BUFFERSIZE      = 4096
16
 
16
 
17
__DEBUG__       = 1
17
__DEBUG__       = 1
18
__DEBUG_LEVEL__ = 1
18
__DEBUG_LEVEL__ = 1
19
 
19
 
20
format binary as ""
20
format binary as ""
21
 
21
 
22
use32
22
use32
23
        org     0x0
23
        org     0x0
24
 
24
 
25
        db      'MENUET01'      ; header
25
        db      'MENUET01'      ; header
26
        dd      0x01            ; header version
26
        dd      0x01            ; header version
27
        dd      START           ; entry point
27
        dd      START           ; entry point
28
        dd      IM_END          ; image size
28
        dd      IM_END          ; image size
29
        dd      I_END+0x1000    ; required memory
29
        dd      I_END+0x1000    ; required memory
30
        dd      I_END+0x1000    ; esp
30
        dd      I_END+0x1000    ; esp
31
        dd      params          ; I_PARAM
31
        dd      params          ; I_PARAM
32
        dd      0x0             ; I_Path
32
        dd      0x0             ; I_Path
33
 
33
 
34
include '../../../../macros.inc'
34
include '../../../../macros.inc'
35
include '../../../../proc32.inc'
35
include '../../../../proc32.inc'
36
include '../../../../dll.inc'
36
include '../../../../dll.inc'
37
include '../../../../debug-fdo.inc'
37
include '../../../../debug-fdo.inc'
38
include '../../box_lib/trunk/box_lib.mac'
38
include '../../box_lib/trunk/box_lib.mac'
39
include '../../http/http.inc'
39
include '../../http/http.inc'
40
 
40
 
41
virtual at 0
41
virtual at 0
42
        http_msg http_msg
42
        http_msg http_msg
43
end virtual
43
end virtual
44
 
44
 
45
START:
45
START:
46
 
46
 
47
        mcall   68, 11                  ; init heap so we can allocate memory dynamically
47
        mcall   68, 11                  ; init heap so we can allocate memory dynamically
48
 
48
 
49
; load libraries
49
; load libraries
50
        stdcall dll.Load, @IMPORT
50
        stdcall dll.Load, @IMPORT
51
        test    eax, eax
51
        test    eax, eax
52
        jnz     exit
52
        jnz     exit
53
 
53
 
54
; check parameters
54
; check parameters
55
        cmp     byte[params], 0         ; no parameters ?
55
        cmp     byte[params], 0         ; no parameters ?
56
        je      reset_events            ; load the GUI
56
        je      reset_events            ; load the GUI
57
 
57
 
58
        inc     [silently]
58
        inc     [silently]
59
 
59
 
60
download:
60
download:
61
 
61
 
62
        DEBUGF  1, "Starting download\n"
62
        DEBUGF  1, "Starting download\n"
63
 
63
 
64
        invoke  HTTP_get, params
64
        invoke  HTTP_get, params
65
        test    eax, eax
65
        test    eax, eax
66
        jz      fail
66
        jz      fail
67
        mov     [identifier], eax
67
        mov     [identifier], eax
68
 
68
 
69
  .loop:
69
  .loop:
70
        invoke  HTTP_process, [identifier]
70
        invoke  HTTP_process, [identifier]
71
        test    eax, eax
71
        test    eax, eax
72
        jnz     .loop
72
        jnz     .loop
73
 
73
 
74
        test    [silently], 0xff
74
        test    [silently], 0xff
75
        jnz     save
75
        jnz     save
76
 
76
 
77
reset_events:
77
reset_events:
78
        DEBUGF  1, "resetting events\n"
78
        DEBUGF  1, "resetting events\n"
79
 
79
 
80
; Report events
80
; Report events
81
; defaults + mouse
81
; defaults + mouse
82
        mcall   40,EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER
82
        mcall   40,EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER
83
 
83
 
84
redraw:
84
redraw:
85
        call    draw_window
85
        call    draw_window
86
 
86
 
87
still:
87
still:
88
;;        DEBUGF  1, "waiting for events\n"
88
;;        DEBUGF  1, "waiting for events\n"
89
 
89
 
90
        mcall   10      ; wait here for event
90
        mcall   10      ; wait here for event
91
 
91
 
92
        cmp     eax, EV_REDRAW
92
        cmp     eax, EV_REDRAW
93
        je      redraw
93
        je      redraw
94
 
94
 
95
        cmp     eax, EV_KEY
95
        cmp     eax, EV_KEY
96
        je      key
96
        je      key
97
 
97
 
98
        cmp     eax, EV_BUTTON
98
        cmp     eax, EV_BUTTON
99
        je      button
99
        je      button
100
        
100
        
101
        cmp     eax, EV_MOUSE
101
        cmp     eax, EV_MOUSE
102
        je      mouse
102
        je      mouse
103
 
103
 
104
        jmp     still
104
        jmp     still
105
 
105
 
106
key:
106
key:
107
        mcall   2       ; read key
107
        mcall   2       ; read key
108
 
108
 
109
        stdcall [edit_box_key], dword edit1
109
        stdcall [edit_box_key], dword edit1
110
 
110
 
111
        cmp     ax, 13 shl 8
111
        cmp     ax, 13 shl 8
112
        je      download
112
        je      download
113
        
113
        
114
        jmp     still
114
        jmp     still
115
        
115
        
116
button:
116
button:
117
 
117
 
118
        mcall   17      ; get id
118
        mcall   17      ; get id
119
 
119
 
120
        cmp     ah, 26
120
        cmp     ah, 26
121
        jne     @f
121
        jne     @f
122
        call    save
122
        call    save
123
        jmp     still
123
        jmp     still
124
  @@:
124
  @@:
125
        cmp     ah, 1   ; button id=1 ?
125
        cmp     ah, 1   ; button id=1 ?
126
        je      exit
126
        je      exit
127
 
127
 
128
        jmp     download
128
        jmp     download
129
 
129
 
130
mouse:
130
mouse:
131
        stdcall [edit_box_mouse], edit1
131
        stdcall [edit_box_mouse], edit1
132
        jmp     still
132
        jmp     still
133
 
133
 
134
exit:
134
exit:
135
        DEBUGF  1, "Exiting\n"
135
        DEBUGF  1, "Exiting\n"
136
        mcall   68, 13, [identifier]    ; free buffer
136
        invoke  HTTP_free, [identifier] ; free buffer
137
fail:
137
fail:
138
        or      eax, -1 ; close this program
138
        or      eax, -1 ; close this program
139
        mcall
139
        mcall
140
 
140
 
141
 
141
 
142
save:
142
save:
143
        mov     ebp, [identifier]
143
        mov     ebp, [identifier]
144
        mov     eax, [ebp + http_msg.content_length]
144
        mov     eax, [ebp + http_msg.content_length]
145
        mov     [final_size], eax
145
        mov     [final_size], eax
146
        lea     ebx, [ebp + http_msg.data]
146
        lea     ebx, [ebp + http_msg.data]
147
        add     ebx, [ebp + http_msg.header_length]
147
        add     ebx, [ebp + http_msg.header_length]
148
        mov     [final_buffer], ebx
148
        mov     [final_buffer], ebx
149
        mcall   70, fileinfo
149
        mcall   70, fileinfo
150
 
150
 
151
        test    [silently], 0xff
151
        test    [silently], 0xff
152
        jnz     exit
152
        jnz     exit
153
 
153
 
154
        mov     ecx, [sc.work_text]
154
        mov     ecx, [sc.work_text]
155
        or      ecx, 0x80000000
155
        or      ecx, 0x80000000
156
        mcall   4, <10, 93>, , download_complete
156
        mcall   4, <10, 93>, , download_complete
157
 
157
 
158
        jmp     still
158
        jmp     still
159
 
159
 
160
;   *********************************************
160
;   *********************************************
161
;   *******  WINDOW DEFINITIONS AND DRAW ********
161
;   *******  WINDOW DEFINITIONS AND DRAW ********
162
;   *********************************************
162
;   *********************************************
163
 
163
 
164
draw_window:
164
draw_window:
165
 
165
 
166
        mcall   12, 1   ; start window draw
166
        mcall   12, 1   ; start window draw
167
 
167
 
168
; get system colors
168
; get system colors
169
        mcall   48, 3, sc, 40
169
        mcall   48, 3, sc, 40
170
 
170
 
171
; draw window
171
; draw window
172
        mov     edx, [sc.work]
172
        mov     edx, [sc.work]
173
        or      edx, 0x34000000
173
        or      edx, 0x34000000
174
        mcall   0, <50, 370>, <350, 140>, , 0, title
174
        mcall   0, <50, 370>, <350, 140>, , 0, title
175
 
175
 
176
; draw "url:" text
176
; draw "url:" text
177
        mov     ecx, [sc.work_text]
177
        mov     ecx, [sc.work_text]
178
        or      ecx, 80000000h
178
        or      ecx, 80000000h
179
        mcall   4, <14, 14>, , type_pls
179
        mcall   4, <14, 14>, , type_pls
180
 
180
 
181
; draw editbox
181
; draw editbox
182
        edit_boxes_set_sys_color edit1, editboxes_end, sc
182
        edit_boxes_set_sys_color edit1, editboxes_end, sc
183
        stdcall [edit_box_draw], edit1
183
        stdcall [edit_box_draw], edit1
184
 
184
 
185
; draw buttons
185
; draw buttons
186
        mcall   8, <90, 68>, <54, 16>, 22, [sc.work_button]     ; reload
186
        mcall   8, <90, 68>, <54, 16>, 22, [sc.work_button]     ; reload
187
        mcall   , <166, 50>, <54, 16>, 24                       ; stop
187
        mcall   , <166, 50>, <54, 16>, 24                       ; stop
188
        mcall   , <224, 54>, , 26                               ; save
188
        mcall   , <224, 54>, , 26                               ; save
189
 
189
 
190
; draw buttons text
190
; draw buttons text
191
        mov     ecx, [sc.work_button_text]
191
        mov     ecx, [sc.work_button_text]
192
        or      ecx, 80000000h
192
        or      ecx, 80000000h
193
        mcall   4, <102, 59>, , button_text
193
        mcall   4, <102, 59>, , button_text
194
 
194
 
195
        mcall   12, 2   ; end window redraw
195
        mcall   12, 2   ; end window redraw
196
 
196
 
197
        ret
197
        ret
198
 
198
 
199
 
199
 
200
;-----------------------------------------------------------------------------
200
;-----------------------------------------------------------------------------
201
; Data area
201
; Data area
202
;-----------------------------------------------------------------------------
202
;-----------------------------------------------------------------------------
203
align   4
203
align   4
204
@IMPORT:
204
@IMPORT:
205
 
205
 
206
library lib_http,       'http.obj', \
206
library lib_http,       'http.obj', \
207
        box_lib,        'box_lib.obj'
207
        box_lib,        'box_lib.obj'
208
 
208
 
209
import  lib_http, \
209
import  lib_http, \
210
        HTTP_get                , 'get' , \
210
        HTTP_get                , 'get' , \
211
        HTTP_process            , 'process'
211
        HTTP_process            , 'process'     ,\
-
 
212
        HTTP_free               , 'free'
212
 
213
 
213
import  box_lib, \
214
import  box_lib, \
214
        edit_box_draw,  'edit_box', \
215
        edit_box_draw,  'edit_box', \
215
        edit_box_key,   'edit_box_key', \
216
        edit_box_key,   'edit_box_key', \
216
        edit_box_mouse, 'edit_box_mouse'
217
        edit_box_mouse, 'edit_box_mouse'
217
 
218
 
218
;---------------------------------------------------------------------
219
;---------------------------------------------------------------------
219
fileinfo        dd 2, 0, 0
220
fileinfo        dd 2, 0, 0
220
final_size      dd 0
221
final_size      dd 0
221
final_buffer    dd 0
222
final_buffer    dd 0
222
                db '/rd/1/.download', 0
223
                db '/rd/1/.download', 0
223
        
224
        
224
;---------------------------------------------------------------------
225
;---------------------------------------------------------------------
225
 
226
 
226
mouse_dd        dd 0
227
mouse_dd        dd 0
227
edit1           edit_box 295, 48, 10, 0xffffff, 0xff, 0x80ff, 0, 0x8000, URLMAXLEN, document_user, mouse_dd, ed_focus+ed_always_focus, 7, 7
228
edit1           edit_box 295, 48, 10, 0xffffff, 0xff, 0x80ff, 0, 0x8000, URLMAXLEN, document_user, mouse_dd, ed_focus+ed_always_focus, 7, 7
228
editboxes_end:
229
editboxes_end:
229
 
230
 
230
;---------------------------------------------------------------------
231
;---------------------------------------------------------------------
231
 
232
 
232
include_debug_strings
233
include_debug_strings
233
 
234
 
234
;---------------------------------------------------------------------
235
;---------------------------------------------------------------------
235
 
236
 
236
type_pls        db 'URL:', 0
237
type_pls        db 'URL:', 0
237
button_text     db 'DOWNLOAD     STOP      SAVE', 0
238
button_text     db 'DOWNLOAD     STOP      SAVE', 0
238
download_complete db 'File saved as /rd/1/.download', 0
239
download_complete db 'File saved as /rd/1/.download', 0
239
title           db 'HTTP Downloader', 0
240
title           db 'HTTP Downloader', 0
240
silently        db 0
241
silently        db 0
241
 
242
 
242
;---------------------------------------------------------------------
243
;---------------------------------------------------------------------
243
document_user   db 'http://'
244
document_user   db 'http://'
244
;---------------------------------------------------------------------
245
;---------------------------------------------------------------------
245
IM_END:
246
IM_END:
246
;---------------------------------------------------------------------
247
;---------------------------------------------------------------------
247
params          rb URLMAXLEN
248
params          rb URLMAXLEN
248
;---------------------------------------------------------------------
249
;---------------------------------------------------------------------
249
                sc system_colors
250
                sc system_colors
250
;---------------------------------------------------------------------
251
;---------------------------------------------------------------------
251
identifier      dd ?
252
identifier      dd ?
252
;---------------------------------------------------------------------
253
;---------------------------------------------------------------------
253
 
254
 
254
I_END:
255
I_END: