Subversion Repositories Kolibri OS

Rev

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

Rev 1645 Rev 1646
-
 
1
; version: 0.5
-
 
2
; last update:  07/10/2010
-
 
3
; written by:   Marat Zakiyanov aka Mario79, aka Mario
-
 
4
; changes:      reducing the size of the binary code,
-
 
5
;               program uses far less memory while running
-
 
6
;               (>0x7000, the old version used >0x100000),
-
 
7
;               process only net event at start with parameter
-
 
8
;-----------------------------------------------------------
-
 
9
; version 0.3 -0.4 
-
 
10
; written by:   CleverMouse
-
 
11
;
-
 
12
;-----------------------------------------------------------
1
; wget 0.2 by barsuk
13
; wget 0.2 by barsuk
2
; based on Menuet Httpc
14
; based on Menuet Httpc
3
 
15
 
4
 
16
 
5
; Enabling debugging puts stuff to the debug board
17
; Enabling debugging puts stuff to the debug board
6
DEBUGGING_ENABLED           equ     1
18
DEBUGGING_ENABLED	equ 1
7
DEBUGGING_DISABLED          equ     0
19
DEBUGGING_DISABLED	equ 0
8
DEBUGGING_STATE             equ     DEBUGGING_ENABLED
20
DEBUGGING_STATE		equ DEBUGGING_ENABLED
9
 
21
 
10
use32
22
use32
11
 org    0x0
23
	org	0x0
12
 db     'MENUET01'    ; header
24
	db 'MENUET01'	; header
13
 dd     0x01          ; header version
25
	dd 0x01		; header version
14
 dd     START         ; entry point
26
	dd START	; entry point
15
 dd     I_END         ; image size
27
	dd IM_END	; image size
16
 dd     0x100000      ; required memory
28
	dd I_END	;0x100000 ; required memory
17
 dd     0x100000      ; esp
29
	dd stacktop	; esp
18
 dd     params		  ; I_PARAM
30
	dd params	; I_PARAM
19
 dd		0x0     	  ;I_Path
31
	dd 0x0		; I_Path
20
 
32
 
21
include 'lang.inc'
33
include	'lang.inc'
22
include '../../../macros.inc'
34
include	'../../../macros.inc'
-
 
35
include	"../../../proc32.inc"
-
 
36
include	"dll.inc"
23
include "DEBUG.INC"
37
include	"debug.inc"
24
 
38
 
25
URLMAXLEN       equ     256  ; maximum length of url string
39
URLMAXLEN	equ 256	; maximum length of url string
26
 
40
 
27
primary_buffer_size	equ	4096
41
primary_buffer_size	equ 4096
28
 
42
 
29
; Memory usage
43
; Memory usage
30
; webpage headers at buf_headers
44
; webpage headers at buf_headers
31
 
45
 
32
START:                              ; start of execution
46
START:	; start of execution
33
 
-
 
34
;dps <"Program started",13,10>
47
;dps	<"Program started",13,10>
-
 
48
; prepare webAddr area	
-
 
49
	mov	al,' '
-
 
50
	mov	edi,webAddr
-
 
51
	mov	ecx,URLMAXLEN
-
 
52
	cld
-
 
53
	rep	stosb
-
 
54
	xor	eax,eax
-
 
55
	stosb
-
 
56
; prepare document area	
-
 
57
	mov	al,'/'
-
 
58
	mov	edi,document
-
 
59
	cld
-
 
60
	stosb
-
 
61
	mov	al,' '
-
 
62
	mov	ecx,URLMAXLEN-1
-
 
63
	rep	stosb
35
 
-
 
36
    mov     eax,40                          ; Report events
-
 
37
    mov     ebx,10000111b                   ; Stack 8 + defaults
-
 
38
    mcall
-
 
39
	
64
 
40
	mov		eax, 68						; create local heap
-
 
41
	mov		ebx, 11
65
; create local heap
42
	mcall
66
	mcall	68,11
-
 
67
 
-
 
68
	call	load_settings
43
	
69
	cmp	[params],byte 0
44
	call		load_settings
-
 
45
	
70
	jz	prepare_event	;red
46
	cmp		byte [params], 0
-
 
47
	jz		red
71
 
48
	
72
	mcall	40,10000000b ; only net event!!!
49
	; we have an url
73
 
50
	
74
; we have an url
51
	mov		edi, document_user
75
	mov	edi,document_user
52
	mov		al, ' '
76
	mov	al,' '
53
	mov		ecx, URLMAXLEN
77
	mov	ecx,URLMAXLEN
54
	rep		stosb
78
	rep	stosb
55
	
79
	
56
	mov		esi, params
80
	mov	esi,params
57
	mov		edi, document_user
81
	mov	edi,document_user
-
 
82
 
58
.copy_param:
83
.copy_param:
59
	mov		al, [esi]
84
	mov	al,[esi]
60
	cmp		al, 0
85
	cmp	al,0
61
	jz		.done
86
	jz	.done
-
 
87
 
62
	cmp		al, ' '
88
	cmp	al,' '
63
	jz		.done_inc
89
	jz	.done_inc
-
 
90
 
64
	mov		[edi], al
91
	mov	[edi],al
65
	inc		esi
92
	inc	esi
66
	inc		edi
93
	inc	edi
67
	jmp		.copy_param
94
	jmp	.copy_param
-
 
95
 
68
.done_inc:
96
.done_inc:
69
	; url is followed by shared memory name.
97
; url is followed by shared memory name.
70
	inc		esi
98
	inc	esi
71
.done:
99
.done:
72
	mov		[shared_name], esi
100
	mov	[shared_name],esi
73
 
101
 
74
	mov		ah, 22			; strange way to tell that socket should be opened...
102
	mov	ah,22	; strange way to tell that socket should be opened...
75
	call	socket_commands
103
	call	socket_commands
76
	
104
 
77
	jmp		still
105
	jmp	still
-
 
106
 
-
 
107
prepare_event:
-
 
108
; Report events
-
 
109
; Stack 8 + defaults
-
 
110
	mcall	40,10000111b
78
	
111
 
79
red:                    ; redraw
112
red:	; redraw
80
    call    draw_window
113
	call	draw_window
81
 
114
 
82
still:
115
still:
83
    mov     eax,23                 ; wait here for event
116
	mcall	23,1	; wait here for event
84
    mov     ebx,1
-
 
85
    mcall
-
 
86
 
-
 
87
    cmp     eax,1                  ; redraw request ?
117
	cmp	eax,1	; redraw request ?
88
    je      red
118
	je	red
-
 
119
 
89
    cmp     eax,2                  ; key in buffer ?
120
	cmp	eax,2	; key in buffer ?
90
    je      key
121
	je	key
-
 
122
 
91
    cmp     eax,3                  ; button in buffer ?
123
	cmp	eax,3	; button in buffer ?
92
    je      button
124
	je	button
93
 
125
 
94
    ; Get the web page data from the remote server
126
; Get the web page data from the remote server
95
    call    read_incoming_data
127
	call	read_incoming_data
96
	
-
 
97
    mov     eax,[status]
128
	mov	eax,[status]
98
    mov     [prev_status],eax
129
	mov	[prev_status],eax
99
 
-
 
100
    mov     eax,53
-
 
101
    mov     ebx,6
-
 
102
    mov     ecx,[socket]
130
	mcall	53,6,[socket]
103
    mcall
-
 
104
 
-
 
105
    mov     [status],eax
131
	mov	[status],eax
106
 
132
 
107
    cmp     [prev_status],4
133
	cmp	[prev_status],4
108
    jge     no_send
134
	jge	no_send
-
 
135
 
109
    cmp     [status],4
136
	cmp	[status],4
110
    jne     no_send
137
	jne	no_send
111
 
138
 
112
    mov     [onoff],1
139
	mov	[onoff],1
113
 
-
 
114
    call    send_request
140
	call	send_request
115
 
141
 
116
no_send:
142
no_send:
117
    call    print_status
143
	call	print_status
118
 
144
 
119
    cmp     [prev_status],4
145
	cmp	[prev_status],4
120
    jne     no_close
146
	jne	no_close
121
    cmp     [status],4   ; connection closed by server
147
	cmp	[status],4	; connection closed by server
122
    jbe     no_close     ; respond to connection close command
148
	jbe	no_close	; respond to connection close command
123
                         ; draw page
149
; draw page
124
 
-
 
125
    call    read_incoming_data
150
	call	read_incoming_data
126
 
-
 
127
    mov     eax,53
-
 
128
    mov     ebx,8
-
 
129
    mov     ecx,[socket]
151
	mcall	53,8,[socket]
130
    mcall
-
 
131
 
-
 
132
    call    draw_page
152
	call	draw_page
133
 
-
 
134
    mov     [onoff],0
153
	mov	[onoff],0
135
 
154
 
136
no_close:
155
no_close:
137
    jmp     still
156
	jmp	still
138
 
157
 
139
key:                    ; key
158
key:	; key
140
    mov     eax,2       ; just read it and ignore
159
	mcall	2	; just read it and ignore
141
    mcall
-
 
142
    shr     eax,8
160
	shr	eax,8
143
    cmp     eax,184
161
	cmp	eax,184
144
    jne     no_down
162
	jne	no_down
145
    cmp     [display_from],25
163
	cmp	[display_from],25
146
    jb      no_down
164
	jb	no_down
147
    sub     [display_from],25
165
	sub	[display_from],25
148
    call    display_page
166
	call	display_page
149
 
167
 
150
no_down:
168
no_down:
151
    cmp     eax,183
169
	cmp	eax,183
152
    jne     no_up
170
	jne	no_up
153
    add     [display_from],25
171
	add	[display_from],25
154
    call    display_page
172
	call	display_page
155
 
173
 
156
no_up:
174
no_up:
157
    jmp     still
175
	jmp	still
158
 
176
 
159
button:                 ; button
177
button:	; button
160
;dps <"Button pressed",13,10>
178
;dps	<"Button pressed",13,10>
161
    mov     eax,17      ; get id
179
	mcall	17	; get id
162
    mcall
-
 
163
	cmp		ah,26
180
	cmp	ah,26
164
	je		save
181
	je	save
165
    cmp     ah,1                   ; button id=1 ?
182
	cmp	ah,1	; button id=1 ?
166
    jne     noclose
183
	jne	noclose
167
 
-
 
168
;dps "Closing socket before exit... "
184
;	dps	"Closing socket before exit... "
169
 
185
 
170
close_end_exit:
186
close_end_exit:
171
 
187
 
172
;dpd eax
188
;dpd	eax
173
;dps <13,10>
189
;dps	<13,10>
174
 
190
 
175
exit:
191
exit:
176
    or      eax,-1                 ; close this program
192
	or	eax,-1	; close this program
177
    mcall
193
	mcall
178
 
194
 
179
save:
195
save:
180
dps "saving"
196
dps	"saving"
181
newline
197
newline
182
	mov		eax, 70
-
 
183
	mov		ebx, fileinfo
198
	mcall	70,fileinfo
184
	mcall
-
 
185
;pregs
199
;pregs
186
 
-
 
187
	jmp		still
200
	jmp	still
188
 
201
 
189
noclose:
202
noclose:
190
    cmp     ah,31
203
	cmp	ah,31
191
    jne     noup
204
	jne	noup
192
    sub     [display_from],20
205
	sub	[display_from],20
193
    call    display_page
206
	call	display_page
194
    jmp     still
207
	jmp	still
195
 
208
 
196
noup:
209
noup:
197
    cmp     ah,32
210
	cmp	ah,32
198
    jne     nodown
211
	jne	nodown
199
    add     [display_from],20
212
	add	[display_from],20
200
    call    display_page
213
	call	display_page
201
    jmp     still
214
	jmp	still
202
 
215
 
203
nodown:
216
nodown:
204
    cmp     ah, 10              ; Enter url
217
	cmp	ah,10	; Enter url
205
    jne     nourl
218
	jne	nourl
206
 
219
 
207
    mov     [addr],dword document_user
220
	mov	[addr],dword document_user
208
    mov     [ya],dword 38
221
	mov	[ya],dword 38
209
    mov     [len],dword URLMAXLEN
222
	mov	[len],dword URLMAXLEN
210
 
223
 
211
    mov     ecx,URLMAXLEN
224
	mov	ecx,URLMAXLEN
212
    mov     edi,[addr]
225
	mov	edi,[addr]
213
    mov     al,' '
226
	mov	al,' '
214
    rep     stosb
227
	rep	stosb
215
 
228
 
216
    call    print_text
229
	call	print_text
217
 
230
 
218
    mov     edi,[addr]
231
	mov	edi,[addr]
219
 
232
 
220
f11:
233
f11:
221
    mov     eax,10
-
 
222
    mcall
234
	mcall	10
223
    cmp     eax,2 ; key?
235
	cmp	eax,2	; key?
224
    jz      fbu
236
	jz	fbu
225
    jmp     still
237
	jmp	still
226
 
238
 
227
fbu:
239
fbu:
228
    mov     eax,2
-
 
229
    mcall  ; get key
240
	mcall	2	; get key
230
    shr     eax,8
241
	shr	eax,8
231
    cmp     eax,8
242
	cmp	eax,8
232
    jnz     nobs
243
	jnz	nobs
233
    cmp     edi,[addr]
244
	cmp	edi,[addr]
234
    jz      f11
245
	jz	f11
235
    sub     edi,1
246
	sub	edi,1
236
    mov     [edi],byte ' '
247
	mov	[edi],byte ' '
237
    call    print_text
248
	call	print_text
238
    jmp     f11
249
	jmp	f11
239
 
250
 
240
nobs:
251
nobs:
241
    cmp     eax, dword 10
252
	cmp	eax,10
242
    je      retkey
253
	je	retkey
243
    cmp     eax, dword 13
254
	cmp	eax,13
244
    je      retkey
255
	je	retkey
245
 
256
 
246
    cmp     eax,dword 31
257
	cmp	eax,31
247
    jbe     f11
258
	jbe	f11
248
 
259
 
249
; Removed in v0.4
260
; Removed in v0.4
250
;    cmp     eax,dword 95
261
;	cmp	eax,95
251
;    jb      keyok
262
;	jb	keyok
252
;    sub     eax,32
263
;	sub	eax,32
253
 
264
 
254
keyok:
265
keyok:
255
    mov     [edi],al
266
	mov	[edi],al
256
 
-
 
257
    call    print_text
267
	call	print_text
258
 
-
 
259
    add     edi,1
268
	add	edi,1
260
    mov     esi,[addr]
269
	mov	esi,[addr]
261
    add     esi,URLMAXLEN
270
	add	esi,URLMAXLEN
262
    cmp     esi,edi
271
	cmp	esi,edi
263
    jnz     f11
272
	jnz	f11
264
 
-
 
265
    jmp  still
273
	jmp	still
266
 
274
 
267
retkey:
275
retkey:
268
    mov     ah, 22   ; start load
276
	mov	ah,22	; start load
269
 
277
 
270
nourl:
278
nourl:
271
    call    socket_commands     ; opens or closes the connection
279
	call	socket_commands	; opens or closes the connection
272
    jmp     still
280
	jmp	still
273
 
-
 
274
 
281
 
275
;****************************************************************************
282
;****************************************************************************
276
;    Function
283
;    Function
277
;       send_request
284
;       send_request
278
;
285
;
279
;   Description
286
;   Description
280
;       Transmits the GET request to the server.
287
;       Transmits the GET request to the server.
281
;       This is done as GET then URL then HTTP/1.1',13,10,13,10 in 3 packets
288
;       This is done as GET then URL then HTTP/1.1',13,10,13,10 in 3 packets
282
;
289
;
283
;****************************************************************************
290
;****************************************************************************
284
send_request:
291
send_request:
285
    pusha
292
	pusha
286
	
-
 
287
	mov		esi, string0
293
	mov	esi,string0
288
	mov		edi, request
294
	mov	edi,request
289
	movsd
295
	movsd
290
 
-
 
291
    ; If proxy is used, make absolute URI - prepend http://
296
; If proxy is used, make absolute URI - prepend http://
292
	cmp		byte [proxyAddr], 0
297
	cmp	[proxyAddr],byte 0
293
	jz		.noproxy
298
	jz	.noproxy
294
	mov		dword [edi], 'http'
299
	mov	dword [edi],'http'
295
	mov		byte [edi+4], ':'
300
	mov	[edi+4],byte ':'
296
	mov		word [edi+5], '//'
301
	mov	[edi+5],word '//'
297
	add		edi, 7
302
	add	edi,7
298
	mov		esi, webAddr
303
	mov	esi,webAddr
-
 
304
 
299
.copy_host_loop:
305
.copy_host_loop:
300
	lodsb
306
	lodsb
301
	cmp		al, ' '
307
	cmp	al,' '
302
	jz		.noproxy
308
	jz	.noproxy
303
	stosb
309
	stosb
304
	jmp		.copy_host_loop
310
	jmp	.copy_host_loop
-
 
311
 
305
.noproxy:
312
.noproxy:
-
 
313
	xor	edx,edx ; 0
306
	
-
 
307
	mov		edx, 0
314
 
308
.next_edx:
315
.next_edx:
309
    ; Determine the length of the url to send in the GET request
316
; Determine the length of the url to send in the GET request
310
	mov		al, [edx+document]
317
	mov	al,[edx+document]
311
	cmp		al, ' '
318
	cmp	al,' '
312
    je     	.document_done
319
	je	.document_done
313
	mov		[edi], al
320
	mov	[edi],al
314
	inc		edi
321
	inc	edi
315
    inc     edx
322
	inc	edx
316
	jmp		.next_edx
323
	jmp	.next_edx
317
.document_done:
-
 
-
 
324
 
318
 
325
.document_done:
319
	mov		esi, stringh
326
	mov	esi,stringh
320
	mov		ecx, stringh_end-stringh
327
	mov	ecx,stringh_end-stringh
321
	rep		movsb
328
	rep	movsb
-
 
329
	xor	edx,edx	; 0
322
 
-
 
323
	mov		edx, 0
330
 
324
.webaddr_next:
331
.webaddr_next:
325
	mov		al, [webAddr + edx]
332
	mov	al,[webAddr + edx]
326
	cmp		al, ' '
333
	cmp	al,' '
327
	je		.webaddr_done
334
	je	.webaddr_done
328
	mov		[edi], al
335
	mov	[edi],al
329
	inc		edi
336
	inc	edi
330
	inc		edx
337
	inc	edx
331
	jmp		.webaddr_next
338
	jmp	.webaddr_next
332
.webaddr_done:
-
 
-
 
339
 
333
 
340
.webaddr_done:
334
	cmp		byte [proxyUser], 0
341
	cmp	[proxyUser],byte 0
335
	jz		@f
342
	jz	@f
336
	call		append_proxy_auth_header
343
	call	append_proxy_auth_header
337
@@:
344
@@:
338
 
-
 
339
	mov		esi, connclose
345
	mov	esi,connclose
340
	mov		ecx, connclose_end-connclose
346
	mov	ecx,connclose_end-connclose
341
	rep		movsb
347
	rep	movsb
342
 
348
 
343
	pusha	
349
	pusha	
344
	mov  eax,63
350
	mov	eax,63
345
	mov  ebx,1
351
	mov	ebx,1
346
	mov  edx, request
352
	mov	edx,request
347
@@:
353
@@:
348
   mov  cl,[edx]
354
	mov	cl,[edx]
349
   cmp edx,edi
355
	cmp	edx,edi
350
   jz   @f
356
	jz	@f
351
   int  40h
357
	mcall
352
   inc  edx
358
	inc	edx
353
   jmp  @b
359
	jmp	@b
354
@@:
360
@@:
355
	popa
361
	popa
356
 
362
 
357
    mov     edx, edi
363
	mov	edx,edi
358
	sub		edx, request
364
	sub	edx,request
359
	
-
 
360
	;;;;now write \r\nConnection: Close \r\n\r\n
365
;;;;now write \r\nConnection: Close \r\n\r\n
361
    mov     eax, 53     ; ' HTTP/1.1 .. '
366
	mcall	53,7,[socket],,request	;' HTTP/1.1 .. '
362
    mov     ebx, 7
-
 
363
    mov     ecx, [socket]
-
 
364
    mov     esi, request
-
 
365
    mcall	
-
 
366
 
-
 
367
    popa
367
	popa
368
    ret
368
	ret
369
 
-
 
370
 
369
 
371
;****************************************************************************
370
;****************************************************************************
372
;    Function
371
;    Function
373
;       print_status
372
;       print_status
374
;
373
;
375
;   Description
374
;   Description
376
;       displays the socket/data received status information
375
;       displays the socket/data received status information
377
;
376
;
378
;****************************************************************************
377
;****************************************************************************
379
print_status:
378
print_status:
380
    pusha
379
	pusha
381
 
-
 
382
    mov     eax,26
-
 
383
    mov     ebx,9
-
 
384
    mcall
380
	mcall	26,9
385
 
-
 
386
    cmp     eax,[nextupdate]
381
	cmp	eax,[nextupdate]
387
    jb      status_return
382
	jb	status_return
388
 
383
 
389
    add     eax,25
384
	add	eax,25
390
 
-
 
391
    mov     [nextupdate],eax
385
	mov	[nextupdate],eax
392
 
-
 
393
    mov     eax,13
-
 
394
    mov     ebx,5*65536+100
386
 
395
    mov     ecx,[winys]
387
	mov	ecx,[winys]
396
    shl     ecx,16
388
	shl	ecx,16
397
    add     ecx,-18*65536+10
389
	add	ecx,-18*65536+10
398
    mov     edx,0xffffff
390
	mcall	13,<5,100>,,0xffffff
399
    mcall
-
 
400
 
-
 
401
    mov     eax,47
-
 
402
    mov     ebx,3*65536
-
 
403
    mov     ecx,[status]
391
 
404
    mov     edx,12*65536-18
392
	mov	edx,12*65536-18
405
    add     edx,[winys]
393
	add	edx,[winys]
406
    mov     esi,0x000000
394
	xor	esi,esi
407
    mcall
-
 
408
 
-
 
409
    mov     eax,47
-
 
410
    mov     ebx,6*65536
395
	mcall	47,<3,0>,[status],,
411
    mov     ecx,[pos]
396
 
412
    mov     edx,40*65536-18
397
	mov	edx,40*65536-18
413
    add     edx,[winys]
-
 
414
    mov     esi,0x000000
398
	add	edx,[winys]
415
    mcall
399
	mcall	,<6,0>,[pos]
416
 
400
 
417
status_return:
401
status_return:
418
    popa
402
	popa
419
    ret
403
	ret
420
 
-
 
421
 
404
 
422
;****************************************************************************
405
;****************************************************************************
423
;    Function
406
;    Function
424
;       read_incoming_data
407
;       read_incoming_data
425
;
408
;
426
;   Description
409
;   Description
427
;       receive the web page from the server, storing it without processing
410
;       receive the web page from the server, storing it without processing
428
;
411
;
429
;****************************************************************************
412
;****************************************************************************
430
read_incoming_data:
413
read_incoming_data:
431
    cmp     [onoff],1
414
	cmp	[onoff],1
432
    je      rid
415
	je	rid
433
    ret
416
	ret
434
 
417
 
435
rid:
418
rid:
436
 
-
 
437
	push	esi
419
	push	esi
438
	push	edi
420
	push	edi
439
dps "rid"
421
dps	"rid"
440
newline
422
newline
441
 
423
 
442
newbyteread:
424
newbyteread:
443
 
-
 
444
	;call	print_status
425
	;call	print_status
445
 
-
 
446
    mov     eax, 53
-
 
447
    mov     ebx, 2
-
 
448
    mov     ecx, [socket]
426
	mcall	53,2,[socket]
449
    mcall
-
 
450
 
-
 
451
    cmp     eax,0
427
	cmp	eax,0
452
    je      no_more_data
428
	je	no_more_data
453
 
-
 
454
    mov     eax, 53
-
 
455
    mov     ebx, 11
-
 
456
	mov		edx, primary_buf
-
 
457
    mov     ecx, [socket]
429
 
458
	mov		esi, primary_buffer_size
-
 
459
    mcall
430
	mcall	53,11,[socket],primary_buf,primary_buffer_size
460
	
431
	
461
;dps "part "
432
;dps	"part "
462
;dph eax
433
;dph	eax
463
;newline
434
;newline
464
 
-
 
465
	mov		edi, [pos]
435
	mov	edi,[pos]
466
 
-
 
467
	add		[pos], eax
436
	add	[pos],eax
468
	push	eax
437
	push	eax
469
	
-
 
470
	mov		eax, 68
-
 
471
	mov		ebx, 20
-
 
472
	mov		ecx, [pos]
-
 
473
	mov		edx, [buf_ptr]
438
	mcall	68,20,[pos],[buf_ptr]
474
	mcall
-
 
475
	
-
 
476
	mov		[buf_ptr], eax
439
	mov	[buf_ptr],eax
477
	add		edi, eax
440
	add	edi,eax
478
	mov		esi, primary_buf
441
	mov	esi,primary_buf
479
	pop		ecx					; number of recently read bytes
442
	pop	ecx	; number of recently read bytes
480
	lea		edx, [ecx - 3]
443
	lea	edx,[ecx - 3]
481
	rep		movsb
444
	rep	movsb
482
	
445
	
483
no_more_data:
446
no_more_data:
484
 
-
 
485
	mov		eax, 53
-
 
486
	mov		ebx, 6
-
 
487
	mov		ecx, [socket]
447
	mcall	53,6,[socket]
488
	mcall
-
 
489
	cmp		eax, 4
448
	cmp	eax,4
490
	jne		no_more_data.finish
449
	jne	no_more_data.finish
491
 
-
 
492
	jmp		newbyteread
450
	jmp	newbyteread
493
 
451
 
494
.finish:
452
.finish:
495
 
-
 
496
;dps "finish "
453
;dps	"finish	"
497
;pregs
454
;pregs
498
 
-
 
499
	call	parse_result
455
	call	parse_result
500
 
-
 
501
	mov		ecx, [shared_name]
456
	mov	ecx,[shared_name]
502
	cmp		byte [ecx], 0
457
	cmp	[ecx],byte 0
503
	jnz		save_in_shared
458
	jnz	save_in_shared
504
	mov		eax, 70
459
 
505
	mov		ebx, fileinfo
460
	mcall	70,fileinfo
506
	mcall
-
 
507
;dps "saving "
461
;dps	"saving "
508
;pregs
462
;pregs
509
 
-
 
510
	;jmp		close_end_exit
463
;	jmp	close_end_exit
511
	
-
 
512
	pop		edi
464
	pop	edi
513
	pop		esi
465
	pop	esi
514
	
-
 
515
	; if called from command line, then exit
466
; if called from command line, then exit
516
	cmp		byte [params], 0
467
	cmp	[params],byte 0
517
	jnz		exit
468
	jnz	exit
518
	
-
 
519
    ret
469
	ret
520
	
470
	
521
save_in_shared:
471
save_in_shared:
522
	mov	eax, 68
-
 
523
	mov	ebx, 22
-
 
524
	mov	esi, 1	; SHM_OPEN+SHM_WRITE
472
	mov	esi,1	; SHM_OPEN+SHM_WRITE
525
	mcall
473
	mcall	68,22
526
	test	eax, eax
474
	test	eax,eax
527
	jz	save_in_shared_done
475
	jz	save_in_shared_done
-
 
476
 
528
	sub	edx, 4
477
	sub	edx,4
529
	jbe	save_in_shared_done
478
	jbe	save_in_shared_done
-
 
479
 
530
	mov	ecx, [final_size]
480
	mov	ecx,[final_size]
531
	cmp	ecx, edx
481
	cmp	ecx,edx
532
	jb	@f
482
	jb	@f
-
 
483
 
533
	mov	ecx, edx
484
	mov	ecx,edx
534
@@:
485
@@:
535
	mov	[eax], ecx
486
	mov	[eax],ecx
536
	lea	edi, [eax+4]
487
	lea	edi,[eax+4]
537
	mov	esi, [final_buffer]
488
	mov	esi,[final_buffer]
538
	mov	edx, ecx
489
	mov	edx,ecx
539
	shr	ecx, 2
490
	shr	ecx,2
540
	rep	movsd
491
	rep	movsd
541
	mov	ecx, edx
492
	mov	ecx,edx
542
	and	ecx, 3
493
	and	ecx,3
543
	rep	movsb
494
	rep	movsb
-
 
495
 
544
save_in_shared_done:
496
save_in_shared_done:
545
	pop	edi
497
	pop	edi
546
	pop	esi
498
	pop	esi
547
	jmp	exit
499
	jmp	exit
548
	
500
	
549
	; this function cuts header, and removes chunk sizes if doc is chunked
501
; this function cuts header, and removes chunk sizes if doc is chunked
550
	; in: buf_ptr, pos; out: buf_ptr, pos.
502
; in: buf_ptr, pos; out: buf_ptr, pos.
551
	
503
	
552
parse_result:
504
parse_result:
553
 
-
 
554
	; close socket
505
; close socket
555
    mov     eax, 53
-
 
556
    mov     ebx, 8
-
 
557
    mov     ecx, [socket]
506
	mcall	53,8,[socket]
558
    mcall
-
 
559
	
507
	
560
dps "close socket: "
508
dps	"close	socket: "
561
dph eax
509
dph	eax
562
newline
510
newline
563
 
-
 
564
	mov		edi, [buf_ptr]
511
	mov	edi,[buf_ptr]
565
	mov		edx, [pos]
512
	mov	edx,[pos]
566
	
-
 
567
	mov		[buf_size], edx
513
	mov	[buf_size],edx
568
	;mov		eax, 70
-
 
569
	;mov		ebx, fileinfo_tmp
514
;	mcall	70,fileinfo_tmp
570
	;mcall
-
 
571
 
-
 
572
dps "pos = "
515
dps	"pos = "
573
dph edx
516
dph	edx
574
newline
517
newline
575
 
518
 
576
	; first, find end of headers
519
; first, find end of headers
577
	
-
 
578
.next_byte:
520
.next_byte:
579
	cmp		dword [edi], 0x0d0a0d0a		; ìíå ëåíü ÷èòàòü ñòàíäàðò, ïóñòü áóäóò îáà âàðèàíòà
521
	cmp	[edi],dword 0x0d0a0d0a	; ìíå ëåíü ÷èòàòü ñòàíäàðò, ïóñòü áóäóò îáà âàðèàíòà
580
	je		.end_of_headers
522
	je	.end_of_headers
581
	cmp		dword [edi], 0x0a0d0a0d
523
	cmp	[edi],dword 0x0a0d0a0d
582
	je		.end_of_headers
524
	je	.end_of_headers
583
	inc		edi
525
	inc	edi
584
	dec		edx
526
	dec	edx
585
	jne		.next_byte
527
	jne	.next_byte
586
	
-
 
587
	; no end of headers. it's an error. let client see all those headers.
528
; no end of headers. it's an error. let client see all those headers.
588
	ret
529
	ret
589
	
530
 
590
.end_of_headers:
531
.end_of_headers:
591
 
-
 
592
 
-
 
593
	; here we look at headers and search content-length or transfer-encoding headers
532
; here we look at headers and search content-length or transfer-encoding headers
594
 
-
 
595
;dps "eoh "
533
;dps	"eoh "
596
;newline
534
;newline
597
 
-
 
598
	sub		edi, [buf_ptr]
535
	sub	edi,[buf_ptr]
599
	add		edi, 3
536
	add	edi,3
600
	mov		[body_pos], edi		; store position where document body starts
537
	mov	[body_pos],edi	; store position where document body starts
601
	mov		[is_chunked], 0
538
	mov	[is_chunked],0
602
 
-
 
603
	; find content-length in headers
539
; find content-length in headers
604
	; not good method, but should work for 'Content-Length:'
540
; not good method, but should work for 'Content-Length:'
605
	
-
 
606
	mov		esi, [buf_ptr]
541
	mov	esi,[buf_ptr]
607
	mov		edi, s_contentlength
542
	mov	edi,s_contentlength
608
	mov		ebx, [body_pos]
543
	mov	ebx,[body_pos]
609
	mov		edx, 0
544
	xor	edx,edx	; 0
610
.cl_next:
545
.cl_next:
611
	mov		al, [esi]
546
	mov	al,[esi]
612
	cmp		al, [edi + edx]
547
	cmp	al,[edi + edx]
613
	jne		.cl_fail
548
	jne	.cl_fail
614
	inc		edx
549
	inc	edx
615
	cmp		edx, len_contentlength
550
	cmp	edx,len_contentlength
616
	je		.cl_found
551
	je	.cl_found
617
	jmp		.cl_incr
552
	jmp	.cl_incr
618
.cl_fail:
553
.cl_fail:
619
	mov		edx, 0
554
	xor	edx,edx	; 0
620
.cl_incr:
555
.cl_incr:
621
	inc		esi
556
	inc	esi
622
	dec		ebx
557
	dec	ebx
623
	je		.cl_error
558
	je	.cl_error
624
	jmp		.cl_next
559
	jmp	.cl_next
625
.cl_error:
560
.cl_error:
626
;pregs
561
;pregs
627
;newline
562
;newline
628
;dph esi
563
;dph	esi
629
;dps	" content-length not found "
564
;dps	" content-length not found "
630
 
-
 
631
	; find 'chunked'
565
; find 'chunked'
632
	
-
 
633
	; äà, ÿ êîïèðóþ êîä, ýòî óæàñíî, íî ìíå õî÷åòñÿ, ÷òîáû ïîñêîðåå çàðàáîòàëî
566
; äà, ÿ êîïèðóþ êîä, ýòî óæàñíî, íî ìíå õî÷åòñÿ, ÷òîáû ïîñêîðåå çàðàáîòàëî
634
	; à òàì óæ îòðåôàêòîðþ
567
; à òàì óæ îòðåôàêòîðþ
635
	
-
 
636
	mov		esi, [buf_ptr]
568
	mov	esi,[buf_ptr]
637
	mov		edi, s_chunked
569
	mov	edi,s_chunked
638
	mov		ebx, [body_pos]
570
	mov	ebx,[body_pos]
639
	mov		edx, 0
571
	xor	edx,edx	; 0
-
 
572
 
640
.ch_next:
573
.ch_next:
641
	mov		al, [esi]
574
	mov	al,[esi]
642
	cmp		al, [edi + edx]
575
	cmp	al,[edi + edx]
643
	jne		.ch_fail
576
	jne	.ch_fail
644
	inc		edx
577
	inc	edx
645
	cmp		edx, len_chunked
578
	cmp	edx,len_chunked
646
	je		.ch_found
579
	je	.ch_found
647
	jmp		.ch_incr
580
	jmp	.ch_incr
-
 
581
 
648
.ch_fail:
582
.ch_fail:
649
	mov		edx, 0
583
	xor	edx,edx	; 0
-
 
584
 
650
.ch_incr:
585
.ch_incr:
651
	inc		esi
586
	inc	esi
652
	dec		ebx
587
	dec	ebx
653
	je		.ch_error
588
	je	.ch_error
654
	jmp		.ch_next
589
	jmp	.ch_next
655
.ch_error:
-
 
-
 
590
 
656
 
591
.ch_error:
657
	; if neither of the 2 headers is found, it's an error
592
; if neither of the 2 headers is found, it's an error
658
;dps "transfer-encoding: chunked not found "
593
;dps	"transfer-encoding: chunked not found "
659
	mov		eax, [pos]
594
	mov	eax,[pos]
660
	sub		eax, [body_pos]
595
	sub	eax,[body_pos]
661
	jmp		.write_final_size
596
	jmp	.write_final_size
662
 
597
 
663
.ch_found:
598
.ch_found:
664
 
-
 
665
	mov		[is_chunked], 1
599
	mov	[is_chunked],1
666
	mov		eax, [body_pos]
600
	mov	eax,[body_pos]
667
	add		eax, [buf_ptr]
601
	add	eax,[buf_ptr]
668
	sub		eax, 2
602
	sub	eax,2
669
	mov		[prev_chunk_end], eax
603
	mov	[prev_chunk_end],eax
670
	jmp		parse_chunks
604
	jmp	parse_chunks
671
	
605
	
672
.cl_found:	
606
.cl_found:	
673
	
-
 
674
	call	read_number		; eax = number from *esi
607
	call	read_number	; eax = number from *esi
675
	inc		eax				; bugfix :)
608
	inc	eax	; bugfix :)
676
	
609
 
677
.write_final_size:
610
.write_final_size:
678
	mov		[final_size], eax		; if this works, i will b very happy...
611
	mov	[final_size],eax	; if this works, i will b very happy...
679
	
612
	
680
	mov		ebx, [pos]	; we well check if it is right
613
	mov	ebx,[pos]	; we well check if it is right
681
	sub		ebx, [body_pos]
614
	sub	ebx,[body_pos]
682
 
615
 
683
;dps "check cl eax==ebx "	
616
;dps	"check cl eax==ebx "
684
;pregs
617
;pregs
685
 
618
 
686
	; everything is ok, so we return
619
; everything is ok, so we return
687
	
-
 
688
	mov		eax, [body_pos]
620
	mov	eax,[body_pos]
689
	mov		ebx, [buf_ptr]
621
	mov	ebx,[buf_ptr]
690
	add		ebx, eax
622
	add	ebx,eax
691
	mov		[final_buffer], ebx
623
	mov	[final_buffer],ebx
692
	;mov		ebx, [pos]
624
;	mov	ebx,[pos]
693
	;sub		ebx, eax
625
;	sub	ebx,eax
694
	;mov		[final_size], ebx
626
;	mov	[final_size],ebx
695
	
-
 
696
	ret
627
	ret
697
	
628
	
698
parse_chunks:
629
parse_chunks:
699
 
-
 
700
;dps "parse chunks"
630
;dps	"parse chunks"
701
;newline
631
;newline
702
	; we have to look through the data and remove sizes of chunks we see
632
	; we have to look through the data and remove sizes of chunks we see
703
	
-
 
704
	; 1. read size of next chunk
633
	; 1. read size of next chunk
705
	; 2. if 0, it's end. if not, continue.
634
	; 2. if 0, it's end. if not, continue.
706
	; 3. make a good buffer and copy a chunk there
635
	; 3. make a good buffer and copy a chunk there
707
	
636
	xor	eax,eax
708
	mov		[final_buffer], 0
637
	mov	[final_buffer],eax	; 0
709
	mov		[final_size], 0
638
	mov	[final_size],eax	; 0
710
	
639
	
711
.read_size:
-
 
712
	
640
.read_size:
713
	mov		eax, [prev_chunk_end]
641
	mov	eax,[prev_chunk_end]
714
	mov		ebx, eax
642
	mov	ebx,eax
715
	sub		ebx, [buf_ptr]
643
	sub	ebx,[buf_ptr]
716
 
-
 
717
	mov		edx, eax
644
	mov	edx,eax
718
	
-
 
719
;dps "rs "
645
;dps	"rs "
720
;pregs
646
;pregs
721
 
-
 
722
	cmp		ebx, [pos]
647
	cmp	ebx,[pos]
723
	jae		chunks_end			; not good
648
	jae	chunks_end	; not good
724
	
649
	
725
	call	read_hex			; in: eax=pointer to text. out:eax=hex number,ebx=end of text.
650
	call	read_hex	; in: eax=pointer to text. out:eax=hex number,ebx=end of text.
726
	cmp		eax, 0
651
	cmp	eax,0
727
	jz		chunks_end
652
	jz	chunks_end
728
 
653
 
729
	add		ebx, 1
654
	add	ebx,1
730
	mov		edx, ebx			; edx = size of size of chunk
655
	mov	edx,ebx	; edx = size of size of chunk
731
	
656
	
732
	add		ebx, eax
657
	add	ebx,eax
733
	mov		[prev_chunk_end], ebx
658
	mov	[prev_chunk_end],ebx
734
	
659
	
735
;dps "sz "
660
;dps	"sz "
736
;pregs
661
;pregs
737
 
-
 
738
	; do copying: from buf_ptr+edx to final_buffer+prev_final_size count eax
662
; do copying: from buf_ptr+edx to final_buffer+prev_final_size count eax
739
	
-
 
740
	; realloc final buffer
663
; realloc final buffer
741
	
-
 
742
	push	eax
664
	push	eax
743
	push	edx
665
	push	edx
744
	push	dword [final_size]
666
	push	dword [final_size]
745
	
-
 
746
	add		[final_size], eax
667
	add	[final_size],eax
747
	
-
 
748
	mov		eax, 68
-
 
749
	mov		ebx, 20
-
 
750
	mov		ecx, [final_size]
-
 
751
	mov		edx, [final_buffer]
668
	mcall	68,20,[final_size],[final_buffer]
752
	mcall
-
 
753
	mov		[final_buffer], eax
669
	mov	[final_buffer],eax
754
;dps "re "
670
;dps	"re "
755
;pregs
671
;pregs
756
	
-
 
757
	pop		edi
672
	pop	edi
758
	pop		esi
673
	pop	esi
759
	pop		ecx
674
	pop	ecx
760
 
-
 
761
	;add		[pos], ecx
675
;	add	[pos],ecx
762
	
-
 
763
	add		edi, [final_buffer]
676
	add	edi,[final_buffer]
764
 
-
 
765
;dps "cp "
677
;dps	"cp "
766
;pregs
678
;pregs
767
	
-
 
768
	rep		movsb
679
	rep	movsb
769
	
-
 
770
	jmp		.read_size
680
	jmp	.read_size
771
	
681
	
772
chunks_end:
682
chunks_end:
773
	; free old buffer
683
; free old buffer
774
dps "chunks end"
684
dps	"chunks end"
775
newline
685
newline
776
	
-
 
777
	mov		eax, 68
-
 
778
	mov		ebx, 13
-
 
779
	mov		ecx, [buf_ptr]
686
	mcall	68,13,[buf_ptr]
780
	mcall
-
 
781
	
-
 
782
	; done!
687
; done!
783
	
-
 
784
	ret
688
	ret
785
	
-
 
786
	
-
 
787
	
689
 
788
; reads content-length from [edi+ecx], result in eax
690
; reads content-length from [edi+ecx], result in eax
789
read_number:
-
 
790
 
691
read_number:
791
	push	ebx
692
	push	ebx
792
	xor		eax, eax
693
	xor	eax,eax
793
	xor		ebx, ebx
694
	xor	ebx,ebx
-
 
695
 
794
.next:
696
.next:
795
	mov		bl, [esi]
697
	mov	bl,[esi]
796
;dph ebx
698
;dph	ebx
797
	cmp		bl, '0'
699
	cmp	bl,'0'
798
	jb		.not_number
700
	jb	.not_number
799
	cmp		bl, '9'
701
	cmp	bl,'9'
800
	ja		.not_number
702
	ja	.not_number
801
	sub		bl, '0'
703
	sub	bl,'0'
802
	shl		eax, 1
704
	shl	eax,1
803
	lea		eax,[eax + eax * 4]		; eax *= 10
705
	lea	eax,[eax + eax * 4]	; eax *= 10
804
	add		eax, ebx
706
	add	eax,ebx
-
 
707
 
805
.not_number:
708
.not_number:
806
	cmp		bl, 13
709
	cmp	bl,13
807
	jz		.done
710
	jz	.done
808
	inc		esi
711
	inc	esi
809
	jmp		.next
712
	jmp	.next
-
 
713
 
810
.done:
714
.done:
811
	pop		ebx
715
	pop	ebx
812
;newline
716
;newline
813
;dps "strtoint eax "
717
;dps	"strtoint eax "
814
;pregs
718
;pregs
815
 
-
 
816
	ret
719
	ret
817
	
-
 
818
	
720
	
819
; reads hex from eax, result in eax, end of text in ebx
721
; reads hex from eax,result in eax,end of text in ebx
820
read_hex:
-
 
821
 
722
read_hex:
822
	add		eax, 2
723
	add	eax,2
823
	mov		ebx, eax
-
 
824
	
724
	mov	ebx,eax
825
	mov		eax, [ebx]
725
	mov	eax,[ebx]
826
	mov		[deba], eax
-
 
827
	
726
	mov	[deba],eax
828
;	pushf
727
;	pushf
829
;   pushad
728
;	pushad
830
;   mov  edx,deba
729
;	mov	edx,deba
831
;   call debug_outstr
730
;	call	debug_outstr
832
;   popad
731
;	popad
833
;   popf
732
;	popf
834
	
-
 
835
	xor		eax, eax
733
	xor	eax,eax
836
	xor		ecx, ecx
734
	xor	ecx,ecx
837
.next:
735
.next:
838
	mov		cl, [ebx]
736
	mov	cl,[ebx]
839
	inc		ebx
737
	inc	ebx
840
	
738
	
841
	cmp		cl, 0x0d
739
	cmp	cl,0x0d
842
	jz		.done
740
	jz	.done
843
;dph ebx
741
;dph	ebx
844
	or		cl, 0x20
742
	or	cl,0x20
845
	sub		cl, '0'
743
	sub	cl,'0'
846
	jb		.bad
744
	jb	.bad
-
 
745
 
847
	cmp		cl, 0x9
746
	cmp	cl,0x9
848
	jbe		.adding
747
	jbe	.adding
-
 
748
 
849
	sub		cl, 'a'-'0'-10
749
	sub	cl,'a'-'0'-10
850
	cmp		cl, 0x0a
750
	cmp	cl,0x0a
851
	jb		.bad
751
	jb	.bad
-
 
752
 
852
	cmp		cl, 0x0f
753
	cmp	cl,0x0f
853
	ja		.bad
754
	ja	.bad
-
 
755
 
854
.adding:
756
.adding:
855
	shl		eax, 4
757
	shl	eax,4
856
	or		eax, ecx
758
	or	eax,ecx
857
;	jmp		.not_number
759
;	jmp	.not_number
858
;.bad:
760
;.bad:
859
.bad:
761
.bad:
860
	jmp		.next
762
	jmp	.next
861
.done:
763
.done:
862
;newline
764
;newline
863
;dps "hextoint eax "
765
;dps	"hextoint eax "
864
;pregs
766
;pregs
865
	ret
767
	ret
866
 
-
 
867
	
-
 
868
 
-
 
869
 
768
 
870
;****************************************************************************
769
;****************************************************************************
871
;    Function
770
;    Function
872
;       draw_page
771
;       draw_page
873
;
772
;
874
;   Description
773
;   Description
875
;       parses the web page data, storing displayable data at 0x20000
774
;       parses the web page data, storing displayable data at 0x20000
876
;       and attributes at 0x30000. It then calls display_page to render
775
;       and attributes at 0x30000. It then calls display_page to render
877
;       the data
776
;       the data
878
;
777
;
879
;****************************************************************************
778
;****************************************************************************
880
draw_page:
779
draw_page:
881
	ret
780
	ret
882
	
-
 
883
 
781
 
884
;****************************************************************************
782
;****************************************************************************
885
;    Function
783
;    Function
886
;       linefeed
784
;       linefeed
887
;
785
;
888
;   Description
786
;   Description
889
;
787
;
890
;
788
;
891
;****************************************************************************
789
;****************************************************************************
892
linefeed:
790
linefeed:
893
 
-
 
894
    ret
791
	ret
895
 
792
 
896
;****************************************************************************
793
;****************************************************************************
897
;    Function
794
;    Function
898
;       display_page
795
;       display_page
899
;
796
;
900
;   Description
797
;   Description
901
;       Renders the text decoded by draw_page
798
;       Renders the text decoded by draw_page
902
;
799
;
903
;****************************************************************************
800
;****************************************************************************
904
display_page:
801
display_page:
905
    ret
802
	ret
906
 
803
 
907
;****************************************************************************
804
;****************************************************************************
908
;    Function
805
;    Function
909
;       socket_commands
806
;       socket_commands
910
;
807
;
911
;   Description
808
;   Description
912
;       opens or closes the socket
809
;       opens or closes the socket
913
;
810
;
914
;****************************************************************************
811
;****************************************************************************
915
socket_commands:
812
socket_commands:
916
    cmp     ah,22       ; open socket
813
	cmp	ah,22	; open socket
917
    jnz     tst3
814
	jnz	tst3
918
 
815
 
919
	dps "opening socket"
816
dps	"opening socket"
920
	newline
817
newline
921
    ; Clear all page memory
818
; Clear all page memory
-
 
819
	xor	eax,eax
-
 
820
	mov	[prev_chunk_end],eax	; 0
-
 
821
	cmp	[buf_ptr],eax	; 0
-
 
822
	jz	no_free
922
	
823
 
923
	mov		[prev_chunk_end], 0
-
 
924
	
-
 
925
	cmp		[buf_ptr], 0
-
 
926
	jz		no_free
-
 
927
	mov		eax, 68		; free buffer
-
 
928
	mov		ebx, 13
-
 
929
	mov		ecx, [buf_ptr]
824
	mcall	68,13,[buf_ptr]	; free	buffer
-
 
825
 
930
	mcall
826
no_free:
931
no_free:
-
 
932
	mov		[buf_size], 0
827
	xor	eax,eax
933
 
828
	mov	[buf_size],eax	; 0
934
    ; Parse the entered url
-
 
935
    call    parse_url
829
; Parse the entered url
936
 
830
	call	parse_url
-
 
831
; Get a free port number
937
    ; Get a free port number
832
	mov	ecx,1000	; local port starting at 1000
938
        mov         ecx, 1000           ; local port starting at 1000
833
 
939
getlp1:
834
getlp1:
940
        inc         ecx
835
	inc	ecx
941
        push    ecx
836
	push	ecx
942
        mov         eax, 53
-
 
943
        mov         ebx, 9
-
 
944
        mcall
837
	mcall	53,9
945
        pop         ecx
838
	pop	ecx
946
        cmp         eax, 0                      ; is this local port in use?
839
	cmp	eax,0	; is this local port in use?
947
        jz              getlp1              ; yes - so try next
840
	jz	getlp1	; yes - so try next
948
 
-
 
949
    mov     eax,53
-
 
950
    mov     ebx,5
841
 
951
    mov     edx,80
842
	mov	edx,80
952
    cmp     [proxyAddr], 0
843
	cmp	[proxyAddr],byte 0
953
    jz      sc000
844
	jz	sc000
954
    mov     edx,[proxyPort]
845
	mov	edx,[proxyPort]
955
sc000:
846
sc000:
956
    mov     esi,dword [server_ip]
847
	mcall	53,5,,,[server_ip],1
957
    mov     edi,1
-
 
958
    mcall
-
 
959
    mov     [socket], eax
848
	mov	[socket],eax
960
 
-
 
961
    mov     [pos],0
-
 
962
    mov     [pagex],0
-
 
963
    mov     [pagey],0
-
 
964
    mov     [pagexs],80
849
	mov	[pagexs],80
965
    mov     [command_on_off],0
-
 
966
	
-
 
967
	mov		[is_body], 0
-
 
-
 
850
	
-
 
851
	push	eax
-
 
852
	xor	eax,eax ; 0
-
 
853
	mov	[pos],eax
-
 
854
	mov	[pagex],eax
-
 
855
	mov	[pagey],eax
-
 
856
	mov	[command_on_off],eax
-
 
857
	mov	[is_body],eax
968
 
858
	pop	eax
969
    ret
859
	ret
970
 
860
 
971
tst3:
861
tst3:
972
    cmp     ah,24     ; close socket
862
	cmp	ah,24	; close	socket
973
    jnz     no_24
863
	jnz	no_24
974
 
-
 
975
    mov     eax,53
-
 
976
    mov     ebx,8
864
 
977
    mov     ecx,[socket]
-
 
978
    mcall
-
 
979
 
865
	mcall	53,8,[socket]
980
    call    draw_page
-
 
981
 
-
 
982
    ret
-
 
983
 
866
	call	draw_page
984
no_24:
867
no_24:
985
    ret
868
	ret
986
 
-
 
987
 
-
 
988
 
869
 
989
;****************************************************************************
870
;****************************************************************************
990
;    Function
871
;    Function
991
;       parse_url
872
;       parse_url
992
;
873
;
993
;   Description
874
;   Description
994
;       parses the full url typed in by the user into a web address ( that
875
;       parses the full url typed in by the user into a web address ( that
995
;       can be turned into an IP address by DNS ) and the page to display
876
;       can be turned into an IP address by DNS ) and the page to display
996
;       DNS will be used to translate the web address into an IP address, if
877
;       DNS will be used to translate the web address into an IP address, if
997
;       needed.
878
;       needed.
998
;       url is at document_user and will be space terminated.
879
;       url is at document_user and will be space terminated.
999
;       web address goes to webAddr and is space terminated.
880
;       web address goes to webAddr and is space terminated.
1000
;       ip address goes to server_ip
881
;       ip address goes to server_ip
1001
;       page goes to document and is space terminated.
882
;       page goes to document and is space terminated.
1002
;
883
;
1003
;       Supported formats:
884
;       Supported formats:
1004
;       address
885
;       address
1005
;        is optional, removed and ignored - only http supported
886
;        is optional, removed and ignored - only http supported
1006
;       
is required. It can be an ip address or web address
887
;       
is required. It can be an ip address or web address
1007
;        is optional and must start with a leading / character
888
;        is optional and must start with a leading / character
1008
;
889
;
1009
;****************************************************************************
890
;****************************************************************************
1010
parse_url:
891
parse_url:
1011
    ; First, reset destination variables
892
; First, reset destination variables
1012
    cld
893
	cld
1013
    mov     al, ' '
894
	mov	al,' '
1014
    mov     edi, document
895
	mov	edi,document
1015
    mov     ecx,URLMAXLEN
896
	mov	ecx,URLMAXLEN
1016
    rep     stosb
897
	rep	stosb
1017
    mov     edi, webAddr
898
	mov	edi,webAddr
1018
    mov     ecx,URLMAXLEN
899
	mov	ecx,URLMAXLEN
1019
    rep     stosb
900
	rep	stosb
1020
 
901
 
1021
    mov     al, '/'
902
	mov	al,'/'
1022
    mov     [document], al
903
	mov	[document],al
1023
 
904
 
1024
    mov     esi, document_user
905
	mov	esi,document_user
1025
    ; remove any leading protocol text
906
; remove any leading protocol text
1026
    mov     ecx, URLMAXLEN
907
	mov	ecx,URLMAXLEN
1027
    mov     ax, '//'
908
	mov	ax,'//'
1028
 
909
 
1029
pu_000:
910
pu_000:
1030
    cmp     [esi], byte ' '     ; end of text?
911
	cmp	[esi],byte ' '	; end of text?
1031
    je      pu_002              ; yep, so not found
912
	je	pu_002		; yep, so not found
1032
    cmp     word [esi], ax
913
	cmp	[esi],ax
1033
    je      pu_001              ; Found it, so esi+2 is start
914
	je	pu_001	; Found it, so esi+2 is start
1034
    inc     esi
915
	inc	esi
1035
    loop    pu_000
916
	loop	pu_000
1036
 
917
 
1037
pu_002:
918
pu_002:
1038
    ; not found, so reset esi to start
919
; not found, so reset esi to start
1039
    mov     esi, document_user -2
920
	mov	esi,document_user-2
1040
 
921
 
1041
pu_001:
922
pu_001:
1042
    add     esi, 2
923
	add	esi,2
1043
 
-
 
1044
    mov     ebx, esi    ; save address of start of web address
924
	mov	ebx,esi	; save address of start of web address
1045
    mov     edi, document_user + URLMAXLEN  ; end of string
925
	mov	edi,document_user + URLMAXLEN	; end of string
1046
 
-
 
1047
    ; look for page delimiter - it's a '/' character
926
; look for page delimiter - it's a '/' character
1048
pu_003:
927
pu_003:
1049
    cmp     [esi], byte ' '     ; end of text?
928
	cmp	[esi],byte ' '	; end of text?
1050
    je      pu_004              ; yep, so none found
929
	je	pu_004		; yep, so none found
1051
    cmp     esi, edi            ; end of string?
930
	cmp	esi,edi		; end of string?
1052
    je      pu_004              ; yep, so none found
931
	je	pu_004		; yep, so none found
1053
    cmp     [esi], byte '/'     ; delimiter?
932
	cmp	[esi],byte '/'	; delimiter?
1054
    je      pu_005              ; yep - process it
933
	je	pu_005		; yep - process it
1055
    inc     esi
934
	inc	esi
1056
    jmp     pu_003
935
	jmp	pu_003
1057
 
936
 
1058
pu_005:
937
pu_005:
1059
    ; copy page to document address
938
; copy page to document address
1060
    ; esi = delimiter
939
; esi = delimiter
1061
    push    esi
940
	push	esi
1062
    mov     ecx, edi            ; end of document_user
941
	mov	ecx,edi		; end of document_user
1063
    mov     edi, document
942
	mov	edi,document
1064
    cld
943
	cld
1065
 
944
 
1066
pu_006:
945
pu_006:
1067
    movsb
946
	movsb
1068
    cmp     esi, ecx
947
	cmp	esi,ecx
1069
    je      pu_007              ; end of string?
948
	je	pu_007		; end of string?
1070
    cmp     [esi], byte ' '     ; end of text
949
	cmp	[esi],byte ' '	; end of text
1071
    je      pu_007
950
;	je	pu_007		; äçåí-àññåìáëåð
-
 
951
;	jmp	pu_006		; íå íàäî ïëîäèòü ñóùíîñòè ïî íàïðàñíó
1072
    jmp     pu_006
952
	jne	pu_006
1073
 
953
 
1074
pu_007:
954
pu_007:
1075
    pop     esi                 ; point esi to '/' delimiter
955
	pop	esi	; point esi to '/' delimiter
1076
 
956
 
1077
pu_004:
957
pu_004:
1078
    ; copy web address to webAddr
958
; copy web address to webAddr
1079
    ; start in ebx, end in esi-1
959
; start in ebx,end in esi-1
1080
    mov     ecx, esi
960
	mov	ecx,esi
1081
    mov     esi, ebx
961
	mov	esi,ebx
1082
    mov     edi, webAddr
962
	mov	edi,webAddr
1083
    cld
963
	cld
1084
 
964
 
1085
pu_008:
965
pu_008:
1086
    movsb
966
	movsb
1087
    cmp     esi, ecx
967
	cmp	esi,ecx
1088
    je      pu_009
968
;	je	pu_009		; äçåí-àññåìáëåð
-
 
969
;	jmp	pu_008		; íå íàäî ïëîäèòü ñóùíîñòè ïî íàïðàñíó
1089
    jmp     pu_008
970
	jne	pu_008
1090
 
971
 
1091
pu_009:
972
pu_009:
1092
    ; For debugging, display resulting strings
973
; For debugging, display resulting strings
1093
 
-
 
1094
if DEBUGGING_STATE = DEBUGGING_ENABLED
974
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1095
    mov     esi, document_user
975
	mov	esi,document_user
1096
    call    debug_print_string
976
	call	debug_print_string
1097
    mov     esi, webAddr
977
	mov	esi,webAddr
1098
    call    debug_print_string
978
	call	debug_print_string
1099
    mov     esi, document
979
	mov	esi,document
1100
    call    debug_print_string
980
	call	debug_print_string
1101
end if
981
end	if
1102
 
-
 
1103
    ; Look up the ip address, or was it specified?
982
; Look up the ip address, or was it specified?
1104
    mov     al, [proxyAddr]
983
	mov	al,[proxyAddr]
1105
    cmp     al, 0
984
	cmp	al,0
1106
    jnz     pu_015
985
	jnz	pu_015
1107
    mov     al, [webAddr]
986
	mov	al,[webAddr]
1108
pu_015:
987
pu_015:
1109
    cmp     al, '0'
988
	cmp	al,'0'
1110
    jb      pu_010              ; Resolve address
989
	jb	pu_010	; Resolve address
1111
    cmp     al, '9'
990
	cmp	al,'9'
1112
    ja      pu_010              ; Resolve address
991
	ja	pu_010	; Resolve address
1113
 
-
 
1114
 
992
 
1115
if DEBUGGING_STATE = DEBUGGING_ENABLED
993
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1116
    mov     esi, str2       ; print gotip
994
	mov	esi,str2	; print	gotip
1117
    call    debug_print_string
995
	call	debug_print_string
1118
end if
996
end	if
1119
 
-
 
1120
    ; Convert address
997
; Convert address
1121
    ; If proxy is given, get proxy address instead of server
998
; If proxy is given, get proxy address instead of server
1122
    mov     esi,proxyAddr-1
999
	mov	esi,proxyAddr-1
1123
    cmp     byte [esi+1], 0
1000
	cmp	byte [esi+1],0
1124
    jnz     pu_020
1001
	jnz	pu_020
1125
    mov     esi,webAddr-1
1002
	mov	esi,webAddr-1
1126
pu_020:
-
 
-
 
1003
 
1127
 
1004
pu_020:
1128
    mov     edi,server_ip
1005
	mov	edi,server_ip
-
 
1006
	xor	eax,eax
1129
    xor     eax,eax
1007
 
1130
ip1:
1008
ip1:
1131
    inc     esi
1009
	inc	esi
1132
    cmp     [esi],byte '0'
1010
	cmp	[esi],byte '0'
1133
    jb      ip2
1011
	jb	ip2
1134
    cmp     [esi],byte '9'
1012
	cmp	[esi],byte '9'
1135
    jg      ip2
1013
	jg	ip2
1136
    imul    eax,10
1014
	imul	eax,10
1137
    movzx   ebx,byte [esi]
1015
	movzx	ebx,byte [esi]
1138
    sub     ebx,48
1016
	sub	ebx,48
1139
    add     eax,ebx
1017
	add	eax,ebx
1140
    jmp     ip1
1018
	jmp	ip1
-
 
1019
 
1141
ip2:
1020
ip2:
1142
    mov     [edi],al
1021
	mov	[edi],al
1143
    xor     eax,eax
1022
	xor	eax,eax
1144
    inc     edi
1023
	inc	edi
1145
    cmp     edi,server_ip+3
1024
	cmp	edi,server_ip+3
1146
    jbe     ip1
1025
	jbe	ip1
1147
 
-
 
1148
    jmp     pu_011
1026
	jmp	pu_011
1149
 
1027
 
1150
pu_010:
1028
pu_010:
1151
 
-
 
1152
if DEBUGGING_STATE = DEBUGGING_ENABLED
1029
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1153
    mov     esi, str1       ; print resolving
1030
	mov	esi,str1	; print	resolving
1154
    call    debug_print_string
1031
	call	debug_print_string
1155
end if
1032
end	if
1156
 
-
 
1157
    ; Resolve Address
1033
; Resolve Address
1158
    call    translateData       ; Convert domain & DNS IP address
1034
	call	translateData	; Convert domain & DNS IP address
1159
    call    resolveDomain       ; get ip address
1035
	call	resolveDomain	; get ip address
1160
 
1036
 
1161
if DEBUGGING_STATE = DEBUGGING_ENABLED
1037
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1162
    mov     esi, str3
1038
	mov	esi,str3
1163
    call    debug_print_string
1039
	call	debug_print_string
1164
end if
1040
end	if
1165
 
1041
 
1166
pu_011:
1042
pu_011:
1167
 
-
 
1168
    ; Done
1043
; Done
1169
    ret
1044
	ret
1170
 
-
 
1171
 
1045
 
1172
;***************************************************************************
1046
;***************************************************************************
1173
;   Function
1047
;   Function
1174
;      translateData
1048
;      translateData
1175
;
1049
;
1176
;   Description
1050
;   Description
1177
;      Coverts the domain name and DNS IP address typed in by the user into
1051
;      Coverts the domain name and DNS IP address typed in by the user into
1178
;      a format suitable for the IP layer.
1052
;      a format suitable for the IP layer.
1179
;
1053
;
1180
;    The ename, in query, is converted and stored in dnsMsg
1054
;    The ename, in query, is converted and stored in dnsMsg
1181
;
1055
;
1182
;***************************************************************************
1056
;***************************************************************************
1183
translateData:
1057
translateData:
1184
 
-
 
1185
    ; first, get the IP address of the DNS server
1058
    ; first, get the IP address of the DNS server
1186
    ; Then, build up the request string.
1059
    ; Then, build up the request string.
1187
 
-
 
1188
 
1060
 
1189
    ; Build the request string
-
 
1190
 
-
 
1191
 
1061
    ; Build the request string
1192
    mov     eax, 0x00010100
1062
	mov	eax,0x00010100
1193
    mov     [dnsMsg], eax
1063
	mov	[dnsMsg],eax
1194
    mov     eax, 0x00000100
1064
	mov	eax,0x00000100
1195
    mov     [dnsMsg+4], eax
1065
	mov	[dnsMsg+4],eax
1196
    mov     eax, 0x00000000
1066
	mov	eax,0x00000000
1197
    mov     [dnsMsg+8], eax
1067
	mov	[dnsMsg+8],eax
1198
 
-
 
1199
    ; domain name goes in at dnsMsg+12
1068
; domain name goes in at dnsMsg+12
1200
    mov     esi, dnsMsg + 12        ; location of label length
1069
	mov	esi,dnsMsg +12	;location of label length
1201
    mov     edi, dnsMsg + 13        ; label start
1070
	mov	edi,dnsMsg + 13	;label start
1202
    mov     edx, proxyAddr
1071
	mov	edx,proxyAddr
1203
    cmp     byte [edx], 0
1072
	cmp	byte [edx],0
1204
    jnz     td000
1073
	jnz	td000
1205
    mov     edx, webAddr
1074
	mov	edx,webAddr
-
 
1075
 
1206
td000:
1076
td000:
1207
    mov     ecx, 12                  ; total string length so far
1077
	mov	ecx,12	; total string length so far
1208
 
1078
 
1209
td002:
1079
td002:
1210
    mov     [esi], byte 0
1080
	mov	[esi],byte 0
1211
    inc     ecx
1081
	inc	ecx
1212
 
1082
 
1213
td0021:
1083
td0021:
1214
    mov     al, [edx]
1084
	mov	al,[edx]
1215
    cmp     al, ' '
1085
	cmp	al,' '
1216
    je      td001                   ; we have finished the string translation
1086
	je	td001	; we have finished the string translation
-
 
1087
 
1217
    cmp     al, 0
1088
	cmp	al,0
1218
    je      td001
1089
	je	td001
-
 
1090
 
1219
    cmp     al, '.'                 ; we have finished the label
1091
	cmp	al,'.'	; we have finished the label
1220
    je      td004
1092
	je	td004
1221
 
1093
 
1222
    inc     byte [esi]
1094
	inc	byte [esi]
1223
    inc     ecx
1095
	inc	ecx
1224
    mov     [edi], al
1096
	mov	[edi],al
1225
    inc     edi
1097
	inc	edi
1226
    inc     edx
1098
	inc	edx
1227
    jmp     td0021
1099
	jmp	td0021
1228
 
1100
 
1229
td004:
1101
td004:
1230
    mov     esi, edi
1102
	mov	esi,edi
1231
    inc     edi
1103
	inc	edi
1232
    inc     edx
1104
	inc	edx
1233
    jmp     td002
1105
	jmp	td002
1234
 
-
 
1235
 
-
 
1236
 
1106
 
1237
    ; write label len + label text
-
 
1238
 
1107
; write label len + label text
1239
td001:
1108
td001:
1240
    mov     [edi], byte 0
1109
	mov	[edi],byte 0
1241
    inc     ecx
1110
	inc	ecx
1242
    inc     edi
1111
	inc	edi
1243
    mov     [edi], dword 0x01000100
1112
	mov	[edi],dword 0x01000100
1244
    add     ecx, 4
1113
	add	ecx,4
1245
 
-
 
1246
    mov     [dnsMsgLen], ecx
1114
	mov	[dnsMsgLen],ecx
1247
 
-
 
1248
    ret
1115
	ret
1249
 
-
 
1250
 
-
 
1251
 
-
 
1252
 
-
 
1253
 
1116
 
1254
;***************************************************************************
1117
;***************************************************************************
1255
;   Function
1118
;   Function
1256
;      resolveDomain
1119
;      resolveDomain
1257
;
1120
;
1258
;   Description
1121
;   Description
1259
;       Sends a question to the dns server
1122
;       Sends a question to the dns server
1260
;       works out the IP address from the response from the DNS server
1123
;       works out the IP address from the response from the DNS server
1261
;
1124
;
1262
;***************************************************************************
1125
;***************************************************************************
1263
resolveDomain:
1126
resolveDomain:
1264
    ; Get a free port number
1127
; Get a free port number
1265
        mov         ecx, 1000           ; local port starting at 1000
1128
	mov	ecx,1000	; local port starting at 1000
1266
getlp:
1129
getlp:
1267
        inc         ecx
1130
	inc	ecx
1268
        push    ecx
1131
	push	ecx
1269
        mov         eax, 53
-
 
1270
        mov         ebx, 9
-
 
1271
        mcall
1132
	mcall	53,9
1272
        pop         ecx
1133
	pop	ecx
1273
        cmp         eax, 0                      ; is this local port in use?
1134
	cmp	eax,0	; is this local port in use?
1274
        jz              getlp               ; yes - so try next
1135
	jz	getlp	; yes - so try next
1275
 
1136
 
1276
    ; Get DNS IP
1137
; Get DNS IP
1277
    mov     eax, 52
-
 
1278
    mov     ebx, 13
-
 
1279
    mcall
1138
	mcall	52,13
1280
    mov     esi, eax
1139
	mov	esi,eax
1281
    ; First, open socket
1140
; First, open socket
1282
    mov     eax, 53
-
 
1283
    mov     ebx, 0
-
 
1284
    mov     edx, 53    ; remote port - dns
1141
	mov	edx,53	; remote port - dns
1285
;    mov     esi, dword [dns_ip]
1142
;	mov	esi,dword [dns_ip]
-
 
1143
	xor	ebx,ebx	; 0
1286
    mcall
1144
	mcall	53
1287
 
-
 
1288
    mov     [socketNum], eax
1145
	mov	[socketNum],eax
1289
 
-
 
1290
    ; write to socket ( request DNS lookup )
1146
; write to socket ( request DNS lookup )
1291
    mov     eax, 53
-
 
1292
    mov     ebx, 4
-
 
1293
    mov     ecx, [socketNum]
-
 
1294
    mov     edx, [dnsMsgLen]
1147
	mcall	53,4,[socketNum],[dnsMsgLen],dnsMsg
1295
    mov     esi, dnsMsg
-
 
1296
    mcall
-
 
1297
 
-
 
1298
    ; Setup the DNS response buffer
1148
; Setup the DNS response buffer
1299
 
-
 
1300
    mov     eax, dnsMsg
1149
	mov	eax,dnsMsg
1301
    mov     [dnsMsgLen], eax
1150
	mov	[dnsMsgLen],eax
1302
 
-
 
1303
    ; now, we wait for
1151
; now, we wait for
1304
    ; UI redraw
1152
; UI redraw
1305
    ; UI close
1153
; UI close
1306
    ; or data from remote
1154
; or data from remote
1307
 
1155
 
1308
ctr001:
1156
ctr001:
1309
    mov     eax,10                 ; wait here for event
1157
	mcall	10	; wait here for event
1310
    mcall
-
 
1311
 
-
 
1312
    cmp     eax,1                  ; redraw request ?
1158
	cmp	eax,1	; redraw request ?
1313
    je      ctr003
1159
	je	ctr003
-
 
1160
 
1314
    cmp     eax,2                  ; key in buffer ?
1161
	cmp	eax,2	; key in buffer ?
1315
    je      ctr004
1162
	je	ctr004
-
 
1163
 
1316
    cmp     eax,3                  ; button in buffer ?
1164
	cmp	eax,3	; button in buffer ?
1317
    je      ctr005
1165
	je	ctr005
1318
 
-
 
1319
 
-
 
1320
    ; Any data in the UDP receive buffer?
1166
; Any data in the UDP receive buffer?
1321
    mov     eax, 53
-
 
1322
    mov     ebx, 2
-
 
1323
    mov     ecx, [socketNum]
1167
	mcall	53,2,[socketNum]
1324
    mcall
-
 
1325
 
-
 
1326
    cmp     eax, 0
1168
	cmp	eax,0
1327
    je      ctr001
1169
	je	ctr001
1328
 
1170
 
1329
    ; we have data - this will be the response
1171
; we have data - this will be the response
1330
ctr002:
1172
ctr002:
1331
    mov     eax, 53
-
 
1332
    mov     ebx, 3
-
 
1333
    mov     ecx, [socketNum]
-
 
1334
    mcall                ; read byte - block (high byte)
1173
	mcall	53,3,[socketNum]	; read byte - block (high byte)
1335
 
-
 
1336
    ; Store the data in the response buffer
1174
; Store the data in the response buffer
1337
    mov     eax, [dnsMsgLen]
1175
	mov	eax,[dnsMsgLen]
1338
    mov     [eax], bl
1176
	mov	[eax],bl
1339
    inc     dword [dnsMsgLen]
1177
	inc	dword [dnsMsgLen]
1340
 
-
 
1341
    mov     eax, 53
-
 
1342
    mov     ebx, 2
-
 
1343
    mov     ecx, [socketNum]
1178
 
1344
    mcall                ; any more data?
-
 
1345
 
1179
	mcall	53,2,[socketNum]	; any more data?
1346
    cmp     eax, 0
1180
	cmp	eax,0
1347
    jne     ctr002              ; yes, so get it
1181
	jne	ctr002	; yes, so get it
1348
 
1182
 
1349
    ; close socket
1183
; close	socket
1350
    mov     eax, 53
-
 
1351
    mov     ebx, 1
-
 
1352
    mov     ecx, [socketNum]
1184
	mcall	53,1,[socketNum]
1353
    mcall
-
 
1354
 
-
 
1355
    mov     [socketNum], dword 0xFFFF
1185
	mov	[socketNum],dword  0xFFFF
1356
 
-
 
1357
    ; Now parse the message to get the host IP
1186
; Now parse the message to get the host IP
1358
    ; Man, this is complicated. It's described in
1187
; Man, this is complicated. It's described in
1359
    ; RFC 1035
1188
; RFC 1035
1360
 
-
 
1361
if DEBUGGING_STATE = DEBUGGING_ENABLED
1189
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1362
    mov     esi, str4
1190
	mov	esi,str4
1363
    call    debug_print_string
1191
	call	debug_print_string
1364
end if
1192
end	if
1365
 
1193
 
1366
    ; 1) Validate that we have an answer with > 0 responses
1194
    ; 1) Validate that we have an answer with > 0 responses
1367
    ; 2) Find the answer record with TYPE 0001 ( host IP )
1195
    ; 2) Find the answer record with TYPE 0001 ( host IP )
1368
    ; 3) Finally, copy the IP address to the display
1196
    ; 3) Finally, copy the IP address to the display
1369
    ; Note: The response is in dnsMsg
1197
    ; Note: The response is in dnsMsg
1370
    ;       The end of the buffer is pointed to by [dnsMsgLen]
1198
    ;       The end of the buffer is pointed to by [dnsMsgLen]
1371
 
1199
 
1372
    ; Clear the IP address text
1200
; Clear the IP address text
1373
    mov     [server_ip], dword 0
1201
	mov	[server_ip],dword  0
1374
 
-
 
1375
    mov     esi, dnsMsg
1202
	mov	esi,dnsMsg
1376
 
-
 
1377
    ; Is this a response to my question?
1203
; Is this a response to my question?
1378
    mov     al, [esi+2]
1204
	mov	al,[esi+2]
1379
    and     al, 0x80
1205
	and	al,0x80
1380
    cmp     al, 0x80
1206
	cmp	al,0x80
1381
    jne     ctr002a
1207
	jne	ctr002a
1382
 
-
 
1383
    ; Were there any errors?
1208
; Were there any errors?
1384
    mov     al, [esi+3]
1209
	mov	al,[esi+3]
1385
    and     al, 0x0F
1210
	and	al,0x0F
1386
    cmp     al, 0x00
1211
	cmp	al,0x00
1387
    jne     ctr002a
1212
	jne	ctr002a
1388
 
-
 
1389
    ; Is there ( at least 1 ) answer?
1213
; Is there ( at least 1 ) answer?
1390
    mov     ax, [esi+6]
1214
	mov	ax,[esi+6]
1391
    cmp     ax, 0x00
1215
	cmp	ax,0x00
1392
    je      ctr002a
1216
	je	ctr002a
1393
 
-
 
1394
    ; Header validated. Scan through and get my answer
1217
; Header valdated. Scan through and get my answer
1395
 
-
 
1396
if DEBUGGING_STATE = DEBUGGING_ENABLED
1218
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1397
    pusha
1219
	pusha
1398
    mov     esi, str4
1220
	mov	esi,str4
1399
    call    debug_print_string
1221
	call	debug_print_string
1400
    popa
1222
	popa
1401
end if
1223
end	if
1402
 
-
 
1403
    add     esi, 12             ; Skip to the question field
1224
	add	esi,12	; Skip to the question field
1404
 
-
 
1405
    ; Skip through the question field
1225
; Skip through the question field
1406
    call    skipName
1226
	call	skipName
1407
    add     esi, 4              ; skip past the questions qtype, qclass
1227
	add	esi,4	; skip past the questions qtype, qclass
1408
 
1228
 
1409
ctr002z:
1229
ctr002z:
1410
    ; Now at the answer. There may be several answers,
1230
; Now at the answer. There may be several answers,
1411
    ; find the right one ( TYPE = 0x0001 )
1231
; find the right one ( TYPE = 0x0001 )
1412
    call    skipName
1232
	call	skipName
1413
    mov     ax, [esi]
1233
	mov	ax,[esi]
1414
    cmp     ax, 0x0100          ; Is this the IP address answer?
1234
	cmp	ax,0x0100	; Is this the IP address answer?
1415
    jne     ctr002c
1235
	jne	ctr002c
1416
 
-
 
1417
    ; Yes! Point esi to the first byte of the IP address
1236
; Yes! Point esi to the first byte of the IP address
1418
    add     esi, 10
1237
	add	esi,10
1419
 
-
 
1420
    mov     eax, [esi]
1238
	mov	eax,[esi]
1421
    mov     [server_ip], eax
1239
	mov	[server_ip],eax
1422
    ret
1240
	ret
1423
 
-
 
1424
 
1241
 
1425
ctr002c:                        ; Skip through the answer, move to the next
1242
ctr002c:	; Skip through the answer, move to the next
1426
    add     esi, 8
1243
	add	esi,8
1427
    movzx   eax, byte [esi+1]
1244
	movzx	eax,byte [esi+1]
1428
    mov     ah, [esi]
1245
	mov	ah,[esi]
1429
    add     esi, eax
1246
	add	esi,eax
1430
    add     esi, 2
1247
	add	esi,2
1431
 
-
 
1432
    ; Have we reached the end of the msg?
1248
; Have we reached the end of the msg?
1433
    ; This is an error condition, should not happen
1249
; This is an error condition, should not happen
1434
    cmp     esi, [dnsMsgLen]
1250
	cmp	esi,[dnsMsgLen]
1435
    jl      ctr002z             ; Check next answer
1251
	jl	ctr002z	; Check next answer
1436
    jmp     ctr002a             ; abort
1252
	jmp	ctr002a	; abort
1437
 
1253
 
1438
ctr002a:
1254
ctr002a:
1439
    jmp     ctr001
1255
	jmp	ctr001
1440
 
1256
 
1441
ctr003:                         ; redraw
1257
ctr003:	; redraw
1442
    call    draw_window
1258
	call	draw_window
1443
    jmp     ctr001
1259
	jmp	ctr001
1444
 
1260
 
1445
ctr004:                         ; key
1261
ctr004:	; key
1446
    mov     eax,2               ; just read it and ignore
1262
	mcall	2	; just read it and ignore
1447
    mcall
-
 
1448
    jmp     ctr001
1263
	jmp	ctr001
1449
 
1264
 
1450
ctr005:                         ; button
1265
ctr005:	; button
1451
    mov     eax,17              ; get id
1266
	mcall	17	; get id
1452
    mcall
-
 
1453
 
-
 
1454
    mov     dl, ah
1267
	mov	dl,ah
1455
 
1268
 
1456
    ; close socket
1269
	; close	socket
1457
    mov     eax, 53
-
 
1458
    mov     ebx, 1
-
 
1459
    mov     ecx, [socketNum]
1270
	mcall	53,1,[socketNum]
1460
    mcall
-
 
1461
 
-
 
1462
    cmp     dl, 1
1271
	cmp	dl,1
1463
    je      exit
1272
	je	exit
1464
 
1273
 
1465
    mov     [socketNum], dword 0xFFFF
1274
	mov	[socketNum],dword  0xFFFF
1466
    mov     [server_ip], dword 0
1275
	mov	[server_ip],dword  0
1467
 
-
 
1468
    ret
1276
	ret
1469
 
-
 
1470
 
-
 
1471
 
1277
 
1472
;***************************************************************************
1278
;***************************************************************************
1473
;   Function
1279
;   Function
1474
;      skipName
1280
;      skipName
1475
;
1281
;
1476
;   Description
1282
;   Description
1477
;       Increment esi to the first byte past the name field
1283
;       Increment esi to the first byte past the name field
1478
;       Names may use compressed labels. Normally do.
1284
;       Names may use compressed labels. Normally do.
1479
;       RFC 1035 page 30 gives details
1285
;       RFC 1035 page 30 gives details
1480
;
1286
;
1481
;***************************************************************************
1287
;***************************************************************************
1482
skipName:
1288
skipName:
1483
    mov     al, [esi]
1289
	mov	al,[esi]
1484
    cmp     al, 0
1290
	cmp	al,0
1485
    je      sn_exit
1291
	je	sn_exit
1486
    and     al, 0xc0
1292
	and	al,0xc0
1487
    cmp     al, 0xc0
1293
	cmp	al,0xc0
1488
    je      sn001
1294
	je	sn001
1489
 
1295
 
1490
    movzx   eax, byte [esi]
1296
	movzx	eax,byte [esi]
1491
    inc     eax
1297
	inc	eax
1492
    add     esi, eax
1298
	add	esi,eax
1493
    jmp     skipName
1299
	jmp	skipName
1494
 
1300
 
1495
sn001:
1301
sn001:
1496
    add     esi, 2                          ; A pointer is always at the end
1302
	add	esi,2	; A pointer is always at the end
1497
    ret
1303
	ret
1498
 
1304
 
1499
sn_exit:
1305
sn_exit:
1500
    inc     esi
1306
	inc	esi
1501
    ret
1307
	ret
1502
 
1308
 
1503
;***************************************************************************
1309
;***************************************************************************
1504
;   Function
1310
;   Function
1505
;       load_settings
1311
;       load_settings
1506
;
1312
;
1507
;   Description
1313
;   Description
1508
;       Load settings from configuration file network.ini
1314
;       Load settings from configuration file network.ini
1509
;
1315
;
1510
;***************************************************************************
1316
;***************************************************************************
1511
include "proc32.inc"
-
 
1512
include "dll.inc"
-
 
1513
load_settings:
1317
load_settings:
1514
    stdcall dll.Load, @IMPORT
1318
	stdcall	dll.Load,@IMPORT
1515
    test    eax, eax
1319
	test	eax,eax
1516
    jnz     ls001
1320
	jnz	ls001
1517
    invoke  ini.get_str, inifile, sec_proxy, key_proxy, proxyAddr, 256, proxyAddr
1321
	invoke	ini.get_str,inifile,sec_proxy,key_proxy,proxyAddr,256,proxyAddr
1518
    invoke  ini.get_int, inifile, sec_proxy, key_proxyport, 80
1322
	invoke	ini.get_int,inifile,sec_proxy,key_proxyport,80
1519
    mov     [proxyPort], eax
1323
	mov	[proxyPort],eax
1520
    invoke  ini.get_str, inifile, sec_proxy, key_user, proxyUser, 256, proxyUser
1324
	invoke	ini.get_str,inifile,sec_proxy,key_user,	proxyUser,256,proxyUser
1521
    invoke  ini.get_str, inifile, sec_proxy, key_password, proxyPassword, 256, proxyPassword
1325
	invoke	ini.get_str,inifile,sec_proxy,key_password,proxyPassword,256,proxyPassword
1522
ls001:
1326
ls001:
1523
    ret
1327
	ret
1524
 
1328
 
1525
;***************************************************************************
1329
;***************************************************************************
1526
;   Function
1330
;   Function
1527
;       append_proxy_auth_header
1331
;       append_proxy_auth_header
1528
;
1332
;
1529
;   Description
1333
;   Description
1530
;       Append header to HTTP request for proxy authentification
1334
;       Append header to HTTP request for proxy authentification
1531
;
1335
;
1532
;***************************************************************************
1336
;***************************************************************************
1533
append_proxy_auth_header:
1337
append_proxy_auth_header:
1534
    mov     esi, proxy_auth_basic
1338
	mov	esi,proxy_auth_basic
1535
    mov     ecx, proxy_auth_basic_end - proxy_auth_basic
1339
	mov	ecx,proxy_auth_basic_end - proxy_auth_basic
1536
    rep     movsb
1340
	rep	movsb
1537
    ; base64-encode string :
1341
; base64-encode string :
1538
    mov     esi, proxyUser
1342
	mov	esi,proxyUser
-
 
1343
 
1539
apah000:
1344
apah000:
1540
    lodsb
1345
	lodsb
1541
    test    al, al
1346
	test	al,al
1542
    jz      apah001
1347
	jz	apah001
1543
    call    encode_base64_byte
1348
	call	encode_base64_byte
1544
    jmp     apah000
1349
	jmp	apah000
-
 
1350
 
1545
apah001:
1351
apah001:
1546
    mov     al, ':'
1352
	mov	al,':'
1547
    call    encode_base64_byte
1353
	call	encode_base64_byte
1548
    mov     esi, proxyPassword
1354
	mov	esi,proxyPassword
-
 
1355
 
1549
apah002:
1356
apah002:
1550
    lodsb
1357
	lodsb
1551
    test    al, al
1358
	test	al,al
1552
    jz      apah003
1359
	jz	apah003
1553
    call    encode_base64_byte
1360
	call	encode_base64_byte
1554
    jmp     apah002
1361
	jmp	apah002
-
 
1362
 
1555
apah003:
1363
apah003:
1556
    call    encode_base64_final
1364
	call	encode_base64_final
1557
    ret
1365
	ret
1558
 
1366
 
1559
encode_base64_byte:
1367
encode_base64_byte:
1560
    inc     ecx
1368
	inc	ecx
1561
    shl     edx, 8
1369
	shl	edx,8
1562
    mov     dl, al
1370
	mov	dl,al
1563
    cmp     ecx, 3
1371
	cmp	ecx,3
1564
    je      ebb001
1372
	je	ebb001
1565
    ret
1373
	ret
-
 
1374
 
1566
ebb001:
1375
ebb001:
1567
    shl     edx, 8
1376
	shl	edx,8
1568
    inc     ecx
1377
	inc	ecx
-
 
1378
 
1569
ebb002:
1379
ebb002:
1570
    rol     edx, 6
1380
	rol	edx,6
1571
    xor     eax, eax
1381
	xor	eax,eax
1572
    xchg    al, dl
1382
	xchg	al,dl
1573
    mov     al, [base64_table+eax]
1383
	mov	al,[base64_table+eax]
1574
    stosb
1384
	stosb
1575
    loop    ebb002
1385
	loop	ebb002
1576
    ret
1386
	ret
1577
 
1387
 
1578
encode_base64_final:
1388
encode_base64_final:
1579
    mov     al, 0
1389
	mov	al,0
1580
    test    ecx, ecx
1390
	test	ecx,ecx
1581
    jz      ebf000
1391
	jz	ebf000
1582
    call    encode_base64_byte
1392
	call	encode_base64_byte
1583
    test    ecx, ecx
1393
	test	ecx,ecx
1584
    jz      ebf001
1394
	jz	ebf001
1585
    call    encode_base64_byte
1395
	call	encode_base64_byte
1586
    mov     byte [edi-2], '='
1396
	mov	byte [edi-2],'='
-
 
1397
 
1587
ebf001:
1398
ebf001:
1588
    mov     byte [edi-1], '='
1399
	mov	byte [edi-1],'='
-
 
1400
 
1589
ebf000:
1401
ebf000:
1590
    ret
1402
	ret
1591
 
1403
 
1592
if DEBUGGING_STATE = DEBUGGING_ENABLED
1404
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1593
 
1405
 
1594
;****************************************************************************
1406
;****************************************************************************
1595
;    Function
1407
;    Function
1596
;       debug_print_string
1408
;       debug_print_string
1597
;
1409
;
1598
;   Description
1410
;   Description
1599
;       prints a string to the debug board, in quotes
1411
;       prints a string to the debug board, in quotes
1600
;
1412
;
1601
;       esi holds ptr to msg to display, which is space or 0 terminated
1413
;       esi holds ptr to msg to display, which is space or 0 terminated
1602
;
1414
;
1603
;       Nothing preserved; I'm assuming a pusha/popa is done before calling
1415
;       Nothing preserved; I'm assuming a pusha/popa is done before calling
1604
;
1416
;
1605
;****************************************************************************
1417
;****************************************************************************
1606
debug_print_string:
1418
debug_print_string:
1607
    push    esi
1419
	push	esi
1608
    mov     cl, '"'
1420
	mov	cl,'"'
1609
    mov     eax,63
-
 
1610
    mov     ebx, 1
-
 
1611
    mcall
1421
	mcall	63,1
1612
    pop     esi
1422
	pop	esi
1613
 
1423
 
1614
dps_000:
1424
dps_000:
1615
    mov     cl, [esi]
1425
	mov	cl,[esi]
1616
    cmp     cl, 0
1426
	cmp	cl,0
1617
    je      dps_exit
1427
	je	dps_exit
-
 
1428
 
1618
    cmp     cl, ' '
1429
	cmp	cl,' '
1619
    je      dps_exit
1430
	je	dps_exit
1620
    jmp     dps_001
1431
	jmp	dps_001
1621
 
1432
 
1622
dps_exit:
1433
dps_exit:
1623
    mov     cl, '"'
1434
	mov	cl,'"'
1624
    mov     eax,63
-
 
1625
    mov     ebx, 1
-
 
1626
    mcall
1435
	mcall	63,1
1627
    mov     cl, 13
1436
	mov	cl,13
1628
    mov     eax,63
-
 
1629
    mov     ebx, 1
-
 
1630
    mcall
1437
	mcall	
1631
    mov     cl, 10
1438
	mov	cl,10
1632
    mov     eax,63
-
 
1633
    mov     ebx, 1
-
 
1634
    mcall
1439
	mcall
1635
    ret
1440
	ret
1636
 
1441
 
1637
dps_001:
1442
dps_001:
1638
    mov     eax,63
-
 
1639
    mov     ebx, 1
-
 
1640
    push    esi
1443
	push	esi
1641
    mcall
1444
	mcall	63,1
1642
 
-
 
1643
    pop     esi
1445
	pop	esi
1644
    inc     esi
1446
	inc	esi
1645
    jmp     dps_000
1447
	jmp	dps_000
1646
end if
1448
end	if
1647
 
-
 
1648
 
1449
 
1649
;****************************************************************************
1450
;****************************************************************************
1650
;    Function
1451
;    Function
1651
;       print_text
1452
;       print_text
1652
;
1453
;
1653
;   Description
1454
;   Description
1654
;       display the url (full path) text
1455
;       display the url (full path) text
1655
;
1456
;
1656
;****************************************************************************
1457
;****************************************************************************
1657
print_text:
1458
print_text:
1658
    ; Draw a bar to blank out previous text
1459
; Draw a bar to blank out previous text
1659
    mov     eax,13
-
 
1660
    mov     ebx,30*65536+URLMAXLEN*6  ; 50 should really be [len], and 103 [xa]
1460
	mov	ebx,30*65536+URLMAXLEN*6	; 50 should really be [len] and 103 [xa]
1661
    mov     ecx,[ya]
1461
	mov	ecx,[ya]
1662
    shl     ecx,16
1462
	shl	ecx,16
1663
    mov     cx,9
1463
	mov	cx,9
1664
    mov     edx,0xFFFFFF
1464
	mcall	13,,,0xFFFFFF
1665
    mcall
-
 
1666
 
-
 
1667
    ; write text
1465
; write text
1668
    mov     eax,4
-
 
1669
    mov     ebx,30*65536
1466
	mov	ebx,30*65536
1670
    add     ebx,[ya]
1467
	add	ebx,[ya]
1671
    mov     ecx,0x000000
-
 
1672
    mov     edx,[addr]
1468
	xor	ecx,ecx
1673
    mov     esi,URLMAXLEN
1469
	mcall	4,,,[addr],URLMAXLEN
1674
    mcall
-
 
1675
 
-
 
1676
    ret
1470
	ret
1677
 
1471
 
1678
;   *********************************************
1472
;   *********************************************
1679
;   *******  WINDOW DEFINITIONS AND DRAW ********
1473
;   *******  WINDOW DEFINITIONS AND DRAW ********
1680
;   *********************************************
1474
;   *********************************************
1681
 
1475
 
1682
draw_window:
1476
draw_window:
-
 
1477
; function 12: tell os about windowdraw
-
 
1478
; 1 start of draw
-
 
1479
	mcall	12,1
1683
 
1480
 
1684
	cmp		byte [params], 0
1481
;	cmp	[params],byte 0
1685
	jz		.noret
-
 
1686
 
-
 
1687
    mov     eax,12                    ; function 12:tell os about windowdraw
-
 
1688
    mov     ebx,1                     ; 1, start of draw
-
 
1689
    mcall
1482
;	jz	.noret
1690
 
-
 
1691
	; ýòî íåñêîëüêî çàãàäî÷íî, íî åñëè íå ðèñîâàòü îêîøêî ñîâñåì, ïðîãà íå ïàøåò.
-
 
1692
	
-
 
1693
    mov     eax,0                     ; function 0 : define and draw window
-
 
1694
    mov     ebx,0          ; [x start] *65536 + [x size]
-
 
1695
    mov     ecx,0          ; [y start] *65536 + [y size]
-
 
1696
    mov     edx,0x14ffffff            ; color of work area RRGGBB,8->color gl
-
 
1697
    mov     edi,title                 ; WINDOW LABEL
-
 
1698
    mcall
-
 
1699
 
-
 
1700
    mov     eax,12                    ; function 12:tell os about windowdraw
-
 
1701
    mov     ebx,2                     ; 2, end of draw
-
 
1702
    mcall
-
 
1703
 
-
 
1704
	ret
-
 
1705
	
-
 
1706
.noret:
-
 
1707
    mov     eax,12                    ; function 12:tell os about windowdraw
-
 
1708
    mov     ebx,1                     ; 1, start of draw
-
 
1709
    mcall
1483
 
1710
 
1484
; ýòî íåñêîëüêî çàãàäî÷íî, íî åñëè íå ðèñîâàòü îêîøêî ñîâñåì, ïðîãà íå ïàøåò.
-
 
1485
; DRAW	WINDOW
1711
                                   ; DRAW WINDOW
1486
; eax	function 0 : define and draw window
-
 
1487
;	xor	eax,eax
1712
    mov     eax,0                     ; function 0 : define and draw window
1488
; ebx	[x start] *65536 + [x size]
-
 
1489
;	xor	ebx,ebx
1713
    mov     ebx,50*65536+600          ; [x start] *65536 + [x size]
1490
; ecx	[y start] *65536 + [y size]
1714
    mov     ecx,350*65536+200          ; [y start] *65536 + [y size]
1491
;	xor	ecx,ecx
1715
    mov     edx,0x14ffffff            ; color of work area RRGGBB,8->color gl
1492
; edx	color of work area RRGGBB,8->color gl
-
 
1493
; esi	color of bar and flags
1716
    mov     edi,title                 ; WINDOW LABEL
1494
;	xor	esi,esi
-
 
1495
;	mcall	,,,0x14ffffff,,title
-
 
1496
 
-
 
1497
; function 12: tell os about windowdraw
-
 
1498
; 2, end of draw
-
 
1499
;	mcall	12,2
-
 
1500
;	ret
1717
    mcall
1501
	
-
 
1502
;.noret:
-
 
1503
; DRAW	WINDOW
-
 
1504
; eax	function 0 : define and draw window
-
 
1505
	xor	eax,eax
-
 
1506
; ebx	[x start] *65536 + [x size]
-
 
1507
; ecx	[y start] *65536 + [y size]
-
 
1508
; edx	color of work area RRGGBB,8->color gl
-
 
1509
; esi	color of bar and flags
1718
 
1510
	xor	esi,esi
1719
 
1511
; edi	WINDOW	LABEL
1720
    mov     esi, URLMAXLEN            ; URL
1512
	mcall	,<50,600>,<350,200>,0x14ffffff,,title
1721
    mov     eax,4                     ; function 4 : write text to window
1513
; eax	function 4: write text to window
-
 
1514
; ebx	[x start] *65536 + [y start]
1722
    mov     ebx,30*65536+38           ; [x start] *65536 + [y start]
1515
; ecx	color of text RRGGBB
-
 
1516
; edx	pointer to text beginning
1723
    mov     ecx,0x000000              ; color of text RRGGBB
1517
; esi	max lenght
1724
    mov     edx,document_user         ; pointer to text beginning
1518
	xor	ecx,ecx
1725
    mcall
-
 
1726
 
-
 
1727
    ; mov     eax,38
-
 
1728
    ; mov     ebx,5*65536+545
-
 
1729
    ; mov     ecx,60*65536+60
-
 
1730
    ; mov     edx,0x000000
1519
	mcall	4,<30,38>,,document_user,URLMAXLEN
1731
    ; mcall
1520
 
1732
 
1521
;	xor	edx,edx
1733
    ;mov     eax,38
1522
;	mcall	38,<5,545>,<60,60>
1734
    ;mov     ebx,5*65536+545
1523
 
1735
    ; mov     ecx,[winys]
1524
;	mov	ecx,[winys]
1736
    ; shl     ecx,16
1525
;	shl	ecx,16
1737
    ; add     ecx,[winys]
1526
;	add	ecx,[winys]
1738
    ; sub     ecx,26*65536+26
1527
;	sub	ecx,26*65536+26
1739
    ;mov     edx,0x000000
-
 
1740
    ;mcall
-
 
1741
                                   ; RELOAD
-
 
1742
    mov     eax,8                     ; function 8 : define and draw button
-
 
1743
    mov     ebx,388*65536+50          ; [x start] *65536 + [x size]
-
 
1744
    mov     ecx,34*65536+14           ; [y start] *65536 + [y size]
-
 
1745
    mov     edx,22                    ; button id
-
 
1746
    mov     esi,0x5588dd              ; button color RRGGBB
-
 
1747
    mcall
1528
;	mcall	38,<5,545>
-
 
1529
 
-
 
1530
; RELOAD
-
 
1531
; eax	function 8 : define and draw button
-
 
1532
; ebx	[x start] *65536 + [x size]
-
 
1533
; ecx	[y start] *65536 + [y size]
-
 
1534
; edx	button id
-
 
1535
; esi	button color RRGGBB
1748
 
1536
	mcall	8,<388,50>,<34,14>,22,0x5588dd
1749
                                   ; URL
-
 
1750
    ;mov     eax,8                     ; function 8 : define and draw button
-
 
1751
    mov     ebx,10*65536+12          ; [x start] *65536 + [x size]
-
 
1752
    mov     ecx,34*65536+12           ; [y start] *65536 + [y size]
1537
; URL
1753
    mov     edx,10                    ; button id
-
 
1754
    ;mov     esi,0x5588dd              ; button color RRGGBB
-
 
1755
    mcall
-
 
1756
 
1538
	mcall	,<10,12>,<34,12>,10
1757
                                   ; STOP
-
 
1758
    ;mov     eax,8                     ; function 8 : define and draw button
-
 
1759
    mov     ebx,443*65536+50          ; [x start] *65536 + [x size]
-
 
1760
    mov     ecx,34*65536+14           ; [y start] *65536 + [y size]
1539
; STOP
1761
    mov     edx,24                    ; button id
-
 
1762
    ;mov     esi,0x5588dd              ; button color RRGGBB
-
 
1763
    mcall
-
 
1764
 
1540
	mcall	,<443,50>,<34,14>,24
1765
									; SAVE
-
 
1766
    mov     ebx,(443+55)*65536+50          ; [x start] *65536 + [x size]
-
 
1767
    mov     ecx,34*65536+14           ; [y start] *65536 + [y size]
-
 
1768
    mov     edx,26                    ; button id
-
 
1769
    ;mov     esi,0x5588dd              ; button color RRGGBB
1541
; SAVE
1770
    mcall
-
 
1771
	
1542
	mcall	,<498,50>,,26
1772
                                   ; BUTTON TEXT
1543
; BUTTON TEXT
1773
    mov     eax,4                     ; function 4 : write text to window
1544
; eax	function 4 : write text to window
1774
    mov     ebx,390*65536+38          ; [x start] *65536 + [y start]
1545
; ebx	[x start] *65536 + [y start]
1775
    mov     ecx,0xffffff              ; color of text RRGGBB
1546
; ecx	color	of	text	RRGGBB
1776
    mov     edx,button_text           ; pointer to text beginning
1547
; edx	pointer	to	text	beginning
1777
    mov     esi,30                    ; text length
1548
; esi	text	length
1778
    mcall
-
 
1779
 
1549
	mcall	4,<390,38>,0xffffff,button_text,30
1780
    call    display_page
1550
	call	display_page
1781
 
1551
 
1782
    mov     eax,12                    ; function 12:tell os about windowdraw
1552
; function 12: tell os about windowdraw
1783
    mov     ebx,2                     ; 2, end of draw
1553
; 2, end of draw
-
 
1554
	mcall	12,2
1784
    mcall
1555
	ret
1785
 
-
 
-
 
1556
;-----------------------------------------------------------------------------
1786
    ret
1557
; Data area
1787
 
1558
;-----------------------------------------------------------------------------
1788
align 4
1559
align	4
1789
@IMPORT:
1560
@IMPORT:
1790
 
1561
 
1791
library	libini, 'libini.obj'
1562
library	libini,'libini.obj'
1792
 
1563
 
1793
import	libini, \
1564
import	libini, \
1794
	ini.get_str, 'ini_get_str',	\
1565
	ini.get_str,'ini_get_str', \
1795
	ini.get_int, 'ini_get_int'
1566
	ini.get_int,'ini_get_int'
1796
 
-
 
-
 
1567
 
1797
 
1568
;---------------------------------------------------------------------
1798
fileinfo		dd	2, 0, 0
1569
fileinfo	dd 2,0,0
1799
final_size		dd		0
1570
final_size	dd 0
1800
final_buffer	dd		0
1571
final_buffer	dd 0
1801
				db	'/rd/1/.download',0
1572
		db '/rd/1/.download',0
1802
				
1573
	
1803
body_pos		dd		0
1574
body_pos	dd 0
1804
 
1575
 
1805
;fileinfo_tmp	dd	2, 0, 0
1576
;fileinfo_tmp	dd 2,0,0
1806
buf_size		dd		0
1577
buf_size	dd 0
1807
buf_ptr			dd		0
1578
buf_ptr		dd 0
1808
				;db	'/rd/1/1',0
1579
;		db	'/rd/1/1',0
1809
 
1580
 
1810
deba			dd		0
1581
deba		dd 0
1811
				db		0
1582
		db 0
1812
 
-
 
1813
 
-
 
-
 
1583
;---------------------------------------------------------------------
1814
if DEBUGGING_STATE = DEBUGGING_ENABLED
1584
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1815
str1:       db  "Resolving...",0
1585
str1:		db "Resolving...",0
1816
str3:       db  "Resolved",0
1586
str3:		db "Resolved",0
1817
str2:       db  "GotIP",0
1587
str2:		db "GotIP",0
1818
str4:       db  "GotResponse",0
1588
str4:		db "GotResponse",0
1819
end if
1589
end	if
1820
 
-
 
1821
params		db	1024 dup(0)
1590
;---------------------------------------------------------------------
1822
 
-
 
1823
button_text     db      ' RELOAD    STOP       SAVE    '
1591
button_text	db ' RELOAD    STOP       SAVE    '
1824
dpx             dd      25  ; x - start of html page in pixels in window
1592
dpx		dd 25	; x - start of html page in pixels in window
1825
dpy             dd      65  ; for y
1593
dpy		dd 65	; for	y
1826
lastletter      db      0
1594
lastletter	db 0
1827
pageyinc        dd      0
1595
pageyinc	dd 0
1828
display_from    dd      20
1596
display_from	dd 20
1829
pos             dd      0x0
1597
pos		dd 0x0
1830
pagex           dd      0x0
1598
pagex		dd 0x0
1831
pagey           dd      0x0
1599
pagey		dd 0x0
1832
pagexs          dd      80
1600
pagexs		dd 80
1833
command_on_off  dd      0x0
1601
command_on_off	dd 0x0
1834
text_type       db      1
1602
text_type	db 1
1835
com2            dd      0x0
1603
com2		dd 0x0
1836
script          dd      0x0
1604
script		dd 0x0
1837
socket          dd      0x0
1605
socket		dd 0x0
1838
 
1606
 
1839
addr            dd  0x0
1607
addr		dd 0x0
1840
ya              dd  0x0
1608
ya		dd 0x0
1841
len             dd  0x00
1609
len		dd 0x00
1842
 
1610
 
1843
title         db      'Downloader',0
1611
title		db 'Downloader',0
1844
 
1612
 
1845
server_ip:      db      207,44,212,20
1613
server_ip:	db 207,44,212,20
1846
;dns_ip:         db      194,145,128,1
1614
;dns_ip:	db 194,145,128,1
-
 
1615
;---------------------------------------------------------------------
-
 
1616
;webAddr:
1847
webAddr:        times URLMAXLEN db ' '
1617
;times URLMAXLEN db ' '
1848
db 0
1618
;db	0
-
 
1619
 
1849
document_user:  db      'Click on the button to the left to enter a URL',0
1620
;document_user:	db 'Click on the button to the left to enter a URL',0
1850
times URLMAXLEN+document_user-$ db 0
1621
;times URLMAXLEN+document_user-$ db 0
-
 
1622
 
1851
document:       db      '/'
1623
;document:	db '/'
1852
times URLMAXLEN-1       db      ' '
1624
;times URLMAXLEN-1 db ' '
1853
 
-
 
-
 
1625
;---------------------------------------------------------------------
1854
s_contentlength		db	'Content-Length:'
1626
s_contentlength	db 'Content-Length:'
1855
len_contentlength	=	15
1627
len_contentlength = 15
1856
 
1628
 
1857
s_chunked			db	'Transfer-Encoding: chunked'
1629
s_chunked	db 'Transfer-Encoding: chunked'
1858
len_chunked			= $ - s_chunked
1630
len_chunked	= $ - s_chunked
1859
 
1631
 
1860
is_body			dd		0 ; 0 if headers, 1 if content
1632
is_body		dd 0	; 0 if headers, 1 if content
1861
is_chunked		dd		0
1633
is_chunked	dd 0
1862
prev_chunk_end	dd		0
1634
prev_chunk_end	dd 0
1863
cur_chunk_size	dd		0
1635
cur_chunk_size	dd 0
1864
 
1636
 
1865
string0:        db      'GET '
1637
string0:	db 'GET '
1866
 
1638
 
1867
stringh:        db      ' HTTP/1.1',13,10,'Host: '
1639
stringh:        db ' HTTP/1.1',13,10,'Host: '
1868
stringh_end:
1640
stringh_end:
1869
proxy_auth_basic: db      13,10,'Proxy-Authorization: Basic '
1641
proxy_auth_basic:	db 13,10,'Proxy-Authorization: Basic '
1870
proxy_auth_basic_end:
1642
proxy_auth_basic_end:
1871
connclose:		db		13,10,'User-Agent: Kolibrios Downloader',13,10,'Connection: Close',13,10,13,10
1643
connclose:	db 13,10,'User-Agent: Kolibrios Downloader',13,10,'Connection: Close',13,10,13,10
1872
connclose_end:
1644
connclose_end:
1873
 
1645
 
1874
base64_table	db	'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
1646
base64_table	db 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
1875
		db	'0123456789+/'
1647
		db '0123456789+/'
1876
 
1648
 
1877
inifile		db	'/sys/network/zeroconf.ini',0
1649
inifile		db '/sys/network/zeroconf.ini',0
1878
 
1650
 
1879
sec_proxy:
1651
sec_proxy:
1880
key_proxy		db		'proxy',0
1652
key_proxy	db 'proxy',0
1881
key_proxyport		db		'port',0
1653
key_proxyport	db 'port',0
1882
key_user		db		'user',0
1654
key_user	db 'user',0
1883
key_password		db		'password',0
1655
key_password	db 'password',0
1884
 
-
 
1885
request			db		256 dup(0)
-
 
1886
 
-
 
1887
proxyAddr		db		256 dup(0)
-
 
1888
proxyUser		db		256 dup(0)
1656
 
1889
proxyPassword	db		256 dup(0)
1657
 
1890
proxyPort		dd		80
1658
proxyPort	dd 80
1891
 
1659
 
1892
shared_name		dd		0
1660
shared_name	dd 0
1893
 
1661
 
1894
;yandex:			db		'menuetos.net'
1662
;yandex:	db 'menuetos.net'
1895
;yandex_end:
1663
;yandex_end:
1896
 
1664
 
1897
status          dd      0x0
1665
status		dd 0x0
1898
prev_status     dd      0x0
1666
prev_status	dd 0x0
1899
 
1667
 
1900
onoff           dd      0x0
1668
onoff		dd 0x0
1901
 
1669
 
1902
nextupdate:     dd      0
1670
nextupdate:	dd 0
1903
winys:          dd      400
1671
winys:		dd 400
1904
 
-
 
1905
primary_buf		rb		primary_buffer_size
-
 
1906
 
1672
 
1907
dnsMsgLen:      dd 0
1673
dnsMsgLen:	dd 0
-
 
1674
socketNum:	dd 0xFFFF
-
 
1675
;---------------------------------------------------------------------
-
 
1676
document_user:	db 'Click on the button to the left to enter a URL',0
-
 
1677
;---------------------------------------------------------------------
-
 
1678
IM_END:
-
 
1679
	rb URLMAXLEN-(IM_END - document_user)
-
 
1680
;---------------------------------------------------------------------
-
 
1681
align 4
-
 
1682
document:
-
 
1683
	rb URLMAXLEN
-
 
1684
;---------------------------------------------------------------------
-
 
1685
align 4
-
 
1686
webAddr:
-
 
1687
	rb URLMAXLEN+1
-
 
1688
;---------------------------------------------------------------------
-
 
1689
align 4
-
 
1690
primary_buf:
-
 
1691
	rb primary_buffer_size
-
 
1692
;---------------------------------------------------------------------
-
 
1693
align 4
-
 
1694
params:		; db 1024 dup(0)
-
 
1695
	rb 1024
-
 
1696
;---------------------------------------------------------------------
-
 
1697
align 4
-
 
1698
request:	; db 256 dup(0)
-
 
1699
	rb 256
-
 
1700
;---------------------------------------------------------------------
-
 
1701
align 4
-
 
1702
proxyAddr:	; db 256 dup(0)
-
 
1703
	rb 256
-
 
1704
;---------------------------------------------------------------------
-
 
1705
align 4
-
 
1706
proxyUser:	; db 256 dup(0)
-
 
1707
	rb 256
-
 
1708
;---------------------------------------------------------------------
-
 
1709
align 4
-
 
1710
proxyPassword:	; db 256 dup(0)
-
 
1711
	rb 256
-
 
1712
;---------------------------------------------------------------------
1908
socketNum:      dd 0xFFFF
1713
align 4
-
 
1714
dnsMsg:
-
 
1715
	rb 4096
-
 
1716
;	rb 0x100000
-
 
1717
;---------------------------------------------------------------------
-
 
1718
align 4
-
 
1719
	rb 4096
-
 
1720
stacktop:
1909
dnsMsg:
1721
;---------------------------------------------------------------------
-
 
1722
I_END:
1910
I_END:
1723
;---------------------------------------------------------------------