Subversion Repositories Kolibri OS

Rev

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

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