Subversion Repositories Kolibri OS

Rev

Rev 1645 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1645 Rev 1646
Line -... Line 1...
-
 
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
Line 3... Line 15...
3
 
15
 
Line 10... Line 22...
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
Line 20... Line 32...
20
 
32
 
21
include 'lang.inc'
33
include	'lang.inc'
-
 
34
include	'../../../macros.inc'
-
 
35
include	"../../../proc32.inc"
22
include '../../../macros.inc'
36
include	"dll.inc"
Line 23... Line 37...
23
include "DEBUG.INC"
37
include	"debug.inc"
Line 24... Line 38...
24
 
38
 
Line 25... Line 39...
25
URLMAXLEN       equ     256  ; maximum length of url string
39
URLMAXLEN	equ 256	; maximum length of url string
26
 
40
 
Line 27... Line 41...
27
primary_buffer_size	equ	4096
41
primary_buffer_size	equ 4096
28
 
-
 
29
; Memory usage
42
 
-
 
43
; Memory usage
-
 
44
; webpage headers at buf_headers
-
 
45
 
-
 
46
START:	; start of execution
-
 
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
Line 30... Line -...
30
; webpage headers at buf_headers
-
 
31
 
-
 
32
START:                              ; start of execution
-
 
33
 
-
 
34
;dps <"Program started",13,10>
59
	cld
35
 
-
 
36
    mov     eax,40                          ; Report events
60
	stosb
Line 37... Line 61...
37
    mov     ebx,10000111b                   ; Stack 8 + defaults
61
	mov	al,' '
-
 
62
	mov	ecx,URLMAXLEN-1
-
 
63
	rep	stosb
Line 38... Line 64...
38
    mcall
64
 
39
	
-
 
Line 40... Line 65...
40
	mov		eax, 68						; create local heap
65
; create local heap
41
	mov		ebx, 11
-
 
42
	mcall
66
	mcall	68,11
43
	
67
 
44
	call		load_settings
68
	call	load_settings
45
	
69
	cmp	[params],byte 0
Line 46... Line 70...
46
	cmp		byte [params], 0
70
	jz	prepare_event	;red
47
	jz		red
71
 
-
 
72
	mcall	40,10000000b ; only net event!!!
48
	
73
 
49
	; we have an url
74
; we have an url
50
	
75
	mov	edi,document_user
51
	mov		edi, document_user
76
	mov	al,' '
-
 
77
	mov	ecx,URLMAXLEN
52
	mov		al, ' '
78
	rep	stosb
53
	mov		ecx, URLMAXLEN
79
	
-
 
80
	mov	esi,params
54
	rep		stosb
81
	mov	edi,document_user
55
	
82
 
56
	mov		esi, params
83
.copy_param:
57
	mov		edi, document_user
84
	mov	al,[esi]
-
 
85
	cmp	al,0
58
.copy_param:
86
	jz	.done
59
	mov		al, [esi]
87
 
60
	cmp		al, 0
88
	cmp	al,' '
61
	jz		.done
89
	jz	.done_inc
62
	cmp		al, ' '
90
 
Line 74... Line 102...
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
Line 76... Line 104...
76
	
104
 
Line -... Line 105...
-
 
105
	jmp	still
-
 
106
 
-
 
107
prepare_event:
-
 
108
; Report events
-
 
109
; Stack 8 + defaults
77
	jmp		still
110
	mcall	40,10000111b
78
	
111
 
Line 79... Line 112...
79
red:                    ; redraw
112
red:	; redraw
80
    call    draw_window
113
	call	draw_window
81
 
-
 
82
still:
-
 
83
    mov     eax,23                 ; wait here for event
-
 
84
    mov     ebx,1
114
 
85
    mcall
115
still:
-
 
116
	mcall	23,1	; wait here for event
86
 
117
	cmp	eax,1	; redraw request ?
87
    cmp     eax,1                  ; redraw request ?
118
	je	red
-
 
119
 
88
    je      red
120
	cmp	eax,2	; key in buffer ?
89
    cmp     eax,2                  ; key in buffer ?
121
	je	key
Line 90... Line 122...
90
    je      key
122
 
91
    cmp     eax,3                  ; button in buffer ?
123
	cmp	eax,3	; button in buffer ?
92
    je      button
-
 
93
 
124
	je	button
94
    ; Get the web page data from the remote server
125
 
95
    call    read_incoming_data
-
 
96
	
-
 
97
    mov     eax,[status]
-
 
98
    mov     [prev_status],eax
126
; Get the web page data from the remote server
99
 
-
 
100
    mov     eax,53
-
 
101
    mov     ebx,6
127
	call	read_incoming_data
Line 102... Line 128...
102
    mov     ecx,[socket]
128
	mov	eax,[status]
103
    mcall
129
	mov	[prev_status],eax
-
 
130
	mcall	53,6,[socket]
104
 
131
	mov	[status],eax
105
    mov     [status],eax
132
 
Line 106... Line 133...
106
 
133
	cmp	[prev_status],4
107
    cmp     [prev_status],4
-
 
108
    jge     no_send
134
	jge	no_send
Line 109... Line 135...
109
    cmp     [status],4
135
 
110
    jne     no_send
136
	cmp	[status],4
Line 111... Line 137...
111
 
137
	jne	no_send
112
    mov     [onoff],1
138
 
113
 
139
	mov	[onoff],1
114
    call    send_request
140
	call	send_request
115
 
141
 
116
no_send:
-
 
117
    call    print_status
142
no_send:
118
 
-
 
119
    cmp     [prev_status],4
-
 
120
    jne     no_close
-
 
121
    cmp     [status],4   ; connection closed by server
143
	call	print_status
122
    jbe     no_close     ; respond to connection close command
-
 
123
                         ; draw page
-
 
124
 
144
 
125
    call    read_incoming_data
-
 
126
 
145
	cmp	[prev_status],4
Line 127... Line 146...
127
    mov     eax,53
146
	jne	no_close
128
    mov     ebx,8
147
	cmp	[status],4	; connection closed by server
Line 129... Line 148...
129
    mov     ecx,[socket]
148
	jbe	no_close	; respond to connection close command
130
    mcall
149
; draw page
131
 
-
 
132
    call    draw_page
150
	call	read_incoming_data
133
 
151
	mcall	53,8,[socket]
134
    mov     [onoff],0
152
	call	draw_page
135
 
153
	mov	[onoff],0
136
no_close:
154
 
Line 156... Line 174...
156
no_up:
174
no_up:
157
    jmp     still
175
	jmp	still
Line 158... Line 176...
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
-
 
162
    mcall
179
	mcall	17	; get id
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
-
 
167
 
183
	jne	noclose
Line 168... Line 184...
168
;dps "Closing socket before exit... "
184
;	dps	"Closing socket before exit... "
Line 169... Line 185...
169
 
185
 
Line 177... Line 193...
177
    mcall
193
	mcall
Line 178... Line 194...
178
 
194
 
179
save:
195
save:
180
dps "saving"
196
dps	"saving"
181
newline
-
 
182
	mov		eax, 70
197
newline
183
	mov		ebx, fileinfo
-
 
184
	mcall
198
	mcall	70,fileinfo
185
;pregs
-
 
186
 
199
;pregs
Line 187... Line 200...
187
	jmp		still
200
	jmp	still
188
 
201
 
189
noclose:
202
noclose:
Line 216... Line 229...
216
    call    print_text
229
	call	print_text
Line 217... Line 230...
217
 
230
 
Line 218... Line 231...
218
    mov     edi,[addr]
231
	mov	edi,[addr]
219
 
-
 
220
f11:
232
 
221
    mov     eax,10
233
f11:
222
    mcall
234
	mcall	10
223
    cmp     eax,2 ; key?
235
	cmp	eax,2	; key?
Line 224... Line 236...
224
    jz      fbu
236
	jz	fbu
225
    jmp     still
-
 
226
 
237
	jmp	still
227
fbu:
238
 
228
    mov     eax,2
239
fbu:
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
Line 236... Line 247...
236
    mov     [edi],byte ' '
247
	mov	[edi],byte ' '
237
    call    print_text
248
	call	print_text
238
    jmp     f11
249
	jmp	f11
Line 239... Line 250...
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
Line 244... Line 255...
244
    je      retkey
255
	je	retkey
245
 
256
 
Line 246... Line 257...
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
Line 250... Line 261...
250
;    cmp     eax,dword 95
261
;	cmp	eax,95
251
;    jb      keyok
262
;	jb	keyok
252
;    sub     eax,32
-
 
253
 
263
;	sub	eax,32
254
keyok:
-
 
255
    mov     [edi],al
264
 
256
 
265
keyok:
257
    call    print_text
266
	mov	[edi],al
258
 
267
	call	print_text
259
    add     edi,1
268
	add	edi,1
260
    mov     esi,[addr]
-
 
261
    add     esi,URLMAXLEN
269
	mov	esi,[addr]
Line 262... Line 270...
262
    cmp     esi,edi
270
	add	esi,URLMAXLEN
263
    jnz     f11
271
	cmp	esi,edi
Line 264... Line 272...
264
 
272
	jnz	f11
265
    jmp  still
273
	jmp	still
266
 
274
 
Line 267... Line -...
267
retkey:
-
 
268
    mov     ah, 22   ; start load
275
retkey:
269
 
276
	mov	ah,22	; start load
270
nourl:
277
 
271
    call    socket_commands     ; opens or closes the connection
278
nourl:
272
    jmp     still
279
	call	socket_commands	; opens or closes the connection
Line 281... Line 288...
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
Line 306... Line -...
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
-
 
Line -... Line 323...
-
 
323
	jmp	.next_edx
317
.document_done:
324
 
318
 
325
.document_done:
319
	mov		esi, stringh
326
	mov	esi,stringh
-
 
327
	mov	ecx,stringh_end-stringh
Line 320... Line -...
320
	mov		ecx, stringh_end-stringh
-
 
321
	rep		movsb
328
	rep	movsb
322
 
329
	xor	edx,edx	; 0
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
-
 
Line -... Line 336...
-
 
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
-
 
335
	jz		@f
341
	cmp	[proxyUser],byte 0
336
	call		append_proxy_auth_header
342
	jz	@f
337
@@:
343
	call	append_proxy_auth_header
Line 338... Line 344...
338
 
344
@@:
Line 346... Line 352...
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
Line 356... Line 362...
356
 
362
 
357
    mov     edx, edi
363
	mov	edx,edi
358
	sub		edx, request
-
 
359
	
364
	sub	edx,request
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 .. '
-
 
362
    mov     ebx, 7
-
 
363
    mov     ecx, [socket]
-
 
364
    mov     esi, request
-
 
365
    mcall	
-
 
366
 
366
	mcall	53,7,[socket],,request	;' HTTP/1.1 .. '
367
    popa
367
	popa
Line 368... Line -...
368
    ret
-
 
369
 
368
	ret
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:
-
 
380
    pusha
-
 
381
 
-
 
382
    mov     eax,26
378
print_status:
383
    mov     ebx,9
-
 
384
    mcall
379
	pusha
385
 
380
	mcall	26,9
Line 386... Line 381...
386
    cmp     eax,[nextupdate]
381
	cmp	eax,[nextupdate]
387
    jb      status_return
-
 
388
 
382
	jb	status_return
Line 389... Line -...
389
    add     eax,25
-
 
390
 
-
 
391
    mov     [nextupdate],eax
383
 
392
 
384
	add	eax,25
393
    mov     eax,13
385
	mov	[nextupdate],eax
394
    mov     ebx,5*65536+100
386
 
395
    mov     ecx,[winys]
-
 
Line 396... Line -...
396
    shl     ecx,16
-
 
397
    add     ecx,-18*65536+10
-
 
398
    mov     edx,0xffffff
-
 
399
    mcall
387
	mov	ecx,[winys]
400
 
388
	shl	ecx,16
401
    mov     eax,47
389
	add	ecx,-18*65536+10
402
    mov     ebx,3*65536
390
	mcall	13,<5,100>,,0xffffff
Line 403... Line -...
403
    mov     ecx,[status]
-
 
404
    mov     edx,12*65536-18
-
 
405
    add     edx,[winys]
-
 
406
    mov     esi,0x000000
391
 
407
    mcall
392
	mov	edx,12*65536-18
408
 
393
	add	edx,[winys]
409
    mov     eax,47
-
 
Line 410... Line 394...
410
    mov     ebx,6*65536
394
	xor	esi,esi
411
    mov     ecx,[pos]
395
	mcall	47,<3,0>,[status],,
412
    mov     edx,40*65536-18
396
 
Line 413... Line -...
413
    add     edx,[winys]
-
 
414
    mov     esi,0x000000
397
	mov	edx,40*65536-18
415
    mcall
398
	add	edx,[winys]
416
 
399
	mcall	,<6,0>,[pos]
417
status_return:
400
 
418
    popa
401
status_return:
Line 431... Line 414...
431
    cmp     [onoff],1
414
	cmp	[onoff],1
432
    je      rid
415
	je	rid
433
    ret
416
	ret
Line 434... Line 417...
434
 
417
 
435
rid:
-
 
436
 
418
rid:
437
	push	esi
419
	push	esi
438
	push	edi
420
	push	edi
439
dps "rid"
421
dps	"rid"
Line 440... Line 422...
440
newline
422
newline
441
 
-
 
442
newbyteread:
423
 
443
 
-
 
444
	;call	print_status
-
 
445
 
-
 
446
    mov     eax, 53
424
newbyteread:
447
    mov     ebx, 2
-
 
448
    mov     ecx, [socket]
-
 
449
    mcall
425
	;call	print_status
450
 
426
	mcall	53,2,[socket]
Line 451... Line -...
451
    cmp     eax,0
-
 
452
    je      no_more_data
-
 
453
 
-
 
454
    mov     eax, 53
-
 
455
    mov     ebx, 11
427
	cmp	eax,0
456
	mov		edx, primary_buf
-
 
Line 457... Line 428...
457
    mov     ecx, [socket]
428
	je	no_more_data
458
	mov		esi, primary_buffer_size
429
 
459
    mcall
430
	mcall	53,11,[socket],primary_buf,primary_buffer_size
460
	
-
 
461
;dps "part "
431
	
462
;dph eax
-
 
463
;newline
432
;dps	"part "
464
 
433
;dph	eax
465
	mov		edi, [pos]
-
 
466
 
-
 
467
	add		[pos], eax
-
 
468
	push	eax
-
 
469
	
434
;newline
470
	mov		eax, 68
-
 
471
	mov		ebx, 20
-
 
472
	mov		ecx, [pos]
435
	mov	edi,[pos]
473
	mov		edx, [buf_ptr]
436
	add	[pos],eax
474
	mcall
437
	push	eax
475
	
438
	mcall	68,20,[pos],[buf_ptr]
476
	mov		[buf_ptr], eax
439
	mov	[buf_ptr],eax
477
	add		edi, eax
440
	add	edi,eax
Line 478... Line 441...
478
	mov		esi, primary_buf
441
	mov	esi,primary_buf
479
	pop		ecx					; number of recently read bytes
-
 
480
	lea		edx, [ecx - 3]
-
 
481
	rep		movsb
-
 
482
	
442
	pop	ecx	; number of recently read bytes
483
no_more_data:
-
 
484
 
443
	lea	edx,[ecx - 3]
485
	mov		eax, 53
444
	rep	movsb
486
	mov		ebx, 6
-
 
487
	mov		ecx, [socket]
445
	
Line 488... Line 446...
488
	mcall
446
no_more_data:
489
	cmp		eax, 4
-
 
490
	jne		no_more_data.finish
447
	mcall	53,6,[socket]
491
 
448
	cmp	eax,4
492
	jmp		newbyteread
-
 
493
 
449
	jne	no_more_data.finish
494
.finish:
-
 
495
 
450
	jmp	newbyteread
496
;dps "finish "
451
 
497
;pregs
452
.finish:
498
 
453
;dps	"finish	"
499
	call	parse_result
454
;pregs
500
 
-
 
501
	mov		ecx, [shared_name]
455
	call	parse_result
502
	cmp		byte [ecx], 0
456
	mov	ecx,[shared_name]
503
	jnz		save_in_shared
-
 
504
	mov		eax, 70
457
	cmp	[ecx],byte 0
505
	mov		ebx, fileinfo
-
 
506
	mcall
458
	jnz	save_in_shared
507
;dps "saving "
459
 
508
;pregs
-
 
509
 
460
	mcall	70,fileinfo
510
	;jmp		close_end_exit
461
;dps	"saving "
511
	
462
;pregs
512
	pop		edi
-
 
513
	pop		esi
463
;	jmp	close_end_exit
Line 514... Line 464...
514
	
464
	pop	edi
515
	; if called from command line, then exit
-
 
516
	cmp		byte [params], 0
-
 
517
	jnz		exit
465
	pop	esi
518
	
466
; if called from command line, then exit
519
    ret
467
	cmp	[params],byte 0
520
	
468
	jnz	exit
-
 
469
	ret
521
save_in_shared:
470
	
522
	mov	eax, 68
471
save_in_shared:
-
 
472
	mov	esi,1	; SHM_OPEN+SHM_WRITE
523
	mov	ebx, 22
473
	mcall	68,22
524
	mov	esi, 1	; SHM_OPEN+SHM_WRITE
474
	test	eax,eax
525
	mcall
475
	jz	save_in_shared_done
-
 
476
 
526
	test	eax, eax
477
	sub	edx,4
527
	jz	save_in_shared_done
478
	jbe	save_in_shared_done
528
	sub	edx, 4
479
 
529
	jbe	save_in_shared_done
480
	mov	ecx,[final_size]
530
	mov	ecx, [final_size]
481
	cmp	ecx,edx
Line 539... Line 490...
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
Line 548... Line 500...
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
Line 550... Line 502...
550
	; in: buf_ptr, pos; out: buf_ptr, pos.
502
; in: buf_ptr, pos; out: buf_ptr, pos.
551
	
-
 
552
parse_result:
503
	
553
 
-
 
554
	; close socket
-
 
555
    mov     eax, 53
504
parse_result:
556
    mov     ebx, 8
-
 
Line 557... Line 505...
557
    mov     ecx, [socket]
505
; close socket
558
    mcall
506
	mcall	53,8,[socket]
559
	
507
	
560
dps "close socket: "
-
 
561
dph eax
508
dps	"close	socket: "
562
newline
509
dph	eax
563
 
-
 
564
	mov		edi, [buf_ptr]
510
newline
565
	mov		edx, [pos]
-
 
566
	
511
	mov	edi,[buf_ptr]
567
	mov		[buf_size], edx
-
 
568
	;mov		eax, 70
-
 
569
	;mov		ebx, fileinfo_tmp
512
	mov	edx,[pos]
570
	;mcall
513
	mov	[buf_size],edx
571
 
514
;	mcall	70,fileinfo_tmp
Line 572... Line 515...
572
dps "pos = "
515
dps	"pos = "
573
dph edx
-
 
574
newline
516
dph	edx
575
 
517
newline
576
	; first, find end of headers
518
 
577
	
519
; first, find end of headers
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
-
 
583
	inc		edi
524
	je	.end_of_headers
584
	dec		edx
525
	inc	edi
Line 585... Line 526...
585
	jne		.next_byte
526
	dec	edx
586
	
-
 
587
	; no end of headers. it's an error. let client see all those headers.
-
 
588
	ret
527
	jne	.next_byte
589
	
-
 
590
.end_of_headers:
528
; no end of headers. it's an error. let client see all those headers.
591
 
529
	ret
592
 
-
 
593
	; here we look at headers and search content-length or transfer-encoding headers
530
 
594
 
531
.end_of_headers:
595
;dps "eoh "
532
; here we look at headers and search content-length or transfer-encoding headers
596
;newline
533
;dps	"eoh "
597
 
-
 
598
	sub		edi, [buf_ptr]
534
;newline
599
	add		edi, 3
535
	sub	edi,[buf_ptr]
600
	mov		[body_pos], edi		; store position where document body starts
-
 
601
	mov		[is_chunked], 0
536
	add	edi,3
602
 
537
	mov	[body_pos],edi	; store position where document body starts
603
	; find content-length in headers
538
	mov	[is_chunked],0
604
	; not good method, but should work for 'Content-Length:'
539
; find content-length in headers
605
	
540
; not good method, but should work for 'Content-Length:'
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:
-
 
626
;pregs
560
.cl_error:
627
;newline
-
 
628
;dph esi
561
;pregs
629
;dps	" content-length not found "
562
;newline
630
 
-
 
631
	; find 'chunked'
563
;dph	esi
632
	
564
;dps	" content-length not found "
633
	; äà, ÿ êîïèðóþ êîä, ýòî óæàñíî, íî ìíå õî÷åòñÿ, ÷òîáû ïîñêîðåå çàðàáîòàëî
565
; find 'chunked'
634
	; à òàì óæ îòðåôàêòîðþ
566
; äà, ÿ êîïèðóþ êîä, ýòî óæàñíî, íî ìíå õî÷åòñÿ, ÷òîáû ïîñêîðåå çàðàáîòàëî
-
 
567
; à òàì óæ îòðåôàêòîðþ
635
	
568
	mov	esi,[buf_ptr]
636
	mov		esi, [buf_ptr]
569
	mov	edi,s_chunked
637
	mov		edi, s_chunked
570
	mov	ebx,[body_pos]
638
	mov		ebx, [body_pos]
571
	xor	edx,edx	; 0
639
	mov		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]
-
 
576
	jne	.ch_fail
643
	jne		.ch_fail
577
	inc	edx
644
	inc		edx
578
	cmp	edx,len_chunked
-
 
579
	je	.ch_found
645
	cmp		edx, len_chunked
580
	jmp	.ch_incr
646
	je		.ch_found
581
 
647
	jmp		.ch_incr
582
.ch_fail:
648
.ch_fail:
583
	xor	edx,edx	; 0
649
	mov		edx, 0
584
 
650
.ch_incr:
-
 
Line -... Line 585...
-
 
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
 
Line 656... Line 591...
656
 
591
.ch_error:
657
	; if neither of the 2 headers is found, it's an error
-
 
658
;dps "transfer-encoding: chunked not found "
592
; if neither of the 2 headers is found, it's an error
659
	mov		eax, [pos]
593
;dps	"transfer-encoding: chunked not found "
660
	sub		eax, [body_pos]
594
	mov	eax,[pos]
661
	jmp		.write_final_size
595
	sub	eax,[body_pos]
662
 
596
	jmp	.write_final_size
663
.ch_found:
597
 
Line 664... Line 598...
664
 
598
.ch_found:
665
	mov		[is_chunked], 1
-
 
666
	mov		eax, [body_pos]
599
	mov	[is_chunked],1
667
	add		eax, [buf_ptr]
600
	mov	eax,[body_pos]
Line 668... Line 601...
668
	sub		eax, 2
601
	add	eax,[buf_ptr]
669
	mov		[prev_chunk_end], eax
602
	sub	eax,2
Line 682... Line 615...
682
 
615
 
683
;dps "check cl eax==ebx "	
616
;dps	"check cl eax==ebx "
Line 684... Line 617...
684
;pregs
617
;pregs
685
 
-
 
686
	; everything is ok, so we return
618
 
687
	
619
; everything is ok, so we return
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
-
 
694
	;mov		[final_size], ebx
625
;	sub	ebx,eax
Line 695... Line 626...
695
	
626
;	mov	[final_size],ebx
696
	ret
-
 
697
	
627
	ret
698
parse_chunks:
628
	
699
 
629
parse_chunks:
700
;dps "parse chunks"
-
 
701
;newline
630
;dps	"parse chunks"
702
	; we have to look through the data and remove sizes of chunks we see
631
;newline
703
	
632
	; we have to look through the data and remove sizes of chunks we see
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
Line 707... Line 636...
707
	
636
	xor	eax,eax
708
	mov		[final_buffer], 0
-
 
709
	mov		[final_size], 0
637
	mov	[final_buffer],eax	; 0
710
	
638
	mov	[final_size],eax	; 0
711
.read_size:
639
	
712
	
-
 
713
	mov		eax, [prev_chunk_end]
640
.read_size:
714
	mov		ebx, eax
-
 
715
	sub		ebx, [buf_ptr]
641
	mov	eax,[prev_chunk_end]
716
 
642
	mov	ebx,eax
717
	mov		edx, eax
-
 
718
	
643
	sub	ebx,[buf_ptr]
719
;dps "rs "
644
	mov	edx,eax
Line 720... Line 645...
720
;pregs
645
;dps	"rs "
721
 
646
;pregs
Line 732... Line 657...
732
	add		ebx, eax
657
	add	ebx,eax
733
	mov		[prev_chunk_end], ebx
658
	mov	[prev_chunk_end],ebx
Line 734... Line 659...
734
	
659
	
735
;dps "sz "
660
;dps	"sz "
736
;pregs
-
 
737
 
661
;pregs
738
	; do copying: from buf_ptr+edx to final_buffer+prev_final_size count eax
-
 
739
	
662
; do copying: from buf_ptr+edx to final_buffer+prev_final_size count eax
740
	; realloc final buffer
-
 
741
	
663
; realloc final buffer
742
	push	eax
664
	push	eax
743
	push	edx
665
	push	edx
744
	push	dword [final_size]
-
 
745
	
666
	push	dword [final_size]
746
	add		[final_size], eax
-
 
747
	
-
 
748
	mov		eax, 68
-
 
749
	mov		ebx, 20
-
 
750
	mov		ecx, [final_size]
667
	add	[final_size],eax
751
	mov		edx, [final_buffer]
-
 
752
	mcall
668
	mcall	68,20,[final_size],[final_buffer]
753
	mov		[final_buffer], eax
669
	mov	[final_buffer],eax
754
;dps "re "
670
;dps	"re "
755
;pregs
-
 
756
	
671
;pregs
757
	pop		edi
672
	pop	edi
758
	pop		esi
673
	pop	esi
759
	pop		ecx
-
 
760
 
674
	pop	ecx
761
	;add		[pos], ecx
-
 
762
	
675
;	add	[pos],ecx
763
	add		edi, [final_buffer]
-
 
764
 
676
	add	edi,[final_buffer]
765
;dps "cp "
677
;dps	"cp "
766
;pregs
-
 
767
	
678
;pregs
768
	rep		movsb
-
 
769
	
679
	rep	movsb
Line 770... Line 680...
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"
-
 
775
newline
-
 
776
	
-
 
777
	mov		eax, 68
684
dps	"chunks end"
778
	mov		ebx, 13
-
 
779
	mov		ecx, [buf_ptr]
-
 
780
	mcall
685
newline
781
	
-
 
782
	; done!
686
	mcall	68,13,[buf_ptr]
Line 783... Line -...
783
	
-
 
784
	ret
-
 
785
	
687
; done!
786
	
688
	ret
787
	
-
 
788
; reads content-length from [edi+ecx], result in eax
689
 
789
read_number:
690
; reads content-length from [edi+ecx], result in eax
790
 
691
read_number:
-
 
692
	push	ebx
791
	push	ebx
693
	xor	eax,eax
792
	xor		eax, eax
694
	xor	ebx,ebx
793
	xor		ebx, ebx
695
 
794
.next:
696
.next:
795
	mov		bl, [esi]
697
	mov	bl,[esi]
Line 800... Line 702...
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
Line 817... Line -...
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
-
 
834
	
732
;	popf
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]
Line 842... Line 740...
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:
Line 862... Line 764...
862
;newline
764
;newline
863
;dps "hextoint eax "
765
;dps	"hextoint eax "
864
;pregs
766
;pregs
865
	ret
767
	ret
Line 866... Line -...
866
 
-
 
867
	
-
 
868
 
-
 
869
 
768
 
870
;****************************************************************************
769
;****************************************************************************
871
;    Function
770
;    Function
872
;       draw_page
771
;       draw_page
873
;
772
;
Line 878... Line 777...
878
;
777
;
879
;****************************************************************************
778
;****************************************************************************
880
draw_page:
779
draw_page:
881
	ret
780
	ret
Line 882... Line -...
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:
-
 
893
 
790
linefeed:
Line 894... Line 791...
894
    ret
791
	ret
895
 
792
 
896
;****************************************************************************
793
;****************************************************************************
Line 917... Line 814...
917
    jnz     tst3
814
	jnz	tst3
Line 918... Line 815...
918
 
815
 
919
	dps "opening socket"
816
dps	"opening socket"
920
	newline
817
newline
-
 
818
; Clear all page memory
-
 
819
	xor	eax,eax
-
 
820
	mov	[prev_chunk_end],eax	; 0
-
 
821
	cmp	[buf_ptr],eax	; 0
Line 921... Line 822...
921
    ; Clear all page memory
822
	jz	no_free
Line 922... Line -...
922
	
-
 
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
823
 
-
 
824
	mcall	68,13,[buf_ptr]	; free	buffer
929
	mov		ecx, [buf_ptr]
825
 
930
	mcall
-
 
931
no_free:
826
no_free:
932
	mov		[buf_size], 0
827
	xor	eax,eax
933
 
-
 
934
    ; Parse the entered url
828
	mov	[buf_size],eax	; 0
935
    call    parse_url
829
; Parse the entered url
-
 
830
	call	parse_url
936
 
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:
-
 
940
        inc         ecx
-
 
941
        push    ecx
834
getlp1:
942
        mov         eax, 53
835
	inc	ecx
943
        mov         ebx, 9
836
	push	ecx
944
        mcall
837
	mcall	53,9
Line 945... Line -...
945
        pop         ecx
-
 
946
        cmp         eax, 0                      ; is this local port in use?
-
 
947
        jz              getlp1              ; yes - so try next
838
	pop	ecx
948
 
839
	cmp	eax,0	; is this local port in use?
949
    mov     eax,53
840
	jz	getlp1	; yes - so try next
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
-
 
954
    mov     edx,[proxyPort]
-
 
955
sc000:
844
	jz	sc000
956
    mov     esi,dword [server_ip]
-
 
957
    mov     edi,1
-
 
958
    mcall
-
 
959
    mov     [socket], eax
-
 
960
 
845
	mov	edx,[proxyPort]
961
    mov     [pos],0
-
 
962
    mov     [pagex],0
-
 
963
    mov     [pagey],0
-
 
Line -... Line 846...
-
 
846
sc000:
-
 
847
	mcall	53,5,,,[server_ip],1
-
 
848
	mov	[socket],eax
-
 
849
	mov	[pagexs],80
-
 
850
	
-
 
851
	push	eax
-
 
852
	xor	eax,eax ; 0
-
 
853
	mov	[pos],eax
964
    mov     [pagexs],80
854
	mov	[pagex],eax
Line 965... Line 855...
965
    mov     [command_on_off],0
855
	mov	[pagey],eax
966
	
856
	mov	[command_on_off],eax
967
	mov		[is_body], 0
857
	mov	[is_body],eax
Line 968... Line -...
968
 
-
 
969
    ret
-
 
970
 
858
	pop	eax
971
tst3:
-
 
972
    cmp     ah,24     ; close socket
-
 
973
    jnz     no_24
859
	ret
974
 
-
 
975
    mov     eax,53
-
 
976
    mov     ebx,8
-
 
977
    mov     ecx,[socket]
860
 
978
    mcall
861
tst3:
Line 979... Line -...
979
 
-
 
980
    call    draw_page
-
 
981
 
862
	cmp	ah,24	; close	socket
982
    ret
863
	jnz	no_24
983
 
864
 
984
no_24:
865
	mcall	53,8,[socket]
985
    ret
866
	call	draw_page
Line 1027... Line 908...
1027
    mov     ax, '//'
908
	mov	ax,'//'
Line 1028... Line 909...
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
Line 1035... Line 916...
1035
    loop    pu_000
916
	loop	pu_000
1036
 
917
 
1037
pu_002:
918
pu_002:
Line 1038... Line 919...
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
 
-
 
1041
pu_001:
921
 
1042
    add     esi, 2
922
pu_001:
1043
 
-
 
1044
    mov     ebx, esi    ; save address of start of web address
923
	add	esi,2
1045
    mov     edi, document_user + URLMAXLEN  ; end of string
924
	mov	ebx,esi	; save address of start of web address
1046
 
925
	mov	edi,document_user + URLMAXLEN	; end of string
1047
    ; look for page delimiter - it's a '/' character
926
; look for page delimiter - it's a '/' character
1048
pu_003:
927
pu_003:
Line 1066... Line 945...
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
Line 1073... Line 953...
1073
 
953
 
1074
pu_007:
954
pu_007:
Line 1075... Line 955...
1075
    pop     esi                 ; point esi to '/' delimiter
955
	pop	esi	; point esi to '/' delimiter
Line 1083... Line 963...
1083
    cld
963
	cld
Line 1084... Line 964...
1084
 
964
 
1085
pu_008:
965
pu_008:
1086
    movsb
966
	movsb
1087
    cmp     esi, ecx
967
	cmp	esi,ecx
-
 
968
;	je	pu_009		; äçåí-àññåìáëåð
1088
    je      pu_009
969
;	jmp	pu_008		; íå íàäî ïëîäèòü ñóùíîñòè ïî íàïðàñíó
Line 1089... Line 970...
1089
    jmp     pu_008
970
	jne	pu_008
1090
 
971
 
1091
pu_009:
-
 
1092
    ; For debugging, display resulting strings
972
pu_009:
1093
 
973
; For debugging, display resulting strings
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
-
 
1101
end if
980
	call	debug_print_string
1102
 
981
end	if
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
Line 1109... Line 988...
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
Line 1113... Line -...
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
-
 
1119
 
996
end	if
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
-
 
Line -... Line 1002...
-
 
1002
	mov	esi,webAddr-1
1126
pu_020:
1003
 
1127
 
1004
pu_020:
-
 
1005
	mov	edi,server_ip
1128
    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'
Line 1136... Line 1014...
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
Line 1149... Line 1027...
1149
 
1027
 
1150
pu_010:
-
 
1151
 
1028
pu_010:
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
-
 
1156
 
1032
end	if
1157
    ; Resolve Address
1033
; Resolve Address
1158
    call    translateData       ; Convert domain & DNS IP address
1034
	call	translateData	; Convert domain & DNS IP address
Line 1159... Line 1035...
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
Line 1163... Line 1039...
1163
    call    debug_print_string
1039
	call	debug_print_string
1164
end if
-
 
1165
 
1040
end	if
1166
pu_011:
1041
 
Line 1167... Line -...
1167
 
-
 
1168
    ; Done
1042
pu_011:
1169
    ret
1043
; Done
1170
 
1044
	ret
1171
 
1045
 
1172
;***************************************************************************
1046
;***************************************************************************
Line 1179... Line 1053...
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.
Line 1187... Line -...
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
-
 
1198
 
1067
	mov	[dnsMsg+8],eax
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
-
 
1074
	mov	edx,webAddr
1205
    mov     edx, webAddr
1075
 
1206
td000:
1076
td000:
Line 1207... Line 1077...
1207
    mov     ecx, 12                  ; total string length so far
1077
	mov	ecx,12	; total string length so far
1208
 
1078
 
Line 1212... Line 1082...
1212
 
1082
 
1213
td0021:
1083
td0021:
1214
    mov     al, [edx]
1084
	mov	al,[edx]
1215
    cmp     al, ' '
1085
	cmp	al,' '
-
 
1086
	je	td001	; we have finished the string translation
1216
    je      td001                   ; we have finished the string translation
1087
 
1217
    cmp     al, 0
1088
	cmp	al,0
-
 
1089
	je	td001
1218
    je      td001
1090
 
1219
    cmp     al, '.'                 ; we have finished the label
1091
	cmp	al,'.'	; we have finished the label
Line 1220... Line 1092...
1220
    je      td004
1092
	je	td004
1221
 
1093
 
Line 1230... Line 1102...
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
Line 1234... Line -...
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
-
 
1245
 
1113
	add	ecx,4
1246
    mov     [dnsMsgLen], ecx
-
 
1247
 
1114
	mov	[dnsMsgLen],ecx
Line 1248... Line -...
1248
    ret
-
 
1249
 
-
 
1250
 
-
 
1251
 
-
 
1252
 
1115
	ret
1253
 
1116
 
1254
;***************************************************************************
1117
;***************************************************************************
1255
;   Function
1118
;   Function
1256
;      resolveDomain
1119
;      resolveDomain
Line 1264... Line 1127...
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
Line 1275... Line 1136...
1275
 
1136
 
1276
    ; Get DNS IP
-
 
1277
    mov     eax, 52
-
 
1278
    mov     ebx, 13
1137
; Get DNS IP
1279
    mcall
1138
	mcall	52,13
1280
    mov     esi, eax
1139
	mov	esi,eax
1281
    ; First, open socket
-
 
1282
    mov     eax, 53
-
 
1283
    mov     ebx, 0
1140
; First, open socket
1284
    mov     edx, 53    ; remote port - dns
1141
	mov	edx,53	; remote port - dns
-
 
1142
;	mov	esi,dword [dns_ip]
1285
;    mov     esi, dword [dns_ip]
1143
	xor	ebx,ebx	; 0
1286
    mcall
-
 
1287
 
1144
	mcall	53
1288
    mov     [socketNum], eax
-
 
1289
 
1145
	mov	[socketNum],eax
1290
    ; write to socket ( request DNS lookup )
-
 
1291
    mov     eax, 53
-
 
1292
    mov     ebx, 4
-
 
1293
    mov     ecx, [socketNum]
1146
; write to socket ( request DNS lookup )
1294
    mov     edx, [dnsMsgLen]
-
 
1295
    mov     esi, dnsMsg
-
 
1296
    mcall
-
 
1297
 
1147
	mcall	53,4,[socketNum],[dnsMsgLen],dnsMsg
1298
    ; Setup the DNS response buffer
-
 
1299
 
1148
; Setup the DNS response buffer
1300
    mov     eax, dnsMsg
1149
	mov	eax,dnsMsg
1301
    mov     [dnsMsgLen], eax
-
 
1302
 
1150
	mov	[dnsMsgLen],eax
1303
    ; now, we wait for
1151
; now, we wait for
1304
    ; UI redraw
1152
; UI redraw
1305
    ; UI close
1153
; UI close
Line 1306... Line 1154...
1306
    ; or data from remote
1154
; or data from remote
1307
 
1155
 
1308
ctr001:
-
 
1309
    mov     eax,10                 ; wait here for event
-
 
1310
    mcall
1156
ctr001:
1311
 
1157
	mcall	10	; wait here for event
-
 
1158
	cmp	eax,1	; redraw request ?
1312
    cmp     eax,1                  ; redraw request ?
1159
	je	ctr003
1313
    je      ctr003
1160
 
-
 
1161
	cmp	eax,2	; key in buffer ?
1314
    cmp     eax,2                  ; key in buffer ?
1162
	je	ctr004
1315
    je      ctr004
1163
 
1316
    cmp     eax,3                  ; button in buffer ?
-
 
1317
    je      ctr005
-
 
1318
 
1164
	cmp	eax,3	; button in buffer ?
1319
 
-
 
1320
    ; Any data in the UDP receive buffer?
-
 
1321
    mov     eax, 53
1165
	je	ctr005
1322
    mov     ebx, 2
-
 
1323
    mov     ecx, [socketNum]
-
 
1324
    mcall
1166
; Any data in the UDP receive buffer?
1325
 
1167
	mcall	53,2,[socketNum]
Line 1326... Line 1168...
1326
    cmp     eax, 0
1168
	cmp	eax,0
1327
    je      ctr001
1169
	je	ctr001
1328
 
-
 
1329
    ; we have data - this will be the response
-
 
1330
ctr002:
-
 
1331
    mov     eax, 53
1170
 
1332
    mov     ebx, 3
-
 
1333
    mov     ecx, [socketNum]
1171
; we have data - this will be the response
1334
    mcall                ; read byte - block (high byte)
1172
ctr002:
1335
 
1173
	mcall	53,3,[socketNum]	; read byte - block (high byte)
1336
    ; Store the data in the response buffer
1174
; Store the data in the response buffer
Line 1337... Line -...
1337
    mov     eax, [dnsMsgLen]
-
 
1338
    mov     [eax], bl
-
 
1339
    inc     dword [dnsMsgLen]
-
 
1340
 
1175
	mov	eax,[dnsMsgLen]
1341
    mov     eax, 53
-
 
1342
    mov     ebx, 2
1176
	mov	[eax],bl
1343
    mov     ecx, [socketNum]
1177
	inc	dword [dnsMsgLen]
Line 1344... Line 1178...
1344
    mcall                ; any more data?
1178
 
1345
 
-
 
1346
    cmp     eax, 0
-
 
1347
    jne     ctr002              ; yes, so get it
1179
	mcall	53,2,[socketNum]	; any more data?
1348
 
-
 
1349
    ; close socket
-
 
1350
    mov     eax, 53
1180
	cmp	eax,0
1351
    mov     ebx, 1
-
 
1352
    mov     ecx, [socketNum]
1181
	jne	ctr002	; yes, so get it
1353
    mcall
1182
 
1354
 
1183
; close	socket
1355
    mov     [socketNum], dword 0xFFFF
-
 
1356
 
1184
	mcall	53,1,[socketNum]
1357
    ; Now parse the message to get the host IP
1185
	mov	[socketNum],dword  0xFFFF
1358
    ; Man, this is complicated. It's described in
1186
; Now parse the message to get the host IP
1359
    ; RFC 1035
1187
; Man, this is complicated. It's described in
Line 1369... Line 1197...
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]
Line 1371... Line 1199...
1371
 
1199
 
1372
    ; Clear the IP address text
1200
; Clear the IP address text
1373
    mov     [server_ip], dword 0
-
 
1374
 
1201
	mov	[server_ip],dword  0
1375
    mov     esi, dnsMsg
-
 
1376
 
1202
	mov	esi,dnsMsg
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
-
 
1382
 
1207
	jne	ctr002a
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
-
 
1388
 
1212
	jne	ctr002a
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
-
 
1393
 
1216
	je	ctr002a
1394
    ; Header validated. Scan through and get my answer
-
 
1395
 
1217
; Header valdated. Scan through and get my answer
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
-
 
1402
 
1223
end	if
1403
    add     esi, 12             ; Skip to the question field
-
 
1404
 
1224
	add	esi,12	; Skip to the question field
1405
    ; Skip through the question field
1225
; Skip through the question field
1406
    call    skipName
1226
	call	skipName
Line 1407... Line 1227...
1407
    add     esi, 4              ; skip past the questions qtype, qclass
1227
	add	esi,4	; skip past the questions qtype, qclass
Line 1411... Line 1231...
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
Line 1423... Line -...
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
-
 
1431
 
1247
	add	esi,2
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
Line 1441... Line 1257...
1441
ctr003:                         ; redraw
1257
ctr003:	; redraw
1442
    call    draw_window
1258
	call	draw_window
1443
    jmp     ctr001
1259
	jmp	ctr001
Line 1444... Line 1260...
1444
 
1260
 
1445
ctr004:                         ; key
1261
ctr004:	; key
1446
    mov     eax,2               ; just read it and ignore
-
 
1447
    mcall
1262
	mcall	2	; just read it and ignore
Line 1448... Line 1263...
1448
    jmp     ctr001
1263
	jmp	ctr001
1449
 
1264
 
1450
ctr005:                         ; button
-
 
1451
    mov     eax,17              ; get id
-
 
1452
    mcall
1265
ctr005:	; button
Line 1453... Line 1266...
1453
 
1266
	mcall	17	; get id
1454
    mov     dl, ah
-
 
1455
 
-
 
1456
    ; close socket
1267
	mov	dl,ah
1457
    mov     eax, 53
-
 
1458
    mov     ebx, 1
-
 
1459
    mov     ecx, [socketNum]
1268
 
1460
    mcall
1269
	; close	socket
Line 1461... Line 1270...
1461
 
1270
	mcall	53,1,[socketNum]
1462
    cmp     dl, 1
1271
	cmp	dl,1
1463
    je      exit
-
 
1464
 
1272
	je	exit
Line 1465... Line -...
1465
    mov     [socketNum], dword 0xFFFF
-
 
1466
    mov     [server_ip], dword 0
-
 
1467
 
1273
 
1468
    ret
1274
	mov	[socketNum],dword  0xFFFF
1469
 
1275
	mov	[server_ip],dword  0
1470
 
1276
	ret
1471
 
1277
 
Line 1506... Line 1312...
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
Line 1534... Line 1338...
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
Line 1558... Line 1366...
1558
 
1366
 
Line 1561... Line 1369...
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]
Line 1582... Line 1392...
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
Line 1591... Line 1403...
1591
 
1403
 
Line 1604... Line 1416...
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
Line 1613... Line 1423...
1613
 
1423
 
1614
dps_000:
1424
dps_000:
1615
    mov     cl, [esi]
1425
	mov	cl,[esi]
1616
    cmp     cl, 0
1426
	cmp	cl,0
-
 
1427
	je	dps_exit
1617
    je      dps_exit
1428
 
1618
    cmp     cl, ' '
1429
	cmp	cl,' '
1619
    je      dps_exit
1430
	je	dps_exit
Line 1620... Line 1431...
1620
    jmp     dps_001
1431
	jmp	dps_001
1621
 
1432
 
1622
dps_exit:
-
 
1623
    mov     cl, '"'
-
 
1624
    mov     eax,63
1433
dps_exit:
1625
    mov     ebx, 1
1434
	mov	cl,'"'
1626
    mcall
-
 
1627
    mov     cl, 13
-
 
1628
    mov     eax,63
1435
	mcall	63,1
1629
    mov     ebx, 1
1436
	mov	cl,13
1630
    mcall
-
 
1631
    mov     cl, 10
-
 
1632
    mov     eax,63
1437
	mcall	
1633
    mov     ebx, 1
1438
	mov	cl,10
Line 1634... Line 1439...
1634
    mcall
1439
	mcall
1635
    ret
-
 
1636
 
-
 
1637
dps_001:
1440
	ret
1638
    mov     eax,63
1441
 
1639
    mov     ebx, 1
-
 
1640
    push    esi
1442
dps_001:
1641
    mcall
1443
	push	esi
1642
 
1444
	mcall	63,1
1643
    pop     esi
1445
	pop	esi
Line 1644... Line -...
1644
    inc     esi
-
 
1645
    jmp     dps_000
1446
	inc	esi
1646
end if
1447
	jmp	dps_000
1647
 
1448
end	if
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
;
-
 
1656
;****************************************************************************
1456
;
1657
print_text:
1457
;****************************************************************************
1658
    ; Draw a bar to blank out previous text
1458
print_text:
1659
    mov     eax,13
1459
; Draw a bar to blank out previous text
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]
-
 
1662
    shl     ecx,16
-
 
1663
    mov     cx,9
1461
	mov	ecx,[ya]
1664
    mov     edx,0xFFFFFF
-
 
1665
    mcall
1462
	shl	ecx,16
1666
 
1463
	mov	cx,9
1667
    ; write text
-
 
1668
    mov     eax,4
1464
	mcall	13,,,0xFFFFFF
1669
    mov     ebx,30*65536
1465
; write text
1670
    add     ebx,[ya]
-
 
1671
    mov     ecx,0x000000
-
 
1672
    mov     edx,[addr]
1466
	mov	ebx,30*65536
Line 1673... Line 1467...
1673
    mov     esi,URLMAXLEN
1467
	add	ebx,[ya]
1674
    mcall
1468
	xor	ecx,ecx
1675
 
1469
	mcall	4,,,[addr],URLMAXLEN
Line 1676... Line 1470...
1676
    ret
1470
	ret
-
 
1471
 
-
 
1472
;   *********************************************
-
 
1473
;   *******  WINDOW DEFINITIONS AND DRAW ********
Line 1677... Line 1474...
1677
 
1474
;   *********************************************
1678
;   *********************************************
1475
 
1679
;   *******  WINDOW DEFINITIONS AND DRAW ********
-
 
1680
;   *********************************************
-
 
1681
 
-
 
1682
draw_window:
-
 
Line 1683... Line 1476...
1683
 
1476
draw_window:
1684
	cmp		byte [params], 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
-
 
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
 
1477
; function 12: tell os about windowdraw
1704
	ret
1478
; 1 start of draw
-
 
1479
	mcall	12,1
1705
	
1480
 
-
 
1481
;	cmp	[params],byte 0
1706
.noret:
1482
;	jz	.noret
-
 
1483
 
1707
    mov     eax,12                    ; function 12:tell os about windowdraw
1484
; ýòî íåñêîëüêî çàãàäî÷íî, íî åñëè íå ðèñîâàòü îêîøêî ñîâñåì, ïðîãà íå ïàøåò.
1708
    mov     ebx,1                     ; 1, start of draw
1485
; DRAW	WINDOW
1709
    mcall
1486
; eax	function 0 : define and draw window
-
 
1487
;	xor	eax,eax
1710
 
1488
; ebx	[x start] *65536 + [x size]
-
 
1489
;	xor	ebx,ebx
-
 
1490
; ecx	[y start] *65536 + [y size]
-
 
1491
;	xor	ecx,ecx
-
 
1492
; edx	color of work area RRGGBB,8->color gl
Line -... Line 1493...
-
 
1493
; esi	color of bar and flags
-
 
1494
;	xor	esi,esi
1711
                                   ; DRAW WINDOW
1495
;	mcall	,,,0x14ffffff,,title
-
 
1496
 
-
 
1497
; function 12: tell os about windowdraw
-
 
1498
; 2, end of draw
-
 
1499
;	mcall	12,2
-
 
1500
;	ret
-
 
1501
	
-
 
1502
;.noret:
-
 
1503
; DRAW	WINDOW
1712
    mov     eax,0                     ; function 0 : define and draw window
1504
; eax	function 0 : define and draw window
1713
    mov     ebx,50*65536+600          ; [x start] *65536 + [x size]
1505
	xor	eax,eax
1714
    mov     ecx,350*65536+200          ; [y start] *65536 + [y size]
1506
; ebx	[x start] *65536 + [x size]
1715
    mov     edx,0x14ffffff            ; color of work area RRGGBB,8->color gl
1507
; ecx	[y start] *65536 + [y size]
-
 
1508
; edx	color of work area RRGGBB,8->color gl
1716
    mov     edi,title                 ; WINDOW LABEL
1509
; esi	color of bar and flags
-
 
1510
	xor	esi,esi
Line 1717... Line 1511...
1717
    mcall
1511
; edi	WINDOW	LABEL
1718
 
1512
	mcall	,<50,600>,<350,200>,0x14ffffff,,title
1719
 
-
 
1720
    mov     esi, URLMAXLEN            ; URL
-
 
1721
    mov     eax,4                     ; function 4 : write text to window
-
 
Line 1722... Line -...
1722
    mov     ebx,30*65536+38           ; [x start] *65536 + [y start]
-
 
1723
    mov     ecx,0x000000              ; color of text RRGGBB
-
 
1724
    mov     edx,document_user         ; pointer to text beginning
1513
; eax	function 4: write text to window
1725
    mcall
1514
; ebx	[x start] *65536 + [y start]
1726
 
1515
; ecx	color of text RRGGBB
1727
    ; mov     eax,38
1516
; edx	pointer to text beginning
1728
    ; mov     ebx,5*65536+545
-
 
1729
    ; mov     ecx,60*65536+60
-
 
1730
    ; mov     edx,0x000000
-
 
1731
    ; mcall
-
 
1732
 
-
 
1733
    ;mov     eax,38
-
 
1734
    ;mov     ebx,5*65536+545
-
 
1735
    ; mov     ecx,[winys]
-
 
1736
    ; shl     ecx,16
1517
; esi	max lenght
Line -... Line 1518...
-
 
1518
	xor	ecx,ecx
-
 
1519
	mcall	4,<30,38>,,document_user,URLMAXLEN
-
 
1520
 
-
 
1521
;	xor	edx,edx
-
 
1522
;	mcall	38,<5,545>,<60,60>
-
 
1523
 
-
 
1524
;	mov	ecx,[winys]
1737
    ; add     ecx,[winys]
1525
;	shl	ecx,16
1738
    ; sub     ecx,26*65536+26
-
 
1739
    ;mov     edx,0x000000
-
 
1740
    ;mcall
-
 
1741
                                   ; RELOAD
1526
;	add	ecx,[winys]
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
1527
;	sub	ecx,26*65536+26
1746
    mov     esi,0x5588dd              ; button color RRGGBB
-
 
1747
    mcall
-
 
1748
 
-
 
1749
                                   ; URL
1528
;	mcall	38,<5,545>
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]
-
 
1753
    mov     edx,10                    ; button id
1529
 
1754
    ;mov     esi,0x5588dd              ; button color RRGGBB
-
 
1755
    mcall
-
 
1756
 
-
 
1757
                                   ; STOP
-
 
1758
    ;mov     eax,8                     ; function 8 : define and draw button
1530
; RELOAD
1759
    mov     ebx,443*65536+50          ; [x start] *65536 + [x size]
-
 
1760
    mov     ecx,34*65536+14           ; [y start] *65536 + [y size]
1531
; eax	function 8 : define and draw button
1761
    mov     edx,24                    ; button id
1532
; ebx	[x start] *65536 + [x size]
1762
    ;mov     esi,0x5588dd              ; button color RRGGBB
1533
; ecx	[y start] *65536 + [y size]
1763
    mcall
1534
; edx	button id
1764
 
1535
; esi	button color RRGGBB
1765
									; SAVE
1536
	mcall	8,<388,50>,<34,14>,22,0x5588dd
1766
    mov     ebx,(443+55)*65536+50          ; [x start] *65536 + [x size]
1537
; URL
1767
    mov     ecx,34*65536+14           ; [y start] *65536 + [y size]
-
 
1768
    mov     edx,26                    ; button id
1538
	mcall	,<10,12>,<34,12>,10
Line 1769... Line 1539...
1769
    ;mov     esi,0x5588dd              ; button color RRGGBB
1539
; STOP
1770
    mcall
1540
	mcall	,<443,50>,<34,14>,24
1771
	
1541
; SAVE
1772
                                   ; BUTTON TEXT
1542
	mcall	,<498,50>,,26
-
 
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
Line 1777... Line 1548...
1777
    mov     esi,30                    ; text length
1548
; esi	text	length
Line 1778... Line 1549...
1778
    mcall
1549
	mcall	4,<390,38>,0xffffff,button_text,30
1779
 
1550
	call	display_page
1780
    call    display_page
1551
 
Line 1781... Line -...
1781
 
-
 
-
 
1552
; function 12: tell os about windowdraw
1782
    mov     eax,12                    ; function 12:tell os about windowdraw
1553
; 2, end of draw
1783
    mov     ebx,2                     ; 2, end of draw
1554
	mcall	12,2
1784
    mcall
1555
	ret
1785
 
1556
;-----------------------------------------------------------------------------
Line 1807... Line 1578...
1807
buf_ptr			dd		0
1578
buf_ptr		dd 0
1808
				;db	'/rd/1/1',0
1579
;		db	'/rd/1/1',0
Line 1809... Line 1580...
1809
 
1580
 
1810
deba			dd		0
1581
deba		dd 0
1811
				db		0
-
 
1812
 
-
 
-
 
1582
		db 0
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
-
 
1820
 
1589
end	if
1821
params		db	1024 dup(0)
-
 
1822
 
1590
;---------------------------------------------------------------------
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
Line 1842... Line 1610...
1842
 
1610
 
Line 1843... Line 1611...
1843
title         db      'Downloader',0
1611
title		db 'Downloader',0
1844
 
1612
 
-
 
1613
server_ip:	db 207,44,212,20
-
 
1614
;dns_ip:	db 194,145,128,1
1845
server_ip:      db      207,44,212,20
1615
;---------------------------------------------------------------------
1846
;dns_ip:         db      194,145,128,1
1616
;webAddr:
-
 
1617
;times URLMAXLEN db ' '
1847
webAddr:        times URLMAXLEN db ' '
1618
;db	0
1848
db 0
1619
 
-
 
1620
;document_user:	db 'Click on the button to the left to enter a URL',0
1849
document_user:  db      'Click on the button to the left to enter a URL',0
1621
;times URLMAXLEN+document_user-$ db 0
1850
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
;---------------------------------------------------------------------
Line 1854... Line 1626...
1854
s_contentlength		db	'Content-Length:'
1626
s_contentlength	db 'Content-Length:'
1855
len_contentlength	=	15
1627
len_contentlength = 15
Line 1880... Line 1652...
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
Line 1884... Line -...
1884
 
-
 
Line 1885... Line -...
1885
request			db		256 dup(0)
-
 
1886
 
-
 
1887
proxyAddr		db		256 dup(0)
-
 
1888
proxyUser		db		256 dup(0)
1656
 
Line 1889... Line 1657...
1889
proxyPassword	db		256 dup(0)
1657
 
Line 1890... Line 1658...
1890
proxyPort		dd		80
1658
proxyPort	dd 80
Line 1900... Line 1668...
1900
onoff           dd      0x0
1668
onoff		dd 0x0
Line 1901... Line 1669...
1901
 
1669
 
1902
nextupdate:     dd      0
1670
nextupdate:	dd 0
Line 1903... Line -...
1903
winys:          dd      400
-
 
1904
 
-
 
1905
primary_buf		rb		primary_buffer_size
1671
winys:		dd 400
1906
 
1672
 
-
 
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
1907
dnsMsgLen:      dd 0
1712
;---------------------------------------------------------------------
-
 
1713
align 4
-
 
1714
dnsMsg:
-
 
1715
	rb 4096
-
 
1716
;	rb 0x100000
-
 
1717
;---------------------------------------------------------------------
-
 
1718
align 4
-
 
1719
	rb 4096
1908
socketNum:      dd 0xFFFF
1720
stacktop:
-
 
1721
;---------------------------------------------------------------------
1909
dnsMsg:
1722
I_END: