Subversion Repositories Kolibri OS

Rev

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

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