Subversion Repositories Kolibri OS

Rev

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

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