Subversion Repositories Kolibri OS

Rev

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

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